concrete.util.access module¶
-
class
concrete.util.access.CommunicationContainerFetchHandler(communication_container)¶ Bases:
objectFetchCommunicationService implementation using Communication containers
Implements the
FetchCommunicationServiceinterface, retrieving Communications from a dict-like communication_container object that maps Communication ID strings to Communications. The communication_container could be an actual dict, or a container such as:DirectoryBackedCommunicationContainerFetchBackedCommunicationContainerMemoryBackedCommunicationContainerRedisHashBackedCommunicationContainerZipFileBackedCommunicationContainerS3BackedCommunicationContainer
Usage:
from concrete.util.access_wrapper import FetchCommunicationServiceWrapper handler = CommunicationContainerFetchHandler(comm_container) fetch_service = FetchCommunicationServiceWrapper(handler) fetch_service.serve(host, port)
Parameters: communication_container – Dict-like object that maps Communication IDs to Communications -
about()¶
-
alive()¶
-
fetch(fetch_request)¶
-
getCommunicationCount()¶
-
getCommunicationIDs(offset, count)¶
-
class
concrete.util.access.DirectoryBackedStoreHandler(store_path)¶ Bases:
objectSimple StoreCommunicationService implementation using a directory
Implements the
StoreCommunicationServiceinterface, storing Communications in a directory.Parameters: store_path – Path where Communications should be Stored -
about()¶
-
alive()¶
-
store(communication)¶ Save Communication to a directory
Stored Communication files will be named [COMMUNICATION_ID].comm. If a file with that name already exists, it will be overwritten.
-
-
class
concrete.util.access.RedisHashBackedStoreHandler(redis_db, key)¶ Bases:
objectSimple StoreCommunicationService implementation using a Redis hash.
Implements the
StoreCommunicationServiceinterface, storing Communications in a Redis hash, indexed by id.Parameters: - redis_db (redis.Redis) – Redis database connection object
- key (str) – key of hash in redis database
-
about()¶
-
alive()¶
-
store(communication)¶ Save Communication to a Redis hash, using the Communication id as a key.
Parameters: communication (Communication) – communication to store
-
class
concrete.util.access.RelayFetchHandler(host, port)¶ Bases:
objectImplements a ‘relay’ to another
FetchCommunicationServiceserver.A
FetchCommunicationServicethat acts as a relay to a secondFetchCommunicationService, where the second service is using the TSocket transport and TCompactProtocol protocol.This class was designed for the use case where you have Thrift JavaScript code that needs to communicate with a
FetchCommunicationServiceserver, but the server does not support the same Thrift serialization protocol as the JavaScript client.The de-facto standard for Concrete services is to use the TCompactProtocol serialization protocol over a TSocket connection. But as of Thrift 0.10.0, the Thrift JavaScript libraries only support using TJSONProtocol over HTTP.
The RelayFetchHandler class is intended to be used as server-side code by a web application. The JavaScript code will make
FetchCommunicationServiceRPC calls to the web server using HTTP/TJSONProtocol, and the web application will then pass these RPC calls to anotherFetchCommunicationServiceusing TSocket/TCompactProtocol RPC calls.Parameters: - host (str) – Hostname of
FetchCommunicationServiceserver - port (int) – Port # of
FetchCommunicationServiceserver
-
about()¶
-
alive()¶
-
fetch(request)¶
-
getCommunicationCount()¶
-
getCommunicationIDs(offset, count)¶
- host (str) – Hostname of
-
class
concrete.util.access.S3BackedStoreHandler(bucket, prefix_len=4)¶ Bases:
objectSimple StoreCommunicationService implementation using an AWS S3 bucket.
Implements the
StoreCommunicationServiceinterface, storing Communications in an S3 bucket, indexed by id, optionally prefixed with a fixed-length, random-looking but deterministic hash to improve performance.References
http://docs.aws.amazon.com/AmazonS3/latest/dev/request-rate-perf-considerations.html
Parameters: - bucket (boto.s3.bucket.Bucket) – S3 bucket object
- prefix_len (int) – length of prefix to add to a Communication id to form its key. A prefix of length four enables S3 to better partition the bucket contents, yielding higher performance and a lower chance of getting rate-limited by AWS.
-
about()¶ Return S3BackedStoreHandler service information.
Returns: An object of type ServiceInfo
-
alive()¶ Return whether service is alive and running.
Returns: True or False
-
store(communication)¶ Save Communication to an S3 bucket, using the Communication id with a hash prefix of length self.prefix_len as a key.
Parameters: communication (Communication) – communication to store
-
concrete.util.access.prefix_s3_key(key_str, prefix_len)¶ Given unprefixed S3 key key_str, prefix the key with a deterministic prefix of hex characters of length prefix_len and return the result. Keys with such prefixes enable better performance on S3 and reduce the likelihood of rate-limiting.
Parameters: - key_str (str) – original (unprefixed) key, as a string
- prefix_len (int) – length of prefix to add to key
Returns: prefixed key
References
http://docs.aws.amazon.com/AmazonS3/latest/dev/request-rate-perf-considerations.html
-
concrete.util.access.unprefix_s3_key(prefixed_key_str, prefix_len)¶ Given prefixed S3 key key_str, remove prefix of length prefix_len from the key and return the result. Keys with random-looking prefixes enable better performance on S3 and reduce the likelihood of rate-limiting.
Parameters: - preixed_key_str (str) – prefixed key, as a string
- prefix_len (int) – length of prefix to remove from key
Returns: unprefixed key
References
http://docs.aws.amazon.com/AmazonS3/latest/dev/request-rate-perf-considerations.html