repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
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'):
""" 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):
... | [
"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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/utils.py#L32-L45 |
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):
""" Check for the signature is correct. """
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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/utils.py#L48-L50 |
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):
""" 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)) | [
"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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/utils.py#L53-L58 |
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):
"""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 ... | [
"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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/utils.py#L183-L190 |
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):
"""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!"
... | [
"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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L17-L40 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L95-L112 |
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):
"""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):
... | [
"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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L115-L136 |
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):
"""Register view to handler."""
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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L139-L143 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L145-L152 |
klen/muffin | muffin/handler.py | Handler.make_response | async def make_response(self, request, response):
"""Convert a handler result to web response."""
while iscoroutine(response):
response = await response
if isinstance(response, StreamResponse):
return response
if isinstance(response, str):
return Res... | python | async def make_response(self, request, response):
"""Convert a handler result to web response."""
while iscoroutine(response):
response = await response
if isinstance(response, StreamResponse):
return response
if isinstance(response, str):
return Res... | [
"async",
"def",
"make_response",
"(",
"self",
",",
"request",
",",
"response",
")",
":",
"while",
"iscoroutine",
"(",
"response",
")",
":",
"response",
"=",
"await",
"response",
"if",
"isinstance",
"(",
"response",
",",
"StreamResponse",
")",
":",
"return",
... | Convert a handler result to web response. | [
"Convert",
"a",
"handler",
"result",
"to",
"web",
"response",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L156-L170 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/handler.py#L172-L187 |
klen/muffin | muffin/plugins.py | BasePlugin.setup | def setup(self, app):
"""Initialize the plugin.
Fill the plugin's options from application.
"""
self.app = app
for name, ptype in self.dependencies.items():
if name not in app.ps or not isinstance(app.ps[name], ptype):
raise PluginException(
... | python | def setup(self, app):
"""Initialize the plugin.
Fill the plugin's options from application.
"""
self.app = app
for name, ptype in self.dependencies.items():
if name not in app.ps or not isinstance(app.ps[name], ptype):
raise PluginException(
... | [
"def",
"setup",
"(",
"self",
",",
"app",
")",
":",
"self",
".",
"app",
"=",
"app",
"for",
"name",
",",
"ptype",
"in",
"self",
".",
"dependencies",
".",
"items",
"(",
")",
":",
"if",
"name",
"not",
"in",
"app",
".",
"ps",
"or",
"not",
"isinstance"... | Initialize the plugin.
Fill the plugin's options from application. | [
"Initialize",
"the",
"plugin",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/plugins.py#L60-L75 |
klen/muffin | muffin/app.py | _exc_middleware_factory | def _exc_middleware_factory(app):
"""Handle exceptions.
Route exceptions to handlers if they are registered in application.
"""
@web.middleware
async def middleware(request, handler):
try:
return await handler(request)
except Exception as exc:
for cls in typ... | python | def _exc_middleware_factory(app):
"""Handle exceptions.
Route exceptions to handlers if they are registered in application.
"""
@web.middleware
async def middleware(request, handler):
try:
return await handler(request)
except Exception as exc:
for cls in typ... | [
"def",
"_exc_middleware_factory",
"(",
"app",
")",
":",
"@",
"web",
".",
"middleware",
"async",
"def",
"middleware",
"(",
"request",
",",
"handler",
")",
":",
"try",
":",
"return",
"await",
"handler",
"(",
"request",
")",
"except",
"Exception",
"as",
"exc"... | Handle exceptions.
Route exceptions to handlers if they are registered in application. | [
"Handle",
"exceptions",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/app.py#L266-L284 |
klen/muffin | muffin/app.py | BaseApplication.register | def register(self, *paths, methods=None, name=None, handler=None):
"""Register function/coroutine/muffin.Handler with the application.
Usage example:
.. code-block:: python
@app.register('/hello')
def hello(request):
return 'Hello World!'
"""
... | python | def register(self, *paths, methods=None, name=None, handler=None):
"""Register function/coroutine/muffin.Handler with the application.
Usage example:
.. code-block:: python
@app.register('/hello')
def hello(request):
return 'Hello World!'
"""
... | [
"def",
"register",
"(",
"self",
",",
"*",
"paths",
",",
"methods",
"=",
"None",
",",
"name",
"=",
"None",
",",
"handler",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"methods",
",",
"str",
")",
":",
"methods",
"=",
"[",
"methods",
"]",
"def",
... | Register function/coroutine/muffin.Handler with the application.
Usage example:
.. code-block:: python
@app.register('/hello')
def hello(request):
return 'Hello World!' | [
"Register",
"function",
"/",
"coroutine",
"/",
"muffin",
".",
"Handler",
"with",
"the",
"application",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/app.py#L29-L76 |
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):
"""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:
... | [
"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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/app.py#L162-L192 |
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):
"""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)
... | [
"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",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/app.py#L194-L231 |
klen/muffin | muffin/app.py | Application.startup | async def startup(self):
"""Start the application.
Support for start-callbacks and lock the application's configuration and plugins.
"""
if self.frozen:
return False
if self._error_handlers:
self.middlewares.append(_exc_middleware_factory(self))
... | python | async def startup(self):
"""Start the application.
Support for start-callbacks and lock the application's configuration and plugins.
"""
if self.frozen:
return False
if self._error_handlers:
self.middlewares.append(_exc_middleware_factory(self))
... | [
"async",
"def",
"startup",
"(",
"self",
")",
":",
"if",
"self",
".",
"frozen",
":",
"return",
"False",
"if",
"self",
".",
"_error_handlers",
":",
"self",
".",
"middlewares",
".",
"append",
"(",
"_exc_middleware_factory",
"(",
"self",
")",
")",
"# Register ... | Start the application.
Support for start-callbacks and lock the application's configuration and plugins. | [
"Start",
"the",
"application",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/app.py#L233-L248 |
klen/muffin | muffin/app.py | Application.middleware | def middleware(self, func):
"""Register given middleware (v1)."""
self.middlewares.append(web.middleware(to_coroutine(func))) | python | def middleware(self, func):
"""Register given middleware (v1)."""
self.middlewares.append(web.middleware(to_coroutine(func))) | [
"def",
"middleware",
"(",
"self",
",",
"func",
")",
":",
"self",
".",
"middlewares",
".",
"append",
"(",
"web",
".",
"middleware",
"(",
"to_coroutine",
"(",
"func",
")",
")",
")"
] | Register given middleware (v1). | [
"Register",
"given",
"middleware",
"(",
"v1",
")",
"."
] | train | https://github.com/klen/muffin/blob/7bc891e174e08b62d1ae232b5d45f8cd8bc82112/muffin/app.py#L261-L263 |
kovidgoyal/html5-parser | src/html5_parser/__init__.py | parse | def parse(
html,
transport_encoding=None,
namespace_elements=False,
treebuilder='lxml',
fallback_encoding=None,
keep_doctype=True,
maybe_xhtml=False,
return_root=True,
line_number_attr=None,
sanitize_names=True,
stack_size=16 * 1024
):
'''
Parse the specified :attr:`h... | python | def parse(
html,
transport_encoding=None,
namespace_elements=False,
treebuilder='lxml',
fallback_encoding=None,
keep_doctype=True,
maybe_xhtml=False,
return_root=True,
line_number_attr=None,
sanitize_names=True,
stack_size=16 * 1024
):
'''
Parse the specified :attr:`h... | [
"def",
"parse",
"(",
"html",
",",
"transport_encoding",
"=",
"None",
",",
"namespace_elements",
"=",
"False",
",",
"treebuilder",
"=",
"'lxml'",
",",
"fallback_encoding",
"=",
"None",
",",
"keep_doctype",
"=",
"True",
",",
"maybe_xhtml",
"=",
"False",
",",
"... | Parse the specified :attr:`html` and return the parsed representation.
:param html: The HTML to be parsed. Can be either bytes or a unicode string.
:param transport_encoding: If specified, assume the passed in bytes are in this encoding.
Ignored if :attr:`html` is unicode.
:param namespace_elemen... | [
"Parse",
"the",
"specified",
":",
"attr",
":",
"html",
"and",
"return",
"the",
"parsed",
"representation",
"."
] | train | https://github.com/kovidgoyal/html5-parser/blob/65ce451652cbab71ed86a9b53ac8c8906f2a2d67/src/html5_parser/__init__.py#L121-L207 |
jamesturk/django-honeypot | honeypot/decorators.py | honeypot_equals | def honeypot_equals(val):
"""
Default verifier used if HONEYPOT_VERIFIER is not specified.
Ensures val == HONEYPOT_VALUE or HONEYPOT_VALUE() if it's a callable.
"""
expected = getattr(settings, 'HONEYPOT_VALUE', '')
if callable(expected):
expected = expected()
return val == e... | python | def honeypot_equals(val):
"""
Default verifier used if HONEYPOT_VERIFIER is not specified.
Ensures val == HONEYPOT_VALUE or HONEYPOT_VALUE() if it's a callable.
"""
expected = getattr(settings, 'HONEYPOT_VALUE', '')
if callable(expected):
expected = expected()
return val == e... | [
"def",
"honeypot_equals",
"(",
"val",
")",
":",
"expected",
"=",
"getattr",
"(",
"settings",
",",
"'HONEYPOT_VALUE'",
",",
"''",
")",
"if",
"callable",
"(",
"expected",
")",
":",
"expected",
"=",
"expected",
"(",
")",
"return",
"val",
"==",
"expected"
] | Default verifier used if HONEYPOT_VERIFIER is not specified.
Ensures val == HONEYPOT_VALUE or HONEYPOT_VALUE() if it's a callable. | [
"Default",
"verifier",
"used",
"if",
"HONEYPOT_VERIFIER",
"is",
"not",
"specified",
".",
"Ensures",
"val",
"==",
"HONEYPOT_VALUE",
"or",
"HONEYPOT_VALUE",
"()",
"if",
"it",
"s",
"a",
"callable",
"."
] | train | https://github.com/jamesturk/django-honeypot/blob/4b149bfca81828eaf418b5a6854e670d156f5e35/honeypot/decorators.py#L9-L17 |
jamesturk/django-honeypot | honeypot/decorators.py | verify_honeypot_value | def verify_honeypot_value(request, field_name):
"""
Verify that request.POST[field_name] is a valid honeypot.
Ensures that the field exists and passes verification according to
HONEYPOT_VERIFIER.
"""
verifier = getattr(settings, 'HONEYPOT_VERIFIER', honeypot_equals)
if request.m... | python | def verify_honeypot_value(request, field_name):
"""
Verify that request.POST[field_name] is a valid honeypot.
Ensures that the field exists and passes verification according to
HONEYPOT_VERIFIER.
"""
verifier = getattr(settings, 'HONEYPOT_VERIFIER', honeypot_equals)
if request.m... | [
"def",
"verify_honeypot_value",
"(",
"request",
",",
"field_name",
")",
":",
"verifier",
"=",
"getattr",
"(",
"settings",
",",
"'HONEYPOT_VERIFIER'",
",",
"honeypot_equals",
")",
"if",
"request",
".",
"method",
"==",
"'POST'",
":",
"field",
"=",
"field_name",
... | Verify that request.POST[field_name] is a valid honeypot.
Ensures that the field exists and passes verification according to
HONEYPOT_VERIFIER. | [
"Verify",
"that",
"request",
".",
"POST",
"[",
"field_name",
"]",
"is",
"a",
"valid",
"honeypot",
"."
] | train | https://github.com/jamesturk/django-honeypot/blob/4b149bfca81828eaf418b5a6854e670d156f5e35/honeypot/decorators.py#L20-L33 |
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):
"""
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):
... | [
"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",
"."
] | train | https://github.com/jamesturk/django-honeypot/blob/4b149bfca81828eaf418b5a6854e670d156f5e35/honeypot/decorators.py#L36-L60 |
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):
"""
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... | [
"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"
] | train | https://github.com/jamesturk/django-honeypot/blob/4b149bfca81828eaf418b5a6854e670d156f5e35/honeypot/decorators.py#L63-L71 |
jamesturk/django-honeypot | honeypot/templatetags/honeypot.py | render_honeypot_field | def render_honeypot_field(field_name=None):
"""
Renders honeypot field named field_name (defaults to HONEYPOT_FIELD_NAME).
"""
if not field_name:
field_name = settings.HONEYPOT_FIELD_NAME
value = getattr(settings, 'HONEYPOT_VALUE', '')
if callable(value):
value = value()
... | python | def render_honeypot_field(field_name=None):
"""
Renders honeypot field named field_name (defaults to HONEYPOT_FIELD_NAME).
"""
if not field_name:
field_name = settings.HONEYPOT_FIELD_NAME
value = getattr(settings, 'HONEYPOT_VALUE', '')
if callable(value):
value = value()
... | [
"def",
"render_honeypot_field",
"(",
"field_name",
"=",
"None",
")",
":",
"if",
"not",
"field_name",
":",
"field_name",
"=",
"settings",
".",
"HONEYPOT_FIELD_NAME",
"value",
"=",
"getattr",
"(",
"settings",
",",
"'HONEYPOT_VALUE'",
",",
"''",
")",
"if",
"calla... | Renders honeypot field named field_name (defaults to HONEYPOT_FIELD_NAME). | [
"Renders",
"honeypot",
"field",
"named",
"field_name",
"(",
"defaults",
"to",
"HONEYPOT_FIELD_NAME",
")",
"."
] | train | https://github.com/jamesturk/django-honeypot/blob/4b149bfca81828eaf418b5a6854e670d156f5e35/honeypot/templatetags/honeypot.py#L8-L17 |
jongracecox/anybadge | anybadge.py | parse_args | def parse_args():
"""Parse the command line arguments."""
import argparse
import textwrap
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''\
Command line utility to generate .svg badges.
This utili... | python | def parse_args():
"""Parse the command line arguments."""
import argparse
import textwrap
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''\
Command line utility to generate .svg badges.
This utili... | [
"def",
"parse_args",
"(",
")",
":",
"import",
"argparse",
"import",
"textwrap",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"formatter_class",
"=",
"argparse",
".",
"RawDescriptionHelpFormatter",
",",
"description",
"=",
"textwrap",
".",
"dedent",
"(",
... | Parse the command line arguments. | [
"Parse",
"the",
"command",
"line",
"arguments",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L360-L437 |
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():
"""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... | [
"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",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L440-L478 |
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):
"""Identify whether the value text is an int."""
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",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L183-L191 |
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 the badge font width."""
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",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L214-L216 |
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):
"""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)) | [
"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",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L219-L222 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L245-L254 |
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):
"""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:
... | [
"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",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L257-L280 |
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 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_... | [
"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",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L291-L301 |
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):
"""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:
... | [
"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",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L304-L330 |
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):
"""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.... | [
"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",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge.py#L340-L357 |
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():
"""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... | [
"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",
"."
] | train | https://github.com/jongracecox/anybadge/blob/1850a9580697e019c601d09f5de490056fed2bab/anybadge_server.py#L129-L156 |
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):
"""
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... | [
"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"
] | train | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L8-L29 |
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 the attribute name identifier
"""
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"
] | train | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L32-L36 |
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):
"""
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 | [
"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"
] | train | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L39-L50 |
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 methods associated with a given class
"""
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"
] | train | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L74-L82 |
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 class variables associated with a given class
"""
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"
] | train | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L85-L94 |
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):
"""
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... | [
"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"
] | train | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L97-L117 |
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 classes associated with a given module
"""
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"
] | train | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/parser.py#L149-L157 |
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 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
] | [
"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"
] | train | https://github.com/mschwager/cohesion/blob/b242ad59770940f3a0904931f27755ede009f491/lib/cohesion/filesystem.py#L21-L29 |
JarryShaw/PyPCAPKit | src/const/ipv6/seed_id.py | SeedID.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return SeedID(key)
if key not in SeedID._member_map_:
extend_enum(SeedID, key, default)
return SeedID[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return SeedID(key)
if key not in SeedID._member_map_:
extend_enum(SeedID, key, default)
return SeedID[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"SeedID",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"SeedID",
".",
"_member_map_",
":",
"extend_enum",
"(",
"SeedID"... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/ipv6/seed_id.py#L18-L24 |
JarryShaw/PyPCAPKit | src/const/vlan/priority_level.py | PriorityLevel.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return PriorityLevel(key)
if key not in PriorityLevel._member_map_:
extend_enum(PriorityLevel, key, default)
return PriorityLevel[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return PriorityLevel(key)
if key not in PriorityLevel._member_map_:
extend_enum(PriorityLevel, key, default)
return PriorityLevel[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"PriorityLevel",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"PriorityLevel",
".",
"_member_map_",
":",
"extend_enum",
"... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/vlan/priority_level.py#L22-L28 |
JarryShaw/PyPCAPKit | src/const/ipv4/tos_thr.py | TOS_THR.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TOS_THR(key)
if key not in TOS_THR._member_map_:
extend_enum(TOS_THR, key, default)
return TOS_THR[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TOS_THR(key)
if key not in TOS_THR._member_map_:
extend_enum(TOS_THR, key, default)
return TOS_THR[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"TOS_THR",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"TOS_THR",
".",
"_member_map_",
":",
"extend_enum",
"(",
"TOS_T... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/ipv4/tos_thr.py#L16-L22 |
JarryShaw/PyPCAPKit | src/const/ipv4/tos_thr.py | TOS_THR._missing_ | def _missing_(cls, value):
"""Lookup function used when value is not found."""
if not (isinstance(value, int) and 0 <= value <= 1):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
su... | python | def _missing_(cls, value):
"""Lookup function used when value is not found."""
if not (isinstance(value, int) and 0 <= value <= 1):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
su... | [
"def",
"_missing_",
"(",
"cls",
",",
"value",
")",
":",
"if",
"not",
"(",
"isinstance",
"(",
"value",
",",
"int",
")",
"and",
"0",
"<=",
"value",
"<=",
"1",
")",
":",
"raise",
"ValueError",
"(",
"'%r is not a valid %s'",
"%",
"(",
"value",
",",
"cls"... | Lookup function used when value is not found. | [
"Lookup",
"function",
"used",
"when",
"value",
"is",
"not",
"found",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/ipv4/tos_thr.py#L25-L31 |
JarryShaw/PyPCAPKit | src/const/hip/registration.py | Registration.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Registration(key)
if key not in Registration._member_map_:
extend_enum(Registration, key, default)
return Registration[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Registration(key)
if key not in Registration._member_map_:
extend_enum(Registration, key, default)
return Registration[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"Registration",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"Registration",
".",
"_member_map_",
":",
"extend_enum",
"("... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/registration.py#L17-L23 |
JarryShaw/PyPCAPKit | src/const/http/error_code.py | ErrorCode.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return ErrorCode(key)
if key not in ErrorCode._member_map_:
extend_enum(ErrorCode, key, default)
return ErrorCode[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return ErrorCode(key)
if key not in ErrorCode._member_map_:
extend_enum(ErrorCode, key, default)
return ErrorCode[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"ErrorCode",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"ErrorCode",
".",
"_member_map_",
":",
"extend_enum",
"(",
"E... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/http/error_code.py#L28-L34 |
JarryShaw/PyPCAPKit | src/corekit/protochain.py | _AliasList.count | def count(self, value):
"""S.count(value) -> integer -- return number of occurrences of value"""
from pcapkit.protocols.protocol import Protocol
try:
flag = issubclass(value, Protocol)
except TypeError:
flag = issubclass(type(value), Protocol)
if flag or i... | python | def count(self, value):
"""S.count(value) -> integer -- return number of occurrences of value"""
from pcapkit.protocols.protocol import Protocol
try:
flag = issubclass(value, Protocol)
except TypeError:
flag = issubclass(type(value), Protocol)
if flag or i... | [
"def",
"count",
"(",
"self",
",",
"value",
")",
":",
"from",
"pcapkit",
".",
"protocols",
".",
"protocol",
"import",
"Protocol",
"try",
":",
"flag",
"=",
"issubclass",
"(",
"value",
",",
"Protocol",
")",
"except",
"TypeError",
":",
"flag",
"=",
"issubcla... | S.count(value) -> integer -- return number of occurrences of value | [
"S",
".",
"count",
"(",
"value",
")",
"-",
">",
"integer",
"--",
"return",
"number",
"of",
"occurrences",
"of",
"value"
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/corekit/protochain.py#L116-L130 |
JarryShaw/PyPCAPKit | src/corekit/protochain.py | _AliasList.index | def index(self, value, start=0, stop=None):
"""S.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but
recommended.
"""
if start is not None an... | python | def index(self, value, start=0, stop=None):
"""S.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but
recommended.
"""
if start is not None an... | [
"def",
"index",
"(",
"self",
",",
"value",
",",
"start",
"=",
"0",
",",
"stop",
"=",
"None",
")",
":",
"if",
"start",
"is",
"not",
"None",
"and",
"start",
"<",
"0",
":",
"start",
"=",
"max",
"(",
"len",
"(",
"self",
")",
"+",
"start",
",",
"0... | S.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but
recommended. | [
"S",
".",
"index",
"(",
"value",
"[",
"start",
"[",
"stop",
"]]",
")",
"-",
">",
"integer",
"--",
"return",
"first",
"index",
"of",
"value",
".",
"Raises",
"ValueError",
"if",
"the",
"value",
"is",
"not",
"present",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/corekit/protochain.py#L133-L168 |
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 first index of value."""
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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/corekit/protochain.py#L213-L215 |
JarryShaw/PyPCAPKit | src/const/hip/nat_traversal.py | NAT_Traversal.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return NAT_Traversal(key)
if key not in NAT_Traversal._member_map_:
extend_enum(NAT_Traversal, key, default)
return NAT_Traversal[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return NAT_Traversal(key)
if key not in NAT_Traversal._member_map_:
extend_enum(NAT_Traversal, key, default)
return NAT_Traversal[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"NAT_Traversal",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"NAT_Traversal",
".",
"_member_map_",
":",
"extend_enum",
"... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/nat_traversal.py#L17-L23 |
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):
"""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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/ospf.py#L95-L155 |
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):
"""Read router and area IDs."""
_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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/ospf.py#L172-L176 |
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):
"""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 ... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/ospf.py#L178-L209 |
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):
"""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, {... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L36-L43 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L46-L53 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L56-L63 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L66-L73 |
JarryShaw/PyPCAPKit | src/utilities/validations.py | bytes_check | def bytes_check(*args, func=None):
"""Check if arguments are bytes type."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (bytes, collections.abc.ByteString)):
name = type(var).__name__
raise BytesError(
f'Function {func} expecte... | python | def bytes_check(*args, func=None):
"""Check if arguments are bytes type."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, (bytes, collections.abc.ByteString)):
name = type(var).__name__
raise BytesError(
f'Function {func} expecte... | [
"def",
"bytes_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",... | Check if arguments are bytes type. | [
"Check",
"if",
"arguments",
"are",
"bytes",
"type",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L76-L83 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L86-L93 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L96-L103 |
JarryShaw/PyPCAPKit | src/utilities/validations.py | bool_check | def bool_check(*args, func=None):
"""Check if arguments are bytes type."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, bool):
name = type(var).__name__
raise BoolError(
f'Function {func} expected bool, {name} got instead.') | python | def bool_check(*args, func=None):
"""Check if arguments are bytes type."""
func = func or inspect.stack()[2][3]
for var in args:
if not isinstance(var, bool):
name = type(var).__name__
raise BoolError(
f'Function {func} expected bool, {name} got instead.') | [
"def",
"bool_check",
"(",
"*",
"args",
",",
"func",
"=",
"None",
")",
":",
"func",
"=",
"func",
"or",
"inspect",
".",
"stack",
"(",
")",
"[",
"2",
"]",
"[",
"3",
"]",
"for",
"var",
"in",
"args",
":",
"if",
"not",
"isinstance",
"(",
"var",
",",
... | Check if arguments are bytes type. | [
"Check",
"if",
"arguments",
"are",
"bytes",
"type",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L106-L113 |
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):
"""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'... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L116-L123 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L126-L133 |
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):
"""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 ... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L136-L143 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L146-L153 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L156-L165 |
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):
"""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, {... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L168-L175 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L178-L185 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L188-L196 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L199-L210 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/validations.py#L226-L236 |
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):
"""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)
... | [
"def",
"fetch",
"(",
"self",
")",
":",
"if",
"self",
".",
"_newflg",
":",
"self",
".",
"_newflg",
"=",
"False",
"temp_dtgram",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"_dtgram",
")",
"for",
"(",
"bufid",
",",
"buffer",
")",
"in",
"self",
".... | Fetch datagram. | [
"Fetch",
"datagram",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/reassembly/reassembly.py#L108-L116 |
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):
"""Return datagram index."""
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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/reassembly/reassembly.py#L119-L125 |
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):
"""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(... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/reassembly/reassembly.py#L128-L139 |
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):
"""Read Mobility Header.
Structure of MH header [RFC 6275]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Proto | Header Len | MH Type | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/mh.py#L91-L139 |
JarryShaw/PyPCAPKit | src/const/hip/di.py | DI.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return DI(key)
if key not in DI._member_map_:
extend_enum(DI, key, default)
return DI[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return DI(key)
if key not in DI._member_map_:
extend_enum(DI, key, default)
return DI[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"DI",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"DI",
".",
"_member_map_",
":",
"extend_enum",
"(",
"DI",
",",
"... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/di.py#L17-L23 |
JarryShaw/PyPCAPKit | src/const/hip/certificate.py | Certificate.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Certificate(key)
if key not in Certificate._member_map_:
extend_enum(Certificate, key, default)
return Certificate[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Certificate(key)
if key not in Certificate._member_map_:
extend_enum(Certificate, key, default)
return Certificate[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"Certificate",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"Certificate",
".",
"_member_map_",
":",
"extend_enum",
"(",
... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/certificate.py#L23-L29 |
JarryShaw/PyPCAPKit | src/protocols/transport/udp.py | UDP.read_udp | def read_udp(self, length):
"""Read User Datagram Protocol (UDP).
Structure of UDP header [RFC 768]:
0 7 8 15 16 23 24 31
+--------+--------+--------+--------+
| Source | Destination |
| Port | Port |
... | python | def read_udp(self, length):
"""Read User Datagram Protocol (UDP).
Structure of UDP header [RFC 768]:
0 7 8 15 16 23 24 31
+--------+--------+--------+--------+
| Source | Destination |
| Port | Port |
... | [
"def",
"read_udp",
"(",
"self",
",",
"length",
")",
":",
"if",
"length",
"is",
"None",
":",
"length",
"=",
"len",
"(",
"self",
")",
"_srcp",
"=",
"self",
".",
"_read_unpack",
"(",
"2",
")",
"_dstp",
"=",
"self",
".",
"_read_unpack",
"(",
"2",
")",
... | Read User Datagram Protocol (UDP).
Structure of UDP header [RFC 768]:
0 7 8 15 16 23 24 31
+--------+--------+--------+--------+
| Source | Destination |
| Port | Port |
+--------+--------+--------+--... | [
"Read",
"User",
"Datagram",
"Protocol",
"(",
"UDP",
")",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/udp.py#L87-L128 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipx.py#L93-L129 |
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):
"""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
... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipx.py#L146-L179 |
JarryShaw/PyPCAPKit | src/const/hip/group.py | Group.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Group(key)
if key not in Group._member_map_:
extend_enum(Group, key, default)
return Group[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Group(key)
if key not in Group._member_map_:
extend_enum(Group, key, default)
return Group[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"Group",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"Group",
".",
"_member_map_",
":",
"extend_enum",
"(",
"Group",
... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/group.py#L26-L32 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/arp.py#L116-L180 |
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):
"""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... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/arp.py#L201-L217 |
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):
"""Resolve IP address according to protocol.
Positional arguments:
* length -- int, protocol address length
* ptype -- int, protocol type
Returns:
* str -- IP address
"""
# if ptype == '0800': ... | [
"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",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/arp.py#L219-L278 |
JarryShaw/PyPCAPKit | src/const/http/setting.py | Setting.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Setting(key)
if key not in Setting._member_map_:
extend_enum(Setting, key, default)
return Setting[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Setting(key)
if key not in Setting._member_map_:
extend_enum(Setting, key, default)
return Setting[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"Setting",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"Setting",
".",
"_member_map_",
":",
"extend_enum",
"(",
"Setti... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/http/setting.py#L23-L29 |
JarryShaw/PyPCAPKit | src/const/hip/transport.py | Transport.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Transport(key)
if key not in Transport._member_map_:
extend_enum(Transport, key, default)
return Transport[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Transport(key)
if key not in Transport._member_map_:
extend_enum(Transport, key, default)
return Transport[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"Transport",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"Transport",
".",
"_member_map_",
":",
"extend_enum",
"(",
"T... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/transport.py#L18-L24 |
JarryShaw/PyPCAPKit | src/const/ipv4/tos_del.py | TOS_DEL.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TOS_DEL(key)
if key not in TOS_DEL._member_map_:
extend_enum(TOS_DEL, key, default)
return TOS_DEL[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TOS_DEL(key)
if key not in TOS_DEL._member_map_:
extend_enum(TOS_DEL, key, default)
return TOS_DEL[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"TOS_DEL",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"TOS_DEL",
".",
"_member_map_",
":",
"extend_enum",
"(",
"TOS_D... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/ipv4/tos_del.py#L16-L22 |
JarryShaw/PyPCAPKit | src/const/misc/ethertype.py | EtherType.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return EtherType(key)
if key not in EtherType._member_map_:
extend_enum(EtherType, key, default)
return EtherType[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return EtherType(key)
if key not in EtherType._member_map_:
extend_enum(EtherType, key, default)
return EtherType[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"EtherType",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"EtherType",
".",
"_member_map_",
":",
"extend_enum",
"(",
"E... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/misc/ethertype.py#L175-L181 |
JarryShaw/PyPCAPKit | src/const/misc/ethertype.py | EtherType._missing_ | def _missing_(cls, value):
"""Lookup function used when value is not found."""
if not (isinstance(value, int) and 0x0000 <= value <= 0xFFFF):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
if 0x0000 <= value <= 0x05DC:
# [Neil_Sembower]
exten... | python | def _missing_(cls, value):
"""Lookup function used when value is not found."""
if not (isinstance(value, int) and 0x0000 <= value <= 0xFFFF):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
if 0x0000 <= value <= 0x05DC:
# [Neil_Sembower]
exten... | [
"def",
"_missing_",
"(",
"cls",
",",
"value",
")",
":",
"if",
"not",
"(",
"isinstance",
"(",
"value",
",",
"int",
")",
"and",
"0x0000",
"<=",
"value",
"<=",
"0xFFFF",
")",
":",
"raise",
"ValueError",
"(",
"'%r is not a valid %s'",
"%",
"(",
"value",
",... | Lookup function used when value is not found. | [
"Lookup",
"function",
"used",
"when",
"value",
"is",
"not",
"found",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/misc/ethertype.py#L184-L412 |
JarryShaw/PyPCAPKit | src/const/ipv4/tos_ecn.py | TOS_ECN.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TOS_ECN(key)
if key not in TOS_ECN._member_map_:
extend_enum(TOS_ECN, key, default)
return TOS_ECN[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TOS_ECN(key)
if key not in TOS_ECN._member_map_:
extend_enum(TOS_ECN, key, default)
return TOS_ECN[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"TOS_ECN",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"TOS_ECN",
".",
"_member_map_",
":",
"extend_enum",
"(",
"TOS_E... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/ipv4/tos_ecn.py#L18-L24 |
JarryShaw/PyPCAPKit | src/const/http/frame.py | Frame.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Frame(key)
if key not in Frame._member_map_:
extend_enum(Frame, key, default)
return Frame[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Frame(key)
if key not in Frame._member_map_:
extend_enum(Frame, key, default)
return Frame[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"Frame",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"Frame",
".",
"_member_map_",
":",
"extend_enum",
"(",
"Frame",
... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/http/frame.py#L27-L33 |
JarryShaw/PyPCAPKit | src/const/http/frame.py | Frame._missing_ | def _missing_(cls, value):
"""Lookup function used when value is not found."""
if not (isinstance(value, int) and 0x00 <= value <= 0xFF):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
if 0x0D <= value <= 0xEF:
extend_enum(cls, 'Unassigned [0x%s]' % hex(... | python | def _missing_(cls, value):
"""Lookup function used when value is not found."""
if not (isinstance(value, int) and 0x00 <= value <= 0xFF):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
if 0x0D <= value <= 0xEF:
extend_enum(cls, 'Unassigned [0x%s]' % hex(... | [
"def",
"_missing_",
"(",
"cls",
",",
"value",
")",
":",
"if",
"not",
"(",
"isinstance",
"(",
"value",
",",
"int",
")",
"and",
"0x00",
"<=",
"value",
"<=",
"0xFF",
")",
":",
"raise",
"ValueError",
"(",
"'%r is not a valid %s'",
"%",
"(",
"value",
",",
... | Lookup function used when value is not found. | [
"Lookup",
"function",
"used",
"when",
"value",
"is",
"not",
"found",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/http/frame.py#L36-L47 |
JarryShaw/PyPCAPKit | src/toolkit/default.py | ipv4_reassembly | def ipv4_reassembly(frame):
"""Make data for IPv4 reassembly."""
if 'IPv4' in frame:
ipv4 = frame['IPv4'].info
if ipv4.flags.df: # dismiss not fragmented frame
return False, None
data = dict(
bufid=(
ipv4.src, ... | python | def ipv4_reassembly(frame):
"""Make data for IPv4 reassembly."""
if 'IPv4' in frame:
ipv4 = frame['IPv4'].info
if ipv4.flags.df: # dismiss not fragmented frame
return False, None
data = dict(
bufid=(
ipv4.src, ... | [
"def",
"ipv4_reassembly",
"(",
"frame",
")",
":",
"if",
"'IPv4'",
"in",
"frame",
":",
"ipv4",
"=",
"frame",
"[",
"'IPv4'",
"]",
".",
"info",
"if",
"ipv4",
".",
"flags",
".",
"df",
":",
"# dismiss not fragmented frame",
"return",
"False",
",",
"None",
"da... | Make data for IPv4 reassembly. | [
"Make",
"data",
"for",
"IPv4",
"reassembly",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/toolkit/default.py#L12-L34 |
JarryShaw/PyPCAPKit | src/toolkit/default.py | ipv6_reassembly | def ipv6_reassembly(frame):
"""Make data for IPv6 reassembly."""
if 'IPv6' in frame:
ipv6 = frame['IPv6'].info
if 'frag' not in ipv6: # dismiss not fragmented frame
return False, None
data = dict(
bufid=(
ipv6.src, ... | python | def ipv6_reassembly(frame):
"""Make data for IPv6 reassembly."""
if 'IPv6' in frame:
ipv6 = frame['IPv6'].info
if 'frag' not in ipv6: # dismiss not fragmented frame
return False, None
data = dict(
bufid=(
ipv6.src, ... | [
"def",
"ipv6_reassembly",
"(",
"frame",
")",
":",
"if",
"'IPv6'",
"in",
"frame",
":",
"ipv6",
"=",
"frame",
"[",
"'IPv6'",
"]",
".",
"info",
"if",
"'frag'",
"not",
"in",
"ipv6",
":",
"# dismiss not fragmented frame",
"return",
"False",
",",
"None",
"data",... | Make data for IPv6 reassembly. | [
"Make",
"data",
"for",
"IPv6",
"reassembly",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/toolkit/default.py#L37-L59 |
JarryShaw/PyPCAPKit | src/toolkit/default.py | tcp_reassembly | def tcp_reassembly(frame):
"""Make data for TCP reassembly."""
if 'TCP' in frame:
ip = (frame['IPv4'] if 'IPv4' in frame else frame['IPv6']).info
tcp = frame['TCP'].info
data = dict(
bufid=(
ip.src, # source IP address
... | python | def tcp_reassembly(frame):
"""Make data for TCP reassembly."""
if 'TCP' in frame:
ip = (frame['IPv4'] if 'IPv4' in frame else frame['IPv6']).info
tcp = frame['TCP'].info
data = dict(
bufid=(
ip.src, # source IP address
... | [
"def",
"tcp_reassembly",
"(",
"frame",
")",
":",
"if",
"'TCP'",
"in",
"frame",
":",
"ip",
"=",
"(",
"frame",
"[",
"'IPv4'",
"]",
"if",
"'IPv4'",
"in",
"frame",
"else",
"frame",
"[",
"'IPv6'",
"]",
")",
".",
"info",
"tcp",
"=",
"frame",
"[",
"'TCP'"... | Make data for TCP reassembly. | [
"Make",
"data",
"for",
"TCP",
"reassembly",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/toolkit/default.py#L62-L87 |
JarryShaw/PyPCAPKit | src/toolkit/default.py | tcp_traceflow | def tcp_traceflow(frame, *, data_link):
"""Trace packet flow for TCP."""
if 'TCP' in frame:
ip = (frame['IPv4'] if 'IPv4' in frame else frame['IPv6']).info
tcp = frame['TCP'].info
data = dict(
protocol=data_link, # data link type from global header
... | python | def tcp_traceflow(frame, *, data_link):
"""Trace packet flow for TCP."""
if 'TCP' in frame:
ip = (frame['IPv4'] if 'IPv4' in frame else frame['IPv6']).info
tcp = frame['TCP'].info
data = dict(
protocol=data_link, # data link type from global header
... | [
"def",
"tcp_traceflow",
"(",
"frame",
",",
"*",
",",
"data_link",
")",
":",
"if",
"'TCP'",
"in",
"frame",
":",
"ip",
"=",
"(",
"frame",
"[",
"'IPv4'",
"]",
"if",
"'IPv4'",
"in",
"frame",
"else",
"frame",
"[",
"'IPv6'",
"]",
")",
".",
"info",
"tcp",... | Trace packet flow for TCP. | [
"Trace",
"packet",
"flow",
"for",
"TCP",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/toolkit/default.py#L90-L108 |
JarryShaw/PyPCAPKit | src/const/ipv4/tos_rel.py | TOS_REL.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TOS_REL(key)
if key not in TOS_REL._member_map_:
extend_enum(TOS_REL, key, default)
return TOS_REL[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TOS_REL(key)
if key not in TOS_REL._member_map_:
extend_enum(TOS_REL, key, default)
return TOS_REL[key] | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"-",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"int",
")",
":",
"return",
"TOS_REL",
"(",
"key",
")",
"if",
"key",
"not",
"in",
"TOS_REL",
".",
"_member_map_",
":",
"extend_enum",
"(",
"TOS_R... | Backport support for original codes. | [
"Backport",
"support",
"for",
"original",
"codes",
"."
] | train | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/ipv4/tos_rel.py#L16-L22 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.