Split out encoding/formatting unhandler error to method, for overridability
This commit is contained in:
parent
602dea1ac6
commit
8c4fedac0a
|
@ -202,8 +202,12 @@ class Encoder(BinaryCodec):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
i = None
|
i = None
|
||||||
if i is None:
|
if i is None:
|
||||||
raise TypeError('Cannot preserves-encode: ' + repr(v))
|
self.cannot_encode(v)
|
||||||
self.encodevalues(5, i)
|
else:
|
||||||
|
self.encodevalues(5, i)
|
||||||
|
|
||||||
|
def cannot_encode(self, v):
|
||||||
|
raise TypeError('Cannot preserves-encode: ' + repr(v))
|
||||||
|
|
||||||
def encode(v, **kwargs):
|
def encode(v, **kwargs):
|
||||||
e = Encoder(**kwargs)
|
e = Encoder(**kwargs)
|
||||||
|
|
|
@ -391,8 +391,12 @@ class Formatter(TextCodec):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
i = None
|
i = None
|
||||||
if i is None:
|
if i is None:
|
||||||
raise TypeError('Cannot preserves-format: ' + repr(v))
|
self.cannot_format(v)
|
||||||
self.write_seq('[', ']', i)
|
else:
|
||||||
|
self.write_seq('[', ']', i)
|
||||||
|
|
||||||
|
def cannot_format(self, v):
|
||||||
|
raise TypeError('Cannot preserves-format: ' + repr(v))
|
||||||
|
|
||||||
def stringify(v, **kwargs):
|
def stringify(v, **kwargs):
|
||||||
e = Formatter(**kwargs)
|
e = Formatter(**kwargs)
|
||||||
|
|
Loading…
Reference in New Issue