pycloud module

This module is the primary building block of the PyCloud infrastructure. Within it, the basic file transfer protocol is laid down.

class pycloud.ClientSocket(host, port)[source]

Bases: socket.socket

This is a subclass of socket.socket. Introduced primarily for simplicity and the setting of pre-defined values.

class pycloud.ReceivedFile(name, ext, sock)[source]

Bases: object

evaluate()[source]

This method evaluates .cert, .id, and all other files with an extension.

take_data(data)[source]

This method adds data to the associated filename and extension.

Parameters:data (byte str) – Data to be added
class pycloud.ServerSocket(port)[source]

Bases: socket.socket

This is a subclass of socket.socket. Creates a socket with a few pre-defined variables.

activate()[source]

This activates the main server event loop for accepting incoming connections.

class pycloud.User(name, pwd, sock)[source]

Bases: object

check_pwd()[source]

This method checks the .pi_users file for self.name.

Returns:Returns the corresponding password to the instance username. If it is not found, 1 is returned.
Return type:str or int
input_request(msg)[source]

This method sends a question to the client, and awaits the response.

Parameters:msg (str) – This is the question that the client will see.
Returns:Returns the answer to the question.
Return type:str
login()[source]

This method logs in the User instance with the instance password and username.

Returns:Returns 0 on success. Returns 1 on failure to login.
Return type:int
make_hashed(salt=None)[source]

This method hashes the self.pwd into a salted hash.

Parameters:salt (str) – Defaults to None. If so, a random salt is generated using SHA-512 hashing.
Returns:The hashed password is returned (which includes the salt at the beginning.
Return type:str
register()[source]

This method registers the User instance with the username and password, and then logs in via self.login().

Returns:Returns 1 on failure. Returns 0 on success.
Return type:int
pycloud.evaluate(sock)[source]

This is the primary function used in server/client communication evaluation.

Data is received and processed depending on whether it contains the primary delimiter for files, or whether it contains certain keywords used for server communication.

Parameters:sock (socket.socket) – The socket by which data is received.
Returns:Returns 0 on success.
Return type:int
Returns:Returns 1 on failure. This is especially important when determining when the server/client communication is over, or whether it is still going to go on. A return of 1 indicates that no more communication will go on. 0 indicates that communication will happen again, and consequently, evaluate() should be called again.
Return type:int
pycloud.get_cwu()[source]

This function gets the current logged-in user.

Returns:Username from the .current_user file
Return type:str
pycloud.pre_proc(filename, is_server=0)[source]

This function processes a filename by whether or not it exists in the current working directory.

Parameters:
  • filename (str) – The filename of the file you want to process.
  • is_server (int) – This acts as a flag for determining how exactly the function should work.
Returns:

Returns the file data if it is found in the local filesystem.

Return type:

byte str

Returns:

Returns the pre-processed filename and extension if the function

acts as a client. (For requesting files) :rtype: byte str :return: Returns FileError if function is acting as a server, and the file could not be

found in the local filesystem.
Return type:byte str
pycloud.proc_block(client_sock, length)[source]

This is a helper function of recv_all(). It receives data according to length.

Parameters:
  • client_sock (socket.socket) – The socket by which data is received.
  • length (int) – The length of the data to check for and receive.
Returns:

Returns None if no packets are received. Otherwise returns the block of data received.

Return type:

None or byte str

pycloud.recv_all(client_sock)[source]

This function receives data on a socket by processing the data length at first.

Parameters:client_sock (socket.socket) – The socket by which data is being received.
Returns:Returns None if no data is received.
Return type:None
Returns:Otherwise returns the data received.
Return type:byte str
pycloud.send_file(sock, b_data)[source]

This function sends a byte string over a connected socket.

Parameters:
  • sock (socket.socket) – The socket by which data is sent.
  • b_data (byte str) – The data to be sent.
Returns:

Returns 0 upon success.

Return type:

int

Returns:

Returns None on failure.

Return type:

None