Skip to content

Commit b9750bd

Browse files
committed
Run the current version of yapf
1 parent 8b64020 commit b9750bd

File tree

8 files changed

+74
-67
lines changed

8 files changed

+74
-67
lines changed

docs/conf.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
sys.path.insert(0, os.path.abspath('..'))
1919
import maxminddb
2020

21-
2221
__version__ = maxminddb.__version__
2322

2423
# If extensions (or modules to document with autodoc) are in another directory,
@@ -33,8 +32,10 @@
3332

3433
# Add any Sphinx extension module names here, as strings. They can be extensions
3534
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
36-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest',
37-
'sphinx.ext.intersphinx', 'sphinx.ext.coverage']
35+
extensions = [
36+
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
37+
'sphinx.ext.coverage'
38+
]
3839

3940
# Add any paths that contain templates here, relative to this directory.
4041
templates_path = ['_templates']
@@ -95,7 +96,6 @@
9596
# A list of ignored prefixes for module index sorting.
9697
#modindex_common_prefix = []
9798

98-
9999
# -- Options for HTML output ---------------------------------------------
100100

101101
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -175,7 +175,6 @@
175175
# Output file base name for HTML help builder.
176176
htmlhelp_basename = 'maxminddbdoc'
177177

178-
179178
# -- Options for LaTeX output --------------------------------------------
180179

181180
latex_elements = {
@@ -192,8 +191,8 @@
192191
# Grouping the document tree into LaTeX files. List of tuples
193192
# (source start file, target name, title, author, documentclass [howto/manual]).
194193
latex_documents = [
195-
('index', 'maxminddb.tex', 'maxminddb Documentation',
196-
'Gregory Oschwald', 'manual'),
194+
('index', 'maxminddb.tex', 'maxminddb Documentation', 'Gregory Oschwald',
195+
'manual'),
197196
]
198197

199198
# The name of an image file (relative to this directory) to place at the top of
@@ -216,29 +215,24 @@
216215
# If false, no module index is generated.
217216
#latex_domain_indices = True
218217

219-
220218
# -- Options for manual page output --------------------------------------
221219

222220
# One entry per manual page. List of tuples
223221
# (source start file, name, description, authors, manual section).
224-
man_pages = [
225-
('index', 'maxminddb', 'maxminddb Documentation',
226-
['Gregory Oschwald'], 1)
227-
]
222+
man_pages = [('index', 'maxminddb', 'maxminddb Documentation',
223+
['Gregory Oschwald'], 1)]
228224

229225
# If true, show URL addresses after external links.
230226
#man_show_urls = False
231227

232-
233228
# -- Options for Texinfo output ------------------------------------------
234229

235230
# Grouping the document tree into Texinfo files. List of tuples
236231
# (source start file, target name, title, author,
237232
# dir menu entry, description, category)
238233
texinfo_documents = [
239-
('index', 'maxminddb', 'maxminddb Documentation',
240-
'Gregory Oschwald', 'maxminddb', 'MaxMind DB Reader',
241-
'Miscellaneous'),
234+
('index', 'maxminddb', 'maxminddb Documentation', 'Gregory Oschwald',
235+
'maxminddb', 'MaxMind DB Reader', 'Miscellaneous'),
242236
]
243237

244238
# Documents to append as an appendix to all manuals.
@@ -250,6 +244,5 @@
250244
# How to display URL addresses: 'footnote', 'no', or 'inline'.
251245
#texinfo_show_urls = 'footnote'
252246

253-
254247
# Example configuration for intersphinx: refer to the Python standard library.
255248
intersphinx_mapping = {'http://docs.python.org/': None}

examples/benchmark.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
import timeit
1212

1313
parser = argparse.ArgumentParser(description='Benchmark maxminddb.')
14-
parser.add_argument('--count', default=250000, type=int,
15-
help='number of lookups')
16-
parser.add_argument('--mode', default=0, type=int,
17-
help='reader mode to use')
18-
parser.add_argument('--file', default='GeoIP2-City.mmdb',
19-
help='path to mmdb file')
14+
parser.add_argument(
15+
'--count', default=250000, type=int, help='number of lookups')
16+
parser.add_argument('--mode', default=0, type=int, help='reader mode to use')
17+
parser.add_argument(
18+
'--file', default='GeoIP2-City.mmdb', help='path to mmdb file')
2019

2120
args = parser.parse_args()
2221

@@ -28,8 +27,9 @@ def lookup_ip_address():
2827
record = reader.get(str(ip))
2928

3029

31-
elapsed = timeit.timeit('lookup_ip_address()',
32-
setup='from __main__ import lookup_ip_address',
33-
number=args.count)
30+
elapsed = timeit.timeit(
31+
'lookup_ip_address()',
32+
setup='from __main__ import lookup_ip_address',
33+
number=args.count)
3434

3535
print(args.count / elapsed, 'lookups per second')

maxminddb/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ def open_database(database, mode=MODE_AUTO):
2727
* MODE_AUTO - tries MODE_MMAP_EXT, MODE_MMAP, MODE_FILE in that
2828
order. Default mode.
2929
"""
30-
has_extension = maxminddb.extension and hasattr(maxminddb.extension, 'Reader')
30+
has_extension = maxminddb.extension and hasattr(maxminddb.extension,
31+
'Reader')
3132
if (mode == MODE_AUTO and has_extension) or mode == MODE_MMAP_EXT:
3233
if not has_extension:
3334
raise ValueError(
34-
"MODE_MMAP_EXT requires the maxminddb.extension module to be available")
35+
"MODE_MMAP_EXT requires the maxminddb.extension module to be available"
36+
)
3537
return maxminddb.extension.Reader(database)
3638
elif mode in (MODE_AUTO, MODE_MMAP, MODE_FILE, MODE_MEMORY):
3739
return maxminddb.reader.Reader(database, mode)

maxminddb/decoder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ def _decode_utf8_string(self, size, offset):
105105
5: _decode_uint, # uint16
106106
6: _decode_uint, # uint32
107107
7: _decode_map,
108-
8: _decode_packed_type(
109-
b'!i', 4, pad=True), # int32
108+
8: _decode_packed_type(b'!i', 4, pad=True), # int32
110109
9: _decode_uint, # uint64
111110
10: _decode_uint, # uint128
112111
11: _decode_array,

maxminddb/reader.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,13 @@ def _read_node(self, node_number, index):
155155
else:
156156
middle = (0xF0 & middle) >> 4
157157
offset = base_offset + index * 4
158-
node_bytes = byte_from_int(middle) + self._buffer[offset:offset +
159-
3]
158+
node_bytes = byte_from_int(middle) + self._buffer[offset:offset + 3]
160159
elif record_size == 32:
161160
offset = base_offset + index * 4
162161
node_bytes = self._buffer[offset:offset + 4]
163162
else:
164-
raise InvalidDatabaseError('Unknown record size: {0}'.format(
165-
record_size))
163+
raise InvalidDatabaseError(
164+
'Unknown record size: {0}'.format(record_size))
166165
return struct.unpack(b'!I', node_bytes)[0]
167166

168167
def _resolve_data_pointer(self, pointer):

setup.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
JYTHON = sys.platform.startswith('java')
1717
requirements = []
1818

19-
if sys.version_info[0] == 2 or (sys.version_info[0] == 3 and
20-
sys.version_info[1] < 3):
19+
if sys.version_info[0] == 2 or (sys.version_info[0] == 3
20+
and sys.version_info[1] < 3):
2121
requirements.append('ipaddress')
2222

2323
compile_args = ['-Wall', '-Wextra']
@@ -30,7 +30,8 @@
3030
'maxminddb.extension',
3131
libraries=['maxminddb'],
3232
sources=['maxminddb/extension/maxminddb.c'],
33-
extra_compile_args=compile_args, )
33+
extra_compile_args=compile_args,
34+
)
3435
]
3536

3637
# Cargo cult code for installing extension with pure Python fallback.
@@ -95,8 +96,8 @@ def status_msgs(*msgs):
9596
def find_packages(location):
9697
packages = []
9798
for pkg in ['maxminddb']:
98-
for _dir, subdirectories, files in (
99-
os.walk(os.path.join(location, pkg))):
99+
for _dir, subdirectories, files in (os.walk(
100+
os.path.join(location, pkg))):
100101
if '__init__.py' in files:
101102
tokens = _dir.split(os.sep)[len(location.split(os.sep)):]
102103
packages.append(".".join(tokens))
@@ -108,7 +109,8 @@ def run_setup(with_cext):
108109
if with_cext:
109110
if Feature:
110111
kwargs['features'] = {
111-
'extension': Feature(
112+
'extension':
113+
Feature(
112114
"optional C implementation",
113115
standard=True,
114116
ext_modules=ext_module)

tests/decoder_test.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ def test_map(self):
9191
},
9292
(b'\xe1\x44\x6e\x61\x6d\x65\xe2\x42\x65\x6e'
9393
b'\x43\x46\x6f\x6f\x42\x7a\x68\x43\xe4\xba\xba'): {
94-
'name': {
95-
'en': 'Foo',
96-
'zh': '人'
97-
}
98-
},
94+
'name': {
95+
'en': 'Foo',
96+
'zh': '人'
97+
}
98+
},
9999
(b'\xe1\x49\x6c\x61\x6e\x67\x75\x61\x67\x65\x73'
100100
b'\x02\x04\x42\x65\x6e\x42\x7a\x68'): {
101-
'languages': ['en', 'zh']
102-
},
101+
'languages': ['en', 'zh']
102+
},
103103
}
104104
self.validate_type_decoding('maps', maps)
105105

@@ -120,37 +120,46 @@ def test_pointer(self):
120120
self.validate_type_decoding('pointers', pointers)
121121

122122
strings = {
123-
b"\x40": '',
124-
b"\x41\x31": '1',
125-
b"\x43\xE4\xBA\xBA": '人',
123+
b"\x40":
124+
'',
125+
b"\x41\x31":
126+
'1',
127+
b"\x43\xE4\xBA\xBA":
128+
'人',
126129
(b"\x5b\x31\x32\x33\x34"
127130
b"\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35"
128131
b"\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37"):
129132
'123456789012345678901234567',
130133
(b"\x5c\x31\x32\x33\x34"
131134
b"\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35"
132135
b"\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36"
133-
b"\x37\x38"): '1234567890123456789012345678',
136+
b"\x37\x38"):
137+
'1234567890123456789012345678',
134138
(b"\x5d\x00\x31\x32\x33"
135139
b"\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34"
136140
b"\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35"
137-
b"\x36\x37\x38\x39"): '12345678901234567890123456789',
141+
b"\x36\x37\x38\x39"):
142+
'12345678901234567890123456789',
138143
(b"\x5d\x01\x31\x32\x33"
139144
b"\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34"
140145
b"\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35"
141-
b"\x36\x37\x38\x39\x30"): '123456789012345678901234567890',
142-
b'\x5e\x00\xd7' + 500 * b'\x78': 'x' * 500,
143-
b'\x5e\x06\xb3' + 2000 * b'\x78': 'x' * 2000,
144-
b'\x5f\x00\x10\x53' + 70000 * b'\x78': 'x' * 70000,
146+
b"\x36\x37\x38\x39\x30"):
147+
'123456789012345678901234567890',
148+
b'\x5e\x00\xd7' + 500 * b'\x78':
149+
'x' * 500,
150+
b'\x5e\x06\xb3' + 2000 * b'\x78':
151+
'x' * 2000,
152+
b'\x5f\x00\x10\x53' + 70000 * b'\x78':
153+
'x' * 70000,
145154
}
146155

147156
def test_string(self):
148157
self.validate_type_decoding('string', self.strings)
149158

150159
def test_byte(self):
151160
# Python 2.6 doesn't support dictionary comprehension
152-
b = dict((byte_from_int(0xc0 ^ int_from_byte(k[0])) + k[1:],
153-
v.encode('utf-8')) for k, v in self.strings.items())
161+
b = dict((byte_from_int(0xc0 ^ int_from_byte(k[0])) + k[1:], v.encode(
162+
'utf-8')) for k, v in self.strings.items())
154163
self.validate_type_decoding('byte', b)
155164

156165
def test_uint16(self):
@@ -207,7 +216,8 @@ def check_decoding(self, type, input, expected, name=None):
207216
decoder = Decoder(db, pointer_test=True)
208217
(
209218
actual,
210-
_, ) = decoder.decode(0)
219+
_,
220+
) = decoder.decode(0)
211221

212222
if type in ('float', 'double'):
213223
self.assertAlmostEqual(expected, actual, places=3, msg=type)

tests/reader_test.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ def test_ipv6_address_in_ipv4_database(self):
9797
def test_no_extension_exception(self):
9898
real_extension = maxminddb.extension
9999
maxminddb.extension = None
100-
with self.assertRaisesRegex(ValueError, 'MODE_MMAP_EXT requires the maxminddb.extension module to be available'):
101-
open_database(
102-
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb', MODE_MMAP_EXT)
100+
with self.assertRaisesRegex(
101+
ValueError,
102+
'MODE_MMAP_EXT requires the maxminddb.extension module to be available'
103+
):
104+
open_database('tests/data/test-data/MaxMind-DB-test-decoder.mmdb',
105+
MODE_MMAP_EXT)
103106
maxminddb.extension = real_extension
104107

105108
def test_broken_database(self):
@@ -216,18 +219,17 @@ def use_with(reader):
216219
with reader:
217220
pass
218221

219-
self.assertRaisesRegex(ValueError, 'Attempt to reopen a closed MaxMind DB',
222+
self.assertRaisesRegex(ValueError,
223+
'Attempt to reopen a closed MaxMind DB',
220224
use_with, reader)
221225

222-
223226
def test_closed(self):
224227
reader = open_database(
225228
'tests/data/test-data/MaxMind-DB-test-decoder.mmdb', self.mode)
226229
self.assertEqual(reader.closed, False)
227230
reader.close()
228231
self.assertEqual(reader.closed, True)
229232

230-
231233
# XXX - Figure out whether we want to have the same behavior on both the
232234
# extension and the pure Python reader. If we do, the pure Python
233235
# reader will need to throw an exception or the extension will need
@@ -379,8 +381,8 @@ def has_maxminddb_extension():
379381
return maxminddb.extension and hasattr(maxminddb.extension, 'Reader')
380382

381383

382-
@unittest.skipIf(not has_maxminddb_extension() and
383-
not os.environ.get('MM_FORCE_EXT_TESTS'),
384+
@unittest.skipIf(not has_maxminddb_extension()
385+
and not os.environ.get('MM_FORCE_EXT_TESTS'),
384386
'No C extension module found. Skipping tests')
385387
class TestExtensionReader(BaseTestReader, unittest.TestCase):
386388
mode = MODE_MMAP_EXT

0 commit comments

Comments
 (0)