repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
sloria/flask-konch | flask_konch/cli.py | cli | def cli():
"""An improved shell command, based on konch."""
from flask.globals import _app_ctx_stack
app = _app_ctx_stack.top.app
options = {key: app.config.get(key, DEFAULTS[key]) for key in DEFAULTS.keys()}
base_context = {"app": app}
if options["KONCH_FLASK_IMPORTS"]:
base_context.up... | python | def cli():
"""An improved shell command, based on konch."""
from flask.globals import _app_ctx_stack
app = _app_ctx_stack.top.app
options = {key: app.config.get(key, DEFAULTS[key]) for key in DEFAULTS.keys()}
base_context = {"app": app}
if options["KONCH_FLASK_IMPORTS"]:
base_context.up... | [
"def",
"cli",
"(",
")",
":",
"from",
"flask",
".",
"globals",
"import",
"_app_ctx_stack",
"app",
"=",
"_app_ctx_stack",
".",
"top",
".",
"app",
"options",
"=",
"{",
"key",
":",
"app",
".",
"config",
".",
"get",
"(",
"key",
",",
"DEFAULTS",
"[",
"key"... | An improved shell command, based on konch. | [
"An",
"improved",
"shell",
"command",
"based",
"on",
"konch",
"."
] | train | https://github.com/sloria/flask-konch/blob/c1829220bcdb3d0a9b41b2016266bee9940cc5e3/flask_konch/cli.py#L35-L89 |
robgolding/tasklib | tasklib/lazy.py | LazyUUIDTask.replace | def replace(self):
"""
Performs conversion to the regular Task object, referenced by the
stored UUID.
"""
replacement = self._tw.tasks.get(uuid=self._uuid)
self.__class__ = replacement.__class__
self.__dict__ = replacement.__dict__ | python | def replace(self):
"""
Performs conversion to the regular Task object, referenced by the
stored UUID.
"""
replacement = self._tw.tasks.get(uuid=self._uuid)
self.__class__ = replacement.__class__
self.__dict__ = replacement.__dict__ | [
"def",
"replace",
"(",
"self",
")",
":",
"replacement",
"=",
"self",
".",
"_tw",
".",
"tasks",
".",
"get",
"(",
"uuid",
"=",
"self",
".",
"_uuid",
")",
"self",
".",
"__class__",
"=",
"replacement",
".",
"__class__",
"self",
".",
"__dict__",
"=",
"rep... | Performs conversion to the regular Task object, referenced by the
stored UUID. | [
"Performs",
"conversion",
"to",
"the",
"regular",
"Task",
"object",
"referenced",
"by",
"the",
"stored",
"UUID",
"."
] | train | https://github.com/robgolding/tasklib/blob/0ad882377639865283021041f19add5aeb10126a/tasklib/lazy.py#L69-L77 |
robgolding/tasklib | tasklib/lazy.py | LazyUUIDTaskSet.replace | def replace(self):
"""
Performs conversion to the regular TaskQuerySet object, referenced by
the stored UUIDs.
"""
replacement = self._tw.tasks.filter(' '.join(self._uuids))
self.__class__ = replacement.__class__
self.__dict__ = replacement.__dict__ | python | def replace(self):
"""
Performs conversion to the regular TaskQuerySet object, referenced by
the stored UUIDs.
"""
replacement = self._tw.tasks.filter(' '.join(self._uuids))
self.__class__ = replacement.__class__
self.__dict__ = replacement.__dict__ | [
"def",
"replace",
"(",
"self",
")",
":",
"replacement",
"=",
"self",
".",
"_tw",
".",
"tasks",
".",
"filter",
"(",
"' '",
".",
"join",
"(",
"self",
".",
"_uuids",
")",
")",
"self",
".",
"__class__",
"=",
"replacement",
".",
"__class__",
"self",
".",
... | Performs conversion to the regular TaskQuerySet object, referenced by
the stored UUIDs. | [
"Performs",
"conversion",
"to",
"the",
"regular",
"TaskQuerySet",
"object",
"referenced",
"by",
"the",
"stored",
"UUIDs",
"."
] | train | https://github.com/robgolding/tasklib/blob/0ad882377639865283021041f19add5aeb10126a/tasklib/lazy.py#L227-L235 |
robgolding/tasklib | tasklib/backends.py | TaskWarrior.save_task | def save_task(self, task):
"""Save a task into TaskWarrior database using add/modify call"""
args = [task['uuid'], 'modify'] if task.saved else ['add']
args.extend(self._get_modified_task_fields_as_args(task))
output = self.execute_command(args)
# Parse out the new ID, if the t... | python | def save_task(self, task):
"""Save a task into TaskWarrior database using add/modify call"""
args = [task['uuid'], 'modify'] if task.saved else ['add']
args.extend(self._get_modified_task_fields_as_args(task))
output = self.execute_command(args)
# Parse out the new ID, if the t... | [
"def",
"save_task",
"(",
"self",
",",
"task",
")",
":",
"args",
"=",
"[",
"task",
"[",
"'uuid'",
"]",
",",
"'modify'",
"]",
"if",
"task",
".",
"saved",
"else",
"[",
"'add'",
"]",
"args",
".",
"extend",
"(",
"self",
".",
"_get_modified_task_fields_as_ar... | Save a task into TaskWarrior database using add/modify call | [
"Save",
"a",
"task",
"into",
"TaskWarrior",
"database",
"using",
"add",
"/",
"modify",
"call"
] | train | https://github.com/robgolding/tasklib/blob/0ad882377639865283021041f19add5aeb10126a/tasklib/backends.py#L330-L363 |
robgolding/tasklib | tasklib/serializing.py | SerializingObject._normalize | def _normalize(self, key, value):
"""
Use normalize_<key> methods to normalize user input. Any user
input will be normalized at the moment it is used as filter,
or entered as a value of Task attribute.
"""
# None value should not be converted by normalizer
if val... | python | def _normalize(self, key, value):
"""
Use normalize_<key> methods to normalize user input. Any user
input will be normalized at the moment it is used as filter,
or entered as a value of Task attribute.
"""
# None value should not be converted by normalizer
if val... | [
"def",
"_normalize",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"# None value should not be converted by normalizer",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"normalize_func",
"=",
"getattr",
"(",
"self",
",",
"'normalize_{0}'",
".",
"format",
... | Use normalize_<key> methods to normalize user input. Any user
input will be normalized at the moment it is used as filter,
or entered as a value of Task attribute. | [
"Use",
"normalize_<key",
">",
"methods",
"to",
"normalize",
"user",
"input",
".",
"Any",
"user",
"input",
"will",
"be",
"normalized",
"at",
"the",
"moment",
"it",
"is",
"used",
"as",
"filter",
"or",
"entered",
"as",
"a",
"value",
"of",
"Task",
"attribute",... | train | https://github.com/robgolding/tasklib/blob/0ad882377639865283021041f19add5aeb10126a/tasklib/serializing.py#L55-L69 |
robgolding/tasklib | tasklib/serializing.py | SerializingObject.datetime_normalizer | def datetime_normalizer(self, value):
"""
Normalizes date/datetime value (considered to come from user input)
to localized datetime value. Following conversions happen:
naive date -> localized datetime with the same date, and time=midnight
naive datetime -> localized datetime wi... | python | def datetime_normalizer(self, value):
"""
Normalizes date/datetime value (considered to come from user input)
to localized datetime value. Following conversions happen:
naive date -> localized datetime with the same date, and time=midnight
naive datetime -> localized datetime wi... | [
"def",
"datetime_normalizer",
"(",
"self",
",",
"value",
")",
":",
"if",
"(",
"isinstance",
"(",
"value",
",",
"datetime",
".",
"date",
")",
"and",
"not",
"isinstance",
"(",
"value",
",",
"datetime",
".",
"datetime",
")",
")",
":",
"# Convert to local midn... | Normalizes date/datetime value (considered to come from user input)
to localized datetime value. Following conversions happen:
naive date -> localized datetime with the same date, and time=midnight
naive datetime -> localized datetime with the same value
localized datetime -> localized ... | [
"Normalizes",
"date",
"/",
"datetime",
"value",
"(",
"considered",
"to",
"come",
"from",
"user",
"input",
")",
"to",
"localized",
"datetime",
"value",
".",
"Following",
"conversions",
"happen",
":"
] | train | https://github.com/robgolding/tasklib/blob/0ad882377639865283021041f19add5aeb10126a/tasklib/serializing.py#L214-L246 |
robgolding/tasklib | tasklib/task.py | TaskResource._update_data | def _update_data(self, data, update_original=False, remove_missing=False):
"""
Low level update of the internal _data dict. Data which are coming as
updates should already be serialized. If update_original is True, the
original_data dict is updated as well.
"""
self._data... | python | def _update_data(self, data, update_original=False, remove_missing=False):
"""
Low level update of the internal _data dict. Data which are coming as
updates should already be serialized. If update_original is True, the
original_data dict is updated as well.
"""
self._data... | [
"def",
"_update_data",
"(",
"self",
",",
"data",
",",
"update_original",
"=",
"False",
",",
"remove_missing",
"=",
"False",
")",
":",
"self",
".",
"_data",
".",
"update",
"(",
"dict",
"(",
"(",
"key",
",",
"self",
".",
"_deserialize",
"(",
"key",
",",
... | Low level update of the internal _data dict. Data which are coming as
updates should already be serialized. If update_original is True, the
original_data dict is updated as well. | [
"Low",
"level",
"update",
"of",
"the",
"internal",
"_data",
"dict",
".",
"Data",
"which",
"are",
"coming",
"as",
"updates",
"should",
"already",
"be",
"serialized",
".",
"If",
"update_original",
"is",
"True",
"the",
"original_data",
"dict",
"is",
"updated",
... | train | https://github.com/robgolding/tasklib/blob/0ad882377639865283021041f19add5aeb10126a/tasklib/task.py#L69-L84 |
robgolding/tasklib | tasklib/task.py | TaskResource.export_data | def export_data(self):
"""
Exports current data contained in the Task as JSON
"""
# We need to remove spaces for TW-1504, use custom separators
data_tuples = ((key, self._serialize(key, value))
for key, value in six.iteritems(self._data))
# Empty ... | python | def export_data(self):
"""
Exports current data contained in the Task as JSON
"""
# We need to remove spaces for TW-1504, use custom separators
data_tuples = ((key, self._serialize(key, value))
for key, value in six.iteritems(self._data))
# Empty ... | [
"def",
"export_data",
"(",
"self",
")",
":",
"# We need to remove spaces for TW-1504, use custom separators",
"data_tuples",
"=",
"(",
"(",
"key",
",",
"self",
".",
"_serialize",
"(",
"key",
",",
"value",
")",
")",
"for",
"key",
",",
"value",
"in",
"six",
".",... | Exports current data contained in the Task as JSON | [
"Exports",
"current",
"data",
"contained",
"in",
"the",
"Task",
"as",
"JSON"
] | train | https://github.com/robgolding/tasklib/blob/0ad882377639865283021041f19add5aeb10126a/tasklib/task.py#L117-L130 |
robgolding/tasklib | tasklib/task.py | Task.from_input | def from_input(cls, input_file=sys.stdin, modify=None, backend=None):
"""
Creates a Task object, directly from the stdin, by reading one line.
If modify=True, two lines are used, first line interpreted as the
original state of the Task object, and second line as its new,
modified... | python | def from_input(cls, input_file=sys.stdin, modify=None, backend=None):
"""
Creates a Task object, directly from the stdin, by reading one line.
If modify=True, two lines are used, first line interpreted as the
original state of the Task object, and second line as its new,
modified... | [
"def",
"from_input",
"(",
"cls",
",",
"input_file",
"=",
"sys",
".",
"stdin",
",",
"modify",
"=",
"None",
",",
"backend",
"=",
"None",
")",
":",
"# Detect the hook type if not given directly",
"name",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"sys",
".... | Creates a Task object, directly from the stdin, by reading one line.
If modify=True, two lines are used, first line interpreted as the
original state of the Task object, and second line as its new,
modified value. This is consistent with the TaskWarrior's hook
system.
Object cre... | [
"Creates",
"a",
"Task",
"object",
"directly",
"from",
"the",
"stdin",
"by",
"reading",
"one",
"line",
".",
"If",
"modify",
"=",
"True",
"two",
"lines",
"are",
"used",
"first",
"line",
"interpreted",
"as",
"the",
"original",
"state",
"of",
"the",
"Task",
... | train | https://github.com/robgolding/tasklib/blob/0ad882377639865283021041f19add5aeb10126a/tasklib/task.py#L215-L253 |
robgolding/tasklib | tasklib/task.py | TaskQuerySet.filter | def filter(self, *args, **kwargs):
"""
Returns a new TaskQuerySet with the given filters added.
"""
clone = self._clone()
for f in args:
clone.filter_obj.add_filter(f)
for key, value in kwargs.items():
clone.filter_obj.add_filter_param(key, value)
... | python | def filter(self, *args, **kwargs):
"""
Returns a new TaskQuerySet with the given filters added.
"""
clone = self._clone()
for f in args:
clone.filter_obj.add_filter(f)
for key, value in kwargs.items():
clone.filter_obj.add_filter_param(key, value)
... | [
"def",
"filter",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"clone",
"=",
"self",
".",
"_clone",
"(",
")",
"for",
"f",
"in",
"args",
":",
"clone",
".",
"filter_obj",
".",
"add_filter",
"(",
"f",
")",
"for",
"key",
",",
"v... | Returns a new TaskQuerySet with the given filters added. | [
"Returns",
"a",
"new",
"TaskQuerySet",
"with",
"the",
"given",
"filters",
"added",
"."
] | train | https://github.com/robgolding/tasklib/blob/0ad882377639865283021041f19add5aeb10126a/tasklib/task.py#L540-L549 |
robgolding/tasklib | tasklib/task.py | TaskQuerySet.get | def get(self, **kwargs):
"""
Performs the query and returns a single object matching the given
keyword arguments.
"""
clone = self.filter(**kwargs)
num = len(clone)
if num == 1:
return clone._result_cache[0]
if not num:
raise Task.D... | python | def get(self, **kwargs):
"""
Performs the query and returns a single object matching the given
keyword arguments.
"""
clone = self.filter(**kwargs)
num = len(clone)
if num == 1:
return clone._result_cache[0]
if not num:
raise Task.D... | [
"def",
"get",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"clone",
"=",
"self",
".",
"filter",
"(",
"*",
"*",
"kwargs",
")",
"num",
"=",
"len",
"(",
"clone",
")",
"if",
"num",
"==",
"1",
":",
"return",
"clone",
".",
"_result_cache",
"[",
"0... | Performs the query and returns a single object matching the given
keyword arguments. | [
"Performs",
"the",
"query",
"and",
"returns",
"a",
"single",
"object",
"matching",
"the",
"given",
"keyword",
"arguments",
"."
] | train | https://github.com/robgolding/tasklib/blob/0ad882377639865283021041f19add5aeb10126a/tasklib/task.py#L551-L568 |
NiklasRosenstein/py-localimport | localimport.py | is_local | def is_local(filename, pathlist):
'''
Returns True if *filename* is a subpath of any of the paths in *pathlist*.
'''
filename = os.path.abspath(filename)
for path_name in pathlist:
path_name = os.path.abspath(path_name)
if is_subpath(filename, path_name):
return True
return False | python | def is_local(filename, pathlist):
'''
Returns True if *filename* is a subpath of any of the paths in *pathlist*.
'''
filename = os.path.abspath(filename)
for path_name in pathlist:
path_name = os.path.abspath(path_name)
if is_subpath(filename, path_name):
return True
return False | [
"def",
"is_local",
"(",
"filename",
",",
"pathlist",
")",
":",
"filename",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"filename",
")",
"for",
"path_name",
"in",
"pathlist",
":",
"path_name",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"path_name",
"... | Returns True if *filename* is a subpath of any of the paths in *pathlist*. | [
"Returns",
"True",
"if",
"*",
"filename",
"*",
"is",
"a",
"subpath",
"of",
"any",
"of",
"the",
"paths",
"in",
"*",
"pathlist",
"*",
"."
] | train | https://github.com/NiklasRosenstein/py-localimport/blob/69af71c37f8bd3b2121ec39083dff18a9a2d04a1/localimport.py#L48-L58 |
NiklasRosenstein/py-localimport | localimport.py | is_subpath | def is_subpath(path, parent):
'''
Returns True if *path* points to the same or a subpath of *parent*.
'''
try:
relpath = os.path.relpath(path, parent)
except ValueError:
return False # happens on Windows if drive letters don't match
return relpath == os.curdir or not relpath.startswith(os.pardir) | python | def is_subpath(path, parent):
'''
Returns True if *path* points to the same or a subpath of *parent*.
'''
try:
relpath = os.path.relpath(path, parent)
except ValueError:
return False # happens on Windows if drive letters don't match
return relpath == os.curdir or not relpath.startswith(os.pardir) | [
"def",
"is_subpath",
"(",
"path",
",",
"parent",
")",
":",
"try",
":",
"relpath",
"=",
"os",
".",
"path",
".",
"relpath",
"(",
"path",
",",
"parent",
")",
"except",
"ValueError",
":",
"return",
"False",
"# happens on Windows if drive letters don't match",
"ret... | Returns True if *path* points to the same or a subpath of *parent*. | [
"Returns",
"True",
"if",
"*",
"path",
"*",
"points",
"to",
"the",
"same",
"or",
"a",
"subpath",
"of",
"*",
"parent",
"*",
"."
] | train | https://github.com/NiklasRosenstein/py-localimport/blob/69af71c37f8bd3b2121ec39083dff18a9a2d04a1/localimport.py#L61-L70 |
NiklasRosenstein/py-localimport | localimport.py | eval_pth | def eval_pth(filename, sitedir, dest=None, imports=None):
'''
Evaluates a `.pth` file (including support for `import` statements), and
appends the result to the list *dest*. If *dest* is #None, it will fall
back to `sys.path`.
If *imports* is specified, it must be a list. `import` statements will not
execu... | python | def eval_pth(filename, sitedir, dest=None, imports=None):
'''
Evaluates a `.pth` file (including support for `import` statements), and
appends the result to the list *dest*. If *dest* is #None, it will fall
back to `sys.path`.
If *imports* is specified, it must be a list. `import` statements will not
execu... | [
"def",
"eval_pth",
"(",
"filename",
",",
"sitedir",
",",
"dest",
"=",
"None",
",",
"imports",
"=",
"None",
")",
":",
"if",
"dest",
"is",
"None",
":",
"dest",
"=",
"sys",
".",
"path",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"filename",
... | Evaluates a `.pth` file (including support for `import` statements), and
appends the result to the list *dest*. If *dest* is #None, it will fall
back to `sys.path`.
If *imports* is specified, it must be a list. `import` statements will not
executed but instead appended to that list in tuples of
(*filename*, ... | [
"Evaluates",
"a",
".",
"pth",
"file",
"(",
"including",
"support",
"for",
"import",
"statements",
")",
"and",
"appends",
"the",
"result",
"to",
"the",
"list",
"*",
"dest",
"*",
".",
"If",
"*",
"dest",
"*",
"is",
"#None",
"it",
"will",
"fall",
"back",
... | train | https://github.com/NiklasRosenstein/py-localimport/blob/69af71c37f8bd3b2121ec39083dff18a9a2d04a1/localimport.py#L73-L107 |
NiklasRosenstein/py-localimport | localimport.py | extend_path | def extend_path(pth, name):
'''
Better implementation of #pkgutil.extend_path() which adds support for
zipped Python eggs. The original #pkgutil.extend_path() gets mocked by this
function inside the #localimport context.
'''
def zip_isfile(z, name):
name.rstrip('/')
return name in z.namelist()
... | python | def extend_path(pth, name):
'''
Better implementation of #pkgutil.extend_path() which adds support for
zipped Python eggs. The original #pkgutil.extend_path() gets mocked by this
function inside the #localimport context.
'''
def zip_isfile(z, name):
name.rstrip('/')
return name in z.namelist()
... | [
"def",
"extend_path",
"(",
"pth",
",",
"name",
")",
":",
"def",
"zip_isfile",
"(",
"z",
",",
"name",
")",
":",
"name",
".",
"rstrip",
"(",
"'/'",
")",
"return",
"name",
"in",
"z",
".",
"namelist",
"(",
")",
"pname",
"=",
"os",
".",
"path",
".",
... | Better implementation of #pkgutil.extend_path() which adds support for
zipped Python eggs. The original #pkgutil.extend_path() gets mocked by this
function inside the #localimport context. | [
"Better",
"implementation",
"of",
"#pkgutil",
".",
"extend_path",
"()",
"which",
"adds",
"support",
"for",
"zipped",
"Python",
"eggs",
".",
"The",
"original",
"#pkgutil",
".",
"extend_path",
"()",
"gets",
"mocked",
"by",
"this",
"function",
"inside",
"the",
"#... | train | https://github.com/NiklasRosenstein/py-localimport/blob/69af71c37f8bd3b2121ec39083dff18a9a2d04a1/localimport.py#L118-L159 |
NiklasRosenstein/py-localimport | localimport.py | localimport._declare_namespace | def _declare_namespace(self, package_name):
'''
Mock for #pkg_resources.declare_namespace() which calls
#pkgutil.extend_path() afterwards as the original implementation doesn't
seem to properly find all available namespace paths.
'''
self.state['declare_namespace'](package_name)
mod = sys.m... | python | def _declare_namespace(self, package_name):
'''
Mock for #pkg_resources.declare_namespace() which calls
#pkgutil.extend_path() afterwards as the original implementation doesn't
seem to properly find all available namespace paths.
'''
self.state['declare_namespace'](package_name)
mod = sys.m... | [
"def",
"_declare_namespace",
"(",
"self",
",",
"package_name",
")",
":",
"self",
".",
"state",
"[",
"'declare_namespace'",
"]",
"(",
"package_name",
")",
"mod",
"=",
"sys",
".",
"modules",
"[",
"package_name",
"]",
"mod",
".",
"__path__",
"=",
"pkgutil",
"... | Mock for #pkg_resources.declare_namespace() which calls
#pkgutil.extend_path() afterwards as the original implementation doesn't
seem to properly find all available namespace paths. | [
"Mock",
"for",
"#pkg_resources",
".",
"declare_namespace",
"()",
"which",
"calls",
"#pkgutil",
".",
"extend_path",
"()",
"afterwards",
"as",
"the",
"original",
"implementation",
"doesn",
"t",
"seem",
"to",
"properly",
"find",
"all",
"available",
"namespace",
"path... | train | https://github.com/NiklasRosenstein/py-localimport/blob/69af71c37f8bd3b2121ec39083dff18a9a2d04a1/localimport.py#L329-L338 |
hubo1016/namedstruct | misc/ethernet.py | ip_frag | def ip_frag(packet):
'''
Not fragments:
ip_frag(packet) == 0
not ip_frag(packet)
First packet of fragments:
ip_frag(packet) == IP_FRAG_ANY
Not first packet of fragments:
ip_frag(packet) & IP_FRAG_LATER
All fragments:
ip_frag(packet) & IP_FRA... | python | def ip_frag(packet):
'''
Not fragments:
ip_frag(packet) == 0
not ip_frag(packet)
First packet of fragments:
ip_frag(packet) == IP_FRAG_ANY
Not first packet of fragments:
ip_frag(packet) & IP_FRAG_LATER
All fragments:
ip_frag(packet) & IP_FRA... | [
"def",
"ip_frag",
"(",
"packet",
")",
":",
"return",
"(",
"(",
"packet",
".",
"frag_off",
"&",
"IP_OFFMASK",
")",
"and",
"IP_FRAG_LATER",
")",
"|",
"(",
"(",
"packet",
".",
"frag_off",
"&",
"(",
"IP_OFFMASK",
"|",
"IP_MF",
")",
")",
"and",
"IP_FRAG_ANY... | Not fragments:
ip_frag(packet) == 0
not ip_frag(packet)
First packet of fragments:
ip_frag(packet) == IP_FRAG_ANY
Not first packet of fragments:
ip_frag(packet) & IP_FRAG_LATER
All fragments:
ip_frag(packet) & IP_FRAG_ANY | [
"Not",
"fragments",
":",
"ip_frag",
"(",
"packet",
")",
"==",
"0",
"not",
"ip_frag",
"(",
"packet",
")",
"First",
"packet",
"of",
"fragments",
":",
"ip_frag",
"(",
"packet",
")",
"==",
"IP_FRAG_ANY",
"Not",
"first",
"packet",
"of",
"fragments",
":",
"ip_... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/misc/ethernet.py#L342-L358 |
hubo1016/namedstruct | misc/openflow/nicira_ext.py | create_extension | def create_extension(namespace, nicira_header, nx_action, nx_stats_request, nx_stats_reply,
msg_subtype, action_subtype, stats_subtype):
'''
/* This command enables or disables an Open vSwitch extension that allows a
* controller to specify the OpenFlow table to which a flow should be ... | python | def create_extension(namespace, nicira_header, nx_action, nx_stats_request, nx_stats_reply,
msg_subtype, action_subtype, stats_subtype):
'''
/* This command enables or disables an Open vSwitch extension that allows a
* controller to specify the OpenFlow table to which a flow should be ... | [
"def",
"create_extension",
"(",
"namespace",
",",
"nicira_header",
",",
"nx_action",
",",
"nx_stats_request",
",",
"nx_stats_reply",
",",
"msg_subtype",
",",
"action_subtype",
",",
"stats_subtype",
")",
":",
"with",
"_warnings",
".",
"catch_warnings",
"(",
")",
":... | /* This command enables or disables an Open vSwitch extension that allows a
* controller to specify the OpenFlow table to which a flow should be added,
* instead of having the switch decide which table is most appropriate as
* required by OpenFlow 1.0. Because NXM was designed as an extension to
* ... | [
"/",
"*",
"This",
"command",
"enables",
"or",
"disables",
"an",
"Open",
"vSwitch",
"extension",
"that",
"allows",
"a",
"*",
"controller",
"to",
"specify",
"the",
"OpenFlow",
"table",
"to",
"which",
"a",
"flow",
"should",
"be",
"added",
"*",
"instead",
"of"... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/misc/openflow/nicira_ext.py#L1130-L3077 |
mduggan/cdifflib | cdifflib.py | CSequenceMatcher.find_longest_match | def find_longest_match(self, alo, ahi, blo, bhi):
"""Find longest matching block in a[alo:ahi] and b[blo:bhi].
Wrapper for the C implementation of this function.
"""
besti, bestj, bestsize = _cdifflib.find_longest_match(self, alo, ahi, blo, bhi)
return _Match(besti, bestj, bests... | python | def find_longest_match(self, alo, ahi, blo, bhi):
"""Find longest matching block in a[alo:ahi] and b[blo:bhi].
Wrapper for the C implementation of this function.
"""
besti, bestj, bestsize = _cdifflib.find_longest_match(self, alo, ahi, blo, bhi)
return _Match(besti, bestj, bests... | [
"def",
"find_longest_match",
"(",
"self",
",",
"alo",
",",
"ahi",
",",
"blo",
",",
"bhi",
")",
":",
"besti",
",",
"bestj",
",",
"bestsize",
"=",
"_cdifflib",
".",
"find_longest_match",
"(",
"self",
",",
"alo",
",",
"ahi",
",",
"blo",
",",
"bhi",
")",... | Find longest matching block in a[alo:ahi] and b[blo:bhi].
Wrapper for the C implementation of this function. | [
"Find",
"longest",
"matching",
"block",
"in",
"a",
"[",
"alo",
":",
"ahi",
"]",
"and",
"b",
"[",
"blo",
":",
"bhi",
"]",
"."
] | train | https://github.com/mduggan/cdifflib/blob/95b1e28fbd14d2c2ff38e108745f7b38b89748a4/cdifflib.py#L32-L38 |
mduggan/cdifflib | cdifflib.py | CSequenceMatcher.set_seq1 | def set_seq1(self, a):
"""Same as SequenceMatcher.set_seq1, but check for non-list inputs
implementation."""
if a is self.a:
return
self.a = a
if not isinstance(self.a, list):
self.a = list(self.a)
# Types must be hashable to work in the c layer. ... | python | def set_seq1(self, a):
"""Same as SequenceMatcher.set_seq1, but check for non-list inputs
implementation."""
if a is self.a:
return
self.a = a
if not isinstance(self.a, list):
self.a = list(self.a)
# Types must be hashable to work in the c layer. ... | [
"def",
"set_seq1",
"(",
"self",
",",
"a",
")",
":",
"if",
"a",
"is",
"self",
".",
"a",
":",
"return",
"self",
".",
"a",
"=",
"a",
"if",
"not",
"isinstance",
"(",
"self",
".",
"a",
",",
"list",
")",
":",
"self",
".",
"a",
"=",
"list",
"(",
"... | Same as SequenceMatcher.set_seq1, but check for non-list inputs
implementation. | [
"Same",
"as",
"SequenceMatcher",
".",
"set_seq1",
"but",
"check",
"for",
"non",
"-",
"list",
"inputs",
"implementation",
"."
] | train | https://github.com/mduggan/cdifflib/blob/95b1e28fbd14d2c2ff38e108745f7b38b89748a4/cdifflib.py#L40-L50 |
mduggan/cdifflib | cdifflib.py | CSequenceMatcher.set_seq2 | def set_seq2(self, b):
"""Same as SequenceMatcher.set_seq2, but uses the c chainb
implementation.
"""
if b is self.b and hasattr(self, 'isbjunk'):
return
self.b = b
if not isinstance(self.a, list):
self.a = list(self.a)
if not isinstance(se... | python | def set_seq2(self, b):
"""Same as SequenceMatcher.set_seq2, but uses the c chainb
implementation.
"""
if b is self.b and hasattr(self, 'isbjunk'):
return
self.b = b
if not isinstance(self.a, list):
self.a = list(self.a)
if not isinstance(se... | [
"def",
"set_seq2",
"(",
"self",
",",
"b",
")",
":",
"if",
"b",
"is",
"self",
".",
"b",
"and",
"hasattr",
"(",
"self",
",",
"'isbjunk'",
")",
":",
"return",
"self",
".",
"b",
"=",
"b",
"if",
"not",
"isinstance",
"(",
"self",
".",
"a",
",",
"list... | Same as SequenceMatcher.set_seq2, but uses the c chainb
implementation. | [
"Same",
"as",
"SequenceMatcher",
".",
"set_seq2",
"but",
"uses",
"the",
"c",
"chainb",
"implementation",
"."
] | train | https://github.com/mduggan/cdifflib/blob/95b1e28fbd14d2c2ff38e108745f7b38b89748a4/cdifflib.py#L52-L75 |
mduggan/cdifflib | cdifflib.py | CSequenceMatcher.get_matching_blocks | def get_matching_blocks(self):
"""Same as SequenceMatcher.get_matching_blocks, but calls through to a
faster loop for find_longest_match. The rest is the same.
"""
if self.matching_blocks is not None:
return self.matching_blocks
matching_blocks = _cdifflib.matching_... | python | def get_matching_blocks(self):
"""Same as SequenceMatcher.get_matching_blocks, but calls through to a
faster loop for find_longest_match. The rest is the same.
"""
if self.matching_blocks is not None:
return self.matching_blocks
matching_blocks = _cdifflib.matching_... | [
"def",
"get_matching_blocks",
"(",
"self",
")",
":",
"if",
"self",
".",
"matching_blocks",
"is",
"not",
"None",
":",
"return",
"self",
".",
"matching_blocks",
"matching_blocks",
"=",
"_cdifflib",
".",
"matching_blocks",
"(",
"self",
")",
"matching_blocks",
".",
... | Same as SequenceMatcher.get_matching_blocks, but calls through to a
faster loop for find_longest_match. The rest is the same. | [
"Same",
"as",
"SequenceMatcher",
".",
"get_matching_blocks",
"but",
"calls",
"through",
"to",
"a",
"faster",
"loop",
"for",
"find_longest_match",
".",
"The",
"rest",
"is",
"the",
"same",
"."
] | train | https://github.com/mduggan/cdifflib/blob/95b1e28fbd14d2c2ff38e108745f7b38b89748a4/cdifflib.py#L78-L89 |
hubo1016/namedstruct | namedstruct/namedstruct.py | _tostream | def _tostream(parser, obj, stream, skipprepack = False):
"""
Compatible to old parsers
"""
if hasattr(parser, 'tostream'):
return parser.tostream(obj, stream, skipprepack)
else:
data = parser.tobytes(obj, skipprepack)
cls = type(parser)
if cls not in _deprecated_parse... | python | def _tostream(parser, obj, stream, skipprepack = False):
"""
Compatible to old parsers
"""
if hasattr(parser, 'tostream'):
return parser.tostream(obj, stream, skipprepack)
else:
data = parser.tobytes(obj, skipprepack)
cls = type(parser)
if cls not in _deprecated_parse... | [
"def",
"_tostream",
"(",
"parser",
",",
"obj",
",",
"stream",
",",
"skipprepack",
"=",
"False",
")",
":",
"if",
"hasattr",
"(",
"parser",
",",
"'tostream'",
")",
":",
"return",
"parser",
".",
"tostream",
"(",
"obj",
",",
"stream",
",",
"skipprepack",
"... | Compatible to old parsers | [
"Compatible",
"to",
"old",
"parsers"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L44-L56 |
hubo1016/namedstruct | namedstruct/namedstruct.py | _to_str | def _to_str(dumped_val, encoding='utf-8', ordered=True):
"""
Convert bytes in a dump value to str, allowing json encode
"""
_dict = OrderedDict if ordered else dict
if isinstance(dumped_val, dict):
return OrderedDict((k, _to_str(v, encoding)) for k,v in dumped_val.items())
elif isinstanc... | python | def _to_str(dumped_val, encoding='utf-8', ordered=True):
"""
Convert bytes in a dump value to str, allowing json encode
"""
_dict = OrderedDict if ordered else dict
if isinstance(dumped_val, dict):
return OrderedDict((k, _to_str(v, encoding)) for k,v in dumped_val.items())
elif isinstanc... | [
"def",
"_to_str",
"(",
"dumped_val",
",",
"encoding",
"=",
"'utf-8'",
",",
"ordered",
"=",
"True",
")",
":",
"_dict",
"=",
"OrderedDict",
"if",
"ordered",
"else",
"dict",
"if",
"isinstance",
"(",
"dumped_val",
",",
"dict",
")",
":",
"return",
"OrderedDict"... | Convert bytes in a dump value to str, allowing json encode | [
"Convert",
"bytes",
"in",
"a",
"dump",
"value",
"to",
"str",
"allowing",
"json",
"encode"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L407-L423 |
hubo1016/namedstruct | namedstruct/namedstruct.py | dump | def dump(val, humanread = True, dumpextra = False, typeinfo = DUMPTYPE_FLAT, ordered=True,
tostr=False, encoding='utf-8'):
'''
Convert a parsed NamedStruct (probably with additional NamedStruct as fields) into a
JSON-friendly format, with only Python primitives (dictionaries, lists, bytes, integers... | python | def dump(val, humanread = True, dumpextra = False, typeinfo = DUMPTYPE_FLAT, ordered=True,
tostr=False, encoding='utf-8'):
'''
Convert a parsed NamedStruct (probably with additional NamedStruct as fields) into a
JSON-friendly format, with only Python primitives (dictionaries, lists, bytes, integers... | [
"def",
"dump",
"(",
"val",
",",
"humanread",
"=",
"True",
",",
"dumpextra",
"=",
"False",
",",
"typeinfo",
"=",
"DUMPTYPE_FLAT",
",",
"ordered",
"=",
"True",
",",
"tostr",
"=",
"False",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"dumped",
"=",
"_dump",... | Convert a parsed NamedStruct (probably with additional NamedStruct as fields) into a
JSON-friendly format, with only Python primitives (dictionaries, lists, bytes, integers etc.)
Then you may use json.dumps, or pprint to further process the result.
:param val: parsed result, may contain NamedStruct
... | [
"Convert",
"a",
"parsed",
"NamedStruct",
"(",
"probably",
"with",
"additional",
"NamedStruct",
"as",
"fields",
")",
"into",
"a",
"JSON",
"-",
"friendly",
"format",
"with",
"only",
"Python",
"primitives",
"(",
"dictionaries",
"lists",
"bytes",
"integers",
"etc",
... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L426-L460 |
hubo1016/namedstruct | namedstruct/namedstruct.py | sizefromlen | def sizefromlen(limit, *properties):
'''
Factory to generate a function which get size from specified field with limits.
Often used in nstruct "size" parameter.
To retrieve size without limit, simply use lambda expression: lambda x: x.header.length
:param limit: the maximum size limit, if ... | python | def sizefromlen(limit, *properties):
'''
Factory to generate a function which get size from specified field with limits.
Often used in nstruct "size" parameter.
To retrieve size without limit, simply use lambda expression: lambda x: x.header.length
:param limit: the maximum size limit, if ... | [
"def",
"sizefromlen",
"(",
"limit",
",",
"*",
"properties",
")",
":",
"def",
"func",
"(",
"namedstruct",
")",
":",
"v",
"=",
"namedstruct",
".",
"_target",
"for",
"p",
"in",
"properties",
":",
"v",
"=",
"getattr",
"(",
"v",
",",
"p",
")",
"if",
"v"... | Factory to generate a function which get size from specified field with limits.
Often used in nstruct "size" parameter.
To retrieve size without limit, simply use lambda expression: lambda x: x.header.length
:param limit: the maximum size limit, if the acquired value if larger then the limit, BadL... | [
"Factory",
"to",
"generate",
"a",
"function",
"which",
"get",
"size",
"from",
"specified",
"field",
"with",
"limits",
".",
"Often",
"used",
"in",
"nstruct",
"size",
"parameter",
".",
"To",
"retrieve",
"size",
"without",
"limit",
"simply",
"use",
"lambda",
"e... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L519-L542 |
hubo1016/namedstruct | namedstruct/namedstruct.py | packsize | def packsize(*properties):
'''
Revert to sizefromlen, store the struct size (len(struct)) to specified property path. The size includes
padding. To store the size without padding, use packrealsize() instead. Often used in nstruct "prepack"
parameter.
:param properties: specified field name, sam... | python | def packsize(*properties):
'''
Revert to sizefromlen, store the struct size (len(struct)) to specified property path. The size includes
padding. To store the size without padding, use packrealsize() instead. Often used in nstruct "prepack"
parameter.
:param properties: specified field name, sam... | [
"def",
"packsize",
"(",
"*",
"properties",
")",
":",
"def",
"func",
"(",
"namedstruct",
")",
":",
"v",
"=",
"namedstruct",
".",
"_target",
"for",
"p",
"in",
"properties",
"[",
":",
"-",
"1",
"]",
":",
"v",
"=",
"getattr",
"(",
"v",
",",
"p",
")",... | Revert to sizefromlen, store the struct size (len(struct)) to specified property path. The size includes
padding. To store the size without padding, use packrealsize() instead. Often used in nstruct "prepack"
parameter.
:param properties: specified field name, same as sizefromlen.
:returns: a ... | [
"Revert",
"to",
"sizefromlen",
"store",
"the",
"struct",
"size",
"(",
"len",
"(",
"struct",
"))",
"to",
"specified",
"property",
"path",
".",
"The",
"size",
"includes",
"padding",
".",
"To",
"store",
"the",
"size",
"without",
"padding",
"use",
"packrealsize"... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L544-L560 |
hubo1016/namedstruct | namedstruct/namedstruct.py | packrealsize | def packrealsize(*properties):
'''
Revert to sizefromlen, pack the struct real size (struct._realsize()) to specified property path.
Unlike packsize, the size without padding is stored. Often used in nstruct "prepack" parameter.
:param properties: specified field name, same as sizefromlen.
... | python | def packrealsize(*properties):
'''
Revert to sizefromlen, pack the struct real size (struct._realsize()) to specified property path.
Unlike packsize, the size without padding is stored. Often used in nstruct "prepack" parameter.
:param properties: specified field name, same as sizefromlen.
... | [
"def",
"packrealsize",
"(",
"*",
"properties",
")",
":",
"def",
"func",
"(",
"namedstruct",
")",
":",
"v",
"=",
"namedstruct",
".",
"_target",
"for",
"p",
"in",
"properties",
"[",
":",
"-",
"1",
"]",
":",
"v",
"=",
"getattr",
"(",
"v",
",",
"p",
... | Revert to sizefromlen, pack the struct real size (struct._realsize()) to specified property path.
Unlike packsize, the size without padding is stored. Often used in nstruct "prepack" parameter.
:param properties: specified field name, same as sizefromlen.
:returns: a function which takes a NamedSt... | [
"Revert",
"to",
"sizefromlen",
"pack",
"the",
"struct",
"real",
"size",
"(",
"struct",
".",
"_realsize",
"()",
")",
"to",
"specified",
"property",
"path",
".",
"Unlike",
"packsize",
"the",
"size",
"without",
"padding",
"is",
"stored",
".",
"Often",
"used",
... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L562-L577 |
hubo1016/namedstruct | namedstruct/namedstruct.py | packvalue | def packvalue(value, *properties):
'''
Store a specified value to specified property path. Often used in nstruct "init" parameter.
:param value: a fixed value
:param properties: specified field name, same as sizefromlen.
:returns: a function which takes a NamedStruct as parameter, and... | python | def packvalue(value, *properties):
'''
Store a specified value to specified property path. Often used in nstruct "init" parameter.
:param value: a fixed value
:param properties: specified field name, same as sizefromlen.
:returns: a function which takes a NamedStruct as parameter, and... | [
"def",
"packvalue",
"(",
"value",
",",
"*",
"properties",
")",
":",
"def",
"func",
"(",
"namedstruct",
")",
":",
"v",
"=",
"namedstruct",
".",
"_target",
"for",
"p",
"in",
"properties",
"[",
":",
"-",
"1",
"]",
":",
"v",
"=",
"getattr",
"(",
"v",
... | Store a specified value to specified property path. Often used in nstruct "init" parameter.
:param value: a fixed value
:param properties: specified field name, same as sizefromlen.
:returns: a function which takes a NamedStruct as parameter, and store the value to property path. | [
"Store",
"a",
"specified",
"value",
"to",
"specified",
"property",
"path",
".",
"Often",
"used",
"in",
"nstruct",
"init",
"parameter",
".",
":",
"param",
"value",
":",
"a",
"fixed",
"value",
":",
"param",
"properties",
":",
"specified",
"field",
"name",
"s... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L579-L595 |
hubo1016/namedstruct | namedstruct/namedstruct.py | packexpr | def packexpr(func, *properties):
'''
Store a evaluated value to specified property path. Often used in nstruct "prepack" parameter.
:param func: a function which takes a NamedStruct as parameter and returns a value, often a lambda expression
:param properties: specified field name, same as siz... | python | def packexpr(func, *properties):
'''
Store a evaluated value to specified property path. Often used in nstruct "prepack" parameter.
:param func: a function which takes a NamedStruct as parameter and returns a value, often a lambda expression
:param properties: specified field name, same as siz... | [
"def",
"packexpr",
"(",
"func",
",",
"*",
"properties",
")",
":",
"def",
"func2",
"(",
"namedstruct",
")",
":",
"v",
"=",
"namedstruct",
".",
"_target",
"for",
"p",
"in",
"properties",
"[",
":",
"-",
"1",
"]",
":",
"v",
"=",
"getattr",
"(",
"v",
... | Store a evaluated value to specified property path. Often used in nstruct "prepack" parameter.
:param func: a function which takes a NamedStruct as parameter and returns a value, often a lambda expression
:param properties: specified field name, same as sizefromlen.
:returns: a function which... | [
"Store",
"a",
"evaluated",
"value",
"to",
"specified",
"property",
"path",
".",
"Often",
"used",
"in",
"nstruct",
"prepack",
"parameter",
".",
":",
"param",
"func",
":",
"a",
"function",
"which",
"takes",
"a",
"NamedStruct",
"as",
"parameter",
"and",
"return... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L597-L612 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._create_embedded_indices | def _create_embedded_indices(self):
'''
Create indices for all the embedded structs. For parser internal use.
'''
try:
_set(self, '_embedded_indices', dict((k,(self,v)) for k,v in getattr(self._parser.typedef, 'inline_names', {}).items()))
except AttributeError:
... | python | def _create_embedded_indices(self):
'''
Create indices for all the embedded structs. For parser internal use.
'''
try:
_set(self, '_embedded_indices', dict((k,(self,v)) for k,v in getattr(self._parser.typedef, 'inline_names', {}).items()))
except AttributeError:
... | [
"def",
"_create_embedded_indices",
"(",
"self",
")",
":",
"try",
":",
"_set",
"(",
"self",
",",
"'_embedded_indices'",
",",
"dict",
"(",
"(",
"k",
",",
"(",
"self",
",",
"v",
")",
")",
"for",
"k",
",",
"v",
"in",
"getattr",
"(",
"self",
".",
"_pars... | Create indices for all the embedded structs. For parser internal use. | [
"Create",
"indices",
"for",
"all",
"the",
"embedded",
"structs",
".",
"For",
"parser",
"internal",
"use",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L84-L91 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._unpack | def _unpack(self, data):
'''
Unpack a struct from bytes. For parser internal use.
'''
#self._logger.log(logging.DEBUG, 'unpacking %r', self)
current = self
while current is not None:
data = current._parser.unpack(data, current)
last = current
... | python | def _unpack(self, data):
'''
Unpack a struct from bytes. For parser internal use.
'''
#self._logger.log(logging.DEBUG, 'unpacking %r', self)
current = self
while current is not None:
data = current._parser.unpack(data, current)
last = current
... | [
"def",
"_unpack",
"(",
"self",
",",
"data",
")",
":",
"#self._logger.log(logging.DEBUG, 'unpacking %r', self)",
"current",
"=",
"self",
"while",
"current",
"is",
"not",
"None",
":",
"data",
"=",
"current",
".",
"_parser",
".",
"unpack",
"(",
"data",
",",
"curr... | Unpack a struct from bytes. For parser internal use. | [
"Unpack",
"a",
"struct",
"from",
"bytes",
".",
"For",
"parser",
"internal",
"use",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L92-L102 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._packto | def _packto(self, stream):
'''
Pack current struct into stream. For parser internal use.
:param stream: a buffered stream (File or BytesIO)
:return: packed bytes length
'''
#self._logger.log(logging.DEBUG, 'packing %r', self)
total_size = 0
... | python | def _packto(self, stream):
'''
Pack current struct into stream. For parser internal use.
:param stream: a buffered stream (File or BytesIO)
:return: packed bytes length
'''
#self._logger.log(logging.DEBUG, 'packing %r', self)
total_size = 0
... | [
"def",
"_packto",
"(",
"self",
",",
"stream",
")",
":",
"#self._logger.log(logging.DEBUG, 'packing %r', self)",
"total_size",
"=",
"0",
"current",
"=",
"self",
"while",
"current",
"is",
"not",
"None",
":",
"total_size",
"+=",
"current",
".",
"_parser",
".",
"pac... | Pack current struct into stream. For parser internal use.
:param stream: a buffered stream (File or BytesIO)
:return: packed bytes length | [
"Pack",
"current",
"struct",
"into",
"stream",
".",
"For",
"parser",
"internal",
"use",
".",
":",
"param",
"stream",
":",
"a",
"buffered",
"stream",
"(",
"File",
"or",
"BytesIO",
")",
":",
"return",
":",
"packed",
"bytes",
"length"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L113-L131 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._prepack | def _prepack(self):
'''
Prepack stage. For parser internal use.
'''
current = self
while current is not None:
current._parser.prepack(current, skip_self = True)
current = getattr(current, '_sub', None)
current = self
while current is not No... | python | def _prepack(self):
'''
Prepack stage. For parser internal use.
'''
current = self
while current is not None:
current._parser.prepack(current, skip_self = True)
current = getattr(current, '_sub', None)
current = self
while current is not No... | [
"def",
"_prepack",
"(",
"self",
")",
":",
"current",
"=",
"self",
"while",
"current",
"is",
"not",
"None",
":",
"current",
".",
"_parser",
".",
"prepack",
"(",
"current",
",",
"skip_self",
"=",
"True",
")",
"current",
"=",
"getattr",
"(",
"current",
",... | Prepack stage. For parser internal use. | [
"Prepack",
"stage",
".",
"For",
"parser",
"internal",
"use",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L133-L144 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._tobytes | def _tobytes(self, skipprepack = False):
'''
Convert the struct to bytes. This is the standard way to convert a NamedStruct to bytes.
:param skipprepack: if True, the prepack stage is skipped. For parser internal use.
:returns: converted bytes
'''
stream... | python | def _tobytes(self, skipprepack = False):
'''
Convert the struct to bytes. This is the standard way to convert a NamedStruct to bytes.
:param skipprepack: if True, the prepack stage is skipped. For parser internal use.
:returns: converted bytes
'''
stream... | [
"def",
"_tobytes",
"(",
"self",
",",
"skipprepack",
"=",
"False",
")",
":",
"stream",
"=",
"BytesIO",
"(",
")",
"self",
".",
"_tostream",
"(",
"stream",
",",
"skipprepack",
")",
"return",
"stream",
".",
"getvalue",
"(",
")"
] | Convert the struct to bytes. This is the standard way to convert a NamedStruct to bytes.
:param skipprepack: if True, the prepack stage is skipped. For parser internal use.
:returns: converted bytes | [
"Convert",
"the",
"struct",
"to",
"bytes",
".",
"This",
"is",
"the",
"standard",
"way",
"to",
"convert",
"a",
"NamedStruct",
"to",
"bytes",
".",
":",
"param",
"skipprepack",
":",
"if",
"True",
"the",
"prepack",
"stage",
"is",
"skipped",
".",
"For",
"pars... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L146-L156 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._tostream | def _tostream(self, stream, skipprepack= False):
'''
Convert the struct into a bytes stream. This is the standard way to convert a NamedStruct to bytes.
:param stream: a list of bytes to get the result
:param skipprepack: if True, the prepack stage is skipped. For parse... | python | def _tostream(self, stream, skipprepack= False):
'''
Convert the struct into a bytes stream. This is the standard way to convert a NamedStruct to bytes.
:param stream: a list of bytes to get the result
:param skipprepack: if True, the prepack stage is skipped. For parse... | [
"def",
"_tostream",
"(",
"self",
",",
"stream",
",",
"skipprepack",
"=",
"False",
")",
":",
"if",
"not",
"skipprepack",
":",
"self",
".",
"_prepack",
"(",
")",
"datasize",
"=",
"self",
".",
"_packto",
"(",
"stream",
")",
"paddingSize",
"=",
"self",
"."... | Convert the struct into a bytes stream. This is the standard way to convert a NamedStruct to bytes.
:param stream: a list of bytes to get the result
:param skipprepack: if True, the prepack stage is skipped. For parser internal use.
:returns: total appended size | [
"Convert",
"the",
"struct",
"into",
"a",
"bytes",
"stream",
".",
"This",
"is",
"the",
"standard",
"way",
"to",
"convert",
"a",
"NamedStruct",
"to",
"bytes",
".",
":",
"param",
"stream",
":",
"a",
"list",
"of",
"bytes",
"to",
"get",
"the",
"result",
":"... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L157-L173 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._realsize | def _realsize(self):
'''
Get the struct size without padding (or the "real size")
:returns: the "real size" in bytes
'''
current = self
size= 0
while current is not None:
size += current._parser.sizeof(current)
last = curr... | python | def _realsize(self):
'''
Get the struct size without padding (or the "real size")
:returns: the "real size" in bytes
'''
current = self
size= 0
while current is not None:
size += current._parser.sizeof(current)
last = curr... | [
"def",
"_realsize",
"(",
"self",
")",
":",
"current",
"=",
"self",
"size",
"=",
"0",
"while",
"current",
"is",
"not",
"None",
":",
"size",
"+=",
"current",
".",
"_parser",
".",
"sizeof",
"(",
"current",
")",
"last",
"=",
"current",
"current",
"=",
"g... | Get the struct size without padding (or the "real size")
:returns: the "real size" in bytes | [
"Get",
"the",
"struct",
"size",
"without",
"padding",
"(",
"or",
"the",
"real",
"size",
")",
":",
"returns",
":",
"the",
"real",
"size",
"in",
"bytes"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L174-L188 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._subclass | def _subclass(self, parser):
'''
Create sub-classed struct from extra data, with specified parser. For parser internal use.
:param parser: parser of subclass
'''
_set(self, '_sub', parser._create(memoryview(getattr(self, '_extra', b'')), self._target))
try:
... | python | def _subclass(self, parser):
'''
Create sub-classed struct from extra data, with specified parser. For parser internal use.
:param parser: parser of subclass
'''
_set(self, '_sub', parser._create(memoryview(getattr(self, '_extra', b'')), self._target))
try:
... | [
"def",
"_subclass",
"(",
"self",
",",
"parser",
")",
":",
"_set",
"(",
"self",
",",
"'_sub'",
",",
"parser",
".",
"_create",
"(",
"memoryview",
"(",
"getattr",
"(",
"self",
",",
"'_extra'",
",",
"b''",
")",
")",
",",
"self",
".",
"_target",
")",
")... | Create sub-classed struct from extra data, with specified parser. For parser internal use.
:param parser: parser of subclass | [
"Create",
"sub",
"-",
"classed",
"struct",
"from",
"extra",
"data",
"with",
"specified",
"parser",
".",
"For",
"parser",
"internal",
"use",
".",
":",
"param",
"parser",
":",
"parser",
"of",
"subclass"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L197-L207 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._extend | def _extend(self, newsub):
'''
Append a subclass (extension) after the base class. For parser internal use.
'''
current = self
while hasattr(current, '_sub'):
current = current._sub
_set(current, '_sub', newsub)
try:
object.__delattr__(self... | python | def _extend(self, newsub):
'''
Append a subclass (extension) after the base class. For parser internal use.
'''
current = self
while hasattr(current, '_sub'):
current = current._sub
_set(current, '_sub', newsub)
try:
object.__delattr__(self... | [
"def",
"_extend",
"(",
"self",
",",
"newsub",
")",
":",
"current",
"=",
"self",
"while",
"hasattr",
"(",
"current",
",",
"'_sub'",
")",
":",
"current",
"=",
"current",
".",
"_sub",
"_set",
"(",
"current",
",",
"'_sub'",
",",
"newsub",
")",
"try",
":"... | Append a subclass (extension) after the base class. For parser internal use. | [
"Append",
"a",
"subclass",
"(",
"extension",
")",
"after",
"the",
"base",
"class",
".",
"For",
"parser",
"internal",
"use",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L214-L225 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._gettype | def _gettype(self):
'''
Return current type of this struct
:returns: a typedef object (e.g. nstruct)
'''
current = self
lastname = getattr(current._parser, 'typedef', None)
while hasattr(current, '_sub'):
current = current._sub
... | python | def _gettype(self):
'''
Return current type of this struct
:returns: a typedef object (e.g. nstruct)
'''
current = self
lastname = getattr(current._parser, 'typedef', None)
while hasattr(current, '_sub'):
current = current._sub
... | [
"def",
"_gettype",
"(",
"self",
")",
":",
"current",
"=",
"self",
"lastname",
"=",
"getattr",
"(",
"current",
".",
"_parser",
",",
"'typedef'",
",",
"None",
")",
"while",
"hasattr",
"(",
"current",
",",
"'_sub'",
")",
":",
"current",
"=",
"current",
".... | Return current type of this struct
:returns: a typedef object (e.g. nstruct) | [
"Return",
"current",
"type",
"of",
"this",
"struct",
":",
"returns",
":",
"a",
"typedef",
"object",
"(",
"e",
".",
"g",
".",
"nstruct",
")"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L226-L240 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._setextra | def _setextra(self, extradata):
'''
Set the _extra field in the struct, which stands for the additional ("extra") data after the
defined fields.
'''
current = self
while hasattr(current, '_sub'):
current = current._sub
_set(current, '_extra', extradata... | python | def _setextra(self, extradata):
'''
Set the _extra field in the struct, which stands for the additional ("extra") data after the
defined fields.
'''
current = self
while hasattr(current, '_sub'):
current = current._sub
_set(current, '_extra', extradata... | [
"def",
"_setextra",
"(",
"self",
",",
"extradata",
")",
":",
"current",
"=",
"self",
"while",
"hasattr",
"(",
"current",
",",
"'_sub'",
")",
":",
"current",
"=",
"current",
".",
"_sub",
"_set",
"(",
"current",
",",
"'_extra'",
",",
"extradata",
")"
] | Set the _extra field in the struct, which stands for the additional ("extra") data after the
defined fields. | [
"Set",
"the",
"_extra",
"field",
"in",
"the",
"struct",
"which",
"stands",
"for",
"the",
"additional",
"(",
"extra",
")",
"data",
"after",
"the",
"defined",
"fields",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L249-L257 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._getextra | def _getextra(self):
'''
Get the extra data of this struct.
'''
current = self
while hasattr(current, '_sub'):
current = current._sub
return getattr(current, '_extra', None) | python | def _getextra(self):
'''
Get the extra data of this struct.
'''
current = self
while hasattr(current, '_sub'):
current = current._sub
return getattr(current, '_extra', None) | [
"def",
"_getextra",
"(",
"self",
")",
":",
"current",
"=",
"self",
"while",
"hasattr",
"(",
"current",
",",
"'_sub'",
")",
":",
"current",
"=",
"current",
".",
"_sub",
"return",
"getattr",
"(",
"current",
",",
"'_extra'",
",",
"None",
")"
] | Get the extra data of this struct. | [
"Get",
"the",
"extra",
"data",
"of",
"this",
"struct",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L258-L265 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._replace_embedded_type | def _replace_embedded_type(self, name, newtype):
'''
Replace the embedded struct to a newly-created struct of another type (usually based on the
original type). The attributes of the old struct is NOT preserved.
:param name: either the original type, or the name of the original ... | python | def _replace_embedded_type(self, name, newtype):
'''
Replace the embedded struct to a newly-created struct of another type (usually based on the
original type). The attributes of the old struct is NOT preserved.
:param name: either the original type, or the name of the original ... | [
"def",
"_replace_embedded_type",
"(",
"self",
",",
"name",
",",
"newtype",
")",
":",
"if",
"hasattr",
"(",
"name",
",",
"'readablename'",
")",
":",
"name",
"=",
"name",
".",
"readablename",
"t",
",",
"i",
"=",
"self",
".",
"_target",
".",
"_embedded_indi... | Replace the embedded struct to a newly-created struct of another type (usually based on the
original type). The attributes of the old struct is NOT preserved.
:param name: either the original type, or the name of the original type. It is always the type
used in type definit... | [
"Replace",
"the",
"embedded",
"struct",
"to",
"a",
"newly",
"-",
"created",
"struct",
"of",
"another",
"type",
"(",
"usually",
"based",
"on",
"the",
"original",
"type",
")",
".",
"The",
"attributes",
"of",
"the",
"old",
"struct",
"is",
"NOT",
"preserved",
... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L325-L338 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._get_embedded | def _get_embedded(self, name):
'''
Return an embedded struct object to calculate the size or use _tobytes(True) to convert just the
embedded parts.
:param name: either the original type, or the name of the original type. It is always the type
used in type de... | python | def _get_embedded(self, name):
'''
Return an embedded struct object to calculate the size or use _tobytes(True) to convert just the
embedded parts.
:param name: either the original type, or the name of the original type. It is always the type
used in type de... | [
"def",
"_get_embedded",
"(",
"self",
",",
"name",
")",
":",
"if",
"hasattr",
"(",
"name",
",",
"'readablename'",
")",
":",
"name",
"=",
"name",
".",
"readablename",
"t",
",",
"i",
"=",
"self",
".",
"_target",
".",
"_embedded_indices",
"[",
"name",
"]",... | Return an embedded struct object to calculate the size or use _tobytes(True) to convert just the
embedded parts.
:param name: either the original type, or the name of the original type. It is always the type
used in type definitions, even if it is already replaced once or m... | [
"Return",
"an",
"embedded",
"struct",
"object",
"to",
"calculate",
"the",
"size",
"or",
"use",
"_tobytes",
"(",
"True",
")",
"to",
"convert",
"just",
"the",
"embedded",
"parts",
".",
":",
"param",
"name",
":",
"either",
"the",
"original",
"type",
"or",
"... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L339-L352 |
hubo1016/namedstruct | namedstruct/namedstruct.py | NamedStruct._registerPickleType | def _registerPickleType(name, typedef):
'''
Register a type with the specified name. After registration, NamedStruct with this type
(and any sub-types) can be successfully pickled and transfered.
'''
NamedStruct._pickleNames[typedef] = name
NamedStruct._pickleTypes[name] ... | python | def _registerPickleType(name, typedef):
'''
Register a type with the specified name. After registration, NamedStruct with this type
(and any sub-types) can be successfully pickled and transfered.
'''
NamedStruct._pickleNames[typedef] = name
NamedStruct._pickleTypes[name] ... | [
"def",
"_registerPickleType",
"(",
"name",
",",
"typedef",
")",
":",
"NamedStruct",
".",
"_pickleNames",
"[",
"typedef",
"]",
"=",
"name",
"NamedStruct",
".",
"_pickleTypes",
"[",
"name",
"]",
"=",
"typedef"
] | Register a type with the specified name. After registration, NamedStruct with this type
(and any sub-types) can be successfully pickled and transfered. | [
"Register",
"a",
"type",
"with",
"the",
"specified",
"name",
".",
"After",
"registration",
"NamedStruct",
"with",
"this",
"type",
"(",
"and",
"any",
"sub",
"-",
"types",
")",
"can",
"be",
"successfully",
"pickled",
"and",
"transfered",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L354-L360 |
hubo1016/namedstruct | namedstruct/namedstruct.py | EmbeddedStruct._create_embedded_indices | def _create_embedded_indices(self):
'''
Create indices for all the embedded structs. For parser internal use.
'''
try:
self._target._embedded_indices.update(((k,(self,v)) for k,v in getattr(self._parser.typedef, 'inline_names', {}).items()))
except AttributeError:
... | python | def _create_embedded_indices(self):
'''
Create indices for all the embedded structs. For parser internal use.
'''
try:
self._target._embedded_indices.update(((k,(self,v)) for k,v in getattr(self._parser.typedef, 'inline_names', {}).items()))
except AttributeError:
... | [
"def",
"_create_embedded_indices",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"_target",
".",
"_embedded_indices",
".",
"update",
"(",
"(",
"(",
"k",
",",
"(",
"self",
",",
"v",
")",
")",
"for",
"k",
",",
"v",
"in",
"getattr",
"(",
"self",
"."... | Create indices for all the embedded structs. For parser internal use. | [
"Create",
"indices",
"for",
"all",
"the",
"embedded",
"structs",
".",
"For",
"parser",
"internal",
"use",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L366-L373 |
hubo1016/namedstruct | namedstruct/namedstruct.py | Parser.parse | def parse(self, buffer, inlineparent = None):
'''
Try to parse the struct from bytes sequence. The bytes sequence is taken from a streaming source.
:param buffer: bytes sequence to be parsed from.
:param inlineparent: if specified, this struct is embedded in another str... | python | def parse(self, buffer, inlineparent = None):
'''
Try to parse the struct from bytes sequence. The bytes sequence is taken from a streaming source.
:param buffer: bytes sequence to be parsed from.
:param inlineparent: if specified, this struct is embedded in another str... | [
"def",
"parse",
"(",
"self",
",",
"buffer",
",",
"inlineparent",
"=",
"None",
")",
":",
"if",
"self",
".",
"base",
"is",
"not",
"None",
":",
"return",
"self",
".",
"base",
".",
"parse",
"(",
"buffer",
",",
"inlineparent",
")",
"r",
"=",
"self",
"."... | Try to parse the struct from bytes sequence. The bytes sequence is taken from a streaming source.
:param buffer: bytes sequence to be parsed from.
:param inlineparent: if specified, this struct is embedded in another struct.
:returns: None if the buffer does not have e... | [
"Try",
"to",
"parse",
"the",
"struct",
"from",
"bytes",
"sequence",
".",
"The",
"bytes",
"sequence",
"is",
"taken",
"from",
"a",
"streaming",
"source",
".",
":",
"param",
"buffer",
":",
"bytes",
"sequence",
"to",
"be",
"parsed",
"from",
".",
":",
"param"... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L671-L690 |
hubo1016/namedstruct | namedstruct/namedstruct.py | Parser.subclass | def subclass(self, namedstruct):
'''
Sub-class a NamedStruct into correct sub types.
:param namedstruct: a NamedStruct of this type.
'''
cp = self
cs = namedstruct
while True:
if hasattr(cs, '_sub'):
cs = cs._sub
... | python | def subclass(self, namedstruct):
'''
Sub-class a NamedStruct into correct sub types.
:param namedstruct: a NamedStruct of this type.
'''
cp = self
cs = namedstruct
while True:
if hasattr(cs, '_sub'):
cs = cs._sub
... | [
"def",
"subclass",
"(",
"self",
",",
"namedstruct",
")",
":",
"cp",
"=",
"self",
"cs",
"=",
"namedstruct",
"while",
"True",
":",
"if",
"hasattr",
"(",
"cs",
",",
"'_sub'",
")",
":",
"cs",
"=",
"cs",
".",
"_sub",
"cp",
"=",
"cs",
".",
"_parser",
"... | Sub-class a NamedStruct into correct sub types.
:param namedstruct: a NamedStruct of this type. | [
"Sub",
"-",
"class",
"a",
"NamedStruct",
"into",
"correct",
"sub",
"types",
".",
":",
"param",
"namedstruct",
":",
"a",
"NamedStruct",
"of",
"this",
"type",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L691-L718 |
hubo1016/namedstruct | namedstruct/namedstruct.py | Parser.new | def new(self, inlineparent = None):
'''
Create an empty struct of this type. "initfunc" is called on the created struct to initialize it.
:param inlineparent: if specified, this struct is embedded into another struct "inlineparent"
:returns: a created struct (usually a ... | python | def new(self, inlineparent = None):
'''
Create an empty struct of this type. "initfunc" is called on the created struct to initialize it.
:param inlineparent: if specified, this struct is embedded into another struct "inlineparent"
:returns: a created struct (usually a ... | [
"def",
"new",
"(",
"self",
",",
"inlineparent",
"=",
"None",
")",
":",
"if",
"self",
".",
"base",
"is",
"not",
"None",
":",
"s",
"=",
"self",
".",
"base",
".",
"new",
"(",
"inlineparent",
")",
"s",
".",
"_extend",
"(",
"self",
".",
"_new",
"(",
... | Create an empty struct of this type. "initfunc" is called on the created struct to initialize it.
:param inlineparent: if specified, this struct is embedded into another struct "inlineparent"
:returns: a created struct (usually a NamedStruct object) | [
"Create",
"an",
"empty",
"struct",
"of",
"this",
"type",
".",
"initfunc",
"is",
"called",
"on",
"the",
"created",
"struct",
"to",
"initialize",
"it",
".",
":",
"param",
"inlineparent",
":",
"if",
"specified",
"this",
"struct",
"is",
"embedded",
"into",
"an... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L733-L748 |
hubo1016/namedstruct | namedstruct/namedstruct.py | Parser.create | def create(self, data, inlineparent = None):
'''
Create a struct and use all bytes of data. Different from parse(), this takes all data,
store unused bytes in "extra" data of the struct. Some types like variable-length array
may have different parse result with create() and parse().
... | python | def create(self, data, inlineparent = None):
'''
Create a struct and use all bytes of data. Different from parse(), this takes all data,
store unused bytes in "extra" data of the struct. Some types like variable-length array
may have different parse result with create() and parse().
... | [
"def",
"create",
"(",
"self",
",",
"data",
",",
"inlineparent",
"=",
"None",
")",
":",
"if",
"self",
".",
"base",
"is",
"not",
"None",
":",
"return",
"self",
".",
"base",
".",
"create",
"(",
"data",
",",
"inlineparent",
")",
"c",
"=",
"self",
".",
... | Create a struct and use all bytes of data. Different from parse(), this takes all data,
store unused bytes in "extra" data of the struct. Some types like variable-length array
may have different parse result with create() and parse().
:param data: bytes of a packed struct.
... | [
"Create",
"a",
"struct",
"and",
"use",
"all",
"bytes",
"of",
"data",
".",
"Different",
"from",
"parse",
"()",
"this",
"takes",
"all",
"data",
"store",
"unused",
"bytes",
"in",
"extra",
"data",
"of",
"the",
"struct",
".",
"Some",
"types",
"like",
"variabl... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L758-L774 |
hubo1016/namedstruct | namedstruct/namedstruct.py | Parser.paddingsize | def paddingsize(self, namedstruct):
'''
Return the size of the padded struct (including the "real" size and the padding bytes)
:param namedstruct: a NamedStruct object of this type.
:returns: size including both data and padding.
'''
if self.base is not ... | python | def paddingsize(self, namedstruct):
'''
Return the size of the padded struct (including the "real" size and the padding bytes)
:param namedstruct: a NamedStruct object of this type.
:returns: size including both data and padding.
'''
if self.base is not ... | [
"def",
"paddingsize",
"(",
"self",
",",
"namedstruct",
")",
":",
"if",
"self",
".",
"base",
"is",
"not",
"None",
":",
"return",
"self",
".",
"base",
".",
"paddingsize",
"(",
"namedstruct",
")",
"realsize",
"=",
"namedstruct",
".",
"_realsize",
"(",
")",
... | Return the size of the padded struct (including the "real" size and the padding bytes)
:param namedstruct: a NamedStruct object of this type.
:returns: size including both data and padding. | [
"Return",
"the",
"size",
"of",
"the",
"padded",
"struct",
"(",
"including",
"the",
"real",
"size",
"and",
"the",
"padding",
"bytes",
")",
":",
"param",
"namedstruct",
":",
"a",
"NamedStruct",
"object",
"of",
"this",
"type",
".",
":",
"returns",
":",
"siz... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L775-L786 |
hubo1016/namedstruct | namedstruct/namedstruct.py | Parser.paddingsize2 | def paddingsize2(self, realsize):
'''
Return a padded size from realsize, for NamedStruct internal use.
'''
if self.base is not None:
return self.base.paddingsize2(realsize)
return (realsize + self.padding - 1) // self.padding * self.padding | python | def paddingsize2(self, realsize):
'''
Return a padded size from realsize, for NamedStruct internal use.
'''
if self.base is not None:
return self.base.paddingsize2(realsize)
return (realsize + self.padding - 1) // self.padding * self.padding | [
"def",
"paddingsize2",
"(",
"self",
",",
"realsize",
")",
":",
"if",
"self",
".",
"base",
"is",
"not",
"None",
":",
"return",
"self",
".",
"base",
".",
"paddingsize2",
"(",
"realsize",
")",
"return",
"(",
"realsize",
"+",
"self",
".",
"padding",
"-",
... | Return a padded size from realsize, for NamedStruct internal use. | [
"Return",
"a",
"padded",
"size",
"from",
"realsize",
"for",
"NamedStruct",
"internal",
"use",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L787-L793 |
hubo1016/namedstruct | namedstruct/namedstruct.py | Parser.tostream | def tostream(self, namedstruct, stream, skipprepack = False):
'''
Convert a NamedStruct to packed bytes, append the bytes to the stream
:param namedstruct: a NamedStruct object of this type to pack.
:param skipprepack: if True, the prepack stage is skipped.
... | python | def tostream(self, namedstruct, stream, skipprepack = False):
'''
Convert a NamedStruct to packed bytes, append the bytes to the stream
:param namedstruct: a NamedStruct object of this type to pack.
:param skipprepack: if True, the prepack stage is skipped.
... | [
"def",
"tostream",
"(",
"self",
",",
"namedstruct",
",",
"stream",
",",
"skipprepack",
"=",
"False",
")",
":",
"return",
"namedstruct",
".",
"_tostream",
"(",
"stream",
",",
"skipprepack",
")"
] | Convert a NamedStruct to packed bytes, append the bytes to the stream
:param namedstruct: a NamedStruct object of this type to pack.
:param skipprepack: if True, the prepack stage is skipped.
:param stream: a buffered stream
:return: appended bytes siz... | [
"Convert",
"a",
"NamedStruct",
"to",
"packed",
"bytes",
"append",
"the",
"bytes",
"to",
"the",
"stream",
":",
"param",
"namedstruct",
":",
"a",
"NamedStruct",
"object",
"of",
"this",
"type",
"to",
"pack",
".",
":",
"param",
"skipprepack",
":",
"if",
"True"... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L805-L817 |
hubo1016/namedstruct | namedstruct/namedstruct.py | Parser.prepack | def prepack(self, namedstruct, skip_self=False, skip_sub=False):
'''
Run prepack
'''
if not skip_self and self.prepackfunc is not None:
self.prepackfunc(namedstruct) | python | def prepack(self, namedstruct, skip_self=False, skip_sub=False):
'''
Run prepack
'''
if not skip_self and self.prepackfunc is not None:
self.prepackfunc(namedstruct) | [
"def",
"prepack",
"(",
"self",
",",
"namedstruct",
",",
"skip_self",
"=",
"False",
",",
"skip_sub",
"=",
"False",
")",
":",
"if",
"not",
"skip_self",
"and",
"self",
".",
"prepackfunc",
"is",
"not",
"None",
":",
"self",
".",
"prepackfunc",
"(",
"namedstru... | Run prepack | [
"Run",
"prepack"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L818-L823 |
hubo1016/namedstruct | namedstruct/namedstruct.py | Parser.packto | def packto(self, namedstruct, stream):
"""
Pack a struct to a stream
:param namedstruct: struct to pack
:param stream: a buffered stream
:return: appended bytes size
"""
# Default implementation
data = self.pack(namedstruct)
... | python | def packto(self, namedstruct, stream):
"""
Pack a struct to a stream
:param namedstruct: struct to pack
:param stream: a buffered stream
:return: appended bytes size
"""
# Default implementation
data = self.pack(namedstruct)
... | [
"def",
"packto",
"(",
"self",
",",
"namedstruct",
",",
"stream",
")",
":",
"# Default implementation",
"data",
"=",
"self",
".",
"pack",
"(",
"namedstruct",
")",
"return",
"stream",
".",
"write",
"(",
"data",
")"
] | Pack a struct to a stream
:param namedstruct: struct to pack
:param stream: a buffered stream
:return: appended bytes size | [
"Pack",
"a",
"struct",
"to",
"a",
"stream",
":",
"param",
"namedstruct",
":",
"struct",
"to",
"pack",
":",
"param",
"stream",
":",
"a",
"buffered",
"stream",
":",
"return",
":",
"appended",
"bytes",
"size"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L824-L836 |
hubo1016/namedstruct | namedstruct/namedstruct.py | FormatParser.unpack | def unpack(self, data, namedstruct):
'''
Unpack the struct from specified bytes. If the struct is sub-classed, definitions from the sub type
is not unpacked.
:param data: bytes of the struct, including fields of sub type and "extra" data.
:param namedstruct: a N... | python | def unpack(self, data, namedstruct):
'''
Unpack the struct from specified bytes. If the struct is sub-classed, definitions from the sub type
is not unpacked.
:param data: bytes of the struct, including fields of sub type and "extra" data.
:param namedstruct: a N... | [
"def",
"unpack",
"(",
"self",
",",
"data",
",",
"namedstruct",
")",
":",
"try",
":",
"result",
"=",
"self",
".",
"struct",
".",
"unpack",
"(",
"data",
"[",
"0",
":",
"self",
".",
"struct",
".",
"size",
"]",
")",
"except",
"struct",
".",
"error",
... | Unpack the struct from specified bytes. If the struct is sub-classed, definitions from the sub type
is not unpacked.
:param data: bytes of the struct, including fields of sub type and "extra" data.
:param namedstruct: a NamedStruct object of this type
:returns:... | [
"Unpack",
"the",
"struct",
"from",
"specified",
"bytes",
".",
"If",
"the",
"struct",
"is",
"sub",
"-",
"classed",
"definitions",
"from",
"the",
"sub",
"type",
"is",
"not",
"unpacked",
".",
":",
"param",
"data",
":",
"bytes",
"of",
"the",
"struct",
"inclu... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L907-L945 |
hubo1016/namedstruct | namedstruct/namedstruct.py | FormatParser.pack | def pack(self, namedstruct):
'''
Pack the struct and return the packed bytes.
:param namedstruct: a NamedStruct of this type.
:returns: packed bytes, only contains fields of definitions in this type, not the sub type and "extra" data.
'''
elements = []
... | python | def pack(self, namedstruct):
'''
Pack the struct and return the packed bytes.
:param namedstruct: a NamedStruct of this type.
:returns: packed bytes, only contains fields of definitions in this type, not the sub type and "extra" data.
'''
elements = []
... | [
"def",
"pack",
"(",
"self",
",",
"namedstruct",
")",
":",
"elements",
"=",
"[",
"]",
"t",
"=",
"namedstruct",
".",
"_target",
"for",
"p",
"in",
"self",
".",
"properties",
":",
"v",
"=",
"t",
"for",
"sp",
"in",
"p",
"[",
"0",
"]",
":",
"v",
"=",... | Pack the struct and return the packed bytes.
:param namedstruct: a NamedStruct of this type.
:returns: packed bytes, only contains fields of definitions in this type, not the sub type and "extra" data. | [
"Pack",
"the",
"struct",
"and",
"return",
"the",
"packed",
"bytes",
".",
":",
"param",
"namedstruct",
":",
"a",
"NamedStruct",
"of",
"this",
"type",
".",
":",
"returns",
":",
"packed",
"bytes",
"only",
"contains",
"fields",
"of",
"definitions",
"in",
"this... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L946-L964 |
hubo1016/namedstruct | namedstruct/namedstruct.py | PrimitiveParser.parse | def parse(self, buffer, inlineparent = None):
'''
Compatible to Parser.parse()
'''
if len(buffer) < self.struct.size:
return None
try:
return (self.struct.unpack(buffer[:self.struct.size])[0], self.struct.size)
except struct.error as exc:
... | python | def parse(self, buffer, inlineparent = None):
'''
Compatible to Parser.parse()
'''
if len(buffer) < self.struct.size:
return None
try:
return (self.struct.unpack(buffer[:self.struct.size])[0], self.struct.size)
except struct.error as exc:
... | [
"def",
"parse",
"(",
"self",
",",
"buffer",
",",
"inlineparent",
"=",
"None",
")",
":",
"if",
"len",
"(",
"buffer",
")",
"<",
"self",
".",
"struct",
".",
"size",
":",
"return",
"None",
"try",
":",
"return",
"(",
"self",
".",
"struct",
".",
"unpack"... | Compatible to Parser.parse() | [
"Compatible",
"to",
"Parser",
".",
"parse",
"()"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L1246-L1255 |
hubo1016/namedstruct | namedstruct/namedstruct.py | PrimitiveParser.create | def create(self, data, inlineparent = None):
'''
Compatible to Parser.create()
'''
try:
return self.struct.unpack(data)[0]
except struct.error as exc:
raise BadFormatError(exc) | python | def create(self, data, inlineparent = None):
'''
Compatible to Parser.create()
'''
try:
return self.struct.unpack(data)[0]
except struct.error as exc:
raise BadFormatError(exc) | [
"def",
"create",
"(",
"self",
",",
"data",
",",
"inlineparent",
"=",
"None",
")",
":",
"try",
":",
"return",
"self",
".",
"struct",
".",
"unpack",
"(",
"data",
")",
"[",
"0",
"]",
"except",
"struct",
".",
"error",
"as",
"exc",
":",
"raise",
"BadFor... | Compatible to Parser.create() | [
"Compatible",
"to",
"Parser",
".",
"create",
"()"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L1261-L1268 |
hubo1016/namedstruct | namedstruct/namedstruct.py | ArrayParser.parse | def parse(self, buffer, inlineparent = None):
'''
Compatible to Parser.parse()
'''
size = 0
v = []
for i in range(0, self.size): # @UnusedVariable
r = self.innerparser.parse(buffer[size:], None)
if r is None:
return None
... | python | def parse(self, buffer, inlineparent = None):
'''
Compatible to Parser.parse()
'''
size = 0
v = []
for i in range(0, self.size): # @UnusedVariable
r = self.innerparser.parse(buffer[size:], None)
if r is None:
return None
... | [
"def",
"parse",
"(",
"self",
",",
"buffer",
",",
"inlineparent",
"=",
"None",
")",
":",
"size",
"=",
"0",
"v",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"self",
".",
"size",
")",
":",
"# @UnusedVariable",
"r",
"=",
"self",
".",
"... | Compatible to Parser.parse() | [
"Compatible",
"to",
"Parser",
".",
"parse",
"()"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L1303-L1315 |
hubo1016/namedstruct | namedstruct/namedstruct.py | ArrayParser.new | def new(self, inlineparent = None):
'''
Compatible to Parser.new()
'''
v = list(range(0, self.size))
for i in range(0, self.size):
v[i] = self.innerparser.new()
return v | python | def new(self, inlineparent = None):
'''
Compatible to Parser.new()
'''
v = list(range(0, self.size))
for i in range(0, self.size):
v[i] = self.innerparser.new()
return v | [
"def",
"new",
"(",
"self",
",",
"inlineparent",
"=",
"None",
")",
":",
"v",
"=",
"list",
"(",
"range",
"(",
"0",
",",
"self",
".",
"size",
")",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"self",
".",
"size",
")",
":",
"v",
"[",
"i",
"]"... | Compatible to Parser.new() | [
"Compatible",
"to",
"Parser",
".",
"new",
"()"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L1316-L1323 |
hubo1016/namedstruct | namedstruct/namedstruct.py | ArrayParser.create | def create(self, data, inlineparent = None):
'''
Compatible to Parser.create()
'''
if self.size > 0:
r = self.parse(data)
if r is None:
raise ParseError('data is not enough to create an array of size ' + self.size)
else:
... | python | def create(self, data, inlineparent = None):
'''
Compatible to Parser.create()
'''
if self.size > 0:
r = self.parse(data)
if r is None:
raise ParseError('data is not enough to create an array of size ' + self.size)
else:
... | [
"def",
"create",
"(",
"self",
",",
"data",
",",
"inlineparent",
"=",
"None",
")",
":",
"if",
"self",
".",
"size",
">",
"0",
":",
"r",
"=",
"self",
".",
"parse",
"(",
"data",
")",
"if",
"r",
"is",
"None",
":",
"raise",
"ParseError",
"(",
"'data is... | Compatible to Parser.create() | [
"Compatible",
"to",
"Parser",
".",
"create",
"()"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L1324-L1343 |
hubo1016/namedstruct | namedstruct/namedstruct.py | ArrayParser.sizeof | def sizeof(self, prim):
'''
Compatible to Parser.sizeof()
'''
size = 0
arraysize = self.size
if arraysize == 0:
arraysize = len(prim)
for i in range(0, arraysize):
if i >= len(prim):
tp = self.innerparser.new()
... | python | def sizeof(self, prim):
'''
Compatible to Parser.sizeof()
'''
size = 0
arraysize = self.size
if arraysize == 0:
arraysize = len(prim)
for i in range(0, arraysize):
if i >= len(prim):
tp = self.innerparser.new()
... | [
"def",
"sizeof",
"(",
"self",
",",
"prim",
")",
":",
"size",
"=",
"0",
"arraysize",
"=",
"self",
".",
"size",
"if",
"arraysize",
"==",
"0",
":",
"arraysize",
"=",
"len",
"(",
"prim",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"arraysize",
")"... | Compatible to Parser.sizeof() | [
"Compatible",
"to",
"Parser",
".",
"sizeof",
"()"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L1344-L1360 |
hubo1016/namedstruct | namedstruct/namedstruct.py | ArrayParser.tobytes | def tobytes(self, prim, skipprepack = False):
'''
Compatible to Parser.tobytes()
'''
stream = BytesIO()
self.tostream(prim, stream, skipprepack=skipprepack)
return stream.getvalue() | python | def tobytes(self, prim, skipprepack = False):
'''
Compatible to Parser.tobytes()
'''
stream = BytesIO()
self.tostream(prim, stream, skipprepack=skipprepack)
return stream.getvalue() | [
"def",
"tobytes",
"(",
"self",
",",
"prim",
",",
"skipprepack",
"=",
"False",
")",
":",
"stream",
"=",
"BytesIO",
"(",
")",
"self",
".",
"tostream",
"(",
"prim",
",",
"stream",
",",
"skipprepack",
"=",
"skipprepack",
")",
"return",
"stream",
".",
"getv... | Compatible to Parser.tobytes() | [
"Compatible",
"to",
"Parser",
".",
"tobytes",
"()"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L1366-L1372 |
hubo1016/namedstruct | namedstruct/namedstruct.py | RawParser.create | def create(self, data, inlineparent = None):
'''
Compatible to Parser.create()
'''
if self.cstr:
return _copy(data).rstrip(b'\x00')
else:
return _copy(data) | python | def create(self, data, inlineparent = None):
'''
Compatible to Parser.create()
'''
if self.cstr:
return _copy(data).rstrip(b'\x00')
else:
return _copy(data) | [
"def",
"create",
"(",
"self",
",",
"data",
",",
"inlineparent",
"=",
"None",
")",
":",
"if",
"self",
".",
"cstr",
":",
"return",
"_copy",
"(",
"data",
")",
".",
"rstrip",
"(",
"b'\\x00'",
")",
"else",
":",
"return",
"_copy",
"(",
"data",
")"
] | Compatible to Parser.create() | [
"Compatible",
"to",
"Parser",
".",
"create",
"()"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L1412-L1419 |
hubo1016/namedstruct | namedstruct/namedstruct.py | typedef.parser | def parser(self):
'''
Get parser for this type. Create the parser on first call.
'''
if not hasattr(self, '_parser'):
self._parser = self._compile()
return self._parser | python | def parser(self):
'''
Get parser for this type. Create the parser on first call.
'''
if not hasattr(self, '_parser'):
self._parser = self._compile()
return self._parser | [
"def",
"parser",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_parser'",
")",
":",
"self",
".",
"_parser",
"=",
"self",
".",
"_compile",
"(",
")",
"return",
"self",
".",
"_parser"
] | Get parser for this type. Create the parser on first call. | [
"Get",
"parser",
"for",
"this",
"type",
".",
"Create",
"the",
"parser",
"on",
"first",
"call",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L1477-L1483 |
hubo1016/namedstruct | namedstruct/namedstruct.py | typedef.new | def new(self, *args, **kwargs):
'''
Create a new object of this type. It is also available as __call__, so you can create a new object
just like creating a class instance: a = mytype(a=1,b=2)
:param args: Replace the embedded struct type. Each argument is a tuple (name, newtype)... | python | def new(self, *args, **kwargs):
'''
Create a new object of this type. It is also available as __call__, so you can create a new object
just like creating a class instance: a = mytype(a=1,b=2)
:param args: Replace the embedded struct type. Each argument is a tuple (name, newtype)... | [
"def",
"new",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"obj",
"=",
"self",
".",
"parser",
"(",
")",
".",
"new",
"(",
")",
"for",
"k",
",",
"v",
"in",
"args",
":",
"obj",
".",
"_replace_embedded_type",
"(",
"k",
",",
"... | Create a new object of this type. It is also available as __call__, so you can create a new object
just like creating a class instance: a = mytype(a=1,b=2)
:param args: Replace the embedded struct type. Each argument is a tuple (name, newtype).
It is equivalent to call _rep... | [
"Create",
"a",
"new",
"object",
"of",
"this",
"type",
".",
"It",
"is",
"also",
"available",
"as",
"__call__",
"so",
"you",
"can",
"create",
"a",
"new",
"object",
"just",
"like",
"creating",
"a",
"class",
"instance",
":",
"a",
"=",
"mytype",
"(",
"a",
... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L1508-L1530 |
hubo1016/namedstruct | namedstruct/namedstruct.py | enum.getName | def getName(self, value, defaultName = None):
'''
Get the enumerate name of a specified value.
:param value: the enumerate value
:param defaultName: returns if the enumerate value is not defined
:returns: the corresponding enumerate value or *defaultName* if not found
'''... | python | def getName(self, value, defaultName = None):
'''
Get the enumerate name of a specified value.
:param value: the enumerate value
:param defaultName: returns if the enumerate value is not defined
:returns: the corresponding enumerate value or *defaultName* if not found
'''... | [
"def",
"getName",
"(",
"self",
",",
"value",
",",
"defaultName",
"=",
"None",
")",
":",
"for",
"k",
",",
"v",
"in",
"self",
".",
"_values",
".",
"items",
"(",
")",
":",
"if",
"v",
"==",
"value",
":",
"return",
"k",
"return",
"defaultName"
] | Get the enumerate name of a specified value.
:param value: the enumerate value
:param defaultName: returns if the enumerate value is not defined
:returns: the corresponding enumerate value or *defaultName* if not found | [
"Get",
"the",
"enumerate",
"name",
"of",
"a",
"specified",
"value",
".",
":",
"param",
"value",
":",
"the",
"enumerate",
"value",
":",
"param",
"defaultName",
":",
"returns",
"if",
"the",
"enumerate",
"value",
"is",
"not",
"defined",
":",
"returns",
":",
... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L2559-L2569 |
hubo1016/namedstruct | namedstruct/namedstruct.py | enum.importAll | def importAll(self, gs):
'''
Import all the enumerate values from this enumerate to *gs*
:param gs: usually globals(), a dictionary. At lease __setitem__ should be implemented if not a dictionary.
'''
for k,v in self._values.items():
gs[k] = v | python | def importAll(self, gs):
'''
Import all the enumerate values from this enumerate to *gs*
:param gs: usually globals(), a dictionary. At lease __setitem__ should be implemented if not a dictionary.
'''
for k,v in self._values.items():
gs[k] = v | [
"def",
"importAll",
"(",
"self",
",",
"gs",
")",
":",
"for",
"k",
",",
"v",
"in",
"self",
".",
"_values",
".",
"items",
"(",
")",
":",
"gs",
"[",
"k",
"]",
"=",
"v"
] | Import all the enumerate values from this enumerate to *gs*
:param gs: usually globals(), a dictionary. At lease __setitem__ should be implemented if not a dictionary. | [
"Import",
"all",
"the",
"enumerate",
"values",
"from",
"this",
"enumerate",
"to",
"*",
"gs",
"*",
":",
"param",
"gs",
":",
"usually",
"globals",
"()",
"a",
"dictionary",
".",
"At",
"lease",
"__setitem__",
"should",
"be",
"implemented",
"if",
"not",
"a",
... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L2578-L2584 |
hubo1016/namedstruct | namedstruct/namedstruct.py | enum.extend | def extend(self, namespace = None, name = None, **kwargs):
'''
Create a new enumerate with current values merged with new enumerate values
:param namespace: same as __init__
:param name: same as __init__
:param kwargs: same as __init__
:returns: a new enumerate type
... | python | def extend(self, namespace = None, name = None, **kwargs):
'''
Create a new enumerate with current values merged with new enumerate values
:param namespace: same as __init__
:param name: same as __init__
:param kwargs: same as __init__
:returns: a new enumerate type
... | [
"def",
"extend",
"(",
"self",
",",
"namespace",
"=",
"None",
",",
"name",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"_readablename",
"d",
"=",
"dict",
"(",
"self",
".",
"_values",
"... | Create a new enumerate with current values merged with new enumerate values
:param namespace: same as __init__
:param name: same as __init__
:param kwargs: same as __init__
:returns: a new enumerate type | [
"Create",
"a",
"new",
"enumerate",
"with",
"current",
"values",
"merged",
"with",
"new",
"enumerate",
"values",
":",
"param",
"namespace",
":",
"same",
"as",
"__init__",
":",
"param",
"name",
":",
"same",
"as",
"__init__",
":",
"param",
"kwargs",
":",
"sam... | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L2585-L2597 |
hubo1016/namedstruct | namedstruct/namedstruct.py | enum.formatter | def formatter(self, value):
'''
Format a enumerate value to enumerate names if possible. Used to generate human readable
dump result.
'''
if not self._bitwise:
n = self.getName(value)
if n is None:
return value
else:
... | python | def formatter(self, value):
'''
Format a enumerate value to enumerate names if possible. Used to generate human readable
dump result.
'''
if not self._bitwise:
n = self.getName(value)
if n is None:
return value
else:
... | [
"def",
"formatter",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"self",
".",
"_bitwise",
":",
"n",
"=",
"self",
".",
"getName",
"(",
"value",
")",
"if",
"n",
"is",
"None",
":",
"return",
"value",
"else",
":",
"return",
"n",
"else",
":",
"na... | Format a enumerate value to enumerate names if possible. Used to generate human readable
dump result. | [
"Format",
"a",
"enumerate",
"value",
"to",
"enumerate",
"names",
"if",
"possible",
".",
"Used",
"to",
"generate",
"human",
"readable",
"dump",
"result",
"."
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L2626-L2648 |
hubo1016/namedstruct | namedstruct/namedstruct.py | OptionalParser.packto | def packto(self, namedstruct, stream):
"""
Pack a struct to a stream
"""
if hasattr(namedstruct, self.name):
return _tostream(self.basetypeparser, getattr(namedstruct, self.name), stream, True)
else:
return 0 | python | def packto(self, namedstruct, stream):
"""
Pack a struct to a stream
"""
if hasattr(namedstruct, self.name):
return _tostream(self.basetypeparser, getattr(namedstruct, self.name), stream, True)
else:
return 0 | [
"def",
"packto",
"(",
"self",
",",
"namedstruct",
",",
"stream",
")",
":",
"if",
"hasattr",
"(",
"namedstruct",
",",
"self",
".",
"name",
")",
":",
"return",
"_tostream",
"(",
"self",
".",
"basetypeparser",
",",
"getattr",
"(",
"namedstruct",
",",
"self"... | Pack a struct to a stream | [
"Pack",
"a",
"struct",
"to",
"a",
"stream"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L2764-L2771 |
hubo1016/namedstruct | namedstruct/namedstruct.py | OptionalParser.prepack | def prepack(self, namedstruct, skip_self=False, skip_sub=False):
'''
Run prepack
'''
if not skip_sub and hasattr(namedstruct, self.name) and hasattr(self.basetypeparser, 'fullprepack'):
self.basetypeparser.fullprepack(getattr(namedstruct, self.name))
Parser.prepack(se... | python | def prepack(self, namedstruct, skip_self=False, skip_sub=False):
'''
Run prepack
'''
if not skip_sub and hasattr(namedstruct, self.name) and hasattr(self.basetypeparser, 'fullprepack'):
self.basetypeparser.fullprepack(getattr(namedstruct, self.name))
Parser.prepack(se... | [
"def",
"prepack",
"(",
"self",
",",
"namedstruct",
",",
"skip_self",
"=",
"False",
",",
"skip_sub",
"=",
"False",
")",
":",
"if",
"not",
"skip_sub",
"and",
"hasattr",
"(",
"namedstruct",
",",
"self",
".",
"name",
")",
"and",
"hasattr",
"(",
"self",
"."... | Run prepack | [
"Run",
"prepack"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L2779-L2785 |
hubo1016/namedstruct | namedstruct/namedstruct.py | DArrayParser.prepack | def prepack(self, namedstruct, skip_self=False, skip_sub=False):
'''
Run prepack
'''
if not skip_sub and hasattr(self.innertypeparser, 'fullprepack'):
for v in getattr(namedstruct, self.name):
self.innertypeparser.fullprepack(v)
Parser.prepack(self, na... | python | def prepack(self, namedstruct, skip_self=False, skip_sub=False):
'''
Run prepack
'''
if not skip_sub and hasattr(self.innertypeparser, 'fullprepack'):
for v in getattr(namedstruct, self.name):
self.innertypeparser.fullprepack(v)
Parser.prepack(self, na... | [
"def",
"prepack",
"(",
"self",
",",
"namedstruct",
",",
"skip_self",
"=",
"False",
",",
"skip_sub",
"=",
"False",
")",
":",
"if",
"not",
"skip_sub",
"and",
"hasattr",
"(",
"self",
".",
"innertypeparser",
",",
"'fullprepack'",
")",
":",
"for",
"v",
"in",
... | Run prepack | [
"Run",
"prepack"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L2928-L2935 |
hubo1016/namedstruct | namedstruct/namedstruct.py | VariantParser.prepack | def prepack(self, namedstruct, skip_self=False, skip_sub=False):
'''
Run prepack
'''
if not skip_sub and self.header is not None and hasattr(self.header, 'fullprepack'):
self.header.fullprepack(namedstruct._seqs[0])
Parser.prepack(self, namedstruct, skip_self, skip_su... | python | def prepack(self, namedstruct, skip_self=False, skip_sub=False):
'''
Run prepack
'''
if not skip_sub and self.header is not None and hasattr(self.header, 'fullprepack'):
self.header.fullprepack(namedstruct._seqs[0])
Parser.prepack(self, namedstruct, skip_self, skip_su... | [
"def",
"prepack",
"(",
"self",
",",
"namedstruct",
",",
"skip_self",
"=",
"False",
",",
"skip_sub",
"=",
"False",
")",
":",
"if",
"not",
"skip_sub",
"and",
"self",
".",
"header",
"is",
"not",
"None",
"and",
"hasattr",
"(",
"self",
".",
"header",
",",
... | Run prepack | [
"Run",
"prepack"
] | train | https://github.com/hubo1016/namedstruct/blob/5039026e0df4ce23003d212358918dbe1a6e1d76/namedstruct/namedstruct.py#L3300-L3306 |
mesowx/MesoPy | MesoPy.py | Meso._checkresponse | def _checkresponse(response):
r""" Returns the data requested by the other methods assuming the response from the API is ok. If not, provides
error handling for all possible API errors. HTTP errors are handled in the get_response() function.
Arguments:
----------
None.
... | python | def _checkresponse(response):
r""" Returns the data requested by the other methods assuming the response from the API is ok. If not, provides
error handling for all possible API errors. HTTP errors are handled in the get_response() function.
Arguments:
----------
None.
... | [
"def",
"_checkresponse",
"(",
"response",
")",
":",
"results_error",
"=",
"'No results were found matching your query'",
"auth_error",
"=",
"'The token or API key is not valid, please contact Josh Clark at joshua.m.clark@utah.edu to '",
"'resolve this'",
"rule_error",
"=",
"'This reque... | r""" Returns the data requested by the other methods assuming the response from the API is ok. If not, provides
error handling for all possible API errors. HTTP errors are handled in the get_response() function.
Arguments:
----------
None.
Returns:
--------
... | [
"r",
"Returns",
"the",
"data",
"requested",
"by",
"the",
"other",
"methods",
"assuming",
"the",
"response",
"from",
"the",
"API",
"is",
"ok",
".",
"If",
"not",
"provides",
"error",
"handling",
"for",
"all",
"possible",
"API",
"errors",
".",
"HTTP",
"errors... | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L84-L125 |
mesowx/MesoPy | MesoPy.py | Meso._get_response | def _get_response(self, endpoint, request_dict):
""" Returns a dictionary of data requested by each function.
Arguments:
----------
endpoint: string, mandatory
Set in all other methods, this is the API endpoint specific to each function.
request_dict: string, mandato... | python | def _get_response(self, endpoint, request_dict):
""" Returns a dictionary of data requested by each function.
Arguments:
----------
endpoint: string, mandatory
Set in all other methods, this is the API endpoint specific to each function.
request_dict: string, mandato... | [
"def",
"_get_response",
"(",
"self",
",",
"endpoint",
",",
"request_dict",
")",
":",
"http_error",
"=",
"'Could not connect to the API. This could be because you have no internet connection, a parameter'",
"' was input incorrectly, or the API is currently down. Please try again.'",
"json... | Returns a dictionary of data requested by each function.
Arguments:
----------
endpoint: string, mandatory
Set in all other methods, this is the API endpoint specific to each function.
request_dict: string, mandatory
A dictionary of parameters that are formatted ... | [
"Returns",
"a",
"dictionary",
"of",
"data",
"requested",
"by",
"each",
"function",
"."
] | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L127-L173 |
mesowx/MesoPy | MesoPy.py | Meso._check_geo_param | def _check_geo_param(self, arg_list):
r""" Checks each function call to make sure that the user has provided at least one of the following geographic
parameters: 'stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa', 'nwsfirezone', 'gacc', or 'subgacc'.
Arguments:
----------
... | python | def _check_geo_param(self, arg_list):
r""" Checks each function call to make sure that the user has provided at least one of the following geographic
parameters: 'stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa', 'nwsfirezone', 'gacc', or 'subgacc'.
Arguments:
----------
... | [
"def",
"_check_geo_param",
"(",
"self",
",",
"arg_list",
")",
":",
"geo_func",
"=",
"lambda",
"a",
",",
"b",
":",
"any",
"(",
"i",
"in",
"b",
"for",
"i",
"in",
"a",
")",
"check",
"=",
"geo_func",
"(",
"self",
".",
"geo_criteria",
",",
"arg_list",
"... | r""" Checks each function call to make sure that the user has provided at least one of the following geographic
parameters: 'stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa', 'nwsfirezone', 'gacc', or 'subgacc'.
Arguments:
----------
arg_list: list, mandatory
A l... | [
"r",
"Checks",
"each",
"function",
"call",
"to",
"make",
"sure",
"that",
"the",
"user",
"has",
"provided",
"at",
"least",
"one",
"of",
"the",
"following",
"geographic",
"parameters",
":",
"stid",
"state",
"country",
"county",
"radius",
"bbox",
"cwa",
"nwsfir... | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L175-L198 |
mesowx/MesoPy | MesoPy.py | Meso.attime | def attime(self, **kwargs):
r""" Returns a dictionary of latest observations at a user specified location for a specified time. Users must
specify at least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or 'subgacc') to obta... | python | def attime(self, **kwargs):
r""" Returns a dictionary of latest observations at a user specified location for a specified time. Users must
specify at least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or 'subgacc') to obta... | [
"def",
"attime",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_check_geo_param",
"(",
"kwargs",
")",
"kwargs",
"[",
"'token'",
"]",
"=",
"self",
".",
"token",
"return",
"self",
".",
"_get_response",
"(",
"'stations/nearesttime'",
",",
"k... | r""" Returns a dictionary of latest observations at a user specified location for a specified time. Users must
specify at least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or 'subgacc') to obtain observation data. Other parameter... | [
"r",
"Returns",
"a",
"dictionary",
"of",
"latest",
"observations",
"at",
"a",
"user",
"specified",
"location",
"for",
"a",
"specified",
"time",
".",
"Users",
"must",
"specify",
"at",
"least",
"one",
"geographic",
"search",
"parameter",
"(",
"stid",
"state",
... | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L200-L273 |
mesowx/MesoPy | MesoPy.py | Meso.precip | def precip(self, start, end, **kwargs):
r""" Returns precipitation observations at a user specified location for a specified time. Users must specify at
least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or 'subgacc') to o... | python | def precip(self, start, end, **kwargs):
r""" Returns precipitation observations at a user specified location for a specified time. Users must specify at
least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or 'subgacc') to o... | [
"def",
"precip",
"(",
"self",
",",
"start",
",",
"end",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_check_geo_param",
"(",
"kwargs",
")",
"kwargs",
"[",
"'start'",
"]",
"=",
"start",
"kwargs",
"[",
"'end'",
"]",
"=",
"end",
"kwargs",
"[",
"'t... | r""" Returns precipitation observations at a user specified location for a specified time. Users must specify at
least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or 'subgacc') to obtain observation data. Other parameters may als... | [
"r",
"Returns",
"precipitation",
"observations",
"at",
"a",
"user",
"specified",
"location",
"for",
"a",
"specified",
"time",
".",
"Users",
"must",
"specify",
"at",
"least",
"one",
"geographic",
"search",
"parameter",
"(",
"stid",
"state",
"country",
"county",
... | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L346-L420 |
mesowx/MesoPy | MesoPy.py | Meso.timeseries | def timeseries(self, start, end, **kwargs):
r""" Returns a time series of observations at a user specified location for a specified time. Users must specify
at least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or 'subgacc... | python | def timeseries(self, start, end, **kwargs):
r""" Returns a time series of observations at a user specified location for a specified time. Users must specify
at least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or 'subgacc... | [
"def",
"timeseries",
"(",
"self",
",",
"start",
",",
"end",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_check_geo_param",
"(",
"kwargs",
")",
"kwargs",
"[",
"'start'",
"]",
"=",
"start",
"kwargs",
"[",
"'end'",
"]",
"=",
"end",
"kwargs",
"[",
... | r""" Returns a time series of observations at a user specified location for a specified time. Users must specify
at least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or 'subgacc') to obtain observation data. Other parameters may ... | [
"r",
"Returns",
"a",
"time",
"series",
"of",
"observations",
"at",
"a",
"user",
"specified",
"location",
"for",
"a",
"specified",
"time",
".",
"Users",
"must",
"specify",
"at",
"least",
"one",
"geographic",
"search",
"parameter",
"(",
"stid",
"state",
"count... | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L422-L495 |
mesowx/MesoPy | MesoPy.py | Meso.climatology | def climatology(self, startclim, endclim, **kwargs):
r""" Returns a climatology of observations at a user specified location for a specified time. Users must specify
at least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or... | python | def climatology(self, startclim, endclim, **kwargs):
r""" Returns a climatology of observations at a user specified location for a specified time. Users must specify
at least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or... | [
"def",
"climatology",
"(",
"self",
",",
"startclim",
",",
"endclim",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_check_geo_param",
"(",
"kwargs",
")",
"kwargs",
"[",
"'startclim'",
"]",
"=",
"startclim",
"kwargs",
"[",
"'endclim'",
"]",
"=",
"endcl... | r""" Returns a climatology of observations at a user specified location for a specified time. Users must specify
at least one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa',
'nwsfirezone', 'gacc', or 'subgacc') to obtain observation data. Other parameters may ... | [
"r",
"Returns",
"a",
"climatology",
"of",
"observations",
"at",
"a",
"user",
"specified",
"location",
"for",
"a",
"specified",
"time",
".",
"Users",
"must",
"specify",
"at",
"least",
"one",
"geographic",
"search",
"parameter",
"(",
"stid",
"state",
"country",
... | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L497-L571 |
mesowx/MesoPy | MesoPy.py | Meso.climate_stats | def climate_stats(self, startclim, endclim, type, **kwargs):
r""" Returns a dictionary of aggregated yearly climate statistics (count, standard deviation,
average, median, maximum, minimum, min time, and max time depending on user specified type) of a time series
for a specified range of time at... | python | def climate_stats(self, startclim, endclim, type, **kwargs):
r""" Returns a dictionary of aggregated yearly climate statistics (count, standard deviation,
average, median, maximum, minimum, min time, and max time depending on user specified type) of a time series
for a specified range of time at... | [
"def",
"climate_stats",
"(",
"self",
",",
"startclim",
",",
"endclim",
",",
"type",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_check_geo_param",
"(",
"kwargs",
")",
"kwargs",
"[",
"'type'",
"]",
"=",
"type",
"kwargs",
"[",
"'startclim'",
"]",
"=... | r""" Returns a dictionary of aggregated yearly climate statistics (count, standard deviation,
average, median, maximum, minimum, min time, and max time depending on user specified type) of a time series
for a specified range of time at user specified location. Users must specify at least one geographic... | [
"r",
"Returns",
"a",
"dictionary",
"of",
"aggregated",
"yearly",
"climate",
"statistics",
"(",
"count",
"standard",
"deviation",
"average",
"median",
"maximum",
"minimum",
"min",
"time",
"and",
"max",
"time",
"depending",
"on",
"user",
"specified",
"type",
")",
... | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L594-L672 |
mesowx/MesoPy | MesoPy.py | Meso.time_stats | def time_stats(self, start, end, type, **kwargs):
r""" Returns a dictionary of discrete time statistics (count, standard deviation, average, median, maximum,
minimum, min time, and max time depending on user specified type) of a time series for a specified range of time
at user specified locatio... | python | def time_stats(self, start, end, type, **kwargs):
r""" Returns a dictionary of discrete time statistics (count, standard deviation, average, median, maximum,
minimum, min time, and max time depending on user specified type) of a time series for a specified range of time
at user specified locatio... | [
"def",
"time_stats",
"(",
"self",
",",
"start",
",",
"end",
",",
"type",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_check_geo_param",
"(",
"kwargs",
")",
"kwargs",
"[",
"'type'",
"]",
"=",
"type",
"kwargs",
"[",
"'start'",
"]",
"=",
"start",
... | r""" Returns a dictionary of discrete time statistics (count, standard deviation, average, median, maximum,
minimum, min time, and max time depending on user specified type) of a time series for a specified range of time
at user specified location. Users must specify at least one geographic search param... | [
"r",
"Returns",
"a",
"dictionary",
"of",
"discrete",
"time",
"statistics",
"(",
"count",
"standard",
"deviation",
"average",
"median",
"maximum",
"minimum",
"min",
"time",
"and",
"max",
"time",
"depending",
"on",
"user",
"specified",
"type",
")",
"of",
"a",
... | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L674-L752 |
mesowx/MesoPy | MesoPy.py | Meso.metadata | def metadata(self, **kwargs):
r""" Returns the metadata for a station or stations. Users must specify at least one geographic search parameter
('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa', 'nwsfirezone', 'gacc', or 'subgacc') to obtain
observation data. Other parameters may als... | python | def metadata(self, **kwargs):
r""" Returns the metadata for a station or stations. Users must specify at least one geographic search parameter
('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa', 'nwsfirezone', 'gacc', or 'subgacc') to obtain
observation data. Other parameters may als... | [
"def",
"metadata",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_check_geo_param",
"(",
"kwargs",
")",
"kwargs",
"[",
"'token'",
"]",
"=",
"self",
".",
"token",
"return",
"self",
".",
"_get_response",
"(",
"'stations/metadata'",
",",
"kw... | r""" Returns the metadata for a station or stations. Users must specify at least one geographic search parameter
('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa', 'nwsfirezone', 'gacc', or 'subgacc') to obtain
observation data. Other parameters may also be included. See below for optional ... | [
"r",
"Returns",
"the",
"metadata",
"for",
"a",
"station",
"or",
"stations",
".",
"Users",
"must",
"specify",
"at",
"least",
"one",
"geographic",
"search",
"parameter",
"(",
"stid",
"state",
"country",
"county",
"radius",
"bbox",
"cwa",
"nwsfirezone",
"gacc",
... | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L754-L827 |
mesowx/MesoPy | MesoPy.py | Meso.latency | def latency(self, start, end, **kwargs):
r""" Returns data latency values for a station based on a start and end date/time. Users must specify at least
one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa', 'nwsfirezone',
'gacc', or 'subgacc') to obtain o... | python | def latency(self, start, end, **kwargs):
r""" Returns data latency values for a station based on a start and end date/time. Users must specify at least
one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa', 'nwsfirezone',
'gacc', or 'subgacc') to obtain o... | [
"def",
"latency",
"(",
"self",
",",
"start",
",",
"end",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_check_geo_param",
"(",
"kwargs",
")",
"kwargs",
"[",
"'start'",
"]",
"=",
"start",
"kwargs",
"[",
"'end'",
"]",
"=",
"end",
"kwargs",
"[",
"'... | r""" Returns data latency values for a station based on a start and end date/time. Users must specify at least
one geographic search parameter ('stid', 'state', 'country', 'county', 'radius', 'bbox', 'cwa', 'nwsfirezone',
'gacc', or 'subgacc') to obtain observation data. Other parameters may also be inc... | [
"r",
"Returns",
"data",
"latency",
"values",
"for",
"a",
"station",
"based",
"on",
"a",
"start",
"and",
"end",
"date",
"/",
"time",
".",
"Users",
"must",
"specify",
"at",
"least",
"one",
"geographic",
"search",
"parameter",
"(",
"stid",
"state",
"country",... | train | https://github.com/mesowx/MesoPy/blob/cd1e837e108ed7a110d81cf789f19afcdd52145b/MesoPy.py#L829-L901 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.avg | def avg(self, key=None):
"""
Get the average value of a given key.
:param key: The key to get the average for
:type key: mixed
:rtype: float or int
"""
count = self.count()
if count:
return self.sum(key) / count | python | def avg(self, key=None):
"""
Get the average value of a given key.
:param key: The key to get the average for
:type key: mixed
:rtype: float or int
"""
count = self.count()
if count:
return self.sum(key) / count | [
"def",
"avg",
"(",
"self",
",",
"key",
"=",
"None",
")",
":",
"count",
"=",
"self",
".",
"count",
"(",
")",
"if",
"count",
":",
"return",
"self",
".",
"sum",
"(",
"key",
")",
"/",
"count"
] | Get the average value of a given key.
:param key: The key to get the average for
:type key: mixed
:rtype: float or int | [
"Get",
"the",
"average",
"value",
"of",
"a",
"given",
"key",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L59-L71 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.chunk | def chunk(self, size):
"""
Chunk the underlying collection.
:param size: The chunk size
:type size: int
:rtype: Collection
"""
chunks = self._chunk(size)
return self.__class__(list(map(self.__class__, chunks))) | python | def chunk(self, size):
"""
Chunk the underlying collection.
:param size: The chunk size
:type size: int
:rtype: Collection
"""
chunks = self._chunk(size)
return self.__class__(list(map(self.__class__, chunks))) | [
"def",
"chunk",
"(",
"self",
",",
"size",
")",
":",
"chunks",
"=",
"self",
".",
"_chunk",
"(",
"size",
")",
"return",
"self",
".",
"__class__",
"(",
"list",
"(",
"map",
"(",
"self",
".",
"__class__",
",",
"chunks",
")",
")",
")"
] | Chunk the underlying collection.
:param size: The chunk size
:type size: int
:rtype: Collection | [
"Chunk",
"the",
"underlying",
"collection",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L73-L84 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection._chunk | def _chunk(self, size):
"""
Chunk the underlying collection.
:param size: The chunk size
:type size: int
:rtype: Collection
"""
items = self.items
return [items[i:i + size] for i in range(0, len(items), size)] | python | def _chunk(self, size):
"""
Chunk the underlying collection.
:param size: The chunk size
:type size: int
:rtype: Collection
"""
items = self.items
return [items[i:i + size] for i in range(0, len(items), size)] | [
"def",
"_chunk",
"(",
"self",
",",
"size",
")",
":",
"items",
"=",
"self",
".",
"items",
"return",
"[",
"items",
"[",
"i",
":",
"i",
"+",
"size",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"items",
")",
",",
"size",
")",
"]"
] | Chunk the underlying collection.
:param size: The chunk size
:type size: int
:rtype: Collection | [
"Chunk",
"the",
"underlying",
"collection",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L86-L97 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.contains | def contains(self, key, value=None):
"""
Determine if an element is in the collection
:param key: The element
:type key: int or str or callable
:param value: The value of the element
:type value: mixed
:return: Whether the element is in the collection
:... | python | def contains(self, key, value=None):
"""
Determine if an element is in the collection
:param key: The element
:type key: int or str or callable
:param value: The value of the element
:type value: mixed
:return: Whether the element is in the collection
:... | [
"def",
"contains",
"(",
"self",
",",
"key",
",",
"value",
"=",
"None",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"return",
"self",
".",
"contains",
"(",
"lambda",
"x",
":",
"data_get",
"(",
"x",
",",
"key",
")",
"==",
"value",
")",
"if",... | Determine if an element is in the collection
:param key: The element
:type key: int or str or callable
:param value: The value of the element
:type value: mixed
:return: Whether the element is in the collection
:rtype: bool | [
"Determine",
"if",
"an",
"element",
"is",
"in",
"the",
"collection"
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L102-L121 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.collapse | def collapse(self):
"""
Collapse the collection items into a single element (list)
:return: A new Collection instance with collapsed items
:rtype: Collection
"""
results = []
items = self.items
for values in items:
if isinstance(values, Base... | python | def collapse(self):
"""
Collapse the collection items into a single element (list)
:return: A new Collection instance with collapsed items
:rtype: Collection
"""
results = []
items = self.items
for values in items:
if isinstance(values, Base... | [
"def",
"collapse",
"(",
"self",
")",
":",
"results",
"=",
"[",
"]",
"items",
"=",
"self",
".",
"items",
"for",
"values",
"in",
"items",
":",
"if",
"isinstance",
"(",
"values",
",",
"BaseCollection",
")",
":",
"values",
"=",
"values",
".",
"all",
"(",... | Collapse the collection items into a single element (list)
:return: A new Collection instance with collapsed items
:rtype: Collection | [
"Collapse",
"the",
"collection",
"items",
"into",
"a",
"single",
"element",
"(",
"list",
")"
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L123-L140 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.diff | def diff(self, items):
"""
Diff the collections with the given items
:param items: The items to diff with
:type items: mixed
:return: A Collection instance
:rtype: Collection
"""
return self.__class__([i for i in self.items if i not in items]) | python | def diff(self, items):
"""
Diff the collections with the given items
:param items: The items to diff with
:type items: mixed
:return: A Collection instance
:rtype: Collection
"""
return self.__class__([i for i in self.items if i not in items]) | [
"def",
"diff",
"(",
"self",
",",
"items",
")",
":",
"return",
"self",
".",
"__class__",
"(",
"[",
"i",
"for",
"i",
"in",
"self",
".",
"items",
"if",
"i",
"not",
"in",
"items",
"]",
")"
] | Diff the collections with the given items
:param items: The items to diff with
:type items: mixed
:return: A Collection instance
:rtype: Collection | [
"Diff",
"the",
"collections",
"with",
"the",
"given",
"items"
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L145-L155 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.each | def each(self, callback):
"""
Execute a callback over each item.
.. code::
collection = Collection([1, 2, 3])
collection.each(lambda x: x + 3)
.. warning::
It only applies the callback but does not modify the collection's items.
Use the... | python | def each(self, callback):
"""
Execute a callback over each item.
.. code::
collection = Collection([1, 2, 3])
collection.each(lambda x: x + 3)
.. warning::
It only applies the callback but does not modify the collection's items.
Use the... | [
"def",
"each",
"(",
"self",
",",
"callback",
")",
":",
"items",
"=",
"self",
".",
"items",
"for",
"item",
"in",
"items",
":",
"if",
"callback",
"(",
"item",
")",
"is",
"False",
":",
"break",
"return",
"self"
] | Execute a callback over each item.
.. code::
collection = Collection([1, 2, 3])
collection.each(lambda x: x + 3)
.. warning::
It only applies the callback but does not modify the collection's items.
Use the `transform() <#backpack.Collection.transform>... | [
"Execute",
"a",
"callback",
"over",
"each",
"item",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L157-L183 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.every | def every(self, step, offset=0):
"""
Create a new collection consisting of every n-th element.
:param step: The step size
:type step: int
:param offset: The start offset
:type offset: int
:rtype: Collection
"""
new = []
for position, it... | python | def every(self, step, offset=0):
"""
Create a new collection consisting of every n-th element.
:param step: The step size
:type step: int
:param offset: The start offset
:type offset: int
:rtype: Collection
"""
new = []
for position, it... | [
"def",
"every",
"(",
"self",
",",
"step",
",",
"offset",
"=",
"0",
")",
":",
"new",
"=",
"[",
"]",
"for",
"position",
",",
"item",
"in",
"enumerate",
"(",
"self",
".",
"items",
")",
":",
"if",
"position",
"%",
"step",
"==",
"offset",
":",
"new",
... | Create a new collection consisting of every n-th element.
:param step: The step size
:type step: int
:param offset: The start offset
:type offset: int
:rtype: Collection | [
"Create",
"a",
"new",
"collection",
"consisting",
"of",
"every",
"n",
"-",
"th",
"element",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L185-L203 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.without | def without(self, *keys):
"""
Get all items except for those with the specified keys.
:param keys: The keys to remove
:type keys: tuple
:rtype: Collection
"""
items = copy(self.items)
keys = reversed(sorted(keys))
for key in keys:
d... | python | def without(self, *keys):
"""
Get all items except for those with the specified keys.
:param keys: The keys to remove
:type keys: tuple
:rtype: Collection
"""
items = copy(self.items)
keys = reversed(sorted(keys))
for key in keys:
d... | [
"def",
"without",
"(",
"self",
",",
"*",
"keys",
")",
":",
"items",
"=",
"copy",
"(",
"self",
".",
"items",
")",
"keys",
"=",
"reversed",
"(",
"sorted",
"(",
"keys",
")",
")",
"for",
"key",
"in",
"keys",
":",
"del",
"items",
"[",
"key",
"]",
"r... | Get all items except for those with the specified keys.
:param keys: The keys to remove
:type keys: tuple
:rtype: Collection | [
"Get",
"all",
"items",
"except",
"for",
"those",
"with",
"the",
"specified",
"keys",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L205-L221 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.only | def only(self, *keys):
"""
Get the items with the specified keys.
:param keys: The keys to keep
:type keys: tuple
:rtype: Collection
"""
items = []
for key, value in enumerate(self.items):
if key in keys:
items.append(value)
... | python | def only(self, *keys):
"""
Get the items with the specified keys.
:param keys: The keys to keep
:type keys: tuple
:rtype: Collection
"""
items = []
for key, value in enumerate(self.items):
if key in keys:
items.append(value)
... | [
"def",
"only",
"(",
"self",
",",
"*",
"keys",
")",
":",
"items",
"=",
"[",
"]",
"for",
"key",
",",
"value",
"in",
"enumerate",
"(",
"self",
".",
"items",
")",
":",
"if",
"key",
"in",
"keys",
":",
"items",
".",
"append",
"(",
"value",
")",
"retu... | Get the items with the specified keys.
:param keys: The keys to keep
:type keys: tuple
:rtype: Collection | [
"Get",
"the",
"items",
"with",
"the",
"specified",
"keys",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L223-L238 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.filter | def filter(self, callback=None):
"""
Run a filter over each of the items.
:param callback: The filter callback
:type callback: callable or None
:rtype: Collection
"""
if callback:
return self.__class__(list(filter(callback, self.items)))
ret... | python | def filter(self, callback=None):
"""
Run a filter over each of the items.
:param callback: The filter callback
:type callback: callable or None
:rtype: Collection
"""
if callback:
return self.__class__(list(filter(callback, self.items)))
ret... | [
"def",
"filter",
"(",
"self",
",",
"callback",
"=",
"None",
")",
":",
"if",
"callback",
":",
"return",
"self",
".",
"__class__",
"(",
"list",
"(",
"filter",
"(",
"callback",
",",
"self",
".",
"items",
")",
")",
")",
"return",
"self",
".",
"__class__"... | Run a filter over each of the items.
:param callback: The filter callback
:type callback: callable or None
:rtype: Collection | [
"Run",
"a",
"filter",
"over",
"each",
"of",
"the",
"items",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L240-L252 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.where | def where(self, key, value):
"""
Filter items by the given key value pair.
:param key: The key to filter by
:type key: str
:param value: The value to filter by
:type value: mixed
:rtype: Collection
"""
return self.filter(lambda item: data_get(it... | python | def where(self, key, value):
"""
Filter items by the given key value pair.
:param key: The key to filter by
:type key: str
:param value: The value to filter by
:type value: mixed
:rtype: Collection
"""
return self.filter(lambda item: data_get(it... | [
"def",
"where",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"return",
"self",
".",
"filter",
"(",
"lambda",
"item",
":",
"data_get",
"(",
"item",
",",
"key",
")",
"==",
"value",
")"
] | Filter items by the given key value pair.
:param key: The key to filter by
:type key: str
:param value: The value to filter by
:type value: mixed
:rtype: Collection | [
"Filter",
"items",
"by",
"the",
"given",
"key",
"value",
"pair",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L254-L266 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.first | def first(self, callback=None, default=None):
"""
Get the first item of the collection.
:param default: The default value
:type default: mixed
"""
if callback is not None:
for val in self.items:
if callback(val):
return val... | python | def first(self, callback=None, default=None):
"""
Get the first item of the collection.
:param default: The default value
:type default: mixed
"""
if callback is not None:
for val in self.items:
if callback(val):
return val... | [
"def",
"first",
"(",
"self",
",",
"callback",
"=",
"None",
",",
"default",
"=",
"None",
")",
":",
"if",
"callback",
"is",
"not",
"None",
":",
"for",
"val",
"in",
"self",
".",
"items",
":",
"if",
"callback",
"(",
"val",
")",
":",
"return",
"val",
... | Get the first item of the collection.
:param default: The default value
:type default: mixed | [
"Get",
"the",
"first",
"item",
"of",
"the",
"collection",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L268-L285 |
sdispater/backpack | backpack/collections/base_collection.py | BaseCollection.flatten | def flatten(self):
"""
Get a flattened list of the items in the collection.
:rtype: Collection
"""
def _flatten(d):
if isinstance(d, dict):
for v in d.values():
for nested_v in _flatten(v):
yield nested_v
... | python | def flatten(self):
"""
Get a flattened list of the items in the collection.
:rtype: Collection
"""
def _flatten(d):
if isinstance(d, dict):
for v in d.values():
for nested_v in _flatten(v):
yield nested_v
... | [
"def",
"flatten",
"(",
"self",
")",
":",
"def",
"_flatten",
"(",
"d",
")",
":",
"if",
"isinstance",
"(",
"d",
",",
"dict",
")",
":",
"for",
"v",
"in",
"d",
".",
"values",
"(",
")",
":",
"for",
"nested_v",
"in",
"_flatten",
"(",
"v",
")",
":",
... | Get a flattened list of the items in the collection.
:rtype: Collection | [
"Get",
"a",
"flattened",
"list",
"of",
"the",
"items",
"in",
"the",
"collection",
"."
] | train | https://github.com/sdispater/backpack/blob/764e7f79fd2b1c1ac4883d8e5c9da5c65dfc875e/backpack/collections/base_collection.py#L287-L306 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.