code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
super(Choice, self)._copy(other, copy_func) self._choice = other._choice self._name = other._name self._parsed = copy_func(other._parsed)
def _copy(self, other, copy_func)
Copies the contents of another Choice object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects
4.177617
3.626083
1.152102
self._contents = self.chosen.dump(force=force) if self._header is None or force: self._header = b'' if self.explicit is not None: for class_, tag in self.explicit: self._header = _dump_header(class_, 1, tag, self._header + self._conte...
def dump(self, force=False)
Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value
5.587995
5.246825
1.065024
return cls(contents=encoded_data, strict=strict)
def load(cls, encoded_data, strict=False)
Loads a BER/DER-encoded byte string using the current class as the spec :param encoded_data: A byte string of BER or DER encoded data :param strict: A boolean indicating if trailing data should be forbidden - if so, a ValueError will be raised when trailing data exi...
7.72925
15.947219
0.484677
if self.__class__ != other.__class__: raise TypeError(unwrap( ''' Can not copy values from %s object to %s object ''', type_name(other), type_name(self) )) self._children = copy_func(other....
def _copy(self, other, copy_func)
Copies the contents of another Concat object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects
4.33335
4.604441
0.941124
prefix = ' ' * nest_level print('%s%s Object #%s' % (prefix, type_name(self), id(self))) print('%s Children:' % (prefix,)) for child in self._children: child.debug(nest_level + 2)
def debug(self, nest_level=1)
Show the binary data and parsed data in a tree structure
3.745005
3.715415
1.007964
contents = b'' for child in self._children: contents += child.dump(force=force) return contents
def dump(self, force=False)
Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value
5.776918
6.138695
0.941066
if not isinstance(value, byte_cls): raise TypeError(unwrap( ''' %s value must be a byte string, not %s ''', type_name(self), type_name(value) )) self._native = value self.contents =...
def set(self, value)
Sets the value of the object :param value: A byte string
4.753896
4.379154
1.085574
if force: native = self.native self.contents = None self.set(native) return Asn1Value.dump(self)
def dump(self, force=False)
Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value
12.326976
10.397621
1.185557
if not isinstance(value, str_cls): raise TypeError(unwrap( ''' %s value must be a unicode string, not %s ''', type_name(self), type_name(value) )) self._unicode = value self.content...
def set(self, value)
Sets the value of the string :param value: A unicode string
4.240726
4.142323
1.023755
super(AbstractString, self)._copy(other, copy_func) self._unicode = other._unicode
def _copy(self, other, copy_func)
Copies the contents of another AbstractString object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects
7.728889
5.638606
1.370709
self._native = bool(value) self.contents = b'\x00' if not value else b'\xff' self._header = None if self._trailer != b'': self._trailer = b''
def set(self, value)
Sets the value of the object :param value: True, False or another value that works with bool()
7.413832
6.636179
1.117184
if self.contents is None: return None if self._native is None: self._native = self.__bool__() return self._native
def native(self)
The native Python datatype representation of this value :return: True, False or None
6.586493
5.073801
1.298138
if isinstance(value, str_cls): if self._map is None: raise ValueError(unwrap( ''' %s value is a unicode string, but no _map provided ''', type_name(self) )) if value...
def set(self, value)
Sets the value of the object :param value: An integer, or a unicode string if _map is set :raises: ValueError - when an invalid value is passed
3.335223
3.064277
1.088421
if self.contents is None: return None if self._native is None: self._native = self.__int__() if self._map is not None and self._native in self._map: self._native = self._map[self._native] return self._native
def native(self)
The native Python datatype representation of this value :return: An integer or None
3.965048
3.343959
1.185734
ValueMap._setup(self) cls = self.__class__ if cls._map is not None: cls._size = max(self._map.keys()) + 1
def _setup(self)
Generates _reverse_map from _map
7.79111
5.954066
1.308536
if isinstance(value, set): if self._map is None: raise ValueError(unwrap( ''' %s._map has not been defined ''', type_name(self) )) bits = [0] * self._size ...
def set(self, value)
Sets the value of the object :param value: An integer or a tuple of integers 0 and 1 :raises: ValueError - when an invalid value is passed
2.877932
2.875462
1.000859
extra_bits = int_from_bytes(self.contents[0:1]) byte_len = len(self.contents[1:]) bit_string = '' if byte_len == 0 else '{0:b}'.format(int_from_bytes(self.contents[1:])) bit_len = len(bit_string) # Left-pad the bit string to a byte multiple to ensure we didn't ...
def _as_chunk(self)
Allows reconstructing indefinite length values :return: A tuple of integers
3.178406
3.091122
1.028237
# For BitString we default the value to be all zeros if self.contents is None: if self._map is None: self.set(()) else: self.set(set()) if self._native is None: bits = self._merge_chunks() if self._map: ...
def native(self)
The native Python datatype representation of this value :return: If a _map is set, a set of names, or if no _map is set, a tuple of integers 1 and 0. None if no value.
5.020844
4.015481
1.250372
super(OctetBitString, self)._copy(other, copy_func) self._bytes = other._bytes
def _copy(self, other, copy_func)
Copies the contents of another OctetBitString object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects
9.546224
4.479647
2.131021
extra_bits = int_from_bytes(self.contents[0:1]) bit_string = '{0:b}'.format(int_from_bytes(self.contents[1:])) # Ensure we have leading zeros since these chunks may be concatenated together mod_bit_len = len(bit_string) % 8 if mod_bit_len != 0: bit_string =...
def _as_chunk(self)
Allows reconstructing indefinite length values :return: A unicode string of bits - 1s and 0s
3.810591
3.571173
1.067042
if self.contents is None: return None if self._native is None: extra_bits = int_from_bytes(self.contents[0:1]) # Fast path if not self._indefinite and extra_bits == 0: self._native = int_from_bytes(self.contents[1:]) ...
def native(self)
The native Python datatype representation of this value :return: An integer or None
4.708457
4.522164
1.041195
if not isinstance(value, byte_cls): raise TypeError(unwrap( ''' %s value must be a byte string, not %s ''', type_name(self), type_name(value) )) self._bytes = value self.contents = ...
def set(self, value)
Sets the value of the object :param value: A byte string
4.624728
4.329711
1.068138
super(OctetString, self)._copy(other, copy_func) self._bytes = other._bytes
def _copy(self, other, copy_func)
Copies the contents of another OctetString object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects
7.490945
4.755952
1.575068
if not isinstance(value, int_types): raise TypeError(unwrap( ''' %s value must be an integer, not %s ''', type_name(self), type_name(value) )) self._native = value self.contents = i...
def set(self, value)
Sets the value of the object :param value: An integer :raises: ValueError - when an invalid value is passed
4.542552
4.671026
0.972496
if self.contents is None: return None if self._native is None: self._native = int_from_bytes(self._merge_chunks()) return self._native
def native(self)
The native Python datatype representation of this value :return: An integer or None
7.483261
6.340801
1.180176
if self._parsed is None or self._parsed[1:3] != (spec, spec_params): parsed_value, _ = _parse_build(self.__bytes__(), spec=spec, spec_params=spec_params) self._parsed = (parsed_value, spec, spec_params) return self._parsed[0]
def parse(self, spec=None, spec_params=None)
Parses the contents generically, or using a spec with optional params :param spec: A class derived from Asn1Value that defines what class_ and tag the value should have, and the semantics of the encoded value. The return value will be of this type. If omitted, the encoded va...
4.061496
3.9351
1.03212
super(ParsableOctetString, self)._copy(other, copy_func) self._bytes = other._bytes self._parsed = copy_func(other._parsed)
def _copy(self, other, copy_func)
Copies the contents of another ParsableOctetString object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects
5.853501
3.33601
1.754641
if self.contents is None: return None if self._parsed is not None: return self._parsed[0].native else: return self.__bytes__()
def native(self)
The native Python datatype representation of this value :return: A byte string or None
7.945441
6.403487
1.240799
if force: if self._parsed is not None: native = self.parsed.dump(force=force) else: native = self.native self.contents = None self.set(native) return Asn1Value.dump(self)
def dump(self, force=False)
Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value
7.642019
7.001025
1.091557
if cls._map is None: raise ValueError(unwrap( ''' %s._map has not been defined ''', type_name(cls) )) if not isinstance(value, str_cls): raise TypeError(unwrap( ''' ...
def map(cls, value)
Converts a dotted unicode string OID into a mapped unicode string :param value: A dotted unicode string OID :raises: ValueError - when no _map dict has been defined on the class TypeError - when value is not a unicode string :return: A mapped un...
3.437082
2.58042
1.331986
if cls not in _SETUP_CLASSES: cls()._setup() _SETUP_CLASSES[cls] = True if cls._map is None: raise ValueError(unwrap( ''' %s._map has not been defined ''', type_name(cls) )) ...
def unmap(cls, value)
Converts a mapped unicode string value into a dotted unicode string OID :param value: A mapped unicode string OR dotted unicode string OID :raises: ValueError - when no _map dict has been defined on the class or the value can't be unmapped TypeError - when value is ...
3.15812
2.821303
1.119384
if not isinstance(value, str_cls): raise TypeError(unwrap( ''' %s value must be a unicode string, not %s ''', type_name(self), type_name(value) )) self._native = value if self._map...
def set(self, value)
Sets the value of the object :param value: A unicode string. May be a dotted integer string, or if _map is provided, one of the mapped values. :raises: ValueError - when an invalid value is passed
3.547414
3.374133
1.051356
if self._dotted is None: output = [] part = 0 for byte in self.contents: if _PY2: byte = ord(byte) part = part * 128 part += byte & 127 # Last byte in subidentifier has the eighth b...
def dotted(self)
:return: A unicode string of the object identifier in dotted notation, thus ignoring any mapped value
3.966115
3.516962
1.127711
if self.contents is None: return None if self._native is None: self._native = self.dotted if self._map is not None and self._native in self._map: self._native = self._map[self._native] return self._native
def native(self)
The native Python datatype representation of this value :return: A unicode string or None. If _map is not defined, the unicode string is a string of dotted integers. If _map is defined and the dotted string is present in the _map, the mapped value is returned.
4.238715
3.029523
1.399136
if not isinstance(value, int_types) and not isinstance(value, str_cls): raise TypeError(unwrap( ''' %s value must be an integer or a unicode string, not %s ''', type_name(self), type_name(value) )) ...
def set(self, value)
Sets the value of the object :param value: An integer or a unicode string from _map :raises: ValueError - when an invalid value is passed
2.29057
2.181014
1.050232
if self.contents is None: return None if self._native is None: self._native = self._map[self.__int__()] return self._native
def native(self)
The native Python datatype representation of this value :return: A unicode string or None
7.520761
6.090786
1.234777
if self.children is None: return self._contents if self._is_mutated(): self._set_contents() return self._contents
def contents(self)
:return: A byte string of the DER-encoded contents of the sequence
7.375335
6.775738
1.088492
mutated = self._mutated if self.children is not None: for child in self.children: if isinstance(child, Sequence) or isinstance(child, SequenceOf): mutated = mutated or child._is_mutated() return mutated
def _is_mutated(self)
:return: A boolean - if the sequence or any children (recursively) have been mutated
3.662448
3.12322
1.172651
child = self.children[index] if child.__class__ == tuple: child = self.children[index] = _build(*child) return child
def _lazy_child(self, index)
Builds a child object if the child has only been parsed into a tuple so far
5.275812
3.733817
1.412981
if self.children is None: self._parse_children() contents = BytesIO() for index, info in enumerate(self._fields): child = self.children[index] if child is None: child_dump = b'' elif child.__class__ == tuple: ...
def _set_contents(self, force=False)
Updates the .contents attribute of the value with the encoded value of all of the child objects :param force: Ensure all contents are in DER format instead of possibly using cached BER-encoded data
3.735253
3.637809
1.026786
cls = self.__class__ cls._field_map = {} cls._field_ids = [] cls._precomputed_specs = [] for index, field in enumerate(cls._fields): if len(field) < 3: field = field + ({},) cls._fields[index] = field cls._field_ma...
def _setup(self)
Generates _field_map, _field_ids and _oid_nums for use in parsing
2.913681
2.565665
1.135644
name, field_spec, field_params = self._fields[index] value_spec = field_spec spec_override = None if self._spec_callbacks is not None and name in self._spec_callbacks: callback = self._spec_callbacks[name] spec_override = callback(self) if s...
def _determine_spec(self, index)
Determine how a value for a field should be constructed :param index: The field number :return: A tuple containing the following elements: - unicode string of the field name - Asn1Value class of the field spec - Asn1Value class of the valu...
3.726591
3.275924
1.137569
if value is None and 'optional' in field_params: return VOID specs_different = field_spec != value_spec is_any = issubclass(field_spec, Any) if issubclass(value_spec, Choice): is_asn1value = isinstance(value, Asn1Value) is_tuple = isinstanc...
def _make_value(self, field_name, field_spec, value_spec, field_params, value)
Contructs an appropriate Asn1Value object for a field :param field_name: A unicode string of the field name :param field_spec: An Asn1Value class that is the field spec :param value_spec: An Asn1Value class that is the vaue spec :param field_params...
2.973685
2.930776
1.014641
if not isinstance(field_name, str_cls): raise TypeError(unwrap( ''' field_name must be a unicode string, not %s ''', type_name(field_name) )) if self._fields is None: raise ValueError(unwrap( ...
def spec(self, field_name)
Determines the spec to use for the field specified. Depending on how the spec is determined (_oid_pair or _spec_callbacks), it may be necessary to set preceding field values before calling this. Usually specs, if dynamic, are controlled by a preceding ObjectIdentifier field. :pa...
3.43625
3.317993
1.035641
if self.contents is None: return None if self._native is None: if self.children is None: self._parse_children(recurse=True) try: self._native = OrderedDict() for index, child in enumerate(self.children): ...
def native(self)
The native Python datatype representation of this value :return: An OrderedDict or None. If an OrderedDict, all child values are recursively converted to native representation also.
3.795248
3.588954
1.05748
super(Sequence, self)._copy(other, copy_func) if self.children is not None: self.children = [] for child in other.children: if child.__class__ == tuple: self.children.append(child) else: self.childr...
def _copy(self, other, copy_func)
Copies the contents of another Sequence object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects
3.043188
3.101306
0.98126
if self.children is None: self._parse_children() prefix = ' ' * nest_level _basic_debug(prefix, self) for field_name in self: child = self._lazy_child(self._field_map[field_name]) if child is not VOID: print('%s Field "%s...
def debug(self, nest_level=1)
Show the binary data and parsed data in a tree structure
5.769238
5.798856
0.994892
if force: self._set_contents(force=force) if self._fields and self.children is not None: for index, (field_name, _, params) in enumerate(self._fields): if self.children[index] is not VOID: continue if 'default' in par...
def dump(self, force=False)
Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value
6.898635
6.239398
1.105657
if isinstance(value, self._child_spec): new_value = value elif issubclass(self._child_spec, Any): if isinstance(value, Asn1Value): new_value = value else: raise ValueError(unwrap( ''' C...
def _make_value(self, value)
Constructs a _child_spec value from a native Python data type, or an appropriate Asn1Value object :param value: A native Python value, or some child of Asn1Value :return: An object of type _child_spec
3.033626
2.776863
1.092465
# We inline this checks to prevent method invocation each time if self.children is None: self._parse_children() self.children.append(self._make_value(value)) if self._native is not None: self._native.append(self.children[-1].native) self._muta...
def append(self, value)
Allows adding a child to the end of the sequence :param value: Native python datatype that will be passed to _child_spec to create new child object
9.20348
8.88241
1.036147
if self.children is None: self._parse_children() contents = BytesIO() for child in self: contents.write(child.dump(force=force)) self._contents = contents.getvalue() self._header = None if self._trailer != b'': self._trailer ...
def _set_contents(self, force=False)
Encodes all child objects into the contents for this object :param force: Ensure all contents are in DER format instead of possibly using cached BER-encoded data
4.478815
4.055387
1.104411
try: self.children = [] if self._contents is None: return contents_length = len(self._contents) child_pointer = 0 while child_pointer < contents_length: parts, child_pointer = _parse(self._contents, contents_le...
def _parse_children(self, recurse=False)
Parses the contents and generates Asn1Value objects based on the definitions from _child_spec. :param recurse: If child objects that are Sequence or SequenceOf objects should be recursively parsed :raises: ValueError - when an error occurs parsing child obje...
3.422292
3.040405
1.125604
if self.contents is None: return None if self._native is None: if self.children is None: self._parse_children(recurse=True) try: self._native = [child.native for child in self] except (ValueError, TypeError) as e:...
def native(self)
The native Python datatype representation of this value :return: A list or None. If a list, all child values are recursively converted to native representation also.
4.14322
3.7794
1.096264
if self.children is None: self._parse_children() prefix = ' ' * nest_level _basic_debug(prefix, self) for child in self: child.debug(nest_level + 1)
def debug(self, nest_level=1)
Show the binary data and parsed data in a tree structure
5.070299
4.943918
1.025563
if force: self._set_contents(force=force) return Asn1Value.dump(self)
def dump(self, force=False)
Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value
13.328537
10.83566
1.230062
cls = self.__class__ if self._contents is None: if self._fields: self.children = [VOID] * len(self._fields) for index, (_, _, params) in enumerate(self._fields): if 'default' in params: if cls._precomputed_...
def _parse_children(self, recurse=False)
Parses the contents and generates Asn1Value objects based on the definitions from _fields. :param recurse: If child objects that are Sequence or SequenceOf objects should be recursively parsed :raises: ValueError - when an error occurs parsing child objects
2.796246
2.736456
1.021849
if self.children is None: self._parse_children() child_tag_encodings = [] for index, child in enumerate(self.children): child_encoding = child.dump(force=force) # Skip encoding defaulted children name, spec, field_params = self._fields[...
def _set_contents(self, force=False)
Encodes all child objects into the contents for this object. This method is overridden because a Set needs to be encoded by removing defaulted fields and then sorting the fields by tag. :param force: Ensure all contents are in DER format instead of possibly using cached...
4.329433
3.817703
1.134042
if self.children is None: self._parse_children() child_encodings = [] for child in self: child_encodings.append(child.dump(force=force)) self._contents = b''.join(sorted(child_encodings)) self._header = None if self._trailer != b'': ...
def _set_contents(self, force=False)
Encodes all child objects into the contents for this object. This method is overridden because a SetOf needs to be encoded by sorting the child encodings. :param force: Ensure all contents are in DER format instead of possibly using cached BER-encoded data
4.593885
3.992104
1.150743
if self.contents is None: return None if self._native is None: string = str_cls(self) has_timezone = re.search('[-\\+]', string) # We don't know what timezone it is in, or it is UTC because of a Z # suffix, so we just assume UTC ...
def native(self)
The native Python datatype representation of this value :return: A datetime.datetime object in the UTC timezone or None
4.134492
3.823604
1.081308
if isinstance(value, datetime): value = value.strftime('%y%m%d%H%M%SZ') if _PY2: value = value.decode('ascii') AbstractString.set(self, value) # Set it to None and let the class take care of converting the next # time that .native is cal...
def set(self, value)
Sets the value of the object :param value: A unicode string or a datetime.datetime object :raises: ValueError - when an invalid value is passed
8.346081
8.129295
1.026667
strlen = len(string) year_num = int(string[0:2]) if year_num < 50: prefix = '20' else: prefix = '19' if strlen == 10: return datetime.strptime(prefix + string, '%Y%m%d%H%M') if strlen == 12: return datetime.strp...
def _date_by_len(self, string)
Parses a date from a string based on its length :param string: A unicode string to parse :return: A datetime.datetime object or a unicode string
2.418535
2.366999
1.021773
strlen = len(string) date_format = None if strlen == 10: date_format = '%Y%m%d%H' elif strlen == 12: date_format = '%Y%m%d%H%M' elif strlen == 14: date_format = '%Y%m%d%H%M%S' elif strlen == 18: date_format = '%Y%...
def _date_by_len(self, string)
Parses a date from a string based on its length :param string: A unicode string to parse :return: A datetime.datetime object, asn1crypto.util.extended_datetime object or a unicode string
2.445741
2.284513
1.070574
super(CertificateChoices, self).validate(class_, tag, contents) if self._choice == 2: if AttCertVersion.load(Sequence.load(contents)[0].dump()).native == 'v2': self._choice = 3
def validate(self, class_, tag, contents)
Ensures that the class and tag specified exist as an alternative. This custom version fixes parsing broken encodings there a V2 attribute # certificate is encoded as a V1 :param class_: The integer class_ from the encoded value header :param tag: The integer tag...
11.310297
11.169267
1.012627
if inspect.isclass(value): cls = value else: cls = value.__class__ if cls.__module__ in set(['builtins', '__builtin__']): return cls.__name__ return '%s.%s' % (cls.__module__, cls.__name__)
def type_name(value)
Returns a user-readable name for the type of an object :param value: A value to get the type name of :return: A unicode string of the object's type name
2.727213
2.681622
1.017001
while len(bytes_) < width: bytes_ = b'\x00' + bytes_ return bytes_
def fill_width(bytes_, width)
Ensure a byte string representing a positive integer is a specific width (in bytes) :param bytes_: The integer byte string :param width: The desired width as an integer :return: A byte string of the width specified
3.170955
3.935508
0.805729
if not isinstance(class_, int): raise TypeError('class_ must be an integer, not %s' % type_name(class_)) if class_ < 0 or class_ > 3: raise ValueError('class_ must be one of 0, 1, 2 or 3, not %s' % class_) if not isinstance(method, int): raise TypeError('method must be an int...
def emit(class_, method, tag, contents)
Constructs a byte string of an ASN.1 DER-encoded value This is typically not useful. Instead, use one of the standard classes from asn1crypto.core, or construct a new class with specific fields, and call the .dump() method. :param class_: An integer ASN.1 class value: 0 (universal), 1 (applica...
1.658932
1.471054
1.127717
if not isinstance(contents, byte_cls): raise TypeError('contents must be a byte string, not %s' % type_name(contents)) contents_len = len(contents) info, consumed = _parse(contents, contents_len) if strict and consumed != contents_len: raise ValueError('Extra data - %d bytes of tr...
def parse(contents, strict=False)
Parses a byte string of ASN.1 BER/DER-encoded data. This is typically not useful. Instead, use one of the standard classes from asn1crypto.core, or construct a new class with specific fields, and call the .load() class method. :param contents: A byte string of BER/DER-encoded data :param ...
4.134
3.875047
1.066826
if not isinstance(contents, byte_cls): raise TypeError('contents must be a byte string, not %s' % type_name(contents)) info, consumed = _parse(contents, len(contents)) return consumed
def peek(contents)
Parses a byte string of ASN.1 BER/DER-encoded data to find the length This is typically used to look into an encoded value to see how long the next chunk of ASN.1-encoded data is. Primarily it is useful when a value is a concatenation of multiple values. :param contents: A byte string of BER/D...
6.308819
5.883173
1.07235
if data_len < pointer + 2: raise ValueError(_INSUFFICIENT_DATA_MESSAGE % (2, data_len - pointer)) start = pointer first_octet = ord(encoded_data[pointer]) if _PY2 else encoded_data[pointer] pointer += 1 tag = first_octet & 31 # Base 128 length using 8th bit as continuation indica...
def _parse(encoded_data, data_len, pointer=0, lengths_only=False)
Parses a byte string into component parts :param encoded_data: A byte string that contains BER-encoded data :param data_len: The integer length of the encoded data :param pointer: The index in the byte string to parse from :param lengths_only: A boolean to cause the c...
2.849576
2.759071
1.032803
header = b'' id_num = 0 id_num |= class_ << 6 id_num |= method << 5 if tag >= 31: header += chr_cls(id_num | 31) while tag > 0: continuation_bit = 0x80 if tag > 0x7F else 0 header += chr_cls(continuation_bit | (tag & 0x7F)) tag = tag >> 7 ...
def _dump_header(class_, method, tag, contents)
Constructs the header bytes for an ASN.1 object :param class_: An integer ASN.1 class value: 0 (universal), 1 (application), 2 (context), 3 (private) :param method: An integer ASN.1 method value: 0 (primitive), 1 (constructed) :param tag: An integer ASN.1 tag value :p...
2.699469
2.397816
1.125803
if not isinstance(value, str_cls): raise TypeError(unwrap( ''' value must be a unicode string, not %s ''', type_name(value) )) scheme = None # Python 2.6 doesn't split properly is the URL doesn't start with http:// or https:// if sys...
def iri_to_uri(value, normalize=False)
Encodes a unicode IRI into an ASCII byte string URI :param value: A unicode string of an IRI :param normalize: A bool that controls URI normalization :return: A byte string of the ASCII-encoded URI
2.38949
2.414543
0.989624
if not isinstance(value, byte_cls): raise TypeError(unwrap( ''' value must be a byte string, not %s ''', type_name(value) )) parsed = urlsplit(value) scheme = parsed.scheme if scheme is not None: scheme = scheme.decode('asci...
def uri_to_iri(value)
Converts an ASCII URI byte string into a unicode IRI :param value: An ASCII-encoded byte string of the URI :return: A unicode string of the IRI
2.275174
2.20262
1.03294
bytes_as_ints = bytes_to_list(exc.object[exc.start:exc.end]) replacements = ['%%%02x' % num for num in bytes_as_ints] return (''.join(replacements), exc.end)
def _iri_utf8_errors_handler(exc)
Error handler for decoding UTF-8 parts of a URI into an IRI. Leaves byte sequences encoded in %XX format, but as part of a unicode string. :param exc: The UnicodeDecodeError exception :return: A 2-element tuple of (replacement unicode string, integer index to resume at)
6.358415
4.273042
1.48803
if string is None or string == '': return None # Anything already hex quoted is pulled out of the URL and unquoted if # possible escapes = [] if re.search('%[0-9a-fA-F]{2}', string): # Try to unquote any percent values, restoring them if they are not # valid UTF-8. Als...
def _urlquote(string, safe='')
Quotes a unicode string for use in a URL :param string: A unicode string :param safe: A unicode string of character to not encode :return: None (if string is None) or an ASCII byte string of the quoted string
4.065702
3.966405
1.025035
if byte_string is None: return byte_string if byte_string == b'': return '' if preserve: replacements = ['\x1A', '\x1C', '\x1D', '\x1E', '\x1F'] preserve_unmap = {} for char in remap: replacement = replacements.pop(0) preserve_unmap[rep...
def _urlunquote(byte_string, remap=None, preserve=None)
Unquotes a URI portion from a byte string into unicode using UTF-8 :param byte_string: A byte string of the data to unquote :param remap: A list of characters (as unicode) that should be re-mapped to a %XX encoding. This is used when characters are not valid in part of a URL. ...
2.497441
2.398616
1.041201
if name != 'teletex': return None return codecs.CodecInfo( name='teletex', encode=TeletexCodec().encode, decode=TeletexCodec().decode, incrementalencoder=TeletexIncrementalEncoder, incrementaldecoder=TeletexIncrementalDecoder, streamreader=TeletexSt...
def teletex_search_function(name)
Search function for teletex codec that is passed to codecs.register()
1.988684
1.75818
1.131104
parser = argparse.ArgumentParser( description='draw basic graphs on terminal') parser.add_argument( 'filename', nargs='?', default="-", help='data file name (comma or space separated). Defaults to stdin.') parser.add_argument( '--title', help='Tit...
def init_args()
Parse and return the arguments.
2.732783
2.713027
1.007282
args = init_args() if args['version']: print('termgraph v{}'.format(VERSION)) sys.exit() _, labels, data, colors = read_data(args) if args['calendar']: calendar_heatmap(data, labels, args) else: chart(colors, data, args, labels)
def main()
Main function.
6.476211
6.362117
1.017933
length = 0 for i in range(len(labels)): if len(labels[i]) > length: length = len(labels[i]) return length
def find_max_label_length(labels)
Return the maximum length for the labels.
2.099309
1.86087
1.128133
min_dat = find_min(data) # We offset by the minimum if there's a negative. off_data = [] if min_dat < 0: min_dat = abs(min_dat) for dat in data: off_data.append([_d + min_dat for _d in dat]) else: off_data = data min_dat = find_min(off_data) max_dat =...
def normalize(data, width)
Normalize the data and return it.
4.483782
4.511772
0.993796
val_min = find_min(data) for i in range(len(labels)): if args['no_labels']: # Hide the labels. label = '' else: label = "{:<{x}}: ".format(labels[i], x=find_max_label_length(labels)) values = data[i] ...
def horiz_rows(labels, data, normal_dat, args, colors)
Prepare the horizontal graph. Each row is printed through the print_row function.
5.249706
5.238721
1.002097
if color: sys.stdout.write(f'\033[{color}m') # Start to write colorized. if num_blocks < 1 and (value > val_min or value > 0): # Print something if it's not the smallest # and the normal value is less than one. sys.stdout.write(SM_TICK) else: for _ in range(num_...
def print_row(value, num_blocks, val_min, color)
A method to print a row for a horizontal graphs. i.e: 1: ▇▇ 2 2: ▇▇▇ 3 3: ▇▇▇▇ 4
4.797872
5.303768
0.904616
val_min = find_min(data) for i in range(len(labels)): if args['no_labels']: # Hide the labels. label = '' else: label = "{:<{x}}: ".format(labels[i], x=find_max_label_length(labels)) print(label, end="") ...
def stacked_graph(labels, data, normal_data, len_categories, args, colors)
Prepare the horizontal stacked graph. Each row is printed through the print_row function.
4.839279
4.577848
1.057108
global maxi, value_list value_list.append(str(value)) # In case the number of blocks at the end of the normalization is less # than the default number, use the maxi variable to escape. if maxi < num_blocks: maxi = num_blocks if num_blocks > 0: vertical_list.append((TICK *...
def vertically(value, num_blocks, val_min, color, args)
Prepare the vertical graph. The whole graph is printed through the print_vertical function.
6.855279
6.885273
0.995644
if color: sys.stdout.write(f'\033[{color}m') # Start to write colorized. for row in vertical_rows: print(*row) sys.stdout.write('\033[0m') # End of printing colored print("-" * len(row) + "Values" + "-" * len(row)) # Print Values for value in zip_longest(*value_list, fill...
def print_vertical(vertical_rows, labels, color, args)
Print the whole vertical graph.
3.519219
3.449762
1.020134
len_categories = len(data[0]) if len_categories > 1: # Stacked graph if args['stacked']: normal_dat = normalize(data, args['width']) stacked_graph(labels, data, normal_dat, len_categories, args, colors) return if not col...
def chart(colors, data, args, labels)
Handle the normalization of data and the printing of the graph.
3.871169
3.742415
1.034404
len_categories = len(data[0]) # Check that there are data for all labels. if len(labels) != len(data): print(">> Error: Label and data array sizes don't match") sys.exit(1) # Check that there are data for all categories per label. for dat in data: if len(dat) != len_ca...
def check_data(labels, data, args)
Check that all data were inserted correctly. Return the colors.
3.74248
3.540979
1.056905
for i in range(len(categories)): if colors: sys.stdout.write(f'\033[{colors[i]}m') # Start to write colorized. sys.stdout.write(TICK + ' ' + categories[i] + ' ') if colors: sys.stdout.write('\033[0m') # Back to original. print('\n\n')
def print_categories(categories, colors)
Print a tick and the category's name for each category above the graph.
4.148755
4.158222
0.997723
filename = args['filename'] stdin = filename == '-' if args['verbose']: print(f'>> Reading data from {( "stdin" if stdin else filename )}') print('') if args['title']: print('# ' + args['title'] + '\n') categories, labels, data, colors = ([] for i in range(4)) f = sy...
def read_data(args)
Read data from a file or stdin and returns it. Filename includes (categories), labels and data. We append categories and labels to lists. Data are inserted to a list of lists due to the categories. i.e. labels = ['2001', '2002', '2003', ...] categories = ['boys', 'girls'] ...
3.653851
3.512559
1.040225
if args['color']: colornum = AVAILABLE_COLORS.get(args['color'][0]) else: colornum = AVAILABLE_COLORS.get('blue') dt_dict = {} for i in range(len(labels)): dt_dict[labels[i]] = data[i][0] # get max value max_val = float(max(data)[0]) tick_1 = "░" tick_2 = ...
def calendar_heatmap(data, labels, args)
Print a calendar heatmap.
2.760209
2.743207
1.006198
'Returns a (uid, gid, pid) tuple' ctxp = _libfuse.fuse_get_context() ctx = ctxp.contents return ctx.uid, ctx.gid, ctx.pid
def fuse_get_context()
Returns a (uid, gid, pid) tuple
7.326336
5.05
1.45076
''' This will shutdown the FUSE mount and cause the call to FUSE(...) to return, similar to sending SIGINT to the process. Flags the native FUSE session as terminated and will cause any running FUSE event loops to exit on the next opportunity. (see fuse.c::fuse_exit) ''' fuse_ptr = ctypes.c...
def fuse_exit()
This will shutdown the FUSE mount and cause the call to FUSE(...) to return, similar to sending SIGINT to the process. Flags the native FUSE session as terminated and will cause any running FUSE event loops to exit on the next opportunity. (see fuse.c::fuse_exit)
10.443046
2.046892
5.101904
'Decorator for the methods that follow' try: if func.__name__ == "init": # init may not fail, as its return code is just stored as # private_data field of struct fuse_context return func(*args, **kwargs) or 0 else: ...
def _wrapper(func, *args, **kwargs)
Decorator for the methods that follow
4.80938
4.572
1.05192
'creates a symlink `target -> source` (e.g. ln -s source target)' return self.operations('symlink', target.decode(self.encoding), source.decode(self.encoding))
def symlink(self, source, target)
creates a symlink `target -> source` (e.g. ln -s source target)
11.505744
6.742435
1.706467
'creates a hard link `target -> source` (e.g. ln source target)' return self.operations('link', target.decode(self.encoding), source.decode(self.encoding))
def link(self, source, target)
creates a hard link `target -> source` (e.g. ln source target)
14.637341
6.752306
2.167754
''' Returns a dictionary with keys identical to the stat C structure of stat(2). st_atime, st_mtime and st_ctime should be floats. NOTE: There is an incompatibility between Linux and Mac OS X concerning st_nlink of directories. Mac OS X counts all files inside t...
def getattr(self, path, fh=None)
Returns a dictionary with keys identical to the stat C structure of stat(2). st_atime, st_mtime and st_ctime should be floats. NOTE: There is an incompatibility between Linux and Mac OS X concerning st_nlink of directories. Mac OS X counts all files inside the directory, while ...
6.130605
1.689602
3.628433
self.reply_err(req, errno.ENOENT)
def lookup(self, req, parent, name)
Look up a directory entry by name and get its attributes. Valid replies: reply_entry reply_err
16.739452
12.012486
1.393504
if ino == 1: attr = {'st_ino': 1, 'st_mode': S_IFDIR | 0o755, 'st_nlink': 2} self.reply_attr(req, attr, 1.0) else: self.reply_err(req, errno.ENOENT)
def getattr(self, req, ino, fi)
Get file attributes Valid replies: reply_attr reply_err
3.147633
3.012395
1.044894
self.reply_err(req, errno.EROFS)
def setattr(self, req, ino, attr, to_set, fi)
Set file attributes Valid replies: reply_attr reply_err
12.274911
10.180473
1.205731
self.reply_err(req, errno.EROFS)
def mknod(self, req, parent, name, mode, rdev)
Create file node Valid replies: reply_entry reply_err
10.541024
13.177213
0.799943