def auth(self): if settings.BASIC_AUTH_USER and settings.BASIC_AUTH_PASSWORD: return settings.BASIC_AUTH_USER, settings.BASIC_AUTH_PASSWORD, else: raise ConfigurationError( "settings.BASIC_AUTH_USER and settings.BASIC_AUTH_PASSWORD must be set." )
def _send_request(self, url): """ Make the tracking API request, return the request body :param url: TODO :type url: str :raises: ConfigurationError if the API URL was not set :rtype: str """ if self.api_url == '': raise ConfigurationError('API URL not set') parsed = urlparse.urlparse(self.api_url) url = "%s://%s%s?%s" % (parsed.scheme, parsed.netloc, parsed.path, url) request = urllib2.Request(url) request.add_header('User-Agent', self.user_agent) request.add_header('Accept-Language', self.accept_language) if not self.cookie_support: self.request_cookie = '' elif self.request_cookie != '': #print 'Adding cookie', self.request_cookie request.add_header('Cookie', self.request_cookie) response = urllib2.urlopen(request) #print response.info() body = response.read() # The cookie in the response will be set in the next request #for header, value in response.getheaders(): # # TODO handle cookies # # set cookie to la # # in case several cookies returned, we keep only the latest one # # (ie. XDEBUG puts its cookie first in the list) # #print header, value # self.request_cookie = '' return body
def get_driver_dir(self): if 'driver_dir' not in self.__config: raise ConfigurationError( "Missing parameter in toml configuration file: key 'driver_dir'" ) return self.__config['driver_dir']
def get_crossref_mail(self): if not ('crossref' in self.__config and 'mail_to' in self.__config['crossref']): raise ConfigurationError( "Missing parameter in toml configuration file: Table 'crossref', key 'mail_to'" ) return self.__config['crossref']['mail_to']
def __setitem__(self, key, value): """Set the value of a configuration parameter. :arg key: The parameter to set :arg value: The value to set it to. .. note:: Some configuration parameters are read-only in which case attempting to set them raises an error, see :attr:`Configuration.READONLY` for details of which. """ if key in Configuration.READONLY and key in self._set and value != self[key]: raise ConfigurationError("%s is read only" % key) if key in Configuration.DEFAULTS: valid_type = Configuration.DEFAULTS[key][1] if not isinstance(value, valid_type): raise ConfigurationError("Values for configuration key %s must be of type %r, not %r" % (key, valid_type, type(value))) self._set.add(key) self._conf[key] = value
def get_notify(self): if 'mail_from' not in self.__config['notify']: raise ConfigurationError( "Missing parameter in toml configuration file: Table 'notify', key 'mail_from'" ) if 'mail_pass' not in self.__config['notify']: raise ConfigurationError( "Missing parameter in toml configuration file: Table 'notify', key 'mail_pass'" ) if 'mail_host' not in self.__config['notify']: raise ConfigurationError( "Missing parameter in toml configuration file: Table 'notify', key 'mail_host'" ) if 'mail_to' not in self.__config['notify']: raise ConfigurationError( "Missing parameter in toml configuration file: Table 'notify', key 'mail_to'" ) return self.__config['notify']['mail_from'], self.__config['notify']['mail_pass'], \ self.__config['notify']['mail_host'], self.__config['notify']['mail_to']
def span_of_current_open() -> Dict[str, any]: current_span = span_from_today() duration = current_span["duration_months"] try: assert duration >= settings.OPEN_MONTHS except AssertionError as e: raise ConfigurationError("OPEN_MONTHS") from e start_of_open = span(current_span["start"], current_span["end"], frac=duration, shift=duration - settings.OPEN_MONTHS) return {"start": start_of_open["start"], "end": current_span["end"]}
def get_query_string(self): """ Return the query string :raises: ConfigurationError if the API URL was not set :rtype: str """ if self.api_url is None: raise ConfigurationError("API URL not set") if len(self.p): qs = self.api_url qs += '?' qs += urllib.urlencode(self.p) else: pass return qs
def set_plugins(self, **kwargs): """ Set supported plugins >>> piwiktrackerinstance.set_plugins(flash=True) See KNOWN_PLUGINS keys for valid values. :param kwargs: A plugin: version dict, e.g. {'java': 6}, see also KNOWN_PLUGINS :type kwargs: dict of {str: int} :rtype: None """ for plugin, version in kwargs.iteritems(): if plugin not in self.KNOWN_PLUGINS.keys(): raise ConfigurationError("Unknown plugin %s, please use one " "of %s" % (plugin, self.KNOWN_PLUGINS.keys())) self.plugins[self.KNOWN_PLUGINS[plugin]] = int(version)
def google_key(self): key = os.getenv("AUTOMAMA_GOOGLE_API_KEY") if key is None: raise ConfigurationError( "AUTOMAMA_GOOGLE_API_KEY env variable is not set.") return key