Skip to content

Instantly share code, notes, and snippets.

@dploeger
Last active December 25, 2015 01:59
Show Gist options
  • Save dploeger/6898931 to your computer and use it in GitHub Desktop.
Save dploeger/6898931 to your computer and use it in GitHub Desktop.
Add xsd:dateTime-arguments for SOAP in Ladon:
In ladon/compat.py:
add to first lines:
from datetime import datetime
and in line #24:
type_to_xsd = {
int: 'long',
long: 'long',
str: 'string',
unicode: 'string',
bool: 'boolean',
float: 'decimal',
attachment: 'binary',
datetime: 'dateTime'
}
=====================
In ladon/types/typeconverter.py
add to first lines
from datetime import dateime,tzinfo
import re
and around line #62:
if typ==bool and (val[0].upper()==PORTABLE_STRING('F') or val.strip()=='0'):
val = False
elif typ==datetime:
xsd_type = re.match('(?P<year>[\d]{4})-(?P<month>[\d]{2})-(?P<day>[\d]{2})T(?P<hour>[\d]{2}):(?P<minute>[\d]{2}):(?P<second>[\d]{2})(?P<tz>Z|[+-][\d]{2}:[\d]{2})', val)
if xsd_type:
xsd_type = xsd_type.groupdict()
tz = None
if xsd_type['tz'] != 'Z':
(hours, minutes) = xsd_type['tz'].split(":")
tz = tzinfo.utcoffset(int(hours) * 60 + int(minutes))
val = datetime(
int(xsd_type['year']),
int(xsd_type['month']),
int(xsd_type['day']),
int(xsd_type['hour']),
int(xsd_type['minute']),
int(xsd_type['second']),
0,
tz
)
else:
val = typ(val)
@dploeger
Copy link
Author

dploeger commented Oct 9, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment