本文整理汇总了Python中pymongo.database.Database.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Python Database.authenticate方法的具体用法?Python Database.authenticate怎么用?Python Database.authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.database.Database
的用法示例。
在下文中一共展示了Database.authenticate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_db
# 需要导入模块: from pymongo.database import Database [as 别名]
# 或者: from pymongo.database.Database import authenticate [as 别名]
def get_db(is_local_deployed=False):
if is_local_deployed:
#for local launch
connection = Connection()
db = connection.wiki
return db
else:
# for dotcloud launch
mongodb_info = json.load(file("/home/dotcloud/environment.json"))
print mongodb_info
connection = Connection(mongodb_info["DOTCLOUD_DATA_MONGODB_HOST"], int(mongodb_info["DOTCLOUD_DATA_MONGODB_PORT"]))
database = Database(connection, "wiki")
database.authenticate("xinz", "hellopy")
db = connection.wiki
return db
示例2: connect
# 需要导入模块: from pymongo.database import Database [as 别名]
# 或者: from pymongo.database.Database import authenticate [as 别名]
def connect(conf, prod):
log.info('setting up mongo connection')
url = conf.get('mongo', 'url')
port = conf.getint('mongo', 'port')
db = conf.get('mongo', 'db')
conn = Connection(url, port)
db = Database(conn, db)
if (prod):
log.info('authenticating mongo connection')
username = conf.get('mongo', 'username')
pwd = conf.get('mongo', 'password')
db.authenticate(username, pwd)
return db
示例3: init_connection
# 需要导入模块: from pymongo.database import Database [as 别名]
# 或者: from pymongo.database.Database import authenticate [as 别名]
def init_connection(self):
if hasattr(self, 'app'):
config = self.app.config
else:
config = self._default_config
connection = Connection(
host=config.get('MONGODB_HOST'),
port=config.get('MONGODB_PORT'),
slave_okay=config.get('MONGODB_SLAVE_OKAY')
)
database = Database(connection, config.get('MONGODB_DATABASE'))
if config.get('MONGODB_USERNAME') is not None:
database.authenticate(
config.get('MONGODB_USERNAME'),
config.get('MONGODB_PASSWORD')
)
return connection, database
示例4: MongoClient
# 需要导入模块: from pymongo.database import Database [as 别名]
# 或者: from pymongo.database.Database import authenticate [as 别名]
# -*- encoding: utf-8 -*-
'''
Created on 2014-11-7
@author: [email protected]
'''
import pymongo
from pymongo.database import Database
from pymongo.mongo_client import MongoClient
from pymongo.collection import Collection
from gridfs import GridFS
if __name__ == '__main__':
con = pymongo.Connection('172.16.10.170', 27017)
# con = MongoClient(host='172.16.10.170', port=27017, max_pool_size=200)
db = Database(con, 'blog')
db.authenticate('admin', 'admin')
coll = Collection(db, 'foo')
coll.insert({'a':1, 'b':2, 'c':3})
# coll.update({'a':1}, {'$set':{'b':4}}, multi=True)
print [x for x in coll.find()]
# MongoClient()
# print user.find({'id':1}).count()
pass
示例5: unicode
# 需要导入模块: from pymongo.database import Database [as 别名]
# 或者: from pymongo.database.Database import authenticate [as 别名]
record[ headers[ii] ] = unicode( row[ii], 'utf-8' )
erase(record)
pass
def erase( record ):
db['global'].remove(record)
if __name__ == "__main__" :
if ( len(sys.argv) != 4 ):
print "Usage: %s <username> <password> <csv-files>" % sys.argv[0]
username = sys.argv[1]
password = sys.argv[2]
csv_file = sys.argv[3]
print username
print password
print csv_file
connection = Connection() # Replace with mongo-url
db = Database(connection,'zip') # Get zip database
db.authenticate(username,password) # Authenticate
remove( csv_file )
示例6: Mongoop
# 需要导入模块: from pymongo.database import Database [as 别名]
# 或者: from pymongo.database.Database import authenticate [as 别名]
class Mongoop(object):
def __init__(self, mongodb_host, mongodb_port, mongodb_credentials=None,
mongodb_options=None, frequency=0, op_triggers=None,
balancer_triggers=None, threshold_timeout=None, query=None):
try:
# mongodb
self._mongodb_host = mongodb_host
self._mongodb_port = mongodb_port
self._mongodb_credentials = mongodb_credentials or {}
self._mongodb_options = mongodb_options or {}
# mongoop triggers
self._frequency = frequency or 30
self.op_triggers = op_triggers or {}
self.balancer_triggers = balancer_triggers or {}
self._threshold_timeout = threshold_timeout or 60
self._query = query or {}
# NOTE: retrieve the minimum threshold.
if self.op_triggers:
self._threshold_timeout = min([v['threshold'] for v in self.op_triggers.values() if 'threshold' in v])
self._base_op_query = {
'secs_running': {'$gte': self._threshold_timeout},
'op': {'$ne': 'none'}
}
self._base_op_query.update(self._query)
self.conn = MongoClient(
host=self._mongodb_host,
port=self._mongodb_port,
read_preference=ReadPreference.PRIMARY,
**self._mongodb_options
)
self.db = Database(self.conn, 'admin')
if self._mongodb_credentials:
# NOTE: avoid a breaking chance since the version 0.5
username = self._mongodb_credentials.get('name') or self._mongodb_credentials.get('username')
self.db.authenticate(username, self._mongodb_credentials['password'])
# NOTE: add the callable for each trigger
self.cycle_op_triggers = []
self.cycle_balancer_triggers = []
for t_name, t_values in self.op_triggers.items():
_callable = self._get_trigger_callable(t_name, t_values)
if _callable:
self.cycle_op_triggers.append(_callable)
for t_name, t_values in self.balancer_triggers.items():
_callable = self._get_trigger_callable(t_name, t_values, category='balancer')
if _callable:
self.cycle_balancer_triggers.append(_callable)
except TypeError as e:
logging.error('unable to authenticate to admin database :: {}'.format(e))
exit(1)
except OperationFailure as e:
logging.error('authentication failure :: {}'.format(e))
except ConnectionFailure as e:
logging.error('unable to connect to database :: {}'.format(e))
else:
logging.info('start mongoop :: {}'.format(self))
def __str__(self):
return u'{} :: frequency={} :: slow_query={} :: op_triggers={} :: balancer_triggers={}'.format(
self.conn, self._frequency, self._base_op_query, len(self.cycle_op_triggers),
len(self.cycle_balancer_triggers))
def __call__(self):
""" Main function.
"""
while True:
start = time()
self.call_op_triggers()
self.call_balancer_triggers()
exec_time = time() - start
if exec_time < self._frequency:
sleep(self._frequency - exec_time)
def call_op_triggers(self):
""" Main function to run the op triggers.
"""
operations = self._current_op()
for trigger in self.cycle_op_triggers:
trigger.run(operations=operations)
def call_balancer_triggers(self):
""" Main function to run the balancer triggers.
"""
if not self.balancer_triggers:
return True
balancer_state = self._get_balancer_state()
for trigger in self.cycle_balancer_triggers:
trigger.run(balancer_state=balancer_state)
def _get_trigger_callable(self, trigger_name, trigger_params, category='op'):
""" Retrieve the corresponding trigger by name and add into the triggers list.
#.........这里部分代码省略.........
示例7: Copyright
# 需要导入模块: from pymongo.database import Database [as 别名]
# 或者: from pymongo.database.Database import authenticate [as 别名]
Created by AFD on 2010-10-14.
Copyright (c) 2010 A. Frederick Dudley. All rights reserved.
"""
from stores.mongo_store import *
from stores.store import *
from pymongo.connection import Connection
from pymongo.database import Database
from binary_tactics.player import Player
from binary_tactics.helpers import *
from binary_tactics.weapons import *
from binary_tactics.units import *
from binary_tactics.stone import *
connection = Connection(host='bt.hipeland.org')
db = Database(connection, 'binary_tactics')
db.authenticate('rix', 'fhpxguvf'.decode('rot13'))
exists = {'$exists': True}
#squads = db.binary_tactics.find({'squad': exists})
#grids = db.binary_tactics.find({'grid': exists})
#squad = [convert_dict(get_dict(db.binary_tactics.find({'squad.value': 1004})[0], db.binary_tactics, db))]
squad = [rand_squad()]
units = [n for n in squad[0]]
weapons = [n.weapon for n in squad[0]]
stones = [rand_comp() for n in xrange(6)]
w = Player('The World', squad, stones, units, weapons, [])