Skip to content

Commit

Permalink
issue stepank#35
Browse files Browse the repository at this point in the history
Add long simple type support.
  • Loading branch information
Jean-Baptiste Lamotte committed Nov 22, 2013
1 parent 30dbe8d commit 54e11fc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/pyws/functions/args/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ def __str__(self):

# The order matters: DateTime should be placed before Date.
# date is a superclass of datetime, thus Date will catch all DateTime fields.
__types__ = (String, Boolean, Integer, Float, DateTime, Date, Dict, List)
__types__ = (String,
Boolean,
Long,
Integer,
Float,
DateTime,
Date,
Dict,
List,
FunctionPointerDict
)

This comment has been minimized.

Copy link
@stepank

stepank Nov 24, 2013

Please, do not use this indentation style, the preferred style is:

__types__ = (String, Boolean, Integer, Float, DateTime, Date, Dict, List)

If lines become longer than 79 symbols (pep8) because of this rule, then split them like this:

__types__ = (
    String, Boolean, Integer, Float, DateTime, Date, Dict, List,
    More, EventMore, SomeMore)


def TypeFactory(type_):
Expand Down
23 changes: 22 additions & 1 deletion src/pyws/functions/args/types/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

from pyws.functions.args.types.base import Type

__all__ = ('String', 'Boolean', 'Integer', 'Float', 'Date', 'DateTime', )
__all__ = ('String',
'Boolean',
'Long',
'Integer',
'Float',
'Date',
'DateTime',)


class String(Type):
Expand All @@ -27,6 +33,7 @@ def _validate(cls, value):
except UnicodeDecodeError:
return unicode(value, 'utf-8')


class Boolean(Type):
"""
Represents boolean values, simplified form is ``bool``, default
Expand All @@ -49,6 +56,19 @@ def serialize(cls, value):
return unicode(value).lower()


class Long(Type):
"""
Represents long numbers, simplified form is ``long``, default
``none_value`` is ``None``.
"""

_represents = long

@classmethod
def _validate(cls, value):
return long(value)


class Integer(Type):
"""
Represents integer numbers, simplified form is ``int``, default
Expand Down Expand Up @@ -99,6 +119,7 @@ def serialize(cls, value):

tz_re = re.compile('((\\+|-)(\d\d):?(\d\d))$')


class DateTime(Date):
"""
Represents datetime values, simplified form is ``datetime``, default
Expand Down
17 changes: 14 additions & 3 deletions src/pyws/protocols/soap/xsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,23 @@ class String(SimpleType):
def get_name(self):
return 'string', 'http://www.w3.org/2001/XMLSchema'


class Boolean(SimpleType):

_represents = args.Boolean

def get_name(self):
return 'boolean', 'http://www.w3.org/2001/XMLSchema'


class Long(SimpleType):

_represents = args.Long

def get_name(self):
return 'long', 'http://www.w3.org/2001/XMLSchema'


class Integer(SimpleType):

_represents = args.Integer
Expand Down Expand Up @@ -119,7 +129,7 @@ def get_children(self, sequence, types):
type = TypeFactory(field.type, self.ns, self.nsmap)
element = et.SubElement(sequence,
xsd_name('element'), name=field.name,
type=qname(*(type.name + (self.nsmap, ))))
type=qname(*(type.name + (self.nsmap,))))

This comment has been minimized.

Copy link
@stepank

stepank Nov 24, 2013

Revert this and similar code style changes, please.

element.set('nillable', 'true')
type.get_types(types)

Expand All @@ -135,14 +145,15 @@ def get_children(self, sequence, types):
type = TypeFactory(self.type.element_type, self.ns, self.nsmap)
et.SubElement(sequence,
xsd_name('element'), name='item',
type=qname(*(type.name + (self.nsmap, ))),
type=qname(*(type.name + (self.nsmap,))),
minOccurs='0', maxOccurs='unbounded')
type.get_types(types)


# The order matters: DateTime should be placed before Date.
# Date is a superclass of DateTime, thus Date will catch all DateTime fields.
__types__ = (String, Boolean, Integer, Float, DateTime, Date, Dict, List)
__types__ = (String, Boolean, Long, Integer, Float, DateTime, Date, Dict, List)


def TypeFactory(type, ns=None, nsmap=None):
for x in __types__:
Expand Down

1 comment on commit 54e11fc

@stepank
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.