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

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
70
71
72
73
74
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
88
89
90
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
92
93
94
95
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

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

required

Returns:

Type Description

True on success.

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

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

    Returns:
        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

An iterator (a ClientsHashes object)

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

    Returns:
        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

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

required

Returns:

Type Description

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

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

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

    Returns:
        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

A list of strings returned by save_as_binary_image()

required

Returns:

Type Description

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

Source code in reels/Clients.py
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
184
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: A list of strings returned by save_as_binary_image()

    Returns:
        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.

Returns:

Type Description

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

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

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

    Returns:
        The number of clients stored in the object which may include repeated ids.
        The container will add one client per add_client_id() call and keep the order.
    """
    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

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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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:
        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