def __init__(self, wsdl): """ @param wsdl: A schema object. @type wsdl: L{wsdl.Definitions} """ self.wsdl = wsdl self.resolver = PathResolver(wsdl) self.builder = Builder(self.resolver)
class Factory: """ A factory for instantiating types defined in the WSDL. @ivar resolver: A schema type resolver. @type resolver: L{PathResolver} @ivar builder: A schema object builder. @type builder: L{Builder} """ def __init__(self, wsdl): """ @param wsdl: A schema object. @type wsdl: L{wsdl.Definitions} """ self.wsdl = wsdl self.resolver = PathResolver(wsdl) self.builder = Builder(self.resolver) def create(self, name): """ Create a WSDL type by name. @param name: The name of a type defined in the WSDL. @type name: str @return: The requested object. @rtype: L{Object} """ timer = metrics.Timer() timer.start() type = self.resolver.find(name) if type is None: raise TypeNotFound(name) if type.enum(): result = sudsobject.Factory.object(name) for e, a in type.children(): setattr(result, e.name, e.name) else: try: result = self.builder.build(type) except Exception as e: log.error("create '%s' failed", name, exc_info=True) raise BuildError(name, e) timer.stop() metrics.log.debug("%s created: %s", name, timer) return result def separator(self, ps): """ Set the path separator. @param ps: The new path separator. @type ps: char """ self.resolver = PathResolver(self.wsdl, ps)
class Factory(object): """ A factory for instantiating types defined in the wsdl @ivar resolver: A schema type resolver. @type resolver: L{PathResolver} @ivar builder: A schema object builder. @type builder: L{Builder} """ def __init__(self, wsdl): """ @param wsdl: A schema object. @type wsdl: L{wsdl.Definitions} """ self.wsdl = wsdl self.resolver = PathResolver(wsdl) self.builder = Builder(self.resolver) def create(self, name): """ create a WSDL type by name @param name: The name of a type defined in the WSDL. @type name: str @return: The requested object. @rtype: L{Object} """ timer = metrics.Timer() timer.start() type = self.resolver.find(name) if type is None: raise TypeNotFound(name) if type.enum(): result = InstFactory.object(name) for e, a in type.children(): setattr(result, e.name, e.name) else: try: result = self.builder.build(type) except Exception as e: log.error("create '%s' failed", name, exc_info=True) raise BuildError(name, e) timer.stop() metrics.log.debug('%s created: %s', name, timer) return result def separator(self, ps): """ Set the path separator. @param ps: The new path separator. @type ps: char """ self.resolver = PathResolver(self.wsdl, ps) def __getattr__(self, item): return self.__getitem__(item) def __getitem__(self, item): def creator(**kwargs): obj = self.create(item) for name, value in kwargs.items(): if not hasattr(obj, name): raise AttributeError( "Object {} does not have attribute {}".format( item, name)) setattr(obj, name, value) return obj return creator