index int64 0 731k | package stringlengths 2 98 ⌀ | name stringlengths 1 76 | docstring stringlengths 0 281k ⌀ | code stringlengths 4 1.07M ⌀ | signature stringlengths 2 42.8k ⌀ |
|---|---|---|---|---|---|
320 | dateutil.relativedelta | normalized |
Return a version of this object represented entirely using integer
values for the relative attributes.
>>> relativedelta(days=1.5, hours=2).normalized()
relativedelta(days=+1, hours=+14)
:return:
Returns a :class:`dateutil.relativedelta.relativedelta` object.
... | def normalized(self):
"""
Return a version of this object represented entirely using integer
values for the relative attributes.
>>> relativedelta(days=1.5, hours=2).normalized()
relativedelta(days=+1, hours=+14)
:return:
Returns a :class:`dateutil.relativedelta.relativedelta` object.
... | (self) |
323 | datetime | timedelta | Difference between two datetime values.
timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
All arguments are optional and default to 0.
Arguments may be integers or floats, and may be positive or negative. | class timedelta:
"""Represent the difference between two datetime objects.
Supported operators:
- add, subtract timedelta
- unary plus, minus, abs
- compare to timedelta
- multiply, divide by int
In addition, datetime supports subtraction of two datetime objects
returning a timedelta,... | null |
324 | maya.core | to_iso8601 | null | def to_iso8601(dt):
return to_utc_offset_naive(dt).isoformat() + 'Z'
| (dt) |
325 | maya.core | to_utc_offset_aware | null | def to_utc_offset_aware(dt):
if dt.tzinfo is not None:
return dt
return pytz.utc.localize(dt)
| (dt) |
326 | maya.core | to_utc_offset_naive | null | def to_utc_offset_naive(dt):
if dt.tzinfo is None:
return dt
return dt.astimezone(pytz.utc).replace(tzinfo=None)
| (dt) |
327 | maya.core | utc_offset |
Returns the time offset from UTC accounting for DST
Keyword Arguments:
time_struct {time.struct_time} -- the struct time for which to
return the UTC offset.
If None, use current local time.
| def utc_offset(time_struct=None):
"""
Returns the time offset from UTC accounting for DST
Keyword Arguments:
time_struct {time.struct_time} -- the struct time for which to
return the UTC offset.
If None, use current... | (time_struct=None) |
328 | maya.core | validate_arguments_type_of_function |
Decorator to validate the <type> of arguments in
the calling function are of the `param_type` class.
if `param_type` is None, uses `param_type` as the class where it is used.
Note: Use this decorator on the functions of the class.
| def validate_arguments_type_of_function(param_type=None):
"""
Decorator to validate the <type> of arguments in
the calling function are of the `param_type` class.
if `param_type` is None, uses `param_type` as the class where it is used.
Note: Use this decorator on the functions of the class.
"... | (param_type=None) |
329 | maya.core | validate_class_type_arguments |
Decorator to validate all the arguments to function
are of the type of calling class for passed operator
| def validate_class_type_arguments(operator):
"""
Decorator to validate all the arguments to function
are of the type of calling class for passed operator
"""
def inner(function):
def wrapper(self, *args, **kwargs):
for arg in args + tuple(kwargs.values()):
if no... | (operator) |
330 | maya.core | when | "Returns a MayaDT instance for the human moment specified.
Powered by dateparser. Useful for scraping websites.
Examples:
'next week', 'now', 'tomorrow', '300 years ago', 'August 14, 2015'
Keyword Arguments:
string -- string to be parsed
timezone -- timezone referenced from (defau... | def when(string, timezone='UTC', prefer_dates_from='current_period'):
""""Returns a MayaDT instance for the human moment specified.
Powered by dateparser. Useful for scraping websites.
Examples:
'next week', 'now', 'tomorrow', '300 years ago', 'August 14, 2015'
Keyword Arguments:
stri... | (string, timezone='UTC', prefer_dates_from='current_period') |
331 | funcsigs | BoundArguments | Result of `Signature.bind` call. Holds the mapping of arguments
to the function's parameters.
Has the following public attributes:
* arguments : OrderedDict
An ordered mutable mapping of parameters' names to arguments' values.
Does not contain arguments' default values.
* signature : ... | class BoundArguments(object):
'''Result of `Signature.bind` call. Holds the mapping of arguments
to the function's parameters.
Has the following public attributes:
* arguments : OrderedDict
An ordered mutable mapping of parameters' names to arguments' values.
Does not contain argument... | (signature, arguments) |
332 | funcsigs | __eq__ | null | def __eq__(self, other):
return (issubclass(other.__class__, BoundArguments) and
self.signature == other.signature and
self.arguments == other.arguments)
| (self, other) |
333 | funcsigs | __hash__ | null | def __hash__(self):
msg = "unhashable type: '{0}'".format(self.__class__.__name__)
raise TypeError(msg)
| (self) |
334 | funcsigs | __init__ | null | def __init__(self, signature, arguments):
self.arguments = arguments
self._signature = signature
| (self, signature, arguments) |
337 | funcsigs | Parameter | Represents a parameter in a function signature.
Has the following public attributes:
* name : str
The name of the parameter as a string.
* default : object
The default value for the parameter if specified. If the
parameter has no default value, this attribute is not set.
* ann... | class Parameter(object):
'''Represents a parameter in a function signature.
Has the following public attributes:
* name : str
The name of the parameter as a string.
* default : object
The default value for the parameter if specified. If the
parameter has no default value, this... | (name, kind, default=<class 'funcsigs._empty'>, annotation=<class 'funcsigs._empty'>, _partial_kwarg=False) |
338 | funcsigs | __eq__ | null | def __eq__(self, other):
return (issubclass(other.__class__, Parameter) and
self._name == other._name and
self._kind == other._kind and
self._default == other._default and
self._annotation == other._annotation)
| (self, other) |
340 | funcsigs | __init__ | null | def __init__(self, name, kind, default=_empty, annotation=_empty,
_partial_kwarg=False):
if kind not in (_POSITIONAL_ONLY, _POSITIONAL_OR_KEYWORD,
_VAR_POSITIONAL, _KEYWORD_ONLY, _VAR_KEYWORD):
raise ValueError("invalid value for 'Parameter.kind' attribute")
self._kind =... | (self, name, kind, default=<class 'funcsigs._empty'>, annotation=<class 'funcsigs._empty'>, _partial_kwarg=False) |
342 | funcsigs | __repr__ | null | def __repr__(self):
return '<{0} at {1:#x} {2!r}>'.format(self.__class__.__name__,
id(self), self.name)
| (self) |
343 | funcsigs | __str__ | null | def __str__(self):
kind = self.kind
formatted = self._name
if kind == _POSITIONAL_ONLY:
if formatted is None:
formatted = ''
formatted = '<{0}>'.format(formatted)
# Add annotation and default value
if self._annotation is not _empty:
formatted = '{0}:{1}'.format(fo... | (self) |
344 | funcsigs | replace | Creates a customized copy of the Parameter. | def replace(self, name=_void, kind=_void, annotation=_void,
default=_void, _partial_kwarg=_void):
'''Creates a customized copy of the Parameter.'''
if name is _void:
name = self._name
if kind is _void:
kind = self._kind
if annotation is _void:
annotation = self._annot... | (self, name=<class 'funcsigs._void'>, kind=<class 'funcsigs._void'>, annotation=<class 'funcsigs._void'>, default=<class 'funcsigs._void'>, _partial_kwarg=<class 'funcsigs._void'>) |
345 | funcsigs | Signature | A Signature object represents the overall signature of a function.
It stores a Parameter object for each parameter accepted by the
function, as well as information specific to the function itself.
A Signature object has the following public attributes and methods:
* parameters : OrderedDict
An... | class Signature(object):
'''A Signature object represents the overall signature of a function.
It stores a Parameter object for each parameter accepted by the
function, as well as information specific to the function itself.
A Signature object has the following public attributes and methods:
* par... | (parameters=None, return_annotation=<class 'funcsigs._empty'>, __validate_parameters__=True) |
346 | funcsigs | __eq__ | null | def __eq__(self, other):
if (not issubclass(type(other), Signature) or
self.return_annotation != other.return_annotation or
len(self.parameters) != len(other.parameters)):
return False
other_positions = dict((param, idx)
for idx, param in enumerate(... | (self, other) |
348 | funcsigs | __init__ | Constructs Signature from the given list of Parameter
objects and 'return_annotation'. All arguments are optional.
| def __init__(self, parameters=None, return_annotation=_empty,
__validate_parameters__=True):
'''Constructs Signature from the given list of Parameter
objects and 'return_annotation'. All arguments are optional.
'''
if parameters is None:
params = OrderedDict()
else:
if ... | (self, parameters=None, return_annotation=<class 'funcsigs._empty'>, __validate_parameters__=True) |
350 | funcsigs | __str__ | null | def __str__(self):
result = []
render_kw_only_separator = True
for idx, param in enumerate(self.parameters.values()):
formatted = str(param)
kind = param.kind
if kind == _VAR_POSITIONAL:
# OK, we have an '*args'-like parameter, so we won't need
# a '*' to sepa... | (self) |
351 | funcsigs | _bind | Private method. Don't use directly. | def _bind(self, args, kwargs, partial=False):
'''Private method. Don't use directly.'''
arguments = OrderedDict()
parameters = iter(self.parameters.values())
parameters_ex = ()
arg_vals = iter(args)
if partial:
# Support for binding arguments to 'functools.partial' objects.
# Se... | (self, args, kwargs, partial=False) |
352 | funcsigs | bind | Get a BoundArguments object, that maps the passed `args`
and `kwargs` to the function's signature. Raises `TypeError`
if the passed arguments can not be bound.
| def bind(*args, **kwargs):
'''Get a BoundArguments object, that maps the passed `args`
and `kwargs` to the function's signature. Raises `TypeError`
if the passed arguments can not be bound.
'''
return args[0]._bind(args[1:], kwargs)
| (*args, **kwargs) |
353 | funcsigs | bind_partial | Get a BoundArguments object, that partially maps the
passed `args` and `kwargs` to the function's signature.
Raises `TypeError` if the passed arguments can not be bound.
| def bind_partial(self, *args, **kwargs):
'''Get a BoundArguments object, that partially maps the
passed `args` and `kwargs` to the function's signature.
Raises `TypeError` if the passed arguments can not be bound.
'''
return self._bind(args, kwargs, partial=True)
| (self, *args, **kwargs) |
354 | funcsigs | replace | Creates a customized copy of the Signature.
Pass 'parameters' and/or 'return_annotation' arguments
to override them in the new copy.
| def replace(self, parameters=_void, return_annotation=_void):
'''Creates a customized copy of the Signature.
Pass 'parameters' and/or 'return_annotation' arguments
to override them in the new copy.
'''
if parameters is _void:
parameters = self.parameters.values()
if return_annotation is ... | (self, parameters=<class 'funcsigs._void'>, return_annotation=<class 'funcsigs._void'>) |
355 | builtins | method-wrapper | null | method-wrapper
| () |
356 | funcsigs | _ParameterKind | null | class _ParameterKind(int):
def __new__(self, *args, **kwargs):
obj = int.__new__(self, *args)
obj._name = kwargs['name']
return obj
def __str__(self):
return self._name
def __repr__(self):
return '<_ParameterKind: {0!r}>'.format(self._name)
| (*args, **kwargs) |
357 | funcsigs | __new__ | null | def __new__(self, *args, **kwargs):
obj = int.__new__(self, *args)
obj._name = kwargs['name']
return obj
| (self, *args, **kwargs) |
358 | funcsigs | __repr__ | null | def __repr__(self):
return '<_ParameterKind: {0!r}>'.format(self._name)
| (self) |
359 | funcsigs | __str__ | null | def __str__(self):
return self._name
| (self) |
360 | builtins | wrapper_descriptor | null | from builtins import wrapper_descriptor
| () |
361 | funcsigs | _empty | null | class _empty(object):
pass
| () |
362 | funcsigs | _get_user_defined_method | null | def _get_user_defined_method(cls, method_name, *nested):
try:
if cls is type:
return
meth = getattr(cls, method_name)
for name in nested:
meth = getattr(meth, name, meth)
except AttributeError:
return
else:
if not isinstance(meth, _NonUserDefin... | (cls, method_name, *nested) |
363 | funcsigs | _void | A private marker - used in Parameter & Signature | class _void(object):
'''A private marker - used in Parameter & Signature'''
| () |
364 | funcsigs | formatannotation | null | def formatannotation(annotation, base_module=None):
if isinstance(annotation, type):
if annotation.__module__ in ('builtins', '__builtin__', base_module):
return annotation.__name__
return annotation.__module__+'.'+annotation.__name__
return repr(annotation)
| (annotation, base_module=None) |
368 | funcsigs | signature | Get a signature object for the passed callable. | def signature(obj):
'''Get a signature object for the passed callable.'''
if not callable(obj):
raise TypeError('{0!r} is not a callable object'.format(obj))
if isinstance(obj, types.MethodType):
sig = signature(obj.__func__)
if obj.__self__ is None:
# Unbound method - ... | (obj) |
371 | mohawk.receiver | Receiver |
A Hawk authority that will receive and respond to requests.
:param credentials_map:
Callable to look up the credentials dict by sender ID.
The credentials dict must have the keys:
``id``, ``key``, and ``algorithm``.
See :ref:`receiving-request` for an example.
:type credent... | class Receiver(HawkAuthority):
"""
A Hawk authority that will receive and respond to requests.
:param credentials_map:
Callable to look up the credentials dict by sender ID.
The credentials dict must have the keys:
``id``, ``key``, and ``algorithm``.
See :ref:`receiving-requ... | (credentials_map, request_header, url, method, content=EmptyValue, content_type=EmptyValue, seen_nonce=None, localtime_offset_in_seconds=0, accept_untrusted_content=False, timestamp_skew_in_seconds=60, **auth_kw) |
372 | mohawk.receiver | __init__ | null | def __init__(self,
credentials_map,
request_header,
url,
method,
content=EmptyValue,
content_type=EmptyValue,
seen_nonce=None,
localtime_offset_in_seconds=0,
accept_untrusted_content=False,
... | (self, credentials_map, request_header, url, method, content=EmptyValue, content_type=EmptyValue, seen_nonce=None, localtime_offset_in_seconds=0, accept_untrusted_content=False, timestamp_skew_in_seconds=60, **auth_kw) |
373 | mohawk.base | _authorize | null | def _authorize(self, mac_type, parsed_header, resource,
their_timestamp=None,
timestamp_skew_in_seconds=default_ts_skew_in_seconds,
localtime_offset_in_seconds=0,
accept_untrusted_content=False):
now = utc_now(offset_in_seconds=localtime_offset_in_seconds)... | (self, mac_type, parsed_header, resource, their_timestamp=None, timestamp_skew_in_seconds=60, localtime_offset_in_seconds=0, accept_untrusted_content=False) |
374 | mohawk.base | _make_header | null | def _make_header(self, resource, mac, additional_keys=None):
keys = additional_keys
if not keys:
# These are the default header keys that you'd send with a
# request header. Response headers are odd because they
# exclude a bunch of keys.
keys = ('id', 'ts', 'nonce', 'ext', 'app'... | (self, resource, mac, additional_keys=None) |
375 | mohawk.receiver | respond |
Respond to the request.
This generates the :attr:`mohawk.Receiver.response_header`
attribute.
:param content=EmptyValue: Byte string of response body that will be sent.
:type content=EmptyValue: str
:param content_type=EmptyValue: content-type header value for respons... | def respond(self,
content=EmptyValue,
content_type=EmptyValue,
always_hash_content=True,
ext=None):
"""
Respond to the request.
This generates the :attr:`mohawk.Receiver.response_header`
attribute.
:param content=EmptyValue: Byte string of response bod... | (self, content=EmptyValue, content_type=EmptyValue, always_hash_content=True, ext=None) |
376 | mohawk.sender | Sender |
A Hawk authority that will emit requests and verify responses.
:param credentials: Dict of credentials with keys ``id``, ``key``,
and ``algorithm``. See :ref:`usage` for an example.
:type credentials: dict
:param url: Absolute URL of the request.
:type url: str
:param... | class Sender(HawkAuthority):
"""
A Hawk authority that will emit requests and verify responses.
:param credentials: Dict of credentials with keys ``id``, ``key``,
and ``algorithm``. See :ref:`usage` for an example.
:type credentials: dict
:param url: Absolute URL of the req... | (credentials, url, method, content=EmptyValue, content_type=EmptyValue, always_hash_content=True, nonce=None, ext=None, app=None, dlg=None, seen_nonce=None, _timestamp=None) |
377 | mohawk.sender | __init__ | null | def __init__(self, credentials,
url,
method,
content=EmptyValue,
content_type=EmptyValue,
always_hash_content=True,
nonce=None,
ext=None,
app=None,
dlg=None,
seen_nonce=None,
# ... | (self, credentials, url, method, content=EmptyValue, content_type=EmptyValue, always_hash_content=True, nonce=None, ext=None, app=None, dlg=None, seen_nonce=None, _timestamp=None) |
380 | mohawk.sender | accept_response |
Accept a response to this request.
:param response_header:
A `Hawk`_ ``Server-Authorization`` header
such as one created by :class:`mohawk.Receiver`.
:type response_header: str
:param content=EmptyValue: Byte string of the response body received.
:type ... | def accept_response(self,
response_header,
content=EmptyValue,
content_type=EmptyValue,
accept_untrusted_content=False,
localtime_offset_in_seconds=0,
timestamp_skew_in_seconds=default_ts_skew_in_seco... | (self, response_header, content=EmptyValue, content_type=EmptyValue, accept_untrusted_content=False, localtime_offset_in_seconds=0, timestamp_skew_in_seconds=60, **auth_kw) |
381 | mohawk.sender | reconfigure | null | def reconfigure(self, credentials):
validate_credentials(credentials)
self.credentials = credentials
| (self, credentials) |
390 | tufup | main | null | def main(args=None):
# show version before anything else
print(f'tufup {__version__}')
# default to --help
if args is None:
args = sys.argv[1:] or ['--help']
# parse command line arguments
options = cli.get_parser().parse_args(args=args)
# exit if version is requested (printed abo... | (args=None) |
394 | bitmath | Bit | Bit based types fundamentally operate on self._bit_value | class Bit(Bitmath):
"""Bit based types fundamentally operate on self._bit_value"""
def _set_prefix_value(self):
self.prefix_value = self._to_prefix_value(self._bit_value)
def _setup(self):
return (2, 0, 'Bit', 'Bits')
def _norm(self, value):
"""Normalize the input value into t... | (value=0, bytes=None, bits=None) |
395 | bitmath | __abs__ | null | def __abs__(self):
return (type(self))(abs(self.prefix_value))
| (self) |
396 | bitmath | __add__ | Supported operations with result types:
- bm + bm = bm
- bm + num = num
- num + bm = num (see radd)
| def __add__(self, other):
"""Supported operations with result types:
- bm + bm = bm
- bm + num = num
- num + bm = num (see radd)
"""
if isinstance(other, numbers.Number):
# bm + num
return other + self.value
else:
# bm + bm
total_bytes = self._byte_value + other.bytes
... | (self, other) |
397 | bitmath | __and__ | "Bitwise and, ex: 100 & 2
bitwise and". Each bit of the output is 1 if the corresponding bit
of x AND of y is 1, otherwise it's 0. | def __and__(self, other):
""""Bitwise and, ex: 100 & 2
bitwise and". Each bit of the output is 1 if the corresponding bit
of x AND of y is 1, otherwise it's 0."""
andd = int(self.bits) & other
return type(self)(bits=andd)
| (self, other) |
398 | bitmath | __div__ | Division: Supported operations with result types:
- bm1 / bm2 = num
- bm / num = bm
- num / bm = num (see rdiv)
| def __div__(self, other):
"""Division: Supported operations with result types:
- bm1 / bm2 = num
- bm / num = bm
- num / bm = num (see rdiv)
"""
if isinstance(other, numbers.Number):
# bm / num
result = self._byte_value / other
return (type(self))(bytes=result)
else:
# bm1 / ... | (self, other) |
399 | bitmath | __eq__ | null | def __eq__(self, other):
if isinstance(other, numbers.Number):
return self.prefix_value == other
else:
return self._byte_value == other.bytes
| (self, other) |
400 | bitmath | __float__ | Return this instances prefix unit as a floating point number | def __float__(self):
"""Return this instances prefix unit as a floating point number"""
return float(self.prefix_value)
| (self) |
401 | bitmath | __ge__ | null | def __ge__(self, other):
if isinstance(other, numbers.Number):
return self.prefix_value >= other
else:
return self._byte_value >= other.bytes
| (self, other) |
402 | bitmath | __gt__ | null | def __gt__(self, other):
if isinstance(other, numbers.Number):
return self.prefix_value > other
else:
return self._byte_value > other.bytes
| (self, other) |
403 | bitmath | __init__ | Instantiate with `value` by the unit, in plain bytes, or
bits. Don't supply more than one keyword.
default behavior: initialize with value of 0
only setting value: assert bytes is None and bits is None
only setting bytes: assert value == 0 and bits is None
only setting bits: assert value == 0 and bytes is None
... | def __init__(self, value=0, bytes=None, bits=None):
"""Instantiate with `value` by the unit, in plain bytes, or
bits. Don't supply more than one keyword.
default behavior: initialize with value of 0
only setting value: assert bytes is None and bits is None
only setting bytes: assert value == 0 and bits is None
only... | (self, value=0, bytes=None, bits=None) |
404 | bitmath | __int__ | Return this instances prefix unit as an integer | def __int__(self):
"""Return this instances prefix unit as an integer"""
return int(self.prefix_value)
| (self) |
405 | bitmath | __le__ | null | def __le__(self, other):
if isinstance(other, numbers.Number):
return self.prefix_value <= other
else:
return self._byte_value <= other.bytes
| (self, other) |
406 | bitmath | __long__ | Return this instances prefix unit as a long integer | def __long__(self):
"""Return this instances prefix unit as a long integer"""
return long(self.prefix_value) # pragma: PY3X no cover
| (self) |
407 | bitmath | __lshift__ | Left shift, ex: 100 << 2
A left shift by n bits is equivalent to multiplication by pow(2,
n). A long integer is returned if the result exceeds the range of
plain integers. | def __lshift__(self, other):
"""Left shift, ex: 100 << 2
A left shift by n bits is equivalent to multiplication by pow(2,
n). A long integer is returned if the result exceeds the range of
plain integers."""
shifted = int(self.bits) << other
return type(self)(bits=shifted)
| (self, other) |
408 | bitmath | __lt__ | null | def __lt__(self, other):
if isinstance(other, numbers.Number):
return self.prefix_value < other
else:
return self._byte_value < other.bytes
| (self, other) |
409 | bitmath | __mul__ | Multiplication: Supported operations with result types:
- bm1 * bm2 = bm1
- bm * num = bm
- num * bm = num (see rmul)
| def __mul__(self, other):
"""Multiplication: Supported operations with result types:
- bm1 * bm2 = bm1
- bm * num = bm
- num * bm = num (see rmul)
"""
if isinstance(other, numbers.Number):
# bm * num
result = self._byte_value * other
return (type(self))(bytes=result)
else:
# ... | (self, other) |
410 | bitmath | __ne__ | null | def __ne__(self, other):
if isinstance(other, numbers.Number):
return self.prefix_value != other
else:
return self._byte_value != other.bytes
| (self, other) |
411 | bitmath | __neg__ | The negative version of this instance | def __neg__(self):
"""The negative version of this instance"""
return (type(self))(-abs(self.prefix_value))
| (self) |
412 | bitmath | __or__ | Bitwise or, ex: 100 | 2
Does a "bitwise or". Each bit of the output is 0 if the corresponding
bit of x AND of y is 0, otherwise it's 1. | def __or__(self, other):
"""Bitwise or, ex: 100 | 2
Does a "bitwise or". Each bit of the output is 0 if the corresponding
bit of x AND of y is 0, otherwise it's 1."""
ord = int(self.bits) | other
return type(self)(bits=ord)
| (self, other) |
413 | bitmath | __pos__ | null | def __pos__(self):
return (type(self))(abs(self.prefix_value))
| (self) |
414 | bitmath | __radd__ | null | def __radd__(self, other):
# num + bm = num
return other + self.value
| (self, other) |
415 | bitmath | __rdiv__ | null | def __rdiv__(self, other):
# num / bm = num
return other / float(self.value)
| (self, other) |
416 | bitmath | __repr__ | Representation of this object as you would expect to see in an
interpreter | def __repr__(self):
"""Representation of this object as you would expect to see in an
interpreter"""
global _FORMAT_REPR
return self.format(_FORMAT_REPR)
| (self) |
417 | bitmath | __rmul__ | null | def __rmul__(self, other):
# num * bm = bm
return self * other
| (self, other) |
418 | bitmath | __rshift__ | Right shift, ex: 100 >> 2
A right shift by n bits is equivalent to division by pow(2, n). | def __rshift__(self, other):
"""Right shift, ex: 100 >> 2
A right shift by n bits is equivalent to division by pow(2, n)."""
shifted = int(self.bits) >> other
return type(self)(bits=shifted)
| (self, other) |
419 | bitmath | __rsub__ | null | def __rsub__(self, other):
# num - bm = num
return other - self.value
| (self, other) |
420 | bitmath | __rtruediv__ | null | def __rtruediv__(self, other):
# num / bm = num
return other / float(self.value)
| (self, other) |
421 | bitmath | __str__ | String representation of this object | def __str__(self):
"""String representation of this object"""
global format_string
return self.format(format_string)
| (self) |
422 | bitmath | __sub__ | Subtraction: Supported operations with result types:
- bm - bm = bm
- bm - num = num
- num - bm = num (see rsub)
| def __sub__(self, other):
"""Subtraction: Supported operations with result types:
- bm - bm = bm
- bm - num = num
- num - bm = num (see rsub)
"""
if isinstance(other, numbers.Number):
# bm - num
return self.value - other
else:
# bm - bm
total_bytes = self._byte_value - other.... | (self, other) |
423 | bitmath | __truediv__ | null | def __truediv__(self, other):
# num / bm
return self.__div__(other)
| (self, other) |
424 | bitmath | __xor__ | Bitwise xor, ex: 100 ^ 2
Does a "bitwise exclusive or". Each bit of the output is the same
as the corresponding bit in x if that bit in y is 0, and it's the
complement of the bit in x if that bit in y is 1. | def __xor__(self, other):
"""Bitwise xor, ex: 100 ^ 2
Does a "bitwise exclusive or". Each bit of the output is the same
as the corresponding bit in x if that bit in y is 0, and it's the
complement of the bit in x if that bit in y is 1."""
xord = int(self.bits) ^ other
return type(self)(bits=xord)
| (self, other) |
425 | bitmath | _do_setup | Setup basic parameters for this class.
`base` is the numeric base which when raised to `power` is equivalent
to 1 unit of the corresponding prefix. I.e., base=2, power=10
represents 2^10, which is the NIST Binary Prefix for 1 Kibibyte.
Likewise, for the SI prefix classes `base` will be 10, and the `power`
for the Kil... | def _do_setup(self):
"""Setup basic parameters for this class.
`base` is the numeric base which when raised to `power` is equivalent
to 1 unit of the corresponding prefix. I.e., base=2, power=10
represents 2^10, which is the NIST Binary Prefix for 1 Kibibyte.
Likewise, for the SI prefix classes `base` will be 10, a... | (self) |
426 | bitmath | _norm | Normalize the input value into the fundamental unit for this prefix
type | def _norm(self, value):
"""Normalize the input value into the fundamental unit for this prefix
type"""
self._bit_value = value * self._unit_value
self._byte_value = self._bit_value / 8.0
| (self, value) |
427 | bitmath | _set_prefix_value | null | def _set_prefix_value(self):
self.prefix_value = self._to_prefix_value(self._bit_value)
| (self) |
428 | bitmath | _setup | null | def _setup(self):
return (2, 0, 'Bit', 'Bits')
| (self) |
429 | bitmath | _to_prefix_value | Return the number of bits/bytes as they would look like if we
converted *to* this unit | def _to_prefix_value(self, value):
"""Return the number of bits/bytes as they would look like if we
converted *to* this unit"""
return value / float(self._unit_value)
| (self, value) |
430 | bitmath | best_prefix | Optional parameter, `system`, allows you to prefer NIST or SI in
the results. By default, the current system is used (Bit/Byte default
to NIST).
Logic discussion/notes:
Base-case, does it need converting?
If the instance is less than one Byte, return the instance as a Bit
instance.
Else, begin by recording the unit... | def best_prefix(self, system=None):
"""Optional parameter, `system`, allows you to prefer NIST or SI in
the results. By default, the current system is used (Bit/Byte default
to NIST).
Logic discussion/notes:
Base-case, does it need converting?
If the instance is less than one Byte, return the instance as a Bit
inst... | (self, system=None) |
431 | bitmath | format | Return a representation of this instance formatted with user
supplied syntax | def format(self, fmt):
"""Return a representation of this instance formatted with user
supplied syntax"""
_fmt_params = {
'base': self.base,
'bin': self.bin,
'binary': self.binary,
'bits': self.bits,
'bytes': self.bytes,
'power': self.power,
'system': self... | (self, fmt) |
432 | bitmath | to_Bit | null | def to_Bit(self):
return Bit(self._bit_value)
| (self) |
433 | bitmath | to_Byte | null | def to_Byte(self):
return Byte(self._byte_value / float(NIST_STEPS['Byte']))
| (self) |
434 | bitmath | to_EB | null | def to_EB(self):
return EB(bits=self._bit_value)
| (self) |
435 | bitmath | to_Eb | null | def to_Eb(self):
return Eb(bits=self._bit_value)
| (self) |
436 | bitmath | to_EiB | null | def to_EiB(self):
return EiB(bits=self._bit_value)
| (self) |
437 | bitmath | to_Eib | null | def to_Eib(self):
return Eib(bits=self._bit_value)
| (self) |
438 | bitmath | to_GB | null | def to_GB(self):
return GB(bits=self._bit_value)
| (self) |
439 | bitmath | to_Gb | null | def to_Gb(self):
return Gb(bits=self._bit_value)
| (self) |
440 | bitmath | to_GiB | null | def to_GiB(self):
return GiB(bits=self._bit_value)
| (self) |
441 | bitmath | to_Gib | null | def to_Gib(self):
return Gib(bits=self._bit_value)
| (self) |
442 | bitmath | to_KiB | null | def to_KiB(self):
return KiB(bits=self._bit_value)
| (self) |
443 | bitmath | to_Kib | null | def to_Kib(self):
return Kib(bits=self._bit_value)
| (self) |
444 | bitmath | to_MB | null | def to_MB(self):
return MB(bits=self._bit_value)
| (self) |
445 | bitmath | to_Mb | null | def to_Mb(self):
return Mb(bits=self._bit_value)
| (self) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.