本文整理汇总了Python中pymongo.connection.Connection.name方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.name方法的具体用法?Python Connection.name怎么用?Python Connection.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.connection.Connection
的用法示例。
在下文中一共展示了Connection.name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DatastoreMongoStub
# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import name [as 别名]
class DatastoreMongoStub(apiproxy_stub.APIProxyStub):
"""Persistent stub for the Python datastore API, using MongoDB to persist.
A DatastoreMongoStub instance handles a single app's data.
"""
_NO_TRANSACTION_WARNING_LOGGED = False
def __init__(self,
app_id,
datastore_file,
history_file,
require_indexes=False,
service_name='datastore_v3',
auto_increment_ids=True):
"""Constructor.
Initializes the datastore stub.
Args:
app_id: string
datastore_file: ignored
history_file: ignored
require_indexes: bool, default False. If True, composite indexes must
exist in index.yaml for queries that need them.
service_name: Service name expected for all calls.
auto_increment_ids: Use incrementing integer IDs for new entities.
"""
super(DatastoreMongoStub, self).__init__(service_name)
assert isinstance(app_id, basestring) and app_id != ''
self.__app_id = app_id
self.__require_indexes = require_indexes
self.__auto_increment_ids = auto_increment_ids
# TODO should be a way to configure the connection
self.__db = Connection()[app_id]
# Setup the intid client
if auto_increment_ids:
self.intid = IntidClient()
else:
self.intid = None
# NOTE our query history gets reset each time the server restarts...
# should this be fixed?
self.__query_history = {}
self.__next_index_id = 1
self.__indexes = {}
self.__index_lock = threading.Lock()
self.__cursor_lock = threading.Lock()
self.__next_cursor = 1
self.__queries = {}
def MakeSyncCall(self, service, call, request, response):
""" The main RPC entry point. service must be 'datastore_v3'. So far, the
supported calls are 'Get', 'Put', 'RunQuery', 'Next', and 'Count'.
"""
super(DatastoreMongoStub, self).MakeSyncCall(service,
call,
request,
response)
explanation = []
assert response.IsInitialized(explanation), explanation
def QueryHistory(self):
"""Returns a dict that maps Query PBs to times they've been run.
"""
return dict((pb, times) for pb, times in self.__query_history.items()
if pb.app() == self.__app_id)
def __collection_for_key(self, key):
return key.path().element(-1).type()
def __id_for_key(self, key):
db_path = []
def add_element_to_db_path(elem):
db_path.append(elem.type())
if elem.has_name():
db_path.append(elem.name())
else:
db_path.append("\t" + str(elem.id()))
for elem in key.path().element_list():
add_element_to_db_path(elem)
return "\10".join(db_path)
def __key_for_id(self, id):
def from_db(value):
if value.startswith("\t"):
return int(value[1:])
return value
return datastore_types.Key.from_path(*[from_db(a) for a in id.split("\10")])
def __create_mongo_value_for_value(self, value):
if isinstance(value, datastore_types.Rating):
return {
#.........这里部分代码省略.........
示例2: DatastoreMongoStub
# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import name [as 别名]
class DatastoreMongoStub(apiproxy_stub.APIProxyStub):
"""Persistent stub for the Python datastore API, using MongoDB to persist.
A DatastoreMongoStub instance handles a single app's data.
"""
def __init__(self,
app_id,
datastore_file=None,
require_indexes=False,
service_name='datastore_v3'):
"""Constructor.
Initializes the datastore stub.
Args:
app_id: string
datastore_file: ignored
require_indexes: bool, default False. If True, composite indexes must
exist in index.yaml for queries that need them.
service_name: Service name expected for all calls.
"""
super(DatastoreMongoStub, self).__init__(service_name)
assert isinstance(app_id, basestring) and app_id != ''
self.__app_id = app_id
self.__require_indexes = require_indexes
self.__trusted = True
# TODO should be a way to configure the connection
self.__db = Connection()[app_id]
# NOTE our query history gets reset each time the server restarts...
# should this be fixed?
self.__query_history = {}
self.__next_index_id = 1
self.__indexes = {}
self.__index_lock = threading.Lock()
self.__cursor_lock = threading.Lock()
self.__next_cursor = 1
self.__queries = {}
self.__id_lock = threading.Lock()
self.__id_map = {}
# Transaction support
self.__next_tx_handle = 1
self.__tx_writes = {}
self.__tx_deletes = set()
self.__tx_actions = []
self.__tx_lock = threading.Lock()
def Clear(self):
"""Clears the datastore.
This is mainly for testing purposes and the admin console.
"""
for name in self.__db.collection_names():
if not name.startswith('system.'):
self.__db.drop_collection(name)
self.__queries = {}
self.__query_history = {}
self.__indexes = {}
self.__id_map = {}
self.__next_tx_handle = 1
self.__tx_writes = {}
self.__tx_deletes = set()
self.__tx_actions = []
self.__db.datastore.drop()
def MakeSyncCall(self, service, call, request, response):
""" The main RPC entry point. service must be 'datastore_v3'.
So far, the supported calls are 'Get', 'Put', 'Delete', 'RunQuery', 'Next',
and 'AllocateIds'.
"""
self.AssertPbIsInitialized(request)
super(DatastoreMongoStub, self).MakeSyncCall(
service, call, request, response)
self.AssertPbIsInitialized(response)
def AssertPbIsInitialized(self, pb):
"""Raises an exception if the given PB is not initialized and valid."""
explanation = []
assert pb.IsInitialized(explanation), explanation
pb.Encode()
def QueryHistory(self):
"""Returns a dict that maps Query PBs to times they've been run."""
return dict((pb, times) for pb, times in self.__query_history.items()
if pb.app() == self.__app_id)
def __collection_for_key(self, key):
collection = key.path().element(-1).type()
#.........这里部分代码省略.........