osbrain.address
— osBrain address logic¶
Implementation of address-related features.
-
class
osbrain.address.
AgentAddress
(transport, address, kind, role, serializer)¶ Bases:
object
Agent address information consisting on the transport protocol, address, kind and role.
Parameters: - transport : str, AgentAddressTransport
Agent transport protocol.
- address : str
Agent address.
- kind : str, AgentAddressKind
Agent kind.
- role : str, AgentAddressRole
Agent role.
- serializer : str
Agent serializer type.
Attributes: - transport : str, AgentAddressTransport
Agent transport protocol.
- address : int
Agent address.
- kind : AgentAddressKind
Agent kind.
- role : AgentAddressRole
Agent role.
- serializer : AgentAddressSerializer
Agent serializer.
Methods
twin
()Returns: -
twin
()¶ Returns: - AgentAddress
The twin address of the current one; while the host and port are kept for the twin, the kind and role change to their corresponding twins, according to the rules defined in the respective classes.
-
class
osbrain.address.
AgentAddressKind
¶ Bases:
str
Agent’s address kind class.
This kind represents the communication pattern being used by the agent address: REP, PULL, PUB…
Methods
capitalize
()Return a capitalized version of S, i.e. casefold
()Return a version of S suitable for caseless comparisons. center
(width[, fillchar])Return S centered in a string of length width. count
(sub[, start[, end]])Return the number of non-overlapping occurrences of substring sub in string S[start:end]. encode
([encoding, errors])Encode S using the codec registered for encoding. endswith
(suffix[, start[, end]])Return True if S ends with the specified suffix, False otherwise. expandtabs
([tabsize])Return a copy of S where all tab characters are expanded using spaces. find
(sub[, start[, end]])Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. format
(*args, **kwargs)Return a formatted version of S, using substitutions from args and kwargs. format_map
(mapping)Return a formatted version of S, using substitutions from mapping. index
(sub[, start[, end]])Like S.find() but raise ValueError when the substring is not found. isalnum
()Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise. isalpha
()Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise. isdecimal
()Return True if there are only decimal characters in S, False otherwise. isdigit
()Return True if all characters in S are digits and there is at least one character in S, False otherwise. isidentifier
()Return True if S is a valid identifier according to the language definition. islower
()Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise. isnumeric
()Return True if there are only numeric characters in S, False otherwise. isprintable
()Return True if all characters in S are considered printable in repr() or S is empty, False otherwise. isspace
()Return True if all characters in S are whitespace and there is at least one character in S, False otherwise. istitle
()Return True if S is a titlecased string and there is at least one character in S, i.e. isupper
()Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise. join
(iterable)Return a string which is the concatenation of the strings in the iterable. ljust
(width[, fillchar])Return S left-justified in a Unicode string of length width. lower
()Return a copy of the string S converted to lowercase. lstrip
([chars])Return a copy of the string S with leading whitespace removed. maketrans
(x[, y, z])Return a translation table usable for str.translate(). partition
(sep)Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. replace
(old, new[, count])Return a copy of S with all occurrences of substring old replaced by new. requires_handler
()Returns: rfind
(sub[, start[, end]])Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. rindex
(sub[, start[, end]])Like S.rfind() but raise ValueError when the substring is not found. rjust
(width[, fillchar])Return S right-justified in a string of length width. rpartition
(sep)Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. rsplit
([sep, maxsplit])Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front. rstrip
([chars])Return a copy of the string S with trailing whitespace removed. split
([sep, maxsplit])Return a list of the words in S, using sep as the delimiter string. splitlines
([keepends])Return a list of the lines in S, breaking at line boundaries. startswith
(prefix[, start[, end]])Return True if S starts with the specified prefix, False otherwise. strip
([chars])Return a copy of the string S with leading and trailing whitespace removed. swapcase
()Return a copy of S with uppercase characters converted to lowercase and vice versa. title
()Return a titlecased version of S, i.e. translate
(table)Return a copy of the string S in which each character has been mapped through the given translation table. twin
()Returns: upper
()Return a copy of S converted to uppercase. zfill
(width)Pad a numeric string S with zeros on the left, to fill a field of the specified width. zmq
()Returns: -
REQUIRE_HANDLER
= ('REP', 'PULL', 'SUB', 'PULL_SYNC_PUB')¶
-
TWIN
= {'PUB': 'SUB', 'PULL': 'PUSH', 'PULL_SYNC_PUB': 'PUSH_SYNC_SUB', 'PUSH': 'PULL', 'PUSH_SYNC_SUB': 'PULL_SYNC_PUB', 'REP': 'REQ', 'REQ': 'REP', 'SUB': 'PUB'}¶
-
ZMQ_KIND_CONVERSION
= {'PUB': 1, 'PULL': 7, 'PULL_SYNC_PUB': 7, 'PUSH': 8, 'PUSH_SYNC_SUB': 8, 'REP': 4, 'REQ': 3, 'SUB': 2}¶
-
requires_handler
()¶ Returns: - bool
Whether the Agent’s address kind requires a handler or not. A socket which processes incoming messages would require a handler (i.e. ‘REP’, ‘PULL’, ‘SUB’…).
-
twin
()¶ Returns: - AgentAddressKind
The twin kind of the current one; REQ would be the twin of REP and viceversa, PUB would be the twin of SUB and viceversa, etc.
-
zmq
()¶ Returns: - int
The equivalent ZeroMQ socket kind.
-
-
class
osbrain.address.
AgentAddressRole
¶ Bases:
str
Agent’s address role class. It can either be ‘server’ or ‘client’.
Methods
capitalize
()Return a capitalized version of S, i.e. casefold
()Return a version of S suitable for caseless comparisons. center
(width[, fillchar])Return S centered in a string of length width. count
(sub[, start[, end]])Return the number of non-overlapping occurrences of substring sub in string S[start:end]. encode
([encoding, errors])Encode S using the codec registered for encoding. endswith
(suffix[, start[, end]])Return True if S ends with the specified suffix, False otherwise. expandtabs
([tabsize])Return a copy of S where all tab characters are expanded using spaces. find
(sub[, start[, end]])Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. format
(*args, **kwargs)Return a formatted version of S, using substitutions from args and kwargs. format_map
(mapping)Return a formatted version of S, using substitutions from mapping. index
(sub[, start[, end]])Like S.find() but raise ValueError when the substring is not found. isalnum
()Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise. isalpha
()Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise. isdecimal
()Return True if there are only decimal characters in S, False otherwise. isdigit
()Return True if all characters in S are digits and there is at least one character in S, False otherwise. isidentifier
()Return True if S is a valid identifier according to the language definition. islower
()Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise. isnumeric
()Return True if there are only numeric characters in S, False otherwise. isprintable
()Return True if all characters in S are considered printable in repr() or S is empty, False otherwise. isspace
()Return True if all characters in S are whitespace and there is at least one character in S, False otherwise. istitle
()Return True if S is a titlecased string and there is at least one character in S, i.e. isupper
()Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise. join
(iterable)Return a string which is the concatenation of the strings in the iterable. ljust
(width[, fillchar])Return S left-justified in a Unicode string of length width. lower
()Return a copy of the string S converted to lowercase. lstrip
([chars])Return a copy of the string S with leading whitespace removed. maketrans
(x[, y, z])Return a translation table usable for str.translate(). partition
(sep)Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. replace
(old, new[, count])Return a copy of S with all occurrences of substring old replaced by new. rfind
(sub[, start[, end]])Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. rindex
(sub[, start[, end]])Like S.rfind() but raise ValueError when the substring is not found. rjust
(width[, fillchar])Return S right-justified in a string of length width. rpartition
(sep)Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. rsplit
([sep, maxsplit])Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front. rstrip
([chars])Return a copy of the string S with trailing whitespace removed. split
([sep, maxsplit])Return a list of the words in S, using sep as the delimiter string. splitlines
([keepends])Return a list of the lines in S, breaking at line boundaries. startswith
(prefix[, start[, end]])Return True if S starts with the specified prefix, False otherwise. strip
([chars])Return a copy of the string S with leading and trailing whitespace removed. swapcase
()Return a copy of S with uppercase characters converted to lowercase and vice versa. title
()Return a titlecased version of S, i.e. translate
(table)Return a copy of the string S in which each character has been mapped through the given translation table. twin
()Returns: upper
()Return a copy of S converted to uppercase. zfill
(width)Pad a numeric string S with zeros on the left, to fill a field of the specified width. -
twin
()¶ Returns: - AgentAddressRole
The twin role of the current one; server would be the twin of client and viceversa.
-
-
class
osbrain.address.
AgentAddressSerializer
(value)¶ Bases:
str
Agent’s address serializer class.
Each communication channel will have a serializer.
Note that for raw message passing, everything must be on bytes, and the programmer is the one responsible for converting data to bytes.
Parameters: - serializer_type : str
Serializer type (i.e.: ‘raw’, ‘pickle’…).
Methods
capitalize
()Return a capitalized version of S, i.e. casefold
()Return a version of S suitable for caseless comparisons. center
(width[, fillchar])Return S centered in a string of length width. count
(sub[, start[, end]])Return the number of non-overlapping occurrences of substring sub in string S[start:end]. encode
([encoding, errors])Encode S using the codec registered for encoding. endswith
(suffix[, start[, end]])Return True if S ends with the specified suffix, False otherwise. expandtabs
([tabsize])Return a copy of S where all tab characters are expanded using spaces. find
(sub[, start[, end]])Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. format
(*args, **kwargs)Return a formatted version of S, using substitutions from args and kwargs. format_map
(mapping)Return a formatted version of S, using substitutions from mapping. index
(sub[, start[, end]])Like S.find() but raise ValueError when the substring is not found. isalnum
()Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise. isalpha
()Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise. isdecimal
()Return True if there are only decimal characters in S, False otherwise. isdigit
()Return True if all characters in S are digits and there is at least one character in S, False otherwise. isidentifier
()Return True if S is a valid identifier according to the language definition. islower
()Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise. isnumeric
()Return True if there are only numeric characters in S, False otherwise. isprintable
()Return True if all characters in S are considered printable in repr() or S is empty, False otherwise. isspace
()Return True if all characters in S are whitespace and there is at least one character in S, False otherwise. istitle
()Return True if S is a titlecased string and there is at least one character in S, i.e. isupper
()Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise. join
(iterable)Return a string which is the concatenation of the strings in the iterable. ljust
(width[, fillchar])Return S left-justified in a Unicode string of length width. lower
()Return a copy of the string S converted to lowercase. lstrip
([chars])Return a copy of the string S with leading whitespace removed. maketrans
(x[, y, z])Return a translation table usable for str.translate(). partition
(sep)Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. replace
(old, new[, count])Return a copy of S with all occurrences of substring old replaced by new. rfind
(sub[, start[, end]])Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. rindex
(sub[, start[, end]])Like S.rfind() but raise ValueError when the substring is not found. rjust
(width[, fillchar])Return S right-justified in a string of length width. rpartition
(sep)Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. rsplit
([sep, maxsplit])Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front. rstrip
([chars])Return a copy of the string S with trailing whitespace removed. split
([sep, maxsplit])Return a list of the words in S, using sep as the delimiter string. splitlines
([keepends])Return a list of the lines in S, breaking at line boundaries. startswith
(prefix[, start[, end]])Return True if S starts with the specified prefix, False otherwise. strip
([chars])Return a copy of the string S with leading and trailing whitespace removed. swapcase
()Return a copy of S with uppercase characters converted to lowercase and vice versa. title
()Return a titlecased version of S, i.e. translate
(table)Return a copy of the string S in which each character has been mapped through the given translation table. upper
()Return a copy of S converted to uppercase. zfill
(width)Pad a numeric string S with zeros on the left, to fill a field of the specified width. -
SERIALIZER_SEPARATOR
= ('pickle', 'json')¶
-
SERIALIZER_SIMPLE
= ('raw',)¶
-
class
osbrain.address.
AgentAddressTransport
¶ Bases:
str
Agent’s address transport class. It can be ‘tcp’, ‘ipc’ or ‘inproc’.
Methods
capitalize
()Return a capitalized version of S, i.e. casefold
()Return a version of S suitable for caseless comparisons. center
(width[, fillchar])Return S centered in a string of length width. count
(sub[, start[, end]])Return the number of non-overlapping occurrences of substring sub in string S[start:end]. encode
([encoding, errors])Encode S using the codec registered for encoding. endswith
(suffix[, start[, end]])Return True if S ends with the specified suffix, False otherwise. expandtabs
([tabsize])Return a copy of S where all tab characters are expanded using spaces. find
(sub[, start[, end]])Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. format
(*args, **kwargs)Return a formatted version of S, using substitutions from args and kwargs. format_map
(mapping)Return a formatted version of S, using substitutions from mapping. index
(sub[, start[, end]])Like S.find() but raise ValueError when the substring is not found. isalnum
()Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise. isalpha
()Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise. isdecimal
()Return True if there are only decimal characters in S, False otherwise. isdigit
()Return True if all characters in S are digits and there is at least one character in S, False otherwise. isidentifier
()Return True if S is a valid identifier according to the language definition. islower
()Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise. isnumeric
()Return True if there are only numeric characters in S, False otherwise. isprintable
()Return True if all characters in S are considered printable in repr() or S is empty, False otherwise. isspace
()Return True if all characters in S are whitespace and there is at least one character in S, False otherwise. istitle
()Return True if S is a titlecased string and there is at least one character in S, i.e. isupper
()Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise. join
(iterable)Return a string which is the concatenation of the strings in the iterable. ljust
(width[, fillchar])Return S left-justified in a Unicode string of length width. lower
()Return a copy of the string S converted to lowercase. lstrip
([chars])Return a copy of the string S with leading whitespace removed. maketrans
(x[, y, z])Return a translation table usable for str.translate(). partition
(sep)Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. replace
(old, new[, count])Return a copy of S with all occurrences of substring old replaced by new. rfind
(sub[, start[, end]])Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. rindex
(sub[, start[, end]])Like S.rfind() but raise ValueError when the substring is not found. rjust
(width[, fillchar])Return S right-justified in a string of length width. rpartition
(sep)Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. rsplit
([sep, maxsplit])Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front. rstrip
([chars])Return a copy of the string S with trailing whitespace removed. split
([sep, maxsplit])Return a list of the words in S, using sep as the delimiter string. splitlines
([keepends])Return a list of the lines in S, breaking at line boundaries. startswith
(prefix[, start[, end]])Return True if S starts with the specified prefix, False otherwise. strip
([chars])Return a copy of the string S with leading and trailing whitespace removed. swapcase
()Return a copy of S with uppercase characters converted to lowercase and vice versa. title
()Return a titlecased version of S, i.e. translate
(table)Return a copy of the string S in which each character has been mapped through the given translation table. upper
()Return a copy of S converted to uppercase. zfill
(width)Pad a numeric string S with zeros on the left, to fill a field of the specified width.
-
class
osbrain.address.
AgentChannel
(kind, receiver, sender)¶ Bases:
object
Agent channel information.
Channels are communication means with sender and receiver in both sides (i.e.: PULL+PUB - PUSH-SUB or PULL+PUSH - PUSH+PULL).
Parameters: - kind : AgentChannelKind
Agent kind.
- sender : str
First AgentAddress.
- receiver : str
Second AgentAddress.
Attributes: - kind : AgentChannelKind
Agent kind.
- sender : str
First AgentAddress.
- receiver : str
Second AgentAddress.
Methods
twin
()Returns: -
twin
()¶ Returns: - AgentChannel
The twin channel of the current one.
-
class
osbrain.address.
AgentChannelKind
¶ Bases:
str
Agent’s channel kind class.
This kind represents the communication pattern being used by the agent channel: ASYNC_REP, STREAM…
Methods
capitalize
()Return a capitalized version of S, i.e. casefold
()Return a version of S suitable for caseless comparisons. center
(width[, fillchar])Return S centered in a string of length width. count
(sub[, start[, end]])Return the number of non-overlapping occurrences of substring sub in string S[start:end]. encode
([encoding, errors])Encode S using the codec registered for encoding. endswith
(suffix[, start[, end]])Return True if S ends with the specified suffix, False otherwise. expandtabs
([tabsize])Return a copy of S where all tab characters are expanded using spaces. find
(sub[, start[, end]])Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. format
(*args, **kwargs)Return a formatted version of S, using substitutions from args and kwargs. format_map
(mapping)Return a formatted version of S, using substitutions from mapping. index
(sub[, start[, end]])Like S.find() but raise ValueError when the substring is not found. isalnum
()Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise. isalpha
()Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise. isdecimal
()Return True if there are only decimal characters in S, False otherwise. isdigit
()Return True if all characters in S are digits and there is at least one character in S, False otherwise. isidentifier
()Return True if S is a valid identifier according to the language definition. islower
()Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise. isnumeric
()Return True if there are only numeric characters in S, False otherwise. isprintable
()Return True if all characters in S are considered printable in repr() or S is empty, False otherwise. isspace
()Return True if all characters in S are whitespace and there is at least one character in S, False otherwise. istitle
()Return True if S is a titlecased string and there is at least one character in S, i.e. isupper
()Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise. join
(iterable)Return a string which is the concatenation of the strings in the iterable. ljust
(width[, fillchar])Return S left-justified in a Unicode string of length width. lower
()Return a copy of the string S converted to lowercase. lstrip
([chars])Return a copy of the string S with leading whitespace removed. maketrans
(x[, y, z])Return a translation table usable for str.translate(). partition
(sep)Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. replace
(old, new[, count])Return a copy of S with all occurrences of substring old replaced by new. rfind
(sub[, start[, end]])Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. rindex
(sub[, start[, end]])Like S.rfind() but raise ValueError when the substring is not found. rjust
(width[, fillchar])Return S right-justified in a string of length width. rpartition
(sep)Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. rsplit
([sep, maxsplit])Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front. rstrip
([chars])Return a copy of the string S with trailing whitespace removed. split
([sep, maxsplit])Return a list of the words in S, using sep as the delimiter string. splitlines
([keepends])Return a list of the lines in S, breaking at line boundaries. startswith
(prefix[, start[, end]])Return True if S starts with the specified prefix, False otherwise. strip
([chars])Return a copy of the string S with leading and trailing whitespace removed. swapcase
()Return a copy of S with uppercase characters converted to lowercase and vice versa. title
()Return a titlecased version of S, i.e. translate
(table)Return a copy of the string S in which each character has been mapped through the given translation table. twin
()Returns: upper
()Return a copy of S converted to uppercase. zfill
(width)Pad a numeric string S with zeros on the left, to fill a field of the specified width. -
TWIN
= {'ASYNC_REP': 'ASYNC_REQ', 'ASYNC_REQ': 'ASYNC_REP', 'SYNC_PUB': 'SYNC_SUB', 'SYNC_SUB': 'SYNC_PUB'}¶
-
twin
()¶ Returns: - AgentChannelKind
The twin kind of the current one; REQ would be the twin of REP and viceversa, PUB would be the twin of SUB and viceversa, etc.
-
-
class
osbrain.address.
SocketAddress
(host, port)¶ Bases:
object
Socket address information consisting on the host and port.
Parameters: - host : str, ipaddress.IPv4Address
IP address.
- port : int
Port number.
Attributes: - host : ipaddress.IPv4Address
IP address.
- port : int
Port number.
-
osbrain.address.
address_to_host_port
(addr)¶ Try to convert an address to a (host, port) tuple.
Parameters: - addr : str, SocketAddress
Returns: - tuple
A (host, port) tuple formed with the corresponding data.
-
osbrain.address.
guess_kind
(kind)¶ Guess if a kind string is an AgentAddressKind or AgentChannelKind.
Parameters: - kind : str
The AgentAddressKind or AgentChannelKind in string format.
Returns: - AgentAddressKind or AgentChannelKind
The actual kind type.