|
49 | 49 |
|
50 | 50 | from os import fstat |
51 | 51 | from mmap import mmap |
52 | | -from inspect import isgenerator |
| 52 | +from inspect import isgenerator, isclass |
53 | 53 | from collections import namedtuple |
54 | 54 |
|
55 | | -from twisted.python.log import err |
| 55 | +from twisted.web import static |
56 | 56 | from twisted.web.server import NOT_DONE_YET, Request |
57 | 57 | from twisted.web.resource import Resource, NoResource |
| 58 | +from twisted.python.log import err |
58 | 59 | from twisted.internet.defer import Deferred |
59 | 60 |
|
60 | 61 | from spyne.error import InternalError |
@@ -108,6 +109,7 @@ def set_mime_type(self, what): |
108 | 109 | def get_cookie(self, key): |
109 | 110 | return self.req.getCookie(key) |
110 | 111 |
|
| 112 | + |
111 | 113 | class TwistedHttpMethodContext(HttpMethodContext): |
112 | 114 | default_transport_context = TwistedHttpTransportContext |
113 | 115 |
|
@@ -450,14 +452,28 @@ def _cb_deferred(ret, request, p_ctx, others, resource, cb=True): |
450 | 452 | _set_response_headers(request, p_ctx.transport.resp_headers) |
451 | 453 |
|
452 | 454 | om = p_ctx.descriptor.out_message |
| 455 | + single_class = None |
453 | 456 | if cb and ((not issubclass(om, ComplexModelBase)) or len(om._type_info) <= 1): |
454 | 457 | p_ctx.out_object = [ret] |
| 458 | + if len(om._type_info) == 1: |
| 459 | + single_class, = om._type_info.values() |
| 460 | + |
455 | 461 | else: |
456 | 462 | p_ctx.out_object = ret |
457 | 463 |
|
458 | 464 | retval = None |
| 465 | + |
459 | 466 | if isinstance(ret, PushBase): |
460 | 467 | retval = _init_push(ret, request, p_ctx, others, resource) |
| 468 | + |
| 469 | + elif ((isclass(om) and issubclass(om, File)) or |
| 470 | + (isclass(single_class) and issubclass(single_class, File))) and \ |
| 471 | + getattr(ret, 'abspath', None) is not None: |
| 472 | + |
| 473 | + file = static.File(ret.abspath, |
| 474 | + defaultType=str(ret.type) or 'application/octet-stream') |
| 475 | + retval = file.render_GET(request) |
| 476 | + |
461 | 477 | else: |
462 | 478 | resource.http_transport.get_out_string(p_ctx) |
463 | 479 |
|
|
0 commit comments