Dolda2000 GitWeb
/
coe.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
82855e2
)
bin: Make decoder type creation overridable.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Tue, 11 Jan 2022 18:29:25 +0000
(19:29 +0100)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Tue, 11 Jan 2022 18:29:25 +0000
(19:29 +0100)
coe/bin.py
patch
|
blob
|
blame
|
history
diff --git
a/coe/bin.py
b/coe/bin.py
index
0aa6e5a
..
395a209
100644
(file)
--- a/
coe/bin.py
+++ b/
coe/bin.py
@@
-153,7
+153,10
@@
class referror(fmterror):
super().__init__("bad backref")
class namedtype(type):
super().__init__("bad backref")
class namedtype(type):
- pass
+ def __new__(cls, *args, typename=None, **kwargs):
+ self = super().__new__(cls, *args, **kwargs)
+ self.typename = typename
+ return self
class decoder(object):
def __init__(self):
class decoder(object):
def __init__(self):
@@
-225,6
+228,9
@@
class decoder(object):
return buf
buf[key] = self.loadtagged(fp, tag)
return buf
buf[key] = self.loadtagged(fp, tag)
+ def makeobjtype(self, nm):
+ return namedtype(str(nm), (data.obj, object), {}, typename=nm)
+
def loadobj(self, fp, ref=False):
if ref:
refid = len(self.reftab)
def loadobj(self, fp, ref=False):
if ref:
refid = len(self.reftab)
@@
-232,8
+238,7
@@
class decoder(object):
nm = self.load(fp)
typ = self.namedtypes.get(nm)
if typ is None:
nm = self.load(fp)
typ = self.namedtypes.get(nm)
if typ is None:
- typ = self.namedtypes[nm] = namedtype(str(nm), (data.obj, object), {})
- typ.typename = nm
+ typ = self.namedtypes[nm] = self.makeobjtype(nm)
ret = typ()
if ref:
self.reftab[refid] = ret
ret = typ()
if ref:
self.reftab[refid] = ret