cengal.io.asock_io.versions.v_0.base

Module Docstring Docstrings: http://www.python.org/dev/peps/pep-0257/

  1#!/usr/bin/env python
  2# coding=utf-8
  3
  4# Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>
  5# 
  6# Licensed under the Apache License, Version 2.0 (the "License");
  7# you may not use this file except in compliance with the License.
  8# You may obtain a copy of the License at
  9# 
 10#     http://www.apache.org/licenses/LICENSE-2.0
 11# 
 12# Unless required by applicable law or agreed to in writing, software
 13# distributed under the License is distributed on an "AS IS" BASIS,
 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15# See the License for the specific language governing permissions and
 16# limitations under the License.
 17
 18
 19"""
 20Module Docstring
 21Docstrings: http://www.python.org/dev/peps/pep-0257/
 22"""
 23
 24
 25__author__ = "ButenkoMS <gtalk@butenkoms.space>"
 26__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>"
 27__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ]
 28__license__ = "Apache License, Version 2.0"
 29__version__ = "4.4.1"
 30__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>"
 31__email__ = "gtalk@butenkoms.space"
 32# __status__ = "Prototype"
 33__status__ = "Development"
 34# __status__ = "Production"
 35
 36
 37import socket
 38import errno
 39from cengal.code_flow_control.smart_values.versions.v_0 import ResultExistence
 40from cengal.base.classes import BaseClassSettings
 41
 42
 43
 44__author__ = 'ButenkoMS <gtalk@butenkoms.space>'
 45
 46
 47SET_OF_CONNECTION_ERRORS = {errno.ECONNRESET, errno.ECONNREFUSED, errno.ECONNABORTED, errno.EPIPE, errno.ESHUTDOWN}
 48INET_TYPE_CONNECTIONS = {socket.AF_INET, socket.AF_INET6}
 49
 50
 51try:
 52    BlockingIOError
 53except NameError:
 54    class BlockingIOError(OSError):
 55        pass
 56
 57try:
 58    InterruptedError
 59except NameError:
 60    class InterruptedError(OSError):
 61        pass
 62
 63try:
 64    ConnectionError
 65except NameError:
 66    class ConnectionError(OSError):
 67        pass
 68
 69try:
 70    BrokenPipeError
 71except NameError:
 72    class BrokenPipeError(ConnectionError):
 73        pass
 74
 75try:
 76    ConnectionAbortedError
 77except NameError:
 78    class ConnectionAbortedError(ConnectionError):
 79        pass
 80
 81try:
 82    ConnectionRefusedError
 83except NameError:
 84    class ConnectionRefusedError(ConnectionError):
 85        pass
 86
 87try:
 88    ConnectionResetError
 89except NameError:
 90    class ConnectionResetError(ConnectionError):
 91        pass
 92
 93
 94MESSAGE_SIZE_LEN = 8
 95SERVER_ANSWER__KEYWORD_ACCEPTED = b'OK'
 96
 97
 98class SimpleNetworkError(Exception):
 99    pass
100
101
102class ConnectionDirectionRole:
103    server = 0
104    client = 1
105
106
107# class IPVersion:
108#     ipv4 = 0
109#     ipv6 = 1
110
111
112# class ConnectionSettings(BaseClassSettings):
113#     def __init__(self, host=None, port=None, keyword=None, direction_role=None, ip_version=None):
114#         '''
115#         :param host: 'localhost', '192.168.0.1', ect.
116#         :param port: 8080
117#         :param keyword: b'sdlkfj s894 saf 84ewksdhf sdf'
118#         :param direction_role: ConnectionDirectionRole()
119#         :param ip_version: IPVersion()
120#         :return:
121#         '''
122#         self.host = host or str()
123#         self.port = port or None
124#         self.keyword = keyword or bytes()
125#         self.direction_role = direction_role or None
126#         self.ip_version = ip_version or None
127#
128#     def check(self):
129#         if (self.port is None) or (self.direction_role is None) or (self.ip_version is None):
130#             raise Exception('port can\'t be None; direction_role can\'t be None; ip_version can\'t be None.')
131
132
133class ConnectionSettings(BaseClassSettings):
134    def __init__(self, direction_role: ConnectionDirectionRole=None, socket_address=None, keyword: bytes=None,
135                 socket_family=socket.AF_INET, socket_type=socket.SOCK_STREAM, socket_protocol=0, socket_fileno=None):
136        '''
137        :param direction_role: ConnectionDirectionRole()
138        :param socket_address: './main.server.AF_UNIX.socket', ('localhost', 8080), ('::', 50007, 0, 0), , ect.
139        :param keyword: b'sdlkfj s894 saf 84ewksdhf sdf'. Can be None for a Super Server
140        :param socket_family: AF_INET (the default), AF_INET6, AF_UNIX, AF_CAN or AF_RDS
141        :param socket_type: SOCK_STREAM (the default), SOCK_DGRAM, SOCK_RAW or perhaps one of the other SOCK_ constants
142        :param socket_protocol: in the case where the address family is AF_CAN the protocol should be one of CAN_RAW or
143            CAN_BCM
144        :param socket_fileno: If fileno is specified, the other arguments are ignored, causing the socket with the
145            specified file descriptor to return
146        '''
147        self.direction_role = direction_role
148        self.keyword = keyword
149        self.socket_address = socket_address
150        self.socket_family = socket_family
151        self.socket_type = socket_type
152        self.socket_protocol = socket_protocol
153        self.socket_fileno = socket_fileno
154        self.expected_clients_with_empty_output_fifo = set()
155
156
157class IOCoreMemoryManagement:
158    def __init__(self):
159        self.global__data_size_limit = ResultExistence(True, 2 * 1024**3)
160
161        self.global_in__data_size_limit = ResultExistence(True, 512 * 1024**2)
162        self.global_in__data_full_size = ResultExistence(True, 0)
163        self.global_in__deletable_data_full_size = ResultExistence(True, 0)
164
165        self.global_out__data_size_limit = ResultExistence(True, 512 * 1024**2)
166        self.global_out__data_full_size = ResultExistence(True, 0)
167        self.global_out__deletable_data_full_size = ResultExistence(True, 0)
168
169    def link_to(self, parent):
170        self.global__data_size_limit = parent.global__data_size_limit
171
172        self.global_in__data_size_limit = parent.global_in__data_size_limit
173        self.global_in__data_full_size = parent.global_in__data_full_size
174        self.global_in__deletable_data_full_size = parent.global_in__deletable_data_full_size
175
176        self.global_out__data_size_limit = parent.global_out__data_size_limit
177        self.global_out__data_full_size = parent.global_out__data_full_size
178        self.global_out__deletable_data_full_size = parent.global_out__deletable_data_full_size
SET_OF_CONNECTION_ERRORS = {32, 103, 104, 108, 111}
INET_TYPE_CONNECTIONS = {<AddressFamily.AF_INET: 2>, <AddressFamily.AF_INET6: 10>}
MESSAGE_SIZE_LEN = 8
SERVER_ANSWER__KEYWORD_ACCEPTED = b'OK'
class SimpleNetworkError(builtins.Exception):
 99class SimpleNetworkError(Exception):
100    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
args
class ConnectionDirectionRole:
103class ConnectionDirectionRole:
104    server = 0
105    client = 1
server = 0
client = 1
class ConnectionSettings(cengal.base.classes.versions.v_0.classes.BaseClassSettings):
134class ConnectionSettings(BaseClassSettings):
135    def __init__(self, direction_role: ConnectionDirectionRole=None, socket_address=None, keyword: bytes=None,
136                 socket_family=socket.AF_INET, socket_type=socket.SOCK_STREAM, socket_protocol=0, socket_fileno=None):
137        '''
138        :param direction_role: ConnectionDirectionRole()
139        :param socket_address: './main.server.AF_UNIX.socket', ('localhost', 8080), ('::', 50007, 0, 0), , ect.
140        :param keyword: b'sdlkfj s894 saf 84ewksdhf sdf'. Can be None for a Super Server
141        :param socket_family: AF_INET (the default), AF_INET6, AF_UNIX, AF_CAN or AF_RDS
142        :param socket_type: SOCK_STREAM (the default), SOCK_DGRAM, SOCK_RAW or perhaps one of the other SOCK_ constants
143        :param socket_protocol: in the case where the address family is AF_CAN the protocol should be one of CAN_RAW or
144            CAN_BCM
145        :param socket_fileno: If fileno is specified, the other arguments are ignored, causing the socket with the
146            specified file descriptor to return
147        '''
148        self.direction_role = direction_role
149        self.keyword = keyword
150        self.socket_address = socket_address
151        self.socket_family = socket_family
152        self.socket_type = socket_type
153        self.socket_protocol = socket_protocol
154        self.socket_fileno = socket_fileno
155        self.expected_clients_with_empty_output_fifo = set()
ConnectionSettings( direction_role: ConnectionDirectionRole = None, socket_address=None, keyword: bytes = None, socket_family=<AddressFamily.AF_INET: 2>, socket_type=<SocketKind.SOCK_STREAM: 1>, socket_protocol=0, socket_fileno=None)
135    def __init__(self, direction_role: ConnectionDirectionRole=None, socket_address=None, keyword: bytes=None,
136                 socket_family=socket.AF_INET, socket_type=socket.SOCK_STREAM, socket_protocol=0, socket_fileno=None):
137        '''
138        :param direction_role: ConnectionDirectionRole()
139        :param socket_address: './main.server.AF_UNIX.socket', ('localhost', 8080), ('::', 50007, 0, 0), , ect.
140        :param keyword: b'sdlkfj s894 saf 84ewksdhf sdf'. Can be None for a Super Server
141        :param socket_family: AF_INET (the default), AF_INET6, AF_UNIX, AF_CAN or AF_RDS
142        :param socket_type: SOCK_STREAM (the default), SOCK_DGRAM, SOCK_RAW or perhaps one of the other SOCK_ constants
143        :param socket_protocol: in the case where the address family is AF_CAN the protocol should be one of CAN_RAW or
144            CAN_BCM
145        :param socket_fileno: If fileno is specified, the other arguments are ignored, causing the socket with the
146            specified file descriptor to return
147        '''
148        self.direction_role = direction_role
149        self.keyword = keyword
150        self.socket_address = socket_address
151        self.socket_family = socket_family
152        self.socket_type = socket_type
153        self.socket_protocol = socket_protocol
154        self.socket_fileno = socket_fileno
155        self.expected_clients_with_empty_output_fifo = set()

:param direction_role: ConnectionDirectionRole() :param socket_address: './main.server.AF_UNIX.socket', ('localhost', 8080), ('::', 50007, 0, 0), , ect. :param keyword: b'sdlkfj s894 saf 84ewksdhf sdf'. Can be None for a Super Server :param socket_family: AF_INET (the default), AF_INET6, AF_UNIX, AF_CAN or AF_RDS :param socket_type: SOCK_STREAM (the default), SOCK_DGRAM, SOCK_RAW or perhaps one of the other SOCK_ constants :param socket_protocol: in the case where the address family is AF_CAN the protocol should be one of CAN_RAW or CAN_BCM :param socket_fileno: If fileno is specified, the other arguments are ignored, causing the socket with the specified file descriptor to return

direction_role
keyword
socket_address
socket_family
socket_type
socket_protocol
socket_fileno
expected_clients_with_empty_output_fifo
Inherited Members
cengal.base.classes.versions.v_0.classes.BaseClassSettings
check
class IOCoreMemoryManagement:
158class IOCoreMemoryManagement:
159    def __init__(self):
160        self.global__data_size_limit = ResultExistence(True, 2 * 1024**3)
161
162        self.global_in__data_size_limit = ResultExistence(True, 512 * 1024**2)
163        self.global_in__data_full_size = ResultExistence(True, 0)
164        self.global_in__deletable_data_full_size = ResultExistence(True, 0)
165
166        self.global_out__data_size_limit = ResultExistence(True, 512 * 1024**2)
167        self.global_out__data_full_size = ResultExistence(True, 0)
168        self.global_out__deletable_data_full_size = ResultExistence(True, 0)
169
170    def link_to(self, parent):
171        self.global__data_size_limit = parent.global__data_size_limit
172
173        self.global_in__data_size_limit = parent.global_in__data_size_limit
174        self.global_in__data_full_size = parent.global_in__data_full_size
175        self.global_in__deletable_data_full_size = parent.global_in__deletable_data_full_size
176
177        self.global_out__data_size_limit = parent.global_out__data_size_limit
178        self.global_out__data_full_size = parent.global_out__data_full_size
179        self.global_out__deletable_data_full_size = parent.global_out__deletable_data_full_size
global__data_size_limit
global_in__data_size_limit
global_in__data_full_size
global_in__deletable_data_full_size
global_out__data_size_limit
global_out__data_full_size
global_out__deletable_data_full_size