id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
17,800
swisscom/cleanerversion
versions/admin.py
VersionedAdmin.get_object
def get_object(self, request, object_id, from_field=None): """ our implementation of get_object allows for cloning when updating an object, not cloning when the button 'save but not clone' is pushed and at no other time will clone be called """ # from_field breaks in 1.7....
python
def get_object(self, request, object_id, from_field=None): """ our implementation of get_object allows for cloning when updating an object, not cloning when the button 'save but not clone' is pushed and at no other time will clone be called """ # from_field breaks in 1.7....
[ "def", "get_object", "(", "self", ",", "request", ",", "object_id", ",", "from_field", "=", "None", ")", ":", "# from_field breaks in 1.7.8", "obj", "=", "super", "(", "VersionedAdmin", ",", "self", ")", ".", "get_object", "(", "request", ",", "object_id", "...
our implementation of get_object allows for cloning when updating an object, not cloning when the button 'save but not clone' is pushed and at no other time will clone be called
[ "our", "implementation", "of", "get_object", "allows", "for", "cloning", "when", "updating", "an", "object", "not", "cloning", "when", "the", "button", "save", "but", "not", "clone", "is", "pushed", "and", "at", "no", "other", "time", "will", "clone", "be", ...
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/admin.py#L240-L259
17,801
swisscom/cleanerversion
versions/admin.py
VersionedAdmin.get_urls
def get_urls(self): """ Appends the custom will_not_clone url to the admin site """ not_clone_url = [url(r'^(.+)/will_not_clone/$', admin.site.admin_view(self.will_not_clone))] restore_url = [ url(r'^(.+)/restore/$', admin.site.admin_view(...
python
def get_urls(self): """ Appends the custom will_not_clone url to the admin site """ not_clone_url = [url(r'^(.+)/will_not_clone/$', admin.site.admin_view(self.will_not_clone))] restore_url = [ url(r'^(.+)/restore/$', admin.site.admin_view(...
[ "def", "get_urls", "(", "self", ")", ":", "not_clone_url", "=", "[", "url", "(", "r'^(.+)/will_not_clone/$'", ",", "admin", ".", "site", ".", "admin_view", "(", "self", ".", "will_not_clone", ")", ")", "]", "restore_url", "=", "[", "url", "(", "r'^(.+)/res...
Appends the custom will_not_clone url to the admin site
[ "Appends", "the", "custom", "will_not_clone", "url", "to", "the", "admin", "site" ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/admin.py#L297-L306
17,802
swisscom/cleanerversion
versions/util/postgresql.py
create_current_version_unique_identity_indexes
def create_current_version_unique_identity_indexes(app_name, database=None): """ Add partial unique indexes for the the identity column of versionable models. This enforces that no two *current* versions can have the same identity. This will only try to create indexes if they do not exist in the d...
python
def create_current_version_unique_identity_indexes(app_name, database=None): """ Add partial unique indexes for the the identity column of versionable models. This enforces that no two *current* versions can have the same identity. This will only try to create indexes if they do not exist in the d...
[ "def", "create_current_version_unique_identity_indexes", "(", "app_name", ",", "database", "=", "None", ")", ":", "indexes_created", "=", "0", "connection", "=", "database_connection", "(", "database", ")", "with", "connection", ".", "cursor", "(", ")", "as", "cur...
Add partial unique indexes for the the identity column of versionable models. This enforces that no two *current* versions can have the same identity. This will only try to create indexes if they do not exist in the database, so it should be safe to run in a post_migrate signal handler. Running it ...
[ "Add", "partial", "unique", "indexes", "for", "the", "the", "identity", "column", "of", "versionable", "models", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/util/postgresql.py#L148-L182
17,803
swisscom/cleanerversion
versions/models.py
VersionManager.get_queryset
def get_queryset(self): """ Returns a VersionedQuerySet capable of handling version time restrictions. :return: VersionedQuerySet """ qs = VersionedQuerySet(self.model, using=self._db) if hasattr(self, 'instance') and hasattr(self.instance, '_querytime'): ...
python
def get_queryset(self): """ Returns a VersionedQuerySet capable of handling version time restrictions. :return: VersionedQuerySet """ qs = VersionedQuerySet(self.model, using=self._db) if hasattr(self, 'instance') and hasattr(self.instance, '_querytime'): ...
[ "def", "get_queryset", "(", "self", ")", ":", "qs", "=", "VersionedQuerySet", "(", "self", ".", "model", ",", "using", "=", "self", ".", "_db", ")", "if", "hasattr", "(", "self", ",", "'instance'", ")", "and", "hasattr", "(", "self", ".", "instance", ...
Returns a VersionedQuerySet capable of handling version time restrictions. :return: VersionedQuerySet
[ "Returns", "a", "VersionedQuerySet", "capable", "of", "handling", "version", "time", "restrictions", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L62-L72
17,804
swisscom/cleanerversion
versions/models.py
VersionManager.next_version
def next_version(self, object, relations_as_of='end'): """ Return the next version of the given object. In case there is no next object existing, meaning the given object is the current version, the function returns this version. Note that if object's version_end_date is None, ...
python
def next_version(self, object, relations_as_of='end'): """ Return the next version of the given object. In case there is no next object existing, meaning the given object is the current version, the function returns this version. Note that if object's version_end_date is None, ...
[ "def", "next_version", "(", "self", ",", "object", ",", "relations_as_of", "=", "'end'", ")", ":", "if", "object", ".", "version_end_date", "is", "None", ":", "next", "=", "object", "else", ":", "next", "=", "self", ".", "filter", "(", "Q", "(", "ident...
Return the next version of the given object. In case there is no next object existing, meaning the given object is the current version, the function returns this version. Note that if object's version_end_date is None, this does not check the database to see if there is a newer version...
[ "Return", "the", "next", "version", "of", "the", "given", "object", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L83-L117
17,805
swisscom/cleanerversion
versions/models.py
VersionManager.previous_version
def previous_version(self, object, relations_as_of='end'): """ Return the previous version of the given object. In case there is no previous object existing, meaning the given object is the first version of the object, then the function returns this version. ``relations...
python
def previous_version(self, object, relations_as_of='end'): """ Return the previous version of the given object. In case there is no previous object existing, meaning the given object is the first version of the object, then the function returns this version. ``relations...
[ "def", "previous_version", "(", "self", ",", "object", ",", "relations_as_of", "=", "'end'", ")", ":", "if", "object", ".", "version_birth_date", "==", "object", ".", "version_start_date", ":", "previous", "=", "object", "else", ":", "previous", "=", "self", ...
Return the previous version of the given object. In case there is no previous object existing, meaning the given object is the first version of the object, then the function returns this version. ``relations_as_of`` is used to fix the point in time for the version; this affects...
[ "Return", "the", "previous", "version", "of", "the", "given", "object", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L119-L151
17,806
swisscom/cleanerversion
versions/models.py
VersionManager.current_version
def current_version(self, object, relations_as_of=None, check_db=False): """ Return the current version of the given object. The current version is the one having its version_end_date set to NULL. If there is not such a version then it means the object has been 'deleted' and so ...
python
def current_version(self, object, relations_as_of=None, check_db=False): """ Return the current version of the given object. The current version is the one having its version_end_date set to NULL. If there is not such a version then it means the object has been 'deleted' and so ...
[ "def", "current_version", "(", "self", ",", "object", ",", "relations_as_of", "=", "None", ",", "check_db", "=", "False", ")", ":", "if", "object", ".", "version_end_date", "is", "None", "and", "not", "check_db", ":", "current", "=", "object", "else", ":",...
Return the current version of the given object. The current version is the one having its version_end_date set to NULL. If there is not such a version then it means the object has been 'deleted' and so there is no current version available. In this case the function returns None. ...
[ "Return", "the", "current", "version", "of", "the", "given", "object", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L153-L185
17,807
swisscom/cleanerversion
versions/models.py
VersionManager.adjust_version_as_of
def adjust_version_as_of(version, relations_as_of): """ Adjusts the passed version's as_of time to an appropriate value, and returns it. ``relations_as_of`` is used to fix the point in time for the version; this affects which related objects are returned when querying for ...
python
def adjust_version_as_of(version, relations_as_of): """ Adjusts the passed version's as_of time to an appropriate value, and returns it. ``relations_as_of`` is used to fix the point in time for the version; this affects which related objects are returned when querying for ...
[ "def", "adjust_version_as_of", "(", "version", ",", "relations_as_of", ")", ":", "if", "not", "version", ":", "return", "version", "if", "relations_as_of", "==", "'end'", ":", "if", "version", ".", "is_current", ":", "# Ensure that version._querytime is active, in cas...
Adjusts the passed version's as_of time to an appropriate value, and returns it. ``relations_as_of`` is used to fix the point in time for the version; this affects which related objects are returned when querying for object relations. Valid ``relations_as_of`` values and how thi...
[ "Adjusts", "the", "passed", "version", "s", "as_of", "time", "to", "an", "appropriate", "value", "and", "returns", "it", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L188-L252
17,808
swisscom/cleanerversion
versions/models.py
VersionedQuerySet._fetch_all
def _fetch_all(self): """ Completely overrides the QuerySet._fetch_all method by adding the timestamp to all objects :return: See django.db.models.query.QuerySet._fetch_all for return values """ if self._result_cache is None: self._result_cache = ...
python
def _fetch_all(self): """ Completely overrides the QuerySet._fetch_all method by adding the timestamp to all objects :return: See django.db.models.query.QuerySet._fetch_all for return values """ if self._result_cache is None: self._result_cache = ...
[ "def", "_fetch_all", "(", "self", ")", ":", "if", "self", ".", "_result_cache", "is", "None", ":", "self", ".", "_result_cache", "=", "list", "(", "self", ".", "iterator", "(", ")", ")", "# TODO: Do we have to test for ValuesListIterable, ValuesIterable,", "# and ...
Completely overrides the QuerySet._fetch_all method by adding the timestamp to all objects :return: See django.db.models.query.QuerySet._fetch_all for return values
[ "Completely", "overrides", "the", "QuerySet", ".", "_fetch_all", "method", "by", "adding", "the", "timestamp", "to", "all", "objects" ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L500-L516
17,809
swisscom/cleanerversion
versions/models.py
VersionedQuerySet._clone
def _clone(self, *args, **kwargs): """ Overrides the QuerySet._clone method by adding the cloning of the VersionedQuerySet's query_time parameter :param kwargs: Same as the original QuerySet._clone params :return: Just as QuerySet._clone, this method returns a clone of the ...
python
def _clone(self, *args, **kwargs): """ Overrides the QuerySet._clone method by adding the cloning of the VersionedQuerySet's query_time parameter :param kwargs: Same as the original QuerySet._clone params :return: Just as QuerySet._clone, this method returns a clone of the ...
[ "def", "_clone", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "clone", "=", "super", "(", "VersionedQuerySet", ",", "self", ")", ".", "_clone", "(", "*", "*", "kwargs", ")", "clone", ".", "querytime", "=", "self", ".", "queryti...
Overrides the QuerySet._clone method by adding the cloning of the VersionedQuerySet's query_time parameter :param kwargs: Same as the original QuerySet._clone params :return: Just as QuerySet._clone, this method returns a clone of the original object
[ "Overrides", "the", "QuerySet", ".", "_clone", "method", "by", "adding", "the", "cloning", "of", "the", "VersionedQuerySet", "s", "query_time", "parameter" ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L518-L529
17,810
swisscom/cleanerversion
versions/models.py
VersionedQuerySet._set_item_querytime
def _set_item_querytime(self, item, type_check=True): """ Sets the time for which the query was made on the resulting item :param item: an item of type Versionable :param type_check: Check the item to be a Versionable :return: Returns the item itself with the time set ""...
python
def _set_item_querytime(self, item, type_check=True): """ Sets the time for which the query was made on the resulting item :param item: an item of type Versionable :param type_check: Check the item to be a Versionable :return: Returns the item itself with the time set ""...
[ "def", "_set_item_querytime", "(", "self", ",", "item", ",", "type_check", "=", "True", ")", ":", "if", "isinstance", "(", "item", ",", "Versionable", ")", ":", "item", ".", "_querytime", "=", "self", ".", "querytime", "elif", "isinstance", "(", "item", ...
Sets the time for which the query was made on the resulting item :param item: an item of type Versionable :param type_check: Check the item to be a Versionable :return: Returns the item itself with the time set
[ "Sets", "the", "time", "for", "which", "the", "query", "was", "made", "on", "the", "resulting", "item" ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L531-L548
17,811
swisscom/cleanerversion
versions/models.py
VersionedQuerySet.as_of
def as_of(self, qtime=None): """ Sets the time for which we want to retrieve an object. :param qtime: The UTC date and time; if None then use the current state (where version_end_date = NULL) :return: A VersionedQuerySet """ clone = self._clone() clon...
python
def as_of(self, qtime=None): """ Sets the time for which we want to retrieve an object. :param qtime: The UTC date and time; if None then use the current state (where version_end_date = NULL) :return: A VersionedQuerySet """ clone = self._clone() clon...
[ "def", "as_of", "(", "self", ",", "qtime", "=", "None", ")", ":", "clone", "=", "self", ".", "_clone", "(", ")", "clone", ".", "querytime", "=", "QueryTime", "(", "time", "=", "qtime", ",", "active", "=", "True", ")", "return", "clone" ]
Sets the time for which we want to retrieve an object. :param qtime: The UTC date and time; if None then use the current state (where version_end_date = NULL) :return: A VersionedQuerySet
[ "Sets", "the", "time", "for", "which", "we", "want", "to", "retrieve", "an", "object", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L550-L560
17,812
swisscom/cleanerversion
versions/models.py
VersionedQuerySet.delete
def delete(self): """ Deletes the records in the QuerySet. """ assert self.query.can_filter(), \ "Cannot use 'limit' or 'offset' with delete." # Ensure that only current objects are selected. del_query = self.filter(version_end_date__isnull=True) # T...
python
def delete(self): """ Deletes the records in the QuerySet. """ assert self.query.can_filter(), \ "Cannot use 'limit' or 'offset' with delete." # Ensure that only current objects are selected. del_query = self.filter(version_end_date__isnull=True) # T...
[ "def", "delete", "(", "self", ")", ":", "assert", "self", ".", "query", ".", "can_filter", "(", ")", ",", "\"Cannot use 'limit' or 'offset' with delete.\"", "# Ensure that only current objects are selected.", "del_query", "=", "self", ".", "filter", "(", "version_end_da...
Deletes the records in the QuerySet.
[ "Deletes", "the", "records", "in", "the", "QuerySet", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L562-L588
17,813
swisscom/cleanerversion
versions/models.py
Versionable.uuid
def uuid(uuid_value=None): """ Returns a uuid value that is valid to use for id and identity fields. :return: unicode uuid object if using UUIDFields, uuid unicode string otherwise. """ if uuid_value: if not validate_uuid(uuid_value): rais...
python
def uuid(uuid_value=None): """ Returns a uuid value that is valid to use for id and identity fields. :return: unicode uuid object if using UUIDFields, uuid unicode string otherwise. """ if uuid_value: if not validate_uuid(uuid_value): rais...
[ "def", "uuid", "(", "uuid_value", "=", "None", ")", ":", "if", "uuid_value", ":", "if", "not", "validate_uuid", "(", "uuid_value", ")", ":", "raise", "ValueError", "(", "\"uuid_value must be a valid UUID version 4 object\"", ")", "else", ":", "uuid_value", "=", ...
Returns a uuid value that is valid to use for id and identity fields. :return: unicode uuid object if using UUIDFields, uuid unicode string otherwise.
[ "Returns", "a", "uuid", "value", "that", "is", "valid", "to", "use", "for", "id", "and", "identity", "fields", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L737-L754
17,814
swisscom/cleanerversion
versions/models.py
Versionable.restore
def restore(self, **kwargs): """ Restores this version as a new version, and returns this new version. If a current version already exists, it will be terminated before restoring this version. Relations (foreign key, reverse foreign key, many-to-many) are not restored w...
python
def restore(self, **kwargs): """ Restores this version as a new version, and returns this new version. If a current version already exists, it will be terminated before restoring this version. Relations (foreign key, reverse foreign key, many-to-many) are not restored w...
[ "def", "restore", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "not", "self", ".", "pk", ":", "raise", "ValueError", "(", "'Instance must be saved and terminated before it can be '", "'restored.'", ")", "if", "self", ".", "is_current", ":", "raise", "...
Restores this version as a new version, and returns this new version. If a current version already exists, it will be terminated before restoring this version. Relations (foreign key, reverse foreign key, many-to-many) are not restored with the old version. If provided in kwargs, ...
[ "Restores", "this", "version", "as", "a", "new", "version", "and", "returns", "this", "new", "version", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L908-L1002
17,815
swisscom/cleanerversion
versions/models.py
Versionable.detach
def detach(self): """ Detaches the instance from its history. Similar to creating a new object with the same field values. The id and identity fields are set to a new value. The returned object has not been saved, call save() afterwards when you are ready to persist the ...
python
def detach(self): """ Detaches the instance from its history. Similar to creating a new object with the same field values. The id and identity fields are set to a new value. The returned object has not been saved, call save() afterwards when you are ready to persist the ...
[ "def", "detach", "(", "self", ")", ":", "self", ".", "id", "=", "self", ".", "identity", "=", "self", ".", "uuid", "(", ")", "self", ".", "version_start_date", "=", "self", ".", "version_birth_date", "=", "get_utc_now", "(", ")", "self", ".", "version_...
Detaches the instance from its history. Similar to creating a new object with the same field values. The id and identity fields are set to a new value. The returned object has not been saved, call save() afterwards when you are ready to persist the object. ManyToMany and revers...
[ "Detaches", "the", "instance", "from", "its", "history", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L1013-L1030
17,816
swisscom/cleanerversion
versions/models.py
Versionable.matches_querytime
def matches_querytime(instance, querytime): """ Checks whether the given instance satisfies the given QueryTime object. :param instance: an instance of Versionable :param querytime: QueryTime value to check against """ if not querytime.active: return True ...
python
def matches_querytime(instance, querytime): """ Checks whether the given instance satisfies the given QueryTime object. :param instance: an instance of Versionable :param querytime: QueryTime value to check against """ if not querytime.active: return True ...
[ "def", "matches_querytime", "(", "instance", ",", "querytime", ")", ":", "if", "not", "querytime", ".", "active", ":", "return", "True", "if", "not", "querytime", ".", "time", ":", "return", "instance", ".", "version_end_date", "is", "None", "return", "(", ...
Checks whether the given instance satisfies the given QueryTime object. :param instance: an instance of Versionable :param querytime: QueryTime value to check against
[ "Checks", "whether", "the", "given", "instance", "satisfies", "the", "given", "QueryTime", "object", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/models.py#L1033-L1048
17,817
swisscom/cleanerversion
versions/fields.py
VersionedForeignKey.contribute_to_related_class
def contribute_to_related_class(self, cls, related): """ Override ForeignKey's methods, and replace the descriptor, if set by the parent's methods """ # Internal FK's - i.e., those with a related name ending with '+' - # and swapped models don't get a related descriptor. ...
python
def contribute_to_related_class(self, cls, related): """ Override ForeignKey's methods, and replace the descriptor, if set by the parent's methods """ # Internal FK's - i.e., those with a related name ending with '+' - # and swapped models don't get a related descriptor. ...
[ "def", "contribute_to_related_class", "(", "self", ",", "cls", ",", "related", ")", ":", "# Internal FK's - i.e., those with a related name ending with '+' -", "# and swapped models don't get a related descriptor.", "super", "(", "VersionedForeignKey", ",", "self", ")", ".", "c...
Override ForeignKey's methods, and replace the descriptor, if set by the parent's methods
[ "Override", "ForeignKey", "s", "methods", "and", "replace", "the", "descriptor", "if", "set", "by", "the", "parent", "s", "methods" ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/fields.py#L32-L44
17,818
swisscom/cleanerversion
versions/fields.py
VersionedForeignKey.get_joining_columns
def get_joining_columns(self, reverse_join=False): """ Get and return joining columns defined by this foreign key relationship :return: A tuple containing the column names of the tables to be joined (<local_col_name>, <remote_col_name>) :rtype: tuple """ sour...
python
def get_joining_columns(self, reverse_join=False): """ Get and return joining columns defined by this foreign key relationship :return: A tuple containing the column names of the tables to be joined (<local_col_name>, <remote_col_name>) :rtype: tuple """ sour...
[ "def", "get_joining_columns", "(", "self", ",", "reverse_join", "=", "False", ")", ":", "source", "=", "self", ".", "reverse_related_fields", "if", "reverse_join", "else", "self", ".", "related_fields", "joining_columns", "=", "tuple", "(", ")", "for", "lhs_fiel...
Get and return joining columns defined by this foreign key relationship :return: A tuple containing the column names of the tables to be joined (<local_col_name>, <remote_col_name>) :rtype: tuple
[ "Get", "and", "return", "joining", "columns", "defined", "by", "this", "foreign", "key", "relationship" ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/fields.py#L65-L90
17,819
swisscom/cleanerversion
versions/settings.py
get_versioned_delete_collector_class
def get_versioned_delete_collector_class(): """ Gets the class to use for deletion collection. :return: class """ key = 'VERSIONED_DELETE_COLLECTOR' try: cls = _cache[key] except KeyError: collector_class_string = getattr(settings, key) cls = import_from_string(colle...
python
def get_versioned_delete_collector_class(): """ Gets the class to use for deletion collection. :return: class """ key = 'VERSIONED_DELETE_COLLECTOR' try: cls = _cache[key] except KeyError: collector_class_string = getattr(settings, key) cls = import_from_string(colle...
[ "def", "get_versioned_delete_collector_class", "(", ")", ":", "key", "=", "'VERSIONED_DELETE_COLLECTOR'", "try", ":", "cls", "=", "_cache", "[", "key", "]", "except", "KeyError", ":", "collector_class_string", "=", "getattr", "(", "settings", ",", "key", ")", "c...
Gets the class to use for deletion collection. :return: class
[ "Gets", "the", "class", "to", "use", "for", "deletion", "collection", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/settings.py#L57-L70
17,820
swisscom/cleanerversion
versions/deletion.py
VersionedCollector.related_objects
def related_objects(self, related, objs): """ Gets a QuerySet of current objects related to ``objs`` via the relation ``related``. """ from versions.models import Versionable related_model = related.related_model if issubclass(related_model, Versionable): ...
python
def related_objects(self, related, objs): """ Gets a QuerySet of current objects related to ``objs`` via the relation ``related``. """ from versions.models import Versionable related_model = related.related_model if issubclass(related_model, Versionable): ...
[ "def", "related_objects", "(", "self", ",", "related", ",", "objs", ")", ":", "from", "versions", ".", "models", "import", "Versionable", "related_model", "=", "related", ".", "related_model", "if", "issubclass", "(", "related_model", ",", "Versionable", ")", ...
Gets a QuerySet of current objects related to ``objs`` via the relation ``related``.
[ "Gets", "a", "QuerySet", "of", "current", "objects", "related", "to", "objs", "via", "the", "relation", "related", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/deletion.py#L149-L163
17,821
swisscom/cleanerversion
versions/deletion.py
VersionedCollector.versionable_delete
def versionable_delete(self, instance, timestamp): """ Soft-deletes the instance, setting it's version_end_date to timestamp. Override this method to implement custom behaviour. :param Versionable instance: :param datetime timestamp: """ instance._delete_at(time...
python
def versionable_delete(self, instance, timestamp): """ Soft-deletes the instance, setting it's version_end_date to timestamp. Override this method to implement custom behaviour. :param Versionable instance: :param datetime timestamp: """ instance._delete_at(time...
[ "def", "versionable_delete", "(", "self", ",", "instance", ",", "timestamp", ")", ":", "instance", ".", "_delete_at", "(", "timestamp", ",", "using", "=", "self", ".", "using", ")" ]
Soft-deletes the instance, setting it's version_end_date to timestamp. Override this method to implement custom behaviour. :param Versionable instance: :param datetime timestamp:
[ "Soft", "-", "deletes", "the", "instance", "setting", "it", "s", "version_end_date", "to", "timestamp", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/deletion.py#L185-L194
17,822
swisscom/cleanerversion
versions/descriptors.py
VersionedManyToManyDescriptor.pks_from_objects
def pks_from_objects(self, objects): """ Extract all the primary key strings from the given objects. Objects may be Versionables, or bare primary keys. :rtype : set """ return {o.pk if isinstance(o, Model) else o for o in objects}
python
def pks_from_objects(self, objects): """ Extract all the primary key strings from the given objects. Objects may be Versionables, or bare primary keys. :rtype : set """ return {o.pk if isinstance(o, Model) else o for o in objects}
[ "def", "pks_from_objects", "(", "self", ",", "objects", ")", ":", "return", "{", "o", ".", "pk", "if", "isinstance", "(", "o", ",", "Model", ")", "else", "o", "for", "o", "in", "objects", "}" ]
Extract all the primary key strings from the given objects. Objects may be Versionables, or bare primary keys. :rtype : set
[ "Extract", "all", "the", "primary", "key", "strings", "from", "the", "given", "objects", ".", "Objects", "may", "be", "Versionables", "or", "bare", "primary", "keys", "." ]
becadbab5d7b474a0e9a596b99e97682402d2f2c
https://github.com/swisscom/cleanerversion/blob/becadbab5d7b474a0e9a596b99e97682402d2f2c/versions/descriptors.py#L395-L402
17,823
matsui528/nanopq
nanopq/pq.py
PQ.fit
def fit(self, vecs, iter=20, seed=123): """Given training vectors, run k-means for each sub-space and create codewords for each sub-space. This function should be run once first of all. Args: vecs (np.ndarray): Training vectors with shape=(N, D) and dtype=np.float32. ...
python
def fit(self, vecs, iter=20, seed=123): """Given training vectors, run k-means for each sub-space and create codewords for each sub-space. This function should be run once first of all. Args: vecs (np.ndarray): Training vectors with shape=(N, D) and dtype=np.float32. ...
[ "def", "fit", "(", "self", ",", "vecs", ",", "iter", "=", "20", ",", "seed", "=", "123", ")", ":", "assert", "vecs", ".", "dtype", "==", "np", ".", "float32", "assert", "vecs", ".", "ndim", "==", "2", "N", ",", "D", "=", "vecs", ".", "shape", ...
Given training vectors, run k-means for each sub-space and create codewords for each sub-space. This function should be run once first of all. Args: vecs (np.ndarray): Training vectors with shape=(N, D) and dtype=np.float32. iter (int): The number of iteration for k-mea...
[ "Given", "training", "vectors", "run", "k", "-", "means", "for", "each", "sub", "-", "space", "and", "create", "codewords", "for", "each", "sub", "-", "space", "." ]
1ce68cad2e3cab62b409e6dd63f676ed7b443ee9
https://github.com/matsui528/nanopq/blob/1ce68cad2e3cab62b409e6dd63f676ed7b443ee9/nanopq/pq.py#L53-L87
17,824
matsui528/nanopq
nanopq/pq.py
PQ.encode
def encode(self, vecs): """Encode input vectors into PQ-codes. Args: vecs (np.ndarray): Input vectors with shape=(N, D) and dtype=np.float32. Returns: np.ndarray: PQ codes with shape=(N, M) and dtype=self.code_dtype """ assert vecs.dtype == np.float32 ...
python
def encode(self, vecs): """Encode input vectors into PQ-codes. Args: vecs (np.ndarray): Input vectors with shape=(N, D) and dtype=np.float32. Returns: np.ndarray: PQ codes with shape=(N, M) and dtype=self.code_dtype """ assert vecs.dtype == np.float32 ...
[ "def", "encode", "(", "self", ",", "vecs", ")", ":", "assert", "vecs", ".", "dtype", "==", "np", ".", "float32", "assert", "vecs", ".", "ndim", "==", "2", "N", ",", "D", "=", "vecs", ".", "shape", "assert", "D", "==", "self", ".", "Ds", "*", "s...
Encode input vectors into PQ-codes. Args: vecs (np.ndarray): Input vectors with shape=(N, D) and dtype=np.float32. Returns: np.ndarray: PQ codes with shape=(N, M) and dtype=self.code_dtype
[ "Encode", "input", "vectors", "into", "PQ", "-", "codes", "." ]
1ce68cad2e3cab62b409e6dd63f676ed7b443ee9
https://github.com/matsui528/nanopq/blob/1ce68cad2e3cab62b409e6dd63f676ed7b443ee9/nanopq/pq.py#L89-L112
17,825
matsui528/nanopq
nanopq/pq.py
PQ.decode
def decode(self, codes): """Given PQ-codes, reconstruct original D-dimensional vectors approximately by fetching the codewords. Args: codes (np.ndarray): PQ-cdoes with shape=(N, M) and dtype=self.code_dtype. Each row is a PQ-code Returns: np.ndar...
python
def decode(self, codes): """Given PQ-codes, reconstruct original D-dimensional vectors approximately by fetching the codewords. Args: codes (np.ndarray): PQ-cdoes with shape=(N, M) and dtype=self.code_dtype. Each row is a PQ-code Returns: np.ndar...
[ "def", "decode", "(", "self", ",", "codes", ")", ":", "assert", "codes", ".", "ndim", "==", "2", "N", ",", "M", "=", "codes", ".", "shape", "assert", "M", "==", "self", ".", "M", "assert", "codes", ".", "dtype", "==", "self", ".", "code_dtype", "...
Given PQ-codes, reconstruct original D-dimensional vectors approximately by fetching the codewords. Args: codes (np.ndarray): PQ-cdoes with shape=(N, M) and dtype=self.code_dtype. Each row is a PQ-code Returns: np.ndarray: Reconstructed vectors with shap...
[ "Given", "PQ", "-", "codes", "reconstruct", "original", "D", "-", "dimensional", "vectors", "approximately", "by", "fetching", "the", "codewords", "." ]
1ce68cad2e3cab62b409e6dd63f676ed7b443ee9
https://github.com/matsui528/nanopq/blob/1ce68cad2e3cab62b409e6dd63f676ed7b443ee9/nanopq/pq.py#L114-L135
17,826
stephenmcd/hot-redis
hot_redis/client.py
transaction
def transaction(): """ Swaps out the current client with a pipeline instance, so that each Redis method call inside the context will be pipelined. Once the context is exited, we execute the pipeline. """ client = default_client() _thread.client = client.pipeline() try: yield ...
python
def transaction(): """ Swaps out the current client with a pipeline instance, so that each Redis method call inside the context will be pipelined. Once the context is exited, we execute the pipeline. """ client = default_client() _thread.client = client.pipeline() try: yield ...
[ "def", "transaction", "(", ")", ":", "client", "=", "default_client", "(", ")", "_thread", ".", "client", "=", "client", ".", "pipeline", "(", ")", "try", ":", "yield", "_thread", ".", "client", ".", "execute", "(", ")", "finally", ":", "_thread", ".",...
Swaps out the current client with a pipeline instance, so that each Redis method call inside the context will be pipelined. Once the context is exited, we execute the pipeline.
[ "Swaps", "out", "the", "current", "client", "with", "a", "pipeline", "instance", "so", "that", "each", "Redis", "method", "call", "inside", "the", "context", "will", "be", "pipelined", ".", "Once", "the", "context", "is", "exited", "we", "execute", "the", ...
6b0cf260c775fd98c44b6703030d33004dabf67d
https://github.com/stephenmcd/hot-redis/blob/6b0cf260c775fd98c44b6703030d33004dabf67d/hot_redis/client.py#L78-L90
17,827
stephenmcd/hot-redis
hot_redis/client.py
HotClient._get_lua_path
def _get_lua_path(self, name): """ Joins the given name with the relative path of the module. """ parts = (os.path.dirname(os.path.abspath(__file__)), "lua", name) return os.path.join(*parts)
python
def _get_lua_path(self, name): """ Joins the given name with the relative path of the module. """ parts = (os.path.dirname(os.path.abspath(__file__)), "lua", name) return os.path.join(*parts)
[ "def", "_get_lua_path", "(", "self", ",", "name", ")", ":", "parts", "=", "(", "os", ".", "path", ".", "dirname", "(", "os", ".", "path", ".", "abspath", "(", "__file__", ")", ")", ",", "\"lua\"", ",", "name", ")", "return", "os", ".", "path", "....
Joins the given name with the relative path of the module.
[ "Joins", "the", "given", "name", "with", "the", "relative", "path", "of", "the", "module", "." ]
6b0cf260c775fd98c44b6703030d33004dabf67d
https://github.com/stephenmcd/hot-redis/blob/6b0cf260c775fd98c44b6703030d33004dabf67d/hot_redis/client.py#L27-L32
17,828
stephenmcd/hot-redis
hot_redis/client.py
HotClient._create_lua_method
def _create_lua_method(self, name, code): """ Registers the code snippet as a Lua script, and binds the script to the client as a method that can be called with the same signature as regular client methods, eg with a single key arg. """ script = self.register_scri...
python
def _create_lua_method(self, name, code): """ Registers the code snippet as a Lua script, and binds the script to the client as a method that can be called with the same signature as regular client methods, eg with a single key arg. """ script = self.register_scri...
[ "def", "_create_lua_method", "(", "self", ",", "name", ",", "code", ")", ":", "script", "=", "self", ".", "register_script", "(", "code", ")", "setattr", "(", "script", ",", "\"name\"", ",", "name", ")", "# Helps debugging redis lib.", "method", "=", "lambda...
Registers the code snippet as a Lua script, and binds the script to the client as a method that can be called with the same signature as regular client methods, eg with a single key arg.
[ "Registers", "the", "code", "snippet", "as", "a", "Lua", "script", "and", "binds", "the", "script", "to", "the", "client", "as", "a", "method", "that", "can", "be", "called", "with", "the", "same", "signature", "as", "regular", "client", "methods", "eg", ...
6b0cf260c775fd98c44b6703030d33004dabf67d
https://github.com/stephenmcd/hot-redis/blob/6b0cf260c775fd98c44b6703030d33004dabf67d/hot_redis/client.py#L47-L57
17,829
stephenmcd/hot-redis
hot_redis/types.py
value_left
def value_left(self, other): """ Returns the value of the other type instance to use in an operator method, namely when the method's instance is on the left side of the expression. """ return other.value if isinstance(other, self.__class__) else other
python
def value_left(self, other): """ Returns the value of the other type instance to use in an operator method, namely when the method's instance is on the left side of the expression. """ return other.value if isinstance(other, self.__class__) else other
[ "def", "value_left", "(", "self", ",", "other", ")", ":", "return", "other", ".", "value", "if", "isinstance", "(", "other", ",", "self", ".", "__class__", ")", "else", "other" ]
Returns the value of the other type instance to use in an operator method, namely when the method's instance is on the left side of the expression.
[ "Returns", "the", "value", "of", "the", "other", "type", "instance", "to", "use", "in", "an", "operator", "method", "namely", "when", "the", "method", "s", "instance", "is", "on", "the", "left", "side", "of", "the", "expression", "." ]
6b0cf260c775fd98c44b6703030d33004dabf67d
https://github.com/stephenmcd/hot-redis/blob/6b0cf260c775fd98c44b6703030d33004dabf67d/hot_redis/types.py#L28-L34
17,830
stephenmcd/hot-redis
hot_redis/types.py
value_right
def value_right(self, other): """ Returns the value of the type instance calling an to use in an operator method, namely when the method's instance is on the right side of the expression. """ return self if isinstance(other, self.__class__) else self.value
python
def value_right(self, other): """ Returns the value of the type instance calling an to use in an operator method, namely when the method's instance is on the right side of the expression. """ return self if isinstance(other, self.__class__) else self.value
[ "def", "value_right", "(", "self", ",", "other", ")", ":", "return", "self", "if", "isinstance", "(", "other", ",", "self", ".", "__class__", ")", "else", "self", ".", "value" ]
Returns the value of the type instance calling an to use in an operator method, namely when the method's instance is on the right side of the expression.
[ "Returns", "the", "value", "of", "the", "type", "instance", "calling", "an", "to", "use", "in", "an", "operator", "method", "namely", "when", "the", "method", "s", "instance", "is", "on", "the", "right", "side", "of", "the", "expression", "." ]
6b0cf260c775fd98c44b6703030d33004dabf67d
https://github.com/stephenmcd/hot-redis/blob/6b0cf260c775fd98c44b6703030d33004dabf67d/hot_redis/types.py#L37-L43
17,831
stephenmcd/hot-redis
hot_redis/types.py
op_left
def op_left(op): """ Returns a type instance method for the given operator, applied when the instance appears on the left side of the expression. """ def method(self, other): return op(self.value, value_left(self, other)) return method
python
def op_left(op): """ Returns a type instance method for the given operator, applied when the instance appears on the left side of the expression. """ def method(self, other): return op(self.value, value_left(self, other)) return method
[ "def", "op_left", "(", "op", ")", ":", "def", "method", "(", "self", ",", "other", ")", ":", "return", "op", "(", "self", ".", "value", ",", "value_left", "(", "self", ",", "other", ")", ")", "return", "method" ]
Returns a type instance method for the given operator, applied when the instance appears on the left side of the expression.
[ "Returns", "a", "type", "instance", "method", "for", "the", "given", "operator", "applied", "when", "the", "instance", "appears", "on", "the", "left", "side", "of", "the", "expression", "." ]
6b0cf260c775fd98c44b6703030d33004dabf67d
https://github.com/stephenmcd/hot-redis/blob/6b0cf260c775fd98c44b6703030d33004dabf67d/hot_redis/types.py#L46-L53
17,832
stephenmcd/hot-redis
hot_redis/types.py
op_right
def op_right(op): """ Returns a type instance method for the given operator, applied when the instance appears on the right side of the expression. """ def method(self, other): return op(value_left(self, other), value_right(self, other)) return method
python
def op_right(op): """ Returns a type instance method for the given operator, applied when the instance appears on the right side of the expression. """ def method(self, other): return op(value_left(self, other), value_right(self, other)) return method
[ "def", "op_right", "(", "op", ")", ":", "def", "method", "(", "self", ",", "other", ")", ":", "return", "op", "(", "value_left", "(", "self", ",", "other", ")", ",", "value_right", "(", "self", ",", "other", ")", ")", "return", "method" ]
Returns a type instance method for the given operator, applied when the instance appears on the right side of the expression.
[ "Returns", "a", "type", "instance", "method", "for", "the", "given", "operator", "applied", "when", "the", "instance", "appears", "on", "the", "right", "side", "of", "the", "expression", "." ]
6b0cf260c775fd98c44b6703030d33004dabf67d
https://github.com/stephenmcd/hot-redis/blob/6b0cf260c775fd98c44b6703030d33004dabf67d/hot_redis/types.py#L56-L63
17,833
jfhbrook/pyee
pyee/_base.py
BaseEventEmitter.on
def on(self, event, f=None): """Registers the function ``f`` to the event name ``event``. If ``f`` isn't provided, this method returns a function that takes ``f`` as a callback; in other words, you can use this method as a decorator, like so:: @ee.on('data') def...
python
def on(self, event, f=None): """Registers the function ``f`` to the event name ``event``. If ``f`` isn't provided, this method returns a function that takes ``f`` as a callback; in other words, you can use this method as a decorator, like so:: @ee.on('data') def...
[ "def", "on", "(", "self", ",", "event", ",", "f", "=", "None", ")", ":", "def", "_on", "(", "f", ")", ":", "self", ".", "_add_event_handler", "(", "event", ",", "f", ",", "f", ")", "return", "f", "if", "f", "is", "None", ":", "return", "_on", ...
Registers the function ``f`` to the event name ``event``. If ``f`` isn't provided, this method returns a function that takes ``f`` as a callback; in other words, you can use this method as a decorator, like so:: @ee.on('data') def data_handler(data): pri...
[ "Registers", "the", "function", "f", "to", "the", "event", "name", "event", "." ]
f5896239f421381e8b787c61c6185e33defb0292
https://github.com/jfhbrook/pyee/blob/f5896239f421381e8b787c61c6185e33defb0292/pyee/_base.py#L42-L65
17,834
jfhbrook/pyee
pyee/_base.py
BaseEventEmitter.once
def once(self, event, f=None): """The same as ``ee.on``, except that the listener is automatically removed after being called. """ def _wrapper(f): def g(*args, **kwargs): self.remove_listener(event, f) # f may return a coroutine, so we need to...
python
def once(self, event, f=None): """The same as ``ee.on``, except that the listener is automatically removed after being called. """ def _wrapper(f): def g(*args, **kwargs): self.remove_listener(event, f) # f may return a coroutine, so we need to...
[ "def", "once", "(", "self", ",", "event", ",", "f", "=", "None", ")", ":", "def", "_wrapper", "(", "f", ")", ":", "def", "g", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "remove_listener", "(", "event", ",", "f", ")", "#...
The same as ``ee.on``, except that the listener is automatically removed after being called.
[ "The", "same", "as", "ee", ".", "on", "except", "that", "the", "listener", "is", "automatically", "removed", "after", "being", "called", "." ]
f5896239f421381e8b787c61c6185e33defb0292
https://github.com/jfhbrook/pyee/blob/f5896239f421381e8b787c61c6185e33defb0292/pyee/_base.py#L110-L127
17,835
jfhbrook/pyee
pyee/_base.py
BaseEventEmitter.remove_all_listeners
def remove_all_listeners(self, event=None): """Remove all listeners attached to ``event``. If ``event`` is ``None``, remove all listeners on all events. """ if event is not None: self._events[event] = OrderedDict() else: self._events = defaultdict(OrderedD...
python
def remove_all_listeners(self, event=None): """Remove all listeners attached to ``event``. If ``event`` is ``None``, remove all listeners on all events. """ if event is not None: self._events[event] = OrderedDict() else: self._events = defaultdict(OrderedD...
[ "def", "remove_all_listeners", "(", "self", ",", "event", "=", "None", ")", ":", "if", "event", "is", "not", "None", ":", "self", ".", "_events", "[", "event", "]", "=", "OrderedDict", "(", ")", "else", ":", "self", ".", "_events", "=", "defaultdict", ...
Remove all listeners attached to ``event``. If ``event`` is ``None``, remove all listeners on all events.
[ "Remove", "all", "listeners", "attached", "to", "event", ".", "If", "event", "is", "None", "remove", "all", "listeners", "on", "all", "events", "." ]
f5896239f421381e8b787c61c6185e33defb0292
https://github.com/jfhbrook/pyee/blob/f5896239f421381e8b787c61c6185e33defb0292/pyee/_base.py#L133-L140
17,836
scott-griffiths/bitstring
bitstring.py
offsetcopy
def offsetcopy(s, newoffset): """Return a copy of a ByteStore with the newoffset. Not part of public interface. """ assert 0 <= newoffset < 8 if not s.bitlength: return copy.copy(s) else: if newoffset == s.offset % 8: return ByteStore(s.getbyteslice(s.byteoffset, s.b...
python
def offsetcopy(s, newoffset): """Return a copy of a ByteStore with the newoffset. Not part of public interface. """ assert 0 <= newoffset < 8 if not s.bitlength: return copy.copy(s) else: if newoffset == s.offset % 8: return ByteStore(s.getbyteslice(s.byteoffset, s.b...
[ "def", "offsetcopy", "(", "s", ",", "newoffset", ")", ":", "assert", "0", "<=", "newoffset", "<", "8", "if", "not", "s", ".", "bitlength", ":", "return", "copy", ".", "copy", "(", "s", ")", "else", ":", "if", "newoffset", "==", "s", ".", "offset", ...
Return a copy of a ByteStore with the newoffset. Not part of public interface.
[ "Return", "a", "copy", "of", "a", "ByteStore", "with", "the", "newoffset", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L248-L287
17,837
scott-griffiths/bitstring
bitstring.py
structparser
def structparser(token): """Parse struct-like format string token into sub-token list.""" m = STRUCT_PACK_RE.match(token) if not m: return [token] else: endian = m.group('endian') if endian is None: return [token] # Split the format string into a list of 'q', ...
python
def structparser(token): """Parse struct-like format string token into sub-token list.""" m = STRUCT_PACK_RE.match(token) if not m: return [token] else: endian = m.group('endian') if endian is None: return [token] # Split the format string into a list of 'q', ...
[ "def", "structparser", "(", "token", ")", ":", "m", "=", "STRUCT_PACK_RE", ".", "match", "(", "token", ")", "if", "not", "m", ":", "return", "[", "token", "]", "else", ":", "endian", "=", "m", ".", "group", "(", "'endian'", ")", "if", "endian", "is...
Parse struct-like format string token into sub-token list.
[ "Parse", "struct", "-", "like", "format", "string", "token", "into", "sub", "-", "token", "list", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L506-L532
17,838
scott-griffiths/bitstring
bitstring.py
tokenparser
def tokenparser(fmt, keys=None, token_cache={}): """Divide the format string into tokens and parse them. Return stretchy token and list of [initialiser, length, value] initialiser is one of: hex, oct, bin, uint, int, se, ue, 0x, 0o, 0b etc. length is None if not known, as is value. If the token is...
python
def tokenparser(fmt, keys=None, token_cache={}): """Divide the format string into tokens and parse them. Return stretchy token and list of [initialiser, length, value] initialiser is one of: hex, oct, bin, uint, int, se, ue, 0x, 0o, 0b etc. length is None if not known, as is value. If the token is...
[ "def", "tokenparser", "(", "fmt", ",", "keys", "=", "None", ",", "token_cache", "=", "{", "}", ")", ":", "try", ":", "return", "token_cache", "[", "(", "fmt", ",", "keys", ")", "]", "except", "KeyError", ":", "token_key", "=", "(", "fmt", ",", "key...
Divide the format string into tokens and parse them. Return stretchy token and list of [initialiser, length, value] initialiser is one of: hex, oct, bin, uint, int, se, ue, 0x, 0o, 0b etc. length is None if not known, as is value. If the token is in the keyword dictionary (keys) then it counts as a ...
[ "Divide", "the", "format", "string", "into", "tokens", "and", "parse", "them", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L534-L633
17,839
scott-griffiths/bitstring
bitstring.py
expand_brackets
def expand_brackets(s): """Remove whitespace and expand all brackets.""" s = ''.join(s.split()) while True: start = s.find('(') if start == -1: break count = 1 # Number of hanging open brackets p = start + 1 while p < len(s): if s[p] == '(': ...
python
def expand_brackets(s): """Remove whitespace and expand all brackets.""" s = ''.join(s.split()) while True: start = s.find('(') if start == -1: break count = 1 # Number of hanging open brackets p = start + 1 while p < len(s): if s[p] == '(': ...
[ "def", "expand_brackets", "(", "s", ")", ":", "s", "=", "''", ".", "join", "(", "s", ".", "split", "(", ")", ")", "while", "True", ":", "start", "=", "s", ".", "find", "(", "'('", ")", "if", "start", "==", "-", "1", ":", "break", "count", "="...
Remove whitespace and expand all brackets.
[ "Remove", "whitespace", "and", "expand", "all", "brackets", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L638-L667
17,840
scott-griffiths/bitstring
bitstring.py
pack
def pack(fmt, *values, **kwargs): """Pack the values according to the format string and return a new BitStream. fmt -- A single string or a list of strings with comma separated tokens describing how to create the BitStream. values -- Zero or more values to pack according to the format. kwarg...
python
def pack(fmt, *values, **kwargs): """Pack the values according to the format string and return a new BitStream. fmt -- A single string or a list of strings with comma separated tokens describing how to create the BitStream. values -- Zero or more values to pack according to the format. kwarg...
[ "def", "pack", "(", "fmt", ",", "*", "values", ",", "*", "*", "kwargs", ")", ":", "tokens", "=", "[", "]", "if", "isinstance", "(", "fmt", ",", "basestring", ")", ":", "fmt", "=", "[", "fmt", "]", "try", ":", "for", "f_item", "in", "fmt", ":", ...
Pack the values according to the format string and return a new BitStream. fmt -- A single string or a list of strings with comma separated tokens describing how to create the BitStream. values -- Zero or more values to pack according to the format. kwargs -- A dictionary or keyword-value pairs ...
[ "Pack", "the", "values", "according", "to", "the", "format", "string", "and", "return", "a", "new", "BitStream", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L4161-L4233
17,841
scott-griffiths/bitstring
bitstring.py
ConstByteStore.getbyteslice
def getbyteslice(self, start, end): """Direct access to byte data.""" c = self._rawarray[start:end] return c
python
def getbyteslice(self, start, end): """Direct access to byte data.""" c = self._rawarray[start:end] return c
[ "def", "getbyteslice", "(", "self", ",", "start", ",", "end", ")", ":", "c", "=", "self", ".", "_rawarray", "[", "start", ":", "end", "]", "return", "c" ]
Direct access to byte data.
[ "Direct", "access", "to", "byte", "data", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L157-L160
17,842
scott-griffiths/bitstring
bitstring.py
ConstByteStore._appendstore
def _appendstore(self, store): """Join another store on to the end of this one.""" if not store.bitlength: return # Set new array offset to the number of bits in the final byte of current array. store = offsetcopy(store, (self.offset + self.bitlength) % 8) if store.of...
python
def _appendstore(self, store): """Join another store on to the end of this one.""" if not store.bitlength: return # Set new array offset to the number of bits in the final byte of current array. store = offsetcopy(store, (self.offset + self.bitlength) % 8) if store.of...
[ "def", "_appendstore", "(", "self", ",", "store", ")", ":", "if", "not", "store", ".", "bitlength", ":", "return", "# Set new array offset to the number of bits in the final byte of current array.", "store", "=", "offsetcopy", "(", "store", ",", "(", "self", ".", "o...
Join another store on to the end of this one.
[ "Join", "another", "store", "on", "to", "the", "end", "of", "this", "one", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L173-L187
17,843
scott-griffiths/bitstring
bitstring.py
ConstByteStore._prependstore
def _prependstore(self, store): """Join another store on to the start of this one.""" if not store.bitlength: return # Set the offset of copy of store so that it's final byte # ends in a position that matches the offset of self, # then join self on to the end of i...
python
def _prependstore(self, store): """Join another store on to the start of this one.""" if not store.bitlength: return # Set the offset of copy of store so that it's final byte # ends in a position that matches the offset of self, # then join self on to the end of i...
[ "def", "_prependstore", "(", "self", ",", "store", ")", ":", "if", "not", "store", ".", "bitlength", ":", "return", "# Set the offset of copy of store so that it's final byte", "# ends in a position that matches the offset of self,", "# then join self on to the end of it.", "stor...
Join another store on to the start of this one.
[ "Join", "another", "store", "on", "to", "the", "start", "of", "this", "one", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L189-L208
17,844
scott-griffiths/bitstring
bitstring.py
Bits._assertsanity
def _assertsanity(self): """Check internal self consistency as a debugging aid.""" assert self.len >= 0 assert 0 <= self._offset, "offset={0}".format(self._offset) assert (self.len + self._offset + 7) // 8 == self._datastore.bytelength + self._datastore.byteoffset return True
python
def _assertsanity(self): """Check internal self consistency as a debugging aid.""" assert self.len >= 0 assert 0 <= self._offset, "offset={0}".format(self._offset) assert (self.len + self._offset + 7) // 8 == self._datastore.bytelength + self._datastore.byteoffset return True
[ "def", "_assertsanity", "(", "self", ")", ":", "assert", "self", ".", "len", ">=", "0", "assert", "0", "<=", "self", ".", "_offset", ",", "\"offset={0}\"", ".", "format", "(", "self", ".", "_offset", ")", "assert", "(", "self", ".", "len", "+", "self...
Check internal self consistency as a debugging aid.
[ "Check", "internal", "self", "consistency", "as", "a", "debugging", "aid", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1195-L1200
17,845
scott-griffiths/bitstring
bitstring.py
Bits._setauto
def _setauto(self, s, length, offset): """Set bitstring from a bitstring, file, bool, integer, array, iterable or string.""" # As s can be so many different things it's important to do the checks # in the correct order, as some types are also other allowed types. # So basestring must be ...
python
def _setauto(self, s, length, offset): """Set bitstring from a bitstring, file, bool, integer, array, iterable or string.""" # As s can be so many different things it's important to do the checks # in the correct order, as some types are also other allowed types. # So basestring must be ...
[ "def", "_setauto", "(", "self", ",", "s", ",", "length", ",", "offset", ")", ":", "# As s can be so many different things it's important to do the checks", "# in the correct order, as some types are also other allowed types.", "# So basestring must be checked before Iterable", "# and b...
Set bitstring from a bitstring, file, bool, integer, array, iterable or string.
[ "Set", "bitstring", "from", "a", "bitstring", "file", "bool", "integer", "array", "iterable", "or", "string", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1245-L1297
17,846
scott-griffiths/bitstring
bitstring.py
Bits._setfile
def _setfile(self, filename, length, offset): """Use file as source of bits.""" source = open(filename, 'rb') if offset is None: offset = 0 if length is None: length = os.path.getsize(source.name) * 8 - offset byteoffset, offset = divmod(offset, 8) ...
python
def _setfile(self, filename, length, offset): """Use file as source of bits.""" source = open(filename, 'rb') if offset is None: offset = 0 if length is None: length = os.path.getsize(source.name) * 8 - offset byteoffset, offset = divmod(offset, 8) ...
[ "def", "_setfile", "(", "self", ",", "filename", ",", "length", ",", "offset", ")", ":", "source", "=", "open", "(", "filename", ",", "'rb'", ")", "if", "offset", "is", "None", ":", "offset", "=", "0", "if", "length", "is", "None", ":", "length", "...
Use file as source of bits.
[ "Use", "file", "as", "source", "of", "bits", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1299-L1312
17,847
scott-griffiths/bitstring
bitstring.py
Bits._setbytes_safe
def _setbytes_safe(self, data, length=None, offset=0): """Set the data from a string.""" data = bytearray(data) if length is None: # Use to the end of the data length = len(data)*8 - offset self._datastore = ByteStore(data, length, offset) else: ...
python
def _setbytes_safe(self, data, length=None, offset=0): """Set the data from a string.""" data = bytearray(data) if length is None: # Use to the end of the data length = len(data)*8 - offset self._datastore = ByteStore(data, length, offset) else: ...
[ "def", "_setbytes_safe", "(", "self", ",", "data", ",", "length", "=", "None", ",", "offset", "=", "0", ")", ":", "data", "=", "bytearray", "(", "data", ")", "if", "length", "is", "None", ":", "# Use to the end of the data", "length", "=", "len", "(", ...
Set the data from a string.
[ "Set", "the", "data", "from", "a", "string", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1314-L1328
17,848
scott-griffiths/bitstring
bitstring.py
Bits._setbytes_unsafe
def _setbytes_unsafe(self, data, length, offset): """Unchecked version of _setbytes_safe.""" self._datastore = ByteStore(data[:], length, offset) assert self._assertsanity()
python
def _setbytes_unsafe(self, data, length, offset): """Unchecked version of _setbytes_safe.""" self._datastore = ByteStore(data[:], length, offset) assert self._assertsanity()
[ "def", "_setbytes_unsafe", "(", "self", ",", "data", ",", "length", ",", "offset", ")", ":", "self", ".", "_datastore", "=", "ByteStore", "(", "data", "[", ":", "]", ",", "length", ",", "offset", ")", "assert", "self", ".", "_assertsanity", "(", ")" ]
Unchecked version of _setbytes_safe.
[ "Unchecked", "version", "of", "_setbytes_safe", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1330-L1333
17,849
scott-griffiths/bitstring
bitstring.py
Bits._readbytes
def _readbytes(self, length, start): """Read bytes and return them. Note that length is in bits.""" assert length % 8 == 0 assert start + length <= self.len if not (start + self._offset) % 8: return bytes(self._datastore.getbyteslice((start + self._offset) // 8, ...
python
def _readbytes(self, length, start): """Read bytes and return them. Note that length is in bits.""" assert length % 8 == 0 assert start + length <= self.len if not (start + self._offset) % 8: return bytes(self._datastore.getbyteslice((start + self._offset) // 8, ...
[ "def", "_readbytes", "(", "self", ",", "length", ",", "start", ")", ":", "assert", "length", "%", "8", "==", "0", "assert", "start", "+", "length", "<=", "self", ".", "len", "if", "not", "(", "start", "+", "self", ".", "_offset", ")", "%", "8", "...
Read bytes and return them. Note that length is in bits.
[ "Read", "bytes", "and", "return", "them", ".", "Note", "that", "length", "is", "in", "bits", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1335-L1342
17,850
scott-griffiths/bitstring
bitstring.py
Bits._setuint
def _setuint(self, uint, length=None): """Reset the bitstring to have given unsigned int interpretation.""" try: if length is None: # Use the whole length. Deliberately not using .len here. length = self._datastore.bitlength except AttributeError: ...
python
def _setuint(self, uint, length=None): """Reset the bitstring to have given unsigned int interpretation.""" try: if length is None: # Use the whole length. Deliberately not using .len here. length = self._datastore.bitlength except AttributeError: ...
[ "def", "_setuint", "(", "self", ",", "uint", ",", "length", "=", "None", ")", ":", "try", ":", "if", "length", "is", "None", ":", "# Use the whole length. Deliberately not using .len here.", "length", "=", "self", ".", "_datastore", ".", "bitlength", "except", ...
Reset the bitstring to have given unsigned int interpretation.
[ "Reset", "the", "bitstring", "to", "have", "given", "unsigned", "int", "interpretation", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1351-L1386
17,851
scott-griffiths/bitstring
bitstring.py
Bits._readuint
def _readuint(self, length, start): """Read bits and interpret as an unsigned int.""" if not length: raise InterpretError("Cannot interpret a zero length bitstring " "as an integer.") offset = self._offset startbyte = (start + offset...
python
def _readuint(self, length, start): """Read bits and interpret as an unsigned int.""" if not length: raise InterpretError("Cannot interpret a zero length bitstring " "as an integer.") offset = self._offset startbyte = (start + offset...
[ "def", "_readuint", "(", "self", ",", "length", ",", "start", ")", ":", "if", "not", "length", ":", "raise", "InterpretError", "(", "\"Cannot interpret a zero length bitstring \"", "\"as an integer.\"", ")", "offset", "=", "self", ".", "_offset", "startbyte", "=",...
Read bits and interpret as an unsigned int.
[ "Read", "bits", "and", "interpret", "as", "an", "unsigned", "int", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1388-L1404
17,852
scott-griffiths/bitstring
bitstring.py
Bits._setint
def _setint(self, int_, length=None): """Reset the bitstring to have given signed int interpretation.""" # If no length given, and we've previously been given a length, use it. if length is None and hasattr(self, 'len') and self.len != 0: length = self.len if length is None o...
python
def _setint(self, int_, length=None): """Reset the bitstring to have given signed int interpretation.""" # If no length given, and we've previously been given a length, use it. if length is None and hasattr(self, 'len') and self.len != 0: length = self.len if length is None o...
[ "def", "_setint", "(", "self", ",", "int_", ",", "length", "=", "None", ")", ":", "# If no length given, and we've previously been given a length, use it.", "if", "length", "is", "None", "and", "hasattr", "(", "self", ",", "'len'", ")", "and", "self", ".", "len"...
Reset the bitstring to have given signed int interpretation.
[ "Reset", "the", "bitstring", "to", "have", "given", "signed", "int", "interpretation", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1410-L1431
17,853
scott-griffiths/bitstring
bitstring.py
Bits._readint
def _readint(self, length, start): """Read bits and interpret as a signed int""" ui = self._readuint(length, start) if not ui >> (length - 1): # Top bit not set, number is positive return ui # Top bit is set, so number is negative tmp = (~(ui - 1)) & ((1 <...
python
def _readint(self, length, start): """Read bits and interpret as a signed int""" ui = self._readuint(length, start) if not ui >> (length - 1): # Top bit not set, number is positive return ui # Top bit is set, so number is negative tmp = (~(ui - 1)) & ((1 <...
[ "def", "_readint", "(", "self", ",", "length", ",", "start", ")", ":", "ui", "=", "self", ".", "_readuint", "(", "length", ",", "start", ")", "if", "not", "ui", ">>", "(", "length", "-", "1", ")", ":", "# Top bit not set, number is positive", "return", ...
Read bits and interpret as a signed int
[ "Read", "bits", "and", "interpret", "as", "a", "signed", "int" ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1433-L1441
17,854
scott-griffiths/bitstring
bitstring.py
Bits._setuintbe
def _setuintbe(self, uintbe, length=None): """Set the bitstring to a big-endian unsigned int interpretation.""" if length is not None and length % 8 != 0: raise CreationError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) self...
python
def _setuintbe(self, uintbe, length=None): """Set the bitstring to a big-endian unsigned int interpretation.""" if length is not None and length % 8 != 0: raise CreationError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) self...
[ "def", "_setuintbe", "(", "self", ",", "uintbe", ",", "length", "=", "None", ")", ":", "if", "length", "is", "not", "None", "and", "length", "%", "8", "!=", "0", ":", "raise", "CreationError", "(", "\"Big-endian integers must be whole-byte. \"", "\"Length = {0...
Set the bitstring to a big-endian unsigned int interpretation.
[ "Set", "the", "bitstring", "to", "a", "big", "-", "endian", "unsigned", "int", "interpretation", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1447-L1452
17,855
scott-griffiths/bitstring
bitstring.py
Bits._readuintbe
def _readuintbe(self, length, start): """Read bits and interpret as a big-endian unsigned int.""" if length % 8: raise InterpretError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) return self._readuint(length, start)
python
def _readuintbe(self, length, start): """Read bits and interpret as a big-endian unsigned int.""" if length % 8: raise InterpretError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) return self._readuint(length, start)
[ "def", "_readuintbe", "(", "self", ",", "length", ",", "start", ")", ":", "if", "length", "%", "8", ":", "raise", "InterpretError", "(", "\"Big-endian integers must be whole-byte. \"", "\"Length = {0} bits.\"", ",", "length", ")", "return", "self", ".", "_readuint...
Read bits and interpret as a big-endian unsigned int.
[ "Read", "bits", "and", "interpret", "as", "a", "big", "-", "endian", "unsigned", "int", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1454-L1459
17,856
scott-griffiths/bitstring
bitstring.py
Bits._setintbe
def _setintbe(self, intbe, length=None): """Set bitstring to a big-endian signed int interpretation.""" if length is not None and length % 8 != 0: raise CreationError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) self._setint...
python
def _setintbe(self, intbe, length=None): """Set bitstring to a big-endian signed int interpretation.""" if length is not None and length % 8 != 0: raise CreationError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) self._setint...
[ "def", "_setintbe", "(", "self", ",", "intbe", ",", "length", "=", "None", ")", ":", "if", "length", "is", "not", "None", "and", "length", "%", "8", "!=", "0", ":", "raise", "CreationError", "(", "\"Big-endian integers must be whole-byte. \"", "\"Length = {0} ...
Set bitstring to a big-endian signed int interpretation.
[ "Set", "bitstring", "to", "a", "big", "-", "endian", "signed", "int", "interpretation", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1465-L1470
17,857
scott-griffiths/bitstring
bitstring.py
Bits._readintbe
def _readintbe(self, length, start): """Read bits and interpret as a big-endian signed int.""" if length % 8: raise InterpretError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) return self._readint(length, start)
python
def _readintbe(self, length, start): """Read bits and interpret as a big-endian signed int.""" if length % 8: raise InterpretError("Big-endian integers must be whole-byte. " "Length = {0} bits.", length) return self._readint(length, start)
[ "def", "_readintbe", "(", "self", ",", "length", ",", "start", ")", ":", "if", "length", "%", "8", ":", "raise", "InterpretError", "(", "\"Big-endian integers must be whole-byte. \"", "\"Length = {0} bits.\"", ",", "length", ")", "return", "self", ".", "_readint",...
Read bits and interpret as a big-endian signed int.
[ "Read", "bits", "and", "interpret", "as", "a", "big", "-", "endian", "signed", "int", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1472-L1477
17,858
scott-griffiths/bitstring
bitstring.py
Bits._readuintle
def _readuintle(self, length, start): """Read bits and interpret as a little-endian unsigned int.""" if length % 8: raise InterpretError("Little-endian integers must be whole-byte. " "Length = {0} bits.", length) assert start + length <= self.len ...
python
def _readuintle(self, length, start): """Read bits and interpret as a little-endian unsigned int.""" if length % 8: raise InterpretError("Little-endian integers must be whole-byte. " "Length = {0} bits.", length) assert start + length <= self.len ...
[ "def", "_readuintle", "(", "self", ",", "length", ",", "start", ")", ":", "if", "length", "%", "8", ":", "raise", "InterpretError", "(", "\"Little-endian integers must be whole-byte. \"", "\"Length = {0} bits.\"", ",", "length", ")", "assert", "start", "+", "lengt...
Read bits and interpret as a little-endian unsigned int.
[ "Read", "bits", "and", "interpret", "as", "a", "little", "-", "endian", "unsigned", "int", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1490-L1516
17,859
scott-griffiths/bitstring
bitstring.py
Bits._readintle
def _readintle(self, length, start): """Read bits and interpret as a little-endian signed int.""" ui = self._readuintle(length, start) if not ui >> (length - 1): # Top bit not set, number is positive return ui # Top bit is set, so number is negative tmp = ...
python
def _readintle(self, length, start): """Read bits and interpret as a little-endian signed int.""" ui = self._readuintle(length, start) if not ui >> (length - 1): # Top bit not set, number is positive return ui # Top bit is set, so number is negative tmp = ...
[ "def", "_readintle", "(", "self", ",", "length", ",", "start", ")", ":", "ui", "=", "self", ".", "_readuintle", "(", "length", ",", "start", ")", "if", "not", "ui", ">>", "(", "length", "-", "1", ")", ":", "# Top bit not set, number is positive", "return...
Read bits and interpret as a little-endian signed int.
[ "Read", "bits", "and", "interpret", "as", "a", "little", "-", "endian", "signed", "int", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1528-L1536
17,860
scott-griffiths/bitstring
bitstring.py
Bits._readfloat
def _readfloat(self, length, start): """Read bits and interpret as a float.""" if not (start + self._offset) % 8: startbyte = (start + self._offset) // 8 if length == 32: f, = struct.unpack('>f', bytes(self._datastore.getbyteslice(startbyte, startbyte + 4))) ...
python
def _readfloat(self, length, start): """Read bits and interpret as a float.""" if not (start + self._offset) % 8: startbyte = (start + self._offset) // 8 if length == 32: f, = struct.unpack('>f', bytes(self._datastore.getbyteslice(startbyte, startbyte + 4))) ...
[ "def", "_readfloat", "(", "self", ",", "length", ",", "start", ")", ":", "if", "not", "(", "start", "+", "self", ".", "_offset", ")", "%", "8", ":", "startbyte", "=", "(", "start", "+", "self", ".", "_offset", ")", "//", "8", "if", "length", "=="...
Read bits and interpret as a float.
[ "Read", "bits", "and", "interpret", "as", "a", "float", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1557-L1573
17,861
scott-griffiths/bitstring
bitstring.py
Bits._readfloatle
def _readfloatle(self, length, start): """Read bits and interpret as a little-endian float.""" startbyte, offset = divmod(start + self._offset, 8) if not offset: if length == 32: f, = struct.unpack('<f', bytes(self._datastore.getbyteslice(startbyte, startbyte + 4))) ...
python
def _readfloatle(self, length, start): """Read bits and interpret as a little-endian float.""" startbyte, offset = divmod(start + self._offset, 8) if not offset: if length == 32: f, = struct.unpack('<f', bytes(self._datastore.getbyteslice(startbyte, startbyte + 4))) ...
[ "def", "_readfloatle", "(", "self", ",", "length", ",", "start", ")", ":", "startbyte", ",", "offset", "=", "divmod", "(", "start", "+", "self", ".", "_offset", ",", "8", ")", "if", "not", "offset", ":", "if", "length", "==", "32", ":", "f", ",", ...
Read bits and interpret as a little-endian float.
[ "Read", "bits", "and", "interpret", "as", "a", "little", "-", "endian", "float", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1595-L1612
17,862
scott-griffiths/bitstring
bitstring.py
Bits._setue
def _setue(self, i): """Initialise bitstring with unsigned exponential-Golomb code for integer i. Raises CreationError if i < 0. """ if i < 0: raise CreationError("Cannot use negative initialiser for unsigned " "exponential-Golomb.") ...
python
def _setue(self, i): """Initialise bitstring with unsigned exponential-Golomb code for integer i. Raises CreationError if i < 0. """ if i < 0: raise CreationError("Cannot use negative initialiser for unsigned " "exponential-Golomb.") ...
[ "def", "_setue", "(", "self", ",", "i", ")", ":", "if", "i", "<", "0", ":", "raise", "CreationError", "(", "\"Cannot use negative initialiser for unsigned \"", "\"exponential-Golomb.\"", ")", "if", "not", "i", ":", "self", ".", "_setbin_unsafe", "(", "'1'", ")...
Initialise bitstring with unsigned exponential-Golomb code for integer i. Raises CreationError if i < 0.
[ "Initialise", "bitstring", "with", "unsigned", "exponential", "-", "Golomb", "code", "for", "integer", "i", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1618-L1638
17,863
scott-griffiths/bitstring
bitstring.py
Bits._readue
def _readue(self, pos): """Return interpretation of next bits as unsigned exponential-Golomb code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ oldpos = pos try: while not self[pos]: pos += 1 ...
python
def _readue(self, pos): """Return interpretation of next bits as unsigned exponential-Golomb code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ oldpos = pos try: while not self[pos]: pos += 1 ...
[ "def", "_readue", "(", "self", ",", "pos", ")", ":", "oldpos", "=", "pos", "try", ":", "while", "not", "self", "[", "pos", "]", ":", "pos", "+=", "1", "except", "IndexError", ":", "raise", "ReadError", "(", "\"Read off end of bitstring trying to read code.\"...
Return interpretation of next bits as unsigned exponential-Golomb code. Raises ReadError if the end of the bitstring is encountered while reading the code.
[ "Return", "interpretation", "of", "next", "bits", "as", "unsigned", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1640-L1663
17,864
scott-griffiths/bitstring
bitstring.py
Bits._getue
def _getue(self): """Return data as unsigned exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readue(0) if value is None or newpos != self.len: raise ReadError ...
python
def _getue(self): """Return data as unsigned exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readue(0) if value is None or newpos != self.len: raise ReadError ...
[ "def", "_getue", "(", "self", ")", ":", "try", ":", "value", ",", "newpos", "=", "self", ".", "_readue", "(", "0", ")", "if", "value", "is", "None", "or", "newpos", "!=", "self", ".", "len", ":", "raise", "ReadError", "except", "ReadError", ":", "r...
Return data as unsigned exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code.
[ "Return", "data", "as", "unsigned", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1665-L1677
17,865
scott-griffiths/bitstring
bitstring.py
Bits._setse
def _setse(self, i): """Initialise bitstring with signed exponential-Golomb code for integer i.""" if i > 0: u = (i * 2) - 1 else: u = -2 * i self._setue(u)
python
def _setse(self, i): """Initialise bitstring with signed exponential-Golomb code for integer i.""" if i > 0: u = (i * 2) - 1 else: u = -2 * i self._setue(u)
[ "def", "_setse", "(", "self", ",", "i", ")", ":", "if", "i", ">", "0", ":", "u", "=", "(", "i", "*", "2", ")", "-", "1", "else", ":", "u", "=", "-", "2", "*", "i", "self", ".", "_setue", "(", "u", ")" ]
Initialise bitstring with signed exponential-Golomb code for integer i.
[ "Initialise", "bitstring", "with", "signed", "exponential", "-", "Golomb", "code", "for", "integer", "i", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1679-L1685
17,866
scott-griffiths/bitstring
bitstring.py
Bits._getse
def _getse(self): """Return data as signed exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readse(0) if value is None or newpos != self.len: raise ReadError ...
python
def _getse(self): """Return data as signed exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readse(0) if value is None or newpos != self.len: raise ReadError ...
[ "def", "_getse", "(", "self", ")", ":", "try", ":", "value", ",", "newpos", "=", "self", ".", "_readse", "(", "0", ")", "if", "value", "is", "None", "or", "newpos", "!=", "self", ".", "len", ":", "raise", "ReadError", "except", "ReadError", ":", "r...
Return data as signed exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code.
[ "Return", "data", "as", "signed", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1687-L1699
17,867
scott-griffiths/bitstring
bitstring.py
Bits._readse
def _readse(self, pos): """Return interpretation of next bits as a signed exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ codenum, pos = self._readue(pos) ...
python
def _readse(self, pos): """Return interpretation of next bits as a signed exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ codenum, pos = self._readue(pos) ...
[ "def", "_readse", "(", "self", ",", "pos", ")", ":", "codenum", ",", "pos", "=", "self", ".", "_readue", "(", "pos", ")", "m", "=", "(", "codenum", "+", "1", ")", "//", "2", "if", "not", "codenum", "%", "2", ":", "return", "-", "m", ",", "pos...
Return interpretation of next bits as a signed exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code.
[ "Return", "interpretation", "of", "next", "bits", "as", "a", "signed", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1701-L1715
17,868
scott-griffiths/bitstring
bitstring.py
Bits._setuie
def _setuie(self, i): """Initialise bitstring with unsigned interleaved exponential-Golomb code for integer i. Raises CreationError if i < 0. """ if i < 0: raise CreationError("Cannot use negative initialiser for unsigned " "interleaved expon...
python
def _setuie(self, i): """Initialise bitstring with unsigned interleaved exponential-Golomb code for integer i. Raises CreationError if i < 0. """ if i < 0: raise CreationError("Cannot use negative initialiser for unsigned " "interleaved expon...
[ "def", "_setuie", "(", "self", ",", "i", ")", ":", "if", "i", "<", "0", ":", "raise", "CreationError", "(", "\"Cannot use negative initialiser for unsigned \"", "\"interleaved exponential-Golomb.\"", ")", "self", ".", "_setbin_unsafe", "(", "'1'", "if", "i", "==",...
Initialise bitstring with unsigned interleaved exponential-Golomb code for integer i. Raises CreationError if i < 0.
[ "Initialise", "bitstring", "with", "unsigned", "interleaved", "exponential", "-", "Golomb", "code", "for", "integer", "i", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1717-L1726
17,869
scott-griffiths/bitstring
bitstring.py
Bits._getuie
def _getuie(self): """Return data as unsigned interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readuie(0) if value is None or newpos != self.len: raise...
python
def _getuie(self): """Return data as unsigned interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readuie(0) if value is None or newpos != self.len: raise...
[ "def", "_getuie", "(", "self", ")", ":", "try", ":", "value", ",", "newpos", "=", "self", ".", "_readuie", "(", "0", ")", "if", "value", "is", "None", "or", "newpos", "!=", "self", ".", "len", ":", "raise", "ReadError", "except", "ReadError", ":", ...
Return data as unsigned interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code.
[ "Return", "data", "as", "unsigned", "interleaved", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1748-L1760
17,870
scott-griffiths/bitstring
bitstring.py
Bits._setsie
def _setsie(self, i): """Initialise bitstring with signed interleaved exponential-Golomb code for integer i.""" if not i: self._setbin_unsafe('1') else: self._setuie(abs(i)) self._append(Bits([i < 0]))
python
def _setsie(self, i): """Initialise bitstring with signed interleaved exponential-Golomb code for integer i.""" if not i: self._setbin_unsafe('1') else: self._setuie(abs(i)) self._append(Bits([i < 0]))
[ "def", "_setsie", "(", "self", ",", "i", ")", ":", "if", "not", "i", ":", "self", ".", "_setbin_unsafe", "(", "'1'", ")", "else", ":", "self", ".", "_setuie", "(", "abs", "(", "i", ")", ")", "self", ".", "_append", "(", "Bits", "(", "[", "i", ...
Initialise bitstring with signed interleaved exponential-Golomb code for integer i.
[ "Initialise", "bitstring", "with", "signed", "interleaved", "exponential", "-", "Golomb", "code", "for", "integer", "i", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1762-L1768
17,871
scott-griffiths/bitstring
bitstring.py
Bits._getsie
def _getsie(self): """Return data as signed interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readsie(0) if value is None or newpos != self.len: raise R...
python
def _getsie(self): """Return data as signed interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code. """ try: value, newpos = self._readsie(0) if value is None or newpos != self.len: raise R...
[ "def", "_getsie", "(", "self", ")", ":", "try", ":", "value", ",", "newpos", "=", "self", ".", "_readsie", "(", "0", ")", "if", "value", "is", "None", "or", "newpos", "!=", "self", ".", "len", ":", "raise", "ReadError", "except", "ReadError", ":", ...
Return data as signed interleaved exponential-Golomb code. Raises InterpretError if bitstring is not a single exponential-Golomb code.
[ "Return", "data", "as", "signed", "interleaved", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1770-L1782
17,872
scott-griffiths/bitstring
bitstring.py
Bits._readsie
def _readsie(self, pos): """Return interpretation of next bits as a signed interleaved exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ codenum, pos = self._readui...
python
def _readsie(self, pos): """Return interpretation of next bits as a signed interleaved exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code. """ codenum, pos = self._readui...
[ "def", "_readsie", "(", "self", ",", "pos", ")", ":", "codenum", ",", "pos", "=", "self", ".", "_readuie", "(", "pos", ")", "if", "not", "codenum", ":", "return", "0", ",", "pos", "try", ":", "if", "self", "[", "pos", "]", ":", "return", "-", "...
Return interpretation of next bits as a signed interleaved exponential-Golomb code. Advances position to after the read code. Raises ReadError if the end of the bitstring is encountered while reading the code.
[ "Return", "interpretation", "of", "next", "bits", "as", "a", "signed", "interleaved", "exponential", "-", "Golomb", "code", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1784-L1802
17,873
scott-griffiths/bitstring
bitstring.py
Bits._setbin_safe
def _setbin_safe(self, binstring): """Reset the bitstring to the value given in binstring.""" binstring = tidy_input_string(binstring) # remove any 0b if present binstring = binstring.replace('0b', '') self._setbin_unsafe(binstring)
python
def _setbin_safe(self, binstring): """Reset the bitstring to the value given in binstring.""" binstring = tidy_input_string(binstring) # remove any 0b if present binstring = binstring.replace('0b', '') self._setbin_unsafe(binstring)
[ "def", "_setbin_safe", "(", "self", ",", "binstring", ")", ":", "binstring", "=", "tidy_input_string", "(", "binstring", ")", "# remove any 0b if present", "binstring", "=", "binstring", ".", "replace", "(", "'0b'", ",", "''", ")", "self", ".", "_setbin_unsafe",...
Reset the bitstring to the value given in binstring.
[ "Reset", "the", "bitstring", "to", "the", "value", "given", "in", "binstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1823-L1828
17,874
scott-griffiths/bitstring
bitstring.py
Bits._setbin_unsafe
def _setbin_unsafe(self, binstring): """Same as _setbin_safe, but input isn't sanity checked. binstring mustn't start with '0b'.""" length = len(binstring) # pad with zeros up to byte boundary if needed boundary = ((length + 7) // 8) * 8 padded_binstring = binstring + '0' * (boun...
python
def _setbin_unsafe(self, binstring): """Same as _setbin_safe, but input isn't sanity checked. binstring mustn't start with '0b'.""" length = len(binstring) # pad with zeros up to byte boundary if needed boundary = ((length + 7) // 8) * 8 padded_binstring = binstring + '0' * (boun...
[ "def", "_setbin_unsafe", "(", "self", ",", "binstring", ")", ":", "length", "=", "len", "(", "binstring", ")", "# pad with zeros up to byte boundary if needed", "boundary", "=", "(", "(", "length", "+", "7", ")", "//", "8", ")", "*", "8", "padded_binstring", ...
Same as _setbin_safe, but input isn't sanity checked. binstring mustn't start with '0b'.
[ "Same", "as", "_setbin_safe", "but", "input", "isn", "t", "sanity", "checked", ".", "binstring", "mustn", "t", "start", "with", "0b", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1830-L1842
17,875
scott-griffiths/bitstring
bitstring.py
Bits._readbin
def _readbin(self, length, start): """Read bits and interpret as a binary string.""" if not length: return '' # Get the byte slice containing our bit slice startbyte, startoffset = divmod(start + self._offset, 8) endbyte = (start + self._offset + length - 1) // 8 ...
python
def _readbin(self, length, start): """Read bits and interpret as a binary string.""" if not length: return '' # Get the byte slice containing our bit slice startbyte, startoffset = divmod(start + self._offset, 8) endbyte = (start + self._offset + length - 1) // 8 ...
[ "def", "_readbin", "(", "self", ",", "length", ",", "start", ")", ":", "if", "not", "length", ":", "return", "''", "# Get the byte slice containing our bit slice", "startbyte", ",", "startoffset", "=", "divmod", "(", "start", "+", "self", ".", "_offset", ",", ...
Read bits and interpret as a binary string.
[ "Read", "bits", "and", "interpret", "as", "a", "binary", "string", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1844-L1859
17,876
scott-griffiths/bitstring
bitstring.py
Bits._setoct
def _setoct(self, octstring): """Reset the bitstring to have the value given in octstring.""" octstring = tidy_input_string(octstring) # remove any 0o if present octstring = octstring.replace('0o', '') binlist = [] for i in octstring: try: if n...
python
def _setoct(self, octstring): """Reset the bitstring to have the value given in octstring.""" octstring = tidy_input_string(octstring) # remove any 0o if present octstring = octstring.replace('0o', '') binlist = [] for i in octstring: try: if n...
[ "def", "_setoct", "(", "self", ",", "octstring", ")", ":", "octstring", "=", "tidy_input_string", "(", "octstring", ")", "# remove any 0o if present", "octstring", "=", "octstring", ".", "replace", "(", "'0o'", ",", "''", ")", "binlist", "=", "[", "]", "for"...
Reset the bitstring to have the value given in octstring.
[ "Reset", "the", "bitstring", "to", "have", "the", "value", "given", "in", "octstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1865-L1878
17,877
scott-griffiths/bitstring
bitstring.py
Bits._readoct
def _readoct(self, length, start): """Read bits and interpret as an octal string.""" if length % 3: raise InterpretError("Cannot convert to octal unambiguously - " "not multiple of 3 bits.") if not length: return '' # Get main octa...
python
def _readoct(self, length, start): """Read bits and interpret as an octal string.""" if length % 3: raise InterpretError("Cannot convert to octal unambiguously - " "not multiple of 3 bits.") if not length: return '' # Get main octa...
[ "def", "_readoct", "(", "self", ",", "length", ",", "start", ")", ":", "if", "length", "%", "3", ":", "raise", "InterpretError", "(", "\"Cannot convert to octal unambiguously - \"", "\"not multiple of 3 bits.\"", ")", "if", "not", "length", ":", "return", "''", ...
Read bits and interpret as an octal string.
[ "Read", "bits", "and", "interpret", "as", "an", "octal", "string", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1880-L1893
17,878
scott-griffiths/bitstring
bitstring.py
Bits._sethex
def _sethex(self, hexstring): """Reset the bitstring to have the value given in hexstring.""" hexstring = tidy_input_string(hexstring) # remove any 0x if present hexstring = hexstring.replace('0x', '') length = len(hexstring) if length % 2: hexstring += '0' ...
python
def _sethex(self, hexstring): """Reset the bitstring to have the value given in hexstring.""" hexstring = tidy_input_string(hexstring) # remove any 0x if present hexstring = hexstring.replace('0x', '') length = len(hexstring) if length % 2: hexstring += '0' ...
[ "def", "_sethex", "(", "self", ",", "hexstring", ")", ":", "hexstring", "=", "tidy_input_string", "(", "hexstring", ")", "# remove any 0x if present", "hexstring", "=", "hexstring", ".", "replace", "(", "'0x'", ",", "''", ")", "length", "=", "len", "(", "hex...
Reset the bitstring to have the value given in hexstring.
[ "Reset", "the", "bitstring", "to", "have", "the", "value", "given", "in", "hexstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1899-L1915
17,879
scott-griffiths/bitstring
bitstring.py
Bits._readhex
def _readhex(self, length, start): """Read bits and interpret as a hex string.""" if length % 4: raise InterpretError("Cannot convert to hex unambiguously - " "not multiple of 4 bits.") if not length: return '' s = self._...
python
def _readhex(self, length, start): """Read bits and interpret as a hex string.""" if length % 4: raise InterpretError("Cannot convert to hex unambiguously - " "not multiple of 4 bits.") if not length: return '' s = self._...
[ "def", "_readhex", "(", "self", ",", "length", ",", "start", ")", ":", "if", "length", "%", "4", ":", "raise", "InterpretError", "(", "\"Cannot convert to hex unambiguously - \"", "\"not multiple of 4 bits.\"", ")", "if", "not", "length", ":", "return", "''", "s...
Read bits and interpret as a hex string.
[ "Read", "bits", "and", "interpret", "as", "a", "hex", "string", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1917-L1932
17,880
scott-griffiths/bitstring
bitstring.py
Bits._ensureinmemory
def _ensureinmemory(self): """Ensure the data is held in memory, not in a file.""" self._setbytes_unsafe(self._datastore.getbyteslice(0, self._datastore.bytelength), self.len, self._offset)
python
def _ensureinmemory(self): """Ensure the data is held in memory, not in a file.""" self._setbytes_unsafe(self._datastore.getbyteslice(0, self._datastore.bytelength), self.len, self._offset)
[ "def", "_ensureinmemory", "(", "self", ")", ":", "self", ".", "_setbytes_unsafe", "(", "self", ".", "_datastore", ".", "getbyteslice", "(", "0", ",", "self", ".", "_datastore", ".", "bytelength", ")", ",", "self", ".", "len", ",", "self", ".", "_offset",...
Ensure the data is held in memory, not in a file.
[ "Ensure", "the", "data", "is", "held", "in", "memory", "not", "in", "a", "file", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1949-L1952
17,881
scott-griffiths/bitstring
bitstring.py
Bits._converttobitstring
def _converttobitstring(cls, bs, offset=0, cache={}): """Convert bs to a bitstring and return it. offset gives the suggested bit offset of first significant bit, to optimise append etc. """ if isinstance(bs, Bits): return bs try: return cache[(bs...
python
def _converttobitstring(cls, bs, offset=0, cache={}): """Convert bs to a bitstring and return it. offset gives the suggested bit offset of first significant bit, to optimise append etc. """ if isinstance(bs, Bits): return bs try: return cache[(bs...
[ "def", "_converttobitstring", "(", "cls", ",", "bs", ",", "offset", "=", "0", ",", "cache", "=", "{", "}", ")", ":", "if", "isinstance", "(", "bs", ",", "Bits", ")", ":", "return", "bs", "try", ":", "return", "cache", "[", "(", "bs", ",", "offset...
Convert bs to a bitstring and return it. offset gives the suggested bit offset of first significant bit, to optimise append etc.
[ "Convert", "bs", "to", "a", "bitstring", "and", "return", "it", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1955-L1986
17,882
scott-griffiths/bitstring
bitstring.py
Bits._slice
def _slice(self, start, end): """Used internally to get a slice, without error checking.""" if end == start: return self.__class__() offset = self._offset startbyte, newoffset = divmod(start + offset, 8) endbyte = (end + offset - 1) // 8 bs = self.__class__() ...
python
def _slice(self, start, end): """Used internally to get a slice, without error checking.""" if end == start: return self.__class__() offset = self._offset startbyte, newoffset = divmod(start + offset, 8) endbyte = (end + offset - 1) // 8 bs = self.__class__() ...
[ "def", "_slice", "(", "self", ",", "start", ",", "end", ")", ":", "if", "end", "==", "start", ":", "return", "self", ".", "__class__", "(", ")", "offset", "=", "self", ".", "_offset", "startbyte", ",", "newoffset", "=", "divmod", "(", "start", "+", ...
Used internally to get a slice, without error checking.
[ "Used", "internally", "to", "get", "a", "slice", "without", "error", "checking", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L1995-L2004
17,883
scott-griffiths/bitstring
bitstring.py
Bits._readtoken
def _readtoken(self, name, pos, length): """Reads a token from the bitstring and returns the result.""" if length is not None and int(length) > self.length - pos: raise ReadError("Reading off the end of the data. " "Tried to read {0} bits when only {1} available."...
python
def _readtoken(self, name, pos, length): """Reads a token from the bitstring and returns the result.""" if length is not None and int(length) > self.length - pos: raise ReadError("Reading off the end of the data. " "Tried to read {0} bits when only {1} available."...
[ "def", "_readtoken", "(", "self", ",", "name", ",", "pos", ",", "length", ")", ":", "if", "length", "is", "not", "None", "and", "int", "(", "length", ")", ">", "self", ".", "length", "-", "pos", ":", "raise", "ReadError", "(", "\"Reading off the end of...
Reads a token from the bitstring and returns the result.
[ "Reads", "a", "token", "from", "the", "bitstring", "and", "returns", "the", "result", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2006-L2020
17,884
scott-griffiths/bitstring
bitstring.py
Bits._reverse
def _reverse(self): """Reverse all bits in-place.""" # Reverse the contents of each byte n = [BYTE_REVERSAL_DICT[b] for b in self._datastore.rawbytes] # Then reverse the order of the bytes n.reverse() # The new offset is the number of bits that were unused at the end. ...
python
def _reverse(self): """Reverse all bits in-place.""" # Reverse the contents of each byte n = [BYTE_REVERSAL_DICT[b] for b in self._datastore.rawbytes] # Then reverse the order of the bytes n.reverse() # The new offset is the number of bits that were unused at the end. ...
[ "def", "_reverse", "(", "self", ")", ":", "# Reverse the contents of each byte", "n", "=", "[", "BYTE_REVERSAL_DICT", "[", "b", "]", "for", "b", "in", "self", ".", "_datastore", ".", "rawbytes", "]", "# Then reverse the order of the bytes", "n", ".", "reverse", ...
Reverse all bits in-place.
[ "Reverse", "all", "bits", "in", "-", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2030-L2040
17,885
scott-griffiths/bitstring
bitstring.py
Bits._truncateend
def _truncateend(self, bits): """Truncate bits from the end of the bitstring.""" assert 0 <= bits <= self.len if not bits: return if bits == self.len: self._clear() return newlength_in_bytes = (self._offset + self.len - bits + 7) // 8 s...
python
def _truncateend(self, bits): """Truncate bits from the end of the bitstring.""" assert 0 <= bits <= self.len if not bits: return if bits == self.len: self._clear() return newlength_in_bytes = (self._offset + self.len - bits + 7) // 8 s...
[ "def", "_truncateend", "(", "self", ",", "bits", ")", ":", "assert", "0", "<=", "bits", "<=", "self", ".", "len", "if", "not", "bits", ":", "return", "if", "bits", "==", "self", ".", "len", ":", "self", ".", "_clear", "(", ")", "return", "newlength...
Truncate bits from the end of the bitstring.
[ "Truncate", "bits", "from", "the", "end", "of", "the", "bitstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2055-L2066
17,886
scott-griffiths/bitstring
bitstring.py
Bits._insert
def _insert(self, bs, pos): """Insert bs at pos.""" assert 0 <= pos <= self.len if pos > self.len // 2: # Inserting nearer end, so cut off end. end = self._slice(pos, self.len) self._truncateend(self.len - pos) self._append(bs) self._ap...
python
def _insert(self, bs, pos): """Insert bs at pos.""" assert 0 <= pos <= self.len if pos > self.len // 2: # Inserting nearer end, so cut off end. end = self._slice(pos, self.len) self._truncateend(self.len - pos) self._append(bs) self._ap...
[ "def", "_insert", "(", "self", ",", "bs", ",", "pos", ")", ":", "assert", "0", "<=", "pos", "<=", "self", ".", "len", "if", "pos", ">", "self", ".", "len", "//", "2", ":", "# Inserting nearer end, so cut off end.", "end", "=", "self", ".", "_slice", ...
Insert bs at pos.
[ "Insert", "bs", "at", "pos", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2068-L2087
17,887
scott-griffiths/bitstring
bitstring.py
Bits._overwrite
def _overwrite(self, bs, pos): """Overwrite with bs at pos.""" assert 0 <= pos < self.len if bs is self: # Just overwriting with self, so do nothing. assert pos == 0 return firstbytepos = (self._offset + pos) // 8 lastbytepos = (self._offset + ...
python
def _overwrite(self, bs, pos): """Overwrite with bs at pos.""" assert 0 <= pos < self.len if bs is self: # Just overwriting with self, so do nothing. assert pos == 0 return firstbytepos = (self._offset + pos) // 8 lastbytepos = (self._offset + ...
[ "def", "_overwrite", "(", "self", ",", "bs", ",", "pos", ")", ":", "assert", "0", "<=", "pos", "<", "self", ".", "len", "if", "bs", "is", "self", ":", "# Just overwriting with self, so do nothing.", "assert", "pos", "==", "0", "return", "firstbytepos", "="...
Overwrite with bs at pos.
[ "Overwrite", "with", "bs", "at", "pos", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2089-L2120
17,888
scott-griffiths/bitstring
bitstring.py
Bits._delete
def _delete(self, bits, pos): """Delete bits at pos.""" assert 0 <= pos <= self.len assert pos + bits <= self.len if not pos: # Cutting bits off at the start. self._truncatestart(bits) return if pos + bits == self.len: # Cutting bit...
python
def _delete(self, bits, pos): """Delete bits at pos.""" assert 0 <= pos <= self.len assert pos + bits <= self.len if not pos: # Cutting bits off at the start. self._truncatestart(bits) return if pos + bits == self.len: # Cutting bit...
[ "def", "_delete", "(", "self", ",", "bits", ",", "pos", ")", ":", "assert", "0", "<=", "pos", "<=", "self", ".", "len", "assert", "pos", "+", "bits", "<=", "self", ".", "len", "if", "not", "pos", ":", "# Cutting bits off at the start.", "self", ".", ...
Delete bits at pos.
[ "Delete", "bits", "at", "pos", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2122-L2146
17,889
scott-griffiths/bitstring
bitstring.py
Bits._reversebytes
def _reversebytes(self, start, end): """Reverse bytes in-place.""" # Make the start occur on a byte boundary # TODO: We could be cleverer here to avoid changing the offset. newoffset = 8 - (start % 8) if newoffset == 8: newoffset = 0 self._datastore = offsetco...
python
def _reversebytes(self, start, end): """Reverse bytes in-place.""" # Make the start occur on a byte boundary # TODO: We could be cleverer here to avoid changing the offset. newoffset = 8 - (start % 8) if newoffset == 8: newoffset = 0 self._datastore = offsetco...
[ "def", "_reversebytes", "(", "self", ",", "start", ",", "end", ")", ":", "# Make the start occur on a byte boundary", "# TODO: We could be cleverer here to avoid changing the offset.", "newoffset", "=", "8", "-", "(", "start", "%", "8", ")", "if", "newoffset", "==", "...
Reverse bytes in-place.
[ "Reverse", "bytes", "in", "-", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2148-L2159
17,890
scott-griffiths/bitstring
bitstring.py
Bits._set
def _set(self, pos): """Set bit at pos to 1.""" assert 0 <= pos < self.len self._datastore.setbit(pos)
python
def _set(self, pos): """Set bit at pos to 1.""" assert 0 <= pos < self.len self._datastore.setbit(pos)
[ "def", "_set", "(", "self", ",", "pos", ")", ":", "assert", "0", "<=", "pos", "<", "self", ".", "len", "self", ".", "_datastore", ".", "setbit", "(", "pos", ")" ]
Set bit at pos to 1.
[ "Set", "bit", "at", "pos", "to", "1", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2161-L2164
17,891
scott-griffiths/bitstring
bitstring.py
Bits._unset
def _unset(self, pos): """Set bit at pos to 0.""" assert 0 <= pos < self.len self._datastore.unsetbit(pos)
python
def _unset(self, pos): """Set bit at pos to 0.""" assert 0 <= pos < self.len self._datastore.unsetbit(pos)
[ "def", "_unset", "(", "self", ",", "pos", ")", ":", "assert", "0", "<=", "pos", "<", "self", ".", "len", "self", ".", "_datastore", ".", "unsetbit", "(", "pos", ")" ]
Set bit at pos to 0.
[ "Set", "bit", "at", "pos", "to", "0", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2166-L2169
17,892
scott-griffiths/bitstring
bitstring.py
Bits._invert_all
def _invert_all(self): """Invert every bit.""" set = self._datastore.setbyte get = self._datastore.getbyte for p in xrange(self._datastore.byteoffset, self._datastore.byteoffset + self._datastore.bytelength): set(p, 256 + ~get(p))
python
def _invert_all(self): """Invert every bit.""" set = self._datastore.setbyte get = self._datastore.getbyte for p in xrange(self._datastore.byteoffset, self._datastore.byteoffset + self._datastore.bytelength): set(p, 256 + ~get(p))
[ "def", "_invert_all", "(", "self", ")", ":", "set", "=", "self", ".", "_datastore", ".", "setbyte", "get", "=", "self", ".", "_datastore", ".", "getbyte", "for", "p", "in", "xrange", "(", "self", ".", "_datastore", ".", "byteoffset", ",", "self", ".", ...
Invert every bit.
[ "Invert", "every", "bit", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2176-L2181
17,893
scott-griffiths/bitstring
bitstring.py
Bits._ilshift
def _ilshift(self, n): """Shift bits by n to the left in place. Return self.""" assert 0 < n <= self.len self._append(Bits(n)) self._truncatestart(n) return self
python
def _ilshift(self, n): """Shift bits by n to the left in place. Return self.""" assert 0 < n <= self.len self._append(Bits(n)) self._truncatestart(n) return self
[ "def", "_ilshift", "(", "self", ",", "n", ")", ":", "assert", "0", "<", "n", "<=", "self", ".", "len", "self", ".", "_append", "(", "Bits", "(", "n", ")", ")", "self", ".", "_truncatestart", "(", "n", ")", "return", "self" ]
Shift bits by n to the left in place. Return self.
[ "Shift", "bits", "by", "n", "to", "the", "left", "in", "place", ".", "Return", "self", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2183-L2188
17,894
scott-griffiths/bitstring
bitstring.py
Bits._irshift
def _irshift(self, n): """Shift bits by n to the right in place. Return self.""" assert 0 < n <= self.len self._prepend(Bits(n)) self._truncateend(n) return self
python
def _irshift(self, n): """Shift bits by n to the right in place. Return self.""" assert 0 < n <= self.len self._prepend(Bits(n)) self._truncateend(n) return self
[ "def", "_irshift", "(", "self", ",", "n", ")", ":", "assert", "0", "<", "n", "<=", "self", ".", "len", "self", ".", "_prepend", "(", "Bits", "(", "n", ")", ")", "self", ".", "_truncateend", "(", "n", ")", "return", "self" ]
Shift bits by n to the right in place. Return self.
[ "Shift", "bits", "by", "n", "to", "the", "right", "in", "place", ".", "Return", "self", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2190-L2195
17,895
scott-griffiths/bitstring
bitstring.py
Bits._imul
def _imul(self, n): """Concatenate n copies of self in place. Return self.""" assert n >= 0 if not n: self._clear() return self m = 1 old_len = self.len while m * 2 < n: self._append(self) m *= 2 self._append(self[0:...
python
def _imul(self, n): """Concatenate n copies of self in place. Return self.""" assert n >= 0 if not n: self._clear() return self m = 1 old_len = self.len while m * 2 < n: self._append(self) m *= 2 self._append(self[0:...
[ "def", "_imul", "(", "self", ",", "n", ")", ":", "assert", "n", ">=", "0", "if", "not", "n", ":", "self", ".", "_clear", "(", ")", "return", "self", "m", "=", "1", "old_len", "=", "self", ".", "len", "while", "m", "*", "2", "<", "n", ":", "...
Concatenate n copies of self in place. Return self.
[ "Concatenate", "n", "copies", "of", "self", "in", "place", ".", "Return", "self", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2197-L2209
17,896
scott-griffiths/bitstring
bitstring.py
Bits._validate_slice
def _validate_slice(self, start, end): """Validate start and end and return them as positive bit positions.""" if start is None: start = 0 elif start < 0: start += self.len if end is None: end = self.len elif end < 0: end += self.le...
python
def _validate_slice(self, start, end): """Validate start and end and return them as positive bit positions.""" if start is None: start = 0 elif start < 0: start += self.len if end is None: end = self.len elif end < 0: end += self.le...
[ "def", "_validate_slice", "(", "self", ",", "start", ",", "end", ")", ":", "if", "start", "is", "None", ":", "start", "=", "0", "elif", "start", "<", "0", ":", "start", "+=", "self", ".", "len", "if", "end", "is", "None", ":", "end", "=", "self",...
Validate start and end and return them as positive bit positions.
[ "Validate", "start", "and", "end", "and", "return", "them", "as", "positive", "bit", "positions", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2240-L2256
17,897
scott-griffiths/bitstring
bitstring.py
Bits._findbytes
def _findbytes(self, bytes_, start, end, bytealigned): """Quicker version of find when everything's whole byte and byte aligned. """ assert self._datastore.offset == 0 assert bytealigned is True # Extract data bytes from bitstring to be found. bytepos = (start + ...
python
def _findbytes(self, bytes_, start, end, bytealigned): """Quicker version of find when everything's whole byte and byte aligned. """ assert self._datastore.offset == 0 assert bytealigned is True # Extract data bytes from bitstring to be found. bytepos = (start + ...
[ "def", "_findbytes", "(", "self", ",", "bytes_", ",", "start", ",", "end", ",", "bytealigned", ")", ":", "assert", "self", ".", "_datastore", ".", "offset", "==", "0", "assert", "bytealigned", "is", "True", "# Extract data bytes from bitstring to be found.", "by...
Quicker version of find when everything's whole byte and byte aligned.
[ "Quicker", "version", "of", "find", "when", "everything", "s", "whole", "byte", "and", "byte", "aligned", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2352-L2377
17,898
scott-griffiths/bitstring
bitstring.py
Bits._findregex
def _findregex(self, reg_ex, start, end, bytealigned): """Find first occurrence of a compiled regular expression. Note that this doesn't support arbitrary regexes, in particular they must match a known length. """ p = start length = len(reg_ex.pattern) # We grab...
python
def _findregex(self, reg_ex, start, end, bytealigned): """Find first occurrence of a compiled regular expression. Note that this doesn't support arbitrary regexes, in particular they must match a known length. """ p = start length = len(reg_ex.pattern) # We grab...
[ "def", "_findregex", "(", "self", ",", "reg_ex", ",", "start", ",", "end", ",", "bytealigned", ")", ":", "p", "=", "start", "length", "=", "len", "(", "reg_ex", ".", "pattern", ")", "# We grab overlapping chunks of the binary representation and", "# do an ordinary...
Find first occurrence of a compiled regular expression. Note that this doesn't support arbitrary regexes, in particular they must match a known length.
[ "Find", "first", "occurrence", "of", "a", "compiled", "regular", "expression", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2379-L2409
17,899
scott-griffiths/bitstring
bitstring.py
Bits.find
def find(self, bs, start=None, end=None, bytealigned=None): """Find first occurrence of substring bs. Returns a single item tuple with the bit position if found, or an empty tuple if not found. The bit position (pos property) will also be set to the start of the substring if it is found...
python
def find(self, bs, start=None, end=None, bytealigned=None): """Find first occurrence of substring bs. Returns a single item tuple with the bit position if found, or an empty tuple if not found. The bit position (pos property) will also be set to the start of the substring if it is found...
[ "def", "find", "(", "self", ",", "bs", ",", "start", "=", "None", ",", "end", "=", "None", ",", "bytealigned", "=", "None", ")", ":", "bs", "=", "Bits", "(", "bs", ")", "if", "not", "bs", ".", "len", ":", "raise", "ValueError", "(", "\"Cannot fin...
Find first occurrence of substring bs. Returns a single item tuple with the bit position if found, or an empty tuple if not found. The bit position (pos property) will also be set to the start of the substring if it is found. bs -- The bitstring to find. start -- The bit positi...
[ "Find", "first", "occurrence", "of", "substring", "bs", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2411-L2447