Merge lp:~j-launchpad-dennis/ladon/xsddatetime into lp:ladon

Proposed by Dennis Plöger
Status: Needs review
Proposed branch: lp:~j-launchpad-dennis/ladon/xsddatetime
Merge into: lp:ladon
Diff against target: 58 lines (+23/-1)
2 files modified
frameworks/python/src/ladon/compat.py (+3/-1)
frameworks/python/src/ladon/types/typeconverter.py (+20/-0)
To merge this branch: bzr merge lp:~j-launchpad-dennis/ladon/xsddatetime
Reviewer Review Type Date Requested Status
Ladon Developer Pending
Review via email: mp+190078@code.launchpad.net

Description of the change

Add support for xsd:DateTime in SOAP-requests

To post a comment you must log in.

Unmerged revisions

107. By Dennis Ploeger <email address hidden>

Added xsd:dateTime-Support

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'frameworks/python/src/ladon/compat.py'
2--- frameworks/python/src/ladon/compat.py 2011-08-22 00:44:05 +0000
3+++ frameworks/python/src/ladon/compat.py 2013-10-09 10:19:56 +0000
4@@ -1,5 +1,6 @@
5 import sys
6 from ladon.types.attachment import attachment
7+from datetime import datetime
8
9 if sys.version_info[0]==2:
10 import StringIO,cStringIO
11@@ -27,7 +28,8 @@
12 unicode: 'string',
13 bool: 'boolean',
14 float: 'decimal',
15- attachment: 'binary'
16+ attachment: 'binary',
17+ datetime: 'dateTime'
18 }
19
20 type_to_jsontype = {
21
22=== modified file 'frameworks/python/src/ladon/types/typeconverter.py'
23--- frameworks/python/src/ladon/types/typeconverter.py 2012-05-04 14:43:58 +0000
24+++ frameworks/python/src/ladon/types/typeconverter.py 2013-10-09 10:19:56 +0000
25@@ -2,6 +2,8 @@
26 import sys
27 from ladon.exceptions.types import *
28 from ladon.compat import PORTABLE_BYTES,PORTABLE_STRING,pytype_support,safe_conversions
29+from datetime import dateime,tzinfo
30+import re
31
32 class TypeConverter(object):
33
34@@ -59,6 +61,24 @@
35 try:
36 if typ==bool and (val[0].upper()==PORTABLE_STRING('F') or val.strip()=='0'):
37 val = False
38+ elif typ==datetime:
39+ 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)
40+ if xsd_type:
41+ xsd_type = xsd_type.groupdict()
42+ tz = None
43+ if xsd_type['tz'] != 'Z':
44+ (hours, minutes) = xsd_type['tz'].split(":")
45+ tz = tzinfo.utcoffset(int(hours) * 60 + int(minutes))
46+ val = datetime(
47+ int(xsd_type['year']),
48+ int(xsd_type['month']),
49+ int(xsd_type['day']),
50+ int(xsd_type['hour']),
51+ int(xsd_type['minute']),
52+ int(xsd_type['second']),
53+ 0,
54+ tz
55+ )
56 else:
57 val = typ(val)
58 # Run incoming filters aka. incoming postfilters

Subscribers

People subscribed via source and target branches