def parse_simple(self): self.eat_whitespace() c = chr(self.peek) if c == u('('): self.next() tree = self.parse_tree() self.eat_whitespace() self.eat(')') return tree if c == u('/'): return NameTree.Leaf(self.parse_path()) if c == u('!'): self.next() return NameTree.Fail if c == u('~'): self.next() return NameTree.Neg if c == u('$'): self.next() return NameTree.Empty self.illegal("simple", c)
def eat_whitespace(self): while not self.at_end and (self.ord in WHITESPACE or self.chr == u("#")): if self.chr == u("#"): self.eat_line() else: self.next()
def __init__(self, str_input): # avoiding circular dependencies from dtab.dtab import Dentry, Dtab self._dentry_cls = Dentry self._dtab_cls = Dtab self._str_input = u(str_input) self._index = 0
def parse_number(self): result = "" seendot = False while self.is_number_char(self.peek): if self.peek == ord('.'): seendot = True if not seendot else self.illegal("number char", self.peek) result += chr(self.peek) self.next() if len(result) == 1 and result[0] == u('.'): self.illegal("weight", '.') return float(result)
def parse_number(self): result = "" seendot = False while self.is_number_char(self.peek): if self.peek == ord('.'): seendot = True if not seendot else self.illegal( "number char", self.peek) result += chr(self.peek) self.next() if len(result) == 1 and result[0] == u('.'): self.illegal("weight", '.') return float(result)
def parse_label(self): bio = BytesIO() while True: c = self.peek if Path.is_showable(c): self.next() bio.write(chr(c)) elif c == FORWARD_SLASH: self.next() self.eat(u('x')) fst = self.parse_hex_char() snd = self.parse_hex_char() bio.write(chr(int(fst, 16) << 4 | int(snd, 16))) else: self.illegal("label char", c) if not self.is_label_char(self.peek): break return bio.getvalue().decode('utf-8')
def parse_label(self): bio = BytesIO() while True: c = self.peek if Path.is_showable(c): self.next() bio.write(bytes(c)) elif c == FORWARD_SLASH: self.next() self.eat(u('x')) fst = self.parse_hex_char() snd = self.parse_hex_char() bio.write(chr(int(fst, 16) << 4 | int(snd, 16))) else: self.illegal("label char", c) if not self.is_label_char(self.peek): break return bio.getvalue().decode('utf-8')
def Utf8(cls, *elems): return cls(*[u(elem) for elem in elems])
def is_number_char(self, char): char = chr(char) return char.isdigit() or char == u('.')
def eat_line(self): while (not self.at_end and self.chr != u("\n")): self.next() if not self.at_end: self.eat("\n")