Example #1
0
    def __init__(self,
                 access_key_id=None,
                 secret_access_key=None,
                 locale=None,
                 associate_tag=None,
                 processor='amazonproduct.processors.objectify',
                 cfg=None):
        """
        .. versionchanged:: 0.2.6
           Passing parameters ``access_key_id``, ``secret_access_key`` and
           ``associate_tag`` directly to the constructor will be removed in one
           of the next releases. See :ref:`config` for alternatives.

        :param access_key_id: AWS access key ID (deprecated).
        :param secret_access_key: AWS secret key (deprecated).
        :param associate_tag: Amazon Associates tracking id (deprecated).
        :param locale: localise results by using one value from ``LOCALES``.
        :param processor: module containing result processing functions. Look
        in package ``amazonproduct.processors`` for values.
        """

        if any([access_key_id, secret_access_key, associate_tag]):
            warnings.warn('Please use a config file!',
                          DeprecationWarning,
                          stacklevel=2)

        self.access_key = access_key_id
        self.secret_key = secret_access_key
        self.associate_tag = associate_tag
        self.locale = locale

        if not all(getattr(self, key, False) for key in REQUIRED_KEYS):
            # load missing valued from config file
            if cfg is None or isinstance(cfg, (str, unicode)):
                cfg = load_config(cfg)
            for key in REQUIRED_KEYS:
                if getattr(self, key, '???') is None and cfg.get(key, None):
                    setattr(self, key, cfg[key])

        try:
            self.host = HOSTS[self.locale]
        except KeyError:
            raise UnknownLocale(locale)

        # GAE does not allow timeouts to be specified manually
        if not running_on_gae():
            socket.setdefaulttimeout(self.TIMEOUT)

        # instantiate processor class
        if isinstance(processor, str):
            self._processor_module = processor
            self.processor = load_class('%s.Processor' % processor)()
        else:
            self._processor_module = processor.__class__.__name__
            self.processor = processor

        self.last_call = datetime(1970, 1, 1)
        self.debug = 0  # set to 1 if you want to see HTTP headers
Example #2
0
    def __init__(self, access_key_id=None, secret_access_key=None, locale=None,
             associate_tag=None, processor='amazonproduct.processors.objectify',
             cfg=None):
        """
        .. versionchanged:: 0.2.6
           Passing parameters ``access_key_id``, ``secret_access_key`` and
           ``associate_tag`` directly to the constructor will be removed in one
           of the next releases. See :ref:`config` for alternatives.

        :param access_key_id: AWS access key ID (deprecated).
        :param secret_access_key: AWS secret key (deprecated).
        :param associate_tag: Amazon Associates tracking id (deprecated).
        :param locale: localise results by using one value from ``LOCALES``.
        :param processor: module containing result processing functions. Look
        in package ``amazonproduct.processors`` for values.
        """

        if any([access_key_id, secret_access_key, associate_tag]):
            warnings.warn('Please use a config file!', DeprecationWarning,
                stacklevel=2)

        self.access_key = access_key_id
        self.secret_key = secret_access_key
        self.associate_tag = associate_tag
        self.locale = locale

        if not all(getattr(self, key, False) for key in REQUIRED_KEYS):
            # load missing valued from config file
            if cfg is None or isinstance(cfg, (str, unicode)):
                cfg = load_config(cfg)
            for key in REQUIRED_KEYS:
                if getattr(self, key, '???') is None and cfg.get(key, None):
                    setattr(self, key, cfg[key])

        try:
            self.host = HOSTS[self.locale]
        except KeyError:
            raise UnknownLocale(locale)

        # GAE does not allow timeouts to be specified manually
        if not running_on_gae():
            socket.setdefaulttimeout(self.TIMEOUT)

        # instantiate processor class
        if isinstance(processor, str):
            self._processor_module = processor
            self.processor = load_class('%s.Processor' % processor)()
        else:
            self._processor_module = processor.__class__.__name__
            self.processor = processor

        self.last_call = datetime(1970, 1, 1)
        self.debug = 0  # set to 1 if you want to see HTTP headers
 def _load_processor(*names):
     """
     Loads result processor. If no processor is given (``None``), the first
     one is taken that can be successfully imported from the list of default
     processors (:const:`PROCESSORS`).
     """
     if len(names) == 0 or names[0] is None:
         names = PROCESSORS
     for name in names:
         # processor was given as string
         if isinstance(name, (str, unicode)):
             try:
                 pclass = load_class(name)
                 if issubclass(pclass, BaseProcessor):
                     return pclass
             except ImportError:
                 continue
         # processor was given as class
         elif isinstance(name, type) and issubclass(name, BaseProcessor):
             return name
     # nothing successfully loaded
     raise ImportError('No processor class could be imported!')
def test_load_class(txt, cls):
    loaded = utils.load_class(txt)
    assert isinstance(loaded, types.TypeType)
    assert loaded == cls
Example #5
0
def test_load_class(txt, cls):
    loaded = utils.load_class(txt)
    assert isinstance(loaded, TypeType)
    assert loaded == cls