desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'For API-compatibility with RepositoryProvider'
| def get_broken_dependencies(self):
| return {}.items()
|
'For API-compatibility with RepositoryProvider'
| def get_dependencies(self):
| return {}.items()
|
'Uses the GitHub API to construct necessary info for all packages
:param invalid_sources:
A list of URLs that should be ignored
:raises:
DownloaderException: when there is an issue download package info
ClientException: when there is an issue parsing package info
:return:
A generator of
\'Package Name\',
\'name\': name... | def get_packages(self, invalid_sources=None):
| if ('get_packages' in self.cache):
for (key, value) in self.cache['get_packages'].items():
(yield (key, value))
return
client = GitHubClient(self.settings)
if ((invalid_sources is not None) and (self.repo in invalid_sources)):
raise StopIteration()
try:
user_r... |
'Return a list of current URLs that are directly referenced by the repo
:return:
A list of URLs'
| def get_sources(self):
| return [self.repo]
|
'For API-compatibility with RepositoryProvider'
| def get_renamed_packages(self):
| return {}
|
'Indicates if this provider can handle the provided repo'
| @classmethod
def match_url(cls, repo):
| return True
|
'Go out and perform HTTP operations, caching the result
:raises:
DownloaderException: when there is an issue download package info
ClientException: when there is an issue parsing package info'
| def prefetch(self):
| [name for (name, info) in self.get_packages()]
|
'List of any URLs that could not be accessed while accessing this repository
:return:
A generator of ("https://example.com", Exception()) tuples'
| def get_failed_sources(self):
| return self.failed_sources.items()
|
'List of package names for packages that are missing information
:return:
A generator of ("Package Name", Exception()) tuples'
| def get_broken_packages(self):
| return self.broken_packages.items()
|
'List of dependency names for dependencies that are missing information
:return:
A generator of ("Dependency Name", Exception()) tuples'
| def get_broken_dependencies(self):
| return self.broken_dependencies.items()
|
'Retrieves and loads the JSON for other methods to use
:raises:
ProviderException: when an error occurs trying to open a file
DownloaderException: when an error occurs trying to open a URL'
| def fetch(self):
| if (self.repo_info is not None):
return
self.repo_info = self.fetch_location(self.repo)
for key in ['packages', 'dependencies']:
if (key not in self.repo_info):
self.repo_info[key] = []
if ('includes' not in self.repo_info):
return
if (re.match('https?://', self.r... |
'Fetch the repository and validates that it is parse-able
:return:
Boolean if the repo was fetched and validated'
| def fetch_and_validate(self):
| if (self.repo in self.failed_sources):
return False
if (self.repo_info is not None):
return True
try:
self.fetch()
except (DownloaderException, ProviderException) as e:
self.failed_sources[self.repo] = e
self.cache['get_packages'] = {}
return False
def... |
'Fetches the contents of a URL of file path
:param location:
The URL or file path
:raises:
ProviderException: when an error occurs trying to open a file
DownloaderException: when an error occurs trying to open a URL
:return:
A dict of the parsed JSON'
| def fetch_location(self, location):
| if re.match('https?://', self.repo, re.I):
with downloader(location, self.settings) as manager:
json_string = manager.fetch(location, 'Error downloading repository.')
else:
if (not os.path.exists(location)):
raise ProviderException((u'Error, file %s does ... |
'Provides access to the dependencies in this repository
:param invalid_sources:
A list of URLs that are permissible to fetch data from
:raises:
ProviderException: when an error occurs trying to open a file
DownloaderException: when there is an issue download package info
ClientException: when there is an issue parsing ... | def get_dependencies(self, invalid_sources=None):
| if ('get_dependencies' in self.cache):
for (key, value) in self.cache['get_dependencies'].items():
(yield (key, value))
return
if ((invalid_sources is not None) and (self.repo in invalid_sources)):
raise StopIteration()
if (not self.fetch_and_validate()):
return
... |
'Provides access to the packages in this repository
:param invalid_sources:
A list of URLs that are permissible to fetch data from
:raises:
ProviderException: when an error occurs trying to open a file
DownloaderException: when there is an issue download package info
ClientException: when there is an issue parsing pack... | def get_packages(self, invalid_sources=None):
| if ('get_packages' in self.cache):
for (key, value) in self.cache['get_packages'].items():
(yield (key, value))
return
if ((invalid_sources is not None) and (self.repo in invalid_sources)):
raise StopIteration()
if (not self.fetch_and_validate()):
return
debug... |
'Return a list of current URLs that are directly referenced by the repo
:return:
A list of URLs and/or file paths'
| def get_sources(self):
| if (not self.fetch_and_validate()):
return []
output = [self.repo]
if (self.schema_major_version >= 2):
for package in self.repo_info['packages']:
details = package.get('details')
if details:
output.append(details)
return output
|
':return: A dict of the packages that have been renamed'
| def get_renamed_packages(self):
| if (not self.fetch_and_validate()):
return {}
if (self.schema_major_version < 2):
return self.repo_info.get('renamed_packages', {})
output = {}
for package in self.repo_info['packages']:
if ('previous_names' not in package):
continue
previous_names = package['... |
'Indicates if this provider can handle the provided channel'
| @classmethod
def match_url(cls, channel):
| return True
|
'Go out and perform HTTP operations, caching the result
:raises:
ProviderException: when an error occurs trying to open a file
DownloaderException: when an error occurs trying to open a URL'
| def prefetch(self):
| self.fetch()
|
'Retrieves and loads the JSON for other methods to use
:raises:
ProviderException: when an error occurs with the channel contents
DownloaderException: when an error occurs trying to open a URL'
| def fetch(self):
| if (self.channel_info is not None):
return
if re.match('https?://', self.channel, re.I):
with downloader(self.channel, self.settings) as manager:
channel_json = manager.fetch(self.channel, 'Error downloading channel.')
else:
if (not os.path.exists(self.channel)):
... |
':raises:
ProviderException: when an error occurs with the channel contents
DownloaderException: when an error occurs trying to open a URL
:return:
A dict of the mapping for URL slug -> package name'
| def get_name_map(self):
| self.fetch()
if (self.schema_major_version >= 2):
return {}
return self.channel_info.get('package_name_map', {})
|
':raises:
ProviderException: when an error occurs with the channel contents
DownloaderException: when an error occurs trying to open a URL
:return:
A dict of the packages that have been renamed'
| def get_renamed_packages(self):
| self.fetch()
if (self.schema_major_version >= 2):
output = {}
if ('packages_cache' in self.channel_info):
for repo in self.channel_info['packages_cache']:
for package in self.channel_info['packages_cache'][repo]:
previous_names = package.get('previ... |
':raises:
ProviderException: when an error occurs with the channel contents
DownloaderException: when an error occurs trying to open a URL
:return:
A list of the repository URLs'
| def get_repositories(self):
| self.fetch()
if ('repositories' not in self.channel_info):
raise ProviderException(text.format(u'\n Channel %s does not appear to be a valid channel file because\n ... |
'Return a list of current URLs that are directly referenced by the
channel
:return:
A list of URLs and/or file paths'
| def get_sources(self):
| return self.get_repositories()
|
'Provides access to the repository info that is cached in a channel
:param repo:
The URL of the repository to get the cached info of
:raises:
ProviderException: when an error occurs with the channel contents
DownloaderException: when an error occurs trying to open a URL
:return:
A dict in the format:
\'Package Name\': ... | def get_packages(self, repo):
| self.fetch()
repo = update_url(repo, self.settings.get('debug'))
packages_key = ('packages_cache' if (self.schema_major_version >= 2) else 'packages')
if (self.channel_info.get(packages_key, False) is False):
return {}
if (self.channel_info[packages_key].get(repo, False) is False):
r... |
'Provides access to the dependency info that is cached in a channel
:param repo:
The URL of the repository to get the cached info of
:raises:
ProviderException: when an error occurs with the channel contents
DownloaderException: when an error occurs trying to open a URL
:return:
A dict in the format:
\'Dependency Name\... | def get_dependencies(self, repo):
| self.fetch()
repo = update_url(repo, self.settings.get('debug'))
if (self.channel_info.get('dependencies_cache', False) is False):
return {}
if (self.channel_info['dependencies_cache'].get(repo, False) is False):
return {}
output = {}
for dependency in self.channel_info['dependen... |
'Indicates if this provider can handle the provided repo'
| @classmethod
def match_url(cls, repo):
| master = re.search('^https?://github.com/[^/]+/[^/]+/?$', repo)
branch = re.search('^https?://github.com/[^/]+/[^/]+/tree/[^/]+/?$', repo)
return ((master is not None) or (branch is not None))
|
'Go out and perform HTTP operations, caching the result
:raises:
DownloaderException: when there is an issue download package info
ClientException: when there is an issue parsing package info'
| def prefetch(self):
| [name for (name, info) in self.get_packages()]
|
'List of any URLs that could not be accessed while accessing this repository
:return:
A generator of ("https://github.com/user/repo", Exception()) tuples'
| def get_failed_sources(self):
| return self.failed_sources.items()
|
'For API-compatibility with RepositoryProvider'
| def get_broken_packages(self):
| return {}.items()
|
'For API-compatibility with RepositoryProvider'
| def get_broken_dependencies(self):
| return {}.items()
|
'For API-compatibility with RepositoryProvider'
| def get_dependencies(self):
| return {}.items()
|
'Uses the GitHub API to construct necessary info for a package
:param invalid_sources:
A list of URLs that should be ignored
:raises:
DownloaderException: when there is an issue download package info
ClientException: when there is an issue parsing package info
:return:
A generator of
\'Package Name\',
\'name\': name,
\... | def get_packages(self, invalid_sources=None):
| if ('get_packages' in self.cache):
for (key, value) in self.cache['get_packages'].items():
(yield (key, value))
return
client = GitHubClient(self.settings)
if ((invalid_sources is not None) and (self.repo in invalid_sources)):
raise StopIteration()
try:
repo_i... |
'Return a list of current URLs that are directly referenced by the repo
:return:
A list of URLs'
| def get_sources(self):
| return [self.repo]
|
'For API-compatibility with RepositoryProvider'
| def get_renamed_packages(self):
| return {}
|
'Indicates if this provider can handle the provided repo'
| @classmethod
def match_url(cls, repo):
| return (re.search('^https?://bitbucket.org/([^/]+/[^/]+)/?$', repo) is not None)
|
'Go out and perform HTTP operations, caching the result
:raises:
DownloaderException: when there is an issue download package info
ClientException: when there is an issue parsing package info'
| def prefetch(self):
| [name for (name, info) in self.get_packages()]
|
'List of any URLs that could not be accessed while accessing this repository
:return:
A generator of ("https://bitbucket.org/user/repo", Exception()) tuples'
| def get_failed_sources(self):
| return self.failed_sources.items()
|
'For API-compatibility with RepositoryProvider'
| def get_broken_packages(self):
| return {}.items()
|
'For API-compatibility with RepositoryProvider'
| def get_broken_dependencies(self):
| return {}.items()
|
'For API-compatibility with RepositoryProvider'
| def get_dependencies(self):
| return {}.items()
|
'Uses the BitBucket API to construct necessary info for a package
:param invalid_sources:
A list of URLs that should be ignored
:raises:
DownloaderException: when there is an issue download package info
ClientException: when there is an issue parsing package info
:return:
A generator of
\'Package Name\',
\'name\': name... | def get_packages(self, invalid_sources=None):
| if ('get_packages' in self.cache):
for (key, value) in self.cache['get_packages'].items():
(yield (key, value))
return
client = BitBucketClient(self.settings)
if ((invalid_sources is not None) and (self.repo in invalid_sources)):
raise StopIteration()
try:
rep... |
'Return a list of current URLs that are directly referenced by the repo
:return:
A list of URLs'
| def get_sources(self):
| return [self.repo]
|
'For API-compatibility with RepositoryProvider'
| def get_renamed_packages(self):
| return {}
|
'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 exists
:return:
An instance of the current class'
| @classmethod
def load(cls, encoded_data, strict=False, **kwargs):
| if (not isinstance(encoded_data, byte_cls)):
raise TypeError((u'encoded_data must be a byte string, not %s' % type_name(encoded_data)))
spec = None
if (cls.tag is not None):
spec = cls
(value, _) = _parse_build(encoded_data, spec=spec, spec_params=kwargs, strict=stri... |
'The optional parameter is not used, but rather included so we don\'t
have to delete it from the parameter dictionary when passing as keyword
args
:param tag_type:
None for normal values, or one of "implicit", "explicit" for tagged
values
:param class_:
The class for the value - defaults to "universal" if tag_type is
N... | def __init__(self, tag_type=None, class_=None, tag=None, optional=None, default=None, contents=None):
| try:
if (self.__class__ not in _SETUP_CLASSES):
cls = self.__class__
if hasattr(cls, u'_setup'):
self._setup()
_SETUP_CLASSES[cls] = True
if (tag_type is not None):
if (tag_type not in (u'implicit', u'explicit')):
raise ... |
'Since str is differnt in Python 2 and 3, this calls the appropriate
method, __unicode__() or __bytes__()
:return:
A unicode string'
| def __str__(self):
| if _PY2:
return self.__bytes__()
else:
return self.__unicode__()
|
':return:
A unicode string'
| def __repr__(self):
| if _PY2:
return (u'<%s %s b%s>' % (type_name(self), id(self), repr(self.dump())))
else:
return (u'<%s %s %s>' % (type_name(self), id(self), repr(self.dump())))
|
'A fall-back method for print() in Python 2
:return:
A byte string of the output of repr()'
| def __bytes__(self):
| return self.__repr__().encode(u'utf-8')
|
'A fall-back method for print() in Python 3
:return:
A unicode string of the output of repr()'
| def __unicode__(self):
| return self.__repr__()
|
'Constructs a new copy of the current object, preserving any tagging
:return:
An Asn1Value object'
| def _new_instance(self):
| new_obj = self.__class__()
new_obj.tag_type = self.tag_type
new_obj.class_ = self.class_
new_obj.tag = self.tag
new_obj.explicit_class = self.explicit_class
new_obj.explicit_tag = self.explicit_tag
return new_obj
|
'Implements the copy.copy() interface
:return:
A new shallow copy of the current Asn1Value object'
| def __copy__(self):
| new_obj = self._new_instance()
new_obj._copy(self, copy.copy)
return new_obj
|
'Implements the copy.deepcopy() interface
:param memo:
A dict for memoization
:return:
A new deep copy of the current Asn1Value object'
| def __deepcopy__(self, memo):
| new_obj = self._new_instance()
memo[id(self)] = new_obj
new_obj._copy(self, copy.deepcopy)
return new_obj
|
'Copies the object, preserving any special tagging from it
:return:
An Asn1Value object'
| def copy(self):
| return copy.deepcopy(self)
|
'Copies the object, applying a new tagging to it
:param tag_type:
A unicode string of "implicit" or "explicit"
:param tag:
A integer tag number
:return:
An Asn1Value object'
| def retag(self, tag_type, tag):
| new_obj = self.__class__(tag_type=tag_type, tag=tag)
new_obj._copy(self, copy.deepcopy)
return new_obj
|
'Copies the object, removing any special tagging from it
:return:
An Asn1Value object'
| def untag(self):
| new_obj = self.__class__()
new_obj._copy(self, copy.deepcopy)
return new_obj
|
'Copies the contents of another Asn1Value 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'
| def _copy(self, other, copy_func):
| if (self.__class__ != other.__class__):
raise TypeError(unwrap(u'\n Can not copy values from %s object to %s object\n ', type_name(other), type_name(self))... |
'Show the binary data and parsed data in a tree structure'
| def debug(self, nest_level=1):
| prefix = (u' ' * nest_level)
has_parsed = hasattr(self, u'parsed')
_basic_debug(prefix, self)
if has_parsed:
self.parsed.debug((nest_level + 2))
elif hasattr(self, u'chosen'):
self.chosen.debug((nest_level + 2))
elif (_PY2 and isinstance(self.native, byte_cls)):
pr... |
'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'
| def dump(self, force=False):
| contents = self.contents
if ((self._header is None) or force):
if (isinstance(self, Constructable) and self._indefinite):
self.method = 0
header = _dump_header(self.class_, self.method, self.tag, self.contents)
trailer = ''
if (self.tag_type == u'explicit'):
... |
'Generates _reverse_map from _map'
| def _setup(self):
| cls = self.__class__
if ((cls._map is None) or (cls._reverse_map is not None)):
return
cls._reverse_map = {}
for (key, value) in cls._map.items():
cls._reverse_map[value] = key
|
'Converts the current object into an object of a different class. The
new class must use the ASN.1 encoding for the value.
:param other_class:
The class to instantiate the new object from
:return:
An instance of the type other_class'
| def cast(self, other_class):
| if (other_class.tag != self.__class__.tag):
raise TypeError(unwrap(u'\n Can not covert a value from %s object to %s object since they\n use dif... |
':return:
A concatenation of the native values of the contained chunks'
| def _merge_chunks(self):
| if (not self._indefinite):
return self._as_chunk()
pointer = self._chunks_offset
contents_len = len(self.contents)
output = None
while (pointer < contents_len):
(sub_value, pointer) = _parse_build(self.contents, pointer, spec=self.__class__)
if (output is None):
o... |
'A method to return a chunk of data that can be combined for
constructed method values
:return:
A native Python value that can be added together. Examples include
byte strings, unicode strings or tuples.'
| def _as_chunk(self):
| if (self._chunks_offset == 0):
return self.contents
return self.contents[self._chunks_offset:]
|
'Copies the contents of another Constructable 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'
| def _copy(self, other, copy_func):
| super(Constructable, self)._copy(other, copy_func)
self.method = other.method
self._indefinite = other._indefinite
|
':param other:
The other Primitive to compare to
:return:
A boolean'
| def __eq__(self, other):
| return (other.__class__ == self.__class__)
|
'The a native Python datatype representation of this value
:return:
None'
| @property
def native(self):
| return None
|
'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'
| def dump(self, force=False):
| return ''
|
'Sets the value of the object before passing to Asn1Value.__init__()
:param value:
An Asn1Value object that will be set as the parsed value'
| def __init__(self, value=None, **kwargs):
| Asn1Value.__init__(self, **kwargs)
try:
if (value is not None):
if (not isinstance(value, Asn1Value)):
raise TypeError(unwrap(u'\n value must be an instance of Ans... |
'The a native Python datatype representation of this value
:return:
The .native value from the parsed value object'
| @property
def native(self):
| if (self._parsed is None):
self.parse()
return self._parsed[0].native
|
'Returns the parsed object from .parse()
:return:
The object returned by .parse()'
| @property
def parsed(self):
| if (self._parsed is None):
self.parse()
return self._parsed[0]
|
'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 value
will be decoded using the standard unive... | def parse(self, spec=None, spec_params=None):
| if ((self._parsed is None) or (self._parsed[1:3] != (spec, spec_params))):
try:
passed_params = spec_params
if (self.tag_type == u'explicit'):
passed_params = ({} if (not spec_params) else spec_params.copy())
passed_params[u'tag_type'] = self.tag_type
... |
'Copies the contents of another Any 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'
| def _copy(self, other, copy_func):
| super(Any, self)._copy(other, copy_func)
self._parsed = copy_func(other._parsed)
|
'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'
| def dump(self, force=False):
| if (self._parsed is None):
self.parse()
return self._parsed[0].dump(force=force)
|
'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 exists
:return:
A instance of the current class'
| @classmethod
def load(cls, encoded_data, strict=False, **kwargs):
| if (not isinstance(encoded_data, byte_cls)):
raise TypeError((u'encoded_data must be a byte string, not %s' % type_name(encoded_data)))
(value, _) = _parse_build(encoded_data, spec=cls, spec_params=kwargs, strict=strict)
return value
|
'Generates _id_map from _alternatives to allow validating contents'
| def _setup(self):
| cls = self.__class__
cls._id_map = {}
cls._name_map = {}
for (index, info) in enumerate(cls._alternatives):
if (len(info) < 3):
info = (info + ({},))
cls._alternatives[index] = info
id_ = _build_id_tuple(info[2], info[1])
cls._id_map[id_] = index
c... |
'Checks to ensure implicit tagging is not being used since it is
incompatible with Choice, then forwards on to Asn1Value.__init__()
:param name:
The name of the alternative to be set - used with value.
Alternatively this may be a dict with a single key being the name
and the value being the value, or a two-element tupl... | def __init__(self, name=None, value=None, tag_type=None, **kwargs):
| kwargs[u'tag_type'] = tag_type
Asn1Value.__init__(self, **kwargs)
try:
if (tag_type == u'implicit'):
raise ValueError(unwrap(u'\n The Choice type can not be implicitly tagged even if... |
':return:
A unicode string of the field name of the chosen alternative'
| @property
def name(self):
| if (not self._name):
self._name = self._alternatives[self._choice][0]
return self._name
|
'Parses the detected alternative
:return:
An Asn1Value object of the chosen alternative'
| def parse(self):
| if (self._parsed is not None):
return self._parsed
try:
(_, spec, params) = self._alternatives[self._choice]
(self._parsed, _) = _parse_build(self.contents, spec=spec, spec_params=params)
except (ValueError, TypeError) as e:
args = e.args[1:]
e.args = (((e.args[0] + (... |
':return:
An Asn1Value object of the chosen alternative'
| @property
def chosen(self):
| return self.parse()
|
'The a native Python datatype representation of this value
:return:
The .native value from the contained value object'
| @property
def native(self):
| return self.chosen.native
|
'Ensures that the class and tag specified exist as an alternative
:param class_:
The integer class_ from the encoded value header
:param tag:
The integer tag from the encoded value header
:param contents:
A byte string of the contents of the value - used when the object
is explicitly tagged
:raises:
ValueError - when v... | def validate(self, class_, tag, contents):
| id_ = (class_, tag)
if (self.tag_type == u'explicit'):
if ((self.explicit_class, self.explicit_tag) != id_):
raise ValueError(unwrap(u'\n %s was explicitly tagged, but the value provided do... |
':return:
A unicode string of a human-friendly representation of the class and tag'
| def _format_class_tag(self, class_, tag):
| return (u'[%s %s]' % (CLASS_NUM_TO_NAME_MAP[class_].upper(), tag))
|
'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'
| def _copy(self, other, copy_func):
| super(Choice, self)._copy(other, copy_func)
self._choice = other._choice
self._name = other._name
self._parsed = copy_func(other._parsed)
|
'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'
| def dump(self, force=False):
| self.contents = self.chosen.dump(force=force)
if ((self._header is None) or force):
if (self.tag_type == u'explicit'):
self._header = _dump_header(self.explicit_class, 1, self.explicit_tag, self.contents)
else:
self._header = ''
return (self._header + self.contents)
|
'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 exists
:return:
A Concat object'
| @classmethod
def load(cls, encoded_data, strict=False):
| return cls(contents=encoded_data, strict=strict)
|
':param value:
A native Python datatype to initialize the object value with
:param contents:
A byte string of the encoded contents of the value
:param strict:
A boolean indicating if trailing data should be forbidden - if so, a
ValueError will be raised when trailing data exists in contents
:raises:
ValueError - when a... | def __init__(self, value=None, contents=None, strict=False):
| if (contents is not None):
try:
contents_len = len(contents)
self._children = []
offset = 0
for spec in self._child_specs:
if (offset < contents_len):
(child_value, offset) = _parse_build(contents, pointer=offset, spec=spec)... |
'Since str is differnt in Python 2 and 3, this calls the appropriate
method, __unicode__() or __bytes__()
:return:
A unicode string'
| def __str__(self):
| if _PY2:
return self.__bytes__()
else:
return self.__unicode__()
|
'A byte string of the DER-encoded contents'
| def __bytes__(self):
| return self.dump()
|
':return:
A unicode string'
| def __unicode__(self):
| return repr(self)
|
':return:
A unicode string'
| def __repr__(self):
| return (u'<%s %s %s>' % (type_name(self), id(self), repr(self.dump())))
|
'Implements the copy.copy() interface
:return:
A new shallow copy of the Concat object'
| def __copy__(self):
| new_obj = self.__class__()
new_obj._copy(self, copy.copy)
return new_obj
|
'Implements the copy.deepcopy() interface
:param memo:
A dict for memoization
:return:
A new deep copy of the Concat object and all child objects'
| def __deepcopy__(self, memo):
| new_obj = self.__class__()
memo[id(self)] = new_obj
new_obj._copy(self, copy.deepcopy)
return new_obj
|
'Copies the object
:return:
A Concat object'
| def copy(self):
| return copy.deepcopy(self)
|
'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'
| def _copy(self, other, copy_func):
| if (self.__class__ != other.__class__):
raise TypeError(unwrap(u'\n Can not copy values from %s object to %s object\n ', type_name(other), type_name(self))... |
'Show the binary data and parsed data in a tree structure'
| def debug(self, nest_level=1):
| prefix = (u' ' * nest_level)
print((u'%s%s Object #%s' % (prefix, type_name(self), id(self))))
print((u'%s Children:' % (prefix,)))
for child in self._children:
child.debug((nest_level + 2))
|
'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'
| def dump(self, force=False):
| contents = ''
for child in self._children:
contents += child.dump(force=force)
return contents
|
':return:
A byte string of the DER-encoded contents of the children'
| @property
def contents(self):
| return self.dump()
|
':return:
Integer'
| def __len__(self):
| return len(self._children)
|
'Allows accessing children by index
:param key:
An integer of the child index
:raises:
KeyError - when an index is invalid
:return:
The Asn1Value object of the child specified'
| def __getitem__(self, key):
| if ((key > (len(self._child_specs) - 1)) or (key < 0)):
raise KeyError(unwrap(u'\n No child is definition for position %d of %s\n ', key, type_name(self)))
... |
'Allows settings children by index
:param key:
An integer of the child index
:param value:
An Asn1Value object to set the child to
:raises:
KeyError - when an index is invalid
ValueError - when the value is not an instance of Asn1Value'
| def __setitem__(self, key, value):
| if ((key > (len(self._child_specs) - 1)) or (key < 0)):
raise KeyError(unwrap(u'\n No child is defined for position %d of %s\n ', key, type_name(self)))
i... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.