Skip to content

Commit 37297fc

Browse files
committed
move FileData to spyne.model.relational
also make its "hidden" fields (those that don't get written to the database) explicit fix its serialization to bytes
1 parent 876a02c commit 37297fc

File tree

3 files changed

+61
-16
lines changed

3 files changed

+61
-16
lines changed

spyne/model/relational.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
#
3+
# spyne - Copyright (C) Spyne contributors.
4+
#
5+
# This library is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU Lesser General Public
7+
# License as published by the Free Software Foundation; either
8+
# version 2.1 of the License, or (at your option) any later version.
9+
#
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public
16+
# License along with this library; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18+
#
19+
20+
from spyne.model.complex import ComplexModel
21+
from spyne.model.primitive import Unicode
22+
23+
24+
class FileData(ComplexModel):
25+
_type_info = [
26+
('name', Unicode),
27+
('type', Unicode),
28+
('path', Unicode),
29+
]
30+
31+
@property
32+
def data(self):
33+
return self._data
34+
35+
@data.setter
36+
def data(self, data):
37+
self._data = data
38+
39+
@property
40+
def handle(self):
41+
return self._handle
42+
43+
@handle.setter
44+
def handle(self, handle):
45+
self._handle = handle
46+

spyne/protocol/_outbase.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
ByteArray, File, ComplexModelBase, AnyXml, AnyHtml, Unicode, Decimal, \
4646
Double, Integer, Time, DateTime, Uuid, Duration, Boolean, AnyDict, \
4747
AnyUri, PushBase, Date
48+
from spyne.model.relational import FileData
49+
4850
from spyne.const.http import HTTP_400, HTTP_401, HTTP_404, HTTP_405, HTTP_413, \
4951
HTTP_500
5052
from spyne.error import Fault, InternalError, ResourceNotFoundError, \
@@ -547,8 +549,13 @@ def file_to_bytes(self, cls, value, suggested_encoding=None):
547549

548550
assert False, "Unhandled file type"
549551

550-
if value is None:
551-
return b''
552+
if isinstance(value, FileData):
553+
try:
554+
return binary_encoding_handlers[encoding](value.data)
555+
except Exception as e:
556+
logger.error("Error encoding value to binary. Error: %r, Value: %r",
557+
e, value)
558+
raise
552559

553560
try:
554561
return binary_encoding_handlers[encoding](value)

spyne/store/relational/document.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,14 @@ def get_xml_as_object(*_, **__):
4848

4949
from sqlalchemy.sql.type_api import UserDefinedType
5050

51-
from spyne import ComplexModel, ValidationError, Unicode
51+
from spyne import ValidationError
52+
from spyne.model.relational import FileData
5253

5354
from spyne.util import six
5455
from spyne.util.six import binary_type, text_type, BytesIO, StringIO
5556
from spyne.util.fileproxy import SeekableFileProxy
5657

5758

58-
class FileData(ComplexModel):
59-
_type_info = [
60-
('name', Unicode),
61-
('type', Unicode),
62-
('path', Unicode),
63-
]
64-
65-
6659
class PGXml(UserDefinedType):
6760
def __init__(self, pretty_print=False, xml_declaration=False,
6861
encoding='UTF-8'):
@@ -311,12 +304,11 @@ def process(value):
311304
value.store = self.store
312305
value.abspath = join(self.store, value.path)
313306

314-
retval = self.get_object_as_json(value, self.cls,
315-
ignore_wrappers=self.ignore_wrappers,
316-
complex_as=self.complex_as,
317-
)
307+
return self.get_object_as_json(value, self.cls,
308+
ignore_wrappers=self.ignore_wrappers,
309+
complex_as=self.complex_as,
310+
)
318311

319-
return retval
320312
return process
321313

322314
def result_processor(self, dialect, col_type):

0 commit comments

Comments
 (0)