forked from rthalley/dnspython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds the NID, L32, L64, and LP types.
- Loading branch information
Showing
13 changed files
with
278 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license | ||
|
||
import struct | ||
|
||
import dns.immutable | ||
|
||
|
||
@dns.immutable.immutable | ||
class L32(dns.rdata.Rdata): | ||
|
||
"""L32 record""" | ||
|
||
# see: rfc6742.txt | ||
|
||
__slots__ = ['preference', 'locator32'] | ||
|
||
def __init__(self, rdclass, rdtype, preference, locator32): | ||
super().__init__(rdclass, rdtype) | ||
self.preference = self._as_uint16(preference) | ||
self.locator32 = self._as_ipv4_address(locator32) | ||
|
||
def to_text(self, origin=None, relativize=True, **kw): | ||
return f'{self.preference} {self.locator32}' | ||
|
||
@classmethod | ||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True, | ||
relativize_to=None): | ||
preference = tok.get_uint16() | ||
nodeid = tok.get_identifier() | ||
return cls(rdclass, rdtype, preference, nodeid) | ||
|
||
def _to_wire(self, file, compress=None, origin=None, canonicalize=False): | ||
file.write(struct.pack('!H', self.preference)) | ||
file.write(dns.ipv4.inet_aton(self.locator32)) | ||
|
||
@classmethod | ||
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None): | ||
preference = parser.get_uint16() | ||
locator32 = parser.get_remaining() | ||
return cls(rdclass, rdtype, preference, locator32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license | ||
|
||
import struct | ||
|
||
import dns.immutable | ||
import dns.rdtypes.util | ||
|
||
|
||
@dns.immutable.immutable | ||
class L64(dns.rdata.Rdata): | ||
|
||
"""L64 record""" | ||
|
||
# see: rfc6742.txt | ||
|
||
__slots__ = ['preference', 'locator64'] | ||
|
||
def __init__(self, rdclass, rdtype, preference, locator64): | ||
super().__init__(rdclass, rdtype) | ||
self.preference = self._as_uint16(preference) | ||
if isinstance(locator64, bytes): | ||
if len(locator64) != 8: | ||
raise ValueError('invalid locator64') | ||
self.locator64 = dns.rdata._hexify(locator64, 4, b':') | ||
else: | ||
dns.rdtypes.util.parse_formatted_hex(locator64, 4, 4, ':') | ||
self.locator64 = locator64 | ||
|
||
def to_text(self, origin=None, relativize=True, **kw): | ||
return f'{self.preference} {self.locator64}' | ||
|
||
@classmethod | ||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True, | ||
relativize_to=None): | ||
preference = tok.get_uint16() | ||
locator64 = tok.get_identifier() | ||
return cls(rdclass, rdtype, preference, locator64) | ||
|
||
def _to_wire(self, file, compress=None, origin=None, canonicalize=False): | ||
file.write(struct.pack('!H', self.preference)) | ||
file.write(dns.rdtypes.util.parse_formatted_hex(self.locator64, | ||
4, 4, ':')) | ||
|
||
@classmethod | ||
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None): | ||
preference = parser.get_uint16() | ||
locator64 = parser.get_remaining() | ||
return cls(rdclass, rdtype, preference, locator64) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license | ||
|
||
import struct | ||
|
||
import dns.immutable | ||
|
||
|
||
@dns.immutable.immutable | ||
class LP(dns.rdata.Rdata): | ||
|
||
"""LP record""" | ||
|
||
# see: rfc6742.txt | ||
|
||
__slots__ = ['preference', 'fqdn'] | ||
|
||
def __init__(self, rdclass, rdtype, preference, fqdn): | ||
super().__init__(rdclass, rdtype) | ||
self.preference = self._as_uint16(preference) | ||
self.fqdn = self._as_name(fqdn) | ||
|
||
def to_text(self, origin=None, relativize=True, **kw): | ||
fqdn = self.fqdn.choose_relativity(origin, relativize) | ||
return '%d %s' % (self.preference, fqdn) | ||
|
||
@classmethod | ||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True, | ||
relativize_to=None): | ||
preference = tok.get_uint16() | ||
fqdn = tok.get_name(origin, relativize, relativize_to) | ||
return cls(rdclass, rdtype, preference, fqdn) | ||
|
||
def _to_wire(self, file, compress=None, origin=None, canonicalize=False): | ||
file.write(struct.pack('!H', self.preference)) | ||
self.fqdn.to_wire(file, compress, origin, canonicalize) | ||
|
||
@classmethod | ||
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None): | ||
preference = parser.get_uint16() | ||
fqdn = parser.get_name(origin) | ||
return cls(rdclass, rdtype, preference, fqdn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license | ||
|
||
import struct | ||
|
||
import dns.immutable | ||
import dns.rdtypes.util | ||
|
||
|
||
@dns.immutable.immutable | ||
class NID(dns.rdata.Rdata): | ||
|
||
"""NID record""" | ||
|
||
# see: rfc6742.txt | ||
|
||
__slots__ = ['preference', 'nodeid'] | ||
|
||
def __init__(self, rdclass, rdtype, preference, nodeid): | ||
super().__init__(rdclass, rdtype) | ||
self.preference = self._as_uint16(preference) | ||
if isinstance(nodeid, bytes): | ||
if len(nodeid) != 8: | ||
raise ValueError('invalid nodeid') | ||
self.nodeid = dns.rdata._hexify(nodeid, 4, b':') | ||
else: | ||
dns.rdtypes.util.parse_formatted_hex(nodeid, 4, 4, ':') | ||
self.nodeid = nodeid | ||
|
||
def to_text(self, origin=None, relativize=True, **kw): | ||
return f'{self.preference} {self.nodeid}' | ||
|
||
@classmethod | ||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True, | ||
relativize_to=None): | ||
preference = tok.get_uint16() | ||
nodeid = tok.get_identifier() | ||
return cls(rdclass, rdtype, preference, nodeid) | ||
|
||
def _to_wire(self, file, compress=None, origin=None, canonicalize=False): | ||
file.write(struct.pack('!H', self.preference)) | ||
file.write(dns.rdtypes.util.parse_formatted_hex(self.nodeid, 4, 4, ':')) | ||
|
||
@classmethod | ||
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None): | ||
preference = parser.get_uint16() | ||
nodeid = parser.get_remaining() | ||
return cls(rdclass, rdtype, preference, nodeid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.