def get_uri(self): """Return URI instance with a defined host (and port, for TCP).""" if not self.environment_variable: raise RuntimeError("Define at least %s.environment_variable" % type(self).__name__) uri_str = os.environ.get(self.host_environment_variable) if uri_str: uri = URI(uri_str) if not uri.host: raise RuntimeError("The URI in %s must include a host." % self.host_environment_variable) if not uri.host.startswith("/") and not uri.port: if not self.default_port: raise RuntimeError("Define at least %s.default_port" % type(self).__name) uri.port = self.default_port return uri else: uri_str = os.environ.get(self.environment_variable) if uri_str: uri = URI(uri_str) if uri.host: if not uri.host.startswith("/") and not uri.port: if not self.default_port: raise RuntimeError( "Define at least %s.default_port" % type(self).__name) uri.port = self.default_port return uri return None
def get_uri(self): """Return URI instance with a defined host and port.""" if not self.environment_variable or not self.default_port: raise RuntimeError("Define at least %s.environment_variable and " "%s.default_port" % (type(self).__name__, type(self).__name__)) uri_str = os.environ.get(self.host_environment_variable) if uri_str: uri = URI(uri_str) if not uri.host: raise RuntimeError("The URI in %s must include a host." % self.host_environment_variable) if not uri.port: uri.port = self.default_port return uri else: uri_str = os.environ.get(self.environment_variable) if uri_str: uri = URI(uri_str) if uri.host: if not uri.port: uri.port = self.default_port return uri return None
def _create_uri(self, dbname=None): # postgres is a special database which is always present, # it was added in 8.1 which is thus our requirement' dbname = dbname or 'postgres' # Do not output the password in the logs if not self.first: log.info('connecting to %s' % self._build_dsn( dbname, filter_password=True)) self.first = False dsn = self._build_dsn(dbname, filter_password=False) uri = URI(dsn) uri.options['isolation'] = 'read-committed' if uri.host == "": pair = test_local_database() if pair is None: raise DatabaseError( _("Could not find a database server on this computer")) uri.host = pair[0] uri.port = int(pair[1]) return uri
def _create_uri(self, dbname=None): # postgres is a special database which is always present, # it was added in 8.1 which is thus our requirement' dbname = dbname or 'postgres' # Do not output the password in the logs if not self.first: log.info('connecting to %s' % self._build_dsn( dbname, filter_password=True)) self.first = False dsn = self._build_dsn(dbname, filter_password=False) uri = URI(dsn) uri.options['isolation'] = 'read-committed' if uri.host == "": pair = test_local_database() if pair is None: raise DatabaseError( _("Could not find a database server on this computer")) uri.host = pair[0] uri.port = int(pair[1]) return uri