Skip to content

Commit

Permalink
fix: Python upgrade readiness changes
Browse files Browse the repository at this point in the history
  • Loading branch information
munna-shaik-s1 committed Dec 4, 2024
1 parent f3a0535 commit 2594062
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ def __new__(cls, name, bases, ns, *, total=True, closed=False):
if "__annotations__" in ns:
own_annotations = ns["__annotations__"]
elif "__annotate__" in ns:
# TODO: Use inspect.VALUE here, and make the annotations lazily evaluated
# TODO: Use inspect.VALUE here, and make the annotations lazily evaluated # noqa
own_annotations = ns["__annotate__"](1)
else:
own_annotations = {}
Expand Down Expand Up @@ -1729,7 +1729,7 @@ def _paramspec_prepare_subst(alias, args):
args = [*args, paramspec.__default__]
if i >= len(args):
raise TypeError(f"Too few arguments for {alias}")
# Special case where Z[[int, str, bool]] == Z[int, str, bool] in PEP 612.
# Special case where Z[[int, str, bool]] == Z[int, str, bool] in PEP 612. # noqa
if len(params) == 1 and not typing._is_param_expr(args[0]):
assert i == 0
args = (args,)
Expand Down Expand Up @@ -1916,7 +1916,7 @@ def _concatenate_getitem(self, parameters):
# 3.10+
if hasattr(typing, "Concatenate"):
Concatenate = typing.Concatenate
_ConcatenateGenericAlias = typing._ConcatenateGenericAlias
_ConcatenateGenericAlias = typing._ConcatenateGenericAlias # noqa
# 3.9
elif sys.version_info[:2] >= (3, 9):

Expand Down Expand Up @@ -3296,7 +3296,7 @@ def __new__(cls, typename, bases, ns):
if "__annotations__" in ns:
types = ns["__annotations__"]
elif "__annotate__" in ns:
# TODO: Use inspect.VALUE here, and make the annotations lazily evaluated
# TODO: Use inspect.VALUE here, and make the annotations lazily evaluated # noqa
types = ns["__annotate__"](1)
else:
types = {}
Expand Down Expand Up @@ -3326,7 +3326,7 @@ def __new__(cls, typename, bases, ns):
else:
class_getitem = typing.Generic.__class_getitem__.__func__
nm_tpl.__class_getitem__ = classmethod(class_getitem)
# update from user namespace without overriding special namedtuple attributes
# update from user namespace without overriding special namedtuple attributes # noqa
for key, val in list(ns.items()):
if key in _prohibited_namedtuple_fields:
raise AttributeError("Cannot overwrite NamedTuple attribute " + key)
Expand Down Expand Up @@ -3475,7 +3475,7 @@ class Buffer(abc.ABC): # noqa: B024
else:

def get_original_bases(cls, /):
"""Return the class's "original" bases prior to modification by `__mro_entries__`.
"""Return the class's "original" bases prior to modification by `__mro_entries__`. # noqa
Examples::
Expand Down
20 changes: 10 additions & 10 deletions lib_files/socks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

if os.name == "nt" and sys.version_info < (3, 0):
try:
import win_inet_pton
import win_inet_pton # noqa
except ImportError:
raise ImportError("To run PySocks on Windows you must install win_inet_pton")

Expand All @@ -50,7 +50,7 @@ def wrapper(*args, **kwargs):
if _is_blocking == 0:
self.setblocking(True)
return function(*args, **kwargs)
except Exception as e:
except Exception as e: # noqa
raise
finally:
# set orgin blocking
Expand Down Expand Up @@ -248,12 +248,12 @@ class _BaseSocket(socket.socket):
def __init__(self, *pos, **kw):
_orig_socket.__init__(self, *pos, **kw)

self._savedmethods = dict()
self._savedmethods = dict() # noqa
for name in self._savenames:
self._savedmethods[name] = getattr(self, name)
delattr(self, name) # Allows normal overriding mechanism to work

_savenames = list()
_savenames = list() # noqa


def _makemethod(name):
Expand Down Expand Up @@ -318,7 +318,7 @@ def settimeout(self, timeout):
self._timeout = timeout
try:
# test if we're connected, if so apply timeout
peer = self.get_proxy_peername()
peer = self.get_proxy_peername() # noqa
super(socksocket, self).settimeout(self._timeout)
except socket.error:
pass
Expand Down Expand Up @@ -847,11 +847,11 @@ def connect(self, dest_pair, catch_errors=None):
self.close()
if not catch_errors:
proxy_addr, proxy_port = proxy_addr
proxy_server = "{}:{}".format(proxy_addr, proxy_port)
proxy_server = "{}:{}".format(proxy_addr, proxy_port) # noqa
printable_type = PRINTABLE_PROXY_TYPES[proxy_type]

msg = "Error connecting to {} proxy {}".format(
printable_type, proxy_server
msg = "Error connecting to {} proxy at address {}:{}".format(
printable_type, proxy_addr, proxy_port
)
log.debug("%s due to: %s", msg, error)

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
raise ProxyConnectionError(msg, error)
Expand Down Expand Up @@ -879,14 +879,14 @@ def connect(self, dest_pair, catch_errors=None):
@set_self_blocking
def connect_ex(self, dest_pair):
"""https://docs.python.org/3/library/socket.html#socket.socket.connect_ex
Like connect(address), but return an error indicator instead of raising an exception for errors returned by the C-level connect() call (other problems, such as "host not found" can still raise exceptions).
Like connect(address), but return an error indicator instead of raising an exception for errors returned by the C-level connect() call (other problems, such as "host not found" can still raise exceptions). # noqa
"""
try:
self.connect(dest_pair, catch_errors=True)
return 0
except OSError as e:
# If the error is numeric (socket errors are numeric), then return number as
# connect_ex expects. Otherwise raise the error again (socket timeout for example)
# connect_ex expects. Otherwise raise the error again (socket timeout for example) # noqa
if e.errno:
return e.errno
else:
Expand Down
6 changes: 3 additions & 3 deletions lib_files/sockshandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
version: 0.3
author: e<[email protected]>
This module provides a Handler which you can use with urllib2 to allow it to tunnel your connection through a socks.sockssocket socket, with out monkey patching the original socket...
This module provides a Handler which you can use with urllib2 to allow it to tunnel your connection through a socks.sockssocket socket, with out monkey patching the original socket... # noqa
"""
from __future__ import print_function

Expand All @@ -19,7 +19,7 @@
import six.moves.urllib.parse
import six.moves.urllib.request
except ImportError: # Python 3
import urllib.request as urllib2
import urllib.request as urllib2 # noqa
import http.client as httplib

import socks # $ pip install PySocks
Expand All @@ -39,7 +39,7 @@ def is_ip(s):
socket.inet_aton(s)
else:
return False
except:
except: # noqa
return False
else:
return True
Expand Down
3 changes: 2 additions & 1 deletion scripts/pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ echo "Generate package - ${version}" && \
ucc-gen --source "${input}" --ta-version "${version}" && \
jq '.' globalConfig.json > globalConfig.new.json && \
mv globalConfig.new.json globalConfig.json && \
cp -f "lib_files/typing_extensions.py" "$output/TA_dataset/lib/typing_extensions.py" && \
echo "Updating typing_extensions.py, socks.py and sockshandler.py in lib of output"
cp -f "lib_files/cus_typing_extensions.py" "$output/TA_dataset/lib/typing_extensions.py" && \
cp -f "lib_files/socks.py" "$output/TA_dataset/lib/socks.py" && \
cp -f "lib_files/sockshandler.py" "$output/TA_dataset/lib/sockshandler.py" && \
echo "Construct tarball" && \
Expand Down

0 comments on commit 2594062

Please sign in to comment.