code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
@wraps(func)
def func_wrapper(*args, **kwargs):
# pylint: disable=C0111, C0103
function_name = func.__name__
CHECKERS_DISABLED = os.getenv('CHECKERS_DISABLED', '')
disabled_functions = [x.strip() for x in CHECKERS_DISABLED.split(',')]
force_run = kwargs.get('force_r... | def disable_checker_on_env(func) | Disable the ``func`` called if its name is present in ``CHECKERS_DISABLED``.
:param func: The function/validator to be disabled.
:type func: callable
:returns: If disabled, ``True``. If enabled, the result of ``func``. | 2.543093 | 2.50989 | 1.013229 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
if isinstance(value, uuid_.UUID):
return value
try:
value = uuid_.UUID(value)
except ValueError:
raise errors.CannotCoerceError('v... | def uuid(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a valid :class:`UUID <python:uuid.UUID>`.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>`
if... | 3.231413 | 3.061227 | 1.055594 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
minimum_length = integer(minimum_length, allow_empty = True)
maximum_length = integer(maximum_length, allow_empty = True)
if coerce_value:
value =... | def string(value,
allow_empty = False,
coerce_value = False,
minimum_length = None,
maximum_length = None,
whitespace_padding = False,
**kwargs) | Validate that ``value`` is a valid string.
:param value: The value to validate.
:type value: :class:`str <python:str>` / :obj:`None <python:None>`
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value``
is empty. If ``False``, raises a
:class:`EmptyValueError <validator... | 1.893182 | 1.876246 | 1.009026 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif value is None:
return None
minimum_length = integer(minimum_length, allow_empty = True, force_run = True) # pylint: disable=E1123
maximum_length = integer(maximum_length, allow_empty... | def iterable(value,
allow_empty = False,
forbid_literals = (str, bytes),
minimum_length = None,
maximum_length = None,
**kwargs) | Validate that ``value`` is a valid iterable.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value``
is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>` if
``value`` is empty. Def... | 2.223742 | 2.201922 | 1.00991 |
if value is not None and not value and allow_empty:
pass
elif (value is not None and not value) or value:
raise errors.NotNoneError('value was not None')
return None | def none(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is :obj:`None <python:None>`.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value``
is empty but **not** :obj:`None <python:None>`. If ``False``, raises a
:class:`NotNoneError` if ``value`` is empty but **not**... | 5.965686 | 10.292777 | 0.579599 |
if not value and allow_empty:
return None
elif not value:
raise errors.EmptyValueError('value was empty')
return value | def not_empty(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is not empty.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>`
if ``value`` is empty. Defaults t... | 5.529801 | 12.308856 | 0.449254 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
try:
parse('%s = None' % value)
except (SyntaxError, ValueError, TypeError):
raise errors.InvalidVariableNameError(
'value (%s) is ... | def variable_name(value,
allow_empty = False,
**kwargs) | Validate that the value is a valid Python variable name.
.. caution::
This function does **NOT** check whether the variable exists. It only
checks that the ``value`` would work as a Python variable (or class, or
function, etc.) name.
:param value: The value to validate.
:param allow_em... | 3.940062 | 4.02952 | 0.977799 |
original_value = value
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
if json_serializer is None:
json_serializer = json_
if isinstance(value, str):
try:
value = json_serial... | def dict(value,
allow_empty = False,
json_serializer = None,
**kwargs) | Validate that ``value`` is a :class:`dict <python:dict>`.
.. hint::
If ``value`` is a string, this validator will assume it is a JSON
object and try to convert it into a :class:`dict <python:dict>`
You can override the JSON serializer used by passing it to the
``json_serializer`` property... | 2.942815 | 2.534301 | 1.161194 |
original_value = value
original_schema = schema
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
if not json_serializer:
json_serializer = json_
if isinstance(value, str):
try:
... | def json(value,
schema = None,
allow_empty = False,
json_serializer = None,
**kwargs) | Validate that ``value`` conforms to the supplied JSON Schema.
.. note::
``schema`` supports JSON Schema Drafts 3 - 7. Unless the JSON Schema indicates the
meta-schema using a ``$schema`` property, the schema will be assumed to conform to
Draft 7.
.. hint::
If either ``value`` or ``sc... | 2.263262 | 2.096508 | 1.079539 |
if maximum is None:
maximum = POSITIVE_INFINITY
else:
maximum = numeric(maximum)
if minimum is None:
minimum = NEGATIVE_INFINITY
else:
minimum = numeric(minimum)
if value is None and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % ... | def numeric(value,
allow_empty = False,
minimum = None,
maximum = None,
**kwargs) | Validate that ``value`` is a numeric value.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value``
is :obj:`None <python:None>`. If ``False``, raises an
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>` if
``v... | 2.102543 | 2.088633 | 1.00666 |
value = numeric(value, # pylint: disable=E1123
allow_empty = allow_empty,
minimum = minimum,
maximum = maximum,
force_run = True)
if value is not None and hasattr(value, 'is... | def integer(value,
allow_empty = False,
coerce_value = False,
minimum = None,
maximum = None,
base = 10,
**kwargs) | Validate that ``value`` is an :class:`int <python:int>`.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is :obj:`None <python:None>`. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>`... | 3.609133 | 3.879028 | 0.930422 |
try:
value = _numeric_coercion(value,
coercion_function = float_,
allow_empty = allow_empty,
minimum = minimum,
maximum = maximum)
except (errors.EmptyValueError,
... | def float(value,
allow_empty = False,
minimum = None,
maximum = None,
**kwargs) | Validate that ``value`` is a :class:`float <python:float>`.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is :obj:`None <python:None>`. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueErro... | 3.720798 | 3.469274 | 1.072501 |
try:
value = _numeric_coercion(value,
coercion_function = fractions.Fraction,
allow_empty = allow_empty,
minimum = minimum,
maximum = maximum)
except (errors.Empty... | def fraction(value,
allow_empty = False,
minimum = None,
maximum = None,
**kwargs) | Validate that ``value`` is a :class:`Fraction <python:fractions.Fraction>`.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value``
is :obj:`None <python:None>`. If ``False``, raises a
:class:`EmptyValueError <validator_collection.error... | 3.754601 | 3.38838 | 1.108081 |
if value is None and allow_empty:
return None
elif value is None:
raise errors.EmptyValueError('value cannot be None')
if isinstance(value, str):
try:
value = decimal_.Decimal(value.strip())
except decimal_.InvalidOperation:
raise errors.CannotCo... | def decimal(value,
allow_empty = False,
minimum = None,
maximum = None,
**kwargs) | Validate that ``value`` is a :class:`Decimal <python:decimal.Decimal>`.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if ``value``
is :obj:`None <python:None>`. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.Em... | 3.013027 | 3.164121 | 0.952248 |
if coercion_function is None:
raise errors.CoercionFunctionEmptyError('coercion_function cannot be empty')
elif not hasattr(coercion_function, '__call__'):
raise errors.NotCallableError('coercion_function must be callable')
value = numeric(value, ... | def _numeric_coercion(value,
coercion_function = None,
allow_empty = False,
minimum = None,
maximum = None) | Validate that ``value`` is numeric and coerce using ``coercion_function``.
:param value: The value to validate.
:param coercion_function: The function to use to coerce ``value`` to the desired
type.
:type coercion_function: callable
:param allow_empty: If ``True``, returns :obj:`None <python:No... | 2.888283 | 2.866806 | 1.007492 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
if not isinstance(value, io.BytesIO):
raise errors.NotBytesIOError('value (%s) is not a BytesIO, '
'is a %s' % (value,... | def bytesIO(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a :class:`BytesIO <python:io.BytesIO>` object.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>`
... | 3.151238 | 2.999169 | 1.050704 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
if not isinstance(value, io.StringIO):
raise ValueError('value (%s) is not an io.StringIO object, '
'is a %s' % (value, type(value... | def stringIO(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a :class:`StringIO <python:io.StringIO>` object.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>`
... | 3.2952 | 3.685944 | 0.893991 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
if hasattr(os, 'PathLike'):
if not isinstance(value, (str, bytes, int, os.PathLike)): # pylint: disable=E1101
raise errors.N... | def path(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a valid path-like object.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>`
if ``value`` is em... | 2.949256 | 2.963717 | 0.995121 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
value = path(value, force_run = True) # pylint: disable=E1123
if not os.path.exists(value):
raise errors.PathExi... | def path_exists(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a path-like object that exists on the local
filesystem.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyVal... | 4.387241 | 4.872941 | 0.900327 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
value = path_exists(value, force_run = True) # pylint: disable=E1123
if not os.path.isfile(value):
raise errors.NotAFil... | def file_exists(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a valid file that exists on the local filesystem.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>`
... | 4.368712 | 4.721759 | 0.92523 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
value = path_exists(value, force_run = True) # pylint: disable=E1123
if not os.path.isdir(value):
raise errors.NotADire... | def directory_exists(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a valid directory that exists on the local
filesystem.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValu... | 3.838994 | 4.439734 | 0.86469 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
value = file_exists(value, force_run = True) # pylint: disable=E1123
try:
with open(value, mode='r'):
pass
... | def readable(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a path to a readable file.
.. caution::
**Use of this validator is an anti-pattern and should be used with caution.**
Validating the readability of a file *before* attempting to read it
exposes your code to a bug called
`TOCTOU <https://en.wikipedia.org/wiki/Tim... | 4.494546 | 4.586723 | 0.979904 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
value = path(value, force_run = True)
if sys.platform in ['win32', 'cygwin']:
raise NotImplementedError('not supported on Windows')
is_valid = os... | def writeable(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a path to a writeable file.
.. caution::
This validator does **NOT** work correctly on a Windows file system. This
is due to the vagaries of how Windows manages its file system and the
various ways in which it can manage file permission.
If called on a Windows f... | 4.26117 | 4.440789 | 0.959553 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
value = file_exists(value, force_run = True)
if sys.platform in ['win32', 'cygwin']:
raise NotImplementedError('not supported on Windows')
is_val... | def executable(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a path to an executable file.
.. caution::
This validator does **NOT** work correctly on a Windows file system. This
is due to the vagaries of how Windows manages its file system and the
various ways in which it can manage file permission.
If called on a Windows... | 4.154225 | 4.367968 | 0.951066 |
is_recursive = kwargs.pop('is_recursive', False)
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
if not isinstance(value, basestring):
raise errors.CannotCoerceError('value must be a valid string, '... | def url(value,
allow_empty = False,
allow_special_ips = False,
**kwargs) | Validate that ``value`` is a valid URL.
.. note::
URL validation is...complicated. The methodology that we have
adopted here is *generally* compliant with
`RFC 1738 <https://tools.ietf.org/html/rfc1738>`_,
`RFC 6761 <https://tools.ietf.org/html/rfc6761>`_,
`RFC 2181 <https://tools.ie... | 2.520511 | 2.455645 | 1.026415 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
if is_py2 and value and isinstance(value, unicode):
value = value.encode('utf-8')
try:
value = ipv6(value, force_run = True) ... | def ip_address(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a valid IP address.
.. note::
First, the validator will check if the address is a valid IPv6 address.
If that doesn't work, the validator will check if the address is a valid
IPv4 address.
If neither works, the validator will raise an error (as always).
:pa... | 2.968868 | 2.899036 | 1.024088 |
if not value and allow_empty is False:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
try:
components = value.split('.')
except AttributeError:
raise errors.InvalidIPAddressError('value (%s) is not a valid ipv4' % value)
... | def ipv4(value, allow_empty = False) | Validate that ``value`` is a valid IP version 4 address.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>`
if ``value`` i... | 2.274076 | 2.243396 | 1.013675 |
if not value and allow_empty is False:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
if not isinstance(value, str):
raise errors.InvalidIPAddressError('value (%s) is not a valid ipv6' % value)
value = value.lower().strip()
is... | def ipv6(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a valid IP address version 6.
:param value: The value to validate.
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <validator_collection.errors.EmptyValueError>`
if ``value`` i... | 2.623846 | 2.503707 | 1.047984 |
if not value and not allow_empty:
raise errors.EmptyValueError('value (%s) was empty' % value)
elif not value:
return None
if not isinstance(value, basestring):
raise errors.CannotCoerceError('value must be a valid string, '
'was %s' % typ... | def mac_address(value,
allow_empty = False,
**kwargs) | Validate that ``value`` is a valid MAC address.
:param value: The value to validate.
:type value: :class:`str <python:str>` / :obj:`None <python:None>`
:param allow_empty: If ``True``, returns :obj:`None <python:None>` if
``value`` is empty. If ``False``, raises a
:class:`EmptyValueError <vali... | 2.73198 | 2.54044 | 1.075396 |
if not is_iterable(type_):
type_ = [type_]
return_value = False
for check_for_type in type_:
if isinstance(check_for_type, type):
return_value = isinstance(obj, check_for_type)
elif obj.__class__.__name__ == check_for_type:
return_value = True
el... | def is_type(obj,
type_,
**kwargs) | Indicate if ``obj`` is a type in ``type_``.
.. hint::
This checker is particularly useful when you want to evaluate whether
``obj`` is of a particular type, but importing that type directly to use
in :func:`isinstance() <python:isinstance>` would cause a circular import
error.
To us... | 2.442179 | 2.93203 | 0.832931 |
return_value = False
for base in base_classes:
if base.__name__ == check_for_type:
return_value = True
break
else:
return_value = _check_base_classes(base.__bases__, check_for_type)
if return_value is True:
break
return re... | def _check_base_classes(base_classes, check_for_type) | Indicate whether ``check_for_type`` exists in ``base_classes``. | 1.95382 | 1.807426 | 1.080996 |
if len(args) == 1:
return True
first_item = args[0]
for item in args[1:]:
if type(item) != type(first_item): # pylint: disable=C0123
return False
if isinstance(item, dict):
if not are_dicts_equivalent(item, first_ite... | def are_equivalent(*args, **kwargs) | Indicate if arguments passed to this function are equivalent.
.. hint::
This checker operates recursively on the members contained within iterables
and :class:`dict <python:dict>` objects.
.. caution::
If you only pass one argument to this checker - even if it is an iterable -
the ch... | 1.957888 | 2.25554 | 0.868035 |
# pylint: disable=too-many-return-statements
if not args:
return False
if len(args) == 1:
return True
if not all(is_dict(x) for x in args):
return False
first_item = args[0]
for item in args[1:]:
if len(item) != len(first_item):
return False
... | def are_dicts_equivalent(*args, **kwargs) | Indicate if :ref:`dicts <python:dict>` passed to this function have identical
keys and values.
:param args: One or more values, passed as positional arguments.
:returns: ``True`` if ``args`` have identical keys/values, and ``False`` if not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError:... | 1.706794 | 1.936123 | 0.881552 |
if minimum is None and maximum is None:
raise ValueError('minimum and maximum cannot both be None')
if value is None:
return False
if minimum is not None and maximum is None:
return value >= minimum
elif minimum is None and maximum is not None:
return value <= maxi... | def is_between(value,
minimum = None,
maximum = None,
**kwargs) | Indicate whether ``value`` is greater than or equal to a supplied ``minimum``
and/or less than or equal to ``maximum``.
.. note::
This function works on any ``value`` that support comparison operators,
whether they are numbers or not. Technically, this means that ``value``,
``minimum``, or `... | 1.793491 | 2.153204 | 0.832941 |
if minimum is None and maximum is None:
raise ValueError('minimum and maximum cannot both be None')
length = len(value)
minimum = validators.numeric(minimum,
allow_empty = True)
maximum = validators.numeric(maximum,
allow_em... | def has_length(value,
minimum = None,
maximum = None,
**kwargs) | Indicate whether ``value`` has a length greater than or equal to a
supplied ``minimum`` and/or less than or equal to ``maximum``.
.. note::
This function works on any ``value`` that supports the
:func:`len() <python:len>` operation. This means that ``value`` must implement
the :func:`__len__... | 2.932906 | 3.605011 | 0.813564 |
if isinstance(value, dict):
return True
try:
value = validators.dict(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_dict(value, **kwargs) | Indicate whether ``value`` is a valid :class:`dict <python:dict>`
.. note::
This will return ``True`` even if ``value`` is an empty
:class:`dict <python:dict>`.
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is valid, ``False`` if it is not.
:rtype: :class:`bool <py... | 4.326828 | 4.834694 | 0.894954 |
try:
value = validators.json(value,
schema = schema,
json_serializer = json_serializer,
**kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return T... | def is_json(value,
schema = None,
json_serializer = None,
**kwargs) | Indicate whether ``value`` is a valid JSON object.
.. note::
``schema`` supports JSON Schema Drafts 3 - 7. Unless the JSON Schema indicates the
meta-schema using a ``$schema`` property, the schema will be assumed to conform to
Draft 7.
:param value: The value to evaluate.
:param schema... | 3.409239 | 4.218251 | 0.808211 |
if value is None:
return False
minimum_length = validators.integer(minimum_length, allow_empty = True, **kwargs)
maximum_length = validators.integer(maximum_length, allow_empty = True, **kwargs)
if isinstance(value, basestring) and not value:
if minimum_length and minimum_length >... | def is_string(value,
coerce_value = False,
minimum_length = None,
maximum_length = None,
whitespace_padding = False,
**kwargs) | Indicate whether ``value`` is a string.
:param value: The value to evaluate.
:param coerce_value: If ``True``, will check whether ``value`` can be coerced
to a string if it is not already. Defaults to ``False``.
:type coerce_value: :class:`bool <python:bool>`
:param minimum_length: If supplied,... | 2.185538 | 2.402227 | 0.909797 |
if obj is None:
return False
if obj in forbid_literals:
return False
try:
obj = validators.iterable(obj,
allow_empty = True,
forbid_literals = forbid_literals,
minimum_length ... | def is_iterable(obj,
forbid_literals = (str, bytes),
minimum_length = None,
maximum_length = None,
**kwargs) | Indicate whether ``obj`` is iterable.
:param forbid_literals: A collection of literals that will be considered invalid
even if they are (actually) iterable. Defaults to a :class:`tuple <python:tuple>`
containing :class:`str <python:str>` and :class:`bytes <python:bytes>`.
:type forbid_literals: ite... | 2.755641 | 2.981413 | 0.924274 |
try:
value = validators.not_empty(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_not_empty(value, **kwargs) | Indicate whether ``value`` is empty.
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is empty, ``False`` if it is not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
keyword parameters passed to the... | 5.272691 | 5.589655 | 0.943295 |
try:
validators.none(value, allow_empty = allow_empty, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_none(value, allow_empty = False, **kwargs) | Indicate whether ``value`` is :obj:`None <python:None>`.
:param value: The value to evaluate.
:param allow_empty: If ``True``, accepts falsey values as equivalent to
:obj:`None <python:None>`. Defaults to ``False``.
:type allow_empty: :class:`bool <python:bool>`
:returns: ``True`` if ``value`` ... | 4.402819 | 5.076979 | 0.867212 |
try:
validators.variable_name(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_variable_name(value, **kwargs) | Indicate whether ``value`` is a valid Python variable name.
.. caution::
This function does **NOT** check whether the variable exists. It only
checks that the ``value`` would work as a Python variable (or class, or
function, etc.) name.
:param value: The value to evaluate.
:returns: ``... | 5.115937 | 6.296345 | 0.812525 |
try:
validators.uuid(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_uuid(value, **kwargs) | Indicate whether ``value`` contains a :class:`UUID <python:uuid.UUID>`
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is valid, ``False`` if it is not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
... | 6.003242 | 5.985599 | 1.002948 |
try:
value = validators.date(value,
minimum = minimum,
maximum = maximum,
coerce_value = coerce_value,
**kwargs)
except SyntaxError as error:
raise error
excep... | def is_date(value,
minimum = None,
maximum = None,
coerce_value = False,
**kwargs) | Indicate whether ``value`` is a :class:`date <python:datetime.date>`.
:param value: The value to evaluate.
:param minimum: If supplied, will make sure that ``value`` is on or after
this value.
:type minimum: :class:`datetime <python:datetime.datetime>` /
:class:`date <python:datetime.date>` / ... | 2.814499 | 3.282042 | 0.857545 |
try:
value = validators.datetime(value,
minimum = minimum,
maximum = maximum,
coerce_value = coerce_value,
**kwargs)
except SyntaxError as error:
r... | def is_datetime(value,
minimum = None,
maximum = None,
coerce_value = False,
**kwargs) | Indicate whether ``value`` is a :class:`datetime <python:datetime.datetime>`.
:param value: The value to evaluate.
:param minimum: If supplied, will make sure that ``value`` is on or after
this value.
:type minimum: :class:`datetime <python:datetime.datetime>` /
:class:`date <python:datetime.d... | 2.893911 | 3.307736 | 0.874892 |
try:
value = validators.time(value,
minimum = minimum,
maximum = maximum,
coerce_value = coerce_value,
**kwargs)
except SyntaxError as error:
raise error
excep... | def is_time(value,
minimum = None,
maximum = None,
coerce_value = False,
**kwargs) | Indicate whether ``value`` is a :class:`time <python:datetime.time>`.
:param value: The value to evaluate.
:param minimum: If supplied, will make sure that ``value`` is on or after this value.
:type minimum: :func:`datetime <validator_collection.validators.datetime>` or
:func:`time <validator_collec... | 2.847406 | 3.484807 | 0.817091 |
try:
value = validators.timezone(value,
positive = positive,
**kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_timezone(value,
positive = True,
**kwargs) | Indicate whether ``value`` is a :class:`tzinfo <python:datetime.tzinfo>`.
.. caution::
This does **not** validate whether the value is a timezone that actually
exists, nor can it resolve timzone names (e.g. ``'Eastern'`` or ``'CET'``).
For that kind of functionality, we recommend you utilize:
... | 4.267237 | 5.748731 | 0.742292 |
try:
value = validators.numeric(value,
minimum = minimum,
maximum = maximum,
**kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return Tru... | def is_numeric(value,
minimum = None,
maximum = None,
**kwargs) | Indicate whether ``value`` is a numeric value.
:param value: The value to evaluate.
:param minimum: If supplied, will make sure that ``value`` is greater than or
equal to this value.
:type minimum: numeric
:param maximum: If supplied, will make sure that ``value`` is less than or
equal to... | 3.652071 | 4.400803 | 0.829865 |
try:
value = validators.integer(value,
coerce_value = coerce_value,
minimum = minimum,
maximum = maximum,
base = base,
**kwargs)... | def is_integer(value,
coerce_value = False,
minimum = None,
maximum = None,
base = 10,
**kwargs) | Indicate whether ``value`` contains a whole number.
:param value: The value to evaluate.
:param coerce_value: If ``True``, will return ``True`` if ``value`` can be coerced
to whole number. If ``False``, will only return ``True`` if ``value`` is already
a whole number (regardless of type). Defaults... | 2.703679 | 3.066103 | 0.881797 |
try:
value = validators.float(value,
minimum = minimum,
maximum = maximum,
**kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_float(value,
minimum = None,
maximum = None,
**kwargs) | Indicate whether ``value`` is a :class:`float <python:float>`.
:param value: The value to evaluate.
:param minimum: If supplied, will make sure that ``value`` is greater than or
equal to this value.
:type minimum: numeric
:param maximum: If supplied, will make sure that ``value`` is less than o... | 3.682455 | 4.191117 | 0.878633 |
try:
value = validators.fraction(value,
minimum = minimum,
maximum = maximum,
**kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return... | def is_fraction(value,
minimum = None,
maximum = None,
**kwargs) | Indicate whether ``value`` is a :class:`Fraction <python:fractions.Fraction>`.
:param value: The value to evaluate.
:param minimum: If supplied, will make sure that ``value`` is greater than or
equal to this value.
:type minimum: numeric
:param maximum: If supplied, will make sure that ``value`... | 3.771114 | 4.462838 | 0.845004 |
try:
value = validators.decimal(value,
minimum = minimum,
maximum = maximum,
**kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return Tru... | def is_decimal(value,
minimum = None,
maximum = None,
**kwargs) | Indicate whether ``value`` contains a :class:`Decimal <python:decimal.Decimal>`.
:param value: The value to evaluate.
:param minimum: If supplied, will make sure that ``value`` is greater than or
equal to this value.
:type minimum: numeric
:param maximum: If supplied, will make sure that ``valu... | 3.66173 | 4.466025 | 0.819908 |
try:
value = validators.path(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_pathlike(value, **kwargs) | Indicate whether ``value`` is a path-like object.
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is valid, ``False`` if it is not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
keyword parameters ... | 6.365739 | 5.910589 | 1.077006 |
try:
value = validators.path_exists(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_on_filesystem(value, **kwargs) | Indicate whether ``value`` is a file or directory that exists on the local
filesystem.
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is valid, ``False`` if it is not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError: if ``kwargs`` contains duplicate keyword parameter... | 6.529611 | 6.373923 | 1.024426 |
try:
value = validators.file_exists(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_file(value, **kwargs) | Indicate whether ``value`` is a file that exists on the local filesystem.
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is valid, ``False`` if it is not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
... | 6.174714 | 5.962382 | 1.035612 |
try:
value = validators.directory_exists(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_directory(value, **kwargs) | Indicate whether ``value`` is a directory that exists on the local filesystem.
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is valid, ``False`` if it is not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplica... | 6.096351 | 6.160392 | 0.989604 |
try:
validators.readable(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_readable(value, **kwargs) | Indicate whether ``value`` is a readable file.
.. caution::
**Use of this validator is an anti-pattern and should be used with caution.**
Validating the readability of a file *before* attempting to read it
exposes your code to a bug called
`TOCTOU <https://en.wikipedia.org/wiki/Time_of_ch... | 6.515746 | 6.44963 | 1.010251 |
if sys.platform in ['win32', 'cygwin']:
raise NotImplementedError('not supported on Windows')
try:
validators.writeable(value,
allow_empty = False,
**kwargs)
except SyntaxError as error:
raise error
except Exception:... | def is_writeable(value,
**kwargs) | Indicate whether ``value`` is a writeable file.
.. caution::
This validator does **NOT** work correctly on a Windows file system. This
is due to the vagaries of how Windows manages its file system and the
various ways in which it can manage file permission.
If called on a Windows file sys... | 4.812565 | 5.414029 | 0.888906 |
if sys.platform in ['win32', 'cygwin']:
raise NotImplementedError('not supported on Windows')
try:
validators.executable(value,
**kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_executable(value,
**kwargs) | Indicate whether ``value`` is an executable file.
.. caution::
This validator does **NOT** work correctly on a Windows file system. This
is due to the vagaries of how Windows manages its file system and the
various ways in which it can manage file permission.
If called on a Windows file s... | 5.002943 | 6.018492 | 0.831262 |
try:
value = validators.email(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_email(value, **kwargs) | Indicate whether ``value`` is an email address.
.. note::
Email address validation is...complicated. The methodology that we have
adopted here is *generally* compliant with
`RFC 5322 <https://tools.ietf.org/html/rfc5322>`_ and uses a combination of
string parsing and regular expressions.
... | 5.328329 | 6.115668 | 0.871259 |
try:
value = validators.url(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_url(value, **kwargs) | Indicate whether ``value`` is a URL.
.. note::
URL validation is...complicated. The methodology that we have
adopted here is *generally* compliant with
`RFC 1738 <https://tools.ietf.org/html/rfc1738>`_,
`RFC 6761 <https://tools.ietf.org/html/rfc6761>`_,
`RFC 2181 <https://tools.ietf.... | 5.231785 | 5.847943 | 0.894637 |
try:
value = validators.domain(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_domain(value, **kwargs) | Indicate whether ``value`` is a valid domain.
.. caution::
This validator does not verify that ``value`` **exists** as a domain. It
merely verifies that its contents *might* exist as a domain.
.. note::
This validator checks to validate that ``value`` resembles a valid
domain name. I... | 5.282277 | 5.745692 | 0.919346 |
try:
value = validators.ip_address(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_ip_address(value, **kwargs) | Indicate whether ``value`` is a valid IP address (version 4 or version 6).
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is valid, ``False`` if it is not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
... | 5.144693 | 5.110519 | 1.006687 |
try:
value = validators.ipv4(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_ipv4(value, **kwargs) | Indicate whether ``value`` is a valid IP version 4 address.
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is valid, ``False`` if it is not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
keyword p... | 5.139691 | 5.367469 | 0.957563 |
try:
value = validators.ipv6(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_ipv6(value, **kwargs) | Indicate whether ``value`` is a valid IP version 6 address.
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is valid, ``False`` if it is not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
keyword p... | 5.221391 | 5.366229 | 0.973009 |
try:
value = validators.mac_address(value, **kwargs)
except SyntaxError as error:
raise error
except Exception:
return False
return True | def is_mac_address(value, **kwargs) | Indicate whether ``value`` is a valid MAC address.
:param value: The value to evaluate.
:returns: ``True`` if ``value`` is valid, ``False`` if it is not.
:rtype: :class:`bool <python:bool>`
:raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
keyword parameters... | 4.968051 | 5.226463 | 0.950557 |
'''Draw a series of elements from left to right'''
tag = self.get_tag()
c = self.canvas
s = self.style
sep = s.h_sep
exx = 0
exy = 0
terms = lx if ltor else reversed(lx) # Reverse so we can draw left to right
for term in terms:
t, texx, texy = self.draw_diagram(term,... | def draw_line(self, lx, ltor) | Draw a series of elements from left to right | 5.232769 | 5.113066 | 1.023411 |
# get models
all_models = apps.get_models()
# get fields
fields = []
for model in all_models:
for field in model._meta.get_fields():
if isinstance(field, models.FileField):
fields.append(field)
return fields | def get_file_fields() | Get all fields which are inherited from FileField | 2.809601 | 2.510171 | 1.119287 |
for filename in files:
os.remove(os.path.join(settings.MEDIA_ROOT, filename)) | def remove_media(files) | Delete file from media dir | 2.716721 | 2.595009 | 1.046902 |
if not path:
path = settings.MEDIA_ROOT
if not os.path.isdir(path):
return False
listdir = [os.path.join(path, filename) for filename in os.listdir(path)]
if all(list(map(remove_empty_dirs, listdir))):
os.rmdir(path)
return True
else:
return False | def remove_empty_dirs(path=None) | Recursively delete empty directories; return True if everything was deleted. | 2.454915 | 2.246879 | 1.092589 |
media = set()
for field in get_file_fields():
is_null = {
'%s__isnull' % field.name: True,
}
is_empty = {
'%s' % field.name: '',
}
storage = field.storage
for value in field.model.objects \
.values_list(field.name, ... | def get_used_media() | Get media which are still used in models | 3.31974 | 3.229151 | 1.028054 |
if not exclude:
exclude = []
media = set()
for root, dirs, files in os.walk(six.text_type(settings.MEDIA_ROOT)):
for name in files:
path = os.path.abspath(os.path.join(root, name))
relpath = os.path.relpath(path, settings.MEDIA_ROOT)
for e in exclu... | def get_all_media(exclude=None) | Get all media from MEDIA_ROOT | 2.316673 | 2.200781 | 1.052659 |
if not exclude:
exclude = []
all_media = get_all_media(exclude)
used_media = get_used_media()
return all_media - used_media | def get_unused_media(exclude=None) | Get media which are not used in models | 2.983315 | 2.799623 | 1.065613 |
self.send_createCluster(hzVersion, xmlconfig)
return self.recv_createCluster() | def createCluster(self, hzVersion, xmlconfig) | Parameters:
- hzVersion
- xmlconfig | 3.760859 | 2.473126 | 1.520691 |
self.send_shutdownMember(clusterId, memberId)
return self.recv_shutdownMember() | def shutdownMember(self, clusterId, memberId) | Parameters:
- clusterId
- memberId | 2.463148 | 2.289024 | 1.076069 |
self.send_terminateMember(clusterId, memberId)
return self.recv_terminateMember() | def terminateMember(self, clusterId, memberId) | Parameters:
- clusterId
- memberId | 2.451903 | 2.378609 | 1.030814 |
self.send_suspendMember(clusterId, memberId)
return self.recv_suspendMember() | def suspendMember(self, clusterId, memberId) | Parameters:
- clusterId
- memberId | 2.566724 | 2.44152 | 1.051281 |
self.send_resumeMember(clusterId, memberId)
return self.recv_resumeMember() | def resumeMember(self, clusterId, memberId) | Parameters:
- clusterId
- memberId | 2.576551 | 2.361135 | 1.091234 |
self.send_mergeMemberToCluster(clusterId, memberId)
return self.recv_mergeMemberToCluster() | def mergeMemberToCluster(self, clusterId, memberId) | Parameters:
- clusterId
- memberId | 2.382147 | 2.081883 | 1.144227 |
self.send_executeOnController(clusterId, script, lang)
return self.recv_executeOnController() | def executeOnController(self, clusterId, script, lang) | Parameters:
- clusterId
- script
- lang | 2.489828 | 2.337214 | 1.065297 |
uniform1 = cspace_convert(color1, input_space, uniform_space)
uniform2 = cspace_convert(color2, input_space, uniform_space)
return np.sqrt(np.sum((uniform1 - uniform2) ** 2, axis=-1)) | def deltaE(color1, color2,
input_space="sRGB1", uniform_space="CAM02-UCS") | Computes the :math:`\Delta E` distance between pairs of colors.
:param input_space: The space the colors start out in. Can be anything
recognized by :func:`cspace_convert`. Default: "sRGB1"
:param uniform_space: Which space to perform the distance measurement
in. This should be a uniform space li... | 2.211166 | 2.174211 | 1.016997 |
XYZ100 = np.asarray(XYZ100, dtype=float)
# this is broadcasting matrix * array-of-vectors, where the vector is the
# last dim
RGB_linear = np.einsum("...ij,...j->...i", XYZ100_to_sRGB1_matrix, XYZ100 / 100)
return RGB_linear | def XYZ100_to_sRGB1_linear(XYZ100) | Convert XYZ to linear sRGB, where XYZ is normalized so that reference
white D65 is X=95.05, Y=100, Z=108.90 and sRGB is on the 0-1 scale. Linear
sRGB has a linear relationship to actual light, so it is an appropriate
space for simulating light (e.g. for alpha blending). | 4.090952 | 4.291858 | 0.953189 |
sRGB1 = np.asarray(sRGB1, dtype=float)
sRGB1_linear = C_linear(sRGB1)
return sRGB1_linear | def sRGB1_to_sRGB1_linear(sRGB1) | Convert sRGB (as floats in the 0-to-1 range) to linear sRGB. | 2.964582 | 2.823357 | 1.05002 |
start = norm_cspace_id(start)
end = norm_cspace_id(end)
return GRAPH.get_transform(start, end) | def cspace_converter(start, end) | Returns a function for converting from colorspace ``start`` to
colorspace ``end``.
E.g., these are equivalent::
out = cspace_convert(arr, start, end)
::
start_to_end_fn = cspace_converter(start, end)
out = start_to_end_fn(arr)
If you are doing a large number of conversions b... | 5.480732 | 8.940104 | 0.61305 |
converter = cspace_converter(start, end)
return converter(arr) | def cspace_convert(arr, start, end) | Converts the colors in ``arr`` from colorspace ``start`` to colorspace
``end``.
:param arr: An array-like of colors.
:param start, end: Any supported colorspace specifiers. See
:ref:`supported-colorspaces` for details. | 4.51137 | 16.455105 | 0.274162 |
if observer == "CIE 1931 2 deg":
return np.asarray(cie1931[name], dtype=float)
elif observer == "CIE 1964 10 deg":
return np.asarray(cie1964[name], dtype=float)
else:
raise ValueError("observer must be 'CIE 1931 2 deg' or "
"'CIE 1964 10 deg', not %s" % ... | def standard_illuminant_XYZ100(name, observer="CIE 1931 2 deg") | Takes a string naming a standard illuminant, and returns its XYZ
coordinates (normalized to Y = 100).
We currently have the following standard illuminants in our database:
* ``"A"``
* ``"C"``
* ``"D50"``
* ``"D55"``
* ``"D65"``
* ``"D75"``
If you need another that isn't on this li... | 1.911017 | 1.942561 | 0.983762 |
if isinstance(whitepoint, str):
return standard_illuminant_XYZ100(whitepoint)
else:
whitepoint = np.asarray(whitepoint, dtype=float)
if whitepoint.shape[-1] != 3:
raise ValueError("Bad whitepoint shape")
return whitepoint | def as_XYZ100_w(whitepoint) | A convenience function for getting whitepoints.
``whitepoint`` can be either a string naming a standard illuminant (see
:func:`standard_illuminant_XYZ100`), or else a whitepoint given explicitly
as an array-like of XYZ values.
We internally call this function anywhere you have to specify a whitepoint
... | 2.878629 | 2.345851 | 1.227115 |
assert 0 <= severity <= 100
fraction = severity % 10
low = int(severity - fraction)
high = low + 10
assert low <= severity <= high
low_matrix = np.asarray(MACHADO_ET_AL_MATRICES[cvd_type][low])
if severity == 100:
# Don't try interpolating between 100 and 110, there is no 11... | def machado_et_al_2009_matrix(cvd_type, severity) | Retrieve a matrix for simulating anomalous color vision.
:param cvd_type: One of "protanomaly", "deuteranomaly", or "tritanomaly".
:param severity: A value between 0 and 100.
:returns: A 3x3 CVD simulation matrix as computed by Machado et al
(2009).
These matrices were downloaded from:
... | 3.235425 | 2.87624 | 1.12488 |
rvchk = self.retval.checker
if rvchk:
def _checker(value):
if not rvchk.check(value):
raise self._type_error(
"Incorrect return type in %s: expected %s got %s" %
(self.name_bt, rvchk.name(),
... | def _make_retval_checker(self) | Create a function that checks the return value of the function. | 4.749485 | 4.560753 | 1.041382 |
def _checker(*args, **kws):
# Check if too many arguments are provided
nargs = len(args)
nnonvaargs = min(nargs, self._max_positional_args)
if nargs > self._max_positional_args and self._ivararg is None:
raise self._too_many_args_error(nar... | def _make_args_checker(self) | Create a function that checks signature of the source function. | 2.807571 | 2.776267 | 1.011276 |
try:
if t is True:
return true_checker
if t is False:
return false_checker
checker = memoized_type_checkers.get(t)
if checker is not None:
return checker
hashable = True
except TypeError:
# Exception may be raised if `t` is... | def checker_for_type(t) | Return "checker" function for the given type `t`.
This checker function will accept a single argument (of any type), and
return True if the argument matches type `t`, or False otherwise. For
example:
chkr = checker_for_type(int)
assert chkr.check(123) is True
assert chkr.check("5")... | 3.268788 | 3.859056 | 0.847043 |
if val is None or val is True or val is False:
return str(val)
sval = repr(val)
sval = sval.replace("\n", " ").replace("\t", " ").replace("`", "'")
if len(sval) > maxlen:
sval = sval[:maxlen - 4] + "..." + sval[-1]
if notype:
return sval
else:
tval = checker_... | def _prepare_value(val, maxlen=50, notype=False) | Stringify value `val`, ensuring that it is not too long. | 2.811239 | 2.743119 | 1.024833 |
if n % 10 == 1 and n % 100 != 11:
return "%dst" % n
if n % 10 == 2 and n % 100 != 12:
return "%dnd" % n
if n % 10 == 3 and n % 100 != 13:
return "%drd" % n
return "%dth" % n | def _nth_str(n) | Return posessive form of numeral `n`: 1st, 2nd, 3rd, etc. | 1.496631 | 1.402049 | 1.06746 |
self.data.increaseClass(className)
tokens = self.tokenizer.tokenize(text)
for token in tokens:
token = self.tokenizer.remove_stop_words(token)
token = self.tokenizer.remove_punctuation(token)
self.data.increaseToken(token, className) | def train(self, text, className) | enhances trained data using the given text and class | 3.365457 | 3.324733 | 1.012249 |
def hid_device_path_exists(device_path, guid = None):
# expecing HID devices
if not guid:
guid = winapi.GetHidGuid()
info_data = winapi.SP_DEVINFO_DATA()
info_data.cb_size = sizeof(winapi.SP_DEVINFO_DATA)
with winapi.DeviceInterfaceSetInfo(guid) as h_info:
fo... | Test if required device_path is still valid
(HID device connected to host) | null | null | null | |
def find_all_hid_devices():
"Finds all HID devices connected to the system"
#
# From DDK documentation (finding and Opening HID collection):
# After a user-mode application is loaded, it does the following sequence
# of operations:
#
# * Calls HidD_GetHidGuid to obtain the system-de... | Finds all HID devices connected to the system | null | null | null | |
def show_hids(target_vid = 0, target_pid = 0, output = None):
# first be kind with local encodings
if not output:
# beware your script should manage encodings
output = sys.stdout
# then the big cheese...
from . import tools
all_hids = None
if target_vid:
if... | Check all HID devices conected to PC hosts. | null | null | null | |
def get_devices_by_parent(self, hid_filter=None):
all_devs = self.get_devices(hid_filter)
dev_group = dict()
for hid_device in all_devs:
#keep a list of known devices matching parent device Ids
parent_id = hid_device.get_parent_instance_id()
de... | Group devices returned from filter query in order \
by devcice parent id. | null | null | null | |
def get_devices(self, hid_filter = None):
if not hid_filter: #empty list or called without any parameters
if type(hid_filter) == type(None):
#request to query connected devices
hid_filter = find_all_hid_devices()
else:
retur... | Filter a HID device list by current object parameters. Devices
must match the all of the filtering parameters | null | null | null | |
def get_parent_device(self):
if not self.parent_instance_id:
return ""
dev_buffer_type = winapi.c_tchar * MAX_DEVICE_ID_LEN
dev_buffer = dev_buffer_type()
try:
if winapi.CM_Get_Device_ID(self.parent_instance_id, byref(dev_buffer),
... | Retreive parent device string id | null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.