stringdatadeque package
Submodules
stringdatadeque.encryptedstringdeque module
An example subclass of string deque.
- class stringdatadeque.encryptedstringdeque.Base64Encoded(name_)[source]
Bases:
str
A class representing a Base64 encoded string.
- __slots__ = ('__name',)
- static is_base64(sb)[source]
Check if the input string or bytes object is a valid Base64 encoded string.
- Parameters:
sb (str or bytes) – The input string or bytes object to be checked.
- Returns:
True if the input is a valid Base64 encoded string, False otherwise.
- Return type:
bool
- __get__(instance, owner)[source]
Get the base64 encoded string.
- Parameters:
instance (RSAMessage or None) – The instance to get the value for.
owner (type) – The owner type of the descriptor.
- Returns:
The value of the descriptor for the instance.
- Return type:
str or Self
- get_decoded(instance)[source]
Get value base64 decoded.
- Parameters:
instance (RSAMessage) – An instance of RSAMessage.
- Returns:
The decoded message as bytes.
- Return type:
bytes
- __set__(instance, value)[source]
Set the value and encode as base64.
- Parameters:
instance (RSAMessage) – The instance of the class where the descriptor attribute is set.
value (str or bytes) – The value to be set, either a string or bytes.
- Returns:
None
- Return type:
None
- class stringdatadeque.encryptedstringdeque.RSAMessage(enc_session_key, nonce, tag, ciphertext)[source]
Bases:
object
A dataclass representing an RSA message.
- Parameters:
enc_session_key (str | bytes) – The encrypted session key.
nonce (str | bytes) – The nonce value.
tag (str | bytes) – The tag value.
ciphertext (str | bytes) – The encrypted ciphertext.
- __slots__ = ('_enc_session_key', '_nonce', '_tag', '_ciphertext')
- __init__(enc_session_key, nonce, tag, ciphertext)[source]
Initialize the object.
- Parameters:
enc_session_key (str or bytes) – The encrypted session key.
nonce (str or bytes) – The nonce value.
tag (str or bytes) – The tag value.
ciphertext (str or bytes) – The encrypted ciphertext.
- Returns:
None
- Return type:
None
-
enc_session_key:
str
|bytes
A class representing a Base64 encoded string.
-
nonce:
str
|bytes
A class representing a Base64 encoded string.
-
tag:
str
|bytes
A class representing a Base64 encoded string.
-
ciphertext:
str
|bytes
A class representing a Base64 encoded string.
- class stringdatadeque.encryptedstringdeque.EncryptedStringDeque(public_key, data=None, format_func=<staticmethod(<function EncryptedStringDeque.__keep_encrypted>)>, sep='')[source]
Bases:
StringDataDeque
[RSAMessage
,Printable
[Printable
]]Read once write many buffer, using RSA and AES.
- Parameters:
public_key (RSA.RsaKey) – The public key used for encryption.
data (SequenceNonstrOfStr | str | None) – The initial data to be stored in the deque.
format_func (Callable[[RSAMessage], str]) – The function used to format the encrypted data.
sep (str) – The separator used when joining the strings.
- __slots__ = ('type', 'public_key', 'session_key', 'enc_session_key', '_data')
- __init__(public_key, data=None, format_func=<staticmethod(<function EncryptedStringDeque.__keep_encrypted>)>, sep='')[source]
Initialize the object.
- Parameters:
public_key (RSA.RsaKey) – The public key used for encryption.
data (Union[str, List[str], None]) – The data to be encrypted. Can be a single string or a list of strings. Defaults to None.
format_func (Callable[[RSAMessage], str]) – The function used to format the encrypted data. Defaults to __keep_encrypted.
sep (str) – The separator used to join multiple encrypted messages. Defaults to ‘’.
- Returns:
None
- Return type:
None
-
session_key:
bytes
-
enc_session_key:
bytes
- type
- public_key
- static decrypt(msg, private_key)[source]
Decrypt a message using RSA encryption and AES decryption.
From https://www.pycryptodome.org/src/examples#encrypt-data-with-rsa.
- Parameters:
msg (RSAMessage) – An RSAMessage object containing encrypted data.
private_key (RSA.RsaKey) – Private key used for decryption.
- Returns:
The decrypted message as a string.
- Return type:
str
stringdatadeque.protocols module
Holds Protocols and types.
stringdatadeque.stringdatadeque module
Holds StringDeque class as well as several implementations of it.
- stringdatadeque.stringdatadeque.current_func_name(n=0)
- class stringdatadeque.stringdatadeque.InMatch[source]
Bases:
str
A class representing a custom string type used for ‘like’ matching.
- Parameters:
pattern (str) – Pattern string to match against.
- Returns:
True if pattern matches.
- __slots__ = ()
- class stringdatadeque.stringdatadeque.StringDataDeque(convert_func: Callable[[ConvertibleToDataType], DataType], format_func: Callable[[DataType], str], data: Sequence[ConvertibleToDataType] | None = None, sep: str = '')[source]
- class stringdatadeque.stringdatadeque.StringDataDeque(convert_func: Callable[[ConvertibleToDataType], DataType], format_func: Callable[[DataType], str], data: ConvertibleToDataType | None = None, sep: str = '')
Bases:
Generic
[DataType
,ConvertibleToDataType
]A generic class representing a deque of data that can be formatted as a string.
- Parameters:
convert_func (Callable[[ConvertibleToDataType], DataType]) – A function to convert data to a specific data type.
format_func (Callable[[DataType], str]) – A function to format data as a string.
data (SequenceNonStr[ConvertibleToDataType] | ConvertibleToDataType | None) – The data to be stored in the deque.
sep (str) – The separator to join elements when converting to a string. defaults to ‘’
- __slots__ = ('_data', 'convert_func', 'format_func', 'sep')
- __init__(convert_func, format_func, data=None, sep='')[source]
Initialize the StringDataDeque.
- Parameters:
convert_func (Callable[[ConvertibleToDataType], DataType]) – A callable function that converts input data to a specific data type.
format_func (Callable[[DataType], str]) – A callable function that formats the data for display.
data (Union[ConvertibleToDataType, SequenceNonStr[ConvertibleToDataType], None]) – Initial data to be processed. It can be a single element, a sequence of elements, or None.
sep (str) – A separator to be used when displaying the data.
- Returns:
None
- Return type:
None
- convert_func
- format_func
- sep
- __format__(format_spec)[source]
Format string with sep override.
- Parameters:
format_spec (str) – A string specifying the format.
- Returns:
The formatted string.
- Return type:
str
- __contains__(key)[source]
Return true if key is in the StringDataDeque or the string representation.
- Parameters:
key (DataType) – The key to check for in the data structure.
- Returns:
True if the key is found in the data structure, False otherwise.
- Return type:
bool
- __add__(other)[source]
Add the input data to the StringDataDeque.
- Parameters:
other (ConvertibleToDataType) – Data to be added to the current object.
- Returns:
Current object after adding the input data.
- Return type:
Self
- __radd__(other)[source]
Right add another value to the data container.
- Parameters:
other (ConvertibleToDataType) – A value that can be converted to the underlying data type of the container.
- Returns:
The modified container with the additional value added.
- Return type:
Self
- __iadd__(other)[source]
Add another element to the data container in place.
- Parameters:
other (ConvertibleToDataType) – Another element to add to the data container.
- Returns:
The updated data container with the new element added.
- Return type:
Self
- __ror__(other)[source]
Right or.
- Perform element-wise mapping of the input sequence using a conversion function
and extend the internal data with the mapped values.
- Parameters:
other (Sequence) – A sequence of elements to apply the conversion function to.
- Returns:
Updated instance with the mapped values added to the internal data.
- Return type:
Self
- __ior__(other)[source]
Update the object with the union of itself and another sequence.
- Parameters:
other (SequenceNonStr[ConvertibleToDataType]) – A sequence of items that can be converted to the same data type as the object.
- Returns:
The updated object after the union operation.
- Return type:
Self
- __len__()[source]
Return the length of the data stored in the StringDataDeque.
- Returns:
The length of the data.
- Return type:
int
- __getitem__(key)[source]
Get an item from the data using the specified key.
- Parameters:
key (SupportsIndex) – The key for retrieving the item from the data.
- Returns:
The item corresponding to the key in the data.
- Return type:
DataType
- __setitem__(key, value)[source]
Set the value of a key in the data dictionary.
- Parameters:
key (SupportsIndex) – The key to set in the dictionary.
value (ConvertibleToDataType) – The value to set for the given key.
- Returns:
None
- Return type:
None
- insert(other, /, pre_process_func=None, skip_conversion=False)[source]
Insert item(s) into the stringDequeue.
- Parameters:
other (
Union
[Sequence
[TypeVar
(T
)],TypeVar
(T
)]) – Item(s) to insert.pre_process_func (
Optional
[Callable
[[TypeVar
(T
)],TypeVar
(ConvertibleToDataType
)]]) – Function that will preprocess the data, defaults to Noneskip_conversion (
bool
) – Flag to skip conversion of items, defaults to False
- Return type:
Self
- Returns:
The StringDeque.
- class stringdatadeque.stringdatadeque.StringDeque(data: Sequence[Printable] | None = None, sep: str = '')[source]
- class stringdatadeque.stringdatadeque.StringDeque(data: Printable | None = None, sep: str = '')
Bases:
StringDataDeque
[str
,Printable
[Printable
]]A class representing a StringDeque.
- __slots__ = ()
- class stringdatadeque.stringdatadeque.CircularStringDeque(size: int, data: Sequence[Printable] | None = None, sep: str = '')[source]
- class stringdatadeque.stringdatadeque.CircularStringDeque(size: int, data: Printable | None = None, sep: str = '')
Bases:
StringDeque
A circular StringBuffer, overwrites once maxlen reached.
- __slots__ = ('_size',)
- __init__(size, data=None, sep='')[source]
Initialize CircularStringDeque with a limited size.
- Parameters:
size (int) – The maximum size of the data structure.
data (SequenceNonStr[Builtin_or_DefinesDunderStr] | Builtin_or_DefinesDunderStr | None) – Initial data to populate the structure (optional).
sep (str) – Separator for data elements when initializing (optional).
- Returns:
None
- Return type:
None
- class stringdatadeque.stringdatadeque.WORMStringDeque(data: Sequence[Printable] | None = None, sep: str = '')[source]
- class stringdatadeque.stringdatadeque.WORMStringDeque(data: Printable | None = None, sep: str = '')
Bases:
StringDeque
A class representing a WORM (Write Once Read Many) String Deque.
This class extends StringDeque and implements WORM (Write Once Read Many) functionality. It does not allow modification of existing items once they are added.
- Note: The following methods are not implemented in WORMStringDeque and will raise
NotImplementedError:
__setitem__: Setting items using indexing is not allowed.
clear: Clearing all items from the deque is not allowed.
__delitem__: Deleting items from the deque is not allowed.
- Raises:
NotImplementedError – When trying to perform unsupported operations on WORMStringDeque.
- __slots__ = ()
- __init__(data=None, sep='')[source]
Initialize the object with optional data and separator.
- Parameters:
data (SequenceNonStr[Builtin_or_DefinesDunderStr] | Builtin_or_DefinesDunderStr | None) – Optional data to initialize the object with.
sep (str) – Optional separator for the data.
- Returns:
None
- Return type:
None
- __setitem__(key, value)[source]
Set the value for a key in the object.
- Parameters:
key (SupportsIndex) – The key to set the value for.
value (Builtin_or_DefinesDunderStr) – The value to set for the key.
- Return type:
None
- Returns:
None
- Raises:
NotImplementedError – If the method is called and not implemented.
Module contents
Main package for stringdatadeque.