Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/raise exception for wrong cert #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from setuptools import setup, find_packages

setup(
name="suds",
name="suds-transbank-chile",
version=suds.__version__,
description="Lightweight SOAP client",
description="Lightweight SOAP client (Adapted For working with Transbank, Chile)",
author="Jeff Ortel",
author_email="[email protected]",
maintainer="Jeff Ortel",
Expand Down
2 changes: 1 addition & 1 deletion suds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#

__version__ = '0.4'
__build__="(beta) R663-20100303"
__build__="GA R699-20100913"

#
# Exceptions
Expand Down
43 changes: 35 additions & 8 deletions suds/bindings/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from suds import *
from suds.sax import Namespace
from suds.sax.parser import Parser
from suds.sax.document import Document
from suds.sax.element import Element
from suds.sudsobject import Factory, Object
from suds.mx import Content
Expand All @@ -32,6 +33,7 @@
from suds.xsd.query import TypeQuery, ElementQuery
from suds.xsd.sxbasic import Element as SchemaElement
from suds.options import Options
from suds.plugin import PluginContainer
from copy import deepcopy

log = getLogger(__name__)
Expand Down Expand Up @@ -109,8 +111,8 @@ def get_message(self, method, args, kwargs):
@type args: list
@param kwargs: Named (keyword) args for the method invoked.
@type kwargs: dict
@return: The soap message.
@rtype: str
@return: The soap envelope.
@rtype: L{Document}
"""

content = self.headercontent(method)
Expand All @@ -123,7 +125,7 @@ def get_message(self, method, args, kwargs):
env.promotePrefixes()
else:
env.refitPrefixes()
return env
return Document(env)

def get_reply(self, method, reply):
"""
Expand All @@ -141,9 +143,12 @@ def get_reply(self, method, reply):
reply = self.replyfilter(reply)
sax = Parser()
replyroot = sax.parse(string=reply)
plugins = PluginContainer(self.options().plugins)
plugins.message.parsed(reply=replyroot)
soapenv = replyroot.getChild('Envelope')
soapenv.promotePrefixes()
soapbody = soapenv.getChild('Body')
self.detect_fault(soapbody)
soapbody = self.multiref.process(soapbody)
nodes = self.replycontent(method, soapbody)
rtypes = self.returned_types(method)
Expand All @@ -161,6 +166,23 @@ def get_reply(self, method, reply):
return (replyroot, result)
return (replyroot, None)

def detect_fault(self, body):
"""
Detect I{hidden} soapenv:Fault element in the soap body.
@param body: The soap envelope body.
@type body: L{Element}
@raise WebFault: When found.
"""
fault = body.getChild('Fault', envns)
if fault is None:
return
unmarshaller = self.unmarshaller(False)
p = unmarshaller.process(fault)
if self.options().faults:
raise WebFault(p, fault)
return self


def replylist(self, rt, nodes):
"""
Construct a I{list} reply. This mehod is called when it has been detected
Expand Down Expand Up @@ -206,14 +228,19 @@ def replycomposite(self, rtypes, nodes):
continue
resolved = rt.resolve(nobuiltin=True)
sobject = unmarshaller.process(node, resolved)
if rt.unbounded():
value = getattr(composite, tag, None)
if value is None:
value = getattr(composite, tag, None)
if value is None:
if rt.unbounded():
value = []
setattr(composite, tag, value)
value.append(sobject)
value.append(sobject)
else:
setattr(composite, tag, sobject)
else:
setattr(composite, tag, sobject)
if not isinstance(value, list):
value = [value,]
setattr(composite, tag, value)
value.append(sobject)
return composite

def get_fault(self, reply):
Expand Down
19 changes: 12 additions & 7 deletions suds/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def build(self, name):
else:
type = name
cls = type.name
if len(type):
data = Factory.object(cls)
else:
if type.mixed():
data = Factory.property(cls)
else:
data = Factory.object(cls)
resolved = type.resolve()
md = data.__metadata__
md.sxtype = resolved
Expand All @@ -73,10 +73,15 @@ def process(self, data, type, history):
value = []
else:
if len(resolved) > 0:
value = Factory.object(resolved.name)
md = value.__metadata__
md.sxtype = resolved
md.ordering = self.ordering(resolved)
if resolved.mixed():
value = Factory.property(resolved.name)
md = value.__metadata__
md.sxtype = resolved
else:
value = Factory.object(resolved.name)
md = value.__metadata__
md.sxtype = resolved
md.ordering = self.ordering(resolved)
setattr(data, type.name, value)
if value is not None:
data = value
Expand Down
72 changes: 60 additions & 12 deletions suds/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
"""

import os
import suds
from tempfile import gettempdir as tmp
from suds.transport import *
from suds.sax.parser import Parser
from suds.sax.element import Element
from datetime import datetime as dt
from datetime import timedelta
from cStringIO import StringIO
Expand Down Expand Up @@ -115,8 +118,6 @@ class FileCache(Cache):
"""
A file-based URL cache.
@cvar fnprefix: The file name prefix.
@type fnprefix: str
@ivar fnsuffix: The file name suffix.
@type fnsuffix: str
@ivar duration: The cached file duration which defines how
long the file will be cached.
Expand All @@ -125,7 +126,6 @@ class FileCache(Cache):
@type location: str
"""
fnprefix = 'suds'
fnsuffix = 'gcf'
units = ('months', 'weeks', 'days', 'hours', 'minutes', 'seconds')

def __init__(self, location=None, **duration):
Expand All @@ -142,6 +142,15 @@ def __init__(self, location=None, **duration):
self.location = location
self.duration = (None, 0)
self.setduration(**duration)
self.checkversion()

def fnsuffix(self):
"""
Get the file name suffix
@return: The suffix
@rtype: str
"""
return 'gcf'

def setduration(self, **duration):
"""
Expand Down Expand Up @@ -194,8 +203,9 @@ def putf(self, id, fp):
fn = self.__fn(id)
f = self.open(fn, 'w')
f.write(fp.read())
fp.close()
f.close()
return fp
return open(fn)
except:
log.debug(id, exc_info=1)
return fp
Expand Down Expand Up @@ -226,7 +236,7 @@ def validate(self, fn):
if self.duration[1] < 1:
return
created = dt.fromtimestamp(os.path.getctime(fn))
d = {self.duration[0] : self.duration[1]}
d = { self.duration[0]:self.duration[1] }
expired = created+timedelta(**d)
if expired < dt.now():
log.debug('%s expired, deleted', fn)
Expand Down Expand Up @@ -254,15 +264,50 @@ def open(self, fn, *args):
self.mktmp()
return open(fn, *args)

def checkversion(self):
path = os.path.join(self.location, 'version')
try:

f = self.open(path)
version = f.read()
f.close()
if version != suds.__version__:
raise Exception()
except:
self.clear()
f = self.open(path, 'w')
f.write(suds.__version__)
f.close()

def __fn(self, id):
if hasattr(id, 'name') and hasattr(id, 'suffix'):
name = id.name
suffix = id.suffix
else:
name = id
suffix = self.fnsuffix
fn = '%s-%s.%s' % (self.fnprefix, abs(hash(name)), suffix)
name = id
suffix = self.fnsuffix()
fn = '%s-%s.%s' % (self.fnprefix, name, suffix)
return os.path.join(self.location, fn)


class DocumentCache(FileCache):
"""
Provides xml document caching.
"""

def fnsuffix(self):
return 'xml'

def get(self, id):
try:
fp = FileCache.getf(self, id)
if fp is None:
return None
p = Parser()
return p.parse(fp)
except:
FileCache.purge(self, id)

def put(self, id, object):
if isinstance(object, Element):
FileCache.put(self, id, str(object))
return object


class ObjectCache(FileCache):
Expand All @@ -273,6 +318,9 @@ class ObjectCache(FileCache):
"""
protocol = 2

def fnsuffix(self):
return 'px'

def get(self, id):
try:
fp = FileCache.getf(self, id)
Expand Down
Loading