id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
1,100 | bartTC/django-attachments | attachments/templatetags/attachments_tags.py | attachment_delete_link | def attachment_delete_link(context, attachment):
"""
Renders a html link to the delete view of the given attachment. Returns
no content if the request-user has no permission to delete attachments.
The user must own either the ``attachments.delete_attachment`` permission
and is the creator of the at... | python | def attachment_delete_link(context, attachment):
if context['user'].has_perm('attachments.delete_foreign_attachments') or (
context['user'] == attachment.creator
and context['user'].has_perm('attachments.delete_attachment')
):
return {
'next': context.request.build_absolute_u... | [
"def",
"attachment_delete_link",
"(",
"context",
",",
"attachment",
")",
":",
"if",
"context",
"[",
"'user'",
"]",
".",
"has_perm",
"(",
"'attachments.delete_foreign_attachments'",
")",
"or",
"(",
"context",
"[",
"'user'",
"]",
"==",
"attachment",
".",
"creator"... | Renders a html link to the delete view of the given attachment. Returns
no content if the request-user has no permission to delete attachments.
The user must own either the ``attachments.delete_attachment`` permission
and is the creator of the attachment, that he can delete it or he has
``attachments.d... | [
"Renders",
"a",
"html",
"link",
"to",
"the",
"delete",
"view",
"of",
"the",
"given",
"attachment",
".",
"Returns",
"no",
"content",
"if",
"the",
"request",
"-",
"user",
"has",
"no",
"permission",
"to",
"delete",
"attachments",
"."
] | 012b7168f9342e07683a54ceab57696e0072962e | https://github.com/bartTC/django-attachments/blob/012b7168f9342e07683a54ceab57696e0072962e/attachments/templatetags/attachments_tags.py#L30-L50 |
1,101 | csurfer/pyheat | pyheat/pyheat.py | PyHeat.show_heatmap | def show_heatmap(self, blocking=True, output_file=None, enable_scroll=False):
"""Method to actually display the heatmap created.
@param blocking: When set to False makes an unblocking plot show.
@param output_file: If not None the heatmap image is output to this
file. Suppor... | python | def show_heatmap(self, blocking=True, output_file=None, enable_scroll=False):
if output_file is None:
if enable_scroll:
# Add a new axes which will be used as scroll bar.
axpos = plt.axes([0.12, 0.1, 0.625, 0.03])
spos = Slider(axpos, "Scroll", 10, len... | [
"def",
"show_heatmap",
"(",
"self",
",",
"blocking",
"=",
"True",
",",
"output_file",
"=",
"None",
",",
"enable_scroll",
"=",
"False",
")",
":",
"if",
"output_file",
"is",
"None",
":",
"if",
"enable_scroll",
":",
"# Add a new axes which will be used as scroll bar.... | Method to actually display the heatmap created.
@param blocking: When set to False makes an unblocking plot show.
@param output_file: If not None the heatmap image is output to this
file. Supported formats: (eps, pdf, pgf, png, ps, raw, rgba, svg,
svgz)
@para... | [
"Method",
"to",
"actually",
"display",
"the",
"heatmap",
"created",
"."
] | cc0ee3721aea70a1da4918957500131aa7077afe | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/pyheat.py#L53-L77 |
1,102 | csurfer/pyheat | pyheat/pyheat.py | PyHeat.__profile_file | def __profile_file(self):
"""Method used to profile the given file line by line."""
self.line_profiler = pprofile.Profile()
self.line_profiler.runfile(
open(self.pyfile.path, "r"), {}, self.pyfile.path
) | python | def __profile_file(self):
self.line_profiler = pprofile.Profile()
self.line_profiler.runfile(
open(self.pyfile.path, "r"), {}, self.pyfile.path
) | [
"def",
"__profile_file",
"(",
"self",
")",
":",
"self",
".",
"line_profiler",
"=",
"pprofile",
".",
"Profile",
"(",
")",
"self",
".",
"line_profiler",
".",
"runfile",
"(",
"open",
"(",
"self",
".",
"pyfile",
".",
"path",
",",
"\"r\"",
")",
",",
"{",
... | Method used to profile the given file line by line. | [
"Method",
"used",
"to",
"profile",
"the",
"given",
"file",
"line",
"by",
"line",
"."
] | cc0ee3721aea70a1da4918957500131aa7077afe | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/pyheat.py#L83-L88 |
1,103 | csurfer/pyheat | pyheat/pyheat.py | PyHeat.__get_line_profile_data | def __get_line_profile_data(self):
"""Method to procure line profiles.
@return: Line profiles if the file has been profiles else empty
dictionary.
"""
if self.line_profiler is None:
return {}
# the [0] is because pprofile.Profile.file_dict stores the l... | python | def __get_line_profile_data(self):
if self.line_profiler is None:
return {}
# the [0] is because pprofile.Profile.file_dict stores the line_dict
# in a list so that it can be modified in a thread-safe way
# see https://github.com/vpelletier/pprofile/blob/da3d60a1b59a061a0e21... | [
"def",
"__get_line_profile_data",
"(",
"self",
")",
":",
"if",
"self",
".",
"line_profiler",
"is",
"None",
":",
"return",
"{",
"}",
"# the [0] is because pprofile.Profile.file_dict stores the line_dict",
"# in a list so that it can be modified in a thread-safe way",
"# see https:... | Method to procure line profiles.
@return: Line profiles if the file has been profiles else empty
dictionary. | [
"Method",
"to",
"procure",
"line",
"profiles",
"."
] | cc0ee3721aea70a1da4918957500131aa7077afe | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/pyheat.py#L90-L102 |
1,104 | csurfer/pyheat | pyheat/pyheat.py | PyHeat.__fetch_heatmap_data_from_profile | def __fetch_heatmap_data_from_profile(self):
"""Method to create heatmap data from profile information."""
# Read lines from file.
with open(self.pyfile.path, "r") as file_to_read:
for line in file_to_read:
# Remove return char from the end of the line and add a
... | python | def __fetch_heatmap_data_from_profile(self):
# Read lines from file.
with open(self.pyfile.path, "r") as file_to_read:
for line in file_to_read:
# Remove return char from the end of the line and add a
# space in the beginning for better visibility.
... | [
"def",
"__fetch_heatmap_data_from_profile",
"(",
"self",
")",
":",
"# Read lines from file.",
"with",
"open",
"(",
"self",
".",
"pyfile",
".",
"path",
",",
"\"r\"",
")",
"as",
"file_to_read",
":",
"for",
"line",
"in",
"file_to_read",
":",
"# Remove return char fro... | Method to create heatmap data from profile information. | [
"Method",
"to",
"create",
"heatmap",
"data",
"from",
"profile",
"information",
"."
] | cc0ee3721aea70a1da4918957500131aa7077afe | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/pyheat.py#L104-L135 |
1,105 | csurfer/pyheat | pyheat/pyheat.py | PyHeat.__create_heatmap_plot | def __create_heatmap_plot(self):
"""Method to actually create the heatmap from profile stats."""
# Define the heatmap plot.
height = len(self.pyfile.lines) / 3
width = max(map(lambda x: len(x), self.pyfile.lines)) / 8
self.fig, self.ax = plt.subplots(figsize=(width, height))
... | python | def __create_heatmap_plot(self):
# Define the heatmap plot.
height = len(self.pyfile.lines) / 3
width = max(map(lambda x: len(x), self.pyfile.lines)) / 8
self.fig, self.ax = plt.subplots(figsize=(width, height))
# Set second sub plot to occupy bottom 20%
plt.subplots_adj... | [
"def",
"__create_heatmap_plot",
"(",
"self",
")",
":",
"# Define the heatmap plot.",
"height",
"=",
"len",
"(",
"self",
".",
"pyfile",
".",
"lines",
")",
"/",
"3",
"width",
"=",
"max",
"(",
"map",
"(",
"lambda",
"x",
":",
"len",
"(",
"x",
")",
",",
"... | Method to actually create the heatmap from profile stats. | [
"Method",
"to",
"actually",
"create",
"the",
"heatmap",
"from",
"profile",
"stats",
"."
] | cc0ee3721aea70a1da4918957500131aa7077afe | https://github.com/csurfer/pyheat/blob/cc0ee3721aea70a1da4918957500131aa7077afe/pyheat/pyheat.py#L137-L189 |
1,106 | limist/py-moneyed | moneyed/classes.py | Money.round | def round(self, ndigits=0):
"""
Rounds the amount using the current ``Decimal`` rounding algorithm.
"""
if ndigits is None:
ndigits = 0
return self.__class__(
amount=self.amount.quantize(Decimal('1e' + str(-ndigits))),
currency=self.currency) | python | def round(self, ndigits=0):
if ndigits is None:
ndigits = 0
return self.__class__(
amount=self.amount.quantize(Decimal('1e' + str(-ndigits))),
currency=self.currency) | [
"def",
"round",
"(",
"self",
",",
"ndigits",
"=",
"0",
")",
":",
"if",
"ndigits",
"is",
"None",
":",
"ndigits",
"=",
"0",
"return",
"self",
".",
"__class__",
"(",
"amount",
"=",
"self",
".",
"amount",
".",
"quantize",
"(",
"Decimal",
"(",
"'1e'",
"... | Rounds the amount using the current ``Decimal`` rounding algorithm. | [
"Rounds",
"the",
"amount",
"using",
"the",
"current",
"Decimal",
"rounding",
"algorithm",
"."
] | 1822e9f77edc6608b429e54c8831b873af9a4de6 | https://github.com/limist/py-moneyed/blob/1822e9f77edc6608b429e54c8831b873af9a4de6/moneyed/classes.py#L158-L166 |
1,107 | klen/muffin | muffin/manage.py | run | def run():
"""CLI endpoint."""
sys.path.insert(0, os.getcwd())
logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler()])
parser = argparse.ArgumentParser(description="Manage Application", add_help=False)
parser.add_argument('app', metavar='app',
type=str, h... | python | def run():
sys.path.insert(0, os.getcwd())
logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler()])
parser = argparse.ArgumentParser(description="Manage Application", add_help=False)
parser.add_argument('app', metavar='app',
type=str, help='Application module ... | [
"def",
"run",
"(",
")",
":",
"sys",
".",
"path",
".",
"insert",
"(",
"0",
",",
"os",
".",
"getcwd",
"(",
")",
")",
"logging",
".",
"basicConfig",
"(",
"level",
"=",
"logging",
".",
"INFO",
",",
"handlers",
"=",
"[",
"logging",
".",
"StreamHandler",... | CLI endpoint. | [
"CLI",
"endpoint",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/manage.py#L250-L278 |
1,108 | klen/muffin | muffin/manage.py | Manager.command | def command(self, init=False):
"""Define CLI command."""
def wrapper(func):
header = '\n'.join([s for s in (func.__doc__ or '').split('\n')
if not s.strip().startswith(':')])
parser = self.parsers.add_parser(func.__name__, description=header)
... | python | def command(self, init=False):
def wrapper(func):
header = '\n'.join([s for s in (func.__doc__ or '').split('\n')
if not s.strip().startswith(':')])
parser = self.parsers.add_parser(func.__name__, description=header)
args, vargs, kw, defs, kwar... | [
"def",
"command",
"(",
"self",
",",
"init",
"=",
"False",
")",
":",
"def",
"wrapper",
"(",
"func",
")",
":",
"header",
"=",
"'\\n'",
".",
"join",
"(",
"[",
"s",
"for",
"s",
"in",
"(",
"func",
".",
"__doc__",
"or",
"''",
")",
".",
"split",
"(",
... | Define CLI command. | [
"Define",
"CLI",
"command",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/manage.py#L145-L202 |
1,109 | klen/muffin | muffin/urls.py | routes_register | def routes_register(app, handler, *paths, methods=None, router=None, name=None):
"""Register routes."""
if router is None:
router = app.router
handler = to_coroutine(handler)
resources = []
for path in paths:
# Register any exception to app
if isinstance(path, type) and i... | python | def routes_register(app, handler, *paths, methods=None, router=None, name=None):
if router is None:
router = app.router
handler = to_coroutine(handler)
resources = []
for path in paths:
# Register any exception to app
if isinstance(path, type) and issubclass(path, BaseExcepti... | [
"def",
"routes_register",
"(",
"app",
",",
"handler",
",",
"*",
"paths",
",",
"methods",
"=",
"None",
",",
"router",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"if",
"router",
"is",
"None",
":",
"router",
"=",
"app",
".",
"router",
"handler",
... | Register routes. | [
"Register",
"routes",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L95-L132 |
1,110 | klen/muffin | muffin/urls.py | parse | def parse(path):
"""Parse URL path and convert it to regexp if needed."""
parsed = re.sre_parse.parse(path)
for case, _ in parsed:
if case not in (re.sre_parse.LITERAL, re.sre_parse.ANY):
break
else:
return path
path = path.strip('^$')
def parse_(match):
[pa... | python | def parse(path):
parsed = re.sre_parse.parse(path)
for case, _ in parsed:
if case not in (re.sre_parse.LITERAL, re.sre_parse.ANY):
break
else:
return path
path = path.strip('^$')
def parse_(match):
[part] = match.groups()
match = DYNR_RE.match(part)
... | [
"def",
"parse",
"(",
"path",
")",
":",
"parsed",
"=",
"re",
".",
"sre_parse",
".",
"parse",
"(",
"path",
")",
"for",
"case",
",",
"_",
"in",
"parsed",
":",
"if",
"case",
"not",
"in",
"(",
"re",
".",
"sre_parse",
".",
"LITERAL",
",",
"re",
".",
... | Parse URL path and convert it to regexp if needed. | [
"Parse",
"URL",
"path",
"and",
"convert",
"it",
"to",
"regexp",
"if",
"needed",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L135-L152 |
1,111 | klen/muffin | muffin/urls.py | RawReResource.url_for | def url_for(self, *subgroups, **groups):
"""Build URL."""
parsed = re.sre_parse.parse(self._pattern.pattern)
subgroups = {n:str(v) for n, v in enumerate(subgroups, 1)}
groups_ = dict(parsed.pattern.groupdict)
subgroups.update({
groups_[k0]: str(v0)
for k0,... | python | def url_for(self, *subgroups, **groups):
parsed = re.sre_parse.parse(self._pattern.pattern)
subgroups = {n:str(v) for n, v in enumerate(subgroups, 1)}
groups_ = dict(parsed.pattern.groupdict)
subgroups.update({
groups_[k0]: str(v0)
for k0, v0 in groups.items()
... | [
"def",
"url_for",
"(",
"self",
",",
"*",
"subgroups",
",",
"*",
"*",
"groups",
")",
":",
"parsed",
"=",
"re",
".",
"sre_parse",
".",
"parse",
"(",
"self",
".",
"_pattern",
".",
"pattern",
")",
"subgroups",
"=",
"{",
"n",
":",
"str",
"(",
"v",
")"... | Build URL. | [
"Build",
"URL",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L38-L49 |
1,112 | klen/muffin | muffin/urls.py | Traverser.state_not_literal | def state_not_literal(self, value):
"""Parse not literal."""
value = negate = chr(value)
while value == negate:
value = choice(self.literals)
yield value | python | def state_not_literal(self, value):
value = negate = chr(value)
while value == negate:
value = choice(self.literals)
yield value | [
"def",
"state_not_literal",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"negate",
"=",
"chr",
"(",
"value",
")",
"while",
"value",
"==",
"negate",
":",
"value",
"=",
"choice",
"(",
"self",
".",
"literals",
")",
"yield",
"value"
] | Parse not literal. | [
"Parse",
"not",
"literal",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L185-L190 |
1,113 | klen/muffin | muffin/urls.py | Traverser.state_max_repeat | def state_max_repeat(self, value):
"""Parse repeatable parts."""
min_, max_, value = value
value = [val for val in Traverser(value, self.groups)]
if not min_ and max_:
for val in value:
if isinstance(val, required):
min_ = 1
... | python | def state_max_repeat(self, value):
min_, max_, value = value
value = [val for val in Traverser(value, self.groups)]
if not min_ and max_:
for val in value:
if isinstance(val, required):
min_ = 1
break
for val in value *... | [
"def",
"state_max_repeat",
"(",
"self",
",",
"value",
")",
":",
"min_",
",",
"max_",
",",
"value",
"=",
"value",
"value",
"=",
"[",
"val",
"for",
"val",
"in",
"Traverser",
"(",
"value",
",",
"self",
".",
"groups",
")",
"]",
"if",
"not",
"min_",
"an... | Parse repeatable parts. | [
"Parse",
"repeatable",
"parts",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L192-L203 |
1,114 | klen/muffin | muffin/urls.py | Traverser.state_in | def state_in(self, value):
"""Parse ranges."""
value = [val for val in Traverser(value, self.groups)]
if not value or not value[0]:
for val in self.literals - set(value):
return (yield val)
yield value[0] | python | def state_in(self, value):
value = [val for val in Traverser(value, self.groups)]
if not value or not value[0]:
for val in self.literals - set(value):
return (yield val)
yield value[0] | [
"def",
"state_in",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"[",
"val",
"for",
"val",
"in",
"Traverser",
"(",
"value",
",",
"self",
".",
"groups",
")",
"]",
"if",
"not",
"value",
"or",
"not",
"value",
"[",
"0",
"]",
":",
"for",
"val",
... | Parse ranges. | [
"Parse",
"ranges",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L207-L213 |
1,115 | klen/muffin | muffin/urls.py | Traverser.state_category | def state_category(value):
"""Parse categories."""
if value == re.sre_parse.CATEGORY_DIGIT:
return (yield '0')
if value == re.sre_parse.CATEGORY_WORD:
return (yield 'x') | python | def state_category(value):
if value == re.sre_parse.CATEGORY_DIGIT:
return (yield '0')
if value == re.sre_parse.CATEGORY_WORD:
return (yield 'x') | [
"def",
"state_category",
"(",
"value",
")",
":",
"if",
"value",
"==",
"re",
".",
"sre_parse",
".",
"CATEGORY_DIGIT",
":",
"return",
"(",
"yield",
"'0'",
")",
"if",
"value",
"==",
"re",
".",
"sre_parse",
".",
"CATEGORY_WORD",
":",
"return",
"(",
"yield",
... | Parse categories. | [
"Parse",
"categories",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/urls.py#L218-L224 |
1,116 | klen/muffin | muffin/utils.py | create_signature | def create_signature(secret, value, digestmod='sha256', encoding='utf-8'):
""" Create HMAC Signature from secret for value. """
if isinstance(secret, str):
secret = secret.encode(encoding)
if isinstance(value, str):
value = value.encode(encoding)
if isinstance(digestmod, str):
... | python | def create_signature(secret, value, digestmod='sha256', encoding='utf-8'):
if isinstance(secret, str):
secret = secret.encode(encoding)
if isinstance(value, str):
value = value.encode(encoding)
if isinstance(digestmod, str):
digestmod = getattr(hashlib, digestmod, hashlib.sha1)
... | [
"def",
"create_signature",
"(",
"secret",
",",
"value",
",",
"digestmod",
"=",
"'sha256'",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"if",
"isinstance",
"(",
"secret",
",",
"str",
")",
":",
"secret",
"=",
"secret",
".",
"encode",
"(",
"encoding",
")",
... | Create HMAC Signature from secret for value. | [
"Create",
"HMAC",
"Signature",
"from",
"secret",
"for",
"value",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/utils.py#L32-L45 |
1,117 | klen/muffin | muffin/utils.py | check_signature | def check_signature(signature, *args, **kwargs):
""" Check for the signature is correct. """
return hmac.compare_digest(signature, create_signature(*args, **kwargs)) | python | def check_signature(signature, *args, **kwargs):
return hmac.compare_digest(signature, create_signature(*args, **kwargs)) | [
"def",
"check_signature",
"(",
"signature",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"hmac",
".",
"compare_digest",
"(",
"signature",
",",
"create_signature",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
")"
] | Check for the signature is correct. | [
"Check",
"for",
"the",
"signature",
"is",
"correct",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/utils.py#L48-L50 |
1,118 | klen/muffin | muffin/utils.py | generate_password_hash | def generate_password_hash(password, digestmod='sha256', salt_length=8):
""" Hash a password with given method and salt length. """
salt = ''.join(random.sample(SALT_CHARS, salt_length))
signature = create_signature(salt, password, digestmod=digestmod)
return '$'.join((digestmod, salt, signature)) | python | def generate_password_hash(password, digestmod='sha256', salt_length=8):
salt = ''.join(random.sample(SALT_CHARS, salt_length))
signature = create_signature(salt, password, digestmod=digestmod)
return '$'.join((digestmod, salt, signature)) | [
"def",
"generate_password_hash",
"(",
"password",
",",
"digestmod",
"=",
"'sha256'",
",",
"salt_length",
"=",
"8",
")",
":",
"salt",
"=",
"''",
".",
"join",
"(",
"random",
".",
"sample",
"(",
"SALT_CHARS",
",",
"salt_length",
")",
")",
"signature",
"=",
... | Hash a password with given method and salt length. | [
"Hash",
"a",
"password",
"with",
"given",
"method",
"and",
"salt",
"length",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/utils.py#L53-L58 |
1,119 | klen/muffin | muffin/utils.py | import_submodules | def import_submodules(package_name, *submodules):
"""Import all submodules by package name."""
package = sys.modules[package_name]
return {
name: importlib.import_module(package_name + '.' + name)
for _, name, _ in pkgutil.walk_packages(package.__path__)
if not submodules or name in ... | python | def import_submodules(package_name, *submodules):
package = sys.modules[package_name]
return {
name: importlib.import_module(package_name + '.' + name)
for _, name, _ in pkgutil.walk_packages(package.__path__)
if not submodules or name in submodules
} | [
"def",
"import_submodules",
"(",
"package_name",
",",
"*",
"submodules",
")",
":",
"package",
"=",
"sys",
".",
"modules",
"[",
"package_name",
"]",
"return",
"{",
"name",
":",
"importlib",
".",
"import_module",
"(",
"package_name",
"+",
"'.'",
"+",
"name",
... | Import all submodules by package name. | [
"Import",
"all",
"submodules",
"by",
"package",
"name",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/utils.py#L183-L190 |
1,120 | klen/muffin | muffin/handler.py | register | def register(*paths, methods=None, name=None, handler=None):
"""Mark Handler.method to aiohttp handler.
It uses when registration of the handler with application is postponed.
::
class AwesomeHandler(Handler):
def get(self, request):
return "I'm awesome!"
... | python | def register(*paths, methods=None, name=None, handler=None):
def wrapper(method):
"""Store route params into method."""
method = to_coroutine(method)
setattr(method, ROUTE_PARAMS_ATTR, (paths, methods, name))
if handler and not hasattr(handler, method.__name__):
setattr(h... | [
"def",
"register",
"(",
"*",
"paths",
",",
"methods",
"=",
"None",
",",
"name",
"=",
"None",
",",
"handler",
"=",
"None",
")",
":",
"def",
"wrapper",
"(",
"method",
")",
":",
"\"\"\"Store route params into method.\"\"\"",
"method",
"=",
"to_coroutine",
"(",
... | Mark Handler.method to aiohttp handler.
It uses when registration of the handler with application is postponed.
::
class AwesomeHandler(Handler):
def get(self, request):
return "I'm awesome!"
@register('/awesome/best')
def best(self, request):
... | [
"Mark",
"Handler",
".",
"method",
"to",
"aiohttp",
"handler",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L17-L40 |
1,121 | klen/muffin | muffin/handler.py | Handler.from_view | def from_view(cls, view, *methods, name=None):
"""Create a handler class from function or coroutine."""
docs = getattr(view, '__doc__', None)
view = to_coroutine(view)
methods = methods or ['GET']
if METH_ANY in methods:
methods = METH_ALL
def proxy(self, *a... | python | def from_view(cls, view, *methods, name=None):
docs = getattr(view, '__doc__', None)
view = to_coroutine(view)
methods = methods or ['GET']
if METH_ANY in methods:
methods = METH_ALL
def proxy(self, *args, **kwargs):
return view(*args, **kwargs)
... | [
"def",
"from_view",
"(",
"cls",
",",
"view",
",",
"*",
"methods",
",",
"name",
"=",
"None",
")",
":",
"docs",
"=",
"getattr",
"(",
"view",
",",
"'__doc__'",
",",
"None",
")",
"view",
"=",
"to_coroutine",
"(",
"view",
")",
"methods",
"=",
"methods",
... | Create a handler class from function or coroutine. | [
"Create",
"a",
"handler",
"class",
"from",
"function",
"or",
"coroutine",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L95-L112 |
1,122 | klen/muffin | muffin/handler.py | Handler.bind | def bind(cls, app, *paths, methods=None, name=None, router=None, view=None):
"""Bind to the given application."""
cls.app = app
if cls.app is not None:
for _, m in inspect.getmembers(cls, predicate=inspect.isfunction):
if not hasattr(m, ROUTE_PARAMS_ATTR):
... | python | def bind(cls, app, *paths, methods=None, name=None, router=None, view=None):
cls.app = app
if cls.app is not None:
for _, m in inspect.getmembers(cls, predicate=inspect.isfunction):
if not hasattr(m, ROUTE_PARAMS_ATTR):
continue
paths_, met... | [
"def",
"bind",
"(",
"cls",
",",
"app",
",",
"*",
"paths",
",",
"methods",
"=",
"None",
",",
"name",
"=",
"None",
",",
"router",
"=",
"None",
",",
"view",
"=",
"None",
")",
":",
"cls",
".",
"app",
"=",
"app",
"if",
"cls",
".",
"app",
"is",
"no... | Bind to the given application. | [
"Bind",
"to",
"the",
"given",
"application",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L115-L136 |
1,123 | klen/muffin | muffin/handler.py | Handler.register | def register(cls, *args, **kwargs):
"""Register view to handler."""
if cls.app is None:
return register(*args, handler=cls, **kwargs)
return cls.app.register(*args, handler=cls, **kwargs) | python | def register(cls, *args, **kwargs):
if cls.app is None:
return register(*args, handler=cls, **kwargs)
return cls.app.register(*args, handler=cls, **kwargs) | [
"def",
"register",
"(",
"cls",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"cls",
".",
"app",
"is",
"None",
":",
"return",
"register",
"(",
"*",
"args",
",",
"handler",
"=",
"cls",
",",
"*",
"*",
"kwargs",
")",
"return",
"cls",
"... | Register view to handler. | [
"Register",
"view",
"to",
"handler",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L139-L143 |
1,124 | klen/muffin | muffin/handler.py | Handler.dispatch | async def dispatch(self, request, view=None, **kwargs):
"""Dispatch request."""
if view is None and request.method not in self.methods:
raise HTTPMethodNotAllowed(request.method, self.methods)
method = getattr(self, view or request.method.lower())
response = await method(req... | python | async def dispatch(self, request, view=None, **kwargs):
if view is None and request.method not in self.methods:
raise HTTPMethodNotAllowed(request.method, self.methods)
method = getattr(self, view or request.method.lower())
response = await method(request, **kwargs)
return a... | [
"async",
"def",
"dispatch",
"(",
"self",
",",
"request",
",",
"view",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"view",
"is",
"None",
"and",
"request",
".",
"method",
"not",
"in",
"self",
".",
"methods",
":",
"raise",
"HTTPMethodNotAllowed"... | Dispatch request. | [
"Dispatch",
"request",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L145-L152 |
1,125 | klen/muffin | muffin/handler.py | Handler.parse | async def parse(self, request):
"""Return a coroutine which parses data from request depends on content-type.
Usage: ::
def post(self, request):
data = await self.parse(request)
# ...
"""
if request.content_type in {'application/x-www-form-ur... | python | async def parse(self, request):
if request.content_type in {'application/x-www-form-urlencoded', 'multipart/form-data'}:
return await request.post()
if request.content_type == 'application/json':
return await request.json()
return await request.text() | [
"async",
"def",
"parse",
"(",
"self",
",",
"request",
")",
":",
"if",
"request",
".",
"content_type",
"in",
"{",
"'application/x-www-form-urlencoded'",
",",
"'multipart/form-data'",
"}",
":",
"return",
"await",
"request",
".",
"post",
"(",
")",
"if",
"request"... | Return a coroutine which parses data from request depends on content-type.
Usage: ::
def post(self, request):
data = await self.parse(request)
# ... | [
"Return",
"a",
"coroutine",
"which",
"parses",
"data",
"from",
"request",
"depends",
"on",
"content",
"-",
"type",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L172-L187 |
1,126 | klen/muffin | muffin/app.py | Application.cfg | def cfg(self):
"""Load the application configuration.
This method loads configuration from python module.
"""
config = LStruct(self.defaults)
module = config['CONFIG'] = os.environ.get(
CONFIGURATION_ENVIRON_VARIABLE, config['CONFIG'])
if module:
... | python | def cfg(self):
config = LStruct(self.defaults)
module = config['CONFIG'] = os.environ.get(
CONFIGURATION_ENVIRON_VARIABLE, config['CONFIG'])
if module:
try:
module = import_module(module)
config.update({
name: getattr(m... | [
"def",
"cfg",
"(",
"self",
")",
":",
"config",
"=",
"LStruct",
"(",
"self",
".",
"defaults",
")",
"module",
"=",
"config",
"[",
"'CONFIG'",
"]",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"CONFIGURATION_ENVIRON_VARIABLE",
",",
"config",
"[",
"'CONFIG'",... | Load the application configuration.
This method loads configuration from python module. | [
"Load",
"the",
"application",
"configuration",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/app.py#L162-L192 |
1,127 | klen/muffin | muffin/app.py | Application.install | def install(self, plugin, name=None, **opts):
"""Install plugin to the application."""
source = plugin
if isinstance(plugin, str):
module, _, attr = plugin.partition(':')
module = import_module(module)
plugin = getattr(module, attr or 'Plugin', None)
... | python | def install(self, plugin, name=None, **opts):
source = plugin
if isinstance(plugin, str):
module, _, attr = plugin.partition(':')
module = import_module(module)
plugin = getattr(module, attr or 'Plugin', None)
if isinstance(plugin, types.ModuleType):
... | [
"def",
"install",
"(",
"self",
",",
"plugin",
",",
"name",
"=",
"None",
",",
"*",
"*",
"opts",
")",
":",
"source",
"=",
"plugin",
"if",
"isinstance",
"(",
"plugin",
",",
"str",
")",
":",
"module",
",",
"_",
",",
"attr",
"=",
"plugin",
".",
"parti... | Install plugin to the application. | [
"Install",
"plugin",
"to",
"the",
"application",
"."
] | 7bc891e174e08b62d1ae232b5d45f8cd8bc82112 | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/app.py#L194-L231 |
1,128 | jamesturk/django-honeypot | honeypot/decorators.py | check_honeypot | def check_honeypot(func=None, field_name=None):
"""
Check request.POST for valid honeypot field.
Takes an optional field_name that defaults to HONEYPOT_FIELD_NAME if
not specified.
"""
# hack to reverse arguments if called with str param
if isinstance(func, six.string_types):
... | python | def check_honeypot(func=None, field_name=None):
# hack to reverse arguments if called with str param
if isinstance(func, six.string_types):
func, field_name = field_name, func
def decorated(func):
def inner(request, *args, **kwargs):
response = verify_honeypot_value(request, fie... | [
"def",
"check_honeypot",
"(",
"func",
"=",
"None",
",",
"field_name",
"=",
"None",
")",
":",
"# hack to reverse arguments if called with str param",
"if",
"isinstance",
"(",
"func",
",",
"six",
".",
"string_types",
")",
":",
"func",
",",
"field_name",
"=",
"fiel... | Check request.POST for valid honeypot field.
Takes an optional field_name that defaults to HONEYPOT_FIELD_NAME if
not specified. | [
"Check",
"request",
".",
"POST",
"for",
"valid",
"honeypot",
"field",
"."
] | 4b149bfca81828eaf418b5a6854e670d156f5e35 | https://github.com/jamesturk/django-honeypot/blob/4b149bfca81828eaf418b5a6854e670d156f5e35/honeypot/decorators.py#L36-L60 |
1,129 | jamesturk/django-honeypot | honeypot/decorators.py | honeypot_exempt | def honeypot_exempt(view_func):
"""
Mark view as exempt from honeypot validation
"""
# borrowing liberally from django's csrf_exempt
def wrapped(*args, **kwargs):
return view_func(*args, **kwargs)
wrapped.honeypot_exempt = True
return wraps(view_func, assigned=available_attrs(vie... | python | def honeypot_exempt(view_func):
# borrowing liberally from django's csrf_exempt
def wrapped(*args, **kwargs):
return view_func(*args, **kwargs)
wrapped.honeypot_exempt = True
return wraps(view_func, assigned=available_attrs(view_func))(wrapped) | [
"def",
"honeypot_exempt",
"(",
"view_func",
")",
":",
"# borrowing liberally from django's csrf_exempt",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"view_func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"wrapped",
... | Mark view as exempt from honeypot validation | [
"Mark",
"view",
"as",
"exempt",
"from",
"honeypot",
"validation"
] | 4b149bfca81828eaf418b5a6854e670d156f5e35 | https://github.com/jamesturk/django-honeypot/blob/4b149bfca81828eaf418b5a6854e670d156f5e35/honeypot/decorators.py#L63-L71 |
1,130 | jongracecox/anybadge | anybadge.py | main | def main():
"""Generate a badge based on command line arguments."""
# Parse command line arguments
args = parse_args()
label = args.label
threshold_text = args.args
suffix = args.suffix
# Check whether thresholds were sent as one word, and is in the
# list of templates. If so, swap in... | python | def main():
# Parse command line arguments
args = parse_args()
label = args.label
threshold_text = args.args
suffix = args.suffix
# Check whether thresholds were sent as one word, and is in the
# list of templates. If so, swap in the template.
if len(args.args) == 1 and args.args[0] i... | [
"def",
"main",
"(",
")",
":",
"# Parse command line arguments",
"args",
"=",
"parse_args",
"(",
")",
"label",
"=",
"args",
".",
"label",
"threshold_text",
"=",
"args",
".",
"args",
"suffix",
"=",
"args",
".",
"suffix",
"# Check whether thresholds were sent as one ... | Generate a badge based on command line arguments. | [
"Generate",
"a",
"badge",
"based",
"on",
"command",
"line",
"arguments",
"."
] | 1850a9580697e019c601d09f5de490056fed2bab | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L440-L478 |
1,131 | jongracecox/anybadge | anybadge.py | Badge.value_is_int | def value_is_int(self):
"""Identify whether the value text is an int."""
try:
a = float(self.value)
b = int(a)
except ValueError:
return False
else:
return a == b | python | def value_is_int(self):
try:
a = float(self.value)
b = int(a)
except ValueError:
return False
else:
return a == b | [
"def",
"value_is_int",
"(",
"self",
")",
":",
"try",
":",
"a",
"=",
"float",
"(",
"self",
".",
"value",
")",
"b",
"=",
"int",
"(",
"a",
")",
"except",
"ValueError",
":",
"return",
"False",
"else",
":",
"return",
"a",
"==",
"b"
] | Identify whether the value text is an int. | [
"Identify",
"whether",
"the",
"value",
"text",
"is",
"an",
"int",
"."
] | 1850a9580697e019c601d09f5de490056fed2bab | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L183-L191 |
1,132 | jongracecox/anybadge | anybadge.py | Badge.font_width | def font_width(self):
"""Return the badge font width."""
return self.get_font_width(font_name=self.font_name, font_size=self.font_size) | python | def font_width(self):
return self.get_font_width(font_name=self.font_name, font_size=self.font_size) | [
"def",
"font_width",
"(",
"self",
")",
":",
"return",
"self",
".",
"get_font_width",
"(",
"font_name",
"=",
"self",
".",
"font_name",
",",
"font_size",
"=",
"self",
".",
"font_size",
")"
] | Return the badge font width. | [
"Return",
"the",
"badge",
"font",
"width",
"."
] | 1850a9580697e019c601d09f5de490056fed2bab | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L214-L216 |
1,133 | jongracecox/anybadge | anybadge.py | Badge.color_split_position | def color_split_position(self):
"""The SVG x position where the color split should occur."""
return self.get_text_width(' ') + self.label_width + \
int(float(self.font_width) * float(self.num_padding_chars)) | python | def color_split_position(self):
return self.get_text_width(' ') + self.label_width + \
int(float(self.font_width) * float(self.num_padding_chars)) | [
"def",
"color_split_position",
"(",
"self",
")",
":",
"return",
"self",
".",
"get_text_width",
"(",
"' '",
")",
"+",
"self",
".",
"label_width",
"+",
"int",
"(",
"float",
"(",
"self",
".",
"font_width",
")",
"*",
"float",
"(",
"self",
".",
"num_padding_c... | The SVG x position where the color split should occur. | [
"The",
"SVG",
"x",
"position",
"where",
"the",
"color",
"split",
"should",
"occur",
"."
] | 1850a9580697e019c601d09f5de490056fed2bab | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L219-L222 |
1,134 | jongracecox/anybadge | anybadge.py | Badge.badge_width | def badge_width(self):
"""The total width of badge.
>>> badge = Badge('pylint', '5', font_name='DejaVu Sans,Verdana,Geneva,sans-serif',
... font_size=11)
>>> badge.badge_width
91
"""
return self.get_text_width(' ' + ' ' * int(float(self.num_paddin... | python | def badge_width(self):
return self.get_text_width(' ' + ' ' * int(float(self.num_padding_chars) * 2.0)) \
+ self.label_width + self.value_width | [
"def",
"badge_width",
"(",
"self",
")",
":",
"return",
"self",
".",
"get_text_width",
"(",
"' '",
"+",
"' '",
"*",
"int",
"(",
"float",
"(",
"self",
".",
"num_padding_chars",
")",
"*",
"2.0",
")",
")",
"+",
"self",
".",
"label_width",
"+",
"self",
... | The total width of badge.
>>> badge = Badge('pylint', '5', font_name='DejaVu Sans,Verdana,Geneva,sans-serif',
... font_size=11)
>>> badge.badge_width
91 | [
"The",
"total",
"width",
"of",
"badge",
"."
] | 1850a9580697e019c601d09f5de490056fed2bab | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L245-L254 |
1,135 | jongracecox/anybadge | anybadge.py | Badge.badge_svg_text | def badge_svg_text(self):
"""The badge SVG text."""
# Identify whether template is a file or the actual template text
if len(self.template.split('\n')) == 1:
with open(self.template, mode='r') as file_handle:
badge_text = file_handle.read()
else:
... | python | def badge_svg_text(self):
# Identify whether template is a file or the actual template text
if len(self.template.split('\n')) == 1:
with open(self.template, mode='r') as file_handle:
badge_text = file_handle.read()
else:
badge_text = self.template
... | [
"def",
"badge_svg_text",
"(",
"self",
")",
":",
"# Identify whether template is a file or the actual template text",
"if",
"len",
"(",
"self",
".",
"template",
".",
"split",
"(",
"'\\n'",
")",
")",
"==",
"1",
":",
"with",
"open",
"(",
"self",
".",
"template",
... | The badge SVG text. | [
"The",
"badge",
"SVG",
"text",
"."
] | 1850a9580697e019c601d09f5de490056fed2bab | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L257-L280 |
1,136 | jongracecox/anybadge | anybadge.py | Badge.get_text_width | def get_text_width(self, text):
"""Return the width of text.
This implementation assumes a fixed font of:
font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"
>>> badge = Badge('x', 1, font_name='DejaVu Sans,Verdana,Geneva,sans-serif', font_size=11)
>>> badge.get_... | python | def get_text_width(self, text):
return len(text) * self.get_font_width(self.font_name, self.font_size) | [
"def",
"get_text_width",
"(",
"self",
",",
"text",
")",
":",
"return",
"len",
"(",
"text",
")",
"*",
"self",
".",
"get_font_width",
"(",
"self",
".",
"font_name",
",",
"self",
".",
"font_size",
")"
] | Return the width of text.
This implementation assumes a fixed font of:
font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"
>>> badge = Badge('x', 1, font_name='DejaVu Sans,Verdana,Geneva,sans-serif', font_size=11)
>>> badge.get_text_width('pylint')
42 | [
"Return",
"the",
"width",
"of",
"text",
"."
] | 1850a9580697e019c601d09f5de490056fed2bab | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L291-L301 |
1,137 | jongracecox/anybadge | anybadge.py | Badge.badge_color | def badge_color(self):
"""Find the badge color based on the thresholds."""
# If no thresholds were passed then return the default color
if not self.thresholds:
return self.default_color
if self.value_type == str:
if self.value in self.thresholds:
... | python | def badge_color(self):
# If no thresholds were passed then return the default color
if not self.thresholds:
return self.default_color
if self.value_type == str:
if self.value in self.thresholds:
return self.thresholds[self.value]
else:
... | [
"def",
"badge_color",
"(",
"self",
")",
":",
"# If no thresholds were passed then return the default color",
"if",
"not",
"self",
".",
"thresholds",
":",
"return",
"self",
".",
"default_color",
"if",
"self",
".",
"value_type",
"==",
"str",
":",
"if",
"self",
".",
... | Find the badge color based on the thresholds. | [
"Find",
"the",
"badge",
"color",
"based",
"on",
"the",
"thresholds",
"."
] | 1850a9580697e019c601d09f5de490056fed2bab | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L304-L330 |
1,138 | jongracecox/anybadge | anybadge.py | Badge.write_badge | def write_badge(self, file_path, overwrite=False):
"""Write badge to file."""
# Validate path (part 1)
if file_path.endswith('/'):
raise Exception('File location may not be a directory.')
# Get absolute filepath
path = os.path.abspath(file_path)
if not path.... | python | def write_badge(self, file_path, overwrite=False):
# Validate path (part 1)
if file_path.endswith('/'):
raise Exception('File location may not be a directory.')
# Get absolute filepath
path = os.path.abspath(file_path)
if not path.lower().endswith('.svg'):
... | [
"def",
"write_badge",
"(",
"self",
",",
"file_path",
",",
"overwrite",
"=",
"False",
")",
":",
"# Validate path (part 1)",
"if",
"file_path",
".",
"endswith",
"(",
"'/'",
")",
":",
"raise",
"Exception",
"(",
"'File location may not be a directory.'",
")",
"# Get a... | Write badge to file. | [
"Write",
"badge",
"to",
"file",
"."
] | 1850a9580697e019c601d09f5de490056fed2bab | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L340-L357 |
1,139 | jongracecox/anybadge | anybadge_server.py | main | def main():
"""Run server."""
global DEFAULT_SERVER_PORT, DEFAULT_SERVER_LISTEN_ADDRESS, DEFAULT_LOGGING_LEVEL
# Check for environment variables
if 'ANYBADGE_PORT' in environ:
DEFAULT_SERVER_PORT = environ['ANYBADGE_PORT']
if 'ANYBADGE_LISTEN_ADDRESS' in environ:
DEFAULT_SERVER_LI... | python | def main():
global DEFAULT_SERVER_PORT, DEFAULT_SERVER_LISTEN_ADDRESS, DEFAULT_LOGGING_LEVEL
# Check for environment variables
if 'ANYBADGE_PORT' in environ:
DEFAULT_SERVER_PORT = environ['ANYBADGE_PORT']
if 'ANYBADGE_LISTEN_ADDRESS' in environ:
DEFAULT_SERVER_LISTEN_ADDRESS = environ[... | [
"def",
"main",
"(",
")",
":",
"global",
"DEFAULT_SERVER_PORT",
",",
"DEFAULT_SERVER_LISTEN_ADDRESS",
",",
"DEFAULT_LOGGING_LEVEL",
"# Check for environment variables",
"if",
"'ANYBADGE_PORT'",
"in",
"environ",
":",
"DEFAULT_SERVER_PORT",
"=",
"environ",
"[",
"'ANYBADGE_PORT... | Run server. | [
"Run",
"server",
"."
] | 1850a9580697e019c601d09f5de490056fed2bab | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge_server.py#L129-L156 |
1,140 | mschwager/cohesion | lib/cohesion/parser.py | get_object_name | def get_object_name(obj):
"""
Return the name of a given object
"""
name_dispatch = {
ast.Name: "id",
ast.Attribute: "attr",
ast.Call: "func",
ast.FunctionDef: "name",
ast.ClassDef: "name",
ast.Subscript: "value",
}
# This is a new ast type in Pyt... | python | def get_object_name(obj):
name_dispatch = {
ast.Name: "id",
ast.Attribute: "attr",
ast.Call: "func",
ast.FunctionDef: "name",
ast.ClassDef: "name",
ast.Subscript: "value",
}
# This is a new ast type in Python 3
if hasattr(ast, "arg"):
name_dispatc... | [
"def",
"get_object_name",
"(",
"obj",
")",
":",
"name_dispatch",
"=",
"{",
"ast",
".",
"Name",
":",
"\"id\"",
",",
"ast",
".",
"Attribute",
":",
"\"attr\"",
",",
"ast",
".",
"Call",
":",
"\"func\"",
",",
"ast",
".",
"FunctionDef",
":",
"\"name\"",
",",... | Return the name of a given object | [
"Return",
"the",
"name",
"of",
"a",
"given",
"object"
] | b242ad59770940f3a0904931f27755ede009f491 | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L8-L29 |
1,141 | mschwager/cohesion | lib/cohesion/parser.py | get_attribute_name_id | def get_attribute_name_id(attr):
"""
Return the attribute name identifier
"""
return attr.value.id if isinstance(attr.value, ast.Name) else None | python | def get_attribute_name_id(attr):
return attr.value.id if isinstance(attr.value, ast.Name) else None | [
"def",
"get_attribute_name_id",
"(",
"attr",
")",
":",
"return",
"attr",
".",
"value",
".",
"id",
"if",
"isinstance",
"(",
"attr",
".",
"value",
",",
"ast",
".",
"Name",
")",
"else",
"None"
] | Return the attribute name identifier | [
"Return",
"the",
"attribute",
"name",
"identifier"
] | b242ad59770940f3a0904931f27755ede009f491 | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L32-L36 |
1,142 | mschwager/cohesion | lib/cohesion/parser.py | is_class_method_bound | def is_class_method_bound(method, arg_name=BOUND_METHOD_ARGUMENT_NAME):
"""
Return whether a class method is bound to the class
"""
if not method.args.args:
return False
first_arg = method.args.args[0]
first_arg_name = get_object_name(first_arg)
return first_arg_name == arg_name | python | def is_class_method_bound(method, arg_name=BOUND_METHOD_ARGUMENT_NAME):
if not method.args.args:
return False
first_arg = method.args.args[0]
first_arg_name = get_object_name(first_arg)
return first_arg_name == arg_name | [
"def",
"is_class_method_bound",
"(",
"method",
",",
"arg_name",
"=",
"BOUND_METHOD_ARGUMENT_NAME",
")",
":",
"if",
"not",
"method",
".",
"args",
".",
"args",
":",
"return",
"False",
"first_arg",
"=",
"method",
".",
"args",
".",
"args",
"[",
"0",
"]",
"firs... | Return whether a class method is bound to the class | [
"Return",
"whether",
"a",
"class",
"method",
"is",
"bound",
"to",
"the",
"class"
] | b242ad59770940f3a0904931f27755ede009f491 | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L39-L50 |
1,143 | mschwager/cohesion | lib/cohesion/parser.py | get_class_methods | def get_class_methods(cls):
"""
Return methods associated with a given class
"""
return [
node
for node in cls.body
if isinstance(node, ast.FunctionDef)
] | python | def get_class_methods(cls):
return [
node
for node in cls.body
if isinstance(node, ast.FunctionDef)
] | [
"def",
"get_class_methods",
"(",
"cls",
")",
":",
"return",
"[",
"node",
"for",
"node",
"in",
"cls",
".",
"body",
"if",
"isinstance",
"(",
"node",
",",
"ast",
".",
"FunctionDef",
")",
"]"
] | Return methods associated with a given class | [
"Return",
"methods",
"associated",
"with",
"a",
"given",
"class"
] | b242ad59770940f3a0904931f27755ede009f491 | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L74-L82 |
1,144 | mschwager/cohesion | lib/cohesion/parser.py | get_class_variables | def get_class_variables(cls):
"""
Return class variables associated with a given class
"""
return [
target
for node in cls.body
if isinstance(node, ast.Assign)
for target in node.targets
] | python | def get_class_variables(cls):
return [
target
for node in cls.body
if isinstance(node, ast.Assign)
for target in node.targets
] | [
"def",
"get_class_variables",
"(",
"cls",
")",
":",
"return",
"[",
"target",
"for",
"node",
"in",
"cls",
".",
"body",
"if",
"isinstance",
"(",
"node",
",",
"ast",
".",
"Assign",
")",
"for",
"target",
"in",
"node",
".",
"targets",
"]"
] | Return class variables associated with a given class | [
"Return",
"class",
"variables",
"associated",
"with",
"a",
"given",
"class"
] | b242ad59770940f3a0904931f27755ede009f491 | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L85-L94 |
1,145 | mschwager/cohesion | lib/cohesion/parser.py | get_instance_variables | def get_instance_variables(node, bound_name_classifier=BOUND_METHOD_ARGUMENT_NAME):
"""
Return instance variables used in an AST node
"""
node_attributes = [
child
for child in ast.walk(node)
if isinstance(child, ast.Attribute) and
get_attribute_name_id(child) == bound_na... | python | def get_instance_variables(node, bound_name_classifier=BOUND_METHOD_ARGUMENT_NAME):
node_attributes = [
child
for child in ast.walk(node)
if isinstance(child, ast.Attribute) and
get_attribute_name_id(child) == bound_name_classifier
]
node_function_call_names = [
get_o... | [
"def",
"get_instance_variables",
"(",
"node",
",",
"bound_name_classifier",
"=",
"BOUND_METHOD_ARGUMENT_NAME",
")",
":",
"node_attributes",
"=",
"[",
"child",
"for",
"child",
"in",
"ast",
".",
"walk",
"(",
"node",
")",
"if",
"isinstance",
"(",
"child",
",",
"a... | Return instance variables used in an AST node | [
"Return",
"instance",
"variables",
"used",
"in",
"an",
"AST",
"node"
] | b242ad59770940f3a0904931f27755ede009f491 | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L97-L117 |
1,146 | mschwager/cohesion | lib/cohesion/parser.py | get_module_classes | def get_module_classes(node):
"""
Return classes associated with a given module
"""
return [
child
for child in ast.walk(node)
if isinstance(child, ast.ClassDef)
] | python | def get_module_classes(node):
return [
child
for child in ast.walk(node)
if isinstance(child, ast.ClassDef)
] | [
"def",
"get_module_classes",
"(",
"node",
")",
":",
"return",
"[",
"child",
"for",
"child",
"in",
"ast",
".",
"walk",
"(",
"node",
")",
"if",
"isinstance",
"(",
"child",
",",
"ast",
".",
"ClassDef",
")",
"]"
] | Return classes associated with a given module | [
"Return",
"classes",
"associated",
"with",
"a",
"given",
"module"
] | b242ad59770940f3a0904931f27755ede009f491 | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L149-L157 |
1,147 | mschwager/cohesion | lib/cohesion/filesystem.py | recursively_get_files_from_directory | def recursively_get_files_from_directory(directory):
"""
Return all filenames under recursively found in a directory
"""
return [
os.path.join(root, filename)
for root, directories, filenames in os.walk(directory)
for filename in filenames
] | python | def recursively_get_files_from_directory(directory):
return [
os.path.join(root, filename)
for root, directories, filenames in os.walk(directory)
for filename in filenames
] | [
"def",
"recursively_get_files_from_directory",
"(",
"directory",
")",
":",
"return",
"[",
"os",
".",
"path",
".",
"join",
"(",
"root",
",",
"filename",
")",
"for",
"root",
",",
"directories",
",",
"filenames",
"in",
"os",
".",
"walk",
"(",
"directory",
")"... | Return all filenames under recursively found in a directory | [
"Return",
"all",
"filenames",
"under",
"recursively",
"found",
"in",
"a",
"directory"
] | b242ad59770940f3a0904931f27755ede009f491 | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/filesystem.py#L21-L29 |
1,148 | JarryShaw/PyPCAPKit | src/corekit/protochain.py | ProtoChain.index | def index(self, value, start=None, stop=None):
"""Return first index of value."""
return self.__alias__.index(value, start, stop) | python | def index(self, value, start=None, stop=None):
return self.__alias__.index(value, start, stop) | [
"def",
"index",
"(",
"self",
",",
"value",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
")",
":",
"return",
"self",
".",
"__alias__",
".",
"index",
"(",
"value",
",",
"start",
",",
"stop",
")"
] | Return first index of value. | [
"Return",
"first",
"index",
"of",
"value",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/corekit/protochain.py#L213-L215 |
1,149 | JarryShaw/PyPCAPKit | src/protocols/link/ospf.py | OSPF.read_ospf | def read_ospf(self, length):
"""Read Open Shortest Path First.
Structure of OSPF header [RFC 2328]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | python | def read_ospf(self, length):
if length is None:
length = len(self)
_vers = self._read_unpack(1)
_type = self._read_unpack(1)
_tlen = self._read_unpack(2)
_rtid = self._read_id_numbers()
_area = self._read_id_numbers()
_csum = self._read_fileng(2)
... | [
"def",
"read_ospf",
"(",
"self",
",",
"length",
")",
":",
"if",
"length",
"is",
"None",
":",
"length",
"=",
"len",
"(",
"self",
")",
"_vers",
"=",
"self",
".",
"_read_unpack",
"(",
"1",
")",
"_type",
"=",
"self",
".",
"_read_unpack",
"(",
"1",
")",... | Read Open Shortest Path First.
Structure of OSPF header [RFC 2328]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| V... | [
"Read",
"Open",
"Shortest",
"Path",
"First",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/ospf.py#L95-L155 |
1,150 | JarryShaw/PyPCAPKit | src/protocols/link/ospf.py | OSPF._read_id_numbers | def _read_id_numbers(self):
"""Read router and area IDs."""
_byte = self._read_fileng(4)
_addr = '.'.join([str(_) for _ in _byte])
return _addr | python | def _read_id_numbers(self):
_byte = self._read_fileng(4)
_addr = '.'.join([str(_) for _ in _byte])
return _addr | [
"def",
"_read_id_numbers",
"(",
"self",
")",
":",
"_byte",
"=",
"self",
".",
"_read_fileng",
"(",
"4",
")",
"_addr",
"=",
"'.'",
".",
"join",
"(",
"[",
"str",
"(",
"_",
")",
"for",
"_",
"in",
"_byte",
"]",
")",
"return",
"_addr"
] | Read router and area IDs. | [
"Read",
"router",
"and",
"area",
"IDs",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/ospf.py#L172-L176 |
1,151 | JarryShaw/PyPCAPKit | src/protocols/link/ospf.py | OSPF._read_encrypt_auth | def _read_encrypt_auth(self):
"""Read Authentication field when Cryptographic Authentication is employed.
Structure of Cryptographic Authentication [RFC 2328]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 ... | python | def _read_encrypt_auth(self):
_resv = self._read_fileng(2)
_keys = self._read_unpack(1)
_alen = self._read_unpack(1)
_seqn = self._read_unpack(4)
auth = dict(
key_id=_keys,
len=_alen,
seq=_seqn,
)
return auth | [
"def",
"_read_encrypt_auth",
"(",
"self",
")",
":",
"_resv",
"=",
"self",
".",
"_read_fileng",
"(",
"2",
")",
"_keys",
"=",
"self",
".",
"_read_unpack",
"(",
"1",
")",
"_alen",
"=",
"self",
".",
"_read_unpack",
"(",
"1",
")",
"_seqn",
"=",
"self",
".... | Read Authentication field when Cryptographic Authentication is employed.
Structure of Cryptographic Authentication [RFC 2328]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+... | [
"Read",
"Authentication",
"field",
"when",
"Cryptographic",
"Authentication",
"is",
"employed",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/ospf.py#L178-L209 |
1,152 | JarryShaw/PyPCAPKit | src/utilities/validations.py | int_check | def int_check(*args, func=None):
"""Check if arguments are integrals."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, numbers.Integral):
name = type(var).__name__
raise ComplexError(
f'Function {func} expected integral number, {... | python | def int_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, numbers.Integral):
name = type(var).__name__
raise ComplexError(
f'Function {func} expected integral number, {name} got instead.') | [
"def",
"int_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",
... | Check if arguments are integrals. | [
"Check",
"if",
"arguments",
"are",
"integrals",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L36-L43 |
1,153 | JarryShaw/PyPCAPKit | src/utilities/validations.py | real_check | def real_check(*args, func=None):
"""Check if arguments are real numbers."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, numbers.Real):
name = type(var).__name__
raise ComplexError(
f'Function {func} expected real number, {name... | python | def real_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, numbers.Real):
name = type(var).__name__
raise ComplexError(
f'Function {func} expected real number, {name} got instead.') | [
"def",
"real_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",
... | Check if arguments are real numbers. | [
"Check",
"if",
"arguments",
"are",
"real",
"numbers",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L46-L53 |
1,154 | JarryShaw/PyPCAPKit | src/utilities/validations.py | complex_check | def complex_check(*args, func=None):
"""Check if arguments are complex numbers."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, numbers.Complex):
name = type(var).__name__
raise ComplexError(
f'Function {func} expected complex n... | python | def complex_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, numbers.Complex):
name = type(var).__name__
raise ComplexError(
f'Function {func} expected complex number, {name} got instead.') | [
"def",
"complex_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",... | Check if arguments are complex numbers. | [
"Check",
"if",
"arguments",
"are",
"complex",
"numbers",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L56-L63 |
1,155 | JarryShaw/PyPCAPKit | src/utilities/validations.py | number_check | def number_check(*args, func=None):
"""Check if arguments are numbers."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, numbers.Number):
name = type(var).__name__
raise DigitError(
f'Function {func} expected number, {name} got in... | python | def number_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, numbers.Number):
name = type(var).__name__
raise DigitError(
f'Function {func} expected number, {name} got instead.') | [
"def",
"number_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
","... | Check if arguments are numbers. | [
"Check",
"if",
"arguments",
"are",
"numbers",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L66-L73 |
1,156 | JarryShaw/PyPCAPKit | src/utilities/validations.py | bytearray_check | def bytearray_check(*args, func=None):
"""Check if arguments are bytearray type."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (bytearray, collections.abc.ByteString, collections.abc.MutableSequence)):
name = type(var).__name__
raise Bytearra... | python | def bytearray_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (bytearray, collections.abc.ByteString, collections.abc.MutableSequence)):
name = type(var).__name__
raise BytearrayError(
f'Function {func} expecte... | [
"def",
"bytearray_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
... | Check if arguments are bytearray type. | [
"Check",
"if",
"arguments",
"are",
"bytearray",
"type",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L86-L93 |
1,157 | JarryShaw/PyPCAPKit | src/utilities/validations.py | str_check | def str_check(*args, func=None):
"""Check if arguments are str type."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (str, collections.UserString, collections.abc.Sequence)):
name = type(var).__name__
raise StringError(
f'Functi... | python | def str_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (str, collections.UserString, collections.abc.Sequence)):
name = type(var).__name__
raise StringError(
f'Function {func} expected str, {name} got instead.... | [
"def",
"str_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",
... | Check if arguments are str type. | [
"Check",
"if",
"arguments",
"are",
"str",
"type",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L96-L103 |
1,158 | JarryShaw/PyPCAPKit | src/utilities/validations.py | list_check | def list_check(*args, func=None):
"""Check if arguments are list type."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (list, collections.UserList, collections.abc.MutableSequence)):
name = type(var).__name__
raise ListError(
f'... | python | def list_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (list, collections.UserList, collections.abc.MutableSequence)):
name = type(var).__name__
raise ListError(
f'Function {func} expected list, {name} got in... | [
"def",
"list_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",
... | Check if arguments are list type. | [
"Check",
"if",
"arguments",
"are",
"list",
"type",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L116-L123 |
1,159 | JarryShaw/PyPCAPKit | src/utilities/validations.py | dict_check | def dict_check(*args, func=None):
"""Check if arguments are dict type."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (dict, collections.UserDict, collections.abc.MutableMapping)):
name = type(var).__name__
raise DictError(
f'F... | python | def dict_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (dict, collections.UserDict, collections.abc.MutableMapping)):
name = type(var).__name__
raise DictError(
f'Function {func} expected dict, {name} got ins... | [
"def",
"dict_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",
... | Check if arguments are dict type. | [
"Check",
"if",
"arguments",
"are",
"dict",
"type",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L126-L133 |
1,160 | JarryShaw/PyPCAPKit | src/utilities/validations.py | tuple_check | def tuple_check(*args, func=None):
"""Check if arguments are tuple type."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (tuple, collections.abc.Sequence)):
name = type(var).__name__
raise TupleError(
f'Function {func} expected ... | python | def tuple_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (tuple, collections.abc.Sequence)):
name = type(var).__name__
raise TupleError(
f'Function {func} expected tuple, {name} got instead.') | [
"def",
"tuple_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",... | Check if arguments are tuple type. | [
"Check",
"if",
"arguments",
"are",
"tuple",
"type",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L136-L143 |
1,161 | JarryShaw/PyPCAPKit | src/utilities/validations.py | io_check | def io_check(*args, func=None):
"""Check if arguments are file-like object."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, io.IOBase):
name = type(var).__name__
raise IOObjError(
f'Function {func} expected file-like object, {na... | python | def io_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, io.IOBase):
name = type(var).__name__
raise IOObjError(
f'Function {func} expected file-like object, {name} got instead.') | [
"def",
"io_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",
... | Check if arguments are file-like object. | [
"Check",
"if",
"arguments",
"are",
"file",
"-",
"like",
"object",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L146-L153 |
1,162 | JarryShaw/PyPCAPKit | src/utilities/validations.py | info_check | def info_check(*args, func=None):
"""Check if arguments are Info instance."""
from pcapkit.corekit.infoclass import Info
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, Info):
name = type(var).__name__
raise InfoError(
f'Funct... | python | def info_check(*args, func=None):
from pcapkit.corekit.infoclass import Info
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, Info):
name = type(var).__name__
raise InfoError(
f'Function {func} expected Info instance, {name} got in... | [
"def",
"info_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"from",
"pcapkit",
".",
"corekit",
".",
"infoclass",
"import",
"Info",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"... | Check if arguments are Info instance. | [
"Check",
"if",
"arguments",
"are",
"Info",
"instance",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L156-L165 |
1,163 | JarryShaw/PyPCAPKit | src/utilities/validations.py | ip_check | def ip_check(*args, func=None):
"""Check if arguments are IP addresses."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, ipaddress._IPAddressBase):
name = type(var).__name__
raise IPError(
f'Function {func} expected IP address, {... | python | def ip_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, ipaddress._IPAddressBase):
name = type(var).__name__
raise IPError(
f'Function {func} expected IP address, {name} got instead.') | [
"def",
"ip_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",
... | Check if arguments are IP addresses. | [
"Check",
"if",
"arguments",
"are",
"IP",
"addresses",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L168-L175 |
1,164 | JarryShaw/PyPCAPKit | src/utilities/validations.py | enum_check | def enum_check(*args, func=None):
"""Check if arguments are of protocol type."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (enum.EnumMeta, aenum.EnumMeta)):
name = type(var).__name__
raise EnumError(
f'Function {func} expecte... | python | def enum_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (enum.EnumMeta, aenum.EnumMeta)):
name = type(var).__name__
raise EnumError(
f'Function {func} expected enumeration, {name} got instead.') | [
"def",
"enum_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",
... | Check if arguments are of protocol type. | [
"Check",
"if",
"arguments",
"are",
"of",
"protocol",
"type",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L178-L185 |
1,165 | JarryShaw/PyPCAPKit | src/utilities/validations.py | frag_check | def frag_check(*args, protocol, func=None):
"""Check if arguments are valid fragments."""
func = func or inspect.stack()[2][3]
if 'IP' in protocol:
_ip_frag_check(*args, func=func)
elif 'TCP' in protocol:
_tcp_frag_check(*args, func=func)
else:
raise FragmentError(f'Unknown f... | python | def frag_check(*args, protocol, func=None):
func = func or inspect.stack()[2][3]
if 'IP' in protocol:
_ip_frag_check(*args, func=func)
elif 'TCP' in protocol:
_tcp_frag_check(*args, func=func)
else:
raise FragmentError(f'Unknown fragmented protocol {protocol}.') | [
"def",
"frag_check",
"(",
"*",
"args",
",",
"protocol",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"if",
"'IP'",
"in",
"protocol",
":",
"_ip_frag_check",
"(",
"*... | Check if arguments are valid fragments. | [
"Check",
"if",
"arguments",
"are",
"valid",
"fragments",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L188-L196 |
1,166 | JarryShaw/PyPCAPKit | src/utilities/validations.py | _ip_frag_check | def _ip_frag_check(*args, func=None):
"""Check if arguments are valid IP fragments."""
func = func or inspect.stack()[2][3]
for var in args:
dict_check(var, func=func)
bufid = var.get('bufid')
str_check(bufid[3], func=func)
bool_check(var.get('mf'), func=func)
ip_chec... | python | def _ip_frag_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
dict_check(var, func=func)
bufid = var.get('bufid')
str_check(bufid[3], func=func)
bool_check(var.get('mf'), func=func)
ip_check(bufid[0], bufid[1], func=func)
bytearray_ch... | [
"def",
"_ip_frag_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"dict_check",
"(",
"var",
",",
"func",
"... | Check if arguments are valid IP fragments. | [
"Check",
"if",
"arguments",
"are",
"valid",
"IP",
"fragments",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L199-L210 |
1,167 | JarryShaw/PyPCAPKit | src/utilities/validations.py | pkt_check | def pkt_check(*args, func=None):
"""Check if arguments are valid packets."""
func = func or inspect.stack()[2][3]
for var in args:
dict_check(var, func=func)
dict_check(var.get('frame'), func=func)
enum_check(var.get('protocol'), func=func)
real_check(var.get('timestamp'), fu... | python | def pkt_check(*args, func=None):
func = func or inspect.stack()[2][3]
for var in args:
dict_check(var, func=func)
dict_check(var.get('frame'), func=func)
enum_check(var.get('protocol'), func=func)
real_check(var.get('timestamp'), func=func)
ip_check(var.get('src'), var.ge... | [
"def",
"pkt_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"dict_check",
"(",
"var",
",",
"func",
"=",
... | Check if arguments are valid packets. | [
"Check",
"if",
"arguments",
"are",
"valid",
"packets",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L226-L236 |
1,168 | JarryShaw/PyPCAPKit | src/reassembly/reassembly.py | Reassembly.fetch | def fetch(self):
"""Fetch datagram."""
if self._newflg:
self._newflg = False
temp_dtgram = copy.deepcopy(self._dtgram)
for (bufid, buffer) in self._buffer.items():
temp_dtgram += self.submit(buffer, bufid=bufid)
return tuple(temp_dtgram)
... | python | def fetch(self):
if self._newflg:
self._newflg = False
temp_dtgram = copy.deepcopy(self._dtgram)
for (bufid, buffer) in self._buffer.items():
temp_dtgram += self.submit(buffer, bufid=bufid)
return tuple(temp_dtgram)
return tuple(self._dtgra... | [
"def",
"fetch",
"(",
"self",
")",
":",
"if",
"self",
".",
"_newflg",
":",
"self",
".",
"_newflg",
"=",
"False",
"temp_dtgram",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"_dtgram",
")",
"for",
"(",
"bufid",
",",
"buffer",
")",
"in",
"self",
".... | Fetch datagram. | [
"Fetch",
"datagram",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/reassembly/reassembly.py#L108-L116 |
1,169 | JarryShaw/PyPCAPKit | src/reassembly/reassembly.py | Reassembly.index | def index(self, pkt_num):
"""Return datagram index."""
int_check(pkt_num)
for counter, datagram in enumerate(self.datagram):
if pkt_num in datagram.index:
return counter
return None | python | def index(self, pkt_num):
int_check(pkt_num)
for counter, datagram in enumerate(self.datagram):
if pkt_num in datagram.index:
return counter
return None | [
"def",
"index",
"(",
"self",
",",
"pkt_num",
")",
":",
"int_check",
"(",
"pkt_num",
")",
"for",
"counter",
",",
"datagram",
"in",
"enumerate",
"(",
"self",
".",
"datagram",
")",
":",
"if",
"pkt_num",
"in",
"datagram",
".",
"index",
":",
"return",
"coun... | Return datagram index. | [
"Return",
"datagram",
"index",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/reassembly/reassembly.py#L119-L125 |
1,170 | JarryShaw/PyPCAPKit | src/reassembly/reassembly.py | Reassembly.run | def run(self, packets):
"""Run automatically.
Positional arguments:
* packets -- list<dict>, list of packet dicts to be reassembled
"""
for packet in packets:
frag_check(packet, protocol=self.protocol)
info = Info(packet)
self.reassembly(... | python | def run(self, packets):
for packet in packets:
frag_check(packet, protocol=self.protocol)
info = Info(packet)
self.reassembly(info)
self._newflg = True | [
"def",
"run",
"(",
"self",
",",
"packets",
")",
":",
"for",
"packet",
"in",
"packets",
":",
"frag_check",
"(",
"packet",
",",
"protocol",
"=",
"self",
".",
"protocol",
")",
"info",
"=",
"Info",
"(",
"packet",
")",
"self",
".",
"reassembly",
"(",
"inf... | Run automatically.
Positional arguments:
* packets -- list<dict>, list of packet dicts to be reassembled | [
"Run",
"automatically",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/reassembly/reassembly.py#L128-L139 |
1,171 | JarryShaw/PyPCAPKit | src/protocols/internet/mh.py | MH.read_mh | def read_mh(self, length, extension):
"""Read Mobility Header.
Structure of MH header [RFC 6275]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Proto | Header Len | MH Type | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+... | python | def read_mh(self, length, extension):
if length is None:
length = len(self)
_next = self._read_protos(1)
_hlen = self._read_unpack(1)
_type = self._read_unpack(1)
_temp = self._read_fileng(1)
_csum = self._read_fileng(2)
# _data = self._read_fileng((_... | [
"def",
"read_mh",
"(",
"self",
",",
"length",
",",
"extension",
")",
":",
"if",
"length",
"is",
"None",
":",
"length",
"=",
"len",
"(",
"self",
")",
"_next",
"=",
"self",
".",
"_read_protos",
"(",
"1",
")",
"_hlen",
"=",
"self",
".",
"_read_unpack",
... | Read Mobility Header.
Structure of MH header [RFC 6275]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Proto | Header Len | MH Type | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... | [
"Read",
"Mobility",
"Header",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/mh.py#L91-L139 |
1,172 | JarryShaw/PyPCAPKit | src/protocols/internet/ipx.py | IPX.read_ipx | def read_ipx(self, length):
"""Read Internetwork Packet Exchange.
Structure of IPX header [RFC 1132]:
Octets Bits Name Description
0 0 ipx.cksum Checksum
2 16 ipx.len Packet L... | python | def read_ipx(self, length):
if length is None:
length = len(self)
_csum = self._read_fileng(2)
_tlen = self._read_unpack(2)
_ctrl = self._read_unpack(1)
_type = self._read_unpack(1)
_dsta = self._read_ipx_address()
_srca = self._read_ipx_address()
... | [
"def",
"read_ipx",
"(",
"self",
",",
"length",
")",
":",
"if",
"length",
"is",
"None",
":",
"length",
"=",
"len",
"(",
"self",
")",
"_csum",
"=",
"self",
".",
"_read_fileng",
"(",
"2",
")",
"_tlen",
"=",
"self",
".",
"_read_unpack",
"(",
"2",
")",
... | Read Internetwork Packet Exchange.
Structure of IPX header [RFC 1132]:
Octets Bits Name Description
0 0 ipx.cksum Checksum
2 16 ipx.len Packet Length (header includes)
4... | [
"Read",
"Internetwork",
"Packet",
"Exchange",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipx.py#L93-L129 |
1,173 | JarryShaw/PyPCAPKit | src/protocols/internet/ipx.py | IPX._read_ipx_address | def _read_ipx_address(self):
"""Read IPX address field.
Structure of IPX address:
Octets Bits Name Description
0 0 ipx.addr.network Network Number
4 32 ipx.addr.node Node Number
... | python | def _read_ipx_address(self):
# Address Number
_byte = self._read_fileng(4)
_ntwk = ':'.join(textwrap.wrap(_byte.hex(), 2))
# Node Number (MAC)
_byte = self._read_fileng(6)
_node = ':'.join(textwrap.wrap(_byte.hex(), 2))
_maca = '-'.join(textwrap.wrap(_byte.hex(),... | [
"def",
"_read_ipx_address",
"(",
"self",
")",
":",
"# Address Number",
"_byte",
"=",
"self",
".",
"_read_fileng",
"(",
"4",
")",
"_ntwk",
"=",
"':'",
".",
"join",
"(",
"textwrap",
".",
"wrap",
"(",
"_byte",
".",
"hex",
"(",
")",
",",
"2",
")",
")",
... | Read IPX address field.
Structure of IPX address:
Octets Bits Name Description
0 0 ipx.addr.network Network Number
4 32 ipx.addr.node Node Number
10 80 ipx.addr.socket ... | [
"Read",
"IPX",
"address",
"field",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipx.py#L146-L179 |
1,174 | JarryShaw/PyPCAPKit | src/protocols/link/arp.py | ARP.read_arp | def read_arp(self, length):
"""Read Address Resolution Protocol.
Structure of ARP header [RFC 826]:
Octets Bits Name Description
0 0 arp.htype Hardware Type
2 16 arp.ptype Proto... | python | def read_arp(self, length):
if length is None:
length = len(self)
_hwty = self._read_unpack(2)
_ptty = self._read_unpack(2)
_hlen = self._read_unpack(1)
_plen = self._read_unpack(1)
_oper = self._read_unpack(2)
_shwa = self._read_addr_resolve(_hlen, _... | [
"def",
"read_arp",
"(",
"self",
",",
"length",
")",
":",
"if",
"length",
"is",
"None",
":",
"length",
"=",
"len",
"(",
"self",
")",
"_hwty",
"=",
"self",
".",
"_read_unpack",
"(",
"2",
")",
"_ptty",
"=",
"self",
".",
"_read_unpack",
"(",
"2",
")",
... | Read Address Resolution Protocol.
Structure of ARP header [RFC 826]:
Octets Bits Name Description
0 0 arp.htype Hardware Type
2 16 arp.ptype Protocol Type
4 32 ... | [
"Read",
"Address",
"Resolution",
"Protocol",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/arp.py#L116-L180 |
1,175 | JarryShaw/PyPCAPKit | src/protocols/link/arp.py | ARP._read_addr_resolve | def _read_addr_resolve(self, length, htype):
"""Resolve MAC address according to protocol.
Positional arguments:
* length -- int, hardware address length
* htype -- int, hardware type
Returns:
* str -- MAC address
"""
if htype == 1: # Ether... | python | def _read_addr_resolve(self, length, htype):
if htype == 1: # Ethernet
_byte = self._read_fileng(6)
_addr = '-'.join(textwrap.wrap(_byte.hex(), 2))
else:
_addr = self._read_fileng(length)
return _addr | [
"def",
"_read_addr_resolve",
"(",
"self",
",",
"length",
",",
"htype",
")",
":",
"if",
"htype",
"==",
"1",
":",
"# Ethernet",
"_byte",
"=",
"self",
".",
"_read_fileng",
"(",
"6",
")",
"_addr",
"=",
"'-'",
".",
"join",
"(",
"textwrap",
".",
"wrap",
"(... | Resolve MAC address according to protocol.
Positional arguments:
* length -- int, hardware address length
* htype -- int, hardware type
Returns:
* str -- MAC address | [
"Resolve",
"MAC",
"address",
"according",
"to",
"protocol",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/arp.py#L201-L217 |
1,176 | JarryShaw/PyPCAPKit | src/protocols/link/arp.py | ARP._read_proto_resolve | def _read_proto_resolve(self, length, ptype):
"""Resolve IP address according to protocol.
Positional arguments:
* length -- int, protocol address length
* ptype -- int, protocol type
Returns:
* str -- IP address
"""
# if ptype == '0800': ... | python | def _read_proto_resolve(self, length, ptype):
# if ptype == '0800': # IPv4
# _byte = self._read_fileng(4)
# _addr = '.'.join([str(_) for _ in _byte])
# elif ptype == '86dd': # IPv6
# adlt = [] # list of IPv6 hexadecimal address
# ctr_ = collect... | [
"def",
"_read_proto_resolve",
"(",
"self",
",",
"length",
",",
"ptype",
")",
":",
"# if ptype == '0800': # IPv4",
"# _byte = self._read_fileng(4)",
"# _addr = '.'.join([str(_) for _ in _byte])",
"# elif ptype == '86dd': # IPv6",
"# adlt = [] # list of IPv6 hexadec... | Resolve IP address according to protocol.
Positional arguments:
* length -- int, protocol address length
* ptype -- int, protocol type
Returns:
* str -- IP address | [
"Resolve",
"IP",
"address",
"according",
"to",
"protocol",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/arp.py#L219-L278 |
1,177 | JarryShaw/PyPCAPKit | src/protocols/internet/ipv6.py | IPv6._read_ip_hextet | def _read_ip_hextet(self):
"""Read first four hextets of IPv6."""
_htet = self._read_fileng(4).hex()
_vers = _htet[0] # version number (6)
_tcls = int(_htet[0:2], base=16) # traffic class
_flow = int(_htet[2:], base=16) # flow label
return (_ver... | python | def _read_ip_hextet(self):
_htet = self._read_fileng(4).hex()
_vers = _htet[0] # version number (6)
_tcls = int(_htet[0:2], base=16) # traffic class
_flow = int(_htet[2:], base=16) # flow label
return (_vers, _tcls, _flow) | [
"def",
"_read_ip_hextet",
"(",
"self",
")",
":",
"_htet",
"=",
"self",
".",
"_read_fileng",
"(",
"4",
")",
".",
"hex",
"(",
")",
"_vers",
"=",
"_htet",
"[",
"0",
"]",
"# version number (6)",
"_tcls",
"=",
"int",
"(",
"_htet",
"[",
"0",
":",
"2",
"]... | Read first four hextets of IPv6. | [
"Read",
"first",
"four",
"hextets",
"of",
"IPv6",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6.py#L188-L195 |
1,178 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP.read_hip | def read_hip(self, length, extension):
"""Read Host Identity Protocol.
Structure of HIP header [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-... | python | def read_hip(self, length, extension):
if length is None:
length = len(self)
_next = self._read_protos(1)
_hlen = self._read_unpack(1)
_type = self._read_binary(1)
if _type[0] != '0':
raise ProtocolError('HIP: invalid format')
_vers = self._read_b... | [
"def",
"read_hip",
"(",
"self",
",",
"length",
",",
"extension",
")",
":",
"if",
"length",
"is",
"None",
":",
"length",
"=",
"len",
"(",
"self",
")",
"_next",
"=",
"self",
".",
"_read_protos",
"(",
"1",
")",
"_hlen",
"=",
"self",
".",
"_read_unpack",... | Read Host Identity Protocol.
Structure of HIP header [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | [
"Read",
"Host",
"Identity",
"Protocol",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L138-L221 |
1,179 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_hip_para | def _read_hip_para(self, length, *, version):
"""Read HIP parameters.
Positional arguments:
* length -- int, length of parameters
Keyword arguments:
* version -- int, HIP version
Returns:
* dict -- extracted HIP parameters
"""
count... | python | def _read_hip_para(self, length, *, version):
counter = 0 # length of read parameters
optkind = list() # parameter type list
options = dict() # dict of parameter data
while counter < length:
# break when eol triggered
kind = self._read_binary(2)
... | [
"def",
"_read_hip_para",
"(",
"self",
",",
"length",
",",
"*",
",",
"version",
")",
":",
"counter",
"=",
"0",
"# length of read parameters",
"optkind",
"=",
"list",
"(",
")",
"# parameter type list",
"options",
"=",
"dict",
"(",
")",
"# dict of parameter data",
... | Read HIP parameters.
Positional arguments:
* length -- int, length of parameters
Keyword arguments:
* version -- int, HIP version
Returns:
* dict -- extracted HIP parameters | [
"Read",
"HIP",
"parameters",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L239-L297 |
1,180 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_unassigned | def _read_para_unassigned(self, code, cbit, clen, *, desc, length, version):
"""Read HIP unassigned parameters.
Structure of HIP unassigned parameters [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 ... | python | def _read_para_unassigned(self, code, cbit, clen, *, desc, length, version):
unassigned = dict(
type=desc,
critical=cbit,
length=clen,
contents=self._read_fileng(clen),
)
plen = length - clen
if plen:
self._read_fileng(plen)
... | [
"def",
"_read_para_unassigned",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"unassigned",
"=",
"dict",
"(",
"type",
"=",
"desc",
",",
"critical",
"=",
"cbit",
",",
"length",
"=",... | Read HIP unassigned parameters.
Structure of HIP unassigned parameters [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"unassigned",
"parameters",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L299-L333 |
1,181 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_esp_info | def _read_para_esp_info(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ESP_INFO parameter.
Structure of HIP ESP_INFO parameter [RFC 7402]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 ... | python | def _read_para_esp_info(self, code, cbit, clen, *, desc, length, version):
if clen != 12:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_resv = self._read_fileng(2)
_kind = self._read_unpack(2)
_olds = self._read_unpack(2)
_news = self._read_u... | [
"def",
"_read_para_esp_info",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"if",
"clen",
"!=",
"12",
":",
"raise",
"ProtocolError",
"(",
"f'HIPv{version}: [Parano {code}] invalid format'",
... | Read HIP ESP_INFO parameter.
Structure of HIP ESP_INFO parameter [RFC 7402]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | [
"Read",
"HIP",
"ESP_INFO",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L335-L378 |
1,182 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_r1_counter | def _read_para_r1_counter(self, code, cbit, clen, *, desc, length, version):
"""Read HIP R1_COUNTER parameter.
Structure of HIP R1_COUNTER parameter [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ... | python | def _read_para_r1_counter(self, code, cbit, clen, *, desc, length, version):
if clen != 12:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
if code == 128 and version != 1:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid parameter')
_re... | [
"def",
"_read_para_r1_counter",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"if",
"clen",
"!=",
"12",
":",
"raise",
"ProtocolError",
"(",
"f'HIPv{version}: [Parano {code}] invalid format'"... | Read HIP R1_COUNTER parameter.
Structure of HIP R1_COUNTER parameter [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"R1_COUNTER",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L380-L418 |
1,183 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_locator_set | def _read_para_locator_set(self, code, cbit, clen, *, desc, length, version):
"""Read HIP LOCATOR_SET parameter.
Structure of HIP LOCATOR_SET parameter [RFC 8046]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5... | python | def _read_para_locator_set(self, code, cbit, clen, *, desc, length, version):
def _read_locator(kind, size):
if kind == 0 and size == 16:
return ipaddress.ip_address(self._read_fileng(16))
elif kind == 1 and size == 20:
return dict(
spi... | [
"def",
"_read_para_locator_set",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"def",
"_read_locator",
"(",
"kind",
",",
"size",
")",
":",
"if",
"kind",
"==",
"0",
"and",
"size",
... | Read HIP LOCATOR_SET parameter.
Structure of HIP LOCATOR_SET parameter [RFC 8046]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"LOCATOR_SET",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L420-L503 |
1,184 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_puzzle | def _read_para_puzzle(self, code, cbit, clen, *, desc, length, version):
"""Read HIP PUZZLE parameter.
Structure of HIP PUZZLE parameter [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 ... | python | def _read_para_puzzle(self, code, cbit, clen, *, desc, length, version):
if version == 1 and clen != 12:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_numk = self._read_unpack(1)
_time = self._read_unpack(1)
_opak = self._read_fileng(2)
_rand... | [
"def",
"_read_para_puzzle",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"if",
"version",
"==",
"1",
"and",
"clen",
"!=",
"12",
":",
"raise",
"ProtocolError",
"(",
"f'HIPv{version}:... | Read HIP PUZZLE parameter.
Structure of HIP PUZZLE parameter [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"PUZZLE",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L505-L553 |
1,185 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_seq | def _read_para_seq(self, code, cbit, clen, *, desc, length, version):
"""Read HIP SEQ parameter.
Structure of HIP SEQ parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
... | python | def _read_para_seq(self, code, cbit, clen, *, desc, length, version):
if clen != 4:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_upid = self._read_unpack(4)
seq = dict(
type=desc,
critical=cbit,
length=clen,
... | [
"def",
"_read_para_seq",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"if",
"clen",
"!=",
"4",
":",
"raise",
"ProtocolError",
"(",
"f'HIPv{version}: [Parano {code}] invalid format'",
")",... | Read HIP SEQ parameter.
Structure of HIP SEQ parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... | [
"Read",
"HIP",
"SEQ",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L613-L644 |
1,186 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_ack | def _read_para_ack(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ACK parameter.
Structure of HIP ACK parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
... | python | def _read_para_ack(self, code, cbit, clen, *, desc, length, version):
if clen % 4 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_upid = list()
for _ in range(clen // 4):
_upid.append(self._read_unpack(4))
ack = dict(
typ... | [
"def",
"_read_para_ack",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"if",
"clen",
"%",
"4",
"!=",
"0",
":",
"raise",
"ProtocolError",
"(",
"f'HIPv{version}: [Parano {code}] invalid fo... | Read HIP ACK parameter.
Structure of HIP ACK parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... | [
"Read",
"HIP",
"ACK",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L646-L681 |
1,187 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_dh_group_list | def _read_para_dh_group_list(self, code, cbit, clen, *, desc, length, version):
"""Read HIP DH_GROUP_LIST parameter.
Structure of HIP DH_GROUP_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2... | python | def _read_para_dh_group_list(self, code, cbit, clen, *, desc, length, version):
_dhid = list()
for _ in range(clen):
_dhid.append(_GROUP_ID.get(self._read_unpack(1), 'Unassigned'))
dh_group_list = dict(
type=desc,
critical=cbit,
length=clen,
... | [
"def",
"_read_para_dh_group_list",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"_dhid",
"=",
"list",
"(",
")",
"for",
"_",
"in",
"range",
"(",
"clen",
")",
":",
"_dhid",
".",
... | Read HIP DH_GROUP_LIST parameter.
Structure of HIP DH_GROUP_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"DH_GROUP_LIST",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L683-L719 |
1,188 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_diffie_hellman | def _read_para_diffie_hellman(self, code, cbit, clen, *, desc, length, version):
"""Read HIP DIFFIE_HELLMAN parameter.
Structure of HIP DIFFIE_HELLMAN parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 ... | python | def _read_para_diffie_hellman(self, code, cbit, clen, *, desc, length, version):
_gpid = self._read_unpack(1)
_vlen = self._read_unpack(2)
_pval = self._read_fileng(_vlen)
diffie_hellman = dict(
type=desc,
critical=cbit,
length=clen,
id=_G... | [
"def",
"_read_para_diffie_hellman",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"_gpid",
"=",
"self",
".",
"_read_unpack",
"(",
"1",
")",
"_vlen",
"=",
"self",
".",
"_read_unpack",... | Read HIP DIFFIE_HELLMAN parameter.
Structure of HIP DIFFIE_HELLMAN parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"DIFFIE_HELLMAN",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L721-L764 |
1,189 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_hip_transform | def _read_para_hip_transform(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_TRANSFORM parameter.
Structure of HIP HIP_TRANSFORM parameter [RFC 5201]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2... | python | def _read_para_hip_transform(self, code, cbit, clen, *, desc, length, version):
if version != 1:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid parameter')
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_stid = list(... | [
"def",
"_read_para_hip_transform",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"if",
"version",
"!=",
"1",
":",
"raise",
"ProtocolError",
"(",
"f'HIPv{version}: [Parano {code}] invalid par... | Read HIP HIP_TRANSFORM parameter.
Structure of HIP HIP_TRANSFORM parameter [RFC 5201]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"HIP_TRANSFORM",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L766-L809 |
1,190 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_hip_cipher | def _read_para_hip_cipher(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_CIPHER parameter.
Structure of HIP HIP_CIPHER parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 ... | python | def _read_para_hip_cipher(self, code, cbit, clen, *, desc, length, version):
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_cpid = list()
for _ in range(clen // 2):
_cpid.append(_CIPHER_ID.get(self._read_unpack(2), 'Unassigned'))... | [
"def",
"_read_para_hip_cipher",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"if",
"clen",
"%",
"2",
"!=",
"0",
":",
"raise",
"ProtocolError",
"(",
"f'HIPv{version}: [Parano {code}] inv... | Read HIP HIP_CIPHER parameter.
Structure of HIP HIP_CIPHER parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | [
"Read",
"HIP",
"HIP_CIPHER",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L811-L852 |
1,191 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_nat_traversal_mode | def _read_para_nat_traversal_mode(self, code, cbit, clen, *, desc, length, version):
"""Read HIP NAT_TRAVERSAL_MODE parameter.
Structure of HIP NAT_TRAVERSAL_MODE parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 ... | python | def _read_para_nat_traversal_mode(self, code, cbit, clen, *, desc, length, version):
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_resv = self._read_fileng(2)
_mdid = list()
for _ in range((clen - 2) // 2):
_mdid.append(... | [
"def",
"_read_para_nat_traversal_mode",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"if",
"clen",
"%",
"2",
"!=",
"0",
":",
"raise",
"ProtocolError",
"(",
"f'HIPv{version}: [Parano {co... | Read HIP NAT_TRAVERSAL_MODE parameter.
Structure of HIP NAT_TRAVERSAL_MODE parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"NAT_TRAVERSAL_MODE",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L854-L899 |
1,192 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_transaction_pacing | def _read_para_transaction_pacing(self, code, cbit, clen, *, desc, length, version):
"""Read HIP TRANSACTION_PACING parameter.
Structure of HIP TRANSACTION_PACING parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 ... | python | def _read_para_transaction_pacing(self, code, cbit, clen, *, desc, length, version):
if clen != 4:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_data = self._read_unpack(4)
transaction_pacing = dict(
type=desc,
critical=cbit,
... | [
"def",
"_read_para_transaction_pacing",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"if",
"clen",
"!=",
"4",
":",
"raise",
"ProtocolError",
"(",
"f'HIPv{version}: [Parano {code}] invalid f... | Read HIP TRANSACTION_PACING parameter.
Structure of HIP TRANSACTION_PACING parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"TRANSACTION_PACING",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L901-L932 |
1,193 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_encrypted | def _read_para_encrypted(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ENCRYPTED parameter.
Structure of HIP ENCRYPTED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8... | python | def _read_para_encrypted(self, code, cbit, clen, *, desc, length, version):
_resv = self._read_fileng(4)
_data = self._read_fileng(clen-4)
encrypted = dict(
type=desc,
critical=cbit,
length=clen,
raw=_data,
)
_plen = length - clen... | [
"def",
"_read_para_encrypted",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"_resv",
"=",
"self",
".",
"_read_fileng",
"(",
"4",
")",
"_data",
"=",
"self",
".",
"_read_fileng",
"(... | Read HIP ENCRYPTED parameter.
Structure of HIP ENCRYPTED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | [
"Read",
"HIP",
"ENCRYPTED",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L934-L980 |
1,194 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_host_id | def _read_para_host_id(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HOST_ID parameter.
Structure of HIP HOST_ID parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1... | python | def _read_para_host_id(self, code, cbit, clen, *, desc, length, version):
def _read_host_identifier(length, code):
algorithm = _HI_ALGORITHM.get(code, 'Unassigned')
if algorithm == 'ECDSA':
host_id = dict(
curve=_ECDSA_CURVE.get(self._read_unpack(2)),
... | [
"def",
"_read_para_host_id",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"def",
"_read_host_identifier",
"(",
"length",
",",
"code",
")",
":",
"algorithm",
"=",
"_HI_ALGORITHM",
".",... | Read HIP HOST_ID parameter.
Structure of HIP HOST_ID parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | [
"Read",
"HIP",
"HOST_ID",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L982-L1058 |
1,195 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_hit_suite_list | def _read_para_hit_suite_list(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIT_SUITE_LIST parameter.
Structure of HIP HIT_SUITE_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 ... | python | def _read_para_hit_suite_list(self, code, cbit, clen, *, desc, length, version):
_hsid = list()
for _ in range(clen):
_hsid.append(_HIT_SUITE_ID.get(self._read_unpack(1), 'Unassigned'))
hit_suite_list = dict(
type=desc,
critical=cbit,
length=clen,... | [
"def",
"_read_para_hit_suite_list",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"_hsid",
"=",
"list",
"(",
")",
"for",
"_",
"in",
"range",
"(",
"clen",
")",
":",
"_hsid",
".",
... | Read HIP HIT_SUITE_LIST parameter.
Structure of HIP HIT_SUITE_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"HIT_SUITE_LIST",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1060-L1098 |
1,196 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_cert | def _read_para_cert(self, code, cbit, clen, *, desc, length, version):
"""Read HIP CERT parameter.
Structure of HIP CERT parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
... | python | def _read_para_cert(self, code, cbit, clen, *, desc, length, version):
_ctgp = self._read_unpack(1)
_ctct = self._read_unpack(1)
_ctid = self._read_unpack(1)
_cttp = self._read_unpack(1)
_ctdt = self._read_fileng(clen-4)
cert = dict(
type=desc,
cr... | [
"def",
"_read_para_cert",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"_ctgp",
"=",
"self",
".",
"_read_unpack",
"(",
"1",
")",
"_ctct",
"=",
"self",
".",
"_read_unpack",
"(",
... | Read HIP CERT parameter.
Structure of HIP CERT parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | [
"Read",
"HIP",
"CERT",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1100-L1149 |
1,197 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_notification | def _read_para_notification(self, code, cbit, clen, *, desc, length, version):
"""Read HIP NOTIFICATION parameter.
Structure of HIP NOTIFICATION parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 ... | python | def _read_para_notification(self, code, cbit, clen, *, desc, length, version):
_resv = self._read_fileng(2)
_code = self._read_unpack(2)
_data = self._read_fileng(2)
_type = _NOTIFICATION_TYPE.get(_code)
if _type is None:
if 1 <= _code <= 50:
_type = ... | [
"def",
"_read_para_notification",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"_resv",
"=",
"self",
".",
"_read_fileng",
"(",
"2",
")",
"_code",
"=",
"self",
".",
"_read_unpack",
... | Read HIP NOTIFICATION parameter.
Structure of HIP NOTIFICATION parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"NOTIFICATION",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1151-L1209 |
1,198 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_echo_request_signed | def _read_para_echo_request_signed(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ECHO_REQUEST_SIGNED parameter.
Structure of HIP ECHO_REQUEST_SIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3... | python | def _read_para_echo_request_signed(self, code, cbit, clen, *, desc, length, version):
_data = self._read_fileng(clen)
echo_request_signed = dict(
type=desc,
critical=cbit,
length=clen,
data=_data,
)
_plen = length - clen
if _plen:... | [
"def",
"_read_para_echo_request_signed",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"_data",
"=",
"self",
".",
"_read_fileng",
"(",
"clen",
")",
"echo_request_signed",
"=",
"dict",
... | Read HIP ECHO_REQUEST_SIGNED parameter.
Structure of HIP ECHO_REQUEST_SIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"Read",
"HIP",
"ECHO_REQUEST_SIGNED",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1211-L1243 |
1,199 | JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_reg_failed | def _read_para_reg_failed(self, code, cbit, clen, *, desc, length, version):
"""Read HIP REG_FAILED parameter.
Structure of HIP REG_FAILED parameter [RFC 8003]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 ... | python | def _read_para_reg_failed(self, code, cbit, clen, *, desc, length, version):
_life = collections.namedtuple('Lifetime', ('min', 'max'))
_mint = self._read_unpack(1)
_maxt = self._read_unpack(1)
_type = list()
for _ in range(clen-2):
_code = self._read_unpack(1)
... | [
"def",
"_read_para_reg_failed",
"(",
"self",
",",
"code",
",",
"cbit",
",",
"clen",
",",
"*",
",",
"desc",
",",
"length",
",",
"version",
")",
":",
"_life",
"=",
"collections",
".",
"namedtuple",
"(",
"'Lifetime'",
",",
"(",
"'min'",
",",
"'max'",
")",... | Read HIP REG_FAILED parameter.
Structure of HIP REG_FAILED parameter [RFC 8003]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | [
"Read",
"HIP",
"REG_FAILED",
"parameter",
"."
] | c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1419-L1475 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.