Skip to content

Commit acbcf10

Browse files
kpumukJens-G
authored andcommitted
Fixed Python flake8 offenses
1 parent 96d62dd commit acbcf10

26 files changed

+79
-52
lines changed

lib/py/src/TTornado.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def _lock_context(self):
6666

6767
class TTornadoStreamTransport(TTransportBase):
6868
"""a framed, buffered transport over a Tornado stream"""
69+
6970
def __init__(self, host, port, stream=None, io_loop=None):
7071
if io_loop is not None:
7172
warnings.warn(
@@ -90,9 +91,9 @@ def with_timeout(self, timeout, future):
9091
return gen.with_timeout(timeout, future)
9192

9293
def isOpen(self):
93-
if self.stream is None:
94-
return False
95-
return not self.stream.closed()
94+
if self.stream is None:
95+
return False
96+
return not self.stream.closed()
9697

9798
@gen.coroutine
9899
def open(self, timeout=None):

lib/py/src/protocol/TJSONProtocol.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
TProtocolFactory, checkIntegerLimits)
2222
import base64
2323
import math
24-
import sys
2524

2625

2726
__all__ = ['TJSONProtocol',

lib/py/src/protocol/TProtocol.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from thrift.Thrift import TException, TType, TFrozenDict
2121
from thrift.transport.TTransport import TTransportException
2222

23-
import sys
2423
from itertools import islice
2524

2625

lib/py/src/transport/THttpClient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def basic_proxy_auth_header(proxy):
102102
ap = "%s:%s" % (urllib.parse.unquote(proxy.username),
103103
urllib.parse.unquote(proxy.password))
104104
cr = base64.b64encode(ap.encode()).strip()
105-
return "Basic " + six.ensure_str(cr)
105+
return "Basic " + cr.decode("ascii")
106106

107107
def using_proxy(self):
108108
return self.realhost is not None

lib/py/src/transport/TSSLSocket.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
from thrift.transport import TSocket
2929
from thrift.transport.TTransport import TTransportException
3030

31-
_match_hostname = lambda cert, hostname: True
31+
32+
def _match_hostname(cert, hostname):
33+
return True
34+
3235

3336
logger = logging.getLogger(__name__)
3437
warnings.filterwarnings(
@@ -356,7 +359,7 @@ def __init__(self, host=None, port=9090, *args, **kwargs):
356359
# Preserve existing behaviors for default values
357360
if 'cert_reqs' not in kwargs:
358361
kwargs['cert_reqs'] = ssl.CERT_NONE
359-
if'certfile' not in kwargs:
362+
if 'certfile' not in kwargs:
360363
kwargs['certfile'] = 'cert.pem'
361364

362365
unix_socket = kwargs.pop('unix_socket', None)

lib/py/src/transport/sslcompat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def _optional_dependencies():
9797
# 3.7. OpenSSL performs hostname matching since Python 3.7, Python no
9898
# longer uses the ssl.match_hostname() function.""
9999
if sys.version_info[0] > 3 or (sys.version_info[0] == 3 and sys.version_info[1] >= 12):
100-
match = lambda cert, hostname: True
100+
def match(cert, hostname):
101+
return True
101102
else:
102103
logger.warning('using legacy validation callback')
103104
match = legacy_validate_callback

lib/py/test/fuzz/fuzz_common.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import os
2323
import atheris
2424

25+
2526
def setup_thrift_imports():
2627
"""Set up the Python path to include Thrift libraries and generated code."""
2728

@@ -48,19 +49,21 @@ def setup_thrift_imports():
4849
sys.path.append(gen_path)
4950
print(sys.path)
5051

52+
5153
setup_thrift_imports()
5254

5355
from thrift.transport import TTransport
5456
from thrift.TSerialization import serialize, deserialize
5557
from fuzz.ttypes import FuzzTest
5658

59+
5760
def create_parser_fuzzer(protocol_factory_class):
5861
"""
5962
Create a parser fuzzer function for a specific protocol.
60-
63+
6164
Args:
6265
protocol_factory_class: The Thrift protocol factory class to use
63-
66+
6467
Returns:
6568
A function that can be used with atheris.Setup()
6669
"""
@@ -71,25 +74,26 @@ def TestOneInput(data):
7174
try:
7275
# Create a memory buffer with the fuzzed data
7376
buf = TTransport.TMemoryBuffer(data)
74-
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
77+
TTransport.TBufferedTransportFactory().getTransport(buf)
7578
factory = protocol_factory_class(string_length_limit=1000, container_length_limit=1000)
7679

7780
# Try to deserialize the fuzzed data into the test class
78-
test_instance = deserialize(FuzzTest(), data, factory)
81+
deserialize(FuzzTest(), data, factory)
7982

80-
except Exception as e:
83+
except Exception:
8184
# We expect various exceptions during fuzzing
8285
pass
8386

8487
return TestOneInput
8588

89+
8690
def create_roundtrip_fuzzer(protocol_factory_class):
8791
"""
8892
Create a roundtrip fuzzer function for a specific protocol.
89-
93+
9094
Args:
9195
protocol_factory_class: The Thrift protocol factory class to use
92-
96+
9397
Returns:
9498
A function that can be used with atheris.Setup()
9599
"""
@@ -100,7 +104,7 @@ def TestOneInput(data):
100104
try:
101105
# Create a memory buffer with the fuzzed data
102106
buf = TTransport.TMemoryBuffer(data)
103-
transport = TTransport.TBufferedTransportFactory().getTransport(buf)
107+
TTransport.TBufferedTransportFactory().getTransport(buf)
104108
factory = protocol_factory_class(string_length_limit=1000, container_length_limit=1000)
105109

106110
# Try to deserialize the fuzzed data into the test class
@@ -112,18 +116,19 @@ def TestOneInput(data):
112116
# Verify the objects are equal after a second deserialization
113117
assert test_instance == deserialized
114118

115-
except AssertionError as e:
116-
raise e
117-
except Exception as e:
119+
except AssertionError:
120+
raise
121+
except Exception:
118122
# We expect various exceptions during fuzzing
119123
pass
120124

121125
return TestOneInput
122126

127+
123128
def _run_fuzzer(fuzzer_function):
124129
"""
125130
Set up and run the fuzzer for a specific protocol.
126-
131+
127132
Args:
128133
fuzzer_function: The fuzzer function to use
129134
"""
@@ -136,7 +141,7 @@ def _run_fuzzer(fuzzer_function):
136141
def run_roundtrip_fuzzer(protocol_factory_class):
137142
"""
138143
Set up and run the fuzzer for a specific protocol.
139-
144+
140145
Args:
141146
protocol_factory_class: The Thrift protocol factory class to use
142147
"""
@@ -146,8 +151,8 @@ def run_roundtrip_fuzzer(protocol_factory_class):
146151
def run_parser_fuzzer(protocol_factory_class):
147152
"""
148153
Set up and run the fuzzer for a specific protocol.
149-
154+
150155
Args:
151156
protocol_factory_class: The Thrift protocol factory class to use
152157
"""
153-
_run_fuzzer(create_parser_fuzzer(protocol_factory_class))
158+
_run_fuzzer(create_parser_fuzzer(protocol_factory_class))

lib/py/test/fuzz/fuzz_parse_TBinaryProtocol.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
from fuzz_common import run_parser_fuzzer
2121
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
2222

23+
2324
def main():
2425
run_parser_fuzzer(TBinaryProtocolFactory)
2526

27+
2628
if __name__ == "__main__":
2729
main()

lib/py/test/fuzz/fuzz_parse_TBinaryProtocolAccelerated.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
from fuzz_common import run_parser_fuzzer
2121
from thrift.protocol.TBinaryProtocol import TBinaryProtocolAcceleratedFactory
2222

23+
2324
def main():
2425
run_parser_fuzzer(TBinaryProtocolAcceleratedFactory)
2526

27+
2628
if __name__ == "__main__":
27-
main()
29+
main()

lib/py/test/fuzz/fuzz_parse_TCompactProtocol.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
from fuzz_common import run_parser_fuzzer
2121
from thrift.protocol.TCompactProtocol import TCompactProtocolFactory
2222

23+
2324
def main():
2425
run_parser_fuzzer(TCompactProtocolFactory)
2526

27+
2628
if __name__ == "__main__":
27-
main()
29+
main()

0 commit comments

Comments
 (0)