Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
wiperf / usr / local / lib / python3.7 / dist-packages / influxdb / __pycache__ / client.cpython-37.pyc
Size: Mime:
B

 €X5
ónã@sdZddlmZddlmZddlmZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZmZddlZddlZddlZddlmZdd	lmZmZmZdd
lmZddlmZdd
lmZGdd„deƒZ dd„Z!dd„Z"dd„Z#dS)zPython client for InfluxDB.é)Úabsolute_import)Údivision)Úprint_function)Úunicode_literalsN)ÚchainÚislice)Úurlparse)Ú
make_linesÚquote_identÚ
quote_literal)Ú	ResultSeté)ÚInfluxDBClientError)ÚInfluxDBServerErrorc@s¾eZdZdZdldd„Zd
d„Zdd„Zedd„ƒZedd„ƒZ	edd„ƒZ
edd„ƒZedd„ƒZedd„ƒZ
edd„ƒZdd „Zd!d"„Zdmd%d&„Zdnd)d*„Zedod,d-„ƒZdpd/d0„Zdqd1d2„Zd3d4„Zed5d6„ƒZdrd7d8„Zd9d:„Zdsd;d<„Zd=d>„Zd?d@„ZdAdB„ZdCdD„Z dtdFdG„Z!dudHdI„Z"dvdJdK„Z#dwdLdM„Z$dNdO„Z%dxdPdQ„Z&dRdS„Z'dTdU„Z(dydVdW„Z)dXdY„Z*dZd[„Z+d\d]„Z,d^d_„Z-d`da„Z.dbdc„Z/dzddde„Z0d{dfdg„Z1d|dhdi„Z2djdk„Z3dS)}ÚInfluxDBClientug	InfluxDBClient primary client object to connect InfluxDB.

    The :class:`~.InfluxDBClient` object holds information necessary to
    connect to InfluxDB. Requests can be made to InfluxDB directly through
    the client.

    The client supports the use as a `context manager
    <https://docs.python.org/3/reference/datamodel.html#context-managers>`_.

    :param host: hostname to connect to InfluxDB, defaults to 'localhost'
    :type host: str
    :param port: port to connect to InfluxDB, defaults to 8086
    :type port: int
    :param username: user to connect, defaults to 'root'
    :type username: str
    :param password: password of the user, defaults to 'root'
    :type password: str
    :param pool_size: urllib3 connection pool size, defaults to 10.
    :type pool_size: int
    :param database: database name to connect to, defaults to None
    :type database: str
    :param ssl: use https instead of http to connect to InfluxDB, defaults to
        False
    :type ssl: bool
    :param verify_ssl: verify SSL certificates for HTTPS requests, defaults to
        False
    :type verify_ssl: bool
    :param timeout: number of seconds Requests will wait for your client to
        establish a connection, defaults to None
    :type timeout: int
    :param retries: number of retries your client will try before aborting,
        defaults to 3. 0 indicates try until success
    :type retries: int
    :param use_udp: use UDP to connect to InfluxDB, defaults to False
    :type use_udp: bool
    :param udp_port: UDP port to connect to InfluxDB, defaults to 4444
    :type udp_port: int
    :param proxies: HTTP(S) proxy to use for Requests, defaults to {}
    :type proxies: dict
    :param path: path of InfluxDB on the server to connect, defaults to ''
    :type path: str
    :param cert: Path to client certificate information to use for mutual TLS
        authentication. You can specify a local cert to use
        as a single file containing the private key and the certificate, or as
        a tuple of both files’ paths, defaults to None
    :type cert: str
    :param gzip: use gzip content encoding to compress requests
    :type gzip: bool
    :param session: allow for the new client request to use an existing
        requests Session, defaults to None
    :type session: requests.Session
    :raises ValueError: if cert is provided but ssl is disabled (set to False)

    Ú	localhosté–ÚrootNFéé\é
ÚcCs:||_t|ƒ|_||_||_||_||_|	|_||_|
|_	t|ƒ|_
|sPt ¡}||_
tjjt|
ƒt|
ƒd}|
r„t tjtj¡|_|sd|_n|ddkr¤||_n
d||_d|_|dkrÂd|_|j
 |jd|¡|d	kræi|_n||_|r
|std
ƒ‚n||j
_d |j|j|j|j¡|_dd
dœ|_||_ d	S)z&Construct a new InfluxDBClient object.)Úpool_connectionsÚpool_maxsizerrú/ÚhttpTÚhttpsz://Nz0Client certificate provided but ssl is disabled.z{0}://{1}:{2}{3}zapplication/jsonzapplication/x-msgpack)zContent-TypeÚAccept)!Ú_InfluxDBClient__hostÚintÚ_InfluxDBClient__portÚ	_usernameÚ	_passwordÚ	_databaseÚ_timeoutÚ_retriesÚ_verify_sslÚ_InfluxDBClient__use_udpÚ_InfluxDBClient__udp_portÚrequestsÚSessionÚ_sessionÚadaptersÚHTTPAdapterÚsocketÚAF_INETÚ
SOCK_DGRAMÚ
udp_socketÚ_InfluxDBClient__pathÚ_schemeÚmountÚ_proxiesÚ
ValueErrorÚcertÚformatÚ_hostÚ_portÚ_pathÚ_InfluxDBClient__baseurlÚ_headersÚ_gzip)ÚselfÚhostÚportÚusernameÚpasswordÚdatabaseÚsslZ
verify_sslÚtimeoutÚretriesÚuse_udpZudp_portÚproxiesZ	pool_sizeÚpathr7ÚgzipÚsessionÚadapter©rNú5/tmp/pip-install-4lg_ekbd/influxdb/influxdb/client.pyÚ__init__WsV




zInfluxDBClient.__init__cCsdS)z*Enter function as used by context manager.NrN)r?rNrNrOÚ	__enter__¬szInfluxDBClient.__enter__cCs| ¡dS)z)Exit function as used by context manager.N)Úclose)r?Z	_exc_typeZ
_exc_valueZ
_tracebackrNrNrOÚ__exit__°szInfluxDBClient.__exit__cCs|jS)N)r<)r?rNrNrOÚ_baseurl´szInfluxDBClient._baseurlcCs|jS)N)r)r?rNrNrOr9¸szInfluxDBClient._hostcCs|jS)N)r )r?rNrNrOr:¼szInfluxDBClient._portcCs|jS)N)r2)r?rNrNrOr;ÀszInfluxDBClient._pathcCs|jS)N)r()r?rNrNrOÚ	_udp_portÄszInfluxDBClient._udp_portcCs|jS)N)r')r?rNrNrOÚ_use_udpÈszInfluxDBClient._use_udpcKs>t|ƒ}| d¡d\}}||d<||d<| |¡|f|ŽS)ahGenerate an instance of InfluxDBClient from given data source name.

        Return an instance of :class:`~.InfluxDBClient` from the provided
        data source name. Supported schemes are "influxdb", "https+influxdb"
        and "udp+influxdb". Parameters for the :class:`~.InfluxDBClient`
        constructor may also be passed to this method.

        :param dsn: data source name
        :type dsn: string
        :param kwargs: additional parameters for `InfluxDBClient`
        :type kwargs: dict
        :raises ValueError: if the provided DSN has any unexpected values

        :Example:

        ::

            >> cli = InfluxDBClient.from_dsn('influxdb://username:password@\
            localhost:8086/databasename', timeout=5)
            >> type(cli)
            <class 'influxdb.client.InfluxDBClient'>
            >> cli = InfluxDBClient.from_dsn('udp+influxdb://username:pass@\
            localhost:8086/databasename', timeout=5, udp_port=159)
            >> print('{0._baseurl} - {0.use_udp} {0.udp_port}'.format(cli))
            http://localhost:8086 - True 159

        .. note:: parameters provided in `**kwargs` may override dsn parameters
        .. note:: when using "udp+influxdb" the specified port (if any) will
            be used for the TCP connection; specify the UDP port with the
            additional `udp_port` parameter (cf. examples).
        Úhostsrr@rA)Ú
_parse_dsnÚpopÚupdate)ÚclsÚdsnÚkwargsÚ	init_argsr@rArNrNrOÚfrom_dsnÌs!
zInfluxDBClient.from_dsncCs
||_dS)z‚Change the client's database.

        :param database: the name of the database to switch to
        :type database: str
        N)r#)r?rDrNrNrOÚswitch_databaseõszInfluxDBClient.switch_databasecCs||_||_dS)zÉChange the client's username.

        :param username: the username to switch to
        :type username: str
        :param password: the password for the username
        :type password: str
        N)r!r")r?rBrCrNrNrOÚswitch_userýszInfluxDBClient.switch_userÚGETéÈcCsîd |j|¡}|dkr|j}|dkr(i}t|ttfƒr@t |¡}|jr”| 	dddœ¡|dk	r”t
 ¡}tj
d|dd}	|	 |¡WdQRX| ¡}d}
d	}x²|
rNy4|jj|||j|jf|||||j|j|jd

}PWqžtjjtjjtjjfk
rJ|d7}|jd	kr||jk}
|dkr>t d
|t ¡d¡|
sF‚YqžXqžW|j ob|j  !d¡}
|
dkrŒ|j"rŒt#j$|j"t%dd|_&nd|_&dd„}d|j'kr´dkrÆnnt(||ƒƒ‚n$|j'|krÖ|S||ƒ}t)||j'ƒ‚dS)aJMake a HTTP request to the InfluxDB API.

        :param url: the path of the HTTP request, e.g. write, query, etc.
        :type url: str
        :param method: the HTTP method for the request, defaults to GET
        :type method: str
        :param params: additional parameters for the request, defaults to None
        :type params: dict
        :param data: the data of the request, defaults to None
        :type data: str
        :param stream: True if a query uses chunked responses
        :type stream: bool
        :param expected_response_code: the expected response code of
            the request, defaults to 200
        :type expected_response_code: int
        :param headers: headers to add to the request
        :type headers: dict
        :returns: the response from the request
        :rtype: :class:`requests.Response`
        :raises InfluxDBServerError: if the response code is any server error
            code (5xx)
        :raises InfluxDBClientError: if the response code is not the
            same as `expected_response_code` and is not a server error code
        z{0}/{1}NrK)zAccept-EncodingzContent-Encodingé	Úw)Ú
compresslevelÚfileobjÚmodeTr)
ÚmethodÚurlÚauthÚparamsÚdataÚstreamÚheadersrIÚverifyrFr
ÚPOSTégY@zContent-Typezapplication/x-msgpackF)ÚpackedZext_hookÚrawcSs |jrtj|jddS|jSdS)N)ú,ú:)Ú
separators)Ú_msgpackÚjsonÚdumpsÚcontent)ÚresponserNrNrOÚreformat_errordsz.InfluxDBClient.request.<locals>.reformat_erroriôiX)*r8rTr=Ú
isinstanceÚdictÚlistryrzr>rZÚioÚBytesIOrKÚGzipFileÚwriteÚgetvaluer+Úrequestr!r"r5r&r$r)Ú
exceptionsÚConnectionErrorÚ	HTTPErrorÚTimeoutr%ÚtimeÚsleepÚrandomroÚgetr{ÚmsgpackZunpackbÚ_msgpack_parse_hookrxÚstatus_coderr)r?rjrirlrmrnÚexpected_response_coderoÚ
compressedÚfÚretryZ_tryr|Ztype_headerr}Úerr_msgrNrNrOr†sx





zInfluxDBClient.requestéÌrycCs‚|j}d|d<|r| d¡}nd}|dkr<t||ƒ d¡}n,|dkrht|tƒrT|g}d |¡d d¡}|jd	d
||||ddS)
aÊWrite data to InfluxDB.

        :param data: the data to be written
        :type data: (if protocol is 'json') dict
                    (if protocol is 'line') sequence of line protocol strings
                                            or single string
        :param params: additional parameters for the request, defaults to None
        :type params: dict
        :param expected_response_code: the expected response code of the write
            operation, defaults to 204
        :type expected_response_code: int
        :param protocol: protocol of input data, either 'json' or 'line'
        :type protocol: str
        :returns: True, if the write operation is successful
        :rtype: bool
        zapplication/octet-streamzContent-TypeÚ	precisionNryzutf-8ÚlineÚ
r„rq)rjrirlrmr’roT)r=rŽr	Úencoder~ÚstrÚjoinr†)r?rmrlr’Úprotocolror˜rNrNrOr„ss&
zInfluxDBClient.writeTccsŽxˆ| ¡D]|}t|tƒr"| d¡}t |¡}i}xF| dg¡D]6}x0|D](}t||tƒrH| |g¡ 	||¡qHWq>Wt
||dVq
WdS)Nzutf-8Úresults)Úraise_errors)Ú
iter_linesr~ÚbytesÚdecoderyÚloadsrŽr€Ú
setdefaultÚextendr)r|r r™rmZ
result_setÚresultÚ_keyrNrNrOÚ_read_chunked_responsežs



z%InfluxDBClient._read_chunked_responsercs|dkri}|dk	r>t | dd¡¡}| |¡t |¡|d<||d<|pN|j|d<|dk	rd||d<|r€d|d<|	d	kr€|	|d
<| ¡ d¡ržd| ¡kržd
}
|jd|
|d||d}|j	}
|
sÔ|rÌ| 
|¡S| ¡}
‡fdd„|
 dg¡Dƒ}t|ƒdkr|d	S|S)a¯Send a query to InfluxDB.

        .. danger::
            In order to avoid injection vulnerabilities (similar to `SQL
            injection <https://www.owasp.org/index.php/SQL_Injection>`_
            vulnerabilities), do not directly include untrusted data into the
            ``query`` parameter, use ``bind_params`` instead.

        :param query: the actual query string
        :type query: str

        :param params: additional parameters for the request,
            defaults to {}
        :type params: dict

        :param bind_params: bind parameters for the query:
            any variable in the query written as ``'$var_name'`` will be
            replaced with ``bind_params['var_name']``. Only works in the
            ``WHERE`` clause and takes precedence over ``params['params']``
        :type bind_params: dict

        :param epoch: response timestamps to be in epoch format either 'h',
            'm', 's', 'ms', 'u', or 'ns',defaults to `None` which is
            RFC3339 UTC format with nanosecond precision
        :type epoch: str

        :param expected_response_code: the expected status code of response,
            defaults to 200
        :type expected_response_code: int

        :param database: database to query, defaults to None
        :type database: str

        :param raise_errors: Whether or not to raise exceptions when InfluxDB
            returns errors, defaults to True
        :type raise_errors: bool

        :param chunked: Enable to use chunked responses from InfluxDB.
            With ``chunked`` enabled, one ResultSet is returned per chunk
            containing all results within that chunk
        :type chunked: bool

        :param chunk_size: Size of each chunk to tell InfluxDB to use.
        :type chunk_size: int

        :param method: the HTTP method for the request, defaults to GET
        :type method: str

        :returns: the queried data
        :rtype: :class:`~.ResultSet`
        Nrlz{}ÚqÚdbÚepochÚtrueÚchunkedrÚ
chunk_sizezselect z into rqÚquery)rjrirlrmrnr’csg|]}t|ˆd‘qS))r )r)Ú.0r§)r rNrOú
<listcomp>sz(InfluxDBClient.query.<locals>.<listcomp>rŸr
)ryr¤rŽrZrzr#ÚlowerÚ
startswithr†rxr©Úlen)r?r°rlZbind_paramsr¬r’rDr r®r¯riÚparams_dictr|rmrŸrN)r rOr°¬sB>


zInfluxDBClient.queryc	

CsV|r>|dkr>x,| ||¡D]}	|j|	||||||dqWdS|j|||||||dS)aêWrite to multiple time series names.

        :param points: the list of points to be written in the database
        :type points: list of dictionaries, each dictionary represents a point
        :type points: (if protocol is 'json') list of dicts, where each dict
                                            represents a point.
                    (if protocol is 'line') sequence of line protocol strings.
        :param time_precision: Either 's', 'm', 'ms' or 'u', defaults to None
        :type time_precision: str
        :param database: the database to write the points to. Defaults to
            the client's current database
        :type database: str
        :param tags: a set of key-value pairs associated with each point. Both
            keys and values must be strings. These are shared tags and will be
            merged with point-specific tags, defaults to None
        :type tags: dict
        :param retention_policy: the retention policy for the points. Defaults
            to None
        :type retention_policy: str
        :param batch_size: value to write the points in batches
            instead of all at one time. Useful for when doing data dumps from
            one database to another or when doing a massive write operation,
            defaults to None
        :type batch_size: int
        :param protocol: Protocol for writing data. Either 'line' or 'json'.
        :type protocol: str
        :param consistency: Consistency for the points.
            One of {'any','one','quorum','all'}.
        :type consistency: str
        :returns: True, if the operation is successful
        :rtype: bool

        .. note:: if no retention policy is specified, the default retention
            policy for the database is used
        r)ÚpointsÚtime_precisionrDÚretention_policyÚtagsržÚconsistencyT)Ú_batchesÚ
_write_points)
r?r·r¸rDr¹rºZ
batch_sizeržr»ÚbatchrNrNrOÚwrite_pointss-zInfluxDBClient.write_pointscCs|jdddd}|jdS)zrCheck connectivity to InfluxDB.

        :returns: The version of the InfluxDB the client is connected to
        Úpingrbr—)rjrir’zX-Influxdb-Version)r†ro)r?r|rNrNrOrÀYs
zInfluxDBClient.pingccsPt|ƒ}xByt|ƒf}Wntk
r,dSXt||dƒ}t||ƒVq
WdS)Nr
)ÚiterÚnextÚ
StopIterationrr)ÚiterableÚsizeÚiteratorÚheadÚrestrNrNrOr¼fszInfluxDBClient._batchesc
Cs¸|dkrtdƒ‚|dkr&td |¡ƒ‚|dkrHd|i}|dk	rL||d<n|}d|pV|ji}	|dk	rj||	d	<|dk	rz||	d
<|dk	rŠ||	d<|jr¢|j|||dn|j||	d
|ddS)N)ÚnÚuÚmsÚsÚmÚhNzFInvalid time precision is given. (use 'n', 'u', 'ms', 's', 'm' or 'h'))ÚanyZoneZquorumÚallNzInvalid consistency: {}ryr·rºr«r»r˜Úrp)ržr¸r—)rmrlr’ržT)r6r8r#rVÚsend_packetr„)
r?r·r¸rDr¹rºržr»rmrlrNrNrOr½ts4
zInfluxDBClient._write_pointscCst| d¡ ¡ƒS)a*Get the list of databases in InfluxDB.

        :returns: all databases in InfluxDB
        :rtype: list of dictionaries

        :Example:

        ::

            >> dbs = client.get_list_database()
            >> dbs
            [{u'name': u'db1'}, {u'name': u'db2'}, {u'name': u'db3'}]
        zSHOW DATABASES)r€r°Ú
get_points)r?rNrNrOÚget_list_database©sz InfluxDBClient.get_list_databasecCsl|p|j}d}|r |d |¡7}|rD|dd dd„| ¡Dƒ¡7}ttj dd„|j||d 	¡Dƒ¡ƒS)	aÅ
        Query SHOW SERIES returns the distinct series in your database.

        FROM and WHERE clauses are optional.

        :param measurement: Show all series from a measurement
        :type id: string
        :param tags: Show all series that match given tags
        :type id: dict
        :param database: the database from which the series should be
            shows, defaults to client's current database
        :type database: str
        zSHOW SERIESz FROM "{0}"z WHERE z and cSsg|]\}}d ||¡‘qS)z	{0}='{1}')r8)r±ÚkÚvrNrNrOr²Îsz2InfluxDBClient.get_list_series.<locals>.<listcomp>cSsg|]}| ¡‘qSrN)Úvalues)r±ÚxrNrNrOr²Ôs)rD)
r#r8rÚitemsr€Ú	itertoolsrÚ
from_iterabler°rÓ)r?rDÚmeasurementrºÚ	query_strrNrNrOÚget_list_series¹s
zInfluxDBClient.get_list_seriescCs|jd t|ƒ¡dddS)z€Create a new database in InfluxDB.

        :param dbname: the name of the database to create
        :type dbname: str
        zCREATE DATABASE {0}rq)riN)r°r8r
)r?ÚdbnamerNrNrOÚcreate_databaseÛszInfluxDBClient.create_databasecCs|jd t|ƒ¡dddS)zzDrop a database from InfluxDB.

        :param dbname: the name of the database to drop
        :type dbname: str
        zDROP DATABASE {0}rq)riN)r°r8r
)r?rßrNrNrOÚ
drop_databaseäszInfluxDBClient.drop_databasecCst| d¡ ¡ƒS)alGet the list of measurements in InfluxDB.

        :returns: all measurements in InfluxDB
        :rtype: list of dictionaries

        :Example:

        ::

            >> dbs = client.get_list_measurements()
            >> dbs
            [{u'name': u'measurements1'},
             {u'name': u'measurements2'},
             {u'name': u'measurements3'}]
        zSHOW MEASUREMENTS)r€r°rÓ)r?rNrNrOÚget_list_measurementsísz$InfluxDBClient.get_list_measurementscCs|jd t|ƒ¡dddS)zŠDrop a measurement from InfluxDB.

        :param measurement: the name of the measurement to drop
        :type measurement: str
        zDROP MEASUREMENT {0}rq)riN)r°r8r
)r?rÜrNrNrOÚdrop_measurementÿszInfluxDBClient.drop_measurementÚ0scCsBd t|ƒt|p|jƒ|||¡}|dkr0|d7}|j|dddS)aèCreate a retention policy for a database.

        :param name: the name of the new retention policy
        :type name: str
        :param duration: the duration of the new retention policy.
            Durations such as 1h, 90m, 12h, 7d, and 4w, are all supported
            and mean 1 hour, 90 minutes, 12 hours, 7 day, and 4 weeks,
            respectively. For infinite retention - meaning the data will
            never be deleted - use 'INF' for duration.
            The minimum retention period is 1 hour.
        :type duration: str
        :param replication: the replication of the retention policy
        :type replication: str
        :param database: the database for which the retention policy is
            created. Defaults to current client's database
        :type database: str
        :param default: whether or not to set the policy as default
        :type default: bool
        :param shard_duration: the shard duration of the retention policy.
            Durations such as 1h, 90m, 12h, 7d, and 4w, are all supported and
            mean 1 hour, 90 minutes, 12 hours, 7 day, and 4 weeks,
            respectively. Infinite retention is not supported. As a workaround,
            specify a "1000w" duration to achieve an extremely long shard group
            duration. Defaults to "0s", which is interpreted by the database
            to mean the default value given the duration.
            The minimum shard group duration is 1 hour.
        :type shard_duration: str
        zRCREATE RETENTION POLICY {0} ON {1} DURATION {2} REPLICATION {3} SHARD DURATION {4}Tz DEFAULTrq)riN)r8r
r#r°)r?ÚnameÚdurationÚreplicationrDÚdefaultÚshard_durationÚquery_stringrNrNrOÚcreate_retention_policys 
z&InfluxDBClient.create_retention_policycCstd t|ƒt|p|jƒ|¡}|r.|d |¡7}|r@|d |¡7}|rR|d |¡7}|dkrb|d7}|j|ddd	S)
a9Modify an existing retention policy for a database.

        :param name: the name of the retention policy to modify
        :type name: str
        :param database: the database for which the retention policy is
            modified. Defaults to current client's database
        :type database: str
        :param duration: the new duration of the existing retention policy.
            Durations such as 1h, 90m, 12h, 7d, and 4w, are all supported
            and mean 1 hour, 90 minutes, 12 hours, 7 day, and 4 weeks,
            respectively. For infinite retention, meaning the data will
            never be deleted, use 'INF' for duration.
            The minimum retention period is 1 hour.
        :type duration: str
        :param replication: the new replication of the existing
            retention policy
        :type replication: int
        :param default: whether or not to set the modified policy as default
        :type default: bool
        :param shard_duration: the shard duration of the retention policy.
            Durations such as 1h, 90m, 12h, 7d, and 4w, are all supported and
            mean 1 hour, 90 minutes, 12 hours, 7 day, and 4 weeks,
            respectively. Infinite retention is not supported. As a workaround,
            specify a "1000w" duration to achieve an extremely long shard group
            duration.
            The minimum shard group duration is 1 hour.
        :type shard_duration: str

        .. note:: at least one of duration, replication, or default flag
            should be set. Otherwise the operation will fail.
        z!ALTER RETENTION POLICY {0} ON {1}z
 DURATION {0}z SHARD DURATION {0}z REPLICATION {0}Tz DEFAULTrq)riN)r8r
r#r°)r?rårDrærçrèrérêrNrNrOÚalter_retention_policy2s#z%InfluxDBClient.alter_retention_policycCs,d t|ƒt|p|jƒ¡}|j|dddS)a0Drop an existing retention policy for a database.

        :param name: the name of the retention policy to drop
        :type name: str
        :param database: the database for which the retention policy is
            dropped. Defaults to current client's database
        :type database: str
        z DROP RETENTION POLICY {0} ON {1}rq)riN)r8r
r#r°)r?rårDrêrNrNrOÚdrop_retention_policycs
z$InfluxDBClient.drop_retention_policycCs8|s|jstdƒ‚| d t|p$|jƒ¡¡}t| ¡ƒS)a)Get the list of retention policies for a database.

        :param database: the name of the database, defaults to the client's
            current database
        :type database: str
        :returns: all retention policies for the database
        :rtype: list of dictionaries

        :Example:

        ::

            >> ret_policies = client.get_list_retention_policies('my_db')
            >> ret_policies
            [{u'default': True,
              u'duration': u'0',
              u'name': u'default',
              u'replicaN': 1}]
        zeget_list_retention_policies() requires a database as a parameter or the client to be using a databasezSHOW RETENTION POLICIES ON {0})r#rr°r8r
r€rÓ)r?rDZrsprNrNrOÚget_list_retention_policiesqs
z*InfluxDBClient.get_list_retention_policiescCst| d¡ ¡ƒS)ayGet the list of all users in InfluxDB.

        :returns: all users in InfluxDB
        :rtype: list of dictionaries

        :Example:

        ::

            >> users = client.get_list_users()
            >> users
            [{u'admin': True, u'user': u'user1'},
             {u'admin': False, u'user': u'user2'},
             {u'admin': False, u'user': u'user3'}]
        z
SHOW USERS)r€r°rÓ)r?rNrNrOÚget_list_usersszInfluxDBClient.get_list_userscCs2d t|ƒt|ƒ¡}|r |d7}|j|dddS)aPCreate a new user in InfluxDB.

        :param username: the new username to create
        :type username: str
        :param password: the password for the new user
        :type password: str
        :param admin: whether the user should have cluster administration
            privileges or not
        :type admin: boolean
        z!CREATE USER {0} WITH PASSWORD {1}z WITH ALL PRIVILEGESrq)riN)r8r
rr°)r?rBrCZadminÚtextrNrNrOÚcreate_user¢s
zInfluxDBClient.create_usercCs$djt|ƒdd}|j|dddS)znDrop a user from InfluxDB.

        :param username: the username to drop
        :type username: str
        z
DROP USER {0}rq)riN)r8r
r°)r?rBrðrNrNrOÚ	drop_user³szInfluxDBClient.drop_usercCs"d t|ƒt|ƒ¡}| |¡dS)zçChange the password of an existing user.

        :param username: the username who's password is being changed
        :type username: str
        :param password: the new password for the user
        :type password: str
        zSET PASSWORD FOR {0} = {1}N)r8r
rr°)r?rBrCrðrNrNrOÚset_user_password¼sz InfluxDBClient.set_user_passwordcCs`|p|j}d}|r$|d t|ƒ¡7}|rLdd„| ¡Dƒ}|dd |¡7}|j||ddd	S)
aDelete series from a database.

        Series must be filtered by either measurement and tags.
        This method cannot be used to delete all series, use
        `drop_database` instead.

        :param database: the database from which the series should be
            deleted, defaults to client's current database
        :type database: str
        :param measurement: Delete all series from a measurement
        :type measurement: str
        :param tags: Delete all series that match given tags
        :type tags: dict
        zDROP SERIESz	 FROM {0}cSs$g|]\}}d t|ƒt|ƒ¡‘qS)z{0}={1})r8r
r)r±rÕrÖrNrNrOr²Ýsz0InfluxDBClient.delete_series.<locals>.<listcomp>z WHERE z AND rq)rDriN)r#r8r
rÙrr°)r?rDrÜrºrÝZtag_eq_listrNrNrOÚ
delete_seriesÈs
zInfluxDBClient.delete_seriescCs d t|ƒ¡}|j|dddS)zýGrant cluster administration privileges to a user.

        :param username: the username to grant privileges to
        :type username: str

        .. note:: Only a cluster administrator can create/drop databases
            and manage users.
        zGRANT ALL PRIVILEGES TO {0}rq)riN)r8r
r°)r?rBrðrNrNrOÚgrant_admin_privilegesâs	z%InfluxDBClient.grant_admin_privilegescCs d t|ƒ¡}|j|dddS)aRevoke cluster administration privileges from a user.

        :param username: the username to revoke privileges from
        :type username: str

        .. note:: Only a cluster administrator can create/ drop databases
            and manage users.
        zREVOKE ALL PRIVILEGES FROM {0}rq)riN)r8r
r°)r?rBrðrNrNrOÚrevoke_admin_privilegesîs	z&InfluxDBClient.revoke_admin_privilegescCs(d |t|ƒt|ƒ¡}|j|dddS)a‡Grant a privilege on a database to a user.

        :param privilege: the privilege to grant, one of 'read', 'write'
            or 'all'. The string is case-insensitive
        :type privilege: str
        :param database: the database to grant the privilege on
        :type database: str
        :param username: the username to grant the privilege to
        :type username: str
        zGRANT {0} ON {1} TO {2}rq)riN)r8r
r°)r?Ú	privilegerDrBrðrNrNrOÚgrant_privilegeús
zInfluxDBClient.grant_privilegecCs(d |t|ƒt|ƒ¡}|j|dddS)aRevoke a privilege on a database from a user.

        :param privilege: the privilege to revoke, one of 'read', 'write'
            or 'all'. The string is case-insensitive
        :type privilege: str
        :param database: the database to revoke the privilege on
        :type database: str
        :param username: the username to revoke the privilege from
        :type username: str
        zREVOKE {0} ON {1} FROM {2}rq)riN)r8r
r°)r?r÷rDrBrðrNrNrOÚrevoke_privilege
s
zInfluxDBClient.revoke_privilegecCs d t|ƒ¡}t| |¡ ¡ƒS)a2Get the list of all privileges granted to given user.

        :param username: the username to get privileges of
        :type username: str

        :returns: all privileges granted to given user
        :rtype: list of dictionaries

        :Example:

        ::

            >> privileges = client.get_list_privileges('user1')
            >> privileges
            [{u'privilege': u'WRITE', u'database': u'db1'},
             {u'privilege': u'ALL PRIVILEGES', u'database': u'db2'},
             {u'privilege': u'NO PRIVILEGES', u'database': u'db3'}]
        zSHOW GRANTS FOR {0})r8r
r€r°rÓ)r?rBrðrNrNrOÚget_list_privilegessz"InfluxDBClient.get_list_privilegescCsd}dd„| |¡ ¡DƒS)a3Get the list of continuous queries in InfluxDB.

        :return: all CQs in InfluxDB
        :rtype: list of dictionaries

        :Example:

        ::

            >> cqs = client.get_list_cqs()
            >> cqs
            [
                {
                    u'db1': []
                },
                {
                    u'db2': [
                        {
                            u'name': u'vampire',
                            u'query': u'CREATE CONTINUOUS QUERY vampire ON '
                                       'mydb BEGIN SELECT count(dracula) INTO '
                                       'mydb.autogen.all_of_them FROM '
                                       'mydb.autogen.one GROUP BY time(5m) END'
                        }
                    ]
                }
            ]
        zSHOW CONTINUOUS QUERIEScSs g|]\}}|dt|ƒi‘qS)r)r€)r±ÚskÚprNrNrOr²Nsz>InfluxDBClient.get_list_continuous_queries.<locals>.<listcomp>)r°rÙ)r?rêrNrNrOÚget_list_continuous_queries0sz*InfluxDBClient.get_list_continuous_queriescCs8d t|ƒt|p|jƒ|r"d|nd|¡}| |¡dS)a–Create a continuous query for a database.

        :param name: the name of continuous query to create
        :type name: str
        :param select: select statement for the continuous query
        :type select: str
        :param database: the database for which the continuous query is
            created. Defaults to current client's database
        :type database: str
        :param resample_opts: resample options
        :type resample_opts: str

        :Example:

        ::

            >> select_clause = 'SELECT mean("value") INTO "cpu_mean" ' \
            ...                 'FROM "cpu" GROUP BY time(1m)'
            >> client.create_continuous_query(
            ...     'cpu_mean', select_clause, 'db_name', 'EVERY 10s FOR 2m'
            ... )
            >> client.get_list_continuous_queries()
            [
                {
                    'db_name': [
                        {
                            'name': 'cpu_mean',
                            'query': 'CREATE CONTINUOUS QUERY "cpu_mean" '
                                    'ON "db_name" '
                                    'RESAMPLE EVERY 10s FOR 2m '
                                    'BEGIN SELECT mean("value") '
                                    'INTO "cpu_mean" FROM "cpu" '
                                    'GROUP BY time(1m) END'
                        }
                    ]
                }
            ]
        z3CREATE CONTINUOUS QUERY {0} ON {1}{2} BEGIN {3} ENDz
 RESAMPLE rN)r8r
r#r°)r?råÚselectrDZ
resample_optsrêrNrNrOÚcreate_continuous_queryPs)z&InfluxDBClient.create_continuous_querycCs(d t|ƒt|p|jƒ¡}| |¡dS)a,Drop an existing continuous query for a database.

        :param name: the name of continuous query to drop
        :type name: str
        :param database: the database for which the continuous query is
            dropped. Defaults to current client's database
        :type database: str
        z DROP CONTINUOUS QUERY {0} ON {1}N)r8r
r#r°)r?rårDrêrNrNrOÚdrop_continuous_query~s
z$InfluxDBClient.drop_continuous_querycCsP|dkrt||ƒ d¡}n|dkr6d |¡d d¡}|j ||j|jf¡dS)ažSend an UDP packet.

        :param packet: the packet to be sent
        :type packet: (if protocol is 'json') dict
                      (if protocol is 'line') list of line protocol strings
        :param protocol: protocol of input data, either 'json' or 'line'
        :type protocol: str
        :param time_precision: Either 's', 'm', 'ms' or 'u', defaults to None
        :type time_precision: str
        ryzutf-8r™ršN)r	r›rr1Úsendtor9rU)r?Úpacketržr¸rmrNrNrOrҌs
zInfluxDBClient.send_packetcCst|jtjƒr|j ¡dS)zClose http session.N)r~r+r)r*rR)r?rNrNrOrRszInfluxDBClient.close)rrrrNFFNrFrNrrNFN)rbNNFrcN)Nr—ry)T)	NNNrcNTFrrb)NNNNNryN)ryN)NNN)NFrä)NNNNN)N)N)F)NNN)NN)N)ryN)4Ú__name__Ú
__module__Ú__qualname__Ú__doc__rPrQrSÚpropertyrTr9r:r;rUrVÚclassmethodr_r`rar†r„Ústaticmethodr©r°r¿rÀr¼r½rÔrÞràrárârãrërìrírîrïrñròrórôrõrörørùrúrýrÿrrÒrRrNrNrNrOrs¨6
D)
j
*
g
6

.
"		

(
/


	
 
-

rc	Cst|ƒ}i}|j d¡}t|ƒdkr2|d}d}n|\}}|dkrPtd |¡ƒ‚|r†|dkrfd|d	<n |d
krxd|d<ntd |¡ƒ‚|j d
¡}g|d<xJ|D]B}t|ƒ}|d |dt	|dƒf¡|d|d<|d|d<q W|j
rt|j
ƒdkr|j
dd…|d<|S)z‚Parse data source name.

    This is a helper function to split the data source name provided in
    the from_dsn classmethod
    ú+r
rNZinfluxdbzUnknown scheme "{0}".ZudpTrHrrEzUnknown modifier "{0}".rurWr@rArBrCrD)rÚschemeÚsplitrµr6r8ÚnetlocÚ
_parse_netlocÚappendrrJ)	r\Zconn_paramsr^Zscheme_inforÚmodifierZnetlocsr
ÚparsedrNrNrOrX£s2


rXcCs4td |¡ƒ}|jpd|jpd|jp&d|jp.ddœS)Nz
http://{0}ri–)rBrCr@rA)rr8rBrCÚhostnamerA)r
ÚinforNrNrOrÌs
rcCsP|dkrDt d|¡\}}tj |¡}|tj|dd7}| ¡dSt ||¡S)Néz>QIiè)ÚmicrosecondsÚZ)ÚstructÚunpackÚdatetimeÚutcfromtimestampÚ	timedeltaÚ	isoformatrZExtType)ÚcodermZepoch_sZepoch_nsÚ	timestamprNrNrOrÔsr)$rÚ
__future__rrrrrrKrÚrryrr.rr‹rrrr)Zrequests.exceptionsÚsix.moves.urllib.parserZinfluxdb.line_protocolr	r
rZinfluxdb.resultsetrr‡rrÚobjectrrXrrrNrNrNrOÚ<module>sF
)