def test_partial_4(self): d = { 'x': DotDictWithAcquisition() } d['x'].local_config = DotDictWithAcquisition() class A(object): def __init__(self, config): self.config = config eq_(d['x'].local_config, config) wrapped_class = class_with_partial_init( A, d['x'].local_config, d['x'] ) a = wrapped_class() del d['x'] # the DotDictWithAcquisition should try to look to its parent # for the key "bad_key", but the weakly referenced parent should be # saved in the wrapped class. That means the 'bad_key' should raise # a 'KeyError' instead try: a.config.bad_key except KeyError: # this is the correct behavior # 'assertRaises' was not used because we're not testing a callable pass
def test_partial_3(self): d = {'x': DotDictWithAcquisition()} d['x'].local_config = DotDictWithAcquisition() class A(object): def __init__(self, config): self.config = config eq_(d['x'].local_config, config) wrapped_class = class_with_partial_init( A, d['x'].local_config, ) a = wrapped_class() del d['x'] # the DotDictWithAcquisition should try to look to its parent # for the key "bad_key", but the weakly referenced parent should be # gone and raise a ReferenceError try: a.config.bad_key except ReferenceError: # this is the correct behavior # 'assertRaises' was not used because we're not testing a callable pass
def test_partial_2(self): local_config = DotDict() global_config = DotDict() class A(object): def __init__(self, config): eq_(local_config, config) wrapped_class = class_with_partial_init(A, local_config, global_config) wrapped_class() eq_(wrapped_class.global_config, global_config)
def test_partial_2(self): local_config = DotDict() global_config = DotDict() class A(object): def __init__(self, config): eq_(local_config, config) wrapped_class = class_with_partial_init(A, local_config, global_config) a = wrapped_class() eq_(wrapped_class.global_config, global_config)
def __init__(self, config, services_list): self.config = config urls = [] for each in services_list: if hasattr(each, 'uri'): # this service has a hard coded uri embedded within uri, cls = each.uri, each config.logger.debug( 'embedded uri class %s %s', cls.__name__, uri ) else: # this is a uri, service pair uri, cls = each config.logger.debug( 'service pair uri class %s %s', cls.__name__, uri ) if isinstance(uri, basestring): uri = (uri, ) for a_uri in uri: urls.append(a_uri) if hasattr(cls, 'wrapped_partial'): config.logger.debug( "appending already wrapped %s", cls.__name__ ) urls.append(cls) else: config.logger.debug( "wrapping %s", cls.__name__ ) urls.append(class_with_partial_init(cls, config)) self.urls = tuple(urls) web.webapi.internalerror = web.debugerror web.config.debug = False self._identify() self._wsgi_func = web.application(self.urls, globals()).wsgifunc()
def main(self): # modwsgi requires a module level name 'application' global application services_list = [] # take the list of services that have been specified in the configman # setup and create a list of services appropriate for the wsgi server # class. Ensure that each service has been coupled with its namespace # from the final configuration for namespace, uri, service_class in ( self.config.services.services_controller.service_list ): services_list.append( # a tuple associating a URI with a service class ( uri, # a binding of the service class with the configuration # namespace for that service class class_with_partial_init( self.config.services[namespace] .service_implementation_class, self.config.services[namespace], self.config ) ) ) # initialize the wsgi server with the list of URI/service impl tuples self.web_server = self.config.web_server.wsgi_server_class( self.config, # needs the whole config not the local namespace services_list ) # for modwsgi the 'run' method returns the wsgi function that the web # server will use. For other webservers, the 'run' method actually # starts the standalone web server. application = self.web_server.run()