-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade to Python 3.7+ syntax (#234)
- Loading branch information
Showing
55 changed files
with
339 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
import logging | ||
import os | ||
import time | ||
import uuid | ||
|
||
from smbprotocol.connection import Connection | ||
|
||
log = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
def test_connection(server, port): | ||
conn = Connection(uuid.uuid4(), server, port=port) | ||
print("Opening connection to %s:%d" % (server, port)) | ||
log.info("Opening connection to %s:%d", server, port) | ||
conn.connect(timeout=5) | ||
conn.disconnect(True) | ||
|
||
|
||
if __name__ == "__main__": | ||
server = os.environ.get("SMB_SERVER", "127.0.0.1") | ||
port = int(os.environ.get("SMB_PORT", 445)) | ||
print("Waiting for SMB server to be online") | ||
log.info("Waiting for SMB server to be online") | ||
|
||
attempt = 1 | ||
total_attempts = 20 | ||
while attempt < total_attempts: | ||
print("Starting attempt %d" % attempt) | ||
log.info("Starting attempt %d", attempt) | ||
try: | ||
test_connection(server, port) | ||
break | ||
except Exception as e: | ||
print("Connection attempt %d failed: %s" % (attempt, str(e))) | ||
log.info("Connection attempt %d failed: %s", attempt, 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") from e | ||
|
||
print("Sleeping for 5 seconds before next attempt") | ||
log.info("Sleeping for 5 seconds before next attempt") | ||
time.sleep(5) | ||
|
||
print("Connection successful") | ||
log.info("Connection successful") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
1 change: 1 addition & 0 deletions
1
reports/junit/python-3.11.3-Linux-6.4.9-1-MANJARO-x86_64-with-glibc2.38.xml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# Copyright: (c) 2019, Jordan Borean (@jborean93) <[email protected]> | ||
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright: (c) 2019, Jordan Borean (@jborean93) <[email protected]> | ||
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright: (c) 2019, Jordan Borean (@jborean93) <[email protected]> | ||
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) | ||
|
||
|
@@ -52,9 +51,8 @@ def _parse_share_access(raw, mode): | |
for c in raw: | ||
access_val = share_access_map.get(c) | ||
if access_val is None: | ||
raise ValueError( | ||
"Invalid share_access char %s, can only be %s" % (c, ", ".join(sorted(share_access_map.keys()))) | ||
) | ||
chars = ", ".join(sorted(share_access_map.keys())) | ||
raise ValueError(f"Invalid share_access char {c}, can only be {chars}") | ||
share_access |= access_val | ||
|
||
if "r" in mode: | ||
|
@@ -82,12 +80,15 @@ def _parse_mode(raw, invalid=""): | |
for c in raw: | ||
dispo_val = disposition_map.get(c) | ||
if dispo_val is None: | ||
raise ValueError("Invalid mode char %s, can only be %s" % (c, ", ".join(sorted(disposition_map.keys())))) | ||
chars = ", ".join(sorted(disposition_map.keys())) | ||
raise ValueError( | ||
f"Invalid mode char {c}, can only be {chars}", | ||
) | ||
|
||
create_disposition |= dispo_val | ||
|
||
if create_disposition == 0: | ||
raise ValueError("Invalid mode value %s, must contain at least r, w, x, or a" % raw) | ||
raise ValueError(f"Invalid mode value {raw}, must contain at least r, w, x, or a") | ||
|
||
return create_disposition | ||
|
||
|
@@ -102,7 +103,7 @@ def _chunk_size(connection, length, operation): | |
:param operation: The operation the chunk is for: 'read', 'write', 'transact' | ||
:return: The size of the chunk we can use and the number of credits to request for the next operation. | ||
""" | ||
max_size = getattr(connection, "max_%s_size" % operation) | ||
max_size = getattr(connection, f"max_{operation}_size") | ||
|
||
# Determine the maximum data length we can send for the operation. We do this by checking the available credits and | ||
# calculating whatever is the smallest; length, negotiated operation size, available credit size). | ||
|
@@ -141,7 +142,7 @@ def _resolve_dfs(raw_io): | |
if not info: | ||
raise ObjectPathNotFound() | ||
|
||
connection_kwargs = getattr(raw_io, "_%s__kwargs" % SMBRawIO.__name__, {}) | ||
connection_kwargs = getattr(raw_io, f"_{SMBRawIO.__name__}__kwargs", {}) | ||
|
||
for target in info: | ||
new_path = raw_path.replace(info.dfs_path, target.target_path, 1) | ||
|
@@ -150,7 +151,7 @@ def _resolve_dfs(raw_io): | |
tree, fd_path = get_smb_tree(new_path, **connection_kwargs) | ||
|
||
except SMBResponseException as link_exc: | ||
log.warning("Failed to connect to DFS link target %s: %s", str(target), link_exc) | ||
log.warning("Failed to connect to DFS link target %s", target, exc_info=link_exc) | ||
continue | ||
|
||
# Record the target that worked for future reference. | ||
|
@@ -612,8 +613,7 @@ def query_directory(self, pattern, info_class): | |
break | ||
|
||
query_flags = 0 # Only the first request should have set SMB2_RESTART_SCANS | ||
for entry in entries: | ||
yield entry | ||
yield from entries | ||
|
||
def readable(self): | ||
return False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright: (c) 2019, Jordan Borean (@jborean93) <[email protected]> | ||
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) | ||
|
||
|
@@ -102,7 +101,7 @@ | |
) | ||
|
||
|
||
def is_remote_path(path): # type: (str) -> bool | ||
def is_remote_path(path: str) -> bool: | ||
""" | ||
Returns True iff the given path is a remote SMB path (rather than a local path). | ||
|
@@ -182,9 +181,8 @@ def copyfile(src, dst, **kwargs): | |
copychunk_response = SMB2SrvCopyChunkResponse() | ||
copychunk_response.unpack(result) | ||
if copychunk_response["chunks_written"].get_value() != len(batch): | ||
raise IOError( | ||
"Failed to copy all the chunks in a server side copyfile: '%s' -> '%s'" | ||
% (norm_src, norm_dst) | ||
raise OSError( | ||
f"Failed to copy all the chunks in a server side copyfile: '{norm_src}' -> '{norm_dst}'" | ||
) | ||
|
||
|
||
|
@@ -433,7 +431,7 @@ def readlink(path, **kwargs): | |
reparse_buffer = _get_reparse_point(norm_path, **kwargs) | ||
reparse_tag = reparse_buffer["reparse_tag"] | ||
if reparse_tag.get_value() != ReparseTags.IO_REPARSE_TAG_SYMLINK: | ||
raise ValueError("Cannot read link of reparse point with tag %s at '%s'" % (str(reparse_tag), norm_path)) | ||
raise ValueError(f"Cannot read link of reparse point with tag {reparse_tag} at '{norm_path}'") | ||
|
||
symlink_buffer = SymbolicLinkReparseDataBuffer() | ||
symlink_buffer.unpack(reparse_buffer["data_buffer"].get_value()) | ||
|
@@ -549,7 +547,7 @@ def scandir(path, search_pattern="*", **kwargs): | |
continue | ||
|
||
dir_entry = SMBDirEntry( | ||
SMBRawIO("%s\\%s" % (path, filename), **kwargs), dir_info, connection_cache=connection_cache | ||
SMBRawIO(rf"{path}\{filename}", **kwargs), dir_info, connection_cache=connection_cache | ||
) | ||
yield dir_entry | ||
|
||
|
@@ -696,12 +694,12 @@ def symlink(src, dst, target_is_directory=False, **kwargs): | |
norm_src = ntpath.abspath(ntpath.join(dst_dir, norm_src)) | ||
else: | ||
flags = SymbolicLinkFlags.SYMLINK_FLAG_ABSOLUTE | ||
substitute_name = "\\??\\UNC\\%s" % norm_src[2:] | ||
substitute_name = "\\??\\UNC\\" + norm_src[2:] | ||
|
||
src_drive = ntpath.splitdrive(norm_src)[0] | ||
dst_drive = ntpath.splitdrive(norm_dst)[0] | ||
if src_drive.lower() != dst_drive.lower(): | ||
raise ValueError("Resolved link src root '%s' must be the same as the dst root '%s'" % (src_drive, dst_drive)) | ||
raise ValueError(f"Resolved link src root '{src_drive}' must be the same as the dst root '{dst_drive}'") | ||
|
||
try: | ||
src_stat = stat(norm_src, **kwargs) | ||
|
@@ -901,13 +899,11 @@ def walk(top, topdown=True, onerror=None, follow_symlinks=False, **kwargs): | |
if not follow_symlinks and py_stat.S_ISLNK(lstat(dirpath, **kwargs).st_mode): | ||
continue | ||
|
||
for dir_top, dir_dirs, dir_files in walk(dirpath, **walk_kwargs): | ||
yield dir_top, dir_dirs, dir_files | ||
yield from walk(dirpath, **walk_kwargs) | ||
else: | ||
# On a bottom up approach we yield the sub directories before the top path. | ||
for dirpath in bottom_up_dirs: | ||
for dir_top, dir_dirs, dir_files in walk(dirpath, **walk_kwargs): | ||
yield dir_top, dir_dirs, dir_files | ||
yield from walk(dirpath, **walk_kwargs) | ||
|
||
yield top, dirs, files | ||
|
||
|
@@ -1095,7 +1091,7 @@ def _get_reparse_point(path, **kwargs): | |
def _rename_information(src, dst, replace_if_exists=False, **kwargs): | ||
verb = "replace" if replace_if_exists else "rename" | ||
if not is_remote_path(ntpath.normpath(dst)): | ||
raise ValueError("dst must be an absolute path to where the file or directory should be %sd." % verb) | ||
raise ValueError(f"dst must be an absolute path to where the file or directory should be {verb}d.") | ||
|
||
raw_args = dict(kwargs) | ||
raw_args.update( | ||
|
@@ -1126,7 +1122,7 @@ def _rename_information(src, dst, replace_if_exists=False, **kwargs): | |
dst_share = ntpath.normpath(dst_raw.fd.tree_connect.share_name).split("\\")[-1] | ||
|
||
if src_guid != dst_guid or src_share.lower() != dst_share.lower(): | ||
raise ValueError("Cannot %s a file to a different root than the src." % verb) | ||
raise ValueError(f"Cannot {verb} a file to a different root than the src.") | ||
|
||
dst_tree = dst_raw.fd.tree_connect | ||
dst_path = dst_raw.fd.file_name | ||
|
@@ -1181,7 +1177,7 @@ def __init__(self, raw, dir_info, connection_cache=None): | |
self._connection_cache = connection_cache | ||
|
||
def __str__(self): | ||
return "<{0}: {1!r}>".format(self.__class__.__name__, self.name) | ||
return f"<{self.__class__.__name__}: {self.name!r}>" | ||
|
||
@property | ||
def name(self): | ||
|
Oops, something went wrong.