strange behaviour with nested lists
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
ladon |
New
|
Undecided
|
Unassigned |
Bug Description
hello,
i am currently having a very strange behaviour when using some nested lists with Ladon 0.7.2,
here is some code to reproduce what i get , i directly put the strange behaviour of what i get inside the code.
how are we suppose to build / handle nested complex types ?
(also, please, i am not sure this is classified as a bug, so may be i should have ask in the "question part" ? if so, please accept all my apologizes and move this post)
#!/bin/env python
# -*- coding: utf-8 -*-
import sys
import platform
import os
import traceback
# -------
from ladon.ladonizer import ladonize
from ladon.types.
from ladon.compat import PORTABLE_STRING
# ---------- Singleton Pattern
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
return cls._instances[cls]
# ---------- for WS result
class Sentence(
words = [ PORTABLE_STRING ]
class SWS(LadonType):
hasError = bool
errMessage = PORTABLE_STRING
sentences = [ Sentence ]
# ---------- WS logic
class Sentencizer0(
__metaclass__ = Singleton
@ladonize(
def sentencize(self, text):
result = SWS()
sentences = text.split("\n")
for sentence in sentences:
S = Sentence()
S.words = sentence.split()
return result
import datetime
a = datetime.
sentencizer = Sentencizer0()
b = datetime.
print("loaded: %s." % (b-a))
def example():
global sentencizer
global R
s = u"""aaa bbb ccc
dd ee f
ggg
hhh i jjj kkk"""
R = sentencizer.
print R.sentences
# running it from Python IDLE, it produce what expected : List of Sentence object containing list of unicode strings
# that are two nested lists.
"""
>>>
loaded: 0:00:00.
>>> example()
[<__main__.Sentence object at 0x02B7ADF0>, <__main__.Sentence object at 0x02B7AB30>, <__main__.Sentence object at 0x02B7AD70>, <__main__.Sentence object at 0x02B7AE10>]
"""
# running it from SOAPUI, it produce a strange behaviour as inner list is now flatten
# i would have expected <sentences> containing item <sentence> containing item of (portable) unicode string
# where am i wrong ?
"""
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://
<SOAP-ENV:Body SOAP-ENV:
<
<item>
</item>
<
</SOAP-ENV:Body>
</SOAP-
"""
so, i am almost sure that i found something buggy or using it bad...
here is what i get :
---8<--- lib/python2. 6/dist- packages/ ladon-0. 7.2-py2. 6.egg/ladon/ server/ wsgi_applicatio n.py", line 315, in __call__ import_ services( self.service_ list) lib/python2. 6/dist- packages/ ladon-0. 7.2-py2. 6.egg/ladon/ server/ wsgi_applicatio n.py", line 271, in import_services _(service) taln/ws/ sentokws0. py", line 32, in <module> object) : taln/ws/ sentokws0. py", line 36, in Sentencizer0 PORTABLE_ STRING, rtype = SWS) lib/python2. 6/dist- packages/ ladon-0. 7.2-py2. 6.egg/ladon/ ladonizer/ decorator. py", line 88, in decorator method_ info = global_ service_ collection( ).add_service_ method( f,*def_ args,** def_kw) lib/python2. 6/dist- packages/ ladon-0. 7.2-py2. 6.egg/ladon/ ladonizer/ collection. py", line 120, in add_service_method info(src_ fname) lib/python2. 6/dist- packages/ ladon-0. 7.2-py2. 6.egg/ladon/ ladonizer/ collection. py", line 79, in source_info python2. 6/ast.py" , line 37, in parse
Traceback (most recent call last):
File "/usr/local/
self.
File "/usr/local/
__import_
File "/var/www/
class Sentencizer0(
File "/var/www/
@ladonize(
File "/usr/local/
ladon_
File "/usr/local/
sinfo = self.source_
File "/usr/local/
a = ast.parse(src)
File "/usr/lib/
return compile(expr, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 3
^
SyntaxError: invalid syntax
---8<---
with the following (change split \n to character * to be sure that there is not something interfering during soap call with soapui)
---8<---
#!/bin/env python
# -*- coding: utf-8 -*-
# ------- ------- ------- ------- ------- ------- ------- ------- ----
from ladon.ladonizer import ladonize ladontype import LadonType
from ladon.types.
from ladon.compat import PORTABLE_STRING
# ---------- Singleton
class Singleton(type):
cls. _instances[ cls] = super(Singleton, cls).__ call__( *args, **kwargs)
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
return cls._instances[cls]
# ---------- for WS result
class Sentence( LadonType) :
words = [ PORTABLE_STRING ]
class SWS(LadonType):
hasError = bool
errMessage = PORTABLE_STRING
sentences = [ Sentence ]
# ---------- WS logic
class Sentencizer0( object) :
__metaclass__ = Singleton
@ladonize( PORTABLE_ STRING, rtype = SWS)
"""Sentencize. ..
result. errMessage = ''
result. hasError = False
result. sentences = []
subr. append( S)
result. sentences = subr
def sentencize(self, text):
"""
result = SWS()
#
sentences = text.split("*")
subr = []
for sentence in sentences:
S = Sentence()
S.words = sentence.split()
return result
import datetime datetime. now() datetime. now()
a = datetime.
sentencizer = Sentencizer0()
b = datetime.
print("loaded: %s." % (b-a))
def example(): sentencize( s)
"""..."""
global sentencizer
global R
s = u"""aaa bbb ccc *
dd ee f *
ggg *
hhh i jjj kkk"""
R = sentencizer.
for s in R.sentences:
for x in s.words:
print x,
print
print R.sentences
---8<---