Skip to content

Commit 4df3830

Browse files
committed
Format sourcode with black
1 parent 8a1c71d commit 4df3830

File tree

105 files changed

+6482
-4816
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+6482
-4816
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ retest:
2222
coverage:
2323
py.test --cov=zeep --cov-report=term-missing --cov-report=html
2424

25+
format:
26+
black src/ tests/
27+
isort --recursive src tests
28+
2529
docs:
2630
$(MAKE) -C docs html
2731

src/zeep/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
from zeep.settings import Settings # noqa
55
from zeep.xsd.valueobjects import AnyObject # noqa
66

7-
__version__ = '3.3.1'
7+
__version__ = "3.3.1"

src/zeep/__main__.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,54 @@
1313
from zeep.settings import Settings
1414
from zeep.transports import Transport
1515

16-
logger = logging.getLogger('zeep')
16+
logger = logging.getLogger("zeep")
1717

1818

1919
def parse_arguments(args=None):
20-
parser = argparse.ArgumentParser(description='Zeep: The SOAP client')
20+
parser = argparse.ArgumentParser(description="Zeep: The SOAP client")
2121
parser.add_argument(
22-
'wsdl_file', type=str, help='Path or URL to the WSDL file',
23-
default=None)
22+
"wsdl_file", type=str, help="Path or URL to the WSDL file", default=None
23+
)
24+
parser.add_argument("--cache", action="store_true", help="Enable cache")
2425
parser.add_argument(
25-
'--cache', action='store_true', help='Enable cache')
26+
"--no-verify", action="store_true", help="Disable SSL verification"
27+
)
28+
parser.add_argument("--verbose", action="store_true", help="Enable verbose output")
2629
parser.add_argument(
27-
'--no-verify', action='store_true', help='Disable SSL verification')
30+
"--profile", help="Enable profiling and save output to given file"
31+
)
2832
parser.add_argument(
29-
'--verbose', action='store_true', help='Enable verbose output')
30-
parser.add_argument(
31-
'--profile', help="Enable profiling and save output to given file")
32-
parser.add_argument(
33-
'--no-strict', action='store_true', default=False,
34-
help="Disable strict mode")
33+
"--no-strict", action="store_true", default=False, help="Disable strict mode"
34+
)
3535
return parser.parse_args(args)
3636

3737

3838
def main(args):
3939
if args.verbose:
40-
logging.config.dictConfig({
41-
'version': 1,
42-
'formatters': {
43-
'verbose': {
44-
'format': '%(name)20s: %(message)s'
45-
}
46-
},
47-
'handlers': {
48-
'console': {
49-
'level': 'DEBUG',
50-
'class': 'logging.StreamHandler',
51-
'formatter': 'verbose',
40+
logging.config.dictConfig(
41+
{
42+
"version": 1,
43+
"formatters": {"verbose": {"format": "%(name)20s: %(message)s"}},
44+
"handlers": {
45+
"console": {
46+
"level": "DEBUG",
47+
"class": "logging.StreamHandler",
48+
"formatter": "verbose",
49+
}
5250
},
53-
},
54-
'loggers': {
55-
'zeep': {
56-
'level': 'DEBUG',
57-
'propagate': True,
58-
'handlers': ['console'],
51+
"loggers": {
52+
"zeep": {
53+
"level": "DEBUG",
54+
"propagate": True,
55+
"handlers": ["console"],
56+
}
5957
},
6058
}
61-
})
59+
)
6260

6361
if args.profile:
6462
import cProfile
63+
6564
profile = cProfile.Profile()
6665
profile.enable()
6766

@@ -88,6 +87,6 @@ def main(args):
8887
client.wsdl.dump()
8988

9089

91-
if __name__ == '__main__':
90+
if __name__ == "__main__":
9291
args = parse_arguments()
9392
main(args)

src/zeep/asyncio/bindings.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
from zeep.wsdl import bindings
22

3-
__all__ = ['AsyncSoap11Binding', 'AsyncSoap12Binding']
3+
__all__ = ["AsyncSoap11Binding", "AsyncSoap12Binding"]
44

55

66
class AsyncSoapBinding(object):
7-
87
async def send(self, client, options, operation, args, kwargs):
98
envelope, http_headers = self._create(
10-
operation, args, kwargs,
11-
client=client,
12-
options=options)
9+
operation, args, kwargs, client=client, options=options
10+
)
1311

1412
response = await client.transport.post_xml(
15-
options['address'], envelope, http_headers)
13+
options["address"], envelope, http_headers
14+
)
1615

1716
if client.settings.raw_response:
18-
return response
19-
17+
return response
18+
2019
operation_obj = self.get(operation)
2120
return self.process_reply(client, operation_obj, response)
2221

src/zeep/asyncio/transport.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@
2020
from aiohttp import Timeout as aio_timeout # Python 3.5, aiohttp < 3
2121

2222

23-
__all__ = ['AsyncTransport']
23+
__all__ = ["AsyncTransport"]
2424

2525

2626
class AsyncTransport(Transport):
2727
"""Asynchronous Transport class using aiohttp."""
28-
binding_classes = [
29-
bindings.AsyncSoap11Binding,
30-
bindings.AsyncSoap12Binding,
31-
]
3228

33-
def __init__(self, loop, cache=None, timeout=300, operation_timeout=None,
34-
session=None, verify_ssl=True, proxy=None):
29+
binding_classes = [bindings.AsyncSoap11Binding, bindings.AsyncSoap12Binding]
30+
31+
def __init__(
32+
self,
33+
loop,
34+
cache=None,
35+
timeout=300,
36+
operation_timeout=None,
37+
session=None,
38+
verify_ssl=True,
39+
proxy=None,
40+
):
3541

3642
self.loop = loop if loop else asyncio.get_event_loop()
3743
self.cache = cache
@@ -43,8 +49,9 @@ def __init__(self, loop, cache=None, timeout=300, operation_timeout=None,
4349
self.proxy = proxy
4450
self.session = session or aiohttp.ClientSession(loop=self.loop)
4551
self._close_session = session is None
46-
self.session._default_headers['User-Agent'] = (
47-
'Zeep/%s (www.python-zeep.org)' % (get_version()))
52+
self.session._default_headers[
53+
"User-Agent"
54+
] = "Zeep/%s (www.python-zeep.org)" % (get_version())
4855

4956
def __del__(self):
5057
if self._close_session:
@@ -70,9 +77,7 @@ async def _load_remote_data_async():
7077
response.raise_for_status()
7178
except aiohttp.ClientError as exc:
7279
raise TransportError(
73-
message=str(exc),
74-
status_code=response.status,
75-
content=result
80+
message=str(exc), status_code=response.status, content=result
7681
).with_traceback(exc.__traceback__) from exc
7782

7883
# Block until we have the data
@@ -83,11 +88,18 @@ async def post(self, address, message, headers):
8388
self.logger.debug("HTTP Post to %s:\n%s", address, message)
8489
with aio_timeout(self.operation_timeout):
8590
response = await self.session.post(
86-
address, data=message, headers=headers,
87-
verify_ssl=self.verify_ssl, proxy=self.proxy)
91+
address,
92+
data=message,
93+
headers=headers,
94+
verify_ssl=self.verify_ssl,
95+
proxy=self.proxy,
96+
)
8897
self.logger.debug(
8998
"HTTP Response from %s (status: %d):\n%s",
90-
address, response.status, await response.read())
99+
address,
100+
response.status,
101+
await response.read(),
102+
)
91103
return response
92104

93105
async def post_xml(self, address, envelope, headers):
@@ -98,8 +110,12 @@ async def post_xml(self, address, envelope, headers):
98110
async def get(self, address, params, headers):
99111
with aio_timeout(self.operation_timeout):
100112
response = await self.session.get(
101-
address, params=params, headers=headers,
102-
verify_ssl=self.verify_ssl, proxy=self.proxy)
113+
address,
114+
params=params,
115+
headers=headers,
116+
verify_ssl=self.verify_ssl,
117+
proxy=self.proxy,
118+
)
103119

104120
return await self.new_response(response)
105121

src/zeep/cache.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323

2424
class Base(object):
25-
2625
def add(self, url, content):
2726
raise NotImplemented()
2827

@@ -32,6 +31,7 @@ def get(self, url):
3231

3332
class InMemoryCache(Base):
3433
"""Simple in-memory caching using dict lookup with support for timeouts"""
34+
3535
_cache = {} # global cache, thread-safe by default
3636

3737
def __init__(self, timeout=3600):
@@ -41,7 +41,8 @@ def add(self, url, content):
4141
logger.debug("Caching contents of %s", url)
4242
if not isinstance(content, (str, bytes)):
4343
raise TypeError(
44-
"a bytes-like object is required, not {}".format(type(content).__name__))
44+
"a bytes-like object is required, not {}".format(type(content).__name__)
45+
)
4546
self._cache[url] = (datetime.datetime.utcnow(), content)
4647

4748
def get(self, url):
@@ -59,18 +60,20 @@ def get(self, url):
5960

6061
class SqliteCache(Base):
6162
"""Cache contents via an sqlite database on the filesystem"""
62-
_version = '1'
63+
64+
_version = "1"
6365

6466
def __init__(self, path=None, timeout=3600):
6567

6668
if sqlite3 is None:
6769
raise RuntimeError("sqlite3 module is required for the SqliteCache")
6870

6971
# No way we can support this when we want to achieve thread safety
70-
if path == ':memory:':
72+
if path == ":memory:":
7173
raise ValueError(
72-
"The SqliteCache doesn't support :memory: since it is not " +
73-
"thread-safe. Please use zeep.cache.InMemoryCache()")
74+
"The SqliteCache doesn't support :memory: since it is not "
75+
+ "thread-safe. Please use zeep.cache.InMemoryCache()"
76+
)
7477

7578
self._lock = threading.RLock()
7679
self._timeout = timeout
@@ -83,14 +86,16 @@ def __init__(self, path=None, timeout=3600):
8386
"""
8487
CREATE TABLE IF NOT EXISTS request
8588
(created timestamp, url text, content text)
86-
""")
89+
"""
90+
)
8791
conn.commit()
8892

8993
@contextmanager
9094
def db_connection(self):
9195
with self._lock:
9296
connection = sqlite3.connect(
93-
self._db_path, detect_types=sqlite3.PARSE_DECLTYPES)
97+
self._db_path, detect_types=sqlite3.PARSE_DECLTYPES
98+
)
9499
yield connection
95100
connection.close()
96101

@@ -103,14 +108,14 @@ def add(self, url, content):
103108
cursor.execute("DELETE FROM request WHERE url = ?", (url,))
104109
cursor.execute(
105110
"INSERT INTO request (created, url, content) VALUES (?, ?, ?)",
106-
(datetime.datetime.utcnow(), url, data))
111+
(datetime.datetime.utcnow(), url, data),
112+
)
107113
conn.commit()
108114

109115
def get(self, url):
110116
with self.db_connection() as conn:
111117
cursor = conn.cursor()
112-
cursor.execute(
113-
"SELECT created, content FROM request WHERE url=?", (url, ))
118+
cursor.execute("SELECT created, content FROM request WHERE url=?", (url,))
114119
rows = cursor.fetchall()
115120

116121
if rows:
@@ -130,12 +135,12 @@ def _decode_data(self, data):
130135
if six.PY2:
131136
data = str(data)
132137
if data.startswith(self._version_string):
133-
return base64.b64decode(data[len(self._version_string):])
138+
return base64.b64decode(data[len(self._version_string) :])
134139

135140
@property
136141
def _version_string(self):
137-
prefix = u'$ZEEP:%s$' % self._version
138-
return bytes(prefix.encode('ascii'))
142+
prefix = u"$ZEEP:%s$" % self._version
143+
return bytes(prefix.encode("ascii"))
139144

140145

141146
def _is_expired(value, timeout):
@@ -150,12 +155,12 @@ def _is_expired(value, timeout):
150155

151156

152157
def _get_default_cache_path():
153-
path = appdirs.user_cache_dir('zeep', False)
158+
path = appdirs.user_cache_dir("zeep", False)
154159
try:
155160
os.makedirs(path)
156161
except OSError as exc:
157162
if exc.errno == errno.EEXIST and os.path.isdir(path):
158163
pass
159164
else:
160165
raise
161-
return os.path.join(path, 'cache.db')
166+
return os.path.join(path, "cache.db")

0 commit comments

Comments
 (0)