Skip to content

Commit ea554d0

Browse files
authored
Add files via upload
1 parent e26aa37 commit ea554d0

10 files changed

Lines changed: 1015 additions & 116 deletions

PyWWW/pywwwget_bard.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def _wrap_text(binary_handle):
315315

316316
# Fallback: pure-Python in-memory objects
317317
if isbytes:
318-
f = io.BytesIO(init if init is not None else b"")
318+
f = io.MkTempFile(init if init is not None else b"")
319319
if reset_to_start:
320320
f.seek(0)
321321
_created(f, "bytesio")
@@ -481,7 +481,7 @@ def download_file_from_ftp_file(url):
481481
use_cwd = detect_cwd(ftp, os.path.dirname(p.path or "/"))
482482
retr_path = os.path.basename(p.path) if use_cwd else p.path
483483

484-
bio = BytesIO()
484+
bio = MkTempFile()
485485
ftp.retrbinary("RETR " + retr_path, bio.write)
486486
ftp.quit()
487487
bio.seek(0)
@@ -525,7 +525,7 @@ def download_file_from_sftp_file(url):
525525
ssh.connect(p.hostname, port=p.port or 22, username=p.username or "anonymous",
526526
password=p.password or "", timeout=10)
527527
sftp = ssh.open_sftp()
528-
bio = BytesIO()
528+
bio = MkTempFile()
529529
sftp.getfo(p.path or "/", bio)
530530
sftp.close()
531531
ssh.close()
@@ -1008,7 +1008,7 @@ def _serve_file_over_http(fileobj, url):
10081008
if must_buffer:
10091009
# Fallback for pipes with multiple clients
10101010
data = fileobj.read()
1011-
fileobj = BytesIO(data)
1011+
fileobj = MkTempFile(data)
10121012

10131013
class FileHandler(BaseHTTPRequestHandler):
10141014
def log_message(self, fmt, *args): pass
@@ -1090,7 +1090,7 @@ def download_file_from_internet_file(url, headers=None):
10901090

10911091
# Wrappers for string input/output
10921092
def upload_file_to_internet_string(data, url):
1093-
return upload_file_to_internet_file(BytesIO(_to_bytes(data)), url)
1093+
return upload_file_to_internet_file(MkTempFile(_to_bytes(data)), url)
10941094

10951095
def download_file_from_internet_string(url, headers=None):
10961096
fp = download_file_from_internet_file(url, headers)

PyWWW/pywwwget_chatgpt.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def _wrap_text(binary_handle):
382382

383383
# Fallback: pure-Python in-memory objects
384384
if isbytes:
385-
f = io.BytesIO(init if init is not None else b"")
385+
f = io.MkTempFile(init if init is not None else b"")
386386
if reset_to_start:
387387
f.seek(0)
388388
_created(f, "bytesio")
@@ -589,7 +589,7 @@ def download_file_from_ftp_file(url):
589589
use_cwd = detect_cwd(ftp, file_dir)
590590
retr_path = os.path.basename(path) if use_cwd else path
591591

592-
bio = BytesIO()
592+
bio = MkTempFile()
593593
ftp.retrbinary("RETR " + retr_path, bio.write)
594594
ftp.quit()
595595
bio.seek(0, 0)
@@ -652,7 +652,7 @@ def upload_file_to_ftp_file(fileobj, url):
652652
return False
653653

654654
def upload_file_to_ftp_string(data, url):
655-
bio = BytesIO(_to_bytes(data))
655+
bio = MkTempFile(_to_bytes(data))
656656
out = upload_file_to_ftp_file(bio, url)
657657
try:
658658
bio.close()
@@ -681,7 +681,7 @@ def download_file_from_sftp_file(url):
681681
try:
682682
ssh.connect(host, port=port, username=user, password=pw, timeout=10)
683683
sftp = ssh.open_sftp()
684-
bio = BytesIO()
684+
bio = MkTempFile()
685685
sftp.getfo(path, bio)
686686
sftp.close()
687687
ssh.close()
@@ -735,7 +735,7 @@ def upload_file_to_sftp_file(fileobj, url):
735735
return False
736736

737737
def upload_file_to_sftp_string(data, url):
738-
bio = BytesIO(_to_bytes(data))
738+
bio = MkTempFile(_to_bytes(data))
739739
out = upload_file_to_sftp_file(bio, url)
740740
try:
741741
bio.close()
@@ -2550,7 +2550,7 @@ def _open_reader():
25502550
return fileobj
25512551
if can_reopen:
25522552
return open(file_path, "rb")
2553-
return BytesIO(data_bytes)
2553+
return MkTempFile(data_bytes)
25542554

25552555
class _Handler(BaseHTTPRequestHandler):
25562556
server_version = "PyWWWGetCleanHTTP/1.0"
@@ -3023,7 +3023,7 @@ def _handle_upload(self):
30233023
outname = tf.name
30243024
outfp = tf
30253025
else:
3026-
out = BytesIO()
3026+
out = MkTempFile()
30273027

30283028
total = 0
30293029
if length is not None:
@@ -3184,7 +3184,7 @@ def upload_file_to_internet_file(fileobj, url):
31843184
return False
31853185

31863186
def upload_file_to_internet_string(data, url):
3187-
bio = BytesIO(_to_bytes(data))
3187+
bio = MkTempFile(_to_bytes(data))
31883188
out = upload_file_to_internet_file(bio, url)
31893189
try:
31903190
bio.close()

PyWWW/pywwwget_deepseek.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def _wrap_text(binary_handle):
578578

579579
# Fallback: pure-Python in-memory objects
580580
if isbytes:
581-
f = io.BytesIO(init if init is not None else b"")
581+
f = io.MkTempFile(init if init is not None else b"")
582582
if reset_to_start:
583583
f.seek(0)
584584
_created(f, "bytesio")
@@ -677,7 +677,7 @@ def download_file_from_ftp_file(url):
677677
use_cwd = detect_cwd(ftp, file_dir)
678678
retr_path = os.path.basename(path) if use_cwd else path
679679

680-
bio = BytesIO()
680+
bio = MkTempFile()
681681

682682
def callback(data):
683683
bio.write(data)
@@ -759,7 +759,7 @@ def upload_file_to_ftp_file(fileobj, url):
759759

760760
def upload_file_to_ftp_string(data, url):
761761
"""Upload string to FTP/FTPS server."""
762-
bio = BytesIO(_to_bytes(data))
762+
bio = MkTempFile(_to_bytes(data))
763763
out = upload_file_to_ftp_file(bio, url)
764764
try:
765765
bio.close()
@@ -835,7 +835,7 @@ def download_file_from_sftp_file(url):
835835
path = p.path or "/"
836836

837837
try:
838-
bio = BytesIO()
838+
bio = MkTempFile()
839839

840840
# Get file size for progress reporting
841841
try:
@@ -927,7 +927,7 @@ def upload_file_to_sftp_file(fileobj, url):
927927

928928
def upload_file_to_sftp_string(data, url):
929929
"""Upload string to SFTP server."""
930-
bio = BytesIO(_to_bytes(data))
930+
bio = MkTempFile(_to_bytes(data))
931931
out = upload_file_to_sftp_file(bio, url)
932932
try:
933933
bio.close()
@@ -2686,7 +2686,7 @@ def _open_reader():
26862686
return fileobj
26872687
if can_reopen:
26882688
return open(file_path, "rb")
2689-
return BytesIO(data_bytes)
2689+
return MkTempFile(data_bytes)
26902690

26912691
class _Handler(BaseHTTPRequestHandler):
26922692
"""HTTP request handler for serving files."""
@@ -3103,7 +3103,7 @@ def upload_file_to_internet_file(fileobj, url):
31033103

31043104
def upload_file_to_internet_string(data, url):
31053105
"""Upload string/bytes to any supported protocol."""
3106-
bio = BytesIO(_to_bytes(data))
3106+
bio = MkTempFile(_to_bytes(data))
31073107
out = upload_file_to_internet_file(bio, url)
31083108
try:
31093109
bio.close()

PyWWW/pywwwget_merged.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def _wrap_text(binary_handle):
389389

390390
# Fallback: pure-Python in-memory objects
391391
if isbytes:
392-
f = io.BytesIO(init if init is not None else b"")
392+
f = io.MkTempFile(init if init is not None else b"")
393393
if reset_to_start:
394394
f.seek(0)
395395
_created(f, "bytesio")
@@ -596,7 +596,7 @@ def download_file_from_ftp_file(url):
596596
use_cwd = detect_cwd(ftp, file_dir)
597597
retr_path = os.path.basename(path) if use_cwd else path
598598

599-
bio = BytesIO()
599+
bio = MkTempFile()
600600
ftp.retrbinary("RETR " + retr_path, bio.write)
601601
ftp.quit()
602602
bio.seek(0, 0)
@@ -659,7 +659,7 @@ def upload_file_to_ftp_file(fileobj, url):
659659
return False
660660

661661
def upload_file_to_ftp_string(data, url):
662-
bio = BytesIO(_to_bytes(data))
662+
bio = MkTempFile(_to_bytes(data))
663663
out = upload_file_to_ftp_file(bio, url)
664664
try:
665665
bio.close()
@@ -688,7 +688,7 @@ def download_file_from_sftp_file(url):
688688
try:
689689
ssh.connect(host, port=port, username=user, password=pw, timeout=10)
690690
sftp = ssh.open_sftp()
691-
bio = BytesIO()
691+
bio = MkTempFile()
692692
sftp.getfo(path, bio)
693693
sftp.close()
694694
ssh.close()
@@ -742,7 +742,7 @@ def upload_file_to_sftp_file(fileobj, url):
742742
return False
743743

744744
def upload_file_to_sftp_string(data, url):
745-
bio = BytesIO(_to_bytes(data))
745+
bio = MkTempFile(_to_bytes(data))
746746
out = upload_file_to_sftp_file(bio, url)
747747
try:
748748
bio.close()
@@ -2557,7 +2557,7 @@ def _open_reader():
25572557
return fileobj
25582558
if can_reopen:
25592559
return open(file_path, "rb")
2560-
return BytesIO(data_bytes)
2560+
return MkTempFile(data_bytes)
25612561

25622562
class _Handler(BaseHTTPRequestHandler):
25632563
server_version = "PyWWWGetCleanHTTP/1.0"
@@ -3030,7 +3030,7 @@ def _handle_upload(self):
30303030
outname = tf.name
30313031
outfp = tf
30323032
else:
3033-
out = BytesIO()
3033+
out = MkTempFile()
30343034

30353035
total = 0
30363036
if length is not None:
@@ -3191,7 +3191,7 @@ def upload_file_to_internet_file(fileobj, url):
31913191
return False
31923192

31933193
def upload_file_to_internet_string(data, url):
3194-
bio = BytesIO(_to_bytes(data))
3194+
bio = MkTempFile(_to_bytes(data))
31953195
out = upload_file_to_internet_file(bio, url)
31963196
try:
31973197
bio.close()

PyWWW/pywwwget_nextver.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _wrap_text(binary_handle):
403403

404404
# Fallback: pure-Python in-memory objects
405405
if isbytes:
406-
f = io.BytesIO(init if init is not None else b"")
406+
f = io.MkTempFile(init if init is not None else b"")
407407
if reset_to_start:
408408
f.seek(0)
409409
_created(f, "bytesio")
@@ -610,7 +610,7 @@ def download_file_from_ftp_file(url):
610610
use_cwd = detect_cwd(ftp, file_dir)
611611
retr_path = os.path.basename(path) if use_cwd else path
612612

613-
bio = BytesIO()
613+
bio = MkTempFile()
614614
ftp.retrbinary("RETR " + retr_path, bio.write)
615615
ftp.quit()
616616
bio.seek(0, 0)
@@ -673,7 +673,7 @@ def upload_file_to_ftp_file(fileobj, url):
673673
return False
674674

675675
def upload_file_to_ftp_string(data, url):
676-
bio = BytesIO(_to_bytes(data))
676+
bio = MkTempFile(_to_bytes(data))
677677
out = upload_file_to_ftp_file(bio, url)
678678
try:
679679
bio.close()
@@ -702,7 +702,7 @@ def download_file_from_sftp_file(url):
702702
try:
703703
ssh.connect(host, port=port, username=user, password=pw, timeout=10)
704704
sftp = ssh.open_sftp()
705-
bio = BytesIO()
705+
bio = MkTempFile()
706706
sftp.getfo(path, bio)
707707
sftp.close()
708708
ssh.close()
@@ -756,7 +756,7 @@ def upload_file_to_sftp_file(fileobj, url):
756756
return False
757757

758758
def upload_file_to_sftp_string(data, url):
759-
bio = BytesIO(_to_bytes(data))
759+
bio = MkTempFile(_to_bytes(data))
760760
out = upload_file_to_sftp_file(bio, url)
761761
try:
762762
bio.close()
@@ -2571,7 +2571,7 @@ def _open_reader():
25712571
return fileobj
25722572
if can_reopen:
25732573
return open(file_path, "rb")
2574-
return BytesIO(data_bytes)
2574+
return MkTempFile(data_bytes)
25752575

25762576
class _Handler(BaseHTTPRequestHandler):
25772577
server_version = "PyWWWGetCleanHTTP/1.0"
@@ -3044,7 +3044,7 @@ def _handle_upload(self):
30443044
outname = tf.name
30453045
outfp = tf
30463046
else:
3047-
out = BytesIO()
3047+
out = MkTempFile()
30483048

30493049
total = 0
30503050
if length is not None:
@@ -3205,7 +3205,7 @@ def upload_file_to_internet_file(fileobj, url):
32053205
return False
32063206

32073207
def upload_file_to_internet_string(data, url):
3208-
bio = BytesIO(_to_bytes(data))
3208+
bio = MkTempFile(_to_bytes(data))
32093209
out = upload_file_to_internet_file(bio, url)
32103210
try:
32113211
bio.close()

0 commit comments

Comments
 (0)