Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
yield motor.Op(self.app.mongodb.worldprop.insert,
{'wid':self.exwid, 'locid':self.exlocid,
'key':'x', 'val':0})
yield motor.Op(self.app.mongodb.worldprop.insert,
{'wid':self.exwid, 'locid':self.exlocid,
'key':'w', 'val':'world'})
yield motor.Op(self.app.mongodb.worldprop.insert,
{'wid':self.exwid, 'locid':None,
'key':'r', 'val':11})
yield motor.Op(self.app.mongodb.worldprop.insert,
{'wid':self.exwid, 'locid':self.exlocid,
'key':'r', 'val':12})
yield motor.Op(self.app.mongodb.instanceprop.remove,
{})
yield motor.Op(self.app.mongodb.instanceprop.insert,
{'iid':self.exiid, 'locid':self.exlocid,
'key':'x', 'val':1})
yield motor.Op(self.app.mongodb.instanceprop.insert,
{'iid':self.exiid, 'locid':self.exlocid,
'key':'y', 'val':2})
yield motor.Op(self.app.mongodb.instanceprop.insert,
{'iid':self.exiid, 'locid':self.exlocid,
'key':'ls', 'val':[1,2,3]})
yield motor.Op(self.app.mongodb.instanceprop.insert,
{'iid':self.exiid, 'locid':self.exlocid,
'key':'map', 'val':{'one':1, 'two':2, 'three':3}})
yield motor.Op(self.app.mongodb.instanceprop.insert,
{'iid':self.exiid, 'locid':None,
'key':'r', 'val':13})
yield motor.Op(self.app.mongodb.instanceprop.insert,
{'iid':self.exiid, 'locid':self.exlocid,
bar = Field(int, required=False)
moo = Field(list)
Doc.register(client=MOTOR_CLIENT, db='nanotestdb')
d = Doc(foo=six.u('foo value'), bar=42)
d.moo = []
yield motor.Op(d.insert)
del d.bar # unset
yield motor.Op(d.save)
result = yield motor.Op(Doc.find_one, {'_id': d._id})
self.assertEqual(d, result)
d.foo = six.u('new foo')
d['bar'] = 1337
d.moo = ['moo 0']
yield motor.Op(d.save, atomic=True)
result = yield motor.Op(Doc.find_one, {'foo': six.u('new foo'), 'bar': 1337})
self.assertEqual(d, result)
d.moo = []
del d['bar']
yield motor.Op(d.save)
result = yield motor.Op(Doc.find_one, {'_id': d._id})
self.assertEqual(d, result)
def find(self, spec=None, count=0, callback=None):
cursor = self.collection.find(spec).limit(count)
docs = yield motor.Op(cursor.to_list)
callback(docs)
def doTest(db):
test_discussion_tree = TestDiscussionTree(db)
try:
yield motor.Op(test_discussion_tree.destroy_discussion_tree) # This blats the whole DB to start from scratch every time.
yield motor.Op(test_discussion_tree.pdt.setup_indexes) # Ensure indexes on DiscussionTree related collections
yield motor.Op(test_discussion_tree.setup_reputations) # Setup some reputations to apply to the discussion tree.
yield motor.Op(test_discussion_tree.create_discussion_tree) # Create a discussion tree.
yield motor.Op(test_discussion_tree.dump_tree, "a", 0) # Do a recursive dump of the discussion tree, with reputations.
except AsyncException as e:
e.stack_trace()
sys.exit(1)
print("Done.")
sys.exit(0)
def post(self):
try:
wid = ObjectId(self.get_argument('world'))
(world, dummy) = yield self.check_world_arguments(wid, None)
key = yield self.invent_key('loc', 'locations', {'wid':wid})
loc = { 'key':key, 'wid':wid, 'name':'New Location' }
locid = yield motor.Op(self.application.mongodb.locations.insert,
loc)
# Also set up a desc property. Every location should have one.
prop = { 'wid':wid, 'locid':locid, 'key':'desc',
'val':{ 'type':'text', 'text':'You are here.' } }
propid = yield motor.Op(self.application.mongodb.worldprop.insert,
prop)
self.write( { 'id':str(locid) } )
except Exception as ex:
# Any exception that occurs, return as an error message.
self.application.twlog.warning('Caught exception (adding location): %s', ex)
self.write( { 'error': str(ex) } )
'_to':None })
# If portto is None, we'll wind up porting to the player's panic
# location.
portto = getattr(cmd, 'portto', None)
task.write_event(cmd.uid, app.localize('action.portout')) # 'The world fades away.'
others = yield task.find_locale_players(uid=cmd.uid, notself=True)
if others:
res = yield motor.Op(app.mongodb.players.find_one,
{'_id':cmd.uid},
{'name':1})
playername = res['name']
task.write_event(others, app.localize('action.oportout') % (playername,)) # '%s disappears.'
# Move the player to the void.
yield motor.Op(app.mongodb.playstate.update,
{'_id':cmd.uid},
{'$set':{'focus':None, 'iid':None, 'locid':None,
'portto':portto,
'lastlocid': None,
'lastmoved':task.starttime }})
task.set_dirty(cmd.uid, DIRTY_FOCUS | DIRTY_LOCALE | DIRTY_WORLD | DIRTY_POPULACE | DIRTY_TOOL)
task.set_data_change( ('playstate', cmd.uid, 'iid') )
task.set_data_change( ('playstate', cmd.uid, 'locid') )
if oldloctx.iid:
task.set_data_change( ('populace', oldloctx.iid, oldloctx.locid) )
task.clear_loctx(cmd.uid)
if cmd.portin:
app.schedule_command({'cmd':'portin', 'uid':cmd.uid}, 1.5)
@tornado.gen.coroutine
def login_user(self, uid=None, pwd=None) :
result = {}
token = base64.b64encode(hashlib.sha256( str(random.getrandbits(256)) ).digest(), random.choice(['rA','aZ','gQ','hH','hG','aR','DD'])).rstrip('==')
# TODO more error situation hanled
try:
yield motor.Op(self.db["user"].update,
{'_id': uid},
{"$set":{'token': token}},
upsert=True
)
except Exception, e:
err_msg= 'serious error: %s' % e
self.log.error(err_msg)
result.update({
'status_code': 400,
'status_txt': 'error unkown.may try latter'})
raise tornado.gen.Return(result)
raise tornado.gen.Return({'token':token})
)
try:
cursor = (
db.images.find({'featured': {'$exists': False}})
)
image = yield motor.Op(cursor.next_object)
_fileids = {}
while image:
yield motor.Op(
db.images.update,
{'_id': image['_id']},
{'$set': {'featured': True}}
)
print image['fileid']
image = yield motor.Op(cursor.next_object)
finally:
IOLoop.instance().stop()
def cmd_externalcopyportal(app, task, cmd, stream):
uid = ObjectId(cmd.uid)
portid = ObjectId(cmd.portid)
portal = yield motor.Op(app.mongodb.portals.find_one,
{'_id':portid})
wid = portal['wid']
locid = portal['locid']
world = yield motor.Op(app.mongodb.worlds.find_one,
{'_id':wid})
if not world:
raise ErrorMessageException('externalcopyportal: no such world: %s' % (wid,))
scid = yield two.execute.portal_resolve_scope(app, portal, uid, None, world)
player = yield motor.Op(app.mongodb.players.find_one,
{'_id':uid},
{'plistid':1})
plistid = player['plistid']
# Create a portal (or return the existing one, if already present)
# The "silent" argument just means that an existing duplicate will
# be returned without complaint.
newportid = yield two.execute.create_portal_for_player(app, uid, plistid, wid, scid, locid, silent=True)
app.log.info('URL-based portal: %s', newportid)
def get(self):
data = {}
data['email'] = self.get_argument('email', u'')
banned = []
cursor = (
self.db.banned.find({})
.sort([('date', -1)])
)
#ban = yield motor.Op(cursor.next_object)
while (yield cursor.fetch_next):
ban = cursor.next_object()
search = {
'user': ban['email']
}
ban['pictures'] = (
yield motor.Op(self.db.images.find(search).count)
)
banned.append(ban)
#ban = yield motor.Op(cursor.next_object)
data['banned'] = banned
self.render('admin/banned.html', **data)