:rtype: :py:class:`dns.name.Name`
"""
- parts = [d for d in text if d.isdigit()]
+ parts = [d for d in text if d.isdecimal()]
parts.reverse()
return dns.name.from_text(".".join(parts), origin=origin)
if value:
return value
prefix = cls._prefix()
- if text.startswith(prefix) and text[len(prefix) :].isdigit():
+ if text.startswith(prefix) and text[len(prefix) :].isdecimal():
value = int(text[len(prefix) :])
cls._check_value(value)
return cls(value)
tokens = text.split()
for t in tokens:
token = t.upper()
- if token.startswith("FLAG") and token[4:].isdigit():
+ if token.startswith("FLAG") and token[4:].isdecimal():
# An unnamed flag, rendered by _to_text() as FLAGn (see below).
flags |= 1 << int(token[4:])
else:
stop = int(cur)
cur = ""
state = 2
- elif c.isdigit():
+ elif c.isdecimal():
cur += c
else:
raise dns.exception.SyntaxError(f"Could not parse {c}")
# try to avoid getaddrinfo()
addrpart = address[:i]
scope = address[i + 1 :]
- if scope.isdigit():
+ if scope.isdecimal():
return (addrpart, port, 0, int(scope))
try:
return (addrpart, port, 0, socket.if_nametoindex(scope))
for c in text:
if escaping:
if edigits == 0:
- if c.isdigit():
+ if c.isdecimal():
total = int(c)
edigits += 1
else:
label += c
escaping = False
else:
- if not c.isdigit():
+ if not c.isdecimal():
raise BadEscape
total *= 10
total += int(c)
raise dns.exception.FormError
if left == b"" and right == b"":
raise dns.exception.FormError
- if not left == b"" and not left.decode().isdigit():
+ if not left == b"" and not left.isdigit():
raise dns.exception.FormError
- if not right == b"" and not right.decode().isdigit():
+ if not right == b"" and not right.isdigit():
raise dns.exception.FormError
latitude[0] = tok.get_int()
t = tok.get_string()
- if t.isdigit():
+ if t.isdecimal():
latitude[1] = int(t)
t = tok.get_string()
if "." in t:
seconds, milliseconds = t.split(".")
- if not seconds.isdigit():
+ if not seconds.isdecimal():
raise dns.exception.SyntaxError("bad latitude seconds value")
latitude[2] = int(seconds)
l = len(milliseconds)
- if l == 0 or l > 3 or not milliseconds.isdigit():
+ if l == 0 or l > 3 or not milliseconds.isdecimal():
raise dns.exception.SyntaxError("bad latitude milliseconds value")
if l == 1:
m = 100
m = 1
latitude[3] = m * int(milliseconds)
t = tok.get_string()
- elif t.isdigit():
+ elif t.isdecimal():
latitude[2] = int(t)
t = tok.get_string()
if t == "S":
longitude[0] = tok.get_int()
t = tok.get_string()
- if t.isdigit():
+ if t.isdecimal():
longitude[1] = int(t)
t = tok.get_string()
if "." in t:
seconds, milliseconds = t.split(".")
- if not seconds.isdigit():
+ if not seconds.isdecimal():
raise dns.exception.SyntaxError("bad longitude seconds value")
longitude[2] = int(seconds)
l = len(milliseconds)
- if l == 0 or l > 3 or not milliseconds.isdigit():
+ if l == 0 or l > 3 or not milliseconds.isdecimal():
raise dns.exception.SyntaxError("bad longitude milliseconds value")
if l == 1:
m = 100
m = 1
longitude[3] = m * int(milliseconds)
t = tok.get_string()
- elif t.isdigit():
+ elif t.isdecimal():
longitude[2] = int(t)
t = tok.get_string()
if t == "W":
):
address = tok.get_string()
protocol = tok.get_string()
- if protocol.isdigit():
+ if protocol.isdecimal():
protocol = int(protocol)
else:
protocol = socket.getprotobyname(protocol)
bitmap = bytearray()
for token in tok.get_remaining():
value = token.unescape().value
- if value.isdigit():
+ if value.isdecimal():
serv = int(value)
else:
if protocol != _proto_udp and protocol != _proto_tcp:
def sigtime_to_posixtime(what):
- if len(what) <= 10 and what.isdigit():
+ if len(what) <= 10 and what.isdecimal():
return int(what)
if len(what) != 14:
raise BadSigTime
raise dns.exception.UnexpectedEnd
c = value[i]
i += 1
- if c.isdigit():
+ if c.isdecimal():
if i >= l:
raise dns.exception.UnexpectedEnd
c2 = value[i]
raise dns.exception.UnexpectedEnd
c3 = value[i]
i += 1
- if not (c2.isdigit() and c3.isdigit()):
+ if not (c2.isdecimal() and c3.isdecimal()):
raise dns.exception.SyntaxError
codepoint = int(c) * 100 + int(c2) * 10 + int(c3)
if codepoint > 255:
raise dns.exception.UnexpectedEnd
c = self.value[i]
i += 1
- if c.isdigit():
+ if c.isdecimal():
if i >= l:
raise dns.exception.UnexpectedEnd
c2 = self.value[i]
raise dns.exception.UnexpectedEnd
c3 = self.value[i]
i += 1
- if not (c2.isdigit() and c3.isdigit()):
+ if not (c2.isdecimal() and c3.isdecimal()):
raise dns.exception.SyntaxError
codepoint = int(c) * 100 + int(c2) * 10 + int(c3)
if codepoint > 255:
raise dns.exception.UnexpectedEnd
c = self.value[i]
i += 1
- if c.isdigit():
+ if c.isdecimal():
if i >= l:
raise dns.exception.UnexpectedEnd
c2 = self.value[i]
raise dns.exception.UnexpectedEnd
c3 = self.value[i]
i += 1
- if not (c2.isdigit() and c3.isdigit()):
+ if not (c2.isdecimal() and c3.isdecimal()):
raise dns.exception.SyntaxError
codepoint = int(c) * 100 + int(c2) * 10 + int(c3)
if codepoint > 255:
if not token.is_identifier():
raise dns.exception.SyntaxError("expecting an identifier")
- if not token.value.isdigit():
+ try:
+ value = int(token.value, base)
+ if value < 0:
+ raise ValueError
+ except ValueError:
raise dns.exception.SyntaxError("expecting an integer")
- return int(token.value, base)
+ return value
def as_uint8(self, token: Token) -> int:
"""Try to interpret the token as an unsigned 8-bit integer.
with self.assertRaises(dns.exception.SyntaxError):
tok = dns.tokenizer.Tokenizer("200000")
tok.get_uint16(base=8)
+ tok = dns.tokenizer.Tokenizer("ff")
+ v = tok.get_int(16)
+ self.assertEqual(v, 255)
def testGetString(self):
tok = dns.tokenizer.Tokenizer("foo")