diff options
| author | Bob Halley <halley@dnspython.org> | 2005-10-06 06:25:52 +0000 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2005-10-06 06:25:52 +0000 |
| commit | 7abb1f23f3c44901c0bcc4aa183c30548e6a1786 (patch) | |
| tree | 6e877bc759ab7663ffd0611cf1eec40a48917891 /dns/name.py | |
| parent | 2cf8da1e004f17dca34c6f4eee12a59ab55b37d9 (diff) | |
| download | dnspython-7abb1f23f3c44901c0bcc4aa183c30548e6a1786.tar.gz | |
add dns.name.Name.parent()
Diffstat (limited to 'dns/name.py')
| -rw-r--r-- | dns/name.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/dns/name.py b/dns/name.py index 3bf5b6e..c5e4b9a 100644 --- a/dns/name.py +++ b/dns/name.py @@ -69,6 +69,11 @@ class AbsoluteConcatenation(dns.exception.DNSException): empty name to an absolute name.""" pass +class NoParent(dns.exception.DNSException): + """Raised if an attempt is made to get the parent of the root name + or the empty name.""" + pass + _escaped = { '"' : True, '(' : True, @@ -490,6 +495,16 @@ class Name(object): return self.derelativize(origin) else: return self + + def parent(self): + """Return the parent of the name. + @rtype: dns.name.Name object + @raises NoParent: the name is either the root name or the empty name, + and thus has no parent. + """ + if self == root or self == empty: + raise NoParent + return Name(self.labels[1:]) root = Name(['']) empty = Name([]) |
