clipdroper 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 arbuztratil-design
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: clipdroper
3
+ Version: 0.1.0
4
+ Summary: Paste text or drop a file from your phone straight into your PC clipboard and Downloads folder, via QR code.
5
+ Author: clipdroper contributors
6
+ License-Expression: MIT
7
+ Keywords: clipboard,qr,phone,lan,transfer,file,http
8
+ Classifier: Environment :: Console
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Topic :: Communications
11
+ Classifier: Topic :: Utilities
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: segno>=1.6
16
+ Requires-Dist: pyperclip>=1.8
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=8.0; extra == "dev"
19
+ Requires-Dist: ruff>=0.5; extra == "dev"
20
+ Dynamic: license-file
21
+
22
+ # clipdroper
23
+
24
+ Paste text or drop a file from your phone straight into your **PC** — clipboard and
25
+ Downloads folder — using a QR code printed in your terminal. No accounts, no apps on the
26
+ phone, just a browser.
27
+
28
+ ## How it works
29
+
30
+ ```
31
+ phone camera your PC
32
+ │ scans QR ───────────────► clipdroper prints QR when started
33
+ ▼ ┌───► ┌──────────────────────────────┐
34
+ phone browser opens URL │ │ clipdroper (HTTP server) │
35
+ │ POST text / file │ │ text → your clipboard │
36
+ ▼ (token-protected) │ │ files → ~/Downloads/… │
37
+ └────────────────────────┴────► └──────────────────────────────┘
38
+ ```
39
+
40
+ Your PC runs one command, prints a QR that encodes a short random token; the phone
41
+ connect via that URL only. The token guards the inbox, so a neighbor with the token
42
+ is the only one who can drop stuff while it runs.
43
+
44
+ ## Install
45
+
46
+ ```
47
+ pip install clipdroper
48
+ ```
49
+
50
+ ## Run
51
+
52
+ ```
53
+ clipdroper
54
+ ```
55
+
56
+ It prints the QR and the URL, and waits:
57
+
58
+ ```
59
+ clipdroper: listening on http://192.168.0.5:8124/?k=2XfQk8...
60
+ ```
61
+
62
+ * Scan the QR with the phone camera → the page opens.
63
+ * Paste text → **Send to clipboard** → it lands in the PC clipboard instantly.
64
+ * Pick a file → **Send file** → it is saved to `~/Downloads/clipdroper/`.
65
+
66
+ Options: `--port`, `--dir` (folder for files), `--token`, `--no-qr`.
67
+
68
+ ## Notes / security
69
+
70
+ * Toy for a trusted LAN. The token is short by design — do not expose the port to the
71
+ internet.
72
+ * No TLS. Clipboard works on Windows/macOS/Linux-desktop (via `pyperclip`).
73
+
74
+ ## Tests
75
+
76
+ ```
77
+ pip install -e ".[dev]"
78
+ pytest # QR rendering, HTTP server, token auth, file upload
79
+ ```
@@ -0,0 +1,58 @@
1
+ # clipdroper
2
+
3
+ Paste text or drop a file from your phone straight into your **PC** — clipboard and
4
+ Downloads folder — using a QR code printed in your terminal. No accounts, no apps on the
5
+ phone, just a browser.
6
+
7
+ ## How it works
8
+
9
+ ```
10
+ phone camera your PC
11
+ │ scans QR ───────────────► clipdroper prints QR when started
12
+ ▼ ┌───► ┌──────────────────────────────┐
13
+ phone browser opens URL │ │ clipdroper (HTTP server) │
14
+ │ POST text / file │ │ text → your clipboard │
15
+ ▼ (token-protected) │ │ files → ~/Downloads/… │
16
+ └────────────────────────┴────► └──────────────────────────────┘
17
+ ```
18
+
19
+ Your PC runs one command, prints a QR that encodes a short random token; the phone
20
+ connect via that URL only. The token guards the inbox, so a neighbor with the token
21
+ is the only one who can drop stuff while it runs.
22
+
23
+ ## Install
24
+
25
+ ```
26
+ pip install clipdroper
27
+ ```
28
+
29
+ ## Run
30
+
31
+ ```
32
+ clipdroper
33
+ ```
34
+
35
+ It prints the QR and the URL, and waits:
36
+
37
+ ```
38
+ clipdroper: listening on http://192.168.0.5:8124/?k=2XfQk8...
39
+ ```
40
+
41
+ * Scan the QR with the phone camera → the page opens.
42
+ * Paste text → **Send to clipboard** → it lands in the PC clipboard instantly.
43
+ * Pick a file → **Send file** → it is saved to `~/Downloads/clipdroper/`.
44
+
45
+ Options: `--port`, `--dir` (folder for files), `--token`, `--no-qr`.
46
+
47
+ ## Notes / security
48
+
49
+ * Toy for a trusted LAN. The token is short by design — do not expose the port to the
50
+ internet.
51
+ * No TLS. Clipboard works on Windows/macOS/Linux-desktop (via `pyperclip`).
52
+
53
+ ## Tests
54
+
55
+ ```
56
+ pip install -e ".[dev]"
57
+ pytest # QR rendering, HTTP server, token auth, file upload
58
+ ```
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "clipdroper"
7
+ version = "0.1.0"
8
+ description = "Paste text or drop a file from your phone straight into your PC clipboard and Downloads folder, via QR code."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "clipdroper contributors" }]
14
+ keywords = ["clipboard", "qr", "phone", "lan", "transfer", "file", "http"]
15
+ classifiers = [
16
+ "Environment :: Console",
17
+ "Programming Language :: Python :: 3",
18
+ "Topic :: Communications",
19
+ "Topic :: Utilities",
20
+ ]
21
+ dependencies = ["segno>=1.6", "pyperclip>=1.8"]
22
+
23
+ [project.scripts]
24
+ clipdroper = "clipdroper.main:main"
25
+
26
+ [project.optional-dependencies]
27
+ dev = ["pytest>=8.0", "ruff>=0.5"]
28
+
29
+ [tool.setuptools.packages.find]
30
+ where = ["src"]
31
+
32
+ [tool.pytest.ini_options]
33
+ testpaths = ["tests"]
34
+ pythonpath = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """clipdroper: paste text/files from your phone into your PC."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ from clipdroper.main import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())
@@ -0,0 +1,43 @@
1
+ """clipdroper command line entry point."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import os
7
+ import secrets
8
+
9
+ from clipdroper.qrterm import render_qr
10
+ from clipdroper.server import DEFAULT_PORT, ClipDropServer
11
+
12
+
13
+ def main(argv: list[str] | None = None) -> int:
14
+ import sys
15
+
16
+ sys.stdout.reconfigure(encoding="utf-8", errors="replace") # QR block chars on any console
17
+ parser = argparse.ArgumentParser(prog="clipdroper", description="Paste text/file from your phone into your PC.")
18
+ parser.add_argument("--port", type=int, default=DEFAULT_PORT, help=f"HTTP port (default: {DEFAULT_PORT})")
19
+ parser.add_argument(
20
+ "--dir",
21
+ default=os.path.join(os.path.expanduser("~"), "Downloads", "clipdroper"),
22
+ help="folder for dropped files",
23
+ )
24
+ parser.add_argument("--token", default=None, help="override auto-generated token")
25
+ parser.add_argument("--no-qr", action="store_true", help="skip printing the QR code")
26
+ args = parser.parse_args(argv)
27
+
28
+ import pyperclip
29
+
30
+ token = args.token or secrets.token_urlsafe(8)
31
+ server = ClipDropServer(args.port, token, pyperclip.copy, args.dir)
32
+ url = server.url()
33
+ print(f"clipdroper: listening on {url}", flush=True)
34
+ if not args.no_qr:
35
+ print(render_qr(url), flush=True)
36
+ print(f" text drops -> clipboard files -> {server.file_dir}", flush=True)
37
+ try:
38
+ server.serve_forever()
39
+ except KeyboardInterrupt:
40
+ print("\nstop")
41
+ finally:
42
+ server.close()
43
+ return 0
@@ -0,0 +1,43 @@
1
+ """Render a QR code as Unicode half-blocks in the terminal."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Sequence
6
+
7
+ import segno
8
+
9
+ _BLOCKS = {
10
+ (False, False): " ",
11
+ (True, False): "▀",
12
+ (False, True): "▄",
13
+ (True, True): "█",
14
+ }
15
+
16
+
17
+ def qr_matrix(content: str) -> list[list[bool]]:
18
+ qr = segno.make_qr(content, error="m")
19
+ return list(qr.matrix)
20
+
21
+
22
+ def _padded(matrix: list[list[bool]], quiet: int = 2) -> list[list[bool]]:
23
+ size = len(matrix) + quiet * 2
24
+ rows = [[False] * size for _ in range(size)]
25
+ for y, row in enumerate(matrix):
26
+ for x, bit in enumerate(row):
27
+ rows[y + quiet][x + quiet] = bit
28
+ return rows
29
+
30
+
31
+ def render_qr(content: str, colors: Sequence[str] = ("\033[36m", "\033[0m")) -> str:
32
+ """Return an ANSI-colored QR string (two terminal rows per matrix row)."""
33
+ grid = _padded(qr_matrix(content))
34
+ even_rows = grid[::2]
35
+ odd_rows = grid[1::2]
36
+ lines = []
37
+ fg, reset = colors
38
+ for up, down in zip(even_rows, odd_rows):
39
+ line = "".join(_BLOCKS[(a, b)] for a, b in zip(up, down))
40
+ lines.append(f"{fg}{line}{reset}")
41
+ if len(grid) % 2:
42
+ lines.append(f"{fg}{''.join(_BLOCKS[(a, False)] for a in grid[-1])}{reset}")
43
+ return "\n".join(lines)
@@ -0,0 +1,258 @@
1
+ """HTTP server for clipdroper: text-to-clipboard and file drops."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hmac
6
+ import os
7
+ import re
8
+ import socket
9
+ import time
10
+ import urllib.parse
11
+ from collections.abc import Callable
12
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
13
+
14
+ DEFAULT_PORT = 8124
15
+
16
+ PAGE = """<!doctype html>
17
+ <html lang="en">
18
+ <head>
19
+ <meta charset="utf-8">
20
+ <meta name="viewport" content="width=device-width, initial-scale=1">
21
+ <title>clipdroper</title>
22
+ <style>
23
+ body{margin:0;font-family:system-ui,-apple-system,sans-serif;background:#111;color:#eee;
24
+ display:flex;flex-direction:column;min-height:100vh;align-items:center;padding:24px 16px;}
25
+ .card{width:100%;max-width:420px;background:#1c1c1e;border-radius:14px;padding:18px;box-sizing:border-box;}
26
+ h1{font-size:20px;margin:0 0 4px;} .sub{color:#9a9a9a;font-size:13px;margin-bottom:16px;}
27
+ textarea{width:100%;box-sizing:border-box;min-height:110px;background:#0d0d0f;color:#eee;border:1px solid #333;
28
+ border-radius:8px;padding:10px;font-size:15px;font-family:inherit;resize:vertical;}
29
+ input[type=file]{width:100%;margin:10px 0 6px;font-size:13px;color:#ddd;}
30
+ button{width:100%;background:#2f6feb;color:#fff;border:0;border-radius:8px;padding:12px;
31
+ font-size:16px;font-weight:600;margin-top:6px;} button:active{background:#1f52b8;}
32
+ .sep{height:1px;background:#333;margin:20px 0;}
33
+ .status{margin-top:10px;font-size:14px;color:#7ad68c;min-height:20px;text-align:center;}
34
+ .err{color:#e57373;}
35
+ </style>
36
+ </head>
37
+ <body>
38
+ <div class="card">
39
+ <h1>clipdroper</h1>
40
+ <div class="sub">sends to your PC clipboard / Downloads</div>
41
+ <textarea id="text" placeholder="Paste text, then press Send"></textarea>
42
+ <button onclick="sendText()">Send to clipboard</button>
43
+ <button onclick="sendFile()" style="margin-top:8px">Send file</button>
44
+ <input type="file" id="file">
45
+ <div class="sep"></div>
46
+ <div class="status" id="status"></div>
47
+ </div>
48
+ <script>
49
+ const token = new URLSearchParams(location.search).get('k') || '';
50
+ function set(msg, err){const el=document.getElementById('status');el.className=err?'status err':'status';el.textContent=msg;}
51
+ async function sendText(){
52
+ const text=document.getElementById('text').value;
53
+ if(!text.trim()){set('empty',true);return;}
54
+ try{
55
+ const r=await fetch('/api/send',{method:'POST',headers:{'Content-Type':'application/json'},
56
+ body:JSON.stringify({k:token,text})});
57
+ const d=await r.json();
58
+ set(d.ok?'Copied to PC clipboard':(d.error||'error'),!d.ok);
59
+ }catch(e){set('network error',true);}
60
+ }
61
+ async function sendFile(){
62
+ const f=document.getElementById('file').files[0];
63
+ if(!f){set('choose a file',true);return;}
64
+ const fd=new FormData(); fd.append('k',token); fd.append('file',f);
65
+ try{
66
+ const r=await fetch('/api/upload',{method:'POST',body:fd});
67
+ const d=await r.json();
68
+ set(d.ok?('Saved '+d.name):(d.error||'error'),!d.ok);
69
+ }catch(e){set('network error',true);}
70
+ }
71
+ </script>
72
+ </body>
73
+ </html>
74
+ """
75
+
76
+
77
+ class DropHandler(BaseHTTPRequestHandler):
78
+ drop: ClipDropServer
79
+ server_version = "clipdroper/0.1"
80
+
81
+ def log_message(self, fmt: str, *args) -> None:
82
+ pass
83
+
84
+ def _json(self, code: int, payload: dict) -> None:
85
+ import json
86
+
87
+ body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
88
+ self.send_response(code)
89
+ self.send_header("Content-Type", "application/json; charset=utf-8")
90
+ self.send_header("Content-Length", str(len(body)))
91
+ self.end_headers()
92
+ self.wfile.write(body)
93
+
94
+ def _page(self, page: str, code: int = 200) -> None:
95
+ body = page.encode("utf-8")
96
+ self.send_response(code)
97
+ self.send_header("Content-Type", "text/html; charset=utf-8")
98
+ self.send_header("Content-Length", str(len(body)))
99
+ self.end_headers()
100
+ self.wfile.write(body)
101
+
102
+ def _ok(self, token: str | None) -> bool:
103
+ return bool(token) and hmac.compare_digest(token, self.drop.token)
104
+
105
+ def do_GET(self) -> None:
106
+ url = urllib.parse.urlparse(self.path)
107
+ if url.path == "/":
108
+ self._page(PAGE)
109
+ return
110
+ self._json(404, {"error": "not found"})
111
+
112
+ def do_POST(self) -> None:
113
+ import json
114
+
115
+ url = urllib.parse.urlparse(self.path)
116
+ length = int(self.headers.get("Content-Length") or 0)
117
+ body = self.rfile.read(length)
118
+ if url.path == "/api/send":
119
+ try:
120
+ data = json.loads(body.decode("utf-8"))
121
+ except (ValueError, UnicodeDecodeError):
122
+ self._json(400, {"error": "bad json"})
123
+ return
124
+ token = data.get("k")
125
+ if not self._ok(token):
126
+ self._json(403, {"error": "bad token"})
127
+ return
128
+ text = str(data.get("text") or "").strip()
129
+ if not text or len(text) > 100_000:
130
+ self._json(400, {"error": "empty or too long"})
131
+ return
132
+ try:
133
+ self.drop.sink(text)
134
+ self._json(200, {"ok": True})
135
+ except Exception: # noqa: BLE001 - any clipboard backend failure
136
+ self._json(500, {"error": "clipboard unavailable"})
137
+ return
138
+ if url.path == "/api/upload":
139
+ return self._handle_upload(body)
140
+ self._json(404, {"error": "not found"})
141
+
142
+ def _handle_upload(self, body: bytes) -> None:
143
+ ctype = self.headers.get("Content-Type") or ""
144
+ token, name, data = _parse_multipart(body, ctype)
145
+ if not self._ok(token):
146
+ self._json(403, {"error": "bad token"})
147
+ return
148
+ if data is None or not name:
149
+ self._json(400, {"error": "no file"})
150
+ return
151
+ name = _safe_name(name)
152
+ if len(data) > 200 * 1024 * 1024:
153
+ self._json(400, {"error": "too large"})
154
+ return
155
+ path = os.path.join(self.drop.file_dir, name)
156
+ if os.path.exists(path):
157
+ stem, dot, ext = name.rpartition(".")
158
+ path = os.path.join(self.drop.file_dir, f"{stem}-{int(time.time())}{dot + ext if dot else ''}")
159
+ try:
160
+ with open(path, "wb") as fh:
161
+ fh.write(data)
162
+ except OSError:
163
+ self._json(500, {"error": "cannot write"})
164
+ return
165
+ self._json(200, {"ok": True, "name": os.path.basename(path)})
166
+
167
+
168
+ class ClipDropServer:
169
+ def __init__(self, port: int, token: str, sink: Callable[[str], None], file_dir: str) -> None:
170
+ self.token = token
171
+ self.sink = sink
172
+ self.file_dir = file_dir
173
+ os.makedirs(file_dir, exist_ok=True)
174
+ self.httpd = ThreadingHTTPServer(("0.0.0.0", port), DropHandler)
175
+ DropHandler.drop = self
176
+
177
+ @property
178
+ def port(self) -> int:
179
+ return self.httpd.server_address[1]
180
+
181
+ def url(self) -> str:
182
+ return f"http://{_lan_ip()}:{self.port}/?k={self.token}"
183
+
184
+ def serve_forever(self) -> None:
185
+ self.httpd.serve_forever()
186
+
187
+ def close(self) -> None:
188
+ self.httpd.shutdown()
189
+ self.httpd.server_close()
190
+
191
+
192
+ def _lan_ip() -> str:
193
+ ips: set[str] = set()
194
+ try:
195
+ hostname = socket.gethostname()
196
+ for info in socket.getaddrinfo(hostname, None, socket.AF_INET):
197
+ addr = info[4][0]
198
+ if not addr.startswith("127."):
199
+ ips.add(addr)
200
+ except OSError:
201
+ pass
202
+ try:
203
+ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
204
+ sock.connect(("8.8.8.8", 80))
205
+ ips.add(sock.getsockname()[0])
206
+ sock.close()
207
+ except OSError:
208
+ pass
209
+ for ip in ips:
210
+ if _is_private(ip):
211
+ return ip
212
+ return min(ips) if ips else "127.0.0.1"
213
+
214
+
215
+ def _is_private(ip: str) -> bool:
216
+ try:
217
+ first = int(ip.split(".")[0])
218
+ second = int(ip.split(".")[1])
219
+ except (ValueError, IndexError):
220
+ return False
221
+ return first == 10 or first == 192 and second == 168 or first == 172 and 16 <= second <= 31
222
+
223
+
224
+ def _safe_name(name: str) -> str:
225
+ name = name.replace("\\", "/").split("/")[-1]
226
+ return re.sub(r"[^A-Za-z0-9._() -]", "_", name).strip() or "file.bin"
227
+
228
+
229
+ _BOUNDARY_RE = re.compile(r"boundary=(?:\"([^\"]+)\"|([^;\s]+))", re.IGNORECASE)
230
+ _DISPOSITION_RE = re.compile(r'name="([^"]*)"(?:;\s*filename="([^"]*)")?')
231
+
232
+
233
+ def _parse_multipart(body: bytes, content_type: str):
234
+ match = _BOUNDARY_RE.search(content_type)
235
+ if not match:
236
+ return None, None, None
237
+ boundary = (match.group(1) or match.group(2)).encode("utf-8")
238
+ token = None
239
+ name = None
240
+ data = None
241
+ for part in body.split(b"--" + boundary):
242
+ if b"\r\n\r\n" not in part:
243
+ continue
244
+ head, _, payload = part.partition(b"\r\n\r\n")
245
+ if not head.lstrip(b"\r\n").startswith(b"Content-Disposition:"):
246
+ continue
247
+ disp = head.decode("utf-8", "replace")
248
+ m = _DISPOSITION_RE.search(disp)
249
+ if not m:
250
+ continue
251
+ pname = m.group(1)
252
+ payload = payload.rstrip(b"\r\n")
253
+ if pname == "k":
254
+ token = payload.decode("utf-8", "replace").strip()
255
+ elif pname == "file":
256
+ name = m.group(2)
257
+ data = payload
258
+ return token, name, data
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: clipdroper
3
+ Version: 0.1.0
4
+ Summary: Paste text or drop a file from your phone straight into your PC clipboard and Downloads folder, via QR code.
5
+ Author: clipdroper contributors
6
+ License-Expression: MIT
7
+ Keywords: clipboard,qr,phone,lan,transfer,file,http
8
+ Classifier: Environment :: Console
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Topic :: Communications
11
+ Classifier: Topic :: Utilities
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: segno>=1.6
16
+ Requires-Dist: pyperclip>=1.8
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=8.0; extra == "dev"
19
+ Requires-Dist: ruff>=0.5; extra == "dev"
20
+ Dynamic: license-file
21
+
22
+ # clipdroper
23
+
24
+ Paste text or drop a file from your phone straight into your **PC** — clipboard and
25
+ Downloads folder — using a QR code printed in your terminal. No accounts, no apps on the
26
+ phone, just a browser.
27
+
28
+ ## How it works
29
+
30
+ ```
31
+ phone camera your PC
32
+ │ scans QR ───────────────► clipdroper prints QR when started
33
+ ▼ ┌───► ┌──────────────────────────────┐
34
+ phone browser opens URL │ │ clipdroper (HTTP server) │
35
+ │ POST text / file │ │ text → your clipboard │
36
+ ▼ (token-protected) │ │ files → ~/Downloads/… │
37
+ └────────────────────────┴────► └──────────────────────────────┘
38
+ ```
39
+
40
+ Your PC runs one command, prints a QR that encodes a short random token; the phone
41
+ connect via that URL only. The token guards the inbox, so a neighbor with the token
42
+ is the only one who can drop stuff while it runs.
43
+
44
+ ## Install
45
+
46
+ ```
47
+ pip install clipdroper
48
+ ```
49
+
50
+ ## Run
51
+
52
+ ```
53
+ clipdroper
54
+ ```
55
+
56
+ It prints the QR and the URL, and waits:
57
+
58
+ ```
59
+ clipdroper: listening on http://192.168.0.5:8124/?k=2XfQk8...
60
+ ```
61
+
62
+ * Scan the QR with the phone camera → the page opens.
63
+ * Paste text → **Send to clipboard** → it lands in the PC clipboard instantly.
64
+ * Pick a file → **Send file** → it is saved to `~/Downloads/clipdroper/`.
65
+
66
+ Options: `--port`, `--dir` (folder for files), `--token`, `--no-qr`.
67
+
68
+ ## Notes / security
69
+
70
+ * Toy for a trusted LAN. The token is short by design — do not expose the port to the
71
+ internet.
72
+ * No TLS. Clipboard works on Windows/macOS/Linux-desktop (via `pyperclip`).
73
+
74
+ ## Tests
75
+
76
+ ```
77
+ pip install -e ".[dev]"
78
+ pytest # QR rendering, HTTP server, token auth, file upload
79
+ ```
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/clipdroper/__init__.py
5
+ src/clipdroper/__main__.py
6
+ src/clipdroper/main.py
7
+ src/clipdroper/qrterm.py
8
+ src/clipdroper/server.py
9
+ src/clipdroper.egg-info/PKG-INFO
10
+ src/clipdroper.egg-info/SOURCES.txt
11
+ src/clipdroper.egg-info/dependency_links.txt
12
+ src/clipdroper.egg-info/entry_points.txt
13
+ src/clipdroper.egg-info/requires.txt
14
+ src/clipdroper.egg-info/top_level.txt
15
+ tests/test_clipdroper.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ clipdroper = clipdroper.main:main
@@ -0,0 +1,6 @@
1
+ segno>=1.6
2
+ pyperclip>=1.8
3
+
4
+ [dev]
5
+ pytest>=8.0
6
+ ruff>=0.5
@@ -0,0 +1 @@
1
+ clipdroper
@@ -0,0 +1,118 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import threading
5
+ from http.client import HTTPConnection
6
+
7
+ import pytest
8
+
9
+ from clipdroper.qrterm import render_qr
10
+ from clipdroper.server import ClipDropServer, _parse_multipart, _safe_name
11
+
12
+
13
+ def _free_port() -> int:
14
+ import socket
15
+
16
+ with socket.socket() as s:
17
+ s.bind(("127.0.0.1", 0))
18
+ return s.getsockname()[1]
19
+
20
+
21
+ @pytest.fixture
22
+ def server():
23
+ sink = []
24
+ srv = ClipDropServer(_free_port(), "tok123", sink.append, ".")
25
+ thread = threading.Thread(target=srv.serve_forever, daemon=True)
26
+ thread.start()
27
+ yield srv, sink
28
+ srv.close()
29
+
30
+
31
+ def _http(srv, method, path, body=None, headers=None) -> tuple[int, bytes]:
32
+ conn = HTTPConnection("127.0.0.1", srv.port, timeout=5)
33
+ conn.request(method, path, body=body, headers=headers or {})
34
+ resp = conn.getresponse()
35
+ data = resp.read()
36
+ conn.close()
37
+ return resp.status, data
38
+
39
+
40
+ def test_qr_renders_blocks():
41
+ out = render_qr("http://127.0.0.1:9/?k=x", colors=("", ""))
42
+ assert "▀" in out or "█" in out or "▄" in out
43
+ assert len(out.splitlines()) > 5
44
+
45
+
46
+ def test_page_served(server):
47
+ srv, _ = server
48
+ status, body = _http(srv, "GET", "/")
49
+ assert status == 200
50
+ assert b"clipdroper" in body
51
+
52
+
53
+ def test_send_text_to_sink(server):
54
+ srv, sink = server
55
+ status, body = _http(
56
+ srv, "POST", "/api/send", body=json.dumps({"k": "tok123", "text": "hello clip"}).encode("utf-8")
57
+ )
58
+ assert status == 200
59
+ assert json.loads(body)["ok"] is True
60
+ assert sink == ["hello clip"]
61
+
62
+
63
+ def test_send_bad_token(server):
64
+ srv, _ = server
65
+ status, _ = _http(srv, "POST", "/api/send", body=json.dumps({"k": "nope", "text": "x"}).encode("utf-8"))
66
+ assert status == 403
67
+
68
+
69
+ def test_upload_file(server):
70
+ srv, _ = server
71
+ import os
72
+
73
+ boundary = "bnd123"
74
+ payload = (
75
+ f"--{boundary}\r\n"
76
+ 'Content-Disposition: form-data; name="k"\r\n\r\n'
77
+ "tok123\r\n"
78
+ f"--{boundary}\r\n"
79
+ 'Content-Disposition: form-data; name="file"; filename="hi.txt"\r\n'
80
+ "Content-Type: text/plain\r\n\r\n"
81
+ "file body\r\n"
82
+ f"--{boundary}--\r\n"
83
+ ).encode()
84
+ status, body = _http(
85
+ srv,
86
+ "POST",
87
+ "/api/upload",
88
+ body=payload,
89
+ headers={"Content-Type": f"multipart/form-data; boundary={boundary}"},
90
+ )
91
+ assert status == 200
92
+ saved = json.loads(body)["name"]
93
+ with open(saved, encoding="utf-8") as fh:
94
+ assert fh.read() == "file body"
95
+ os.remove(saved)
96
+
97
+
98
+ def test_parse_multipart():
99
+ boundary = "abc"
100
+ body = (
101
+ f"--{boundary}\r\n"
102
+ 'Content-Disposition: form-data; name="k"\r\n\r\n'
103
+ "t1\r\n"
104
+ f"--{boundary}\r\n"
105
+ 'Content-Disposition: form-data; name="file"; filename="a b.txt"\r\n\r\n'
106
+ "data\r\n"
107
+ f"--{boundary}--\r\n"
108
+ ).encode()
109
+ token, name, data = _parse_multipart(body, f"multipart/form-data; boundary={boundary}")
110
+ assert token == "t1"
111
+ assert name == "a b.txt"
112
+ assert data == b"data"
113
+
114
+
115
+ def test_safe_name():
116
+ assert _safe_name("..\\..\\evil.txt") == "evil.txt"
117
+ assert _safe_name("bad/name?.txt") == "name_.txt"
118
+ assert _safe_name(" ") == "file.bin"