signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
@abstractmethod<EOL><INDENT>def error_presenter(self):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Return presenter that is used for error handling
:return: WWebErrorPresenter | f9877:c9:m1 |
@verify_type(target_route=WWebTargetRouteProto)<EOL><INDENT>def target_route_valid(self, target_route):<DEDENT> | return target_route.presenter_action()[<NUM_LIT:0>] != '<STR_LIT:_>'<EOL> | Check target route for execution. This method is used for omitting special methods (actions)
from being executed
:param target_route: route to check
:return: bool | f9877:c9:m2 |
@verify_subclass(request_cls=WWebRequest)<EOL><INDENT>def __init__(self, request_cls=WWebRequest):<DEDENT> | self.__request_cls = request_cls<EOL> | Construct class
:param request_cls: request class to use | f9878:c1:m0 |
@verify_type(request_line=str)<EOL><INDENT>def read_request_line(self, request_line):<DEDENT> | request = self.__request_cls.parse_request_line(self, request_line)<EOL>protocol_version = self.protocol_version()<EOL>if protocol_version == '<STR_LIT>':<EOL><INDENT>if request.method() != '<STR_LIT:GET>':<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT><DEDENT>elif protocol_version == '<STR_LIT:1.0>' or protocol... | Read HTTP-request line
:param request_line: line to parse
for HTTP/0.9 is GET <Request-URI>
for HTTP/1.0 and 1.1 is <METHOD> <Request-URI> HTTP/<HTTP-Version>, where HTTP-Version is 1.0
or 1.1.
for HTTP/2: binary headers are used | f9878:c1:m1 |
@verify_type(status=(int, None), headers=(WHTTPHeaders, None), response_data=(bytes, None))<EOL><INDENT>@verify_value(status=lambda x: x is None or x > <NUM_LIT:0>)<EOL>def __init__(self, status=None, headers=None, response_data=None):<DEDENT> | WWebResponseProto.__init__(self)<EOL>self.__status = status<EOL>self.__headers = headers<EOL>self.__response_data = response_data<EOL>self.__pushed_responses = []<EOL> | Create new response
:param status: response status code
:param headers: response headers
:param response_data: response data | f9879:c0:m0 |
def status(self): | return self.__status<EOL> | :meth:`.WWebResponseProto.status` method implementation | f9879:c0:m1 |
def headers(self): | return self.__headers<EOL> | :meth:`.WWebResponseProto.headers` method implementation | f9879:c0:m2 |
def response_data(self): | return self.__response_data<EOL> | :meth:`.WWebResponseProto.response_data` method implementation | f9879:c0:m3 |
@verify_type(response=WWebResponseProto)<EOL><INDENT>def __push__(self, *responses):<DEDENT> | self.__pushed_responses.extend(responses)<EOL> | Save responses to push
:param responses: responses to push
:return: | f9879:c0:m4 |
def __pushed_responses__(self): | return tuple(self.__pushed_responses)<EOL> | :meth:`.WWebResponseProto.__pushed_responses__` method implementation | f9879:c0:m5 |
@verify_type('<STR_LIT>', request=WWebRequestProto)<EOL><INDENT>def __init__(self, request):<DEDENT> | WWebErrorPresenter.__init__(self, request)<EOL>self.__messages = {<EOL><NUM_LIT>: '<STR_LIT>'<EOL>}<EOL> | Create new error presenter
:param request: origin request | f9881:c0:m0 |
@verify_type('<STR_LIT>', code=int)<EOL><INDENT>@verify_value('<STR_LIT>', code=lambda x: x > <NUM_LIT:0>)<EOL>def error_code(self, code):<DEDENT> | return WWebResponse(<EOL>status=code,<EOL>headers=WHTTPHeaders(**{'<STR_LIT:Content-Type>': '<STR_LIT>'}),<EOL>response_data=self.__message__(code).encode()<EOL>)<EOL> | :meth:`.WWebErrorPresenter.error_code` method implementation | f9881:c0:m2 |
@verify_type(exception=Exception)<EOL><INDENT>def exception_error(self, exception):<DEDENT> | return self.error_code(<NUM_LIT>)<EOL> | :meth:`.WWebErrorPresenter.exception_error` method implementation | f9881:c0:m3 |
@classmethod<EOL><INDENT>def __presenter_name__(cls):<DEDENT> | return '<STR_LIT>'<EOL> | :meth:`.WWebPresenter.__presenter_name__` method implementation | f9881:c0:m4 |
@verify_type(pattern=str, presenter=str, action=(str, None), virtual_hosts=(list, tuple, set, None))<EOL><INDENT>@verify_type(protocols=(list, tuple, set, None), ports=(list, tuple, set, None))<EOL>@verify_type(methods=(list, tuple, set, None))<EOL>def __init__(self, pattern, presenter, **kwargs):<DEDENT> | self.original_pattern = pattern<EOL>self.route_args = []<EOL>self.presenter = presenter<EOL>self.presenter_args = {}<EOL>self.action = "<STR_LIT:index>"<EOL>self.virtual_hosts = None<EOL>self.ports = None<EOL>self.protocols = ("<STR_LIT:http>", "<STR_LIT>")<EOL>self.methods = ("<STR_LIT:GET>", "<STR_LIT:POST>")<EOL>arg... | Create new route
:param pattern: route declarative pattern, that may contain arguments definition
:param presenter: target presenter name
:param kwargs: route arguments (default and special arguments) | f9881:c1:m0 |
@classmethod<EOL><INDENT>@verify_type(uri=str)<EOL>def normalize_uri(cls, uri):<DEDENT> | uri = WWebRoute.multiple_slashes_re.sub("<STR_LIT:/>", uri)<EOL>if len(uri) > <NUM_LIT:1>:<EOL><INDENT>if uri[-<NUM_LIT:1>] == '<STR_LIT:/>':<EOL><INDENT>uri = uri[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>return uri<EOL> | Normalize the given URI (removes extra slashes)
:param uri: uri to normalize
:return: str | f9881:c1:m1 |
@verify_type(request=WWebRequestProto, service=WWebServiceProto)<EOL><INDENT>def match(self, request, service):<DEDENT> | uri = self.normalize_uri(request.path())<EOL>if request.session().protocol() not in self.protocols:<EOL><INDENT>return<EOL><DEDENT>if request.method() not in self.methods:<EOL><INDENT>return<EOL><DEDENT>if self.virtual_hosts and request.virtual_host() not in self.virtual_hosts:<EOL><INDENT>return<EOL><DEDENT>if self.po... | Check this route for matching the given request. If this route is matched, then target route is
returned.
:param request: request to match
:param service: source service
:return: WWebTargetRoute or None | f9881:c1:m2 |
def url_for(self, **kwargs): | host = self.virtual_hosts[<NUM_LIT:0>] if self.virtual_hosts is not None and len(self.virtual_hosts) == <NUM_LIT:1> else None<EOL>port = self.ports[<NUM_LIT:0>] if self.ports is not None and len(self.ports) == <NUM_LIT:1> else None<EOL>protocol = self.protocols[<NUM_LIT:0>] if self.protocols is not None and len(self.pr... | Generate url for client with specified route arguments. For the source route '/page/{page_index}'
this method must be called with 'page_index' parameter (for '3' as 'page_index' parameter result will
be '/page/3' for 'foo_bar' - '/page/foo_bar'). If 'host', 'protocol' and 'ports' are set as single
... | f9881:c1:m3 |
@verify_type(presenter_name=str, presenter_action=str, route=WWebRoute, route_map=WWebRouteMapProto)<EOL><INDENT>def __init__(self, presenter_name, presenter_action, route, route_map, **presenter_args):<DEDENT> | self.__presenter_name = presenter_name<EOL>self.__presenter_action = presenter_action<EOL>self.__presenter_args = presenter_args<EOL>self.__route = route<EOL>self.__route_map = route_map<EOL> | Construct new target route
:param presenter_name: name of the target presenter. May vary from the presenter name that is specified
in route object
:param presenter_action: presenter action (method) to execute
:param presenter_args: args to execute with
:param route: source route... | f9881:c2:m0 |
def route(self): | return self.__route<EOL> | Return origin route map
:return: WWebRoute | f9881:c2:m1 |
def route_map(self): | return self.__route_map<EOL> | Return origin route map
:return: WWebRouteMap | f9881:c2:m2 |
def presenter_name(self): | return self.__presenter_name<EOL> | :meth:`.WWebTargetRouteProto.presenter_class` method implementation | f9881:c2:m3 |
def presenter_action(self): | return self.__presenter_action<EOL> | :meth:`.WWebTargetRouteProto.presenter_action` method implementation | f9881:c2:m4 |
def presenter_args(self): | return self.__presenter_args<EOL> | :meth:`.WWebTargetRouteProto.presenter_args` method implementation | f9881:c2:m5 |
def __init__(self): | self.__routes = []<EOL>self.__error_presenter = WSimpleErrorPresenter<EOL> | Create new route map | f9881:c3:m0 |
@verify_type('<STR_LIT>', request=WWebRequestProto, service=WWebServiceProto)<EOL><INDENT>def route(self, request, service):<DEDENT> | for route in self.__routes:<EOL><INDENT>result = route.match(request, service)<EOL>if result is not None:<EOL><INDENT>if self.target_route_valid(result) is True:<EOL><INDENT>return result<EOL><DEDENT><DEDENT><DEDENT> | :meth:`.WWebRouteMapProto.route` method implementation | f9881:c3:m1 |
def error_presenter(self): | return self.__error_presenter<EOL> | :meth:`.WWebRouteMapProto.error_presenter` method implementation | f9881:c3:m2 |
@verify_subclass(presenter=WWebErrorPresenter)<EOL><INDENT>def set_error_presenter(self, presenter):<DEDENT> | self.__error_presenter = presenter<EOL> | Set error presenter for this route map
:param presenter: presenter to be used for error handling
:return: None | f9881:c3:m3 |
@verify_type('<STR_LIT>', pattern=str, presenter=str)<EOL><INDENT>def connect(self, pattern, presenter, **kwargs):<DEDENT> | self.__routes.append(WWebRoute(pattern, presenter, **kwargs))<EOL> | Connect the given pattern with the given presenter
:param pattern: URI pattern
:param presenter: target presenter name
:param kwargs: route arguments (see :class:`.WWebRoute`)
:return: None | f9881:c3:m4 |
@verify_type(route=WWebRoute)<EOL><INDENT>def append(self, route):<DEDENT> | self.__routes.append(route)<EOL> | Append route to collection
:param route: route to add
:return: None | f9881:c3:m5 |
@verify_type(route_as_txt=str)<EOL><INDENT>@verify_value(route_as_txt=lambda x: len(x) > <NUM_LIT:0>)<EOL>def import_route(self, route_as_txt):<DEDENT> | route_match = WWebRouteMap.import_route_re.match(route_as_txt)<EOL>if route_match is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>pattern = route_match.group(<NUM_LIT:1>)<EOL>presenter_name = route_match.group(<NUM_LIT:2>)<EOL>route_args = route_match.group(<NUM_LIT:4>) <EOL>if route_args is not None:<E... | Import route written as a string
:param route_as_txt: single string (single route) to import
:return: None | f9881:c3:m6 |
def __init__(self): | WWebPresenterCollectionProto.__init__(self)<EOL>self.__presenters = {}<EOL> | Construct new collection | f9881:c4:m0 |
@verify_subclass(presenter=WWebPresenter)<EOL><INDENT>def add(self, presenter):<DEDENT> | self.__presenters[presenter.__presenter_name__()] = presenter<EOL> | Add presenter to this collection
:param presenter: presenter to add
:return: None | f9881:c4:m1 |
@verify_type(section=str, presenter_name=str)<EOL><INDENT>@verify_value(section=lambda x: len(x) > <NUM_LIT:0>, presenter_name=lambda x: len(x) > <NUM_LIT:0>)<EOL>def presenter(self, presenter_name):<DEDENT> | if presenter_name in self.__presenters.keys():<EOL><INDENT>return self.__presenters[presenter_name]<EOL><DEDENT> | :meth:`.WWebPresenterCollectionProto.presenter` method implementation | f9881:c4:m2 |
@verify_type(presenter_name=str)<EOL><INDENT>@verify_value(presenter_name=lambda x: len(x) > <NUM_LIT:0>)<EOL>def has(self, presenter_name):<DEDENT> | return presenter_name in self.__presenters.keys()<EOL> | :meth:`.WWebPresenterCollectionProto.has` method implementation | f9881:c4:m3 |
def __len__(self): | return len(self.__presenters)<EOL> | Return total presenters count
:return: int | f9881:c4:m4 |
@verify_type(route_map=(WWebRouteMap, None), collection=(WWebPresenterCollectionProto, None))<EOL><INDENT>@verify_type(debugger=(WWebDebugInfo, None))<EOL>@verify_subclass(factory=(WWebPresenterFactoryProto, None))<EOL>def __init__(self, route_map=None, collection=None, factory=None, debugger=None):<DEDENT> | self.__route_map = route_map if route_map is not None else WWebRouteMap()<EOL>self.__presenter_collection = collection<EOL>self.__factory = factory() if factory is not None else WWebPresenterFactory()<EOL>self.__debugger = debugger<EOL>if self.__presenter_collection is None:<EOL><INDENT>self.__presenter_collection = WS... | Create new service
:param route_map: route map to be uses (if None, internal route map will be used)
:param collection: collection to be used (if None, internal collection will be used) | f9881:c5:m0 |
def route_map(self): | return self.__route_map<EOL> | :meth:`.WWebServiceProto.route_map` method implementation | f9881:c5:m1 |
def presenter_collection(self): | return self.__presenter_collection<EOL> | :meth:`.WWebServiceProto.presenter_collection` method implementation | f9881:c5:m2 |
def presenter_factory(self): | return self.__factory<EOL> | :meth:`.WWebServiceProto.presenter_factory` method implementation | f9881:c5:m3 |
@verify_type(session=WWebSessionProto)<EOL><INDENT>def process_request(self, session):<DEDENT> | debugger = self.debugger()<EOL>debugger_session_id = debugger.session_id() if debugger is not None else None<EOL>try:<EOL><INDENT>request = session.read_request()<EOL>if debugger_session_id is not None:<EOL><INDENT>debugger.request(<EOL>debugger_session_id, request, session.protocol_version(), session.protocol()<EOL>)<... | Process single request from the given session
:param session: session for reading requests and writing responses
:return: None | f9881:c5:m4 |
@verify_type('<STR_LIT>', request=WWebRequestProto, target_route=WWebTargetRouteProto)<EOL><INDENT>def create_presenter(self, request, target_route):<DEDENT> | presenter_name = target_route.presenter_name()<EOL>if self.presenter_collection().has(presenter_name) is False:<EOL><INDENT>raise RuntimeError('<STR_LIT>' % presenter_name)<EOL><DEDENT>presenter_class = self.presenter_collection().presenter(presenter_name)<EOL>return self.presenter_factory().instantiate(presenter_class... | Create presenter from the given requests and target routes
:param request: client request
:param target_route: route to use
:return: WWebPresenter | f9881:c5:m5 |
@verify_type('<STR_LIT>', request=WWebRequestProto, target_route=WWebTargetRouteProto)<EOL><INDENT>def execute(self, request, target_route):<DEDENT> | presenter = self.create_presenter(request, target_route)<EOL>presenter_name = target_route.presenter_name()<EOL>action_name = target_route.presenter_action()<EOL>presenter_args = target_route.presenter_args()<EOL>if hasattr(presenter, action_name) is False:<EOL><INDENT>raise RuntimeError('<STR_LIT>' % (action_name, pre... | :meth:`.WWebServiceProto.execute` method implementation | f9881:c5:m6 |
@verify_type('<STR_LIT>', pattern=str, presenter=(type, str))<EOL><INDENT>@verify_value('<STR_LIT>', presenter=lambda x: issubclass(x, WWebPresenter) or isinstance(x, str))<EOL>def connect(self, pattern, presenter, **kwargs):<DEDENT> | if isinstance(presenter, type) and issubclass(presenter, WWebPresenter) is True:<EOL><INDENT>self.presenter_collection().add(presenter)<EOL>presenter = presenter.__presenter_name__()<EOL><DEDENT>self.__route_map.connect(pattern, presenter, **kwargs)<EOL> | Shortcut for self.route_map().connect() method. It is possible to pass presenter class instead of
its name - in that case such class will be saved in presenter collection and it will be available in
route matching.
:param pattern: same as pattern in :meth:`.WWebRouteMap.connect` method
... | f9881:c5:m7 |
@verify_subclass(presenter=WWebPresenter)<EOL><INDENT>def add_presenter(self, presenter):<DEDENT> | self.__presenter_collection.add(presenter)<EOL>if issubclass(presenter, WWebEnhancedPresenter) is True:<EOL><INDENT>for route in presenter.__public_routes__():<EOL><INDENT>self.route_map().append(route)<EOL><DEDENT><DEDENT> | Add presenter to a collection. If the given presenter is a :class:`.WWebEnhancedPresenter` instance
then public routes are checked (via :meth:`..WWebEnhancedPresenter.__public_routes__` method) and are
added in this route map
:param presenter: presenter to add
:return: None | f9881:c5:m8 |
@verify_type('<STR_LIT>', request=WWebRequestProto, presenter_name=str)<EOL><INDENT>@verify_type(original_target_route=WWebTargetRoute)<EOL>def proxy(self, request, original_target_route, presenter_name, **kwargs):<DEDENT> | action_kwargs = kwargs.copy()<EOL>action_name = '<STR_LIT:index>'<EOL>if '<STR_LIT:action>' in action_kwargs:<EOL><INDENT>action_name = action_kwargs['<STR_LIT:action>']<EOL>action_kwargs.pop('<STR_LIT:action>')<EOL><DEDENT>original_route = original_target_route.route()<EOL>original_route_map = original_target_route.ro... | Execute the given presenter as a target for the given client request
:param request: original client request
:param original_target_route: previous target route
:param presenter_name: target presenter name
:param kwargs: presenter arguments
:return: WWebResponseProto | f9881:c5:m9 |
@verify_type('<STR_LIT>', request=WWebRequestProto)<EOL><INDENT>@verify_type(target_route=WWebTargetRoute, service=WWebService)<EOL>def __init__(self, request, target_route, service):<DEDENT> | WWebPresenter.__init__(self, request)<EOL>self.__target_route = target_route<EOL>self.__service = service<EOL> | Create new enhanced presenter
:param request: client request
:param target_route: source target route
:param service: source service | f9881:c6:m0 |
def __target_route__(self): | return self.__target_route<EOL> | Return origin target route
:return: WWebTargetRoute | f9881:c6:m1 |
def __service__(self): | return self.__service<EOL> | Return origin service instance
:return: WWebService | f9881:c6:m2 |
@classmethod<EOL><INDENT>def __public_routes__(cls):<DEDENT> | return tuple()<EOL> | Return web routes, that this presenter makes "public" (available to :class:`.WWebService` route map)
see :meth:`.WWebService.add_presenter` method
:return: tuple/list of WWebRoute | f9881:c6:m3 |
@verify_type('<STR_LIT>', presenter_name=str)<EOL><INDENT>def __proxy__(self, presenter_name, **kwargs):<DEDENT> | return self.__service__().proxy(self.__request__(), self.__target_route__(), presenter_name, **kwargs)<EOL> | Execute the given presenter as a target for the original client request
:param presenter_name: target presenter name
:param kwargs: presenter arguments
:return: WWebResponseProto | f9881:c6:m4 |
@staticmethod<EOL><INDENT>def presenter_constructor(presenter_class, request, target_route, service):<DEDENT> | return presenter_class(request)<EOL> | Function that is used for WWebPresenter creating
:param presenter_class: class to construct
:param request: original client request
:param target_route: target route to execute
:param service: source (parent) service
:return: WWebPresenter | f9881:c7:m0 |
@staticmethod<EOL><INDENT>def enhanced_presenter_constructor(presenter_class, request, target_route, service):<DEDENT> | return presenter_class(request, target_route, service)<EOL> | Function that is used for WWebEnhancedPresenter creating
:param presenter_class: class to construct
:param request: original client request
:param target_route: target route to execute
:param service: source (parent) service
:return: WWebEnhancedPresenter | f9881:c7:m1 |
def __init__(self): | WWebPresenterFactoryProto.__init__(self)<EOL>self.__constructors = {<EOL>WWebPresenter.__init__: WWebPresenterFactory.presenter_constructor,<EOL>WWebEnhancedPresenter.__init__: WWebPresenterFactory.enhanced_presenter_constructor<EOL>}<EOL> | Construct new factory | f9881:c7:m2 |
@verify_subclass(presenter_class=WWebPresenter)<EOL><INDENT>def instantiable(self, presenter_class):<DEDENT> | return presenter_class.__init__ in self.__constructors.keys()<EOL> | :meth:`.WWebPresenterFactoryProto.instantiable` method implementation.
Checks if class doesn't have its own constructor and is derived from WWebPresenter or from
WWebEnhancedPresenter
:param presenter_class: class to check
:return: bool | f9881:c7:m4 |
@verify_type('<STR_LIT>', request=WWebRequestProto, target_route=WWebTargetRouteProto, service=WWebService)<EOL><INDENT>@verify_subclass('<STR_LIT>', presenter_class=WWebPresenter)<EOL>def instantiate(self, presenter_class, request, target_route, service, *args, **kwargs):<DEDENT> | if self.instantiable(presenter_class) is False:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>return self.__constructors[presenter_class.__init__](presenter_class, request, target_route, service)<EOL> | :meth:`.WWebPresenterFactoryProto.instantiate` method implementation.
Construct new presenter or raise en exception if it isn't possible.
:param presenter_class: class to construct
:param request: original client request
:param target_route: target route to execute
:param servi... | f9881:c7:m5 |
@abstractmethod<EOL><INDENT>@verify_type(io_loop=IOLoop)<EOL>def setup_handler(self, io_loop):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Set up this handler with the specified IOLoop
:param io_loop: service (or service client) loop to use with
:return: None | f9882:c0:m0 |
def loop_stopped(self): | pass<EOL> | Method is called when previously set up loop was stopped
:return: None | f9882:c0:m1 |
@verify_type(handler=WIOLoopServiceHandler, loop=(IOLoop, None), timeout=(int, None))<EOL><INDENT>def __init__(self, handler, loop=None, timeout=None):<DEDENT> | self.__loop = IOLoop() if loop is None else loop<EOL>self.__handler = handler<EOL>self.__timeout = timeout<EOL> | Create new service (or service client)
:param handler: handler that do the work
:param loop: loop to use (or None for internal one)
:param timeout: timeout after which this loop will be stopped | f9882:c1:m0 |
def loop(self): | return self.__loop<EOL> | Return service loop object
:return: IOLoop | f9882:c1:m1 |
def handler(self): | return self.__handler<EOL> | Return service handler
:return: WIOLoopServiceHandler | f9882:c1:m2 |
def timeout(self): | return self.__timeout<EOL> | Return service timeout. (None for endless loop)
:return: int or None | f9882:c1:m3 |
def start(self): | timeout = self.timeout()<EOL>if timeout is not None and timeout > <NUM_LIT:0>:<EOL><INDENT>self.__loop.add_timeout(timedelta(<NUM_LIT:0>, timeout), self.stop)<EOL><DEDENT>self.handler().setup_handler(self.loop())<EOL>self.loop().start()<EOL>self.handler().loop_stopped()<EOL> | Set up handler and start loop
:return: None | f9882:c1:m4 |
def stop(self): | self.loop().stop()<EOL> | Stop loop
:return: None | f9882:c1:m5 |
@abstractmethod<EOL><INDENT>def handler_fn(self, fd, event):<DEDENT> | raise NotImplementedError('<STR_LIT>')<EOL> | Process (handle) specified event
:param fd: integer file descriptor or a file-like object with a fileno() method
:param event: IOLoop event
:return: None | f9882:c2:m0 |
@verify_type(transport=WNetworkNativeTransportProto, config=WConfig, io_handler=WNativeSocketIOHandler)<EOL><INDENT>def __init__(self, transport, config, io_handler):<DEDENT> | WIOLoopServiceHandler.__init__(self)<EOL>self.__transport = transport<EOL>self.__config = config<EOL>self.__io_handler = io_handler<EOL> | Create new socket handler
:param transport: transport to use
:param config: configuration to be used with transport
:param io_handler: handler that do the real work | f9882:c3:m0 |
def transport(self): | return self.__transport<EOL> | Return currently used transport
:return: WNetworkNativeTransportProto | f9882:c3:m1 |
def config(self): | return self.__config<EOL> | Return handler configuration
:return: WConfig | f9882:c3:m2 |
def io_handler(self): | return self.__io_handler<EOL> | Return IO-handler
:return: WNativeSocketIOHandler | f9882:c3:m3 |
def __init__(self): | WNativeSocketIOHandler.__init__(self)<EOL>self.__transport_socket = None<EOL> | Create new IO-handler | f9882:c4:m0 |
def transport_socket(self, new_socket=None): | if new_socket is not None:<EOL><INDENT>self.__transport_socket = new_socket<EOL><DEDENT>return self.__transport_socket<EOL> | Save and/or return currently used socket object
:param new_socket: new socket to save
:return: socket object (any type, None if socket wasn't set) | f9882:c4:m1 |
@verify_type('<STR_LIT>', transport=WNetworkNativeTransportProto, config=WConfig)<EOL><INDENT>@verify_type('<STR_LIT>', io_handler=WNativeSocketIOHandler)<EOL>@verify_type(server_mode=bool)<EOL>def __init__(self, transport, config, io_handler, server_mode):<DEDENT> | WBasicNativeSocketHandler.__init__(self, transport, config, io_handler)<EOL>self.__server_mode = server_mode<EOL> | Create new loop-handler
:param transport: transport to use
:param config: configuration to use (in the most cases it is used by transport object only)
:param io_handler: io-handler to use
:param server_mode: set 'server_mode' flag for correct transport configuration | f9882:c5:m0 |
def server_mode(self): | return self.__server_mode<EOL> | Return current mode. True if this handler works as a server, otherwise - False
:return: bool | f9882:c5:m1 |
@verify_type(io_loop=IOLoop)<EOL><INDENT>def setup_handler(self, io_loop):<DEDENT> | if self.server_mode() is True:<EOL><INDENT>s = self.transport().server_socket(self.config())<EOL><DEDENT>else:<EOL><INDENT>s = self.transport().client_socket(self.config())<EOL><DEDENT>io_handler = self.io_handler()<EOL>if isinstance(io_handler, WNativeSocketDirectIOHandler) is True:<EOL><INDENT>io_handler.transport_so... | :meth:`.WIOLoopServiceHandler.setup_handler` implementation.
If :class:`.WNativeSocketDirectIOHandler` is used as a io-handler, then socket object is saved
to this handler before loop starting
:param io_loop: io_loop to use
:return: None | f9882:c5:m2 |
def loop_stopped(self): | transport = self.transport()<EOL>if self.server_mode() is True:<EOL><INDENT>transport.close_server_socket(self.config())<EOL><DEDENT>else:<EOL><INDENT>transport.close_client_socket(self.config())<EOL><DEDENT> | Terminate socket connection because of stopping loop
:return: None | f9882:c5:m3 |
def discard_queue_messages(self): | zmq_stream_queue = self.handler().stream()._send_queue<EOL>while not zmq_stream_queue.empty():<EOL><INDENT>try:<EOL><INDENT>zmq_stream_queue.get(False)<EOL><DEDENT>except queue.Empty:<EOL><INDENT>continue<EOL><DEDENT>zmq_stream_queue.task_done()<EOL><DEDENT> | Sometimes it is necessary to drop undelivered messages. These messages may be stored in different
caches, for example in a zmq socket queue. With different zmq flags we can tweak zmq sockets and
contexts no to keep those messages. But inside ZMQStream class there is a queue that can not be
clean... | f9882:c7:m1 |
def __init__(self): | self.__private_key = None<EOL>self.__public_key = None<EOL> | Create object for RSA cryptography | f9883:c0:m0 |
def __set_private_key(self, pk): | self.__private_key = pk<EOL>self.__public_key = pk.public_key()<EOL> | Internal method that sets the specified private key
:param pk: private key to set
:return: None | f9883:c0:m1 |
def __set_public_key(self, pk): | self.__private_key = None<EOL>self.__public_key = pk<EOL> | Internal method that sets the specified public key
:param pk: public key to set
:return: None | f9883:c0:m2 |
def private_key_size(self): | if self.__private_key is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return self.__private_key.key_size<EOL> | Return private key size
:return: int | f9883:c0:m3 |
def has_private_key(self): | return self.__private_key is not None<EOL> | Check if this object has a private key
:return: bool | f9883:c0:m4 |
def has_public_key(self): | return self.__public_key is not None<EOL> | Check if this object has a public key
:return: bool | f9883:c0:m5 |
@verify_type(key_size=int, public_exponent=int)<EOL><INDENT>@verify_value(key_size=lambda x: ((x % <NUM_LIT>) == <NUM_LIT:0>) and x >= <NUM_LIT>, public_exponent=lambda x: x > <NUM_LIT:0>)<EOL>def generate_private_key(self, key_size=<NUM_LIT>, public_exponent=<NUM_LIT>):<DEDENT> | self.__set_private_key(<EOL>rsa.generate_private_key(<EOL>public_exponent=public_exponent, key_size=key_size, backend=default_backend()<EOL>)<EOL>)<EOL> | Generate a private (and a corresponding public) key
:return: None | f9883:c0:m6 |
@verify_type(password=(str, bytes, None))<EOL><INDENT>def export_private_key(self, password=None):<DEDENT> | if self.__private_key is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if password is not None:<EOL><INDENT>if isinstance(password, str) is True:<EOL><INDENT>password = password.encode()<EOL><DEDENT>return self.__private_key.private_bytes(<EOL>encoding=serialization.Encoding.PEM,<EOL>format=serialization.... | Export a private key in PEM-format
:param password: If it is not None, then result will be encrypt with given password
:return: bytes | f9883:c0:m7 |
def export_public_key(self): | if self.__public_key is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return self.__public_key.public_bytes(<EOL>encoding=serialization.Encoding.PEM,<EOL>format=serialization.PublicFormat.SubjectPublicKeyInfo<EOL>)<EOL> | Export a public key in PEM-format
:return: bytes | f9883:c0:m8 |
@verify_type(pem_text=(str, bytes), password=(str, bytes, None))<EOL><INDENT>def import_private_key(self, pem_text, password=None):<DEDENT> | if isinstance(pem_text, str) is True:<EOL><INDENT>pem_text = pem_text.encode()<EOL><DEDENT>if password is not None and isinstance(password, str) is True:<EOL><INDENT>password = password.encode()<EOL><DEDENT>self.__set_private_key(<EOL>serialization.load_pem_private_key(pem_text, password=password, backend=default_backe... | Import a private key from data in PEM-format
:param pem_text: text with private key
:param password: If it is not None, then result will be decrypt with the given password
:return: None | f9883:c0:m9 |
@verify_type(pem_text=(str, bytes))<EOL><INDENT>def import_public_key(self, pem_text):<DEDENT> | if isinstance(pem_text, str) is True:<EOL><INDENT>pem_text = pem_text.encode()<EOL><DEDENT>self.__set_public_key(<EOL>serialization.load_pem_public_key(pem_text, backend=default_backend())<EOL>)<EOL> | Import a public key from data in PEM-format
:param pem_text: text with public key
:return: None | f9883:c0:m10 |
@verify_type(data=bytes, oaep_hash_fn_name=(str, None), mgf1_hash_fn_name=(str, None))<EOL><INDENT>@verify_value(oaep_hash_fn_name=lambda x: x is None or hasattr(hashes, x))<EOL>@verify_value(mgf1_hash_fn_name=lambda x: x is None or hasattr(hashes, x))<EOL>def encrypt(self, data, oaep_hash_fn_name=None, mgf1_hash_fn_na... | if self.__public_key is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if oaep_hash_fn_name is None:<EOL><INDENT>oaep_hash_fn_name = self.__class__.__default_oaep_hash_function_name__<EOL><DEDENT>if mgf1_hash_fn_name is None:<EOL><INDENT>mgf1_hash_fn_name = self.__class__.__default_mgf1_hash_function_name_... | Encrypt a data with PKCS1 OAEP protocol
:param data: data to encrypt
:param oaep_hash_fn_name: hash function name to use with OAEP
:param mgf1_hash_fn_name: hash function name to use with MGF1 padding
:return: bytes | f9883:c0:m11 |
@verify_type(data=bytes, oaep_hash_fn_name=(str, None), mgf1_hash_fn_name=(str, None))<EOL><INDENT>@verify_value(oaep_hash_fn_name=lambda x: x is None or hasattr(hashes, x))<EOL>@verify_value(mgf1_hash_fn_name=lambda x: x is None or hasattr(hashes, x))<EOL>def decrypt(self, data, oaep_hash_fn_name=None, mgf1_hash_fn_na... | if self.__private_key is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if oaep_hash_fn_name is None:<EOL><INDENT>oaep_hash_fn_name = self.__class__.__default_oaep_hash_function_name__<EOL><DEDENT>if mgf1_hash_fn_name is None:<EOL><INDENT>mgf1_hash_fn_name = self.__class__.__default_mgf1_hash_function_name... | Decrypt a data that used PKCS1 OAEP protocol
:param data: data to decrypt
:param oaep_hash_fn_name: hash function name to use with OAEP
:param mgf1_hash_fn_name: hash function name to use with MGF1 padding
:return: bytes | f9883:c0:m12 |
@verify_type(byte_sequence=bytes)<EOL><INDENT>def __init__(self, byte_sequence):<DEDENT> | self.__byte_sequence = byte_sequence<EOL> | Create converter
:param byte_sequence: sequence to convert | f9884:c0:m0 |
def __str__(self): | return hexlify(self.__byte_sequence).decode('<STR_LIT:ascii>')<EOL> | Return result of converting the sequence
:return: str | f9884:c0:m1 |
@verify_type(string=(str, bytes))<EOL><INDENT>def __init__(self, string):<DEDENT> | self.__string = string<EOL> | Create converter
:param string: hex-string to convert | f9884:c1:m0 |
def __bytes__(self): | return unhexlify(self.__string)<EOL> | Return result of converting the hex-string
:return: bytes | f9884:c1:m1 |
@abstractmethod<EOL><INDENT>@verify_type(data=bytes, block_size=int)<EOL>@verify_value(block_size=lambda x: x > <NUM_LIT:0>)<EOL>def pad(self, data, block_size):<DEDENT> | raise NotImplementedError("<STR_LIT>")<EOL> | Pad given data to given size
:param data: data to pad
:param block_size: size to pad
:return: bytes | f9885:c0:m0 |
@abstractmethod<EOL><INDENT>@verify_type(data=bytes, block_size=int)<EOL>@verify_value(block_size=lambda x: x > <NUM_LIT:0>)<EOL>def reverse_pad(self, data, block_size):<DEDENT> | raise NotImplementedError("<STR_LIT>")<EOL> | Remove pads and return original data
:param data: data to remove pads from
:param block_size: size data aligned to
:return: bytes | f9885:c0:m1 |
@verify_type(padding=(int, None))<EOL><INDENT>@verify_value(padding=lambda x: x is None or (<NUM_LIT:0> <= x <= <NUM_LIT>))<EOL>def __init__(self, padding=None):<DEDENT> | if padding is None:<EOL><INDENT>padding = <NUM_LIT:0><EOL><DEDENT>self.__padding_symbol = bytes([padding])<EOL> | Create new padding class
:param padding: integer code of ASCII character | f9885:c1:m0 |
def padding_symbol(self): | return self.__padding_symbol<EOL> | Return character with witch data is padded
:return: bytes | f9885:c1:m1 |
@verify_type(data=bytes, block_size=int)<EOL><INDENT>@verify_value(block_size=lambda x: x > <NUM_LIT:0>)<EOL>def pad(self, data, block_size):<DEDENT> | padding_symbol = self.padding_symbol()<EOL>blocks_count = (len(data) // block_size)<EOL>if (len(data) % block_size) != <NUM_LIT:0>:<EOL><INDENT>blocks_count += <NUM_LIT:1><EOL><DEDENT>total_length = blocks_count * block_size<EOL>return self._fill(data, total_length, padding_symbol)<EOL> | :meth:`.WBlockPadding.pad` method implementation | f9885:c1:m2 |
@verify_type(data=bytes, block_size=int)<EOL><INDENT>@verify_value(block_size=lambda x: x > <NUM_LIT:0>)<EOL>def reverse_pad(self, data, block_size):<DEDENT> | return data.rstrip(self.padding_symbol())<EOL> | :meth:`.WBlockPadding.reverse_pad` method implementation | f9885:c1:m3 |
@verify_type(data=bytes, total_length=int, padding_symbol=bytes)<EOL><INDENT>@verify_value(total_length=lambda x: x > <NUM_LIT:0>, padding_symbol=lambda x: len(x) == <NUM_LIT:1>)<EOL>def _fill(self, data, total_length, padding_symbol):<DEDENT> | return data.ljust(total_length, padding_symbol)<EOL> | Append padding symbol to the end of data till specified length is reached
:param data: data to append to
:param total_length: target length
:param padding_symbol: symbol to pad
:return: bytes | f9885:c1:m4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.