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_documentation_string stringlengths 1 47.2k | 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):
... | Create HMAC Signature from secret for value. | 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)) | Check for the signature is correct. | 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)) | Hash a password with given method and salt length. | 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 ... | Import all submodules by package name. | 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!"
... | 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):
... | 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... | Create a handler class from function or coroutine. | 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):
... | Bind to the given application. | 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) | Register view to handler. | 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... | Dispatch request. | 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... | Convert a handler result to web response. | 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... | Return a coroutine which parses data from request depends on content-type.
Usage: ::
def post(self, request):
data = await self.parse(request)
# ... | 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(
... | Initialize the plugin.
Fill the plugin's options from application. | 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... | Handle exceptions.
Route exceptions to handlers if they are registered in application. | 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!'
"""
... | Register function/coroutine/muffin.Handler with the application.
Usage example:
.. code-block:: python
@app.register('/hello')
def hello(request):
return 'Hello World!' | 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:
... | Load the application configuration.
This method loads configuration from python module. | 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)
... | Install plugin to the application. | 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))
... | Start the application.
Support for start-callbacks and lock the application's configuration and plugins. | 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))) | Register given middleware (v1). | 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... | 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... | 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... | Default verifier used if HONEYPOT_VERIFIER is not specified.
Ensures val == HONEYPOT_VALUE or HONEYPOT_VALUE() if it's a callable. | 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... | Verify that request.POST[field_name] is a valid honeypot.
Ensures that the field exists and passes verification according to
HONEYPOT_VERIFIER. | 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):
... | Check request.POST for valid honeypot field.
Takes an optional field_name that defaults to HONEYPOT_FIELD_NAME if
not specified. | 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... | Mark view as exempt from honeypot validation | 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()
... | Renders honeypot field named field_name (defaults to HONEYPOT_FIELD_NAME). | 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... | Parse the command line arguments. | 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... | Generate a badge based on command line arguments. | 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 | Identify whether the value text is an int. | 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) | Return the badge font width. | 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)) | The SVG x position where the color split should occur. | 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... | The total width of badge.
>>> badge = Badge('pylint', '5', font_name='DejaVu Sans,Verdana,Geneva,sans-serif',
... font_size=11)
>>> badge.badge_width
91 | 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:
... | The badge SVG text. | 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_... | 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 | 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:
... | Find the badge color based on the thresholds. | 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.... | Write badge to file. | 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... | Run server. | 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... | Return the name of a given object | 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 | Return the attribute name identifier | 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 | Return whether a class method is bound to the class | 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)
] | Return methods associated with a given class | 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
] | Return class variables associated with a given class | 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... | Return instance variables used in an AST node | 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)
] | Return classes associated with a given module | 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
] | Return all filenames under recursively found in a directory | 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] | Backport support for original codes. | 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] | Backport support for original codes. | 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] | Backport support for original codes. | 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... | Lookup function used when value is not found. | 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] | Backport support for original codes. | 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] | Backport support for original codes. | 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... | S.count(value) -> integer -- return number of occurrences of value | 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... | 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. | 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) | Return first index of value. | 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] | Backport support for original codes. | 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | 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... | 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 | Read router and area IDs. | 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 ... | 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
+-+-+-+-+-+-+-+-+-+... | 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, {... | Check if arguments are integrals. | 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... | Check if arguments are real numbers. | 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... | Check if arguments are complex numbers. | 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... | Check if arguments are numbers. | 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... | Check if arguments are bytes type. | 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... | Check if arguments are bytearray type. | 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... | Check if arguments are str type. | 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.') | Check if arguments are bytes type. | 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'... | Check if arguments are list type. | 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... | Check if arguments are dict type. | 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 ... | Check if arguments are tuple type. | 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... | Check if arguments are file-like object. | 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... | Check if arguments are Info instance. | 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, {... | Check if arguments are IP addresses. | 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... | Check if arguments are of protocol type. | 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... | Check if arguments are valid fragments. | 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... | Check if arguments are valid IP fragments. | 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... | Check if arguments are valid packets. | 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)
... | Fetch datagram. | 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 | Return datagram index. | 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(... | Run automatically.
Positional arguments:
* packets -- list<dict>, list of packet dicts to be reassembled | 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 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+... | Read Mobility Header.
Structure of MH header [RFC 6275]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Proto | Header Len | MH Type | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... | 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] | Backport support for original codes. | 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] | Backport support for original codes. | 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 |
... | Read User Datagram Protocol (UDP).
Structure of UDP header [RFC 768]:
0 7 8 15 16 23 24 31
+--------+--------+--------+--------+
| Source | Destination |
| Port | Port |
+--------+--------+--------+--... | 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... | 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... | 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
... | 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 ... | 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] | Backport support for original codes. | 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... | 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 ... | 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... | Resolve MAC address according to protocol.
Positional arguments:
* length -- int, hardware address length
* htype -- int, hardware type
Returns:
* str -- MAC address | 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': ... | Resolve IP address according to protocol.
Positional arguments:
* length -- int, protocol address length
* ptype -- int, protocol type
Returns:
* str -- IP address | 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] | Backport support for original codes. | 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] | Backport support for original codes. | 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] | Backport support for original codes. | 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] | Backport support for original codes. | 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... | Lookup function used when value is not found. | 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] | Backport support for original codes. | 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] | Backport support for original codes. | 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(... | Lookup function used when value is not found. | 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, ... | Make data for IPv4 reassembly. | 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, ... | Make data for IPv6 reassembly. | 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
... | Make data for TCP reassembly. | 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
... | Trace packet flow for TCP. | 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] | Backport support for original codes. | 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.