Skip to content

Commit 0784873

Browse files
committed
Provide __repr__ for the Metadata class
1 parent d3a3425 commit 0784873

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

HISTORY.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ History
66
1.2.0 (2015-04-XX)
77
++++++++++++++++++
88

9+
* The ``Metadata`` class now overloads ``__repr__`` to provide a useful
10+
representation of the contents when debugging.
911
* An ``InvalidDatabaseError`` will now be thrown if the data type read from
1012
the database is invalid. Previously a ``KeyError`` was thrown.
1113

maxminddb/reader.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def __init__(self, database, mode=MODE_AUTO):
7676
metadata_start += len(self._METADATA_START_MARKER)
7777
metadata_decoder = Decoder(self._buffer, metadata_start)
7878
(metadata, _) = metadata_decoder.decode(metadata_start)
79-
self._metadata = Metadata(**metadata) # pylint: disable=star-args
79+
self._metadata = Metadata(
80+
**metadata) # pylint: disable=bad-option-value
8081

8182
self._decoder = Decoder(self._buffer, self._metadata.search_tree_size
8283
+ self._DATA_SECTION_SEPARATOR_SIZE)
@@ -176,6 +177,7 @@ def _resolve_data_pointer(self, pointer):
176177

177178
def close(self):
178179
"""Closes the MaxMind DB file and returns the resources to the system"""
180+
# pylint: disable=unidiomatic-typecheck
179181
if type(self._buffer) not in (str, bytes):
180182
self._buffer.close()
181183

@@ -210,3 +212,10 @@ def node_byte_size(self):
210212
def search_tree_size(self):
211213
"""The size of the search tree"""
212214
return self.node_count * self.node_byte_size
215+
216+
def __repr__(self):
217+
args = ', '.join('%s=%r' % x for x in self.__dict__.items())
218+
return '{module}.{class_name}({data})'.format(
219+
module=self.__module__,
220+
class_name=self.__class__.__name__,
221+
data=args)

0 commit comments

Comments
 (0)