Beispiel #1
0
    def __init__(self, databases, transport=None):
        """ initialize couchdbkit handler with COUCHDB_DATABASES
        settings """

        self.__dict__ = self.__shared_state__
        
        if transport is None:
            self.transport = getDefaultHTTPTransport()
        # create databases sessions
        for app_name, uri in databases:
            parts = urlparse.urlsplit(urllib.unquote(uri))
            if parts[0] != 'http' and parts[0] != 'https':
                raise ValueError('Invalid dbstring')
            dbname = parts[2].split("/")[1]
            if "@" in parts[1]:
                server_parts = parts[1].split('@')
                if ":" in server_parts[0]:
                    username, password = server_parts[0].split(":")
                else:
                    username = server_parts[0]
                    password = ''
                server_uri = "%s://%s" % (parts[0], server_parts[1])
            else:
                server_uri = '%s://%s' % (parts[0], parts[1])
                username = password = ""
                     
            if username:
                self.transport.add_credentials(username, password)
            server = Server(server_uri, self.transport)
            app_label = app_name.split('.')[-1]
            self._databases[app_label] = create_session(server, dbname, local)
Beispiel #2
0
    def __init__(self, transport=None, headers=None):
        """Constructor for a `RestClient` object.

        RestClient represent an HTTP client.

        :param transport: any http instance of object based on 
                `restclient.transport.HTTPTransportBase`. By default it will use 
                a client based on `pycurl <http://pycurl.sourceforge.net/>`_ if 
                installed or `restclient.transport.HTTPLib2Transport`,a client based on 
                `Httplib2 <http://code.google.com/p/httplib2/>`_ or make your
                own depending of the option you need to access to the serve
                (authentification, proxy, ....).
        :param headers: dict, optionnal headers that will
            be added to HTTP request.
        """ 

        if transport is None:
            transport = getDefaultHTTPTransport()

        self.transport = transport

        self.status = None
        self.response = None
        self._headers = headers