Skip to content

Commit

Permalink
Expose is_single_port and is_cidr properties in repr.
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Dec 16, 2016
1 parent 0c7596b commit b7d53ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ChangeLog
`1.1.0 (unreleased) <https://github.com/scaleway/port-range/compare/v1.0.5...develop>`_
---------------------------------------------------------------------------------------

* Expose ``is_single_port`` and ``is_cidr`` properties in ``repr()``.
* Add default ``isort`` config.
* Run unittests against Python 3.3, 3.5, 3.6-dev, 3.7-dev, PyPy2.7 and PyPy3.3.
* Remove popularity badge: PyPI download counters are broken and no longer
Expand Down
10 changes: 6 additions & 4 deletions port_range/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ def parse_range(self, port_range):

def __repr__(self):
""" Print all components of the range. """
return '{}(port_from={}, port_to={}, base={}, offset={}, prefix={}, ' \
'mask={})'.format(self.__class__.__name__, self.port_from,
self.port_to, self.base, self.offset,
self.prefix, self.mask)
return (
'{}(port_from={}, port_to={}, base={}, offset={}, prefix={}, '
'mask={}, is_single_port={}, is_cidr={})').format(
self.__class__.__name__, self.port_from, self.port_to,
self.base, self.offset, self.prefix, self.mask,
self.is_single_port, self.is_cidr)

def __str__(self):
""" Return the most appropriate string representation. """
Expand Down
2 changes: 1 addition & 1 deletion port_range/tests/test_port_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_output_string(self):
self.assertEqual(
repr(PortRange([1027, 1028])),
"PortRange(port_from=1027, port_to=1028, base=1027, offset=3, "
"prefix=15, mask=1)")
"prefix=15, mask=1, is_single_port=False, is_cidr=True)")

def test_cidr_string_rendering(self):
self.assertEqual(PortRange([32768, 65535]).cidr_string, '32768/1')
Expand Down

0 comments on commit b7d53ee

Please sign in to comment.