signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
@verify_type(component=(str, Component))<EOL><INDENT>def reset_component(self, component):<DEDENT> | if isinstance(component, str) is True:<EOL><INDENT>component = WURI.Component(component)<EOL><DEDENT>self.__components[component] = None<EOL> | Unset component in this URI
:param component: component name (or component type) to reset
:return: None | f9844:c0:m4 |
@classmethod<EOL><INDENT>@verify_type(uri=str)<EOL>def parse(cls, uri):<DEDENT> | uri_components = urlsplit(uri)<EOL>adapter_fn = lambda x: x if x is not None and (isinstance(x, str) is False or len(x)) > <NUM_LIT:0> else None<EOL>return cls(<EOL>scheme=adapter_fn(uri_components.scheme),<EOL>username=adapter_fn(uri_components.username),<EOL>password=adapter_fn(uri_components.password),<EOL>hostname=... | Parse URI-string and return WURI object
:param uri: string to parse
:return: WURI | f9844:c0:m5 |
def __iter__(self): | for component in WURI.Component:<EOL><INDENT>component_name = component.value<EOL>component_value_fn = getattr(self, component_name)<EOL>yield component, component_value_fn()<EOL><DEDENT> | Iterate over URI components. This method yields tuple of component name and its value
:return: generator | f9844:c0:m6 |
def __init__(self): | self.__query = {}<EOL> | Create new query component | f9844:c1:m0 |
@verify_type(name=str, value=(str, None))<EOL><INDENT>def replace_parameter(self, name, value=None):<DEDENT> | self.__query[name] = [value]<EOL> | Replace parameter in this query. All previously added values will be discarded
:param name: parameter name to replace
:param value: parameter value to set (None to set null-value)
:return: None | f9844:c1:m1 |
@verify_type(name=str, value=(str, None))<EOL><INDENT>def add_parameter(self, name, value=None):<DEDENT> | if name not in self.__query:<EOL><INDENT>self.__query[name] = [value]<EOL><DEDENT>else:<EOL><INDENT>self.__query[name].append(value)<EOL><DEDENT> | Add new parameter value to this query. New value will be appended to previously added values.
:param name: parameter name
:param value: value to add (None to set null-value)
:return: None | f9844:c1:m2 |
@verify_type(name=str)<EOL><INDENT>def remove_parameter(self, name):<DEDENT> | if name in self.__query:<EOL><INDENT>self.__query.pop(name)<EOL><DEDENT> | Remove the specified parameter from this query
:param name: name of a parameter to remove
:return: None | f9844:c1:m3 |
@verify_type(item=str)<EOL><INDENT>def __contains__(self, item):<DEDENT> | return item in self.__query<EOL> | Check if this query has the specified parameter
:param item: parameter name to check
:return: bool | f9844:c1:m4 |
def __str__(self): | parameters = {x: [y if y is not None else '<STR_LIT>' for y in self.__query[x]] for x in self.__query}<EOL>return urlencode(parameters, True)<EOL> | Encode parameters from this query, so it can be use in URI
:return: str | f9844:c1:m5 |
@verify_type(item=str)<EOL><INDENT>def __getitem__(self, item):<DEDENT> | return tuple(self.__query[item])<EOL> | Return all parameters values
:param item: parameter name to retrieve
:return: tuple of str and None | f9844:c1:m6 |
def __iter__(self): | for name in self.__query:<EOL><INDENT>yield name<EOL><DEDENT> | Iterate over parameters names
:return: str | f9844:c1:m7 |
@classmethod<EOL><INDENT>@verify_type(query_str=str)<EOL>def parse(cls, query_str):<DEDENT> | parsed_query = parse_qs(query_str, keep_blank_values=True, strict_parsing=True)<EOL>result = cls()<EOL>for parameter_name in parsed_query.keys():<EOL><INDENT>for parameter_value in parsed_query[parameter_name]:<EOL><INDENT>result.add_parameter(<EOL>parameter_name,<EOL>parameter_value if len(parameter_value) > <NUM_LIT:... | Parse string that represent query component from URI
:param query_str: string without '?'-sign
:return: WURIQuery | f9844:c1:m8 |
@verify_type(base_query=WURIQuery, specs=ParameterSpecification, extra_parameters=bool)<EOL><INDENT>def __init__(self, base_query, *specs, extra_parameters=True):<DEDENT> | WURIQuery.__init__(self)<EOL>self.__specs = {}<EOL>self.__extra_parameters = extra_parameters<EOL>for spec in specs:<EOL><INDENT>self.add_specification(spec)<EOL><DEDENT>for name in base_query:<EOL><INDENT>for value in base_query[name]:<EOL><INDENT>self.add_parameter(name, value)<EOL><DEDENT><DEDENT>for name in self.__... | Create new strict query
:param base_query: base query, that must match all of the specifications
:param specs: list of parameters specifications
:param extra_parameters: whether parameters that was not specified in "specs" are allowed | f9844:c2:m0 |
def extra_parameters(self): | return self.__extra_parameters<EOL> | Return flag, whether query parameters that was not specified in "specs" are allowed
:return: bool | f9844:c2:m1 |
@verify_type(specification=ParameterSpecification)<EOL><INDENT>def replace_specification(self, specification):<DEDENT> | self.__specs[specification.name()] = specification<EOL> | Replace current query parameter specification or add new one. No checks for the specified or any
parameter are made regarding specification replacement
:param specification: new specification that will replace specification for the corresponding parameter
:return: None | f9844:c2:m2 |
@verify_type(specification=ParameterSpecification)<EOL><INDENT>def add_specification(self, specification):<DEDENT> | name = specification.name()<EOL>if name in self.__specs:<EOL><INDENT>raise ValueError('<STR_LIT>' % name)<EOL><DEDENT>self.__specs[name] = specification<EOL> | Add a new query parameter specification. If this object already has a specification for the
specified parameter - exception is raised. No checks for the specified or any parameter are made
regarding specification appending
:param specification: new specification that will be added
:retu... | f9844:c2:m3 |
@verify_type(name=str)<EOL><INDENT>def remove_specification(self, name):<DEDENT> | if name in self.__specs:<EOL><INDENT>self.__specs.pop(name)<EOL><DEDENT> | Remove a specification that matches a query parameter. No checks for the specified or any parameter
are made regarding specification removing
:param name: parameter name to remove
:return: None | f9844:c2:m4 |
@verify_type(name=str, value=(str, None))<EOL><INDENT>def replace_parameter(self, name, value=None):<DEDENT> | spec = self.__specs[name] if name in self.__specs else None<EOL>if self.extra_parameters() is False and spec is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if spec is not None and spec.nullable() is False and value is None:<EOL><INDENT>raise ValueError('<STR_LIT>' % name)<EOL><DEDENT>if spec is not None... | Replace a query parameter values with a new value. If a new value does not match current
specifications, then exception is raised
:param name: parameter name to replace
:param value: new parameter value. None is for empty (null) value
:return: None | f9844:c2:m5 |
@verify_type(name=str, value=(str, None))<EOL><INDENT>def add_parameter(self, name, value=None):<DEDENT> | spec = self.__specs[name] if name in self.__specs else None<EOL>if self.extra_parameters() is False and spec is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if spec is not None and spec.nullable() is False and value is None:<EOL><INDENT>raise ValueError('<STR_LIT>' % name)<EOL><DEDENT>if spec is not None... | Add a query parameter and its value. If this query already has a parameter, or a new value does
not match current specifications, then exception is raised
:param name: parameter name to add
:param value: parameter value. None is for empty (null) value
:return: None | f9844:c2:m6 |
@verify_type(name=str)<EOL><INDENT>def remove_parameter(self, name):<DEDENT> | spec = self.__specs[name] if name in self.__specs else None<EOL>if spec is not None and spec.optional() is False:<EOL><INDENT>raise ValueError('<STR_LIT>' % name)<EOL><DEDENT>WURIQuery.remove_parameter(self, name)<EOL> | Remove parameter from this query. If a parameter is mandatory, then exception is raised
:param name: parameter name to remove
:return: None | f9844:c2:m7 |
@classmethod<EOL><INDENT>@verify_type(query_name=str)<EOL>def parse(cls, query_str):<DEDENT> | return WURIQuery.parse(query_str)<EOL> | :meth:`.WURIQuery.parse` method implementation. Returns :class:`.WURIQuery instead of
:class:`.WStrictURIQuery`
:return: WURIQuery | f9844:c2:m8 |
@classmethod<EOL><INDENT>@verify_type(query_str=str, specs=ParameterSpecification, extra_parameters=bool)<EOL>def strict_parse(cls, query_str, *specs, extra_parameters=True):<DEDENT> | plain_result = cls.parse(query_str)<EOL>return WStrictURIQuery(plain_result, *specs, extra_parameters=extra_parameters)<EOL> | Parse query and return :class:`.WStrictURIQuery` object
:param query_str: query component of URI to parse
:param specs: list of parameters specifications
:param extra_parameters: whether parameters that was not specified in "specs" are allowed
:return: WStrictURIQuery | f9844:c2:m9 |
@verify_type(component=WURI.Component, requirement=Requirement, reg_exp=(str, None))<EOL><INDENT>def __init__(self, component, requirement, reg_exp=None):<DEDENT> | self.__component = component<EOL>self.__requirement = requirement<EOL>self.__re_obj = re.compile(reg_exp) if reg_exp is not None else None<EOL> | Create new URI component descriptor
:param component: URI component, that
:param requirement: URI component necessity
:param reg_exp: If specified - a regular expression, which URI component value (if defined) must match | f9844:c3:m0 |
def component(self): | return self.__component<EOL> | Return an URI component, that this specification is describing
:return: WURI.Component | f9844:c3:m1 |
def requirement(self): | return self.__requirement<EOL> | Return an URI component necessity
:return: WURIComponentVerifier.Requirement | f9844:c3:m2 |
def re_obj(self): | return self.__re_obj<EOL> | If it was specified in a constructor, return regular expression object, that may be used for
matching
:return: re module object or None | f9844:c3:m3 |
@verify_type(uri=WURI)<EOL><INDENT>def validate(self, uri):<DEDENT> | requirement = self.requirement()<EOL>uri_component = uri.component(self.component())<EOL>if uri_component is None:<EOL><INDENT>return requirement != WURIComponentVerifier.Requirement.required<EOL><DEDENT>if requirement == WURIComponentVerifier.Requirement.unsupported:<EOL><INDENT>return False<EOL><DEDENT>re_obj = self.... | Check an URI for compatibility with this specification. Return True if the URI is compatible.
:param uri: an URI to check
:return: bool | f9844:c3:m4 |
@verify_type('<STR_LIT>', requirement=WURIComponentVerifier.Requirement)<EOL><INDENT>@verify_type(specs=WStrictURIQuery.ParameterSpecification, extra_parameters=bool)<EOL>def __init__(self, requirement, *specs, extra_parameters=True):<DEDENT> | WURIComponentVerifier.__init__(self, WURI.Component.query, requirement)<EOL>self.__specs = specs<EOL>self.__extra_parameters = extra_parameters<EOL> | Create new query descriptor
:param requirement: same as 'requirement' in :meth:`.WURIComponentVerifier.__init__`
:param specs: list of parameters specifications
:param extra_parameters: whether parameters that was not specified in "specs" are allowed | f9844:c4:m0 |
@verify_type('<STR_LIT>', uri=WURI)<EOL><INDENT>def validate(self, uri):<DEDENT> | if WURIComponentVerifier.validate(self, uri) is False:<EOL><INDENT>return False<EOL><DEDENT>try:<EOL><INDENT>WStrictURIQuery(<EOL>WURIQuery.parse(uri.component(self.component())),<EOL>*self.__specs,<EOL>extra_parameters=self.__extra_parameters<EOL>)<EOL><DEDENT>except ValueError:<EOL><INDENT>return False<EOL><DEDENT>re... | Check that an query part of an URI is compatible with this descriptor. Return True if the URI is
compatible.
:param uri: an URI to check
:return: bool | f9844:c4:m1 |
@verify_type(scheme_name=str, verifiers=WURIComponentVerifier)<EOL><INDENT>def __init__(self, scheme_name, *verifiers):<DEDENT> | self.__scheme_name = scheme_name<EOL>self.__verifiers = {<EOL>WURI.Component.scheme: WURIComponentVerifier(<EOL>WURI.Component.scheme, WURIComponentVerifier.Requirement.required<EOL>)<EOL>}<EOL>for verifier in verifiers:<EOL><INDENT>component = verifier.component()<EOL>if component in self.__verifiers:<EOL><INDENT>rais... | Create new scheme specification. Every component that was not described by this method is treated
as unsupported
:param scheme_name: URI scheme value
:param verifiers: list of specifications for URI components | f9844:c5:m0 |
def scheme_name(self): | return self.__scheme_name<EOL> | Return scheme name that this specification is describing
:return: str | f9844:c5:m1 |
@verify_type(component=WURI.Component)<EOL><INDENT>def verifier(self, component):<DEDENT> | return self.__verifiers[component]<EOL> | Return descriptor for the specified component
:param component: component name which descriptor should be returned
:return: WSchemeSpecification.ComponentDescriptor | f9844:c5:m2 |
def __iter__(self): | for component in WURI.Component:<EOL><INDENT>yield component, self.__verifiers[component]<EOL><DEDENT> | Iterate over URI components. This method yields tuple of component (:class:`.WURI.Component`) and
its descriptor (WURIComponentVerifier)
:return: generator | f9844:c5:m3 |
@verify_type(uri=WURI)<EOL><INDENT>def is_compatible(self, uri):<DEDENT> | for component, component_value in uri:<EOL><INDENT>if self.verifier(component).validate(uri) is False:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL> | Check if URI is compatible with this specification. Compatible URI has scheme name that matches
specification scheme name, has all of the required components, does not have unsupported components
and may have optional components
:param uri: URI to check
:return: bool | f9844:c5:m4 |
@classmethod<EOL><INDENT>@abstractmethod<EOL>def scheme_specification(cls):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Return scheme specification
:return: WSchemeSpecification | f9844:c6:m0 |
@classmethod<EOL><INDENT>@abstractmethod<EOL>@verify_type(uri=WURI)<EOL>def create_handler(cls, uri, **kwargs):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Return handler instance
:param uri: original URI, that a handler is created for
:param kwargs: additional arguments that may be used by a handler specialization
:return: WSchemeHandler | f9844:c6:m1 |
def __init__(self, *scheme_handlers_cls, default_handler_cls=None): | self.__handlers_cls = []<EOL>self.__default_handler_cls = default_handler_cls<EOL>for handler_cls in scheme_handlers_cls:<EOL><INDENT>self.add(handler_cls)<EOL><DEDENT> | Create new collection
:param scheme_handlers_cls: handlers to add to this collection
:param default_handler: handler that must be called for a URI that does not have scheme component | f9844:c7:m0 |
@verify_subclass(scheme_handler_cls=WSchemeHandler)<EOL><INDENT>def add(self, scheme_handler_cls):<DEDENT> | self.__handlers_cls.append(scheme_handler_cls)<EOL> | Append the specified handler to this collection
:param scheme_handler_cls: handler that should be added
:return: None | f9844:c7:m1 |
def handler(self, scheme_name=None): | if scheme_name is None:<EOL><INDENT>return self.__default_handler_cls<EOL><DEDENT>for handler in self.__handlers_cls:<EOL><INDENT>if handler.scheme_specification().scheme_name() == scheme_name:<EOL><INDENT>return handler<EOL><DEDENT><DEDENT> | Return handler which scheme name matches the specified one
:param scheme_name: scheme name to search for
:return: WSchemeHandler class or None (if matching handler was not found) | f9844:c7:m2 |
@verify_type(uri=WURI)<EOL><INDENT>def open(self, uri, **kwargs):<DEDENT> | handler = self.handler(uri.scheme())<EOL>if handler is None:<EOL><INDENT>raise WSchemeCollection.NoHandlerFound(uri)<EOL><DEDENT>if uri.scheme() is None:<EOL><INDENT>uri.component('<STR_LIT>', handler.scheme_specification().scheme_name())<EOL><DEDENT>if handler.scheme_specification().is_compatible(uri) is False:<EOL><I... | Return handler instance that matches the specified URI. WSchemeCollection.NoHandlerFound and
WSchemeCollection.SchemeIncompatible may be raised.
:param uri: URI to search handler for
:param kwargs: additional arguments that may be used by a handler specialization
:return: WSchemeHandler | f9844:c7:m3 |
def verify_type(*tags, **type_kwargs): | return TypeVerifier(*tags).decorator(**type_kwargs)<EOL> | Shortcut for :class:`.TypeVerifier`
:param tags: verification tags. See :meth:`.Verifier.__init__`
:param type_kwargs: verifier specification. See :meth:`.TypeVerifier.check`
:return: decorator (function) | f9845:m0 |
def verify_subclass(*tags, **type_kwargs): | return SubclassVerifier(*tags).decorator(**type_kwargs)<EOL> | Shortcut for :class:`.SubclassVerifier`
:param tags: verification tags. See :meth:`.Verifier.__init__`
:param type_kwargs: verifier specification. See :meth:`.SubclassVerifier.check`
:return: decorator (function) | f9845:m1 |
def verify_value(*tags, **type_kwargs): | return ValueVerifier(*tags).decorator(**type_kwargs)<EOL> | Shortcut for :class:`.ValueVerifier`
:param tags: verification tags. See :meth:`.Verifier.__init__`
:param type_kwargs: verifier specification. See :meth:`.ValueVerifier.check`
:return: decorator (function) | f9845:m2 |
def __init__(self, *tags, env_var=None, silent_checks=False): | self._tags = list(tags)<EOL>self._env_var = env_var if env_var is not None else self.__class__.__environment_var__<EOL>self._silent_checks = silent_checks<EOL> | Construct a new :class:`.Verifier`
:param tags: Tags to mark this checks. Only strings are supported
:param env_var: Environment variable name that is used for check bypassing. If is None, then default \
value is used :attr:`.Verifier.__environment_var__`
:param silent_checks: If it is... | f9845:c0:m0 |
def decorate_disabled(self): | if len(self._tags) == <NUM_LIT:0>:<EOL><INDENT>return False<EOL><DEDENT>if self._env_var not in os.environ:<EOL><INDENT>return True<EOL><DEDENT>env_tags = os.environ[self._env_var].split(self.__class__.__tags_delimiter__)<EOL>if '<STR_LIT:*>' in env_tags:<EOL><INDENT>return False<EOL><DEDENT>for tag in self._tags:<EOL>... | Return True if this decoration must be omitted, otherwise - False.
This class searches for tags values in environment variable
(:attr:`.Verifier.__environment_var__`), Derived class can implement any logic
:return: bool | f9845:c0:m1 |
def check(self, arg_spec, arg_name, decorated_function): | return lambda x: None<EOL> | Return callable object that takes single value - future argument. This callable must raise
an exception if error occurs. It is recommended to return None if everything is OK
:param arg_spec: specification that is used to describe check like types, lambda-functions, \
list of types just anything... | f9845:c0:m2 |
def _args_checks_gen(self, decorated_function, function_spec, arg_specs): | inspected_args = function_spec.args<EOL>args_check = {}<EOL>for i in range(len(inspected_args)):<EOL><INDENT>arg_name = inspected_args[i]<EOL>if arg_name in arg_specs.keys():<EOL><INDENT>args_check[arg_name] = self.check(arg_specs[arg_name], arg_name, decorated_function)<EOL><DEDENT><DEDENT>return args_check<EOL> | Generate checks for positional argument testing
:param decorated_function: function decorator
:param function_spec: function inspect information
:param arg_specs: argument specification (same as arg_specs in :meth:`.Verifier.decorate`)
:return: internal structure, that is used by :meth... | f9845:c0:m3 |
def _varargs_checks_gen(self, decorated_function, function_spec, arg_specs): | inspected_varargs = function_spec.varargs<EOL>if inspected_varargs is not None and inspected_varargs in arg_specs.keys():<EOL><INDENT>return self.check(<EOL>arg_specs[inspected_varargs], inspected_varargs, decorated_function<EOL>)<EOL><DEDENT> | Generate checks for positional variable argument (varargs) testing
:param decorated_function: function decorator
:param function_spec: function inspect information
:param arg_specs: argument specification (same as arg_specs in :meth:`.Verifier.decorate`)
:return: internal structure, th... | f9845:c0:m5 |
def _kwargs_checks_gen(self, decorated_function, function_spec, arg_specs): | args_names = []<EOL>args_names.extend(function_spec.args)<EOL>if function_spec.varargs is not None:<EOL><INDENT>args_names.append(function_spec.args)<EOL><DEDENT>args_check = {}<EOL>for arg_name in arg_specs.keys():<EOL><INDENT>if arg_name not in args_names:<EOL><INDENT>args_check[arg_name] = self.check(<EOL>arg_specs[... | Generate checks for keyword argument testing
:param decorated_function: function decorator
:param function_spec: function inspect information
:param arg_specs: argument specification (same as arg_specs in :meth:`.Verifier.decorate`)
:return: internal structure, that is used by :meth:`.... | f9845:c0:m7 |
def decorator(self, **arg_specs): | if self.decorate_disabled() is True:<EOL><INDENT>def empty_decorator(decorated_function):<EOL><INDENT>return decorated_function<EOL><DEDENT>return empty_decorator<EOL><DEDENT>def first_level_decorator(decorated_function):<EOL><INDENT>function_spec = getfullargspec(decorated_function)<EOL>args_checks = self._args_checks... | Return decorator that can decorate target function
:param arg_specs: dictionary where keys are parameters name and values are theirs specification.\
Specific specification is passed as is to :meth:`Verifier.check` method with corresponding \
parameter name.
:return: function | f9845:c0:m9 |
def help_info(self, exc, decorated_function, arg_name, arg_spec): | if self._silent_checks is not True:<EOL><INDENT>print('<STR_LIT>', file=sys.stderr)<EOL>print(str(exc), file=sys.stderr)<EOL>fn_name = Verifier.function_name(decorated_function)<EOL>print('<STR_LIT>' % fn_name, file=sys.stderr)<EOL>if decorated_function.__doc__ is not None:<EOL><INDENT>print('<STR_LIT>', file=sys.stder... | Print debug information to stderr. (Do nothing if object was constructed with silent_checks=True)
:param exc: raised exception
:param decorated_function: target function (function to decorate)
:param arg_name: function parameter name
:param arg_spec: function parameter specification
... | f9845:c0:m10 |
@staticmethod<EOL><INDENT>def function_name(fn):<DEDENT> | fn_name = fn.__name__<EOL>if hasattr(fn, '<STR_LIT>'):<EOL><INDENT>return fn.__qualname__<EOL><DEDENT>elif hasattr(fn, '<STR_LIT>'):<EOL><INDENT>owner = fn.__self__<EOL>if isclass(owner) is False:<EOL><INDENT>owner = owner.__class__<EOL><DEDENT>return '<STR_LIT>' % (owner.__name__, fn_name)<EOL><DEDENT>return fn_name<E... | Return function name in pretty style
:param fn: source function
:return: str | f9845:c0:m11 |
def check(self, type_spec, arg_name, decorated_function): | def raise_exception(x_spec):<EOL><INDENT>exc_text = '<STR_LIT>' % (<EOL>arg_name, Verifier.function_name(decorated_function)<EOL>)<EOL>exc_text += '<STR_LIT>' % (x_spec, type_spec)<EOL>raise TypeError(exc_text)<EOL><DEDENT>if isinstance(type_spec, (tuple, list, set)):<EOL><INDENT>for single_type in type_spec:<EOL><INDE... | Return callable that checks function parameter for type validity. Checks parameter if it is
instance of specified class or classes
:param type_spec: type or list/tuple/set of types
:param arg_name: function parameter name
:param decorated_function: target function
:return: funct... | f9845:c1:m0 |
def check(self, type_spec, arg_name, decorated_function): | def raise_exception(text_spec):<EOL><INDENT>exc_text = '<STR_LIT>' % (<EOL>arg_name, Verifier.function_name(decorated_function)<EOL>)<EOL>exc_text += '<STR_LIT>' % text_spec<EOL>raise TypeError(exc_text)<EOL><DEDENT>if isinstance(type_spec, (tuple, list, set)):<EOL><INDENT>for single_type in type_spec:<EOL><INDENT>if (... | Return callable that checks function parameter for class validity. Checks parameter if it is
class or subclass of specified class or classes
:param type_spec: type or list/tuple/set of types
:param arg_name: function parameter name
:param decorated_function: target function
:ret... | f9845:c2:m0 |
def check(self, value_spec, arg_name, decorated_function): | def raise_exception(text_spec):<EOL><INDENT>exc_text = '<STR_LIT>' % (<EOL>arg_name, Verifier.function_name(decorated_function)<EOL>)<EOL>exc_text += '<STR_LIT>' % text_spec<EOL>raise ValueError(exc_text)<EOL><DEDENT>if isinstance(value_spec, (tuple, list, set)):<EOL><INDENT>for single_value in value_spec:<EOL><INDENT>... | Return callable that checks function parameter for value validity. Checks parameter if its value
passes specified restrictions.
:param value_spec: function or list/tuple/set of functions. Each function must accept one parameter and \
must return True or False if it passed restrictions or not.
... | f9845:c3:m0 |
@verify_type(size=int, value=(WBinArray, int, bytes, None))<EOL><INDENT>@verify_value(size=lambda x: x >= <NUM_LIT:0>)<EOL>def __init__(self, size=<NUM_LIT:0>, value=None):<DEDENT> | self.__array = []<EOL>self.__size = size<EOL>for i in range(self.__size):<EOL><INDENT>self.__array.append(WBinArray(<NUM_LIT:0>, self.__class__.byte_size))<EOL><DEDENT>if value is not None:<EOL><INDENT>if isinstance(value, (WBinArray, int)) is True:<EOL><INDENT>value = WBinArray(int(value), self.__size * self.__class__... | Construct new array.
:param size: count of bytes
:param value: value with which this sequence must be initialized (default 0) | f9847:c0:m0 |
def bin_value(self): | return WBinArray.join(*self.__array)<EOL> | Return this sequence as single big WBinArray
:return: WBinArray | f9847:c0:m1 |
def bin_array(self): | return self.__array<EOL> | Return this sequence as list of bytes (WBinArray)
:return: list of WBinArray | f9847:c0:m2 |
def resize(self, size): | if size < len(self):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>current_size = self.__size<EOL>for i in range(size - current_size):<EOL><INDENT>self.__array.append(WBinArray(<NUM_LIT:0>, self.__class__.byte_size))<EOL><DEDENT>self.__size = size<EOL> | Grow this array to specified length. This array can't be shrinked
:param size: new length
:return: None | f9847:c0:m3 |
def __len__(self): | return self.__size<EOL> | Return count of bytes
:return: int | f9847:c0:m4 |
def __str__(self): | return str([str(x) for x in self.__array])<EOL> | Convert to string
:return: str | f9847:c0:m5 |
def __getitem__(self, item): | return self.__array[item]<EOL> | Return byte (WBinArray) at specified index
:param item: item index
:return: WBinArray | f9847:c0:m6 |
@verify_type('<STR_LIT>', value=(WBinArray, int))<EOL><INDENT>@verify_type(key=int)<EOL>def __setitem__(self, key, value):<DEDENT> | if key < <NUM_LIT:0> or key >= len(self):<EOL><INDENT>raise IndexError('<STR_LIT>')<EOL><DEDENT>self.__array[key] = WBinArray(value, self.__class__.byte_size)<EOL> | Set value for the given index. Specified value must resign within byte capability (must be non
negative and be less then 2^<byte_size>).
:param key: item index
:param value: value to set
:return: None | f9847:c0:m7 |
def __bytes__(self): | return bytes([int(x) for x in self.__array])<EOL> | Convert to bytes
:return: bytes | f9847:c0:m8 |
def swipe(self): | result = WFixedSizeByteArray(len(self))<EOL>for i in range(len(self)):<EOL><INDENT>result[len(self) - i - <NUM_LIT:1>] = self[i]<EOL><DEDENT>return result<EOL> | Mirror current array value in reverse. Bytes that had greater index will have lesser index, and
vice-versa. This method doesn't change this array. It creates a new one and return it as a result.
:return: WFixedSizeByteArray | f9847:c0:m9 |
@verify_type(size=(int, None))<EOL><INDENT>@verify_value(value=lambda x: int(x) >= <NUM_LIT:0>, size=lambda x: x is None or x >= <NUM_LIT:0>)<EOL>def __init__(self, value=<NUM_LIT:0>, size=None):<DEDENT> | if isinstance(value, (int, WBinArray)) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>self.__value = int(value)<EOL>self.__size = size<EOL>if self.__size is not None:<EOL><INDENT>if self.__value > ((<NUM_LIT:2> ** self.__size) - <NUM_LIT:1>):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT... | Create new bit sequence.
:param value: value with which this sequence must be initialized.
:param size: sequence fixed size (number of bits). | f9848:c0:m0 |
def __len__(self): | if self.__size is not None:<EOL><INDENT>return self.__size<EOL><DEDENT>elif self.__value == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>return self.__value.bit_length()<EOL><DEDENT> | Return size if array has fixed size, otherwise return bits count
:return: int | f9848:c0:m1 |
@verify_type(item=(int, slice))<EOL><INDENT>def __getitem__(self, item):<DEDENT> | if isinstance(item, int):<EOL><INDENT>if item >= self.__len__() or item < <NUM_LIT:0>:<EOL><INDENT>raise IndexError('<STR_LIT>')<EOL><DEDENT>mask = <NUM_LIT:1> << (len(self) - item - <NUM_LIT:1>)<EOL>return <NUM_LIT:1> if (self.__value & mask) > <NUM_LIT:0> else <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>start = item.st... | Return bit value for specified index or array part defined by the slice
:param item: index or slice object
:return: int for single item, WBinArray for slice | f9848:c0:m2 |
@verify_type(key=int)<EOL><INDENT>@verify_value(value=lambda x: int(x) >= <NUM_LIT:0>)<EOL>def __setitem__(self, key, value):<DEDENT> | if isinstance(value, (int, WBinArray)) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>value = int(value)<EOL>if self.__size is not None:<EOL><INDENT>if key < <NUM_LIT:0> or key >= len(self):<EOL><INDENT>raise IndexError('<STR_LIT>')<EOL><DEDENT>length = len(WBinArray(value))<EOL>if (key + length - <NUM_... | Set value for the given index. If value is greater then 1 or value is a WBinArray with length
greater then 1, then all the bits are copied from original value to this array starting by the key
index.
:param key: starting position
:param value: value to set
:return: None | f9848:c0:m3 |
def __int__(self): | if self.__size is None:<EOL><INDENT>return self.__value<EOL><DEDENT>else:<EOL><INDENT>mask = ((<NUM_LIT:2> ** self.__size) - <NUM_LIT:1>)<EOL>return self.__value & mask<EOL><DEDENT> | Convert to integer
:return: int | f9848:c0:m4 |
def __str__(self): | format_str = "<STR_LIT>" % len(self)<EOL>return format_str.format(self.__int__())<EOL> | Convert to string
:return: str | f9848:c0:m5 |
def __add__(self, other): | return self.__int__() + other.__int__()<EOL> | Return addition of two objects
:param other: second summand
:return: int | f9848:c0:m6 |
def __sub__(self, other): | return self.__int__() - other.__int__()<EOL> | Return subtraction of two objects
:param other: subtrahend
:return: int | f9848:c0:m7 |
@verify_type(size=(int, None))<EOL><INDENT>@verify_value(size=lambda x: x >= <NUM_LIT:0>)<EOL>def resize(self, size):<DEDENT> | if size is not None:<EOL><INDENT>self.__value = int(WBinArray(self.__value)[:size])<EOL><DEDENT>self.__size = size<EOL> | Resize current array. If size is None, then array became nonfixed-length array. If new size is
less then current size and value, then value will be truncated (lesser significant bits will be
truncated).
:param size:
:return: | f9848:c0:m8 |
@verify_type(bits_count=int)<EOL><INDENT>@verify_value(bits_count=lambda x: x > <NUM_LIT:0>)<EOL>def split(self, bits_count):<DEDENT> | result = []<EOL>array = WBinArray(self.__value, self.__size)<EOL>if (len(array) % bits_count) > <NUM_LIT:0>:<EOL><INDENT>array.resize(len(array) + (bits_count - (len(array) % bits_count)))<EOL><DEDENT>while len(array):<EOL><INDENT>result.append(WBinArray(array[:bits_count], bits_count))<EOL>array = array[bits_count:]<E... | Split array into smaller parts. Each small array is fixed-length WBinArray (length of that array is
bits_count).
:param bits_count: array length
:return: list of WBinArray | f9848:c0:m9 |
def concat(self, array): | if isinstance(array, WBinArray) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>value = ((int(self) << len(array)) | int(array))<EOL>return WBinArray(value, len(self) + len(array))<EOL> | Return new fixed-length array, that is made by creating new array with length of sum of two arrays
(this array and the given one). In newly created array the most significant bit of the given array
will have an index lesser then an index of the least significant bit of this array.
:param array:... | f9848:c0:m10 |
def rconcat(self, array): | if isinstance(array, WBinArray) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>return array.concat(self)<EOL> | Reverse' concatenation. Works the same as :meth:`.WBinArray.concat`, but in newly created array
the most significant bit of the given array will have an index greater then an index of the least
significant bit of this array
:param array: array to concatenate with
:return: WBinArray | f9848:c0:m11 |
def extend(self, *array_list): | result = WBinArray(int(self), len(self))<EOL>for array in array_list:<EOL><INDENT>result = result.concat(array)<EOL><DEDENT>return result<EOL> | Concatenate this array with the given arrays. This method doesn't modify current array. Instead,
it creates new one, that have all of arrays. (see :meth:`.WBinArray.concat` method)
:param array_list: list of WBinArray
:return: newly created WBinArray | f9848:c0:m12 |
def swipe(self): | result = WBinArray(<NUM_LIT:0>, len(self))<EOL>for i in range(len(self)):<EOL><INDENT>result[len(self) - i - <NUM_LIT:1>] = self[i]<EOL><DEDENT>return result<EOL> | Mirror current array value in reverse. Bits that had greater index will have lesser index, and
vice-versa. This method doesn't change this array. It creates a new one and return it as a result.
:return: WBinArray | f9848:c0:m13 |
@staticmethod<EOL><INDENT>def join(*args):<DEDENT> | if len(args) == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>result = WBinArray(int(args[<NUM_LIT:0>]), len(args[<NUM_LIT:0>]))<EOL>if len(args) == <NUM_LIT:1>:<EOL><INDENT>return result<EOL><DEDENT>else:<EOL><INDENT>result = result.extend(*(args[<NUM_LIT:1>:]))<EOL><DEDENT>return result<EOL> | Concatenate all of the given arrays. (see :meth:`.WBinArray.concat` method)
:param args: list of WBinArray
:return: WBinArray | f9848:c0:m14 |
def __init__(self): | WMessengerOnionLayerProto.__init__(self, WMessengerComposerLayer.__layer_name__)<EOL> | Construct new layer | f9849:c0:m0 |
@verify_type('<STR_LIT>', envelope=WMessengerEnvelopeProto, session=WMessengerOnionSessionProto, mode=Mode)<EOL><INDENT>@verify_type('<STR_LIT>', composer_factory=WComposerFactory)<EOL>def process(self, envelope, session, mode=None, composer_factory=None, **kwargs):<DEDENT> | if mode == WMessengerComposerLayer.Mode.compose:<EOL><INDENT>return self.compose(envelope, session, composer_factory, **kwargs)<EOL><DEDENT>elif mode == WMessengerComposerLayer.Mode.decompose:<EOL><INDENT>return self.decompose(envelope, session, composer_factory, **kwargs)<EOL><DEDENT>raise RuntimeError('<STR_LIT>')<EO... | :meth:`.WMessengerOnionLayerProto.process` implementation | f9849:c0:m1 |
@verify_type(meta=(WMessengerEnvelopeProto, dict, None))<EOL><INDENT>def __init__(self, data, meta=None):<DEDENT> | self.__data = data<EOL>self.__meta = {}<EOL>if meta is not None:<EOL><INDENT>if isinstance(meta, WMessengerEnvelopeProto) is True:<EOL><INDENT>if isinstance(meta, WMessengerEnvelope) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>self.__meta = meta.meta()<EOL><DEDENT>elif isinstance(meta, dict):<EOL><IN... | Construct new envelope
:param data: original message
:param meta: envelope meta-data to copy | f9850:c0:m0 |
def message(self): | return self.__data<EOL> | Return original message
:return: any type | f9850:c0:m1 |
def meta(self): | return self.__meta.copy()<EOL> | Return envelope dictionary copy
:return: dict | f9850:c0:m2 |
@verify_type(key=str)<EOL><INDENT>def add_meta(self, key, value):<DEDENT> | self.__meta[key] = value<EOL> | Add meta-information (value) for the given key
:param key: meta-key
:param value: meta-value
:return: None | f9850:c0:m3 |
def __init__(self): | WMessengerOnionPackerLayerProto.__init__(self, WMessengerJSONPacker.__layer_name__)<EOL> | Construct new layer | f9851:c0:m0 |
def __init__(self): | WMessengerOnionLayerProto.__init__(self, WMessengerSimpleCastingLayer.__layer_name__)<EOL> | Construct new layer | f9854:c0:m0 |
@verify_type(name=str, mode_cls=type)<EOL><INDENT>def __init__(self, name, mode_cls):<DEDENT> | WMessengerOnionLayerProto.__init__(self, name)<EOL>self.__mode_cls = mode_cls<EOL> | Construct new layer
:param name: layer name
:param mode_cls: layer's "mode" class | f9854:c1:m0 |
@verify_type('<STR_LIT>', envelope=WMessengerEnvelopeProto, session=WMessengerOnionSessionProto)<EOL><INDENT>def process(self, envelope, session, mode=None, **kwargs):<DEDENT> | if mode is None:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if isinstance(mode, self.__mode_cls) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>return self._process(envelope, session, mode, **kwargs)<EOL> | :meth:`.WMessengerOnionLayerProto.process` implementation | f9854:c1:m1 |
@abstractmethod<EOL><INDENT>@verify_type(envelope=WMessengerEnvelopeProto, session=WMessengerOnionSessionProto)<EOL>def _process(self, envelope, session, mode, **kwargs):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Real processing method.
:param envelope: original envelope
:param session: original session
:param mode: specified mode
:param kwargs: layer arguments
:return: WMessengerEnvelopeProto | f9854:c1:m2 |
@verify_type(name=str)<EOL><INDENT>def __init__(self, name):<DEDENT> | WMessengerOnionModeLayerProto.__init__(self, name, WMessengerOnionCoderLayerProto.Mode)<EOL> | Construct new layer
:param name: layer name | f9854:c2:m0 |
@verify_type('<STR_LIT>', envelope=WMessengerEnvelopeProto, session=WMessengerOnionSessionProto)<EOL><INDENT>def _process(self, envelope, session, mode, **kwargs):<DEDENT> | if mode == WMessengerOnionCoderLayerProto.Mode.encode:<EOL><INDENT>return self.encode(envelope, session, **kwargs)<EOL><DEDENT>else: <EOL><INDENT>return self.decode(envelope, session, **kwargs)<EOL><DEDENT> | :meth:`.WMessengerOnionLayerProto.process` implementation | f9854:c2:m1 |
@abstractmethod<EOL><INDENT>@verify_type(envelope=(WMessengerTextEnvelope, WMessengerBytesEnvelope), session=WMessengerOnionSessionProto)<EOL>def encode(self, envelope, session, **kwargs):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Encrypt/encode message
:param envelope: message to encrypt/encode
:param session: original session
:return: WMessengerTextEnvelope or WMessengerBytesEnvelope | f9854:c2:m2 |
@abstractmethod<EOL><INDENT>@verify_type(envelope=(WMessengerTextEnvelope, WMessengerBytesEnvelope), session=WMessengerOnionSessionProto)<EOL>def decode(self, envelope, session, **kwargs):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Decrypt/decode message
:param envelope: message to decrypt/decode
:param session: original session
:return: WMessengerTextEnvelope or WMessengerBytesEnvelope | f9854:c2:m3 |
@verify_type('<STR_LIT>', envelope=WMessengerEnvelopeProto, session=WMessengerOnionSessionProto)<EOL><INDENT>def _process(self, envelope, session, mode, **kwargs):<DEDENT> | if mode == WMessengerOnionPackerLayerProto.Mode.pack:<EOL><INDENT>return self.pack(envelope, session, **kwargs)<EOL><DEDENT>else: <EOL><INDENT>return self.unpack(envelope, session, **kwargs)<EOL><DEDENT> | :meth:`.WMessengerOnionLayerProto.process` implementation | f9854:c3:m1 |
@abstractmethod<EOL><INDENT>@verify_type(envelope=WMessengerEnvelopeProto, session=WMessengerOnionSessionProto)<EOL>def pack(self, envelope, session, **kwargs):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Pack/serialize message
:param envelope: message to pack/serialize
:param session: original session
:return: WMessengerTextEnvelope or WMessengerBytesEnvelope | f9854:c3:m2 |
@abstractmethod<EOL><INDENT>@verify_type(envelope=(WMessengerTextEnvelope, WMessengerBytesEnvelope), session=WMessengerOnionSessionProto)<EOL>def unpack(self, envelope, session, **kwargs):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Unpack/de-serialize message
:param envelope: message to unpack/de-serialize
:param session: original session
:return: WMessengerEnvelopeProto | f9854:c3:m3 |
@abstractmethod<EOL><INDENT>@verify_type(layer_name=str)<EOL>def layer(self, layer_name):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Return messengers layer by its name
:param layer_name: name of a layer
:return: WMessengerOnionLayerProto instance | f9855:c0:m0 |
@abstractmethod<EOL><INDENT>def layers_names(self):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Available layers names
:return: list of str | f9855:c0:m1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.