Skip to content

Client

reels.Clients

Clients(binary_image=None)

Interface to the c++ container object to hold clients.

The purpose of this object is to be filled (via successive add_client_id() calls) and passed to a Clips (and indirectly to Targets objects). The content can just be serialized as a pickle to make it pythonic, checked for size and iterated by calling client_hashes().

Parameters:

Name Type Description Default
binary_image list

An optional binary image (returned by save_as_binary_image()) to initialize the object with data copied from another Clients object.

None
Source code in reels/Clients.py
68
69
70
71
72
def __init__(self, binary_image=None):
    self.cl_id = new_clients()

    if binary_image is not None:
        self.load_from_binary_image(binary_image)

__getstate__()

Used by pickle.dump() (See https://docs.python.org/3/library/pickle.html)

Source code in reels/Clients.py
86
87
88
def __getstate__(self):
    """Used by pickle.dump() (See https://docs.python.org/3/library/pickle.html)"""
    return self.save_as_binary_image()

__setstate__(state)

Used by pickle.load() (See https://docs.python.org/3/library/pickle.html)

Source code in reels/Clients.py
90
91
92
93
def __setstate__(self, state):
    """Used by pickle.load() (See https://docs.python.org/3/library/pickle.html)"""
    self.cl_id = new_clients()
    self.load_from_binary_image(state)

add_client_id(client)

Define clients explicitly.

Parameters:

Name Type Description Default
client str

The "client". A string representing "the actor".

required

Returns:

Type Description
bool

True on success.

Source code in reels/Clients.py
106
107
108
109
110
111
112
113
114
115
def add_client_id(self, client):
    """Define clients explicitly.

    Args:
        client (str): The "client". A string representing "the actor".

    Returns:
        (bool): True on success.
    """
    return clients_add_client_id(self.cl_id, client)

client_hashes()

Return an iterator to iterate over all the hashed client ids.

Returns:

Type Description
ClientsHashes

An iterator (a ClientsHashes object)

Source code in reels/Clients.py
117
118
119
120
121
122
123
def client_hashes(self):
    """Return an iterator to iterate over all the hashed client ids.

    Returns:
        (ClientsHashes): An iterator (a ClientsHashes object)
    """
    return ClientsHashes(self.cl_id, self.num_clients())

hash_client_id(client)

Convert a client id into a hash (as stored buy the internal C** Clients object).

Parameters:

Name Type Description Default
client str

The "client". A string representing "the actor".

required

Returns:

Type Description
str

The hash as a decimal python string starting with 'h' to prevent numeric conversion.

Source code in reels/Clients.py
 95
 96
 97
 98
 99
100
101
102
103
104
def hash_client_id(self, client):
    """Convert a client id into a hash (as stored buy the internal C** Clients object).

    Args:
        client (str): The "client". A string representing "the actor".

    Returns:
        (str): The hash as a decimal python string starting with 'h' to prevent numeric conversion.
    """
    return clients_hash_client_id(self.cl_id, client)

load_from_binary_image(binary_image)

Load the state of the c++ Clients object from a binary_image returned by a previous save_as_binary_image() call.

Parameters:

Name Type Description Default
binary_image list

A list of strings returned by save_as_binary_image()

required

Returns:

Type Description
bool

True on success, destroys, initializes and returns false on failure.

Source code in reels/Clients.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
def load_from_binary_image(self, binary_image):
    """Load the state of the c++ Clients object from a binary_image
        returned by a previous save_as_binary_image() call.

    Args:
        binary_image (list): A list of strings returned by save_as_binary_image()

    Returns:
        (bool): True on success, destroys, initializes and returns false on failure.
    """
    failed = False

    for binary_image_block in binary_image:
        if not clients_load_block(self.cl_id, binary_image_block):
            failed = True
            break

    if not failed:
        failed = not clients_load_block(self.cl_id, "")

    if failed:
        destroy_clients(self.cl_id)
        self.cl_id = new_clients()
        return False

    return True

num_clients()

Return the number of clients in the object.

The container will add one client per add_client_id() call and keep the order.

Returns:

Type Description
int

The number of clients stored in the object which may include repeated ids.

Source code in reels/Clients.py
125
126
127
128
129
130
131
132
133
def num_clients(self):
    """Return the number of clients in the object.

    The container will add one client per add_client_id() call and keep the order.

    Returns:
        (int): The number of clients stored in the object which may include repeated ids.
    """
    return clients_num_clients(self.cl_id)

save_as_binary_image()

Saves the state of the c++ Clients object as a Python list of strings referred to a binary_image.

Returns:

Type Description
list

The binary_image containing the state of the Clients. There is not much you can do with it except serializing it as a Python (e.g., pickle) object and loading it into another Clients object. Pass it to the constructor to create an initialized object,

Source code in reels/Clients.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
def save_as_binary_image(self):
    """Saves the state of the c++ Clients object as a Python
        list of strings referred to a binary_image.

    Returns:
        (list): The binary_image containing the state of the Clients. There is
            not much you can do with it except serializing it as a Python
            (e.g., pickle) object and loading it into another Clients object.
            Pass it to the constructor to create an initialized object,
    """
    bi_idx = clients_save(self.cl_id)
    if bi_idx == 0:
        return None

    bi = []
    bi_size = size_binary_image_iterator(bi_idx)
    for t in range(bi_size):
        bi.append(next_binary_image_iterator(bi_idx))

    destroy_binary_image_iterator(bi_idx)

    return bi

ClientsHashes(cl_id, size)

Iterator over the hashes of a Clients container.

Source code in reels/Clients.py
38
39
40
41
def __init__(self, cl_id, size):
    self.cl_id = cl_id
    self.size = size
    self.idx = 0