
client Package
**************


"client" Package
================


"blob" Module
=============

class class crate.client.blob.BlobContainer(container_name, connection)

   Bases: "object"

   class that represents a blob collection in crate.

   can be used to download, upload and delete blobs

   delete(digest)

      Delete a blob

      Parameters:
         **digest** -- the hex digest of the blob to be deleted

      Returns:
         True if blob existed

   exists(digest)

      Check if a blob exists

      Parameters:
         **digest** -- Hex digest of the blob

      Returns:
         Boolean indicating existence of the blob

   get(digest)

      Return the contents of a blob

      Parameters:
         **digest** -- the hex digest of the blob to return

      Returns:
         generator returning chunks of data

   put(f, digest=None)

      Upload a blob

      Parameters:
         * **f** -- File object to be uploaded (required to support
           seek if digest is not provided)

         * **digest** -- Optional SHA-1 hex digest of the file
           contents. Gets computed before actual upload if not
           provided, which requires an extra file read.

      Returns:
         The hex digest of the uploaded blob if not provided in the
         call. Otherwise a boolean indicating if the blob has been
         newly created


"compat" Module
===============

crate.client.compat.cprint(s)


"connection" Module
===================

class class crate.client.connection.Connection(servers=None, timeout=None, client=None)

   Bases: "object"

   close()

      Close the connection now

   commit()

      Transactions are not supported, so "commit" is not implemented.

   cursor()

      Return a new Cursor Object using the connection.

   get_blob_container(container_name)

      Retrieve a BlobContainer for *container_name*

      Parameters:
         **container_name** -- the name of the BLOB container.

      Returns:
         a :class:ContainerObject

crate.client.connection.connect(servers=None, timeout=None, client=None)

   Create a :class:Connection object

   Parameters:
      * **servers** -- either a string in the form of
        '<hostname>:<port>' or a list of servers in the form of
        ['<hostname>:<port>', '...']

      * **timeout** -- (optional) define the retry timeout for
        unreachable servers in seconds

      * **client** -- (optional - for testing) client used to
        communicate with crate.

   >>> connect(['host1:9200', 'host2:9200'])
   <Connection <Client ['host1:9200', 'host2:9200']>>


"crash" Module
==============

crate cli

can be used to query crate using SQL

class class crate.client.crash.CrateCmd(*args)

   Bases: "cmd.Cmd"

   cols()

   do_EOF(arg)

   do_connect(server)

      connect to one or more server with "connect servername:port"

   do_delete(statement)

      execute a SQL delete statement

      E.g.:
         "delete from locations where name = 'Algol'

   do_exit(*args)

      exit the shell

   do_insert(statement)

      execute a SQL insert statement

      E.g.:
         "insert into locations (name) values ('Algol')

   do_quit(*args)

      exit the shell

   do_select(statement)

      execute a SQL select statement

      E.g.:
         "select name from locations where name = 'Algol'"

   do_update(statement)

      execute a SQL update statement

      E.g.:
         "update from locations set name = 'newName' where name =
         'Algol'

   execute(statement)

   execute_query(statement)

   pprint(rows)

   prompt = 'cr> '

crate.client.crash.main()


"cursor" Module
===============

class class crate.client.cursor.Cursor(connection)

   Bases: "object"

   not thread-safe by intention should not be shared between different
   threads

   close()

      Close the cursor now

   description

      This read-only attribute is a sequence of 7-item sequences.

   execute(sql, parameters=None)

      Prepare and execute a database operation (query or command).

   executemany(sql, seq_of_parameters)

      Prepare a database operation (query or command) and then execute
      it against all parameter sequences or mappings found in the
      sequence "seq_of_parameters".

   fetchall()

      Fetch all (remaining) rows of a query result, returning them as
      a sequence of sequences (e.g. a list of tuples). Note that the
      cursor's arraysize attribute can affect the performance of this
      operation.

   fetchmany(count=None)

      Fetch the next set of rows of a query result, returning a
      sequence of sequences (e.g. a list of tuples). An empty sequence
      is returned when no more rows are available.

   fetchone()

      Fetch the next row of a query result set, returning a single
      sequence, or None when no more data is available. Alias for
      "next()".

   lastrowid = None

   next()

      Fetch the next row of a query result set, returning a single
      sequence, or None when no more data is available.

   rowcount

      This read-only attribute specifies the number of rows that the
      last .execute*() produced (for DQL statements like "SELECT") or
      affected (for DML statements like "UPDATE" or "INSERT").

   setinputsizes(sizes)

      Not supported method.

   setoutputsize(size, column=None)

      Not supported method.


"exceptions" Module
===================

exception exception crate.client.exceptions.BlobException(table, digest)

   Bases: "exceptions.Exception"

exception exception crate.client.exceptions.ConnectionError(msg=None)

   Bases: "crate.client.exceptions.OperationalError"

exception exception crate.client.exceptions.DataError(msg=None)

   Bases: "crate.client.exceptions.DatabaseError"

exception exception crate.client.exceptions.DatabaseError(msg=None)

   Bases: "crate.client.exceptions.Error"

exception exception crate.client.exceptions.DigestNotFoundException(table, digest)

   Bases: "crate.client.exceptions.BlobException"

exception exception crate.client.exceptions.Error(msg=None)

   Bases: "exceptions.StandardError"

exception exception crate.client.exceptions.IntegrityError(msg=None)

   Bases: "crate.client.exceptions.DatabaseError"

exception exception crate.client.exceptions.InterfaceError(msg=None)

   Bases: "crate.client.exceptions.Error"

exception exception crate.client.exceptions.InternalError(msg=None)

   Bases: "crate.client.exceptions.DatabaseError"

exception exception crate.client.exceptions.NotSupportedError(msg=None)

   Bases: "crate.client.exceptions.DatabaseError"

exception exception crate.client.exceptions.OperationalError(msg=None)

   Bases: "crate.client.exceptions.DatabaseError"

exception exception crate.client.exceptions.ProgrammingError(msg=None)

   Bases: "crate.client.exceptions.DatabaseError"

exception exception crate.client.exceptions.Warning

   Bases: "exceptions.StandardError"


"http" Module
=============

class class crate.client.http.Client(servers=None, timeout=None)

   Bases: "object"

   Crate connection client using crate's HTTP API.

   blob_del(table, digest)

      Deletes the blob with given digest under the given table.

   blob_exists(table, digest)

      Returns true if the blob with the given digest exists under the
      given table.

   blob_get(table, digest, chunk_size=131072)

      Returns a file like object representing the contents of the blob
      with the given digest.

   blob_put(table, digest, data)

      Stores the contents of the file like @data object in a blob
      under the given table and digest.

   default_server = '127.0.0.1:9200'

      Default server to use if no servers are given on instantiation.

   retry_interval = 30

      Retry interval for failed servers in seconds.

   sql(stmt, parameters=None)

      Execute SQL stmt against the crate server.

   sql_path = '_sql'

      Crate URI path for issuing SQL statements.


"test_cursor" Module
====================

class class crate.client.test_cursor.CursorTest(methodName='runTest')

   Bases: "unittest.case.TestCase"

   test_execute_with_args()


"test_http" Module
==================

class class crate.client.test_http.HttpClientTest(methodName='runTest')

   Bases: "unittest.case.TestCase"

   test_http_error_is_re_raised(*args, **keywargs)

   test_http_error_is_re_raised_in_raise_for_status(*args, **keywargs)

   test_no_connection_exception()

   test_programming_error_contains_http_error_response_content(*args, **keywargs)

class class crate.client.test_http.ThreadSafeHttpClientTest(*args, **kwargs)

   Bases: "unittest.case.TestCase"

   Using a pool of 5 Threads to emit commands to the multiple servers
   through one Client-instance

   check if number of servers in _inactive_servers and _active_servers
   always euqals the number of servers initially given.

   num_commands = 1000

   num_threads = 5

   servers = ['127.0.0.1:9200', '127.0.0.2:9200', '127.0.0.3:9200']

   test_client_threaded(*args, **keywargs)

      Testing if lists of servers is handled correctly when client is
      used from multiple threads with some requests failing.

      **ATTENTION:** this test is probabilistic and does not ensure
      that the client is indeed thread-safe in all cases, it can only
      show that it withstands this scenario.

   thread_timeout = 5.0

crate.client.test_http.fail_sometimes_fake_request(*args, **kwargs)

crate.client.test_http.fake_request(*args, **kwargs)

crate.client.test_http.fake_request_lazy_raise(*args, **kwargs)
