equal
deleted
inserted
replaced
20 ) |
20 ) |
21 from . import ( |
21 from . import ( |
22 encoding, |
22 encoding, |
23 error, |
23 error, |
24 util, |
24 util, |
|
25 wireprototypes, |
25 ) |
26 ) |
26 from .utils import ( |
27 from .utils import ( |
27 cborutil, |
28 cborutil, |
28 stringutil, |
29 stringutil, |
29 ) |
30 ) |
838 try: |
839 try: |
839 if not emitted: |
840 if not emitted: |
840 yield createcommandresponseokframe(stream, requestid) |
841 yield createcommandresponseokframe(stream, requestid) |
841 emitted = True |
842 emitted = True |
842 |
843 |
843 for chunk in cborutil.streamencode(o): |
844 # Objects emitted by command functions can be serializable |
844 for frame in emitter.send(chunk): |
845 # data structures or special types. |
|
846 # TODO consider extracting the content normalization to a |
|
847 # standalone function, as it may be useful for e.g. cachers. |
|
848 |
|
849 # A pre-encoded object is sent directly to the emitter. |
|
850 if isinstance(o, wireprototypes.encodedresponse): |
|
851 for frame in emitter.send(o.data): |
845 yield frame |
852 yield frame |
|
853 |
|
854 # A regular object is CBOR encoded. |
|
855 else: |
|
856 for chunk in cborutil.streamencode(o): |
|
857 for frame in emitter.send(chunk): |
|
858 yield frame |
846 |
859 |
847 except Exception as e: |
860 except Exception as e: |
848 for frame in createerrorframe(stream, requestid, |
861 for frame in createerrorframe(stream, requestid, |
849 '%s' % e, |
862 '%s' % e, |
850 errtype='server'): |
863 errtype='server'): |