signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def kill(self):
self._abort = True<EOL>
Abort process.
f9547:c0:m14
def reset(self):
self._abort = False<EOL>
Revive class from a killed state.
f9547:c0:m15
def _walk(self):
self._base_len = len(self.base)<EOL>for base, dirs, files in os.walk(self.base, followlinks=self.follow_links):<EOL><INDENT>for name in dirs[:]:<EOL><INDENT>try:<EOL><INDENT>if not self._valid_folder(base, name):<EOL><INDENT>dirs.remove(name)<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>dirs.remove(name)<EOL>value = self.on_error(base, name)<EOL>if value is not None: <EOL><INDENT>yield value<EOL><DEDENT><DEDENT>if self._abort:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if len(files):<EOL><INDENT>for name in files:<EOL><INDENT>try:<EOL><INDENT>valid = self._valid_file(base, name)<EOL><DEDENT>except Exception:<EOL><INDENT>valid = False<EOL>value = self.on_error(base, name)<EOL>if value is not None:<EOL><INDENT>yield value<EOL><DEDENT><DEDENT>if valid:<EOL><INDENT>yield self.on_match(base, name)<EOL><DEDENT>else:<EOL><INDENT>self._skipped += <NUM_LIT:1><EOL>value = self.on_skip(base, name)<EOL>if value is not None:<EOL><INDENT>yield value<EOL><DEDENT><DEDENT>if self._abort:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>if self._abort:<EOL><INDENT>break<EOL><DEDENT><DEDENT>
Start search for valid files.
f9547:c0:m16
def match(self):
return list(self.imatch())<EOL>
Run the directory walker.
f9547:c0:m17
def imatch(self):
self._skipped = <NUM_LIT:0><EOL>for f in self._walk():<EOL><INDENT>yield f<EOL><DEDENT>
Run the directory walker as iterator.
f9547:c0:m18
def _flag_transform(flags):
<EOL>flags = (flags & FLAG_MASK) | _wcparse.PATHNAME<EOL>if flags & _wcparse.REALPATH and util.platform() == "<STR_LIT>":<EOL><INDENT>flags |= _wcparse._FORCEWIN<EOL>if flags & _wcparse.FORCECASE:<EOL><INDENT>flags ^= _wcparse.FORCECASE<EOL><DEDENT><DEDENT>return flags<EOL>
Transform flags to glob defaults.
f9548:m0
def iglob(patterns, *, flags=<NUM_LIT:0>):
yield from Glob(util.to_tuple(patterns), flags).glob()<EOL>
Glob.
f9548:m1
def glob(patterns, *, flags=<NUM_LIT:0>):
return list(iglob(util.to_tuple(patterns), flags=flags))<EOL>
Glob.
f9548:m2
@util.deprecated("<STR_LIT>")<EOL>def globsplit(pattern, *, flags=<NUM_LIT:0>):
return _wcparse.WcSplit(pattern, _flag_transform(flags)).split()<EOL>
Split pattern by '|'.
f9548:m3
def translate(patterns, *, flags=<NUM_LIT:0>):
flags = _flag_transform(flags)<EOL>return _wcparse.translate(_wcparse.split(patterns, flags), flags)<EOL>
Translate glob pattern.
f9548:m4
def globmatch(filename, patterns, *, flags=<NUM_LIT:0>):
flags = _flag_transform(flags)<EOL>if not _wcparse.is_unix_style(flags):<EOL><INDENT>filename = util.norm_slash(filename)<EOL><DEDENT>return _wcparse.compile(_wcparse.split(patterns, flags), flags).match(filename)<EOL>
Check if filename matches pattern. By default case sensitivity is determined by the file system, but if `case_sensitive` is set, respect that instead.
f9548:m5
def globfilter(filenames, patterns, *, flags=<NUM_LIT:0>):
matches = []<EOL>flags = _flag_transform(flags)<EOL>unix = _wcparse.is_unix_style(flags)<EOL>obj = _wcparse.compile(_wcparse.split(patterns, flags), flags)<EOL>for filename in filenames:<EOL><INDENT>if not unix:<EOL><INDENT>filename = util.norm_slash(filename)<EOL><DEDENT>if obj.match(filename):<EOL><INDENT>matches.append(filename)<EOL><DEDENT><DEDENT>return matches<EOL>
Filter names using pattern.
f9548:m6
def raw_escape(pattern, unix=False):
pattern = util.norm_pattern(pattern, False, True)<EOL>return escape(pattern, unix)<EOL>
Apply raw character transform before applying escape.
f9548:m7
def escape(pattern, unix=False):
is_bytes = isinstance(pattern, bytes)<EOL>replace = br'<STR_LIT>' if is_bytes else r'<STR_LIT>'<EOL>win = util.platform() == "<STR_LIT>"<EOL>if win and not unix:<EOL><INDENT>magic = _wcparse.RE_BWIN_MAGIC if is_bytes else _wcparse.RE_WIN_MAGIC<EOL><DEDENT>else:<EOL><INDENT>magic = _wcparse.RE_BMAGIC if is_bytes else _wcparse.RE_MAGIC<EOL><DEDENT>drive = b'<STR_LIT>' if is_bytes else '<STR_LIT>'<EOL>if win and not unix:<EOL><INDENT>m = (_wcparse.RE_BWIN_PATH if is_bytes else _wcparse.RE_WIN_PATH).match(pattern)<EOL>if m:<EOL><INDENT>drive = m.group(<NUM_LIT:0>)<EOL><DEDENT><DEDENT>pattern = pattern[len(drive):]<EOL>return drive + magic.sub(replace, pattern)<EOL>
Escape.
f9548:m8
def __init__(self, pattern, flags=<NUM_LIT:0>):
self.flags = _flag_transform(flags | _wcparse.REALPATH) ^ _wcparse.REALPATH<EOL>self.follow_links = bool(flags & FOLLOW)<EOL>self.dot = bool(flags & DOTMATCH)<EOL>self.negate = bool(flags & NEGATE)<EOL>self.globstar = bool(flags & _wcparse.GLOBSTAR)<EOL>self.braces = bool(flags & _wcparse.BRACE)<EOL>self.case_sensitive = _wcparse.get_case(flags)<EOL>self.is_bytes = isinstance(pattern[<NUM_LIT:0>], bytes)<EOL>self.specials = (b'<STR_LIT:.>', b'<STR_LIT:..>') if self.is_bytes else ('<STR_LIT:.>', '<STR_LIT:..>')<EOL>self.empty = b'<STR_LIT>' if self.is_bytes else '<STR_LIT>'<EOL>self.current = b'<STR_LIT:.>' if self.is_bytes else '<STR_LIT:.>'<EOL>self._parse_patterns(_wcparse.split(pattern, flags))<EOL>if self.flags & _wcparse._FORCEWIN:<EOL><INDENT>self.sep = b'<STR_LIT:\\>' if self.is_bytes else '<STR_LIT:\\>'<EOL><DEDENT>else:<EOL><INDENT>self.sep = b'<STR_LIT:/>' if self.is_bytes else '<STR_LIT:/>'<EOL><DEDENT>
Initialize the directory walker object.
f9548:c0:m0
def _parse_patterns(self, pattern):
self.pattern = []<EOL>self.npatterns = None<EOL>npattern = []<EOL>for p in pattern:<EOL><INDENT>if _wcparse.is_negative(p, self.flags):<EOL><INDENT>npattern.append(p[<NUM_LIT:1>:])<EOL><DEDENT>else:<EOL><INDENT>self.pattern.extend(<EOL>[_wcparse.WcPathSplit(x, self.flags).split() for x in _wcparse.expand_braces(p, self.flags)]<EOL>)<EOL><DEDENT><DEDENT>if npattern:<EOL><INDENT>self.npatterns = _wcparse.compile(npattern, self.flags ^ (_wcparse.NEGATE | _wcparse.REALPATH))<EOL><DEDENT>if not self.pattern and self.npatterns is not None:<EOL><INDENT>self.pattern.append(_wcparse.WcPathSplit((b'<STR_LIT>' if self.is_bytes else '<STR_LIT>'), self.flags).split())<EOL><DEDENT>
Parse patterns.
f9548:c0:m1
def _is_hidden(self, name):
return not self.dot and name[<NUM_LIT:0>:<NUM_LIT:1>] in (b'<STR_LIT:.>', '<STR_LIT:.>')<EOL>
Check if is file hidden.
f9548:c0:m2
def _is_this(self, name):
return name in (b'<STR_LIT:.>', '<STR_LIT:.>') or name == self.sep<EOL>
Check if "this" directory `.`.
f9548:c0:m3
def _is_parent(self, name):
return name in (b'<STR_LIT:..>', '<STR_LIT:..>')<EOL>
Check if `..`.
f9548:c0:m4
def _match_excluded(self, filename, patterns):
return _wcparse._match_real(<EOL>filename, patterns._include, patterns._exclude, patterns._follow, self.symlinks<EOL>)<EOL>
Call match real directly to skip unnecessary `exists` check.
f9548:c0:m5
def _is_excluded(self, path, dir_only):
return self.npatterns and self._match_excluded(path, self.npatterns)<EOL>
Check if file is excluded.
f9548:c0:m6
def _match_literal(self, a, b=None):
return a.lower() == b if not self.case_sensitive else a == b<EOL>
Match two names.
f9548:c0:m7
def _get_matcher(self, target):
if target is None:<EOL><INDENT>matcher = None<EOL><DEDENT>elif isinstance(target, (str, bytes)):<EOL><INDENT>if not self.case_sensitive:<EOL><INDENT>match = target.lower()<EOL><DEDENT>else:<EOL><INDENT>match = target<EOL><DEDENT>matcher = functools.partial(self._match_literal, b=match)<EOL><DEDENT>else:<EOL><INDENT>matcher = target.match<EOL><DEDENT>return matcher<EOL>
Get deep match.
f9548:c0:m8
def _glob_dir(self, curdir, matcher, dir_only=False, deep=False):
scandir = self.current if not curdir else curdir<EOL>if os.path.isdir(scandir) and matcher is not None:<EOL><INDENT>for special in self.specials:<EOL><INDENT>if matcher(special):<EOL><INDENT>yield os.path.join(curdir, special)<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>if NO_SCANDIR_WORKAROUND:<EOL><INDENT>with os.scandir(scandir) as scan:<EOL><INDENT>for f in scan:<EOL><INDENT>try:<EOL><INDENT>if deep and self._is_hidden(f.name):<EOL><INDENT>continue<EOL><DEDENT>path = os.path.join(curdir, f.name)<EOL>is_dir = f.is_dir()<EOL>if is_dir:<EOL><INDENT>is_link = f.is_symlink()<EOL>self.symlinks[path] = is_link<EOL><DEDENT>else:<EOL><INDENT>is_link = False<EOL><DEDENT>if deep and not self.follow_links and is_link:<EOL><INDENT>continue<EOL><DEDENT>if (not dir_only or is_dir) and (matcher is None or matcher(f.name)):<EOL><INDENT>yield path<EOL><DEDENT>if deep and is_dir:<EOL><INDENT>yield from self._glob_dir(path, matcher, dir_only, deep)<EOL><DEDENT><DEDENT>except OSError: <EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for f in os.listdir(scandir):<EOL><INDENT>if deep and self._is_hidden(f):<EOL><INDENT>continue<EOL><DEDENT>path = os.path.join(curdir, f)<EOL>is_dir = os.path.isdir(path)<EOL>if is_dir:<EOL><INDENT>is_link = os.path.islink(path)<EOL>self.symlinks[path] = is_link<EOL><DEDENT>else:<EOL><INDENT>is_link = False<EOL><DEDENT>if deep and not self.follow_links and is_link:<EOL><INDENT>continue<EOL><DEDENT>if (not dir_only or is_dir) and (matcher is None or matcher(f)):<EOL><INDENT>yield path<EOL><DEDENT>if deep and is_dir:<EOL><INDENT>yield from self._glob_dir(path, matcher, dir_only, deep)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except OSError: <EOL><INDENT>pass<EOL><DEDENT>
Non recursive directory glob.
f9548:c0:m9
def _glob(self, curdir, this, rest):
is_magic = this.is_magic<EOL>dir_only = this.dir_only<EOL>target = this.pattern<EOL>is_globstar = this.is_globstar<EOL>if is_magic and is_globstar:<EOL><INDENT>this = rest.pop(<NUM_LIT:0>) if rest else None<EOL>globstar_end = this is None<EOL>while this and not globstar_end:<EOL><INDENT>if this:<EOL><INDENT>dir_only = this.dir_only<EOL>target = this.pattern<EOL><DEDENT>if this and this.is_globstar:<EOL><INDENT>this = rest.pop(<NUM_LIT:0>) if rest else None<EOL>if this is None:<EOL><INDENT>globstar_end = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if globstar_end:<EOL><INDENT>target = None<EOL><DEDENT>this = rest.pop(<NUM_LIT:0>) if rest else None<EOL>matcher = self._get_matcher(target)<EOL>if globstar_end and curdir:<EOL><INDENT>yield os.path.join(curdir, self.empty)<EOL><DEDENT>for path in self._glob_dir(curdir, matcher, dir_only, deep=True):<EOL><INDENT>if this:<EOL><INDENT>yield from self._glob(path, this, rest[:])<EOL><DEDENT>else:<EOL><INDENT>yield path<EOL><DEDENT><DEDENT><DEDENT>elif not dir_only:<EOL><INDENT>matcher = self._get_matcher(target)<EOL>yield from self._glob_dir(curdir, matcher)<EOL><DEDENT>else:<EOL><INDENT>this = rest.pop(<NUM_LIT:0>) if rest else None<EOL>matcher = self._get_matcher(target)<EOL>for path in self._glob_dir(curdir, matcher, True):<EOL><INDENT>if this:<EOL><INDENT>yield from self._glob(path, this, rest[:])<EOL><DEDENT>else:<EOL><INDENT>yield path<EOL><DEDENT><DEDENT><DEDENT>
Handle glob flow. There are really only a couple of cases: - File name. - File name pattern (magic). - Directory. - Directory name pattern (magic). - Extra slashes `////`. - `globstar` `**`.
f9548:c0:m10
def _get_starting_paths(self, curdir):
results = [curdir]<EOL>if not self._is_parent(curdir) and not self._is_this(curdir):<EOL><INDENT>fullpath = os.path.abspath(curdir)<EOL>basename = os.path.basename(fullpath)<EOL>dirname = os.path.dirname(fullpath)<EOL>if basename:<EOL><INDENT>matcher = self._get_matcher(basename)<EOL>results = [os.path.basename(name) for name in self._glob_dir(dirname, matcher, self)]<EOL><DEDENT><DEDENT>return results<EOL>
Get the starting location. For case sensitive paths, we have to "glob" for it first as Python doesn't like for its users to think about case. By scanning for it, we can get the actual casing and then compare.
f9548:c0:m11
def glob(self):
<EOL>self.symlinks = {}<EOL>if self.is_bytes:<EOL><INDENT>curdir = os.fsencode(os.curdir)<EOL><DEDENT>else:<EOL><INDENT>curdir = os.curdir<EOL><DEDENT>for pattern in self.pattern:<EOL><INDENT>dir_only = pattern[-<NUM_LIT:1>].dir_only if pattern else False<EOL>if pattern:<EOL><INDENT>if not pattern[<NUM_LIT:0>].is_magic:<EOL><INDENT>this = pattern[<NUM_LIT:0>]<EOL>curdir = this[<NUM_LIT:0>]<EOL>if not os.path.lexists(curdir):<EOL><INDENT>return<EOL><DEDENT>results = [curdir] if this.is_drive else self._get_starting_paths(curdir)<EOL>if not results:<EOL><INDENT>if not dir_only:<EOL><INDENT>yield curdir<EOL><DEDENT>return<EOL><DEDENT>if this.dir_only:<EOL><INDENT>for start in results:<EOL><INDENT>if os.path.isdir(start):<EOL><INDENT>rest = pattern[<NUM_LIT:1>:]<EOL>if rest:<EOL><INDENT>this = rest.pop(<NUM_LIT:0>)<EOL>for match in self._glob(curdir, this, rest):<EOL><INDENT>if not self._is_excluded(match, dir_only):<EOL><INDENT>yield os.path.join(match, self.empty) if dir_only else match<EOL><DEDENT><DEDENT><DEDENT>elif not self._is_excluded(curdir, dir_only):<EOL><INDENT>yield os.path.join(curdir, self.empty) if dir_only else curdir<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for start in results:<EOL><INDENT>if os.path.lexists(start) and not self._is_excluded(start, dir_only):<EOL><INDENT>yield os.path.join(start, self.empty) if dir_only else start<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>rest = pattern[:]<EOL>this = rest.pop(<NUM_LIT:0>)<EOL>for match in self._glob(curdir if not curdir == self.current else self.empty, this, rest):<EOL><INDENT>if not self._is_excluded(match, dir_only):<EOL><INDENT>yield os.path.join(match, self.empty) if dir_only else match<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>
Starts off the glob iterator.
f9548:c0:m12
def _flag_transform(flags):
return (flags & FLAG_MASK)<EOL>
Transform flags to glob defaults.
f9549:m0
@util.deprecated("<STR_LIT>")<EOL>def fnsplit(pattern, *, flags=<NUM_LIT:0>):
return _wcparse.WcSplit(pattern, _flag_transform(flags)).split()<EOL>
Split pattern by '|'.
f9549:m1
def translate(patterns, *, flags=<NUM_LIT:0>):
flags = _flag_transform(flags)<EOL>return _wcparse.translate(_wcparse.split(patterns, flags), flags)<EOL>
Translate `fnmatch` pattern.
f9549:m2
def fnmatch(filename, patterns, *, flags=<NUM_LIT:0>):
flags = _flag_transform(flags)<EOL>if not _wcparse.is_unix_style(flags):<EOL><INDENT>filename = util.norm_slash(filename)<EOL><DEDENT>return _wcparse.compile(_wcparse.split(patterns, flags), flags).match(filename)<EOL>
Check if filename matches pattern. By default case sensitivity is determined by the file system, but if `case_sensitive` is set, respect that instead.
f9549:m3
def filter(filenames, patterns, *, flags=<NUM_LIT:0>):
matches = []<EOL>flags = _flag_transform(flags)<EOL>unix = _wcparse.is_unix_style(flags)<EOL>obj = _wcparse.compile(_wcparse.split(patterns, flags), flags)<EOL>for filename in filenames:<EOL><INDENT>if not unix:<EOL><INDENT>filename = util.norm_slash(filename)<EOL><DEDENT>if obj.match(filename):<EOL><INDENT>matches.append(filename)<EOL><DEDENT><DEDENT>return matches<EOL>
Filter names using pattern.
f9549:m4
def get_version():
path = os.path.join(os.path.dirname(__file__), '<STR_LIT>')<EOL>fp, pathname, desc = imp.find_module('<STR_LIT>', [path])<EOL>try:<EOL><INDENT>vi = imp.load_module('<STR_LIT>', fp, pathname, desc).__version_info__<EOL>return vi._get_canonical(), vi._get_dev_status()<EOL><DEDENT>except Exception:<EOL><INDENT>print(traceback.format_exc())<EOL><DEDENT>finally:<EOL><INDENT>fp.close()<EOL><DEDENT>
Get version and version_info without importing the entire module.
f9550:m0
def get_requirements(req):
install_requires = []<EOL>with open(req) as f:<EOL><INDENT>for line in f:<EOL><INDENT>if not line.startswith("<STR_LIT:#>"):<EOL><INDENT>install_requires.append(line.strip())<EOL><DEDENT><DEDENT><DEDENT>return install_requires<EOL>
Load list of dependencies.
f9550:m1
def get_description():
with open("<STR_LIT>", '<STR_LIT:r>') as f:<EOL><INDENT>desc = f.read()<EOL><DEDENT>return desc<EOL>
Get long description.
f9550:m2
def post_parser(self, ctx, formatter):
pass<EOL>
In overridden method, It should parse the formatted value from the given string. :param ctx: :param formatter: :return:
f9554:c0:m2
def format(self, d):
return d<EOL>
In overridden method, It Should return string representation of the given argument. :param d: a value to format :return: Formatted value. :rtype: str
f9554:c0:m3
@property<EOL><INDENT>def sub_formatter(self):<DEDENT>
if not self._sub_formatter:<EOL><INDENT>self._sub_formatter = self._create_formatter()<EOL><DEDENT>return self._sub_formatter<EOL>
:return: The underlying formatter. :rtype: :py:class:`khayyam.JalaliDateFormatter`
f9554:c1:m2
@property<EOL><INDENT>def hour(self):<DEDENT>
return self._time.hour<EOL>
:getter: Returns the hour :type: int
f9571:c0:m1
@property<EOL><INDENT>def minute(self):<DEDENT>
return self._time.minute<EOL>
:getter: Returns the minute :type: int
f9571:c0:m2
@property<EOL><INDENT>def second(self):<DEDENT>
return self._time.second<EOL>
:getter: Returns the second :type: int
f9571:c0:m3
@property<EOL><INDENT>def microsecond(self):<DEDENT>
return self._time.microsecond<EOL>
:getter: Returns the microsecond :type: int
f9571:c0:m4
@property<EOL><INDENT>def tzinfo(self):<DEDENT>
return self._time.tzinfo<EOL>
:getter: Returns the timezone info :type: :py:class:`datetime.tzinfo`
f9571:c0:m5
@classmethod<EOL><INDENT>def formatterfactory(cls, fmt):<DEDENT>
return JalaliDatetimeFormatter(fmt)<EOL>
Creates the appropriate formatter for this type. :param fmt: str The format string :return: The new formatter instance. :rtype: :py:class:`khayyam.formatting.JalaliDatetimeFormatter`
f9571:c0:m6
@classmethod<EOL><INDENT>def now(cls, tz=None):<DEDENT>
return cls(datetime.now(tz))<EOL>
If optional argument tz is :py:obj:`None` or not specified, this is like today(), but, if possible, supplies more precision than can be gotten from going through a :py:func:`time.time()` timestamp (for example, this may be possible on platforms supplying the C gettimeofday() function). Else tz must be an instance of a :py:class:`datetime.tzinfo` subclass, and the current date and time are converted to tz's time zone. In this case the result is equivalent to `tz.fromutc(JalaliDatetime.utcnow().replace(tzinfo=tz))`. See also :py:meth:`khayyam.JalaliDate.today` and :py:meth:`khayyam.JalaliDatetime.utcnow`. :param tz: :py:class:`datetime.tzinfo` The optional timezone to get current local date & time. :return: the current local date and time :rtype: :py:class:`khayyam.JalaliDatetime`
f9571:c0:m7
@classmethod<EOL><INDENT>def utcnow(cls):<DEDENT>
return cls(datetime.utcnow())<EOL>
This is like :py:meth:`khayyam.JalaliDatetime.now`, but returns the current UTC date and time, as a naive datetime object. :return: The current UTC date and time, with tzinfo None. :rtype: :py:class:`khayyam.JalaliDatetime`
f9571:c0:m8
@classmethod<EOL><INDENT>def fromtimestamp(cls, timestamp, tz=None):<DEDENT>
return cls(datetime.fromtimestamp(timestamp, tz=tz))<EOL>
Creates a new :py:class:`khayyam.JalaliDatetime` instance from the given posix timestamp. If optional argument tz is :py:obj:`None` or not specified, the timestamp is converted to the platform's local date and time, and the returned datetime object is naive. Else tz must be an instance of a class :py:class:`datetime.tzinfo` subclass, and the timestamp is converted to tz's time zone. In this case the result is equivalent to `tz.fromutc(JalaliDatetime.utcfromtimestamp(timestamp).replace(tzinfo=tz))`. This method may raise `ValueError`, if the timestamp is out of the range of values supported by the platform C localtime() or gmtime() functions. It's common for this to be restricted to years in 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored by fromtimestamp(), and then it's possible to have two timestamps differing by a second that yield identical datetime objects. See also :py:class:`khayyam.JalaliDatetime.utcfromtimestamp`. .. testsetup:: api-datetime-fromtimestamp import khayyam from khayyam import JalaliDatetime .. doctest:: api-datetime-fromtimestamp >>> JalaliDatetime.fromtimestamp(1313132131.21232) khayyam.JalaliDatetime(1390, 5, 21, 11, 25, 31, 212320, Jomeh) :param timestamp: float the posix timestamp, i.e 1014324234.23423423. :param tz: :py:class:`datetime.tzinfo` The optional timezone to get local date & time from the given timestamp. :return: The local date and time corresponding to the POSIX timestamp, such as is returned by :py:func:`time.time()`. :rtype: :py:class:`khayyam.JalaliDatetime`
f9571:c0:m9
@classmethod<EOL><INDENT>def utcfromtimestamp(cls, timestamp):<DEDENT>
return cls(datetime.utcfromtimestamp(timestamp))<EOL>
This may raise ValueError, if the timestamp is out of the range of values supported by the platform C gmtime() function. It's common for this to be restricted to years in 1970 through 2038. See also :py:meth:`khayyam.JalaliDatetime.fromtimestamp`. :return: The UTC datetime corresponding to the POSIX timestamp, with tzinfo None. :rtype: :py:class:`khayyam.JalaliDatetime`
f9571:c0:m10
@classmethod<EOL><INDENT>def fromordinal(cls, ordinal):<DEDENT>
return cls.min + timedelta(days=ordinal - <NUM_LIT:1>)<EOL>
Return the jalali datetime corresponding to the proleptic jalali ordinal, where Farvardin 1 of year 1 has ordinal 1. ValueError is raised unless 1 <= ordinal <= JalaliDatetime.max.toordinal(). The hour, minute, second and microsecond of the result are all 0, and tzinfo is None.
f9571:c0:m11
@classmethod<EOL><INDENT>def combine(cls, date, _time):<DEDENT>
if isinstance(date, (JalaliDatetime, khayyam.JalaliDate)):<EOL><INDENT>date = date.todate()<EOL><DEDENT>return cls(datetime.combine(date, _time))<EOL>
Return a new jalali datetime object whose date members are equal to the given date object's, and whose _time and tzinfo members are equal to the given _time object's. For any datetime object d, d == datetime.combine(d.date(), d.timetz()). If date is a datetime object, its _time and tzinfo members are ignored. :param date: :py:class:`khayyam.JalaliDate` the date object to combine. :param _time: :py:class:`datetime.time` the time object to combine. :return: the combined jalali date & time object. :rtype: :py:class:`khayyam.JalaliDatetime`
f9571:c0:m12
@classmethod<EOL><INDENT>def strptime(cls, date_string, fmt):<DEDENT>
result = cls.formatterfactory(fmt).parse(date_string)<EOL>result = {<EOL>k: v for k, v in result.items() if k in (<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'<EOL>)<EOL>}<EOL>return cls(**result)<EOL>
Return a :py:class:`khayyam.JalaliDatetime` corresponding to *date_string*, parsed according to format. ValueError is raised if the *date_string* and format can’t be parsed with :py:class:`khayyam.formatting.JalaliDatetimeFormatter` instance returned by :py:meth:`khayyam.JalaliDatetime.formatterfactory` method. :param date_string: str The representing date & time in specified format. :param fmt: str The format string. :return: Jalali datetime object. :rtype: :py:class:`khayyam.JalaliDatetime`
f9571:c0:m13
def todatetime(self):
arr = get_gregorian_date_from_julian_day(self.tojulianday())<EOL>return datetime(int(arr[<NUM_LIT:0>]), int(arr[<NUM_LIT:1>]), int(arr[<NUM_LIT:2>]), self.hour, self.minute, self.second, self.microsecond,<EOL>self.tzinfo)<EOL>
Converts the current instance to the python builtins :py:class:`datetime.datetime` instance. :return: the new :py:class:`datetime.datetime` instance representing the current date and time in gregorian calendar. :rtype: :py:class:`datetime.datetime`
f9571:c0:m14
def date(self):
return khayyam.JalaliDate(self.year, self.month, self.day)<EOL>
Return date object with same year, month and day. :rtype: :py:class:`khayyam.JalaliDate`
f9571:c0:m15
def time(self):
return time(self.hour, self.minute, self.second, self.microsecond)<EOL>
Return time object with same hour, minute, second and microseconds. tzinfo is :py:obj:`None`. See also method :py:meth:`khayyam.JalaliDatetime.timetz()`. :rtype: :py:class:`datetime.time`
f9571:c0:m16
def timetz(self):
return time(self.hour, self.minute, self.second, self.microsecond, self.tzinfo)<EOL>
Return time object with same hour, minute, second, microsecond, and tzinfo attributes. See also method :py:meth:`khayyam.JalaliDatetime.time()`. :rtype: :py:class:`datetime.time`
f9571:c0:m17
def replace(self, year=None, month=None, day=None, hour=None,<EOL>minute=None, second=None, microsecond=None, tzinfo=None):
year, month, day = self._validate(<EOL>year if year else self.year,<EOL>month if month else self.month,<EOL>day if day else self.day<EOL>)<EOL>result = JalaliDatetime(<EOL>year,<EOL>month,<EOL>day,<EOL>self.hour if hour is None else hour,<EOL>self.minute if minute is None else minute,<EOL>self.second if second is None else second,<EOL>self.microsecond if microsecond is None else microsecond,<EOL>tzinfo if tzinfo != self.tzinfo else self.tzinfo<EOL>)<EOL>return result<EOL>
Return a :py:class:`khayyam.JalaliDatetime` instance with the same attributes, except for those attributes given new values by whichever keyword arguments are specified. Note that tzinfo=None can be specified to create a naive datetime from an aware datetime with no conversion of date and time data, without adjusting the date the and time based tzinfo. :param year: int :param month: int :param day: int :param hour: int :param minute: int :param second: int :param microsecond: int :param tzinfo: :py:class:`datetime.tzinfo` :rtype: :py:class:`khayyam.JalaliDatetime`
f9571:c0:m18
def astimezone(self, tz):
if self.tzinfo is tz:<EOL><INDENT>return self<EOL><DEDENT>if self.tzinfo:<EOL><INDENT>utc = self - self.utcoffset()<EOL><DEDENT>else:<EOL><INDENT>utc = self<EOL><DEDENT>return tz.fromutc(utc.replace(tzinfo=tz))<EOL>
Return a :py:class:`khayyam.JalaliDatetime` object with new :py:meth:`khayyam.JalaliDatetime.tzinfo` attribute tz, adjusting the date and time data so the result is the same UTC time as self, but in *tz*‘s local time. *tz* must be an instance of a :py:class:`datetime.tzinfo` subclass, and its :py:meth:`datetime.tzinfo.utcoffset()` and :py:meth:`datetime.tzinfo.dst()` methods must not return :py:obj:`None`. *self* must be aware (`self.tzinfo` must not be `None`, and `self.utcoffset()` must not return `None`). If `self.tzinfo` is `tz`, `self.astimezone(tz)` is equal to `self`: no adjustment of date or time data is performed. Else the result is local time in time zone `tz`, representing the same UTC time as `self`: after `astz = dt.astimezone(tz), astz - astz.utcoffset()` will usually have the same date and time data as `dt - dt.utcoffset()`. The discussion of class :py:class:`datetime.tzinfo` explains the cases at Daylight Saving Time transition boundaries where this cannot be achieved (an issue only if `tz` models both standard and daylight time). If you merely want to attach a time zone object `tz` to a datetime dt without adjustment of date and time data, use `dt.replace(tzinfo=tz)`. If you merely want to remove the time zone object from an aware datetime dt without conversion of date and time data, use `dt.replace(tzinfo=None)`. Note that the default :py:meth:`datetime.tzinfo.fromutc()` method can be overridden in a :py:class:`datetime.tzinfo` subclass to affect the result returned by :py:meth:`khayyam.JalaliDatetime.astimezone()`. Ignoring error cases, :py:meth:`khayyam.JalaliDatetime.astimezone()` acts like: .. code-block:: python :emphasize-lines: 3,5 def astimezone(self, tz): # doctest: +SKIP if self.tzinfo is tz: return self if self.tzinfo: utc = self - self.utcoffset() else: utc = self return tz.fromutc(utc.replace(tzinfo=tz)) :param tz: :py:class:`datetime.tzinfo` :rtype: :py:class:`khayyam.JalaliDatetime`
f9571:c0:m19
def utcoffset(self):
if self.tzinfo:<EOL><INDENT>return self.tzinfo.utcoffset(self)<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
If :py:meth:`khayyam.JalaliDatetime.tzinfo` is :py:obj:`None`, returns :py:obj:`None`, else returns `self.tzinfo.utcoffset(self)`, and raises an exception if the latter doesn’t return :py:obj:`None`, or a :py:class:`datetime.timedelta` object representing a whole number of minutes with magnitude less than one day. :rtype: :py:class:`datetime.timedelta`
f9571:c0:m20
def dst(self):
if self.tzinfo:<EOL><INDENT>return self.tzinfo.dst(self)<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
If :py:meth:`khayyam.JalaliDatetime.tzinfo` is :py:obj:`None`, returns :py:obj:`None`, else returns `self.tzinfo.dst(self)`, and raises an exception if the latter doesn’t return :py:obj:`None`, or a :py:class:`datetime.timedelta` object representing a whole number of minutes with magnitude less than one day. :rtype: :py:class:`datetime.timedelta`
f9571:c0:m21
def tzname(self):
if self.tzinfo:<EOL><INDENT>return self.tzinfo.tzname(self)<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
If :py:meth:`khayyam.JalaliDatetime.tzinfo` is :py:obj:`None`, returns :py:obj:`None`, else returns `self.tzinfo.tzname(self)`, raises an exception if the latter doesn’t return:py:obj:`None`or a string object. :rtype: str
f9571:c0:m22
def copy(self):
return JalaliDatetime(<EOL>self.year, self.month, self.day,<EOL>self.hour, self.minute, self.second, self.microsecond,<EOL>tzinfo=self.tzinfo<EOL>)<EOL>
It's equivalent to: .. testsetup:: api-datetime-copy from khayyam import JalaliDatetime .. doctest:: api-datetime-copy >>> source_date = JalaliDatetime(1394, 3, 24, 10, 2, 3, 999999) >>> JalaliDatetime(source_date.year, source_date.month, source_date.day, source_date.hour, source_date.minute, source_date.second, source_date.microsecond) khayyam.JalaliDatetime(1394, 3, 24, 10, 2, 3, 999999, Yekshanbeh) :return: A Copy of the current instance. :rtype: :py:class:`khayyam.JalaliDatetime`
f9571:c0:m24
def isoformat(self, sep='<STR_LIT:T>'):
return self.strftime('<STR_LIT>' + sep + '<STR_LIT>')<EOL>
Return a string representing the date and time in ISO 8601 format, YYYY-MM-DDTHH:MM:SS.mmmmmm or, if microsecond is 0, YYYY-MM-DDTHH:MM:SS If utcoffset() does not return :py:obj:`None`, a 6-character string is appended, giving the UTC offset in (signed) hours and minutes: YYYY-MM-DDTHH:MM:SS.mmmmmm+HH:MM or, if microsecond is 0 YYYY-MM-DDTHH:MM:SS+HH:MM :param sep: str The separator between date & time. :return: The ISO formatted date & time. :rtype: str
f9571:c0:m25
def localshortformat(self):
return self.strftime('<STR_LIT>')<EOL>
Return a string representing the date and time in preserved format: `%a %d %b %y %H:%M`. .. testsetup:: api-datetime-localshortformat from __future__ import print_function from khayyam import JalaliDatetime .. doctest:: api-datetime-localshortformat >>> print(JalaliDatetime(1394, 3, 24, 10, 2, 3, 999999).localshortformat()) ی 24 خر 94 10:02 :return: The local short formatted date & time string. :rtype: str
f9571:c0:m26
def localshortformatascii(self):
return self.strftime('<STR_LIT>')<EOL>
Return a string representing the date and time in preserved format: `%e %d %g %y %H:%M`. .. testsetup:: api-datetime-localshortformatascii from __future__ import print_function from khayyam import JalaliDatetime .. doctest:: api-datetime-localshortformatascii >>> print(JalaliDatetime(1394, 3, 24, 10, 2, 3, 999999).localshortformatascii()) Y 24 Kh 94 10:02 :return: The local short ascii formatted date & time string. :rtype: str
f9571:c0:m27
def localdatetimeformat(self):
return self.strftime('<STR_LIT>')<EOL>
Return a string representing the date and time in preserved format: `%A %d %B %Y %I:%M:%S %p`. .. testsetup:: api-datetime-localdatetimeformat from __future__ import print_function from khayyam import JalaliDatetime .. doctest:: api-datetime-localdatetimeformat >>> print(JalaliDatetime(1394, 3, 24, 10, 2, 3, 999999).localdatetimeformat()) یکشنبه 24 خرداد 1394 10:02:03 ق.ظ :return: The local formatted date & time string. :rtype: str
f9571:c0:m28
def localdatetimeformatascii(self):
return self.strftime('<STR_LIT>')<EOL>
Return a string representing the date and time in preserved format: `%E %d %G %Y %I:%M:%S %t`. .. testsetup:: api-datetime-localdatetimeformatascii from __future__ import print_function from khayyam import JalaliDatetime .. doctest:: api-datetime-localdatetimeformatascii >>> print(JalaliDatetime(1394, 3, 24, 10, 2, 3, 999999).localdatetimeformatascii()) Yekshanbeh 24 Khordad 1394 10:02:03 AM :return: The local ascii formatted date & time string. :rtype: str
f9571:c0:m29
def localtimeformat(self):
return self.strftime('<STR_LIT>')<EOL>
Return a string representing the date and time in preserved format: `%I:%M:%S %p`. .. testsetup:: api-datetime-localtimeformat from __future__ import print_function from khayyam import JalaliDatetime .. doctest:: api-datetime-localtimeformat >>> print(JalaliDatetime(1394, 3, 24, 10, 2, 3, 999999).localtimeformat()) 10:02:03 ق.ظ :return: The local formatted time string. :rtype: str
f9571:c0:m30
def hour12(self):
res = self.hour<EOL>if res > <NUM_LIT:12>:<EOL><INDENT>res -= <NUM_LIT:12><EOL><DEDENT>elif res == <NUM_LIT:0>:<EOL><INDENT>res = <NUM_LIT:12><EOL><DEDENT>return res<EOL>
Return The hour value between `1-12`. use :py:meth:`khayyam.JalaliDatetime.ampm()` or :py:meth:`khayyam.JalaliDatetime.ampmascii()` to determine `ante meridiem` and or `post meridiem` :rtype: int
f9571:c0:m31
def ampm(self):
if self.hour < <NUM_LIT:12>:<EOL><INDENT>return AM_PM[<NUM_LIT:0>]<EOL><DEDENT>return AM_PM[<NUM_LIT:1>]<EOL>
:rtype: str :return: The 'ق.ظ' or 'ب.ظ' to determine `ante meridiem` and or `post meridiem`
f9571:c0:m32
def ampmascii(self):
if self.hour < <NUM_LIT:12>:<EOL><INDENT>return AM_PM_ASCII[<NUM_LIT:0>]<EOL><DEDENT>return AM_PM_ASCII[<NUM_LIT:1>]<EOL>
:rtype: str :return: The 'AM' or 'PM' to determine `ante meridiem` and or `post meridiem`
f9571:c0:m33
def utcoffsetformat(self):
if self.tzinfo:<EOL><INDENT>td = self.utcoffset()<EOL>_minutes = td.seconds / <NUM_LIT><EOL>hours = _minutes / <NUM_LIT><EOL>minutes = _minutes % <NUM_LIT><EOL>return '<STR_LIT>' % (hours, minutes)<EOL><DEDENT>return '<STR_LIT>'<EOL>
.. testsetup:: api-datetime-utcoffsetformat from __future__ import def copy from khayyam import JalaliDatetime, TehranTimezone .. doctest:: api-datetime-utcoffsetformat >>> print(JalaliDatetime(1394, 3, 24, 10, 2, 3, 999999, tzinfo=TehranTimezone).utcoffsetformat()) 04:30 :return: The formatted(*HH:MM*) time representing offset from UTC. :rtype: str
f9571:c0:m34
def tznameformat(self):
return self.tzname() or '<STR_LIT>'<EOL>
If :py:meth:`khayyam.JalaliDatetime.tzinfo` is :py:obj:`None`, returns empty string, else returns `self.tzinfo.tzname(self)`, raises an exception if the latter doesn’t return:py:obj:`None`or a string object. :rtype: str
f9571:c0:m35
def dayofyear(self):
return (self.date() - khayyam.JalaliDate(self.year, <NUM_LIT:1>, <NUM_LIT:1>)).days + <NUM_LIT:1><EOL>
Return the day of year (1-[365, 366]). :rtype: int
f9571:c0:m36
def __unicode__(self):
return '<STR_LIT>' % (<EOL>self.year,<EOL>self.month,<EOL>self.day,<EOL>self.hour,<EOL>self.minute,<EOL>self.second,<EOL>self.microsecond,<EOL>'<STR_LIT>' % self.tzinfo.__unicode__() if self.tzinfo else '<STR_LIT>',<EOL>self.weekdaynameascii()<EOL>)<EOL>
Return the default :py:class:`khayyam.JalaliDatetime` representation. .. testsetup:: api-datetime-__unicode__ from __future__ import print_function from khayyam import JalaliDatetime, TehranTimezone .. doctest:: api-datetime-__unicode__ >>> print(JalaliDatetime(1394, 3, 24, 10, 2, 3, 999999, tzinfo=TehranTimezone).__unicode__()) khayyam.JalaliDatetime(1394, 3, 24, 10, 2, 3, 999999, tzinfo=+03:30 dst:60, Yekshanbeh)
f9571:c0:m37
def __str__(self):
return self.isoformat(sep='<STR_LIT:U+0020>')<EOL>
The same as :py:meth:`khayyam.JalaliDatetime.isoformat(sep=' ')`. :rtype: str
f9571:c0:m38
def deprecated(func):
def new_func(*args, **kwargs):<EOL><INDENT>warnings.warn("<STR_LIT>" % func.__name__,<EOL>category=DeprecationWarning)<EOL>return func(*args, **kwargs)<EOL><DEDENT>new_func.__name__ = func.__name__<EOL>new_func.__doc__ = func.__doc__<EOL>new_func.__dict__.update(func.__dict__)<EOL>return new_func<EOL>
This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.
f9576:m1
@property<EOL><INDENT>def isleap(self):<DEDENT>
return is_jalali_leap_year(self.year)<EOL>
`True` if the current instance is in a leap year. :type: bool
f9577:c0:m1
@property<EOL><INDENT>def daysinmonth(self):<DEDENT>
return get_days_in_jalali_month(self.year, self.month)<EOL>
Total days in the current month. :type: int
f9577:c0:m2
@staticmethod<EOL><INDENT>def formatterfactory(fmt):<DEDENT>
return JalaliDateFormatter(fmt)<EOL>
By default it will be return a :py:class:`khayyam.formatting.JalaliDateFormatter` instance based on given format string. :param fmt: see: :doc:`/directives` :type fmt: str :return: Formatter object, based on the given format string. :rtype: khayyam.formatting.BaseFormatter
f9577:c0:m3
@classmethod<EOL><INDENT>def today(cls):<DEDENT>
return cls(datetime.date.today())<EOL>
:return: The current local date. :rtype: :py:class:`khayyam.JalaiDate`
f9577:c0:m4
@classmethod<EOL><INDENT>def fromtimestamp(cls, timestamp):<DEDENT>
return cls(datetime.date.fromtimestamp(timestamp))<EOL>
Such as is returned by :func:`time.time()`. This may raise :class:`ValueError`, if the timestamp is out of the range of values supported by the platform C localtime() function. It’s common for this to be restricted to years from 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored by fromtimestamp(). :return: Local date corresponding to the POSIX timestamp :rtype: :py:class:`khayyam.JalaiDate`
f9577:c0:m5
@classmethod<EOL><INDENT>def fromordinal(cls, ordinal):<DEDENT>
return cls.min + datetime.timedelta(days=ordinal - <NUM_LIT:1>)<EOL>
Where Farvardin 1 of year 1 has ordinal 1. ValueError is raised unless 1 <= ordinal <= `khayyam.jalaliDate(khayyam.MAXYEAR).toordinal()`. :return: The date corresponding to the proleptic Shamsi ordinal. :rtype: :py:class:`khayyam.JalaiDate`
f9577:c0:m6
@classmethod<EOL><INDENT>def strptime(cls, date_string, fmt):<DEDENT>
<EOL>result = cls.formatterfactory(fmt).parse(date_string)<EOL>result = {k: v for k, v in result.items() if k in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')}<EOL>return cls(**result)<EOL>
This is opposite of the :py:meth:`khayyam.JalaliDate.strftime`, and used to parse date strings into date object. `ValueError` is raised if the date_string and format can’t be parsed by time.strptime() or if it returns a value which isn’t a time tuple. For a complete list of formatting directives, see :doc:`/directives`. :param date_string: :param fmt: :return: A :py:class:`khayyam.JalaliDate` corresponding to date_string, parsed according to format :rtype: :py:class:`khayyam.JalaiDate`
f9577:c0:m7
def tojulianday(self):
return get_julian_day_from_jalali_date(self.year, self.month, self.day)<EOL>
:return: Julian day representing the current instance. :rtype: int
f9577:c0:m9
def copy(self):
return JalaliDate(self.year, self.month, self.day)<EOL>
It's equivalent to: >>> source_date = JalaliDate(1394, 3, 24) >>> JalaliDate(source_date.year, source_date.month, source_date.day) khayyam.JalaliDate(1394, 3, 24, Yekshanbeh) :return: A Copy of the current instance. :rtype: :py:class:`khayyam.JalaiDate`
f9577:c0:m10
def replace(self, year=None, month=None, day=None):
return JalaliDate(<EOL>year if year else self.year,<EOL>month if month else self.month,<EOL>day if day else self.day<EOL>)<EOL>
Replaces the given arguments on this instance, and return a new instance. :param year: :param month: :param day: :return: A :py:class:`khayyam.JalaliDate` with the same attributes, except for those attributes given new values by which keyword arguments are specified.
f9577:c0:m11
def todate(self):
arr = get_gregorian_date_from_julian_day(self.tojulianday())<EOL>return datetime.date(int(arr[<NUM_LIT:0>]), int(arr[<NUM_LIT:1>]), int(arr[<NUM_LIT:2>]))<EOL>
Calculates the corresponding day in the gregorian calendar. this is the main use case of this library. :return: Corresponding date in gregorian calendar. :rtype: :py:class:`datetime.date`
f9577:c0:m12
def toordinal(self):
return (self - self.min).days + <NUM_LIT:1><EOL>
It's equivalent to: .. testsetup:: api-date-toordinal import khayyam from khayyam import JalaliDate .. doctest:: api-date-toordinal >>> d = JalaliDate(1361, 6, 15) >>> (d - JalaliDate(khayyam.MINYEAR)).days + 1 496899 :return: The corresponding proleptic Shamsi ordinal days. :rtype: int
f9577:c0:m13
def timetuple(self):
return time.struct_time((<EOL>self.year,<EOL>self.month,<EOL>self.day,<EOL><NUM_LIT:0>,<EOL><NUM_LIT:0>,<EOL><NUM_LIT:0>,<EOL>self.weekday(),<EOL>self.dayofyear(),<EOL>-<NUM_LIT:1><EOL>))<EOL>
It's equivalent to: >>> time.struct_time((d.year, d.month, d.day, d.hour, d.minute, d.second, d.weekday(), dayofyear, [-1|1|0])) # doctest: +SKIP time.struct_time(tm_year=2015, tm_mon=7, tm_mday=28, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=209, tm_isdst=-1) The tm_isdst flag of the result is set according to the dst() method: `tzinfo` is None or dst() returns None, tm_isdst is set to -1; else if dst() returns a non-zero value, tm_isdst is set to 1; else tm_isdst is set to 0. :return: A :py:class:`time.struct_time` such as returned by time.localtime(). :rtype: :py:class:`time.struct_time`
f9577:c0:m14
def weekday(self):
return (self.todate().weekday() + <NUM_LIT:2>) % <NUM_LIT:7><EOL>
:rtype: int :return: The day of the week as an integer, where Saturday is 0 and Friday is 6.
f9577:c0:m15
def isoweekday(self):
return self.weekday() + <NUM_LIT:1><EOL>
:rtype: int :return: The day of the week as an integer, where Saturday is 1 and Friday is 7.
f9577:c0:m16
def isocalendar(self):
return self.year, self.weekofyear(SATURDAY), self.isoweekday()<EOL>
:rtype: tuple :return: Return a 3-tuple, (year, week number, isoweekday).
f9577:c0:m17
def isoformat(self):
return self.strftime('<STR_LIT>')<EOL>
Returns ISO formatted jalali date.: .. testsetup:: api-date-isoformat from khayyam import JalaliDate .. doctest:: api-date-isoformat >>> JalaliDate(1361, 12, 4).isoformat() == '1361-12-04' True :rtype: str :return: A string representing the date in ISO 8601 format, ‘YYYY-MM-DD’.
f9577:c0:m18
def strftime(self, format_string):
return self.formatterfactory(format_string).format(self)<EOL>
Format codes referring to hours, minutes or seconds will see 0 values. For a complete list of formatting directives, see :doc:`/directives`. :param format_string: The format string. :return: A string representing the date, controlled by an explicit format string :rtype: unicode
f9577:c0:m19
def weekdayname(self):
return PERSIAN_WEEKDAY_NAMES[self.weekday()]<EOL>
:return: The corresponding persian weekday name: [شنبه - جمعه] :rtype: unicode
f9577:c0:m20
def weekdayabbr(self):
return PERSIAN_WEEKDAY_ABBRS[self.weekday()]<EOL>
:return: The corresponding persian weekday abbreviation: [ش ی د س چ پ ج] :rtype: unicode
f9577:c0:m21
def weekdaynameascii(self):
return PERSIAN_WEEKDAY_NAMES_ASCII[self.weekday()]<EOL>
:rtype: unicode :return: The corresponding persian weekday name in ASCII: [Shanbeh - Jomeh]
f9577:c0:m22
def weekdayabbrascii(self):
return PERSIAN_WEEKDAY_ABBRS_ASCII[self.weekday()]<EOL>
:return: The corresponding persian weekday abbreviation in ASCII: [Sh, Y, D, Se, Ch, P, J] :rtype: unicode
f9577:c0:m23
def englishweekdaynameascii(self):
return ENGLISH_WEEKDAY_NAMES_ASCII[self.weekday()]<EOL>
:rtype: unicode :return: The corresponding english weekday name in ASCII: [Saturday - Friday]
f9577:c0:m24
def monthname(self):
return PERSIAN_MONTH_NAMES[self.month]<EOL>
:rtype: unicode :return: The corresponding persian month name: [فروردین - اسفند]
f9577:c0:m25