Airshare Module¶
airshare.cli module¶
Command Line Interface for Airshare.
airshare.exception module¶
Exceptions defined for Airshare.
-
exception
airshare.exception.
CodeExistsError
(code)[source]¶ Bases:
airshare.exception.AirshareError
Exception to be raised when Airshare code already exists.
To be raised when trying to create or serve an Airshare server, but one already exists with that identifying code.
-
exception
airshare.exception.
CodeNotFoundError
(code)[source]¶ Bases:
airshare.exception.AirshareError
Exception to be raised when the Airshare code is not found.
To be raised when trying to download from or upload to an Airshare, but none exists with that identifying code.
airshare.receiver module¶
Module for receiving data and hosting receiving servers.
-
airshare.receiver.
receive
(*, code, decompress=False)[source]¶ Receive file(s) from a sending server.
Parameters: - code (str) – Identifying code for the Airshare sending server.
- decompress (boolean, default=False) – Flag to enable or disable decompression (Zip).
Returns: text (or) file_path – Returns the text or path of the file received, if successful.
Return type: str
-
airshare.receiver.
receive_server
(*, code, decompress=False, port=80)[source]¶ Serves a file receiver and registers it as a Multicast-DNS service.
Parameters: - code (str) – Identifying code for the Airshare service and server.
- decompress (boolean, default=False) – Flag to enable or disable decompression (Zip).
- port (int, default=80) – Port number at which the server is hosted on the device.
-
airshare.receiver.
receive_server_proc
(*, code, decompress=False, port=80)[source]¶ Creates a process with ‘receive_server’ as the target.
Parameters: - code (str) – Identifying code for the Airshare service and server.
- decompress (boolean, default=False) – Flag to enable or disable decompression (Zip).
- port (int, default=80) – Port number at which the server is hosted on the device.
Returns: process – A multiprocessing.Process object with ‘receive_server’ as target.
Return type: multiprocessing.Process
airshare.sender module¶
Module for sending data and hosting sending servers.
-
airshare.sender.
send
(*, code, file, compress=False)[source]¶ Send file(s) or directories to a receiving server.
Parameters: - code (str) – Identifying code for the Airshare receiving server.
- file (str or list or None) – Relative path or list of paths of the files or directories to serve. For multiple files or directories, contents are automatically zipped.
- compress (boolean, default=False) – Flag to enable or disable compression (Zip). Effective when only one file is given.
Returns: status_code – Status code of upload POST request.
Return type: int
-
airshare.sender.
send_server
(*, code, text=None, file=None, compress=False, port=80)[source]¶ Serves a file or text and registers it as a Multicast-DNS service.
Parameters: - code (str) – Identifying code for the Airshare service and server.
- text (str or None) – String value to be shared. If both text and files are given, text will be shared. Must be given if files is not given.
- file (str or list or None) – Relative path or list of paths of the files or directories to serve. If multiple files or directories are given, the contents are automatically zipped. If not given or both files and text are given, text will be shared. Must be given if text is not given.
- compress (boolean, default=False) – Flag to enable or disable compression (Zip). Effective when only one file is given.
- port (int, default=80) – Port number at which the server is hosted on the device.
-
airshare.sender.
send_server_proc
(*, code, text=None, file=None, compress=False, port=80)[source]¶ Creates a process with ‘send_server’ as the target.
Parameters: - code (str) – Identifying code for the Airshare service and server.
- text (str or None) – String value to be shared. If both text and files are given, text will be shared. Must be given if files is not given.
- file (str or list or None) – Relative path or list of paths of the files or directories to serve. If multiple files or directories are given, the contents are automatically zipped. If not given or both files and text are given, text will be shared. Must be given if text is not given.
- compress (boolean, default=False) – Flag to enable or disable compression (Zip). Effective when only one file is given.
- port (int, default=80) – Port number at which the server is hosted on the device.
Returns: process – A multiprocessing.Process object with ‘send_server’ as target.
Return type: multiprocessing.Process
airshare.utils module¶
Utility functions for Airshare.
-
airshare.utils.
get_local_ip_address
()[source]¶ Obtains the device’s local network IP address.
Returns: ip – Packed 32-bit representation of the device’s local IP Address. Return type: bytes
-
airshare.utils.
qr_code
(url)[source]¶ Generate QR Code from URL and print it.
Parameters: url (str) – URL to create the QR Code for.
-
airshare.utils.
get_service_info
(code)[source]¶ Get service information for an Airshare service.
Parameters: code (str) – Identifying code for the Airshare service. Returns: info – Details of the Airshare service. Return type: zeroconf.ServiceInfo
-
airshare.utils.
register_service
(code, addresses, port)[source]¶ Registers an Airshare Multicast-DNS service based in the local network.
Parameters: - code (str) – Identifying code for the Airshare service.
- addresses (list) – List of local network IP Addresses for the service.
- port (int) – Port number for the Airshare service’s server.
Returns: info – Details of the Airshare service.
Return type: zeroconf.ServiceInfo
-
airshare.utils.
get_zip_file
(files)[source]¶ Creates a temporary Zip Archive of files and directories.
Parameters: files (list) – List of paths of files and directories to compress. Returns: - zip_file_path (str) – Canonical file path of the temporary Zip Archive file.
- zip_file_name (str) – File name to be assigned to the Zip Archive (during sending).
-
airshare.utils.
unzip_file
(zip_file_path)[source]¶ Unzips a Zip Archive file into a new directory.
Parameters: zip_file_path (str) – Path of the Zip Archive file to unzip. Returns: zip_dir – Canonical path of the unzipped directory. Return type: str