osbrain.address
— osBrain address logic¶
Implementation of address-related features.
-
class
osbrain.address.
AgentAddress
(host, port, kind=None, role=None)¶ Bases:
osbrain.address.SocketAddress
Agent address information consisting on the host, port, kind and role.
Parameters: - host : str
Agent host.
- port : int
Agent port.
- kind : int, str, AgentAddressKind
Agent kind.
- role : str, AgentAddressRole
Agent role.
Attributes: - host : str
Agent host.
- port : int
Agent port.
- kind : AgentAddressKind
Agent kind.
- role : AgentAddressRole
Agent role.
Methods
socket_addr
()Returns: twin
()Returns: -
socket_addr
()¶ Returns: - SocketAddress
Agent address as a SocketAddress object. This means kind and role information are lost.
-
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:
int
Agent’s address kind class. It can be any ZMQ type (‘REP’, ‘PUB’…).
Inherits from int to be compatible with ZMQ definitions, however, it is represented in its string form. The equivalence can also be evaluated against its string form.
Attributes: denominator
the denominator of a rational number in lowest terms
imag
the imaginary part of a complex number
numerator
the numerator of a rational number in lowest terms
real
the real part of a complex number
Methods
bit_length
()Number of bits necessary to represent self in binary. conjugate
Returns self, the complex conjugate of any int. from_bytes
(bytes, byteorder, *[, signed])Return the integer represented by the given array of bytes. requires_handler
()Returns: to_bytes
(length, byteorder, *[, signed])Return an array of bytes representing an integer. twin
()Returns: -
ZMQ_KIND_TWIN
= {1: 2, 2: 1, 3: 4, 4: 3, 7: 8, 8: 7}¶
-
ZMQ_STR_CONVERSION
= {1: 'PUB', 2: 'SUB', 3: 'REQ', 4: 'REP', 7: 'PULL', 8: 'PUSH', 'PULL': 7, 'PUB': 1, 'SUB': 2, 'REQ': 3, 'REP': 4, 'PUSH': 8}¶
-
key
= 'PULL'¶
-
keys
= ['SUB', 'PUB', 'REQ', 'REP', 'PUSH', 'PULL']¶
-
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.
-
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.
SocketAddress
(host, port)¶ Bases:
object
Socket address information consisting on the host and port.
Parameters: - host : str
Agent host.
- port : int
Agent port.
Attributes: - host : str
Agent host.
- port : int
Agent port.