signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
|---|---|---|---|
@verify_type(config=WConfig, close_fd=bool)<EOL><INDENT>def close_client_socket(self, config, close_fd=True):<DEDENT>
|
if close_fd is True:<EOL><INDENT>self.__client_socket.close()<EOL><DEDENT>self.__client_socket = None<EOL>
|
:meth:`.WNetworkNativeTransportProto.close_client_socket` method implementation
|
f9870:c2:m9
|
def _create_socket(self):
|
return socket.socket(socket.AF_INET, socket.SOCK_DGRAM)<EOL>
|
Create general UDP-socket
:return: socket.socket
|
f9870:c3:m0
|
def _create_socket(self):
|
return socket.socket(socket.AF_INET, socket.SOCK_STREAM)<EOL>
|
Create general TCP-socket
:return: socket.socket
|
f9870:c4:m0
|
@verify_type('<STR_LIT>', target_socket_config=WNetworkNativeTransportSocketConfig)<EOL><INDENT>@verify_type('<STR_LIT>', bind_socket_config=WNetworkNativeTransportSocketConfig)<EOL>def __init__(self, target_socket_config, bind_socket_config):<DEDENT>
|
WNetworkNativeTransport.__init__(self, target_socket_config, bind_socket_config)<EOL>
|
Create new broadcast transport
|
f9870:c5:m0
|
@verify_type('<STR_LIT>', config=WConfig)<EOL><INDENT>def target_socket(self, config):<DEDENT>
|
target = WNetworkNativeTransport.target_socket(self, config)<EOL>if isinstance(target.address(), WIPV4Address) is False:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return target<EOL>
|
This method overrides :meth:`.WNetworkNativeTransport.target_socket` method. Do the same thing as
basic method do, but also checks that the result address is IPv4 address.
:param config: beacon configuration
:return: WIPV4SocketInfo
|
f9870:c5:m1
|
@verify_type('<STR_LIT>', config=WConfig)<EOL><INDENT>def create_client_socket(self, config):<DEDENT>
|
client_socket = WUDPNetworkNativeTransport.create_client_socket(self, config)<EOL>client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, <NUM_LIT:1>)<EOL>return client_socket<EOL>
|
Create client broadcast socket
:param config: client configuration
:return: socket.socket
|
f9870:c5:m2
|
@verify_type('<STR_LIT>', target_socket_config=WNetworkNativeTransportSocketConfig)<EOL><INDENT>@verify_type('<STR_LIT>', bind_socket_config=WNetworkNativeTransportSocketConfig)<EOL>def __init__(self, target_socket_config, bind_socket_config):<DEDENT>
|
WUDPNetworkNativeTransport.__init__(self, target_socket_config, bind_socket_config)<EOL>
|
Create new multicast transport
|
f9870:c6:m0
|
@verify_type('<STR_LIT>', config=WConfig)<EOL><INDENT>def target_socket(self, config):<DEDENT>
|
target = WUDPNetworkNativeTransport.target_socket(self, config)<EOL>if WNetworkIPV4.is_multicast(target.address()) is False:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return target<EOL>
|
This method overrides :meth:`.WNetworkNativeTransport.target_socket` method. Do the same thing as
basic method do, but also checks that the result address is IPv4 multicast address.
:param config: beacon configuration
:return: WIPV4SocketInfo
|
f9870:c6:m1
|
@verify_type('<STR_LIT>', config=WConfig)<EOL><INDENT>def create_server_socket(self, config):<DEDENT>
|
server_socket = WUDPNetworkNativeTransport.create_server_socket(self, config)<EOL>group = socket.inet_aton(str(self.target_socket(config).address()))<EOL>group_membership = struct.pack('<STR_LIT>', group, socket.INADDR_ANY)<EOL>server_socket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, group_membership)<EOL>return server_socket<EOL>
|
Create server multicast socket. Socket will be joined to the multicast-group (same as it is
specified in client configuration, same as client does)
:param config: server configuration
:return: socket.socket
|
f9870:c6:m2
|
@staticmethod<EOL><INDENT>def header_name_check(header_name):<DEDENT>
|
header_match = WHTTPHeaders.header_name_re.match(header_name.encode('<STR_LIT>'))<EOL>return len(header_name) > <NUM_LIT:0> and header_match is not None<EOL>
|
Check header name for validity. Return True if name is valid
:param header_name: name to check
:return: bool
|
f9871:c0:m0
|
def __init__(self, **kwargs):
|
self.__headers = {}<EOL>self.__ro_flag = False<EOL>self.__normalization_mode = '<STR_LIT:1.0>'<EOL>self.__set_cookies = WHTTPCookieJar()<EOL>for arg_name in kwargs.keys():<EOL><INDENT>self.add_headers(arg_name, kwargs[arg_name])<EOL><DEDENT>
|
Construct new headers collection
:param kwargs: dictionary of header names and corresponding values
|
f9871:c0:m1
|
def headers(self):
|
return tuple(self.__headers.keys())<EOL>
|
Get specified header names
:return: tuple of str
|
f9871:c0:m2
|
@verify_type('<STR_LIT>', header_name=str)<EOL><INDENT>@verify_value('<STR_LIT>', header_name=lambda x: WHTTPHeaders.header_name_check(x))<EOL>def remove_headers(self, header_name):<DEDENT>
|
if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>header_name = self.normalize_name(header_name)<EOL>if header_name in self.__headers.keys():<EOL><INDENT>self.__headers.pop(header_name)<EOL><DEDENT>
|
Remove header by its name
:param header_name: name of header to remove
:return: None
|
f9871:c0:m3
|
@verify_type('<STR_LIT>', header_name=str)<EOL><INDENT>@verify_value('<STR_LIT>', header_name=lambda x: WHTTPHeaders.header_name_check(x))<EOL>@verify_type(value=str, values=str)<EOL>def add_headers(self, header_name, value, *values):<DEDENT>
|
if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>header_name = self.normalize_name(header_name)<EOL>if header_name not in self.__headers.keys():<EOL><INDENT>self.__headers[header_name] = [value]<EOL><DEDENT>else:<EOL><INDENT>self.__headers[header_name].append(value)<EOL><DEDENT>for single_value in values:<EOL><INDENT>self.__headers[header_name].append(single_value)<EOL><DEDENT>
|
Add new header
:param header_name: name of the header to add
:param value: header value
:param values: additional header values (in a result request/response must be concatenated by the coma \
or by the separate header string)
:return: None
|
f9871:c0:m4
|
@verify_type('<STR_LIT>', header_name=str, value=str, values=str)<EOL><INDENT>@verify_value('<STR_LIT>', header_name=lambda x: WHTTPHeaders.header_name_check(x))<EOL>def replace_headers(self, header_name, value, *values):<DEDENT>
|
if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>header_name = self.normalize_name(header_name)<EOL>self.remove_headers(header_name)<EOL>self.add_headers(header_name, value, *values)<EOL>
|
Replace header value with specified value and/or values
:param header_name: target header
:param value: new header value
:param values: additional header values (in a result request/response must be concatenated by the coma \
or by the separate header string)
:return: None
|
f9871:c0:m5
|
@verify_type('<STR_LIT>', header_name=str)<EOL><INDENT>@verify_value('<STR_LIT>', header_name=lambda x: WHTTPHeaders.header_name_check(x))<EOL>def get_headers(self, header_name):<DEDENT>
|
header_name = self.normalize_name(header_name)<EOL>if header_name in self.__headers.keys():<EOL><INDENT>return tuple(self.__headers[header_name])<EOL><DEDENT>
|
Return header value by its name
:param header_name: header name
:return: tuple of str
|
f9871:c0:m6
|
@verify_type('<STR_LIT>', item=str)<EOL><INDENT>@verify_value('<STR_LIT>', item=lambda x: WHTTPHeaders.header_name_check(x))<EOL>def __getitem__(self, item):<DEDENT>
|
return self.get_headers(item)<EOL>
|
Return header value by its name
:param item: header name
:return: tuple of str
|
f9871:c0:m7
|
@verify_type(header_name=str)<EOL><INDENT>@verify_value(header_name=lambda x: WHTTPHeaders.header_name_check(x))<EOL>def normalize_name(self, header_name):<DEDENT>
|
if self.__normalization_mode in ['<STR_LIT>', '<STR_LIT:1.0>', '<STR_LIT>']:<EOL><INDENT>return '<STR_LIT:->'.join([x.capitalize() for x in header_name.split('<STR_LIT:->')])<EOL><DEDENT>elif self.__normalization_mode == '<STR_LIT:2>':<EOL><INDENT>return header_name.lower()<EOL><DEDENT>raise RuntimeError('<STR_LIT>' % self.__normalization_mode)<EOL>
|
Return header name as it is recommended (required) by corresponding http protocol. For
protocol switching use :meth:`.WHTTPHeaders.switch_name_style` method.
All current available protocols (0.9-2) compare header names in a case-insensitive fashion. However,
previous protocol versions (0.9-1.1) recommends to use camel-case names like Foo or Foo-Bar. But
HTTP/2 (RFC 7540) strictly requires lowercase only header names.
:param header_name: name to convert
:return: str
|
f9871:c0:m8
|
@verify_type(http_protocol_version=str)<EOL><INDENT>@verify_value(http_protocol_version=lambda x: x in ['<STR_LIT>', '<STR_LIT:1.0>', '<STR_LIT>', '<STR_LIT:2>'])<EOL>def switch_name_style(self, http_protocol_version):<DEDENT>
|
new_headers = WHTTPHeaders()<EOL>new_headers.__normalization_mode = http_protocol_version<EOL>names = self.headers()<EOL>for name in names:<EOL><INDENT>new_headers.add_headers(name, *self.get_headers(name))<EOL><DEDENT>for cookie_name in self.__set_cookies.cookies():<EOL><INDENT>new_headers.__set_cookies.add_cookie(self.__set_cookies[cookie_name].copy())<EOL><DEDENT>return new_headers<EOL>
|
Return object copy with header names saved as it is described in the given protocol version
see :meth:`.WHTTPHeaders.normalize_name`
:param http_protocol_version: target HTTP protocol version
:return: WHTTPHeaders
|
f9871:c0:m9
|
def ro(self):
|
ro_headers = WHTTPHeaders()<EOL>names = self.headers()<EOL>for name in names:<EOL><INDENT>ro_headers.add_headers(name, *self.get_headers(name))<EOL><DEDENT>ro_headers.__cookies = self.__set_cookies.ro()<EOL>ro_headers.__ro_flag = True<EOL>return ro_headers<EOL>
|
Return read-only copy of this object
:return: WHTTPHeaders
|
f9871:c0:m10
|
@verify_type('<STR_LIT>', value=(str, None))<EOL><INDENT>def content_type(self, value=None):<DEDENT>
|
content_type = self.normalize_name('<STR_LIT:Content-Type>')<EOL>if value is not None:<EOL><INDENT>self.replace_headers(content_type, value)<EOL><DEDENT>if content_type in self.__headers.keys():<EOL><INDENT>return self.__headers[content_type][<NUM_LIT:0>]<EOL><DEDENT>
|
Set (replace) and or get "Content-Type" header value
:param value: value to set (if specified)
:return: None if header doesn't exist, otherwise - str
|
f9871:c0:m11
|
def set_cookie_jar(self):
|
return self.__set_cookies<EOL>
|
Return internal cookie jar that must be used for HTTP-response
see :class:`.WHTTPCookieJar`
:return: WHTTPCookieJar
|
f9871:c0:m12
|
def client_cookie_jar(self):
|
cookie_jar = WHTTPCookieJar()<EOL>cookie_header = self.get_headers('<STR_LIT>')<EOL>for cookie_string in (cookie_header if cookie_header is not None else tuple()):<EOL><INDENT>for single_cookie in WHTTPCookieJar.import_header_text(cookie_string):<EOL><INDENT>cookie_jar.add_cookie(single_cookie)<EOL><DEDENT><DEDENT>return cookie_jar.ro()<EOL>
|
Return internal cookie jar that must be used as HTTP-request cookies
see :class:`.WHTTPCookieJar`
:return: WHTTPCookieJar
|
f9871:c0:m13
|
@classmethod<EOL><INDENT>@verify_type(http_code=str)<EOL>def import_headers(cls, http_code):<DEDENT>
|
headers = WHTTPHeaders()<EOL>message = email.message_from_file(StringIO(http_code))<EOL>for header_name, header_value in message.items():<EOL><INDENT>headers.add_headers(header_name, header_value)<EOL><DEDENT>cookie_header = headers.get_headers('<STR_LIT>')<EOL>if cookie_header is not None:<EOL><INDENT>for cookie_string in cookie_header:<EOL><INDENT>for single_cookie in WHTTPCookieJar.import_header_text(cookie_string):<EOL><INDENT>headers.set_cookie_jar().add_cookie(single_cookie)<EOL><DEDENT><DEDENT>headers.remove_headers('<STR_LIT>')<EOL><DEDENT>return headers<EOL>
|
Create WHTTPHeaders by the given code. If code has 'Set-Cookie' headers, that headers are
parsed, data are stored in internal cookie jar. At the end of parsing 'Set-Cookie' headers are
removed from the result
:param http_code: HTTP code to parse
:return: WHTTPHeaders
|
f9871:c0:m14
|
@staticmethod<EOL><INDENT>def cookie_name_check(cookie_name):<DEDENT>
|
cookie_match = WHTTPCookie.cookie_name_non_compliance_re.match(cookie_name.encode('<STR_LIT>'))<EOL>return len(cookie_name) > <NUM_LIT:0> and cookie_match is None<EOL>
|
Check cookie name for validity. Return True if name is valid
:param cookie_name: name to check
:return: bool
|
f9872:c0:m0
|
@staticmethod<EOL><INDENT>def cookie_value_check(cookie_value):<DEDENT>
|
return WHTTPCookie.cookie_value_non_compliance_re.match(cookie_value.encode('<STR_LIT>')) is None<EOL>
|
Check cookie value for validity. Return True if value is valid
:param cookie_value: value to check
:return: bool
|
f9872:c0:m1
|
@staticmethod<EOL><INDENT>def cookie_attr_value_check(attr_name, attr_value):<DEDENT>
|
attr_value.encode('<STR_LIT>')<EOL>return WHTTPCookie.cookie_attr_value_compliance[attr_name].match(attr_value) is not None<EOL>
|
Check cookie attribute value for validity. Return True if value is valid
:param attr_name: attribute name to check
:param attr_value: attribute value to check
:return: bool
|
f9872:c0:m2
|
@verify_type(name=str, value=str)<EOL><INDENT>@verify_value(name=lambda x: WHTTPCookie.cookie_name_check(x))<EOL>@verify_value(value=lambda x: WHTTPCookie.cookie_value_check(x))<EOL>def __init__(self, name, value, **attrs):<DEDENT>
|
self.__name = name<EOL>self.__value = value<EOL>self.__attrs = {}<EOL>self.__ro_flag = False<EOL>for attr_name in attrs:<EOL><INDENT>self.attr(attr_name, attrs[attr_name])<EOL><DEDENT>
|
Construct new cookie with defined name, value and attributes
:param name: cookie name
:param value: cookie value
:param attrs: cookie attribute with its value. Attribute name must be in lowercase. In order to set
'max-age' attribute, dash character ('-') may be replaced by underscore ('_') both variants are
allowed
|
f9872:c0:m3
|
def name(self):
|
return self.__name<EOL>
|
Return cookie name
:return: str
|
f9872:c0:m4
|
@verify_type(name=str, new_value=(str, None))<EOL><INDENT>@verify_value(new_value=lambda x: x is None or WHTTPCookie.cookie_value_check(x))<EOL>def value(self, new_value=None):<DEDENT>
|
if new_value is not None:<EOL><INDENT>if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>self.__value = new_value<EOL><DEDENT>return self.__value<EOL>
|
Return cookie value. Cookie value can be updated, when new_value is not None. Cookie value
couldn't be changed if cookie is in read-only mode (RuntimeError exception is raised).
:param new_value: new value to set
:return: str
|
f9872:c0:m5
|
def attrs_as_dict(self):
|
return self.__attrs.copy()<EOL>
|
Return cookie attributes as dictionary, where keys are attribute names and values are their
values
:return: dict
|
f9872:c0:m6
|
@verify_type(name=str)<EOL><INDENT>def __attr_name(self, name):<DEDENT>
|
if name not in self.cookie_attr_value_compliance.keys():<EOL><INDENT>suggested_name = name.replace('<STR_LIT:_>', '<STR_LIT:->').lower()<EOL>if suggested_name not in self.cookie_attr_value_compliance.keys():<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>name = suggested_name<EOL><DEDENT>return name<EOL>
|
Return suitable and valid attribute name. This method replaces dash char to underscore. If name
is invalid ValueError exception is raised
:param name: cookie attribute name
:return: str
|
f9872:c0:m7
|
@verify_type('<STR_LIT>', attr_name=str)<EOL><INDENT>@verify_type(attr_value=(str, None))<EOL>def attr(self, attr_name, attr_value=None):<DEDENT>
|
name = self.__attr_name(attr_name)<EOL>if attr_value is not None:<EOL><INDENT>if WHTTPCookie.cookie_attr_value_check(name, attr_value) is not True:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>self.__attrs[name] = attr_value<EOL>return attr_value<EOL><DEDENT>return self.__attrs[name]<EOL>
|
Return attribute value. Attribute value can be updated with this method. In order to update
attribute value attr_value must be set. Cookie attribute value couldn't be changed if cookie is
in read-only mode (RuntimeError exception is raised).
:param attr_name: target attribute name
:param attr_value: new value to set
:return: str
|
f9872:c0:m8
|
@verify_type('<STR_LIT>', attr_name=str)<EOL><INDENT>def remove_attr(self, attr_name):<DEDENT>
|
if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>name = self.__attr_name(attr_name)<EOL>if name in self.__attrs.keys():<EOL><INDENT>self.__attrs.pop(attr_name)<EOL><DEDENT>
|
Remove cookie attribute. Cookie attribute couldn't be removed if cookie is in read-only mode
(RuntimeError exception is raised).
:param attr_name: name of attribute to remove
:return: None
|
f9872:c0:m9
|
def __str__(self):
|
simple_cookie = SimpleCookie()<EOL>simple_cookie[self.__name] = self.__value<EOL>for attr_name in self.__attrs.keys():<EOL><INDENT>simple_cookie[self.__name][attr_name] = self.__attrs[attr_name]<EOL><DEDENT>return str(simple_cookie)<EOL>
|
Return valid "Set-Cookie" HTTP-header for this cookie
:return: str
|
f9872:c0:m10
|
def ro(self):
|
ro_cookie = self.copy()<EOL>ro_cookie.__ro_flag = True<EOL>return ro_cookie<EOL>
|
Return read-only copy
:return: WHTTPCookie
|
f9872:c0:m11
|
def copy(self):
|
copy_cookie = WHTTPCookie(self.__name, self.__value)<EOL>copy_cookie.__attrs = self.__attrs.copy()<EOL>return copy_cookie<EOL>
|
Return copy
:return: WHTTPCookie
|
f9872:c0:m12
|
def __init__(self):
|
self.__cookies = {}<EOL>self.__ro_flag = False<EOL>
|
Construct new collection
|
f9872:c1:m0
|
def cookies(self):
|
return tuple(self.__cookies.keys())<EOL>
|
Return available cookie names
:return: tuple of str
|
f9872:c1:m1
|
@verify_type(cookie=WHTTPCookie)<EOL><INDENT>def add_cookie(self, cookie):<DEDENT>
|
if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>self.__cookies[cookie.name()] = cookie<EOL>
|
Add new cookie (or replace if there is cookie with the same name already)
:param cookie: cookie to add
:return: None
|
f9872:c1:m2
|
@verify_type(cookie_name=str)<EOL><INDENT>def remove_cookie(self, cookie_name):<DEDENT>
|
if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if cookie_name in self.__cookies.keys():<EOL><INDENT>self.__cookies.pop(cookie_name)<EOL><DEDENT>
|
Remove cookie by its name
:param cookie_name: cookie name
:return:
|
f9872:c1:m3
|
@verify_type(item=str)<EOL><INDENT>def __getitem__(self, item):<DEDENT>
|
return self.__cookies[item]<EOL>
|
Get cookie by its name
:param item: cookie name
:return:
|
f9872:c1:m4
|
def __iter__(self):
|
for cookie in self.__cookies.values():<EOL><INDENT>yield cookie<EOL><DEDENT>
|
Iterate over cookie collection
:return: None
|
f9872:c1:m5
|
def ro(self):
|
ro_jar = WHTTPCookieJar()<EOL>for cookie in self.__cookies.values():<EOL><INDENT>ro_jar.add_cookie(cookie.ro())<EOL><DEDENT>ro_jar.__ro_flag = True<EOL>return ro_jar<EOL>
|
Return read-only copy
:return: WHTTPCookieJar
|
f9872:c1:m6
|
@classmethod<EOL><INDENT>@verify_type(simple_cookie=SimpleCookie)<EOL>def import_simple_cookie(cls, simple_cookie):<DEDENT>
|
cookie_jar = WHTTPCookieJar()<EOL>for cookie_name in simple_cookie.keys():<EOL><INDENT>cookie_attrs = {}<EOL>for attr_name in WHTTPCookie.cookie_attr_value_compliance.keys():<EOL><INDENT>attr_value = simple_cookie[cookie_name][attr_name]<EOL>if attr_value != '<STR_LIT>':<EOL><INDENT>cookie_attrs[attr_name] = attr_value<EOL><DEDENT><DEDENT>cookie_jar.add_cookie(WHTTPCookie(<EOL>cookie_name, simple_cookie[cookie_name].value, **cookie_attrs<EOL>))<EOL><DEDENT>return cookie_jar<EOL>
|
Create cookie jar from SimpleCookie object
:param simple_cookie: cookies to import
:return: WHTTPCookieJar
|
f9872:c1:m7
|
@classmethod<EOL><INDENT>@verify_type(cookie_text=str)<EOL>def import_header_text(cls, cookie_text):<DEDENT>
|
simple_cookie = SimpleCookie()<EOL>simple_cookie.load(cookie_text)<EOL>return cls.import_simple_cookie(simple_cookie)<EOL>
|
Create cookie jar from HTTP Header text like 'Set-Cookie: cookie=value'
:param cookie_text: http header code
:return: WHTTPCookieJar
|
f9872:c1:m8
|
@verify_type(session=WWebSessionProto, method=str, path=str, headers=(WHTTPHeaders, None))<EOL><INDENT>@verify_type(request_data=(bytes, None))<EOL>@verify_value(method=lambda x: len(x) > <NUM_LIT:0>)<EOL>@verify_value(path=lambda x: len(x) > <NUM_LIT:0>)<EOL>def __init__(self, session, method, path, headers=None, request_data=None):<DEDENT>
|
WWebRequestProto.__init__(self)<EOL>self.__session = session<EOL>self.__method = method.upper()<EOL>self.__path = path<EOL>self.__headers = headers<EOL>self.__request_data = request_data<EOL>self.__ro_flag = False<EOL>
|
Create new request descriptor
:param session: request origin
:param method: called HTTP-method
:param path: called HTTP-path
|
f9873:c0:m0
|
def session(self):
|
return self.__session<EOL>
|
Return origin session
:return: WWebSessionProto
|
f9873:c0:m1
|
def method(self):
|
return self.__method<EOL>
|
Return requested method
:return: str
|
f9873:c0:m2
|
def path(self):
|
return self.__path<EOL>
|
Return requested path
:return: str
|
f9873:c0:m3
|
def headers(self):
|
return self.__headers<EOL>
|
Return request headers
:return: WHTTPHeaders
|
f9873:c0:m4
|
@verify_type(headers=WHTTPHeaders)<EOL><INDENT>def set_headers(self, headers):<DEDENT>
|
if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>self.__headers = headers<EOL>
|
Set headers for request
:param headers: headers to set
:return: None
|
f9873:c0:m5
|
def request_data(self):
|
return self.__request_data<EOL>
|
Return request data
:return: bytes
|
f9873:c0:m6
|
@verify_type(request_data=bytes)<EOL><INDENT>def set_request_data(self, request_data):<DEDENT>
|
if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>self.__request_data = request_data<EOL>
|
Set payload data for request
:param request_data: data to set
:return: None
|
f9873:c0:m7
|
@classmethod<EOL><INDENT>@verify_type('<STR_LIT>', session=WWebSessionProto)<EOL>@verify_type(request_line=str)<EOL>def parse_request_line(cls, session, request_line):<DEDENT>
|
r = cls.request_line_re.search(request_line)<EOL>if r is not None:<EOL><INDENT>method, path, protocol_sentence, protocol_version = r.groups()<EOL>return WWebRequest(session, method, path)<EOL><DEDENT>raise ValueError('<STR_LIT>')<EOL>
|
Parse given request line like 'GET /foo' or 'POST /zzz HTTP/1.0'
:param session: origin session
:param request_line: line to parse
:return: WWebRequest
|
f9873:c0:m8
|
@verify_type('<STR_LIT>', http_code=str)<EOL><INDENT>def parse_headers(self, http_code):<DEDENT>
|
if self.__ro_flag:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>self.__headers = WHTTPHeaders.import_headers(http_code)<EOL>
|
Parse http-code (like 'Header-X: foo\r\nHeader-Y: bar\r\n') and retrieve (save) HTTP-headers
:param http_code: code to parse
:return: None
|
f9873:c0:m9
|
def ro(self):
|
request = WWebRequest(<EOL>self.session(), self.method(), self.path(),<EOL>headers=self.headers().ro(), request_data=self.request_data()<EOL>)<EOL>request.__ro_flag = True<EOL>return request<EOL>
|
Create read-only copy
:return: WWebRequest
|
f9873:c0:m10
|
@abstractmethod<EOL><INDENT>def session_id(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Create new token, that is used for session identification
:return: any type
|
f9875:c0:m0
|
@abstractmethod<EOL><INDENT>@verify_type(request=WWebRequestProto, protocol_version=str, protocol=str)<EOL>def request(self, session_id, request, protocol_version, protocol):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Dump client request
:param session_id: session origin
:param request: client request
:param protocol_version: client protocol version (like 0.9/1.0/1.1/2)
:param protocol: client protocol (like http/https)
:return: None
|
f9875:c0:m1
|
@abstractmethod<EOL><INDENT>@verify_type(response=WWebResponseProto)<EOL>def response(self, session_id, response):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Dump server response to client
:param session_id: session origin
:param response: server response
:return: None
|
f9875:c0:m2
|
@abstractmethod<EOL><INDENT>@verify_type(target_route=(WWebTargetRouteProto, None))<EOL>def target_route(self, session_id, target_route):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Dump target route
:param session_id: session origin
:param target_route: target route
:return: None
|
f9875:c0:m3
|
@abstractmethod<EOL><INDENT>@verify_type(exc=Exception)<EOL>def exception(self, session_id, exc):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Dump raised exception (may be called more then once)
:param session_id: session origin
:param exc: raised exception
:return: None
|
f9875:c0:m4
|
@abstractmethod<EOL><INDENT>def finalize(self, session_id):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Client session finalization. This method is called whenever exceptions were risen or not
:param session_id: session origin
:return: None
|
f9875:c0:m5
|
def status(self):
|
pass<EOL>
|
Return response status code. Is required for 1.0 protocol and beyond. It must be avoid
in HTTP/0.9
:return: None or int
|
f9877:c0:m0
|
def headers(self):
|
pass<EOL>
|
Return headers to set in response.
:return: None if no headers is needed to be written or WHTTPHeaders
|
f9877:c0:m1
|
def response_data(self):
|
pass<EOL>
|
Return response payload
:return: None if not required or bytes
|
f9877:c0:m2
|
def __pushed_responses__(self):
|
return tuple()<EOL>
|
Return related HTTP-responses, that can be pushed to client. Available on HTTP/2 only
:return: None if not required or tuple of WWebResponseProto
|
f9877:c0:m3
|
@abstractmethod<EOL><INDENT>def session(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return current session with which request is created
:return: WWebSessionProto
|
f9877:c1:m0
|
@abstractmethod<EOL><INDENT>def method(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return request method (like POST/GET/...)
:return: str
|
f9877:c1:m1
|
@abstractmethod<EOL><INDENT>def path(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return request path (like /foo/bar/index.html)
:return: str
|
f9877:c1:m2
|
@abstractmethod<EOL><INDENT>def headers(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return request headers
:return: None or WHTTPHeaders
|
f9877:c1:m3
|
def request_data(self):
|
pass<EOL>
|
Return request payload
:return: None or bytes
|
f9877:c1:m4
|
def virtual_host(self):
|
if self.headers() is not None:<EOL><INDENT>host_value = self.headers()['<STR_LIT>']<EOL>return host_value[<NUM_LIT:0>].lower() if host_value is not None else None<EOL><DEDENT>
|
Return request virtual host ("Host" header value)
:return: None or str
|
f9877:c1:m5
|
def content_type(self):
|
if self.headers() is not None:<EOL><INDENT>return self.headers().content_type()<EOL><DEDENT>
|
Return request content_type ("Content-Type" header value)
:return: None or str
|
f9877:c1:m6
|
def get_vars(self):
|
if self.method() != '<STR_LIT:GET>':<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>re_search = WWebRequestProto.get_vars_re.search(self.path())<EOL>if re_search is not None:<EOL><INDENT>return urllib.parse.parse_qs(re_search.group(<NUM_LIT:1>), keep_blank_values=<NUM_LIT:1>)<EOL><DEDENT>
|
Parse request path and return GET-vars
:return: None or dictionary of names and tuples of values
|
f9877:c1:m7
|
def post_vars(self):
|
if self.method() != '<STR_LIT:POST>':<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>content_type = self.content_type()<EOL>if content_type is None or content_type.lower() != '<STR_LIT>':<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>request_data = self.request_data()<EOL>request_data = request_data.decode() if request_data is not None else '<STR_LIT>'<EOL>re_search = WWebRequestProto.post_vars_re.search(request_data)<EOL>if re_search is not None:<EOL><INDENT>return urllib.parse.parse_qs(re_search.group(<NUM_LIT:1>), keep_blank_values=<NUM_LIT:1>)<EOL><DEDENT>
|
Parse request payload and return POST-vars
:return: None or dictionary of names and tuples of values
|
f9877:c1:m8
|
@abstractmethod<EOL><INDENT>def client_address(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return client IP-address and port
:return: WIPV4SocketInfo
|
f9877:c2:m0
|
@abstractmethod<EOL><INDENT>def server_address(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return server IP-address and port to which client is connected
:return: WIPV4SocketInfo
|
f9877:c2:m1
|
@abstractmethod<EOL><INDENT>def protocol_version(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return currently used protocol version
:return: str (one of "0.9"/"1.0"/"1.1"/"2")
|
f9877:c2:m2
|
@abstractmethod<EOL><INDENT>def protocol(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return currently used protocol
:return: str (one of "http"/"https")
|
f9877:c2:m3
|
@abstractmethod<EOL><INDENT>def read_request(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Read next request from session
:return: WWebRequestProto
|
f9877:c2:m4
|
@abstractmethod<EOL><INDENT>@verify_type(request=WWebRequestProto, reponse=WWebResponseProto)<EOL>def write_response(self, request, response):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Write response to client
:param request: original client request
:param response: response to write
:return:
|
f9877:c2:m5
|
@abstractmethod<EOL><INDENT>def session_close(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Close session
:return: None
|
f9877:c2:m6
|
@verify_type(request=WWebRequestProto)<EOL><INDENT>def __init__(self, request):<DEDENT>
|
self.__request = request<EOL>
|
Construct new worker
:param request: client request
|
f9877:c3:m0
|
@abstractclassmethod<EOL><INDENT>def __presenter_name__(cls):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
:return: str or None (in most cases - str)
|
f9877:c3:m1
|
def __request__(self):
|
return self.__request<EOL>
|
Return client request
:return: WWebRequestProto
|
f9877:c3:m2
|
@abstractmethod<EOL><INDENT>@verify_type(code=int)<EOL>@verify_value(code=lambda x: x > <NUM_LIT:0>)<EOL>def error_code(self, code):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return response for the given HTTP-code
:param code: HTTP-code of error
:return: WWebResponseProto
|
f9877:c4:m0
|
@abstractmethod<EOL><INDENT>@verify_type(exception=Exception)<EOL>def exception_error(self, exception):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return response for the given exception
:param exception: raised exception to process and or display
:return: WWebResponseProto
|
f9877:c4:m1
|
@abstractmethod<EOL><INDENT>def presenter_name(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return presenter name to be used
:return: WWebPresenter
|
f9877:c5:m0
|
@abstractmethod<EOL><INDENT>def presenter_action(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return method name to be called
:return: str
|
f9877:c5:m1
|
def presenter_args(self):
|
return dict()<EOL>
|
Return arguments to be used with presenter method
:return: dict, where keys - are argument names and values - argument values (any type)
|
f9877:c5:m2
|
@abstractmethod<EOL><INDENT>@verify_type(presenter_name=str)<EOL>@verify_value(presenter_name=lambda x: len(x) > <NUM_LIT:0>)<EOL>def presenter(self, presenter_name):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return presenter by its name
:param presenter_name: name of presenter class
:return: type (WWebPresenter sublcass) or None (if there is no such presenter)
|
f9877:c6:m0
|
@abstractmethod<EOL><INDENT>@verify_type(presenter_name=str)<EOL>@verify_value(presenter_name=lambda x: len(x) > <NUM_LIT:0>)<EOL>def has(self, presenter_name):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return if there is a presenter with the given name
:param presenter_name: name of presenter
:return: bool
|
f9877:c6:m1
|
@abstractmethod<EOL><INDENT>@verify_subclass(presenter_class=WWebPresenter)<EOL>def instantiable(self, presenter_class):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Check if this factory can produce the specified presenter
:param presenter_class: target presenter class
:return: bool
|
f9877:c7:m0
|
@abstractmethod<EOL><INDENT>@verify_type(presenter_name=str)<EOL>@verify_subclass(presenter_class=WWebPresenter)<EOL>def instantiate(self, presenter_class, *args, **kwargs):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Create new presenter object. Different implementation may have different required arguments
:param presenter_class: presenter class to instantiate
:param args: instantiation arguments (may vary)
:param kwargs: instantiation arguments (may vary)
:return: WWebPresenter
|
f9877:c7:m1
|
@abstractmethod<EOL><INDENT>def route_map(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return service route map
:return: WWebRouteMapProto
|
f9877:c8:m0
|
@abstractmethod<EOL><INDENT>def presenter_collection(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return service presenter collection
:return: WWebPresenterCollection
|
f9877:c8:m1
|
@abstractmethod<EOL><INDENT>def presenter_factory(self):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return current presenter factory
:return: WWebPresenterFactoryProto
|
f9877:c8:m2
|
@abstractmethod<EOL><INDENT>@verify_type(request=WWebRequestProto, target_route=WWebTargetRouteProto)<EOL>def execute(self, request, target_route):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Execute given target route and return response
:param request: client request
:param target_route: route to execute
:return: WWebResponseProto
|
f9877:c8:m3
|
@abstractmethod<EOL><INDENT>@verify_type(request=WWebRequestProto, service=WWebServiceProto)<EOL>def route(self, request, service):<DEDENT>
|
raise NotImplementedError('<STR_LIT>')<EOL>
|
Return the first route that matches client request
:param request: client request
:param service: source service
:return: None if no route is found, WWebTargetRouteProto otherwise
|
f9877:c9:m0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.