예제 #1
0
    print("************* ERROR *************")
except Exception as exc:
    print("OK  <%s>" % str(exc))

try:
    # illegal Unicode value for an XML file
    f = Foo('\ud800')
    x = xml_pickle.dumps(f)
    print("************* ERROR *************")
except Exception as exc:
    print("OK  <%s>" % str(exc))

try:
    # illegal Unicode value for an XML file
    f = Foo(WeirdUni('\ud800'))
    x = xml_pickle.dumps(f)
    print("************* ERROR *************")
except Exception as exc:
    print("OK  <%s>" % str(exc))

try:
    # safe_content assumes it can always convert the string
    # to unicode, which isn't true
    # ex: pickling a UTF-8 encoded value
    setInBody(StringType, 1)
    f = Foo('\xed\xa0\x80')
    x = xml_pickle.dumps(f)
    print("************* ERROR *************")
except Exception as exc:
    print("OK  <%s>" % str(exc))
예제 #2
0
try:
    # illegal Unicode value for an XML file 
    f = Foo('\ud800')
    x = xml_pickle.dumps(f)
    print("************* ERROR *************")
except Exception as exc:
    print("OK  <%s>" % str(exc))
    
try:
    # illegal Unicode value for an XML file
    f = Foo(WeirdUni('\ud800'))
    x = xml_pickle.dumps(f)
    print("************* ERROR *************")
except Exception as exc:
    print("OK  <%s>" % str(exc))
    
try:
    # safe_content assumes it can always convert the string
    # to unicode, which isn't true
    # ex: pickling a UTF-8 encoded value
    setInBody(bytes, 1)
    f = Foo('\xed\xa0\x80')
    x = xml_pickle.dumps(f)
    print("************* ERROR *************")
except Exception as exc:
    print("OK  <%s>" % str(exc))
    



예제 #3
0
try:
    # illegal Unicode value for an XML file 
    f = Foo(u'\ud800')
    x = xml_pickle.dumps(f)
    print "************* ERROR *************"
except Exception,exc:
    print "OK  <%s>" % str(exc)
    
try:
    # illegal Unicode value for an XML file
    f = Foo(WeirdUni(u'\ud800'))
    x = xml_pickle.dumps(f)
    print "************* ERROR *************"
except Exception,exc:
    print "OK  <%s>" % str(exc)
    
try:
    # safe_content assumes it can always convert the string
    # to unicode, which isn't true
    # ex: pickling a UTF-8 encoded value
    setInBody(StringType, 1)
    f = Foo('\xed\xa0\x80')
    x = xml_pickle.dumps(f)
    print "************* ERROR *************"
except Exception,exc:
    print "OK  <%s>" % str(exc)
    



예제 #4
0
##	  print type(obj.f), obj.f
##	  print type(obj.i), obj.i, type(obj.i2), obj.i2
##	  print type(obj.li), obj.li
##	  print type(obj.j), obj.j
##	  print type(obj.n), obj.n
##	  print type(obj.d), obj.d['One'], obj.d['Two'], obj.d['Three']
##	  print type(obj.l), obj.l[0], obj.l[1], obj.l[2]
##	  print type(obj.tup), obj.tup[0], obj.tup[1], obj.tup[2]

xml_pickle.setParanoia(0)  # allow it to use our namespace

foo = foo_class()

# try putting numeric content in body (doesn't matter which
# numeric type)
setInBody(ComplexType, 1)

# test both code paths

# path 1 - non-nested ('attr' nodes)
foo.s1 = "this is a \" string with a ' in it"
foo.s2 = 'this is a \' string with a " in it'
foo.f = 123.456
foo.i = 789
foo.i2 = 0  # zero was a bug in 1.0.1
foo.li = 5678
foo.j = 12 + 34j
foo.n = None

# path 2 - nested ('item/key/val' nodes)
foo.d = {'One': "First dict item", 'Two': 222, 'Three': 333.444}
예제 #5
0
##	  print type(obj.f), obj.f
##	  print type(obj.i), obj.i, type(obj.i2), obj.i2
##	  print type(obj.li), obj.li
##	  print type(obj.j), obj.j
##	  print type(obj.n), obj.n
##	  print type(obj.d), obj.d['One'], obj.d['Two'], obj.d['Three']
##	  print type(obj.l), obj.l[0], obj.l[1], obj.l[2]
##	  print type(obj.tup), obj.tup[0], obj.tup[1], obj.tup[2]

xml_pickle.setParanoia(0)  # allow it to use our namespace

foo = foo_class()

# try putting numeric content in body (doesn't matter which
# numeric type)
setInBody(complex, 1)

# test both code paths

# path 1 - non-nested ('attr' nodes)
foo.s1 = "this is a \" string with a ' in it"
foo.s2 = 'this is a \' string with a " in it'
foo.f = 123.456
foo.i = 789
foo.i2 = 0  # zero was a bug in 1.0.1
foo.li = 5678
foo.j = 12 + 34j
foo.n = None

# path 2 - nested ('item/key/val' nodes)
foo.d = {'One': "First dict item", 'Two': 222, 'Three': 333.444}
예제 #6
0
     hasCoreData, py_version, isNewStyleClass

from gnosis.util.XtoY import ntoa

# add "standard" extension types
import gnosis.xml.pickle.ext._mutators

from types import *

try:  # Get a usable StringIO
    from cStringIO import StringIO
except:
    from StringIO import StringIO

# default settings
setInBody(IntType, 0)
setInBody(FloatType, 0)
setInBody(LongType, 0)
setInBody(ComplexType, 0)
setInBody(StringType, 0)
# our unicode vs. "regular string" scheme relies on unicode
# strings only being in the body, so this is hardcoded.
setInBody(UnicodeType, 1)

# Define exceptions and flags
XMLPicklingError = "gnosis.xml.pickle.XMLPicklingError"
XMLUnpicklingError = "gnosis.xml.pickle.XMLUnpicklingError"

# Maintain list of object identities for multiple and cyclical references
# (also to keep temporary objects alive)
visited = {}
예제 #7
0
import gnosis.xml.pickle.ext._mutators

# XML legality checking
from gnosis.xml.xmlmap import is_legal_xml

import gnosis.pyconfig

from types import *

try:  # Get a usable StringIO
    from io import StringIO
except:
    from io import StringIO

# default settings
setInBody(int, 0)
setInBody(float, 0)
setInBody(int, 0)
setInBody(complex, 0)
setInBody(bytes, 0)
# our unicode vs. "regular string" scheme relies on unicode
# strings only being in the body, so this is hardcoded.
setInBody(str, 1)

# Define exceptions and flags
XMLPicklingError = "gnosis.xml.pickle.XMLPicklingError"
XMLUnpicklingError = "gnosis.xml.pickle.XMLUnpicklingError"

# Maintain list of object identities for multiple and cyclical references
# (also to keep temporary objects alive)
visited = {}
예제 #8
0
파일: _pickle.py 프로젝트: Ax47/devSpiral
import gnosis.xml.pickle.ext._mutators

# XML legality checking
from gnosis.xml.xmlmap import is_legal_xml

import gnosis.pyconfig

from types import *

try:		# Get a usable StringIO
    from cStringIO import StringIO
except:
    from StringIO import StringIO

# default settings
setInBody(IntType,0)
setInBody(FloatType,0)
setInBody(LongType,0)
setInBody(ComplexType,0)
setInBody(StringType,0)
# our unicode vs. "regular string" scheme relies on unicode
# strings only being in the body, so this is hardcoded.
setInBody(UnicodeType,1)

# Define exceptions and flags
XMLPicklingError = "gnosis.xml.pickle.XMLPicklingError"
XMLUnpicklingError = "gnosis.xml.pickle.XMLUnpicklingError"

# Maintain list of object identities for multiple and cyclical references
# (also to keep temporary objects alive)
visited = {}
예제 #9
0
##	  print type(obj.f), obj.f
##	  print type(obj.i), obj.i, type(obj.i2), obj.i2
##	  print type(obj.li), obj.li
##	  print type(obj.j), obj.j
##	  print type(obj.n), obj.n
##	  print type(obj.d), obj.d['One'], obj.d['Two'], obj.d['Three']
##	  print type(obj.l), obj.l[0], obj.l[1], obj.l[2]
##	  print type(obj.tup), obj.tup[0], obj.tup[1], obj.tup[2]

xml_pickle.setParanoia(0)  # allow it to use our namespace

foo = foo_class()

# try putting numeric content in body (doesn't matter which
# numeric type)
setInBody(ComplexType,1)

# test both code paths

# path 1 - non-nested ('attr' nodes)
foo.s1 = "this is a \" string with a ' in it"
foo.s2 = 'this is a \' string with a " in it'
foo.f = 123.456
foo.i = 789
foo.i2 = 0 # zero was a bug in 1.0.1
foo.li = 5678L
foo.j = 12+34j
foo.n = None

# path 2 - nested ('item/key/val' nodes)
foo.d = { 'One': "First dict item",
예제 #10
0
    raise Exception("AAGH! Didn't get StringType for pstring")
if not isinstance(o2.estring, StringType):
    raise Exception("AAGH! Didn't get StringType for estring")

#print "UNICODE:", `o2.ustring`, type(o2.ustring)
#print "PLAIN:  ", o2.pstring, type(o2.pstring)
#print "ESCAPED:", o2.estring, type(o2.estring)

if o.ustring != o2.ustring or \
   o.pstring != o2.pstring or \
   o.estring != o2.estring:
    raise Exception("ERROR(1)")

#-- Pickle with Python strings in body
#print '\n------------* Pickle with Python strings in body *----------------------'
setInBody(StringType, 1)
xml = dumps(o)
#print xml,
#print '------------* Restored attributes from different strings *--------------'
o2 = loads(xml)
# check types explicitly, since comparison will coerce types
if not isinstance(o2.ustring, str):
    raise Exception("AAGH! Didn't get str")
if not isinstance(o2.pstring, str):
    raise Exception("AAGH! Didn't get StringType for pstring")
if not isinstance(o2.estring, str):
    raise Exception("AAGH! Didn't get StringType for estring")

#print "UNICODE:", `o2.ustring`, type(o2.ustring)
#print "PLAIN:  ", o2.pstring, type(o2.pstring)
#print "ESCAPED:", o2.estring, type(o2.estring)
예제 #11
0
print '------------* Restored attributes from different strings *--------------'
o2 = loads(xml)
if not isinstance(o2.ustring, UnicodeType):
    raise "AAGH! Didn't get UnicodeType"
if not isinstance(o2.pstring, StringType):
    raise "AAGH! Didn't get StringType for pstring"
if not isinstance(o2.estring, StringType):
    raise "AAGH! Didn't get StringType for estring"

print "UNICODE:", ` o2.ustring `, type(o2.ustring)
print "PLAIN:  ", o2.pstring, type(o2.pstring)
print "ESCAPED:", o2.estring, type(o2.estring)

#-- Pickle with Python strings in body
print '\n------------* Pickle with Python strings in body *----------------------'
setInBody(StringType, 1)
xml = dumps(o)
print xml,
print '------------* Restored attributes from different strings *--------------'
o2 = loads(xml)
if not isinstance(o2.ustring, UnicodeType):
    raise "AAGH! Didn't get UnicodeType"
if not isinstance(o2.pstring, StringType):
    raise "AAGH! Didn't get StringType for pstring"
if not isinstance(o2.estring, StringType):
    raise "AAGH! Didn't get StringType for estring"

print "UNICODE:", ` o2.ustring `, type(o2.ustring)
print "PLAIN:  ", o2.pstring, type(o2.pstring)
print "ESCAPED:", o2.estring, type(o2.estring)
예제 #12
0
    raise "AAGH! Didn't get StringType for pstring"
if not isinstance(o2.estring,StringType):
    raise "AAGH! Didn't get StringType for estring"

#print "UNICODE:", `o2.ustring`, type(o2.ustring)
#print "PLAIN:  ", o2.pstring, type(o2.pstring)
#print "ESCAPED:", o2.estring, type(o2.estring)

if o.ustring != o2.ustring or \
   o.pstring != o2.pstring or \
   o.estring != o2.estring:
    raise "ERROR(1)"

#-- Pickle with Python strings in body
#print '\n------------* Pickle with Python strings in body *----------------------'
setInBody(StringType, 1)
xml = dumps(o)
#print xml,
#print '------------* Restored attributes from different strings *--------------'
o2 = loads(xml)
# check types explicitly, since comparison will coerce types
if not isinstance(o2.ustring,UnicodeType):
    raise "AAGH! Didn't get UnicodeType"
if not isinstance(o2.pstring,StringType):
    raise "AAGH! Didn't get StringType for pstring"
if not isinstance(o2.estring,StringType):
    raise "AAGH! Didn't get StringType for estring"

#print "UNICODE:", `o2.ustring`, type(o2.ustring)
#print "PLAIN:  ", o2.pstring, type(o2.pstring)
#print "ESCAPED:", o2.estring, type(o2.estring)
예제 #13
0
    print("AAGH! Didn't get bytes for estring")
    raise

#print "UNICODE:", `o2.ustring`, type(o2.ustring)
#print "PLAIN:  ", o2.pstring, type(o2.pstring)
#print "ESCAPED:", o2.estring, type(o2.estring)

if o.ustring != o2.ustring or \
   o.pstring != o2.pstring or \
   o.estring != o2.estring:
    print("ERROR(1)")
    raise

#-- Pickle with Python strings in body
#print '\n------------* Pickle with Python strings in body *----------------------'
setInBody(bytes, 1)
xml = dumps(o)
#print xml,
#print '------------* Restored attributes from different strings *--------------'
o2 = loads(xml)
# check types explicitly, since comparison will coerce types
if not isinstance(o2.ustring, str):
    print("AAGH! Didn't get str")
    raise
if not isinstance(o2.pstring, bytes):
    print("AAGH! Didn't get bytes for pstring")
    raise
if not isinstance(o2.estring, bytes):
    print("AAGH! Didn't get bytes for estring")
    raise