syft.generic.string¶
Module Contents¶
-
class
syft.generic.string.String(object: object = None, encoding: str = None, errors: str = None, id: Union[int, str] = None, owner: BaseWorker = None, tags: List[str] = None, description: str = None)¶ Bases:
syft.generic.object.AbstractObjectThis is a class that wraps the Python built-in str class. In addition to providing access to most of str’s method call API, it allows sending such wrapped string between workers the same way Syft tensors can be moved around among workers.
-
methods_to_hook¶
-
send(self, location: BaseWorker)¶ Sends this String object to the worker specified by ‘location’. and returns a pointer to that string as a StringPointer object.
- Parameters
location – The BaseWorker object which you want to send this object to. Note that this is never actually the BaseWorker but instead a class which inherits the BaseWorker abstraction.
- Returns
A StringPointer objects to self.
-
get_class_attributes(self)¶ returns minimal necessary keyword arguments to create a String object
-
on(self, object: str, wrap=False)¶ Takes and object of type strings and assigns it to self.child
-
__add__(self, other: Union[str, 'String'])¶ [Important] overriding the __add__ here is not yet activated. The real hooking happens in syft/generic/frameworks/hook/hook.py. Hooking as implemented here (using @overloaded.method) is to be activated when hook_args.py is adapted to wrapping reponses of str types into String types. This is not yet supported.
-
add_string(self, _self: String, other: String)¶ This method is created in a way adapted to the logic implemented in hook_args.py. That is, it can be wrapped with the decorator @oerloaded.method.
hook_args.py args hooking logic needs that the data types of argument be unchanged. For instance, ‘other’ should always be of a fixed type ‘String’ or ‘str’ but not alternating between both. This can cause unexpected behaviou due to caching in hook_args.py.
- Parameters
_self – a String object (as received by the decorator). It represents the objects on which we called the add method. It will always be of type str inside this method. Since the decorator methods strips the str out of the String object.
other – a String object that we wish to concatenate to _self. Same as above, it is a String object as received by the decorator but here it will always be of type str.
- Returns
The concatentenated str object between _self and other. this str object will be wrapped by the decorator into a String object
-
static
create_pointer(obj, location: BaseWorker = None, id_at_location: str or int = None, register: bool = False, owner: BaseWorker = None, ptr_id: str or int = None, garbage_collect_data: bool = True)¶ Creates a StringPointer object that points to a String object ‘obj’ after sending the latter to the worker ‘location’.
- Returns
a StringPointer object
-
static
simplify(worker: BaseWorker, string: String)¶ Breaks String object into a tuple of simpler objects, its constituting objects that are serializable.
- Parameters
worker – a BaseWorker object
string – the String object to be simplified
- Returns
A tuple of simpler objects that are sufficient to recreate a String object that is a clone of string.
-
static
detail(worker: BaseWorker, simple_obj: Tuple)¶ Create an object of type String from the reduced representation in simple_obj.
- Parameters
worker – BaseWorker The worker on which the new String object is to be created.
simple_obj – tuple A tuple resulting from the serialized then deserialized returned tuple from the simplify static method above.
- Returns
A String object
-