Skip to content

Commit 5bd1e84

Browse files
authored
Merge pull request #176 from BambuTools/ftp_socket_fix
fix connection unwrap
2 parents e1281f6 + 4e2b87e commit 5bd1e84

6 files changed

Lines changed: 18 additions & 5 deletions

File tree

bambulabs_api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
except Exception:
66
__version__ = "0.dev0+unknown"
77

8+
from bambulabs_api import client, mqtt_client, ftp_client, ams
9+
810
# flake8: noqa: F405
911
from .client import * # noqa
1012
from .filament_info import Filament, AMSFilamentSettings, FilamentTray # noqa
1113
from .states_info import PrintStatus, GcodeState # noqa
1214
from .mqtt_client import * # noqa
1315
from .ftp_client import * # noqa
1416
from .ams import * # noqa
17+
from bambulabs_api.logger import logger # noqa: F401
1518

1619

1720
__all__ = []
1821
__all__.extend(client.__all__)
1922
__all__.extend(mqtt_client.__all__)
2023
__all__.extend(ftp_client.__all__)
2124
__all__.extend(ams.__all__)
25+
__all__.append("logger")

bambulabs_api/ftp_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
class ImplicitFTP_TLS(ftplib.FTP_TLS):
1717
"""FTP_TLS subclass that automatically wraps sockets in SSL to support implicit FTPS.""" # noqa
1818

19-
def __init__(self, *args, **kwargs):
19+
def __init__(self, *args, unwrap: bool = False, **kwargs):
2020
super().__init__(*args, **kwargs)
2121
self._sock = None
22+
self.unwrap = unwrap
2223

2324
"""Explicit FTPS, with shared TLS session"""
2425
def ntransfercmd(self, cmd, rest=None):
@@ -45,16 +46,16 @@ def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
4546
self.voidcmd('TYPE I')
4647
conn = self.transfercmd(cmd, rest)
4748
try:
48-
while 1:
49+
while True:
4950
buf = fp.read(blocksize)
5051
if not buf:
5152
break
5253
conn.sendall(buf)
5354
if callback:
5455
callback(buf)
5556
# shutdown ssl layer
56-
if isinstance(conn, ssl.SSLSocket):
57-
# conn.unwrap() # Fix for storbinary waiting indefinitely for response message from server # noqa
57+
if isinstance(conn, ssl.SSLSocket) and self.unwrap:
58+
conn.unwrap() # Fix for storbinary waiting indefinitely for response message from server # noqa
5859
pass
5960
finally:
6061
conn.close() # This is the addition to the previous comment.

bambulabs_api/logger.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__all__ = ["logger"]
2+
13
import logging
24

35
logger = logging.getLogger("bambulabs_api")

docs/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Release notes for each release here:
77
.. toctree::
88
:maxdepth: 1
99

10+
2.6.6 <release/2.6.6-notes.rst>
1011
2.6.5 <release/2.6.5-notes.rst>
1112
2.6.4 <release/2.6.4-notes.rst>
1213
2.6.3 <release/2.6.3-notes.rst>

docs/release/2.6.6-notes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bambulabs API 2.6.6 Release Notes
2+
=================================
3+
4+
* Add unwrap connection option
5+
* Expose bambulab logger

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "bambulabs_api"
7-
version = "2.6.5"
7+
version = "2.6.6"
88
authors = [
99
{ name="Chris Ioannidis", email="chris.ioannidis23@imperial.ac.uk" },
1010
{ name="Haotian Wu", email="64962148+ohmdelta@users.noreply.github.com"}

0 commit comments

Comments
 (0)