From ea4353090af100d1bb9cfcd44e2fa428c18b4945 Mon Sep 17 00:00:00 2001 From: Korbinian Preisler Date: Fri, 2 Dec 2011 07:29:54 +0100 Subject: [PATCH] User buffer for binary fields issue2316 review192001 --- proteus/__init__.py | 10 +++++++++- proteus/config.py | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/proteus/__init__.py b/proteus/__init__.py index de24c50c3e..f660f71f2d 100644 --- a/proteus/__init__.py +++ b/proteus/__init__.py @@ -92,6 +92,14 @@ class CharDescriptor(FieldDescriptor): super(CharDescriptor, self).__set__(instance, value or '') +class BinaryDescriptor(FieldDescriptor): + default = None + + def __set__(self, instance, value): + assert isinstance(value, (basestring, buffer)) or value in (None, False) + super(BinaryDescriptor, self).__set__(instance, value or '') + + class IntegerDescriptor(FieldDescriptor): default = 0 @@ -296,7 +304,7 @@ class MetaModelFactory(object): 'char': CharDescriptor, 'text': CharDescriptor, 'sha': CharDescriptor, - 'binary': CharDescriptor, + 'binary': BinaryDescriptor, 'selection': CharDescriptor, # TODO implement its own descriptor 'integer': IntegerDescriptor, 'biginteger': IntegerDescriptor, diff --git a/proteus/config.py b/proteus/config.py index 012cf096cd..d2531c1764 100644 --- a/proteus/config.py +++ b/proteus/config.py @@ -17,10 +17,17 @@ def dump_decimal(self, value, write): write(str(value)) write("\n") +def dump_buffer(self, value, write): + self.write = write + value = xmlrpclib.Binary(value) + value.encode(self) + del self.write + xmlrpclib.Marshaller.dispatch[Decimal] = dump_decimal xmlrpclib.Marshaller.dispatch[datetime.date] = \ lambda self, value, write: self.dump_datetime( datetime.datetime.combine(value, datetime.time()), write) +xmlrpclib.Marshaller.dispatch[buffer] = dump_buffer def _end_double(self, data):