Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 style updates #212

Merged
merged 4 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build_helpers/check-smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_connection(server, port):
print("Connection attempt %d failed: %s" % (attempt, str(e)))
attempt += 1
if attempt == total_attempts:
raise Exception("Timeout while waiting for SMB server to come " "online")
raise Exception("Timeout while waiting for SMB server to come online")

print("Sleeping for 5 seconds before next attempt")
time.sleep(5)
Expand Down
4 changes: 2 additions & 2 deletions src/smbclient/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _receive_resp(request):
transaction += (set_req, _receive_resp)


class SMBFileTransaction(object):
class SMBFileTransaction:
def __init__(self, raw):
"""
Stores compound requests in 1 class that can be committed when required. Either uses the opened raw object or
Expand Down Expand Up @@ -392,7 +392,7 @@ def __init__(
"file": CreateOptions.FILE_NON_DIRECTORY_FILE,
}.get(self.FILE_TYPE, 0)

super(SMBRawIO, self).__init__()
super().__init__()

def __enter__(self):
self.open()
Expand Down
2 changes: 1 addition & 1 deletion src/smbclient/_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ def _set_basic_information(
set_info(transaction, basic_info)


class SMBDirEntry(object):
class SMBDirEntry:
def __init__(self, raw, dir_info, connection_cache=None):
self._smb_raw = raw
self._dir_info = dir_info
Expand Down
2 changes: 1 addition & 1 deletion src/smbclient/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class _ConfigSingleton(type):

def __call__(cls, *args, **kwargs):
if cls not in cls.__instances:
config = super(_ConfigSingleton, cls).__call__(*args, **kwargs)
config = super().__call__(*args, **kwargs)
cls.__instances[cls] = config

# Needs to be done after the config instance is in the singleton dict due to setting this value will kick
Expand Down
12 changes: 2 additions & 10 deletions src/smbprotocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)

import logging

try:
from logging import NullHandler
except ImportError: # pragma: no cover

class NullHandler(logging.Handler):
def emit(self, record):
pass

from logging import NullHandler

logger = logging.getLogger(__name__)
logger.addHandler(NullHandler())
Expand All @@ -20,7 +12,7 @@ def emit(self, record):
MAX_PAYLOAD_SIZE = 65536


class Dialects(object):
class Dialects:
"""
[MS-SMB2] v53.0 2017-09-15

Expand Down
16 changes: 8 additions & 8 deletions src/smbprotocol/change_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
log = logging.getLogger(__name__)


class ChangeNotifyFlags(object):
class ChangeNotifyFlags:
"""
[MS-SMB2] 2.2.35 SMB2 CHANGE_NOTIFY Request - Flags
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/598f395a-e7a2-4cc8-afb3-ccb30dd2df7c
Expand All @@ -30,7 +30,7 @@ class ChangeNotifyFlags(object):
SMB2_WATCH_TREE = 0x0001


class CompletionFilter(object):
class CompletionFilter:
"""
[MS-SMB2] 2.2.35 SMB2 CHANGE_NOTIFY Request - CompletionFilter
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/598f395a-e7a2-4cc8-afb3-ccb30dd2df7c
Expand All @@ -50,7 +50,7 @@ class CompletionFilter(object):
FILE_NOTIFY_CHANGE_STREAM_WRITE = 0x00000800


class FileAction(object):
class FileAction:
"""
[MS-FSCC] 2.7.1 FILE_NOTIFY_INFORMATION - Action
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/634043d7-7b39-47e9-9e26-bda64685e4c9
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(self):
),
]
)
super(FileNotifyInformation, self).__init__()
super().__init__()


class SMB2ChangeNotifyRequest(Structure):
Expand Down Expand Up @@ -144,7 +144,7 @@ def __init__(self):
("reserved", IntField(size=4)),
]
)
super(SMB2ChangeNotifyRequest, self).__init__()
super().__init__()


class SMB2ChangeNotifyResponse(Structure):
Expand Down Expand Up @@ -189,10 +189,10 @@ def __init__(self):
),
]
)
super(SMB2ChangeNotifyResponse, self).__init__()
super().__init__()


class FileSystemWatcher(object):
class FileSystemWatcher:
def __init__(self, open):
"""
A class that encapsulates a FileSystemWatcher over SMB. It is designed to make it easy to run the watcher in
Expand Down Expand Up @@ -254,7 +254,7 @@ def result(self):

@property
def cancelled(self):
""" States whether the change notify request was cancelled or not. """ ""
"""States whether the change notify request was cancelled or not."""
return self._request is not None and self._request.cancelled is True

def start(self, completion_filter, flags=0, output_buffer_length=65536, send=True):
Expand Down
38 changes: 19 additions & 19 deletions src/smbprotocol/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
log = logging.getLogger(__name__)


class SecurityMode(object):
class SecurityMode:
"""
[MS-SMB2] v53.0 2017-09-15

Expand All @@ -64,7 +64,7 @@ class SecurityMode(object):
SMB2_NEGOTIATE_SIGNING_REQUIRED = 0x0002


class Capabilities(object):
class Capabilities:
"""
[MS-SMB2] v53.0 2017-09-15

Expand All @@ -81,7 +81,7 @@ class Capabilities(object):
SMB2_GLOBAL_CAP_ENCRYPTION = 0x00000040


class NegotiateContextType(object):
class NegotiateContextType:
"""
[MS-SMB2] v53.0 2017-09-15

Expand All @@ -98,7 +98,7 @@ class NegotiateContextType(object):
SMB2_SIGNING_CAPABILITIES = 0x0008


class HashAlgorithms(object):
class HashAlgorithms:
"""
[MS-SMB2] v53.0 2017-09-15

Expand All @@ -109,7 +109,7 @@ class HashAlgorithms(object):
SHA_512 = 0x0001


class Ciphers(object):
class Ciphers:
"""
[MS-SMB2] v53.0 2017-09-15

Expand Down Expand Up @@ -189,7 +189,7 @@ def __init__(self):
]
)

super(SMB2NegotiateRequest, self).__init__()
super().__init__()


class SMB3NegotiateRequest(Structure):
Expand Down Expand Up @@ -276,7 +276,7 @@ def __init__(self):
),
]
)
super(SMB3NegotiateRequest, self).__init__()
super().__init__()

def _negotiate_context_offset_value(self, structure):
# The offset from the beginning of the SMB2 header to the first, 8-byte
Expand Down Expand Up @@ -359,7 +359,7 @@ def __init__(self):
),
]
)
super(SMB2NegotiateContextRequest, self).__init__()
super().__init__()

def _data_structure_type(self, structure):
con_type = structure["context_type"].get_value()
Expand Down Expand Up @@ -421,7 +421,7 @@ def __init__(self):
),
]
)
super(SMB2PreauthIntegrityCapabilities, self).__init__()
super().__init__()


class SMB2EncryptionCapabilities(Structure):
Expand Down Expand Up @@ -454,7 +454,7 @@ def __init__(self):
),
]
)
super(SMB2EncryptionCapabilities, self).__init__()
super().__init__()


class SMB2NetnameNegotiateContextId(Structure):
Expand Down Expand Up @@ -601,7 +601,7 @@ def __init__(self):
),
]
)
super(SMB2NegotiateResponse, self).__init__()
super().__init__()

def _negotiate_context_count_value(self, structure):
# If the dialect_revision is SMBv3.1.1, this field specifies the
Expand Down Expand Up @@ -667,7 +667,7 @@ class SMB2Echo(Structure):

def __init__(self):
self.fields = OrderedDict([("structure_size", IntField(size=2, default=4)), ("reserved", IntField(size=2))])
super(SMB2Echo, self).__init__()
super().__init__()


class SMB2CancelRequest(Structure):
Expand All @@ -694,7 +694,7 @@ def __init__(self):
("reserved", IntField(size=2)),
]
)
super(SMB2CancelRequest, self).__init__()
super().__init__()


class SMB2TransformHeader(Structure):
Expand All @@ -719,10 +719,10 @@ def __init__(self):
("data", BytesField()), # not in spec
]
)
super(SMB2TransformHeader, self).__init__()
super().__init__()


class Connection(object):
class Connection:
def __init__(self, guid, server_name, port=445, require_signing=True):
"""
[MS-SMB2] v53.0 2017-09-15
Expand Down Expand Up @@ -1112,7 +1112,7 @@ def echo(self, sid=0, timeout=60, credit_request=1):
:param credit_request: The number of credits to request
:return: the credits that were granted by the server
"""
log.info("Sending Echo request with a timeout of %d and credit " "request of %d" % (timeout, credit_request))
log.info("Sending Echo request with a timeout of %d and credit request of %d" % (timeout, credit_request))

echo_msg = SMB2Echo()
log.debug(echo_msg)
Expand Down Expand Up @@ -1566,15 +1566,15 @@ def _send_smb2_negotiate(self, dialect, timeout, encryption_algorithms, signing_
int_cap["data"]["hash_algorithms"] = [HashAlgorithms.SHA_512]
int_cap["data"]["salt"] = self.salt
log.debug(
"Adding preauth integrity capabilities of hash SHA512 " "and salt %s to negotiate request" % self.salt
"Adding preauth integrity capabilities of hash SHA512 and salt %s to negotiate request" % self.salt
)

enc_cap = SMB2NegotiateContextRequest()
enc_cap["context_type"] = NegotiateContextType.SMB2_ENCRYPTION_CAPABILITIES
enc_cap["data"] = SMB2EncryptionCapabilities()
supported_ciphers = encryption_algorithms
enc_cap["data"]["ciphers"] = supported_ciphers
log.debug("Adding encryption capabilities of AES128|256 GCM and " "AES128|256 CCM to negotiate request")
log.debug("Adding encryption capabilities of AES128|256 GCM and AES128|256 CCM to negotiate request")

netname_id = SMB2NegotiateContextRequest()
netname_id["context_type"] = NegotiateContextType.SMB2_NETNAME_NEGOTIATE_CONTEXT_ID
Expand Down Expand Up @@ -1656,7 +1656,7 @@ def _calculate_credit_charge(self, message):
return credit_charge


class Request(object):
class Request:
def __init__(self, message, message_type, connection, session_id=None):
"""
[MS-SMB2] v53.0 2017-09-15
Expand Down
Loading