Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpclib-2.5.2 fixes #118

Merged
merged 11 commits into from Jan 15, 2012
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -2,6 +2,11 @@
Changelog Changelog
========= =========


rpclib-2.5.2-beta
-----------------
* Misc. fixes.
* Full change log: https://github.com/arskom/rpclib/pull/118

rpclib-2.5.1-beta rpclib-2.5.1-beta
----------------- -----------------
* Switched to magic cookie constants instead of strings in protocol logic. * Switched to magic cookie constants instead of strings in protocol logic.
Expand Down
2 changes: 1 addition & 1 deletion src/rpclib/__init__.py
Expand Up @@ -17,7 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# #


__version__ = '2.5.1-beta' __version__ = '2.5.2-beta'


from rpclib._base import TransportContext from rpclib._base import TransportContext
from rpclib._base import EventContext from rpclib._base import EventContext
Expand Down
2 changes: 1 addition & 1 deletion src/rpclib/interface/xml_schema/_base.py
Expand Up @@ -108,7 +108,7 @@ def build_schema_nodes(self, with_schema_location=False):
import_.set('schemaLocation', sl) import_.set('schemaLocation', sl)


# append simpleType and complexType tags # append simpleType and complexType tags
for node in self.namespaces[pref].types.values(): for node in reversed(self.namespaces[pref].types.values()):
schema.append(node) schema.append(node)


# append element tags # append element tags
Expand Down
2 changes: 1 addition & 1 deletion src/rpclib/model/_base.py
Expand Up @@ -257,7 +257,7 @@ class Attributes(ModelBase.Attributes):
values = set() values = set()
"""The set of possible values for this type.""" """The set of possible values for this type."""


def __new__(cls, ** kwargs): def __new__(cls, **kwargs):
"""Overriden so that any attempt to instantiate a primitive will return """Overriden so that any attempt to instantiate a primitive will return
a customized class instead of an instance. a customized class instead of an instance.


Expand Down
4 changes: 2 additions & 2 deletions src/rpclib/model/primitive.py
Expand Up @@ -552,5 +552,5 @@ def from_string(cls, string):
class Mandatory(object): class Mandatory(object):
"""Class that contains mandatory variants of primitives.""" """Class that contains mandatory variants of primitives."""


String = String(min_occurs=1, nillable=False, min_len=1) String = String(type_name="mandatory_string", min_occurs=1, nillable=False, min_len=1)
Integer = Integer(min_occurs=1, nillable=False) Integer = Integer(type_name="mandatory_integer", min_occurs=1, nillable=False)
1 change: 1 addition & 0 deletions src/rpclib/model/table.py
Expand Up @@ -61,6 +61,7 @@
sqlalchemy.Integer: primitive.Integer, sqlalchemy.Integer: primitive.Integer,
sqlalchemy.SmallInteger: primitive.Integer, sqlalchemy.SmallInteger: primitive.Integer,


sqlalchemy.Binary: binary.ByteArray,
sqlalchemy.LargeBinary: binary.ByteArray, sqlalchemy.LargeBinary: binary.ByteArray,
sqlalchemy.Boolean: primitive.Boolean, sqlalchemy.Boolean: primitive.Boolean,
sqlalchemy.DateTime: primitive.DateTime, sqlalchemy.DateTime: primitive.DateTime,
Expand Down
1 change: 1 addition & 0 deletions src/rpclib/protocol/_base.py
Expand Up @@ -69,6 +69,7 @@ class ProtocolBase(object):


def __init__(self, app=None, validator=None): def __init__(self, app=None, validator=None):
self.__app = None self.__app = None
self.validator = None


self.set_app(app) self.set_app(app)
self.event_manager = EventManager(self) self.event_manager = EventManager(self)
Expand Down
55 changes: 36 additions & 19 deletions src/rpclib/protocol/csv/__init__.py
Expand Up @@ -29,7 +29,9 @@


from rpclib.protocol import ProtocolBase from rpclib.protocol import ProtocolBase


def complex_to_csv(cls, values): def complex_to_csv(ctx):
cls, = ctx.descriptor.out_message._type_info.values()

queue = StringIO() queue = StringIO()
writer = csv.writer(queue, dialect=csv.excel) writer = csv.writer(queue, dialect=csv.excel)


Expand All @@ -40,34 +42,49 @@ def complex_to_csv(cls, values):


keys = sorted(type_info.keys()) keys = sorted(type_info.keys())


writer.writerow(keys) if ctx.out_error is None and ctx.out_object is None:
yield queue.getvalue() writer.writerow(['Error in generating the document'])
queue.truncate(0) for r in ctx.out_error.to_string_iterable(ctx.out_error):

writer.writerow([r])
if values is not None:
for v in values: yield queue.getvalue()
d = serializer.to_dict(v) queue.truncate(0)
writer.writerow([d.get(k, None) for k in keys])
yield queue.getvalue() elif ctx.out_error is None:
queue.truncate(0) writer.writerow(keys)
yield queue.getvalue()
queue.truncate(0)

if ctx.out_object[0] is not None:
for v in ctx.out_object[0]:
d = serializer.to_dict(v)
row = [ ]
for k in keys:
val = d.get(k, None)
if val:
val=val.encode('utf8')
row.append(val)

writer.writerow(row)
yield queue.getvalue()
queue.truncate(0)


class OutCsv(ProtocolBase): class OutCsv(ProtocolBase):
mime_type = 'text/csv' mime_type = 'text/csv'


def create_in_document(self, ctx): def create_in_document(self, ctx):
raise Exception("not supported") raise Exception("not supported")


def serialize(self, ctx): def serialize(self, ctx, message):
result_message_class = ctx.descriptor.out_message assert message in (self.RESPONSE,)


if ctx.out_object is None: if ctx.out_object is None:
ctx.out_object = [] ctx.out_object = []


assert len(result_message_class._type_info) == 1, """CSV Serializer assert len(ctx.descriptor.out_message._type_info) == 1, """CSV Serializer
supports functions with exactly one return type: supports functions with exactly one return type:
%r""" % result_message_class._type_info %r""" % ctx.descriptor.out_message._type_info

# assign raw result to its wrapper, result_message
out_type, = result_message_class._type_info.itervalues()


ctx.out_string = complex_to_csv(out_type, ctx.out_object) ctx.out_string = complex_to_csv(ctx)
ctx.transport.resp_headers['Content-Disposition'] = (
'attachment; filename=%s.csv;' % ctx.descriptor.name)
6 changes: 5 additions & 1 deletion src/rpclib/protocol/http.py
Expand Up @@ -199,9 +199,13 @@ def deserialize(self, ctx, message):


self.event_manager.fire_event('before_deserialize', ctx) self.event_manager.fire_event('before_deserialize', ctx)


if ctx.in_header_doc is not None: if len(ctx.in_header_doc) > 0:
ctx.in_header = self.dict_to_object(ctx.in_header_doc, ctx.in_header = self.dict_to_object(ctx.in_header_doc,
ctx.descriptor.in_header) ctx.descriptor.in_header)
else:
ctx.in_header = [None] * len(
ctx.descriptor.in_header.get_flat_type_info(
ctx.descriptor.in_message))


if ctx.in_body_doc is not None: if ctx.in_body_doc is not None:
ctx.in_object = self.dict_to_object(ctx.in_body_doc, ctx.in_object = self.dict_to_object(ctx.in_body_doc,
Expand Down
3 changes: 2 additions & 1 deletion src/rpclib/protocol/xml/_base.py
Expand Up @@ -71,7 +71,8 @@ class XmlObject(ProtocolBase):
conventions. conventions.


:param app: The owner application instance. :param app: The owner application instance.
:param validator: One of (None, 'soft', 'lxml'). :param validator: One of (None, 'soft', 'lxml', 'schema',
ProtocolBase.SOFT_VALIDATION, XmlObject.SCHEMA_VALIDATION).
""" """


SCHEMA_VALIDATION = type("schema", (object,), {}) SCHEMA_VALIDATION = type("schema", (object,), {})
Expand Down
7 changes: 6 additions & 1 deletion src/rpclib/server/wsgi.py
Expand Up @@ -42,7 +42,12 @@
def _wsgi_input_to_iterable(http_env): def _wsgi_input_to_iterable(http_env):
istream = http_env.get('wsgi.input') istream = http_env.get('wsgi.input')


length = int(http_env.get('CONTENT_LENGTH', str(MAX_CONTENT_LENGTH))) length = http_env.get('CONTENT_LENGTH', str(MAX_CONTENT_LENGTH))
if len(length) == 0:
length = 0
else:
length = int(length)

if length > MAX_CONTENT_LENGTH: if length > MAX_CONTENT_LENGTH:
raise RequestTooLongError() raise RequestTooLongError()
bytes_read = 0 bytes_read = 0
Expand Down