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... | 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.app... | 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 _w... | 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... | 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... | 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>mat... | 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.sc... | 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 = ... | 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) f... | 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... | 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.app... | 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(trace... | 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... | 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.... | 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,
... | 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 d... | 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.
:para... | 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 ... | 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 t... | 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... | 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.
:rt... | 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: :... | 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_dat... | 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 micros... | 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... | 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,... | 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, ... | 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... | 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).localt... | 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:... | 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=Tehr... | 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... | 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... | 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 acc... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.