changes by python-modernize

main
Alex Morega 12 years ago
parent 610c26d816
commit a75ea0d693

@ -245,7 +245,7 @@ class BaseConfigurator(object):
def configure_custom(self, config): def configure_custom(self, config):
"""Configure an object with a user-supplied factory.""" """Configure an object with a user-supplied factory."""
c = config.pop('()') c = config.pop('()')
if not hasattr(c, '__call__') and hasattr(types, 'ClassType') and type(c) != types.ClassType: if not hasattr(c, '__call__') and type(c) != type:
c = self.resolve(c) c = self.resolve(c)
props = config.pop('.', None) props = config.pop('.', None)
# Check for valid identifiers # Check for valid identifiers
@ -296,21 +296,21 @@ class DictConfigurator(BaseConfigurator):
level = handler_config.get('level', None) level = handler_config.get('level', None)
if level: if level:
handler.setLevel(_checkLevel(level)) handler.setLevel(_checkLevel(level))
except StandardError, e: except Exception as e:
raise ValueError('Unable to configure handler ' raise ValueError('Unable to configure handler '
'%r: %s' % (name, e)) '%r: %s' % (name, e))
loggers = config.get('loggers', EMPTY_DICT) loggers = config.get('loggers', EMPTY_DICT)
for name in loggers: for name in loggers:
try: try:
self.configure_logger(name, loggers[name], True) self.configure_logger(name, loggers[name], True)
except StandardError, e: except Exception as e:
raise ValueError('Unable to configure logger ' raise ValueError('Unable to configure logger '
'%r: %s' % (name, e)) '%r: %s' % (name, e))
root = config.get('root', None) root = config.get('root', None)
if root: if root:
try: try:
self.configure_root(root, True) self.configure_root(root, True)
except StandardError, e: except Exception as e:
raise ValueError('Unable to configure root ' raise ValueError('Unable to configure root '
'logger: %s' % e) 'logger: %s' % e)
else: else:
@ -325,7 +325,7 @@ class DictConfigurator(BaseConfigurator):
try: try:
formatters[name] = self.configure_formatter( formatters[name] = self.configure_formatter(
formatters[name]) formatters[name])
except StandardError, e: except Exception as e:
raise ValueError('Unable to configure ' raise ValueError('Unable to configure '
'formatter %r: %s' % (name, e)) 'formatter %r: %s' % (name, e))
# Next, do filters - they don't refer to anything else, either # Next, do filters - they don't refer to anything else, either
@ -333,7 +333,7 @@ class DictConfigurator(BaseConfigurator):
for name in filters: for name in filters:
try: try:
filters[name] = self.configure_filter(filters[name]) filters[name] = self.configure_filter(filters[name])
except StandardError, e: except Exception as e:
raise ValueError('Unable to configure ' raise ValueError('Unable to configure '
'filter %r: %s' % (name, e)) 'filter %r: %s' % (name, e))
@ -346,7 +346,7 @@ class DictConfigurator(BaseConfigurator):
handler = self.configure_handler(handlers[name]) handler = self.configure_handler(handlers[name])
handler.name = name handler.name = name
handlers[name] = handler handlers[name] = handler
except StandardError, e: except Exception as e:
raise ValueError('Unable to configure handler ' raise ValueError('Unable to configure handler '
'%r: %s' % (name, e)) '%r: %s' % (name, e))
# Next, do loggers - they refer to handlers and filters # Next, do loggers - they refer to handlers and filters
@ -385,7 +385,7 @@ class DictConfigurator(BaseConfigurator):
existing.remove(name) existing.remove(name)
try: try:
self.configure_logger(name, loggers[name]) self.configure_logger(name, loggers[name])
except StandardError, e: except Exception as e:
raise ValueError('Unable to configure logger ' raise ValueError('Unable to configure logger '
'%r: %s' % (name, e)) '%r: %s' % (name, e))
@ -408,7 +408,7 @@ class DictConfigurator(BaseConfigurator):
if root: if root:
try: try:
self.configure_root(root) self.configure_root(root)
except StandardError, e: except Exception as e:
raise ValueError('Unable to configure root ' raise ValueError('Unable to configure root '
'logger: %s' % e) 'logger: %s' % e)
finally: finally:
@ -420,7 +420,7 @@ class DictConfigurator(BaseConfigurator):
factory = config['()'] # for use in exception handler factory = config['()'] # for use in exception handler
try: try:
result = self.configure_custom(config) result = self.configure_custom(config)
except TypeError, te: except TypeError as te:
if "'format'" not in str(te): if "'format'" not in str(te):
raise raise
#Name of parameter changed from fmt to format. #Name of parameter changed from fmt to format.
@ -450,7 +450,7 @@ class DictConfigurator(BaseConfigurator):
for f in filters: for f in filters:
try: try:
filterer.addFilter(self.config['filters'][f]) filterer.addFilter(self.config['filters'][f])
except StandardError, e: except Exception as e:
raise ValueError('Unable to add filter %r: %s' % (f, e)) raise ValueError('Unable to add filter %r: %s' % (f, e))
def configure_handler(self, config): def configure_handler(self, config):
@ -459,14 +459,14 @@ class DictConfigurator(BaseConfigurator):
if formatter: if formatter:
try: try:
formatter = self.config['formatters'][formatter] formatter = self.config['formatters'][formatter]
except StandardError, e: except Exception as e:
raise ValueError('Unable to set formatter ' raise ValueError('Unable to set formatter '
'%r: %s' % (formatter, e)) '%r: %s' % (formatter, e))
level = config.pop('level', None) level = config.pop('level', None)
filters = config.pop('filters', None) filters = config.pop('filters', None)
if '()' in config: if '()' in config:
c = config.pop('()') c = config.pop('()')
if not hasattr(c, '__call__') and hasattr(types, 'ClassType') and type(c) != types.ClassType: if not hasattr(c, '__call__') and type(c) != type:
c = self.resolve(c) c = self.resolve(c)
factory = c factory = c
else: else:
@ -476,7 +476,7 @@ class DictConfigurator(BaseConfigurator):
'target' in config: 'target' in config:
try: try:
config['target'] = self.config['handlers'][config['target']] config['target'] = self.config['handlers'][config['target']]
except StandardError, e: except Exception as e:
raise ValueError('Unable to set target handler ' raise ValueError('Unable to set target handler '
'%r: %s' % (config['target'], e)) '%r: %s' % (config['target'], e))
elif issubclass(klass, logging.handlers.SMTPHandler) and\ elif issubclass(klass, logging.handlers.SMTPHandler) and\
@ -489,7 +489,7 @@ class DictConfigurator(BaseConfigurator):
kwargs = dict([(k, config[k]) for k in config if valid_ident(k)]) kwargs = dict([(k, config[k]) for k in config if valid_ident(k)])
try: try:
result = factory(**kwargs) result = factory(**kwargs)
except TypeError, te: except TypeError as te:
if "'stream'" not in str(te): if "'stream'" not in str(te):
raise raise
#The argument name changed from strm to stream #The argument name changed from strm to stream
@ -511,7 +511,7 @@ class DictConfigurator(BaseConfigurator):
for h in handlers: for h in handlers:
try: try:
logger.addHandler(self.config['handlers'][h]) logger.addHandler(self.config['handlers'][h])
except StandardError, e: except Exception as e:
raise ValueError('Unable to add handler %r: %s' % (h, e)) raise ValueError('Unable to add handler %r: %s' % (h, e))
def common_logger_config(self, logger, config, incremental=False): def common_logger_config(self, logger, config, incremental=False):

@ -26,7 +26,7 @@ def unpickle(pickled_string):
""" """
try: try:
obj = loads(pickled_string) obj = loads(pickled_string)
except (StandardError, UnpicklingError) as e: except (Exception, UnpicklingError) as e:
raise UnpickleError('Could not unpickle.', pickled_string, e) raise UnpickleError('Could not unpickle.', pickled_string, e)
return obj return obj
@ -76,7 +76,7 @@ class Job(object):
assert isinstance(kwargs, dict), '%r is not a valid kwargs dict.' % (kwargs,) assert isinstance(kwargs, dict), '%r is not a valid kwargs dict.' % (kwargs,)
job = cls(connection=connection) job = cls(connection=connection)
if inspect.ismethod(func): if inspect.ismethod(func):
job._instance = func.im_self job._instance = func.__self__
job._func_name = func.__name__ job._func_name = func.__name__
elif inspect.isfunction(func) or inspect.isbuiltin(func): elif inspect.isfunction(func) or inspect.isbuiltin(func):
job._func_name = '%s.%s' % (func.__module__, func.__name__) job._func_name = '%s.%s' % (func.__module__, func.__name__)

Loading…
Cancel
Save