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.
ServerSocket
(port)[source]¶ Bases:
socket.socket
This is a subclass of
socket.socket
. Creates a socket with a few pre-defined variables.
-
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
-
-
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 of1
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 befound 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 tolength
.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