Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(168201)

Delta Between Two Patch Sets: Lib/ipaddress.py

Issue 20480: Add ipaddress property to get reverse DNS name
Left Patch Set: Created 5 years, 10 months ago
Right Patch Set: Created 5 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/library/ipaddress.rst ('k') | Lib/test/test_ipaddress.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # Copyright 2007 Google Inc. 1 # Copyright 2007 Google Inc.
2 # Licensed to PSF under a Contributor Agreement. 2 # Licensed to PSF under a Contributor Agreement.
3 3
4 """A fast, lightweight IPv4/IPv6 manipulation library in Python. 4 """A fast, lightweight IPv4/IPv6 manipulation library in Python.
5 5
6 This library is used to create/poke/manipulate IPv4 and IPv6 addresses 6 This library is used to create/poke/manipulate IPv4 and IPv6 addresses
7 and networks. 7 and networks.
8 8
9 """ 9 """
10 10
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 432
433 @property 433 @property
434 def compressed(self): 434 def compressed(self):
435 """Return the shorthand version of the IP address as a string.""" 435 """Return the shorthand version of the IP address as a string."""
436 return str(self) 436 return str(self)
437 437
438 @property 438 @property
439 def reverse_pointer(self): 439 def reverse_pointer(self):
440 """The name of the reverse DNS pointer for the IP address, e.g.: 440 """The name of the reverse DNS pointer for the IP address, e.g.:
441 >>> ipaddress.ip_address("127.0.0.1").reverse_pointer 441 >>> ipaddress.ip_address("127.0.0.1").reverse_pointer
442 '1.0.0.127.in-addr.arpa.' 442 '1.0.0.127.in-addr.arpa'
443 >>> ipaddress.ip_address("2001:db8::1").reverse_pointer 443 >>> ipaddress.ip_address("2001:db8::1").reverse_pointer
444 '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6 .arpa.' 444 '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6 .arpa'
445 445
446 """ 446 """
447 return self._reverse_pointer() 447 return self._reverse_pointer()
448 448
449 @property 449 @property
450 def version(self): 450 def version(self):
451 msg = '%200s has no version specified' % (type(self),) 451 msg = '%200s has no version specified' % (type(self),)
452 raise NotImplementedError(msg) 452 raise NotImplementedError(msg)
453 453
454 def _check_int_address(self, address): 454 def _check_int_address(self, address):
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 if parts[0] < parts[-1]: 1176 if parts[0] < parts[-1]:
1177 return True 1177 return True
1178 return False 1178 return False
1179 1179
1180 def _reverse_pointer(self): 1180 def _reverse_pointer(self):
1181 """Return the reverse DNS pointer name for the IPv4 address. 1181 """Return the reverse DNS pointer name for the IPv4 address.
1182 1182
1183 This implements the method described in RFC1035 3.5. 1183 This implements the method described in RFC1035 3.5.
1184 1184
1185 """ 1185 """
1186 rev_octets = str(self).split('.')[::-1] 1186 reverse_octets = str(self).split('.')[::-1]
1187 return '.'.join(rev_octets) + '.in-addr.arpa.' 1187 return '.'.join(reverse_octets) + '.in-addr.arpa'
1188 1188
1189 @property 1189 @property
1190 def max_prefixlen(self): 1190 def max_prefixlen(self):
1191 return self._max_prefixlen 1191 return self._max_prefixlen
1192 1192
1193 @property 1193 @property
1194 def version(self): 1194 def version(self):
1195 return self._version 1195 return self._version
1196 1196
1197 1197
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 return '%s/%d' % (':'.join(parts), self._prefixlen) 1766 return '%s/%d' % (':'.join(parts), self._prefixlen)
1767 return ':'.join(parts) 1767 return ':'.join(parts)
1768 1768
1769 def _reverse_pointer(self): 1769 def _reverse_pointer(self):
1770 """Return the reverse DNS pointer name for the IPv6 address. 1770 """Return the reverse DNS pointer name for the IPv6 address.
1771 1771
1772 This implements the method described in RFC3596 2.5. 1772 This implements the method described in RFC3596 2.5.
1773 1773
1774 """ 1774 """
1775 reverse_chars = self.exploded[::-1].replace(':', '') 1775 reverse_chars = self.exploded[::-1].replace(':', '')
1776 return '.'.join(reverse_chars) + '.ip6.arpa.' 1776 return '.'.join(reverse_chars) + '.ip6.arpa'
1777 1777
1778 @property 1778 @property
1779 def max_prefixlen(self): 1779 def max_prefixlen(self):
1780 return self._max_prefixlen 1780 return self._max_prefixlen
1781 1781
1782 @property 1782 @property
1783 def version(self): 1783 def version(self):
1784 return self._version 1784 return self._version
1785 1785
1786 1786
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2173 Note that the site-local address space has been deprecated by RFC 3879. 2173 Note that the site-local address space has been deprecated by RFC 3879.
2174 Use is_private to test if this address is in the space of unique local 2174 Use is_private to test if this address is in the space of unique local
2175 addresses as defined by RFC 4193. 2175 addresses as defined by RFC 4193.
2176 2176
2177 Returns: 2177 Returns:
2178 A boolean, True if the address is reserved per RFC 3513 2.5.6. 2178 A boolean, True if the address is reserved per RFC 3513 2.5.6.
2179 2179
2180 """ 2180 """
2181 return (self.network_address.is_site_local and 2181 return (self.network_address.is_site_local and
2182 self.broadcast_address.is_site_local) 2182 self.broadcast_address.is_site_local)
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+