From 04dac06adc12265aeb750f565d34ffeaf4a65e63 Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Sun, 7 Jun 2020 23:05:50 +0530 Subject: [PATCH] Changed default port to 8000 * The default port has been changed from 80 to 8000, to avoid the use of a restricted port. * The documentation has been updated to reflect the same. --- PIP.md | 18 ++++++++++++++---- README.md | 2 +- airshare/cli.py | 4 ++-- airshare/exception.py | 8 ++++---- airshare/receiver.py | 10 +++++----- airshare/sender.py | 10 +++++----- docs/source/_static/cli_usage.txt | 4 ++-- docs/source/index.rst | 20 ++++++++++++++------ 8 files changed, 47 insertions(+), 29 deletions(-) diff --git a/PIP.md b/PIP.md index 24c7108..78ba580 100644 --- a/PIP.md +++ b/PIP.md @@ -37,13 +37,23 @@ PyPI: https://pypi.org/project/Airshare
## Installation -Use the package manager [pip](https://pip.pypa.io/en/stable/) to install Airshare. +* Install using `pip` ```bash $ pip install Airshare ``` -If you have a non-Apple device, consider installing Avahi (for Linux) or Bonjour (for Windows) if you'd like to use Link-local Name Resolution (for the `.local` addresses). +* Install using `pipx` + +```bash +$ pipx install Airshare +``` + +* Install using Homebrew + +```bash +$ brew install airshare +``` ## Example @@ -60,7 +70,7 @@ To receive using the CLI, $ airshare noobmaster ``` -or visit `http://noobmaster.local` in the browser to download. +or visit `http://noobmaster.local:8000` in the browser to download. You can also `import airshare` in any Python program. Visit the documentation for detailed usage instructions. @@ -68,7 +78,7 @@ You can also `import airshare` in any Python program. Visit the documentation fo * Link-local Name Resolution (for the `.local` addresses) on non-Apple devices requires Avahi (on Linux) or Bonjour (on Windows). Chances are you already have them, but if you don't, do check the web on how to install them. -* Link-local Name Resolution does not work on Android phones. This is because Android browsers do not have inbuilt Multicast-DNS service discovery. For this reason, we included QR Code support, for you to visit the URLs easily. +* Android browsers do not have inbuilt Multicast-DNS service discovery, and cannot resolve the `.local` addresses. For this reason, we included QR Code support, for you to visit the URLs easily. * Windows users with Python < 3.8, use Ctrl + Break to quit, as Ctrl + C will not work. This is a known issue with `asyncio`, which has been fixed in Python 3.8. If you do not have a Break key, try using Ctrl + Fn + B, or check the web for other alternatives (depending on your PC). diff --git a/README.md b/README.md index 22bf92b..c51dd87 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ To receive using the CLI, $ airshare noobmaster ``` -or visit `http://noobmaster.local` in the browser to download. +or visit `http://noobmaster.local:8000` in the browser to download. You can also `import airshare` in any Python program. Visit the documentation for detailed usage instructions. diff --git a/airshare/cli.py b/airshare/cli.py index 809d35b..08c2db9 100644 --- a/airshare/cli.py +++ b/airshare/cli.py @@ -13,8 +13,8 @@ @click.command(name="airshare") @click.argument("code", nargs=1) -@click.option("-p", "--port", type=int, default=80, help=""" -Specify the port number to host a sending or receiving server (defaults to 80). +@click.option("-p", "--port", type=int, default=8000, help=""" +Specify the port number to host a sending or receiving server (default 8000). """) @click.option("-t", "--text", type=str, help=""" Send (serve) text content. For multiple words, enclose within quotes. diff --git a/airshare/exception.py b/airshare/exception.py index 4f69c3f..ff9467a 100644 --- a/airshare/exception.py +++ b/airshare/exception.py @@ -20,7 +20,7 @@ def __init__(self, code): def __str__(self): return "CodeExistsError: The Airshare `" + self.code \ - + ".local` already exists!" + + "` already exists!" class CodeNotFoundError(AirshareError): @@ -34,7 +34,7 @@ def __init__(self, code): def __str__(self): return "CodeNotFoundError: The Airshare `" + self.code \ - + ".local` was not found!" + + "` was not found!" class IsNotReceiverError(AirshareError): @@ -48,7 +48,7 @@ def __init__(self, code): def __str__(self): return "IsNotReceiverError: The Airshare `" + self.code \ - + ".local` is not an Upload Receiver!" + + "` is not an Upload Receiver!" class IsNotSenderError(AirshareError): @@ -62,4 +62,4 @@ def __init__(self, code): def __str__(self): return "IsNotSenderError: The Airshare `" + self.code \ - + ".local` is not a Text or File Sender!" + + "` is not a Text or File Sender!" diff --git a/airshare/receiver.py b/airshare/receiver.py index 8539a2c..a11e00e 100644 --- a/airshare/receiver.py +++ b/airshare/receiver.py @@ -105,7 +105,7 @@ def receive(*, code, decompress=False): airshare_type = requests.get(url + "/airshare").text if "Sender" not in airshare_type: raise IsNotSenderError(code) - print("Receiving from Airshare `" + code + ".local`...") + print("Receiving from Airshare `" + code + "`...") sleep(2) if airshare_type == "Text Sender": text = requests.get(url + "/text").text @@ -145,7 +145,7 @@ def receive(*, code, decompress=False): return file_path -def receive_server(*, code, decompress=False, port=80): +def receive_server(*, code, decompress=False, port=8000): r"""Serves a file receiver and registers it as a Multicast-DNS service. Parameters @@ -154,7 +154,7 @@ def receive_server(*, code, decompress=False, port=80): Identifying code for the Airshare service and server. decompress : boolean, default=False Flag to enable or disable decompression (Zip). - port : int, default=80 + port : int, default=8000 Port number at which the server is hosted on the device. """ info = get_service_info(code) @@ -191,7 +191,7 @@ def receive_server(*, code, decompress=False, port=80): loop.run_forever() -def receive_server_proc(*, code, decompress=False, port=80): +def receive_server_proc(*, code, decompress=False, port=8000): r"""Creates a process with 'receive_server' as the target. Parameters @@ -200,7 +200,7 @@ def receive_server_proc(*, code, decompress=False, port=80): Identifying code for the Airshare service and server. decompress : boolean, default=False Flag to enable or disable decompression (Zip). - port : int, default=80 + port : int, default=8000 Port number at which the server is hosted on the device. Returns diff --git a/airshare/sender.py b/airshare/sender.py index 258afce..54455b5 100644 --- a/airshare/sender.py +++ b/airshare/sender.py @@ -138,11 +138,11 @@ def send(*, code, file, compress=False): m = MultipartEncoder(fields={"field0": (name, open(file, "rb"))}) headers = {"content-type": m.content_type, "airshare-compress": compress} r = requests.post(url + "/upload", data=m, headers=headers) - print("Uploaded `" + name + "` to Airshare `" + code + ".local`!") + print("Uploaded `" + name + "` to Airshare `" + code + "`!") return r.status_code -def send_server(*, code, text=None, file=None, compress=False, port=80): +def send_server(*, code, text=None, file=None, compress=False, port=8000): r"""Serves a file or text and registers it as a Multicast-DNS service. Parameters @@ -161,7 +161,7 @@ def send_server(*, code, text=None, file=None, compress=False, port=80): compress : boolean, default=False Flag to enable or disable compression (Zip). Effective when only one file is given. - port : int, default=80 + port : int, default=8000 Port number at which the server is hosted on the device. """ info = get_service_info(code) @@ -227,7 +227,7 @@ def send_server(*, code, text=None, file=None, compress=False, port=80): loop.run_forever() -def send_server_proc(*, code, text=None, file=None, compress=False, port=80): +def send_server_proc(*, code, text=None, file=None, compress=False, port=8000): r"""Creates a process with 'send_server' as the target. Parameters @@ -246,7 +246,7 @@ def send_server_proc(*, code, text=None, file=None, compress=False, port=80): compress : boolean, default=False Flag to enable or disable compression (Zip). Effective when only one file is given. - port : int, default=80 + port : int, default=8000 Port number at which the server is hosted on the device. Returns diff --git a/docs/source/_static/cli_usage.txt b/docs/source/_static/cli_usage.txt index 52f7df5..5d210fc 100644 --- a/docs/source/_static/cli_usage.txt +++ b/docs/source/_static/cli_usage.txt @@ -9,7 +9,7 @@ Usage: airshare [OPTIONS] CODE [FILES] Options: -p, --port INTEGER Specify the port number to host a sending or receiving - server (defaults to 80). + server (default 8000). -t, --text TEXT Send (serve) text content. For multiple words, enclose within quotes. @@ -26,4 +26,4 @@ Options: --help Show this message and exit. - --version Show the version and exit. \ No newline at end of file + --version Show the version and exit. diff --git a/docs/source/index.rst b/docs/source/index.rst index 6d787b9..759bd9a 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -69,14 +69,23 @@ Important Links Installation ------------ -Use the package manager `pip `__ to -install Airshare. +* Installation using ``pip`` .. code:: bash $ pip install Airshare -If you have a non-Apple device, consider installing Avahi (for Linux) or Bonjour (for Windows) if you'd like to use Link-local Name Resolution (for the ``.local`` addresses). +* Installation using ``pipx`` + +.. code:: bash + + $ pipx install Airshare + +* Installation using Homebrew + +.. code:: bash + + $ brew install airshare CLI Tool Reference ------------------ @@ -106,14 +115,13 @@ Known Issues ------------ * Link-local Name Resolution (for the ``.local`` addresses) on non-Apple devices requires Avahi (on Linux) or Bonjour (on Windows). Chances are you already have them, but if you don't, do check the web on how to install them. -* Link-local Name Resolution does not work on Android phones. This is because Android browsers do not have inbuilt Multicast-DNS service discovery. For this reason, we included QR Code support, for you to visit the URLs easily. +* Android browsers do not have inbuilt Multicast-DNS service discovery, and cannot resolve the ``.local`` addresses. For this reason, we included QR Code support, for you to visit the URLs easily. * Windows users with Python < 3.8, use ``Ctrl`` + ``Break`` to quit, as ``Ctrl`` + ``C`` will not work. This is a known issue with ``asyncio``, which has been fixed in Python 3.8. If you do not have a ``Break`` key, try using ``Ctrl`` + ``Fn`` + ``B``, or check the web for other alternatives (depending on your PC). Contributing ------------ -Pull requests are welcome. For major changes, please open an issue first -to discuss what you would like to change. +Pull requests are welcome. Read our `Contribution Guide `__ for more details. License -------