Example #1
0
    def __init__(self,
                 url='localhost:9200',
                 path='',
                 timeout=30,
                 connection_type=None,
                 connection=None):
        super(Elastic, self).__init__()
        url_parts = url.split(':')
        self.host = url_parts[0]
        self.port = int(url_parts[1]) if len(url_parts) == 2 else 9200
        self.url = '%s:%s' % (self.host, self.port)
        self.timeout = None if timeout is None else timeout * 1000
        self.path = path

        if connection_type is None:
            if thrift_installed and self.port >= 9500 and self.port <= 9600:
                self.connection_type = 'thrift'
            else:
                self.connection_type = 'http'
        else:
            self.connection_type = connection_type

        if connection is None:
            if self.connection_type == 'http':
                self.connection = HttpConnection(self.host,
                                                 self.port,
                                                 timeout=self.timeout)
            else:
                self.connection = ThriftConnection(self.host,
                                                   self.port,
                                                   timeout=self.timeout)
        else:
            self.connection = connection
Example #2
0
    def _get_connection_from_url(self, url, timeout, **kwargs):
        """Returns a connection object given a string url"""

        url = self._decode_url(url, "")

        if url.scheme == 'http' or url.scheme == 'https':
            return HttpConnection(url.geturl(), timeout=timeout, **kwargs)
        else:
            if sys.version_info[0] > 2:
                raise ValueError("Thrift transport is not available "
                                 "for Python 3")

            try:
                from thrift_connection import ThriftConnection
            except ImportError:
                raise ImportError("The 'thrift' python package "
                                  "does not seem to be installed.")
            return ThriftConnection(url.hostname,
                                    url.port,
                                    timeout=timeout,
                                    **kwargs)
Example #3
0
    def __init__(self, url='localhost:9200', path='', timeout=30, connection=None, json_encoder=encode_date_optional_time, **kwargs):
        super(Elastic, self).__init__()

        self.url = self._decode_url(url,path)
        self.timeout = timeout  # seconds
        self.json_encoder = json_encoder

        if connection is None:
            if self.url.scheme == 'http' or self.url.scheme == 'https':
                connection = HttpConnection(self.url.geturl(), timeout=self.timeout, **kwargs)
            else:
                if sys.version_info[0] > 2:
                    raise ValueError("Thrift transport not available for Python 3")

                try:
                    from thrift_connection import ThriftConnection
                except ImportError:
                    raise ImportError("The 'thrift' python package does not seem to be installed.")
                connection = ThriftConnection(self.url.hostname, self.url.port, timeout=self.timeout, **kwargs)

        self.connection = connection