Skip to content
This repository

rpclib-2.5.2 fixes #118

Merged
merged 11 commits into from over 2 years ago

1 participant

Burak Arslan
This page is out of date. Refresh to see the latest.
5  CHANGELOG.rst
Source Rendered
@@ -2,6 +2,11 @@
2 2
 Changelog
3 3
 =========
4 4
 
  5
+rpclib-2.5.2-beta
  6
+-----------------
  7
+ * Misc. fixes.
  8
+ * Full change log: https://github.com/arskom/rpclib/pull/118
  9
+
5 10
 rpclib-2.5.1-beta
6 11
 -----------------
7 12
  * Switched to magic cookie constants instead of strings in protocol logic.
2  src/rpclib/__init__.py
@@ -17,7 +17,7 @@
17 17
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
18 18
 #
19 19
 
20  
-__version__ = '2.5.1-beta'
  20
+__version__ = '2.5.2-beta'
21 21
 
22 22
 from rpclib._base import TransportContext
23 23
 from rpclib._base import EventContext
2  src/rpclib/interface/xml_schema/_base.py
@@ -108,7 +108,7 @@ def build_schema_nodes(self, with_schema_location=False):
108 108
                     import_.set('schemaLocation', sl)
109 109
 
110 110
             # append simpleType and complexType tags
111  
-            for node in self.namespaces[pref].types.values():
  111
+            for node in reversed(self.namespaces[pref].types.values()):
112 112
                 schema.append(node)
113 113
 
114 114
             # append element tags
2  src/rpclib/model/_base.py
@@ -257,7 +257,7 @@ class Attributes(ModelBase.Attributes):
257 257
         values = set()
258 258
         """The set of possible values for this type."""
259 259
 
260  
-    def __new__(cls, ** kwargs):
  260
+    def __new__(cls, **kwargs):
261 261
         """Overriden so that any attempt to instantiate a primitive will return
262 262
         a customized class instead of an instance.
263 263
 
4  src/rpclib/model/primitive.py
@@ -552,5 +552,5 @@ def from_string(cls, string):
552 552
 class Mandatory(object):
553 553
     """Class that contains mandatory variants of primitives."""
554 554
 
555  
-    String = String(min_occurs=1, nillable=False, min_len=1)
556  
-    Integer = Integer(min_occurs=1, nillable=False)
  555
+    String = String(type_name="mandatory_string", min_occurs=1, nillable=False, min_len=1)
  556
+    Integer = Integer(type_name="mandatory_integer", min_occurs=1, nillable=False)
1  src/rpclib/model/table.py
@@ -61,6 +61,7 @@
61 61
     sqlalchemy.Integer: primitive.Integer,
62 62
     sqlalchemy.SmallInteger: primitive.Integer,
63 63
 
  64
+    sqlalchemy.Binary: binary.ByteArray,
64 65
     sqlalchemy.LargeBinary: binary.ByteArray,
65 66
     sqlalchemy.Boolean: primitive.Boolean,
66 67
     sqlalchemy.DateTime: primitive.DateTime,
1  src/rpclib/protocol/_base.py
@@ -69,6 +69,7 @@ class ProtocolBase(object):
69 69
 
70 70
     def __init__(self, app=None, validator=None):
71 71
         self.__app = None
  72
+        self.validator = None
72 73
 
73 74
         self.set_app(app)
74 75
         self.event_manager = EventManager(self)
55  src/rpclib/protocol/csv/__init__.py
@@ -29,7 +29,9 @@
29 29
 
30 30
 from rpclib.protocol import ProtocolBase
31 31
 
32  
-def complex_to_csv(cls, values):
  32
+def complex_to_csv(ctx):
  33
+    cls, = ctx.descriptor.out_message._type_info.values()
  34
+
33 35
     queue = StringIO()
34 36
     writer = csv.writer(queue, dialect=csv.excel)
35 37
 
@@ -40,16 +42,32 @@ def complex_to_csv(cls, values):
40 42
 
41 43
     keys = sorted(type_info.keys())
42 44
 
43  
-    writer.writerow(keys)
44  
-    yield queue.getvalue()
45  
-    queue.truncate(0)
46  
-
47  
-    if values is not None:
48  
-        for v in values:
49  
-            d = serializer.to_dict(v)
50  
-            writer.writerow([d.get(k, None) for k in keys])
51  
-            yield queue.getvalue()
52  
-            queue.truncate(0)
  45
+    if ctx.out_error is None and ctx.out_object is None:
  46
+        writer.writerow(['Error in generating the document'])
  47
+        for r in ctx.out_error.to_string_iterable(ctx.out_error):
  48
+            writer.writerow([r])
  49
+
  50
+        yield queue.getvalue()
  51
+        queue.truncate(0)
  52
+
  53
+    elif ctx.out_error is None:
  54
+        writer.writerow(keys)
  55
+        yield queue.getvalue()
  56
+        queue.truncate(0)
  57
+
  58
+        if ctx.out_object[0] is not None:
  59
+            for v in ctx.out_object[0]:
  60
+                d = serializer.to_dict(v)
  61
+                row = [ ]
  62
+                for k in keys:
  63
+                    val = d.get(k, None)
  64
+                    if val:
  65
+                        val=val.encode('utf8')
  66
+                    row.append(val)
  67
+
  68
+                writer.writerow(row)
  69
+                yield queue.getvalue()
  70
+                queue.truncate(0)
53 71
 
54 72
 class OutCsv(ProtocolBase):
55 73
     mime_type = 'text/csv'
@@ -57,17 +75,16 @@ class OutCsv(ProtocolBase):
57 75
     def create_in_document(self, ctx):
58 76
         raise Exception("not supported")
59 77
 
60  
-    def serialize(self, ctx):
61  
-        result_message_class = ctx.descriptor.out_message
  78
+    def serialize(self, ctx, message):
  79
+        assert message in (self.RESPONSE,)
62 80
 
63 81
         if ctx.out_object is None:
64 82
             ctx.out_object = []
65 83
 
66  
-        assert len(result_message_class._type_info) == 1, """CSV Serializer
  84
+        assert len(ctx.descriptor.out_message._type_info) == 1, """CSV Serializer
67 85
             supports functions with exactly one return type:
68  
-            %r""" % result_message_class._type_info
69  
-
70  
-        # assign raw result to its wrapper, result_message
71  
-        out_type, = result_message_class._type_info.itervalues()
  86
+            %r""" % ctx.descriptor.out_message._type_info
72 87
 
73  
-        ctx.out_string = complex_to_csv(out_type, ctx.out_object)
  88
+        ctx.out_string = complex_to_csv(ctx)
  89
+        ctx.transport.resp_headers['Content-Disposition'] = (
  90
+                    'attachment; filename=%s.csv;' % ctx.descriptor.name)
6  src/rpclib/protocol/http.py
@@ -199,9 +199,13 @@ def deserialize(self, ctx, message):
199 199
 
200 200
         self.event_manager.fire_event('before_deserialize', ctx)
201 201
 
202  
-        if ctx.in_header_doc is not None:
  202
+        if len(ctx.in_header_doc) > 0:
203 203
             ctx.in_header = self.dict_to_object(ctx.in_header_doc,
204 204
                                                     ctx.descriptor.in_header)
  205
+        else:
  206
+            ctx.in_header = [None] * len(
  207
+                        ctx.descriptor.in_header.get_flat_type_info(
  208
+                                                    ctx.descriptor.in_message))
205 209
 
206 210
         if ctx.in_body_doc is not None:
207 211
             ctx.in_object = self.dict_to_object(ctx.in_body_doc,
3  src/rpclib/protocol/xml/_base.py
@@ -71,7 +71,8 @@ class XmlObject(ProtocolBase):
71 71
     conventions.
72 72
 
73 73
     :param app: The owner application instance.
74  
-    :param validator: One of (None, 'soft', 'lxml').
  74
+    :param validator: One of (None, 'soft', 'lxml', 'schema',
  75
+                ProtocolBase.SOFT_VALIDATION, XmlObject.SCHEMA_VALIDATION).
75 76
     """
76 77
 
77 78
     SCHEMA_VALIDATION = type("schema", (object,), {})
7  src/rpclib/server/wsgi.py
@@ -42,7 +42,12 @@
42 42
 def _wsgi_input_to_iterable(http_env):
43 43
     istream = http_env.get('wsgi.input')
44 44
 
45  
-    length = int(http_env.get('CONTENT_LENGTH', str(MAX_CONTENT_LENGTH)))
  45
+    length = http_env.get('CONTENT_LENGTH', str(MAX_CONTENT_LENGTH))
  46
+    if len(length) == 0:
  47
+        length = 0
  48
+    else:
  49
+        length = int(length)
  50
+
46 51
     if length > MAX_CONTENT_LENGTH:
47 52
         raise RequestTooLongError()
48 53
     bytes_read = 0
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.