From c5f7c7b01be868147220aa8d30265bac30d34572 Mon Sep 17 00:00:00 2001 From: Garrett Holmstrom Date: Thu, 7 Feb 2013 17:08:02 -0800 Subject: [PATCH] Kill off a 2.7-ism --- requestbuilder/auth.py | 11 ++++++++++- requestbuilder/config.py | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/requestbuilder/auth.py b/requestbuilder/auth.py index 2531039..f4220a1 100644 --- a/requestbuilder/auth.py +++ b/requestbuilder/auth.py @@ -12,11 +12,14 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +from __future__ import absolute_import + import argparse import base64 import hashlib import hmac import os +import logging import requests.auth import six import time @@ -35,9 +38,15 @@ class BaseAuth(requests.auth.AuthBase): def __init__(self, service, **kwargs): self.args = kwargs self.config = service.config - self.log = service.log.getChild(self.__class__.__name__) self.service = service + # Yes, service.log.getChild is shorter, but it was added in 2.7. + if service.log is logging.root: + self.log = logging.getLogger(self.__class__.__name__) + else: + self.log = logging.getLogger('{0}.{1}'.format( + service.log.name, self.__class__.__name__)) + def collect_arg_objs(self): return aggregate_subclass_fields(self.__class__, 'ARGS') diff --git a/requestbuilder/config.py b/requestbuilder/config.py index 73b6cb6..59413c3 100644 --- a/requestbuilder/config.py +++ b/requestbuilder/config.py @@ -12,13 +12,21 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +from __future__ import absolute_import + import ConfigParser import itertools +import logging class Config(object): def __init__(self, filenames, log=None): if log: - self.log = log.getChild('config') + # Yes, service.log.getChild is shorter, but it was added in 2.7. + print dir(logging) + if log is logging.root: + self.log = logging.getChild('config') + else: + self.log = logging.getLogger('{0}.config'.format(log.name)) else: self.log = _FakeLogger() self.globals = {}