3 isafe = set("abcdefghijklmnopqrstuvwxyz" +
4 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
6 qsafe = isafe | set("0123456789-+")
9 if not isinstance(o, symbol):
11 return (s.name == o.name) and (s.ns == o.ns)
14 return (hash(self.ns) * 31) + hash(self.name)
17 ns, nm = ("", o) if isinstance(o, str) else (s.ns, s.name)
18 return s.ns < ns or s.name < nm
20 ns, nm = ("", o) if isinstance(o, str) else (s.ns, s.name)
21 return s.ns > ns or s.name > nm
43 return nssymbol(ns, name)
47 return self.quote(self.name)
48 return "%s:%s" % (self.quote(self.ns), self.quote(self.name))
50 class usymbol(symbol):
54 def __init__(self, name):
57 class nssymbol(symbol):
58 __slots__ = ["ns", "name"]
60 def __init__(self, ns, name, *args, **kw):
61 super().__init__(*args, **kw)
65 class namedtype(type):
66 def __new__(cls, *args, typename=None, **kwargs):
67 self = super().__new__(cls, *args, **kwargs)
68 self.typename = typename
72 def make(cls, *args, typename=None, **kwargs):
73 self = cls(*args, **kwargs)
74 self.typename = typename
78 def __getitem__(self, key):
79 return self.__dict__[key]
80 def __setitem__(self, key, val):
81 self.__dict__[key] = val
82 def __delitem__(self, key):
83 del self.__dict__[key]
84 def __getattr__(self, name):
86 return self.__dict__[symbol.get("", name)]
88 raise AttributeError(name) from None