class SynchedRunnable(Runnable): i = 0 def run(self): self.i += 1 doneSignal.countDown() run = synchronize.make_synchronized(run)
class modjy_publisher: def init_publisher(self): self.cache = None if self.params['app_directory']: self.app_directory = self.expand_relative_path( self.params['app_directory']) else: self.app_directory = self.servlet_context.getRealPath('/') self.params['app_directory'] = self.app_directory if self.app_directory is not None and not self.app_directory in sys.path: sys.path.append(self.app_directory) def map_uri(self, req, environ): source_uri = '%s%s%s' % (self.app_directory, File.separator, self.params['app_filename']) callable_name = self.params['app_callable_name'] if self.params['callable_query_name']: query_string = req.getQueryString() if query_string: for name_val in query_string.split('&'): if name_val.find('=') != -1: name, value = name_val.split('=', 1) else: name, value = name_val, '' if name == self.params['callable_query_name']: callable_name = value else: callable_name = '' return source_uri, callable_name def get_app_object(self, req, environ): environ["SCRIPT_NAME"] = "%s%s" % (req.getContextPath(), req.getServletPath()) path_info = req.getPathInfo() or "" environ["PATH_INFO"] = path_info environ["PATH_TRANSLATED"] = File(self.app_directory, path_info).getPath() if self.params['app_import_name']: return self.get_app_object_importable( self.params['app_import_name']) else: if self.cache is None: self.cache = {} return self.get_app_object_old_style(req, environ) get_app_object = synchronize.make_synchronized(get_app_object) def get_app_object_importable(self, importable_name): self.log.debug("Attempting to import application callable '%s'\n" % (importable_name, )) # Under the importable mechanism, the cache contains a single object if self.cache is None: application, instantiable, method_name = self.load_importable( importable_name.strip()) if instantiable and self.params['cache_callables']: application = application() self.cache = application, instantiable, method_name application, instantiable, method_name = self.cache self.log.debug("Application is " + str(application)) if instantiable and not self.params['cache_callables']: application = application() self.log.debug("Instantiated application is " + str(application)) if method_name is not None: if not hasattr(application, method_name): self.log.fatal( "Attribute error application callable '%s' as no method '%s'" % (application, method_name)) self.raise_exc( ApplicationNotFound, "Attribute error application callable '%s' as no method '%s'" % (application, method_name)) application = getattr(application, method_name) self.log.debug("Application method is " + str(application)) return application def load_importable(self, name): try: instantiable = False method_name = None importable_name = name if name.find('()') != -1: instantiable = True importable_name, method_name = name.split('()') if method_name.startswith('.'): method_name = method_name[1:] if not method_name: method_name = None module_path, from_name = importable_name.rsplit('.', 1) imported = __import__(module_path, globals(), locals(), [from_name]) imported = getattr(imported, from_name) return imported, instantiable, method_name except (ImportError, AttributeError), aix: self.log.fatal( "Import error import application callable '%s': %s\n" % (name, str(aix))) self.raise_exc( ApplicationNotFound, "Failed to import app callable '%s': %s" % (name, str(aix)))
class test167(lang.Thread): def run(self): pass run = synchronize.make_synchronized(run)
class modjy_publisher: def init_publisher(self): self.cache = None if self.params['app_directory']: self.app_directory = self.expand_relative_path( self.params['app_directory']) else: self.app_directory = self.servlet_context.getRealPath('/') self.params['app_directory'] = self.app_directory if not self.app_directory in sys.path: sys.path.append(self.app_directory) def map_uri(self, req, environ): script_name = "%s%s" % (req.getContextPath(), req.getServletPath()) path_info = req.getPathInfo() or "" source_uri = '%s%s%s' % (self.app_directory, File.separator, self.params['app_filename']) callable_name = self.params['app_callable_name'] if self.params['callable_query_name']: query_string = req.getQueryString() if query_string and '=' in query_string: for name_val in query_string.split('&'): name, value = name_val.split('=') if name == self.params['callable_query_name']: callable_name = value environ["SCRIPT_NAME"] = script_name environ["PATH_INFO"] = path_info environ["PATH_TRANSLATED"] = File(self.app_directory, path_info).getPath() return source_uri, callable_name def get_app_object(self, req, environ): if self.params['app_import_name'] is not None: return self.get_app_object_importable( self.params['app_import_name']) else: if self.cache is None: self.cache = {} return self.get_app_object_old_style(req, environ) get_app_object = synchronize.make_synchronized(get_app_object) def get_app_object_importable(self, importable_name): self.log.debug("Attempting to import application callable '%s'\n" % (importable_name, )) # Under the importable mechanism, the cache contains a single object if self.cache is None: application, instantiable, method_name = self.load_importable( importable_name.strip()) if instantiable and self.params['cache_callables']: application = application() self.cache = application, instantiable, method_name application, instantiable, method_name = self.cache self.log.debug("Application is " + str(application)) if instantiable and not self.params['cache_callables']: application = application() self.log.debug("Instantiated application is " + str(application)) if method_name is not None: application = getattr(application, method_name) self.log.debug("Application method is " + str(application)) return application def load_importable(self, name): try: instantiable = False method_name = None names = name.split('.') names.reverse() imported = __import__(names.pop()) while names: n = names.pop() if n.endswith("()"): n = n[:-2] instantiable = True self.log.debug("importable '%s' is instantiable." % n) if len(names) > 1: names.reverse() message = "Failed to import '%s': '%s' is not a valid method name" % ( name, ".".join(names)) self.log.error(message) self.raise_exc(ApplicationNotFound, message) elif len(names) == 1: method_name = names.pop() else: method_name = None imported = getattr(imported, n) self.log.debug("Imported '%s' from '%s'\n" % (n, str(imported))) return imported, instantiable, method_name except (ImportError, AttributeError), aix: self.log.fatal( "Import error import application callable '%s': %s\n" % (name, str(aix))) self.raise_exc( ApplicationNotFound, "Failed to import app callable '%s': %s" % (name, str(aix)))
def test_synchronized_callable(self): self.assertTrue(callable(synchronize.make_synchronized(lambda: None)))
def test_synchronized_callable(self): self.assertTrue( isinstance(synchronize.make_synchronized(lambda: None), collections.Callable))
def test_synchronized_callable(self): self.assertTrue(isinstance(synchronize.make_synchronized(lambda: None), collections.Callable))