<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import datetime <EOL> import ast <EOL> import keyword <EOL> import bson <EOL> from bson . objectid import ObjectId <EOL> import pymongo <EOL> import tornado . options <EOL> tornado . options . define ( <EOL> '<STR_LIT>' , type = str , <EOL> help = '<STR_LIT>' , <EOL> callback = lambda path : tornado . options . parse_config_file ( path , final = False ) ) <EOL> tornado . options . define ( <EOL> '<STR_LIT>' , type = str , <EOL> help = '<STR_LIT>' ) <EOL> tornado . options . define ( <EOL> '<STR_LIT>' , type = str , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> tornado . options . define ( <EOL> '<STR_LIT>' , type = bool , <EOL> help = '<STR_LIT>' ) <EOL> tornado . options . define ( <EOL> '<STR_LIT>' , type = bool , <EOL> help = '<STR_LIT>' ) <EOL> tornado . options . define ( <EOL> '<STR_LIT>' , type = bool , <EOL> help = '<STR_LIT>' ) <EOL> args = tornado . options . parse_command_line ( ) <EOL> opts = tornado . options . options <EOL> if '<STR_LIT>' in args : <EOL> args . remove ( '<STR_LIT>' ) <EOL> opts . check = True <EOL> if '<STR_LIT>' in args : <EOL> args . remove ( '<STR_LIT>' ) <EOL> opts . display = True <EOL> if '<STR_LIT>' in args : <EOL> args . remove ( '<STR_LIT>' ) <EOL> opts . remove = True <EOL> if '<STR_LIT>' in args : <EOL> args . remove ( '<STR_LIT>' ) <EOL> opts . removeworld = True <EOL> if opts . python_path : <EOL> sys . path . insert ( <NUM_LIT:0> , opts . python_path ) <EOL> import twcommon . access <EOL> import twcommon . interp <EOL> from twcommon . misc import sluggify <EOL> if not args : <EOL> print ( '<STR_LIT>' ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> class World ( object ) : <EOL> def __init__ ( self ) : <EOL> self . creator = '<STR_LIT>' <EOL> self . wid = None <EOL> self . name = None <EOL> self . copyable = True <EOL> self . instancing = '<STR_LIT>' <EOL> self . props = { } <EOL> self . proplist = [ ] <EOL> self . playerprops = { } <EOL> self . playerproplist = [ ] <EOL> self . locations = { } <EOL> self . locationlist = [ ] <EOL> self . portals = { } <EOL> def check_symbols_used ( self ) : <EOL> self . symbolsused = set ( ) <EOL> all_interptext_props = [ ] <EOL> all_code_props = [ ] <EOL> for ( key , propval ) in self . props . items ( ) : <EOL> if keyword . iskeyword ( key ) : <EOL> print ( '<STR_LIT>' % ( key , None ) ) <EOL> if is_interp_text ( propval ) : <EOL> all_interptext_props . append ( ( propval [ '<STR_LIT:text>' ] , None ) ) <EOL> if is_code ( propval ) : <EOL> all_code_props . append ( ( key , propval [ '<STR_LIT:text>' ] , None ) ) <EOL> if is_move ( propval ) : <EOL> if propval [ '<STR_LIT>' ] not in self . locations : <EOL> print ( '<STR_LIT>' % ( key , None , propval [ '<STR_LIT>' ] ) ) <EOL> for ( lockey , loc ) in self . locations . items ( ) : <EOL> for ( key , propval ) in loc . props . items ( ) : <EOL> if keyword . iskeyword ( key ) : <EOL> print ( '<STR_LIT>' % ( key , lockey ) ) <EOL> if is_interp_text ( propval ) : <EOL> all_interptext_props . append ( ( propval [ '<STR_LIT:text>' ] , lockey ) ) <EOL> if is_code ( propval ) : <EOL> all_code_props . append ( ( key , propval [ '<STR_LIT:text>' ] , lockey ) ) <EOL> if is_move ( propval ) : <EOL> if propval [ '<STR_LIT>' ] not in self . locations : <EOL> print ( '<STR_LIT>' % ( key , lockey , propval [ '<STR_LIT>' ] ) ) <EOL> for ( key , text , lockey ) in all_code_props : <EOL> try : <EOL> ast . parse ( text , filename = '<STR_LIT>' % ( lockey , key , ) ) <EOL> except Exception as ex : <EOL> print ( '<STR_LIT>' % ( key , lockey , ex ) ) <EOL> for ( text , lockey ) in all_interptext_props : <EOL> for nod in twcommon . interp . parse ( text ) : <EOL> if isinstance ( nod , twcommon . interp . Link ) : <EOL> self . symbolsused . add ( ( nod . target , lockey ) ) <EOL> if isinstance ( nod , twcommon . interp . Interpolate ) : <EOL> self . symbolsused . add ( ( nod . expr , lockey ) ) <EOL> for ( symbol , lockey ) in self . symbolsused : <EOL> if not symbol . isidentifier ( ) : <EOL> try : <EOL> ast . parse ( symbol ) <EOL> except : <EOL> print ( '<STR_LIT>' % ( symbol , lockey , ) ) <EOL> continue <EOL> if lockey is None : <EOL> loc = None <EOL> else : <EOL> loc = self . locations [ lockey ] <EOL> if loc and symbol in loc . props : <EOL> continue <EOL> if symbol in self . props : <EOL> continue <EOL> print ( '<STR_LIT>' % ( symbol , lockey , ) ) <EOL> class Location ( object ) : <EOL> def __init__ ( self , name , key = None ) : <EOL> self . name = name <EOL> if key is None : <EOL> self . key = sluggify ( name ) <EOL> else : <EOL> self . key = key <EOL> self . locid = None <EOL> self . props = { } <EOL> self . proplist = [ ] <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . key , self . name ) <EOL> def parse_world ( filename ) : <EOL> world = World ( ) <EOL> curloc = None <EOL> curprop = None <EOL> fl = open ( filename ) <EOL> while True : <EOL> ln = fl . readline ( ) <EOL> if not ln : <EOL> break <EOL> ln = ln . rstrip ( ) <EOL> isindent = <NUM_LIT:0> <EOL> val = ln . lstrip ( ) <EOL> if len ( val ) < len ( ln ) : <EOL> isindent = len ( ln ) - len ( val ) <EOL> ln = val <EOL> if not ln or ln . startswith ( '<STR_LIT:#>' ) : <EOL> continue <EOL> if ln . startswith ( '<STR_LIT>' ) : <EOL> break <EOL> if ln . startswith ( '<STR_LIT:*>' ) : <EOL> curprop = None <EOL> lockey , dummy , locname = ln [ <NUM_LIT:1> : ] . partition ( '<STR_LIT::>' ) <EOL> lockey = lockey . strip ( ) <EOL> locname = locname . strip ( ) <EOL> if not locname : <EOL> locname = lockey <EOL> lockey = sluggify ( locname ) <EOL> if lockey in world . locations : <EOL> error ( '<STR_LIT>' % ( lockey , ) ) <EOL> curloc = Location ( locname , lockey ) <EOL> world . locations [ lockey ] = curloc <EOL> world . locationlist . append ( lockey ) <EOL> curprop = '<STR_LIT>' <EOL> continue <EOL> if isindent and curprop is not None : <EOL> if not curloc : <EOL> if curprop not in world . proplist : <EOL> world . proplist . append ( curprop ) <EOL> append_to_prop ( world . props , curprop , ln , indent = isindent ) <EOL> else : <EOL> if curprop not in curloc . proplist : <EOL> curloc . proplist . append ( curprop ) <EOL> append_to_prop ( curloc . props , curprop , ln , indent = isindent ) <EOL> continue <EOL> key , dummy , val = ln . partition ( '<STR_LIT::>' ) <EOL> if not dummy : <EOL> error ( '<STR_LIT>' % ( ln [ : <NUM_LIT> ] , ) ) <EOL> continue <EOL> key = key . strip ( ) <EOL> val = val . strip ( ) <EOL> if not curloc and key . startswith ( '<STR_LIT:$>' ) : <EOL> curprop = None <EOL> if key == '<STR_LIT>' : <EOL> world . wid = val <EOL> elif key == '<STR_LIT>' : <EOL> world . name = val <EOL> elif key == '<STR_LIT>' : <EOL> world . creator = val <EOL> elif key == '<STR_LIT>' : <EOL> world . copyable = not ( val . lower ( ) [ <NUM_LIT:0> ] in [ '<STR_LIT:0>' , '<STR_LIT:n>' , '<STR_LIT:f>' ] ) <EOL> elif key == '<STR_LIT>' : <EOL> world . instancing = val <EOL> if val not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> error ( '<STR_LIT>' ) <EOL> elif key . startswith ( '<STR_LIT>' ) : <EOL> key = key [ <NUM_LIT:8> : ] . strip ( ) <EOL> propval = parse_prop ( val ) <EOL> if key in world . playerprops : <EOL> error ( '<STR_LIT>' % ( key , ) ) <EOL> world . playerprops [ key ] = propval <EOL> world . playerproplist . append ( key ) <EOL> curprop = key <EOL> continue <EOL> else : <EOL> error ( '<STR_LIT>' % ( key , ) ) <EOL> continue <EOL> if not key . isidentifier ( ) : <EOL> error ( '<STR_LIT>' % ( key , ) ) <EOL> propval = parse_prop ( val ) <EOL> if not curloc : <EOL> if key in world . props : <EOL> error ( '<STR_LIT>' % ( key , ) ) <EOL> world . props [ key ] = propval <EOL> world . proplist . append ( key ) <EOL> curprop = key <EOL> else : <EOL> if key in curloc . props : <EOL> error ( '<STR_LIT>' % ( curloc . key , key , ) ) <EOL> curloc . props [ key ] = propval <EOL> curloc . proplist . append ( key ) <EOL> curprop = key <EOL> fl . close ( ) <EOL> world . check_symbols_used ( ) <EOL> return world <EOL> def parse_prop ( prop ) : <EOL> if prop . startswith ( '<STR_LIT:*>' ) : <EOL> key , dummy , val = prop [ <NUM_LIT:1> : ] . partition ( '<STR_LIT:U+0020>' ) <EOL> if not val and key not in ( '<STR_LIT:code>' , '<STR_LIT>' ) : <EOL> error ( '<STR_LIT>' % ( key , ) ) <EOL> return None <EOL> if key == '<STR_LIT>' : <EOL> plistkey , dummy , val = val . partition ( '<STR_LIT:U+0020>' ) <EOL> res = { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : plistkey , <EOL> '<STR_LIT>' : [ ] } <EOL> if '<STR_LIT>' in val . split ( ) : <EOL> res [ '<STR_LIT>' ] = True <EOL> return res <EOL> if key == '<STR_LIT>' : <EOL> val = sluggify ( val . strip ( ) ) <EOL> return { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : val } <EOL> elif key == '<STR_LIT>' : <EOL> val = sluggify ( val . strip ( ) ) <EOL> return { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:key>' : val } <EOL> elif key == '<STR_LIT>' : <EOL> return { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:text>' : val } <EOL> elif key == '<STR_LIT>' : <EOL> return { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:text>' : val } <EOL> elif key == '<STR_LIT:text>' : <EOL> return { '<STR_LIT:type>' : '<STR_LIT:text>' , '<STR_LIT:text>' : val } <EOL> elif key == '<STR_LIT>' : <EOL> return { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:text>' : val } <EOL> elif key == '<STR_LIT:code>' : <EOL> return { '<STR_LIT:type>' : '<STR_LIT:code>' , '<STR_LIT:text>' : val } <EOL> elif key == '<STR_LIT>' : <EOL> return { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:text>' : val } <EOL> elif key == '<STR_LIT>' : <EOL> return { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:key>' : val } <EOL> elif key == '<STR_LIT>' : <EOL> val = datetime . datetime . strptime ( val , '<STR_LIT>' ) <EOL> return datetime . datetime ( year = val . year , month = val . month , day = val . day , tzinfo = datetime . timezone . utc ) <EOL> else : <EOL> error ( '<STR_LIT>' % ( key , ) ) <EOL> return None <EOL> try : <EOL> propval = ast . literal_eval ( prop ) <EOL> dummy = bson . BSON . encode ( { '<STR_LIT>' : propval } , check_keys = True ) <EOL> return propval <EOL> except : <EOL> pass <EOL> return { '<STR_LIT:type>' : '<STR_LIT:text>' , '<STR_LIT:text>' : prop } <EOL> def append_to_prop ( dic , key , ln , indent = <NUM_LIT:0> ) : <EOL> val = dic . get ( key , None ) <EOL> if not val : <EOL> val = { '<STR_LIT:type>' : '<STR_LIT:text>' , '<STR_LIT:text>' : ln } <EOL> dic [ key ] = val <EOL> elif type ( val ) is str : <EOL> val += ( '<STR_LIT>' + ln ) <EOL> dic [ key ] = val <EOL> elif type ( val ) is dict and ln . startswith ( '<STR_LIT:->' ) : <EOL> subkey , dummy , subval = ln [ <NUM_LIT:1> : ] . partition ( '<STR_LIT::>' ) <EOL> if not dummy : <EOL> error ( '<STR_LIT>' ) <EOL> return <EOL> subkey = subkey . strip ( ) <EOL> subval = subval . strip ( ) <EOL> if val . get ( '<STR_LIT:type>' , None ) == '<STR_LIT>' and subkey == '<STR_LIT>' : <EOL> subls = [ s2val . strip ( ) for s2val in subval . split ( '<STR_LIT:U+002C>' ) ] <EOL> if len ( subls ) != <NUM_LIT:4> : <EOL> error ( '<STR_LIT>' ) <EOL> return None <EOL> val [ '<STR_LIT>' ] . append ( subls ) <EOL> else : <EOL> val [ subkey ] = subval <EOL> elif type ( val ) is dict and val . get ( '<STR_LIT:type>' , None ) in ( '<STR_LIT:code>' , '<STR_LIT>' ) : <EOL> if '<STR_LIT>' not in val : <EOL> val [ '<STR_LIT>' ] = indent <EOL> indentstr = '<STR_LIT:U+0020>' * ( indent - val [ '<STR_LIT>' ] ) <EOL> if not val [ '<STR_LIT:text>' ] . strip ( ) : <EOL> val [ '<STR_LIT:text>' ] = '<STR_LIT>' <EOL> else : <EOL> indentstr = '<STR_LIT:\n>' + indentstr <EOL> val [ '<STR_LIT:text>' ] += ( indentstr + ln ) <EOL> elif type ( val ) is dict and '<STR_LIT:text>' in val : <EOL> val [ '<STR_LIT:text>' ] += ( '<STR_LIT>' + ln ) <EOL> else : <EOL> error ( '<STR_LIT>' % ( key , ) ) <EOL> def transform_prop ( world , db , val ) : <EOL> if type ( val ) is not dict : <EOL> return val <EOL> key = val . get ( '<STR_LIT:type>' , None ) <EOL> if key == '<STR_LIT>' : <EOL> if '<STR_LIT>' in val : <EOL> val [ '<STR_LIT>' ] = twcommon . access . level_named ( val [ '<STR_LIT>' ] ) <EOL> if key == '<STR_LIT>' : <EOL> if val [ '<STR_LIT>' ] in world . portlistmap : <EOL> plistid = world . portlistmap [ val [ '<STR_LIT>' ] ] [ '<STR_LIT>' ] <EOL> else : <EOL> plistid = db . portlists . insert ( { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : world . wid , '<STR_LIT:key>' : val [ '<STR_LIT>' ] } ) <EOL> print ( '<STR_LIT>' % ( val [ '<STR_LIT>' ] , plistid , ) ) <EOL> db . portals . remove ( { '<STR_LIT>' : plistid , '<STR_LIT>' : None } ) <EOL> listpos = <NUM_LIT:0.0> <EOL> portid = None <EOL> for quad in val [ '<STR_LIT>' ] : <EOL> tocreator = db . players . find_one ( { '<STR_LIT:name>' : quad [ <NUM_LIT:1> ] } ) <EOL> if not tocreator : <EOL> error ( '<STR_LIT>' % ( quad [ <NUM_LIT:0> ] , quad [ <NUM_LIT:1> ] ) ) <EOL> return '<STR_LIT>' <EOL> toworld = db . worlds . find_one ( { '<STR_LIT:name>' : quad [ <NUM_LIT:0> ] , '<STR_LIT>' : tocreator [ '<STR_LIT>' ] } ) <EOL> if not toworld : <EOL> error ( '<STR_LIT>' % ( quad [ <NUM_LIT:0> ] , ) ) <EOL> return '<STR_LIT>' <EOL> toloc = db . locations . find_one ( { '<STR_LIT>' : toworld [ '<STR_LIT>' ] , '<STR_LIT:key>' : quad [ <NUM_LIT:3> ] } ) <EOL> if not toloc : <EOL> error ( '<STR_LIT>' % ( quad [ <NUM_LIT:0> ] , quad [ <NUM_LIT:3> ] ) ) <EOL> return '<STR_LIT>' <EOL> query = { '<STR_LIT>' : plistid , '<STR_LIT>' : None , '<STR_LIT>' : toworld [ '<STR_LIT>' ] , '<STR_LIT>' : toloc [ '<STR_LIT>' ] } <EOL> if quad [ <NUM_LIT:2> ] in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> query [ '<STR_LIT>' ] = quad [ <NUM_LIT:2> ] <EOL> else : <EOL> query [ '<STR_LIT>' ] = ObjectId ( quad [ <NUM_LIT:2> ] ) <EOL> query [ '<STR_LIT>' ] = listpos <EOL> listpos += <NUM_LIT:1.0> <EOL> portid = db . portals . insert ( query ) <EOL> print ( '<STR_LIT>' % ( quad , portid , ) ) <EOL> newval = { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : val [ '<STR_LIT>' ] } <EOL> if '<STR_LIT:text>' in val : <EOL> newval [ '<STR_LIT:text>' ] = val [ '<STR_LIT:text>' ] <EOL> if '<STR_LIT>' in val : <EOL> newval [ '<STR_LIT>' ] = True <EOL> if '<STR_LIT>' in val : <EOL> newval [ '<STR_LIT>' ] = twcommon . access . level_named ( val [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in val : <EOL> newval [ '<STR_LIT>' ] = twcommon . access . level_named ( val [ '<STR_LIT>' ] ) <EOL> return newval <EOL> return val <EOL> def prop_to_string ( val ) : <EOL> if type ( val ) is not dict : <EOL> return repr ( val ) <EOL> key = val . get ( '<STR_LIT:type>' , None ) <EOL> if key == '<STR_LIT>' : <EOL> return '<STR_LIT>' % ( val [ '<STR_LIT>' ] , ) <EOL> if key == '<STR_LIT>' : <EOL> return '<STR_LIT>' % ( val [ '<STR_LIT:key>' ] , ) <EOL> if key == '<STR_LIT>' : <EOL> res = '<STR_LIT>' % ( val [ '<STR_LIT:text>' ] , ) <EOL> if '<STR_LIT>' in val : <EOL> res += ( '<STR_LIT>' + val [ '<STR_LIT>' ] ) <EOL> return res <EOL> if key == '<STR_LIT>' : <EOL> res = '<STR_LIT>' % ( val [ '<STR_LIT:text>' ] , ) <EOL> if '<STR_LIT>' in val : <EOL> res += ( '<STR_LIT>' + val [ '<STR_LIT>' ] ) <EOL> return res <EOL> if key == '<STR_LIT>' : <EOL> res = '<STR_LIT>' % ( val [ '<STR_LIT:text>' ] , ) <EOL> return res <EOL> if key == '<STR_LIT:text>' : <EOL> val = val [ '<STR_LIT:text>' ] <EOL> if '<STR_LIT>' in val : <EOL> return val . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return val <EOL> if key == '<STR_LIT>' : <EOL> val = val [ '<STR_LIT:text>' ] <EOL> if '<STR_LIT:\n>' not in text : <EOL> return '<STR_LIT>' % ( text , ) <EOL> else : <EOL> ls = [ '<STR_LIT:U+0020>' + val for val in text . split ( '<STR_LIT:\n>' ) ] <EOL> text = '<STR_LIT:\n>' . join ( ls ) <EOL> return '<STR_LIT>' % ( text , ) <EOL> if key == '<STR_LIT:code>' : <EOL> text = val [ '<STR_LIT:text>' ] <EOL> if '<STR_LIT:\n>' not in text : <EOL> return '<STR_LIT>' % ( text , ) <EOL> else : <EOL> ls = [ '<STR_LIT:U+0020>' + val for val in text . split ( '<STR_LIT:\n>' ) ] <EOL> text = '<STR_LIT:\n>' . join ( ls ) <EOL> return '<STR_LIT>' % ( text , ) <EOL> return repr ( val ) <EOL> def is_interp_text ( res ) : <EOL> return ( type ( res ) is dict and res . get ( '<STR_LIT:type>' , None ) == '<STR_LIT:text>' ) <EOL> def is_code ( res ) : <EOL> return ( type ( res ) is dict and res . get ( '<STR_LIT:type>' , None ) == '<STR_LIT:code>' ) <EOL> def is_move ( res ) : <EOL> return ( type ( res ) is dict and res . get ( '<STR_LIT:type>' , None ) == '<STR_LIT>' ) <EOL> errorcount = <NUM_LIT:0> <EOL> def error ( msg ) : <EOL> global errorcount <EOL> errorcount = errorcount + <NUM_LIT:1> <EOL> print ( '<STR_LIT>' % ( msg , ) ) <EOL> filename = args . pop ( <NUM_LIT:0> ) <EOL> world = parse_world ( filename ) <EOL> if errorcount : <EOL> print ( '<STR_LIT>' % ( errorcount , ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if opts . display : <EOL> if not args : <EOL> args = [ '<STR_LIT:.>' , '<STR_LIT>' ] + world . locationlist <EOL> for val in args : <EOL> if '<STR_LIT:.>' in val : <EOL> lockey , dummy , key = val . partition ( '<STR_LIT:.>' ) <EOL> else : <EOL> lockey , key = ( val , None ) <EOL> if not key : <EOL> key = None <EOL> if not lockey : <EOL> print ( '<STR_LIT>' ) <EOL> print ( ) <EOL> if key is None : <EOL> for key in world . proplist : <EOL> print ( '<STR_LIT>' % ( key , prop_to_string ( world . props [ key ] ) ) ) <EOL> print ( ) <EOL> else : <EOL> if key not in world . props : <EOL> error ( '<STR_LIT>' % ( '<STR_LIT:*>' , key ) ) <EOL> continue <EOL> print ( '<STR_LIT>' % ( key , prop_to_string ( world . props [ key ] ) ) ) <EOL> print ( ) <EOL> continue <EOL> if lockey == '<STR_LIT>' : <EOL> print ( '<STR_LIT>' ) <EOL> print ( ) <EOL> if key is None : <EOL> for key in world . playerproplist : <EOL> print ( '<STR_LIT>' % ( key , prop_to_string ( world . playerprops [ key ] ) ) ) <EOL> print ( ) <EOL> else : <EOL> if key not in world . playerprops : <EOL> error ( '<STR_LIT>' % ( '<STR_LIT>' , key ) ) <EOL> continue <EOL> print ( '<STR_LIT>' % ( key , prop_to_string ( world . playerprops [ key ] ) ) ) <EOL> print ( ) <EOL> continue <EOL> loc = world . locations . get ( lockey , None ) <EOL> if loc is None : <EOL> error ( '<STR_LIT>' % ( lockey , ) ) <EOL> continue <EOL> print ( '<STR_LIT>' % ( loc . key , loc . name ) ) <EOL> print ( ) <EOL> if key is None : <EOL> for key in loc . proplist : <EOL> print ( '<STR_LIT>' % ( key , prop_to_string ( loc . props [ key ] ) ) ) <EOL> print ( ) <EOL> else : <EOL> if key not in loc . props : <EOL> error ( '<STR_LIT>' % ( loc . key , key ) ) <EOL> continue <EOL> print ( '<STR_LIT>' % ( key , prop_to_string ( loc . props [ key ] ) ) ) <EOL> print ( ) <EOL> if opts . display or opts . check : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> client = pymongo . MongoClient ( tz_aware = True ) <EOL> db = client [ opts . mongo_database ] <EOL> dbcreator = db . players . find_one ( { '<STR_LIT:name>' : world . creator } ) <EOL> if not dbcreator : <EOL> error ( '<STR_LIT>' % ( world . creator , ) ) <EOL> world . creatoruid = dbcreator [ '<STR_LIT>' ] <EOL> if not world . wid : <EOL> dbworld = db . worlds . find_one ( { '<STR_LIT:name>' : world . name } ) <EOL> if dbworld and dbworld . get ( '<STR_LIT>' ) != world . creatoruid : <EOL> error ( '<STR_LIT>' % ( world . name , world . creator ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> dbworld = db . worlds . find_one ( { '<STR_LIT>' : ObjectId ( world . wid ) } ) <EOL> if dbworld : <EOL> wid = dbworld [ '<STR_LIT>' ] <EOL> print ( '<STR_LIT>' % ( dbworld [ '<STR_LIT:name>' ] , wid ) ) <EOL> else : <EOL> dbworld = { <EOL> '<STR_LIT>' : world . creatoruid , <EOL> '<STR_LIT:name>' : world . name , <EOL> '<STR_LIT>' : world . copyable , <EOL> '<STR_LIT>' : world . instancing , <EOL> } <EOL> wid = db . worlds . insert ( dbworld ) <EOL> dbworld = db . worlds . find_one ( { '<STR_LIT>' : wid } ) <EOL> if not dbworld : <EOL> error ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> print ( '<STR_LIT>' % ( dbworld [ '<STR_LIT:name>' ] , wid ) ) <EOL> world . wid = wid <EOL> world . allportlists = list ( db . portlists . find ( { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : world . wid } ) ) <EOL> world . allportlists . sort ( key = lambda x : x [ '<STR_LIT>' ] ) <EOL> world . portlistmap = { val [ '<STR_LIT:key>' ] : val for val in world . allportlists } <EOL> if opts . remove : <EOL> if not args : <EOL> error ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> for val in args : <EOL> if '<STR_LIT:.>' in val : <EOL> lockey , dummy , key = val . partition ( '<STR_LIT:.>' ) <EOL> else : <EOL> lockey , key = ( val , None ) <EOL> if not key : <EOL> key = None <EOL> if not lockey : <EOL> if key is None : <EOL> db . worldprop . remove ( { '<STR_LIT>' : wid , '<STR_LIT>' : None } ) <EOL> print ( '<STR_LIT>' ) <EOL> else : <EOL> db . worldprop . remove ( { '<STR_LIT>' : wid , '<STR_LIT>' : None , '<STR_LIT:key>' : key } ) <EOL> print ( '<STR_LIT>' % ( key , ) ) <EOL> continue <EOL> if lockey == '<STR_LIT>' : <EOL> if key is None : <EOL> db . wplayerprop . remove ( { '<STR_LIT>' : wid } ) <EOL> print ( '<STR_LIT>' ) <EOL> else : <EOL> db . wplayerprop . remove ( { '<STR_LIT>' : wid , '<STR_LIT:key>' : key } ) <EOL> print ( '<STR_LIT>' % ( key , ) ) <EOL> continue <EOL> loc = world . locations . get ( lockey , None ) <EOL> if loc is None : <EOL> error ( '<STR_LIT>' % ( lockey , ) ) <EOL> continue <EOL> if not loc . locid : <EOL> dbloc = db . locations . find_one ( { '<STR_LIT>' : wid , '<STR_LIT:key>' : lockey } ) <EOL> if dbloc : <EOL> loc . locid = dbloc [ '<STR_LIT>' ] <EOL> else : <EOL> error ( '<STR_LIT>' % ( lockey , ) ) <EOL> continue <EOL> if key is None : <EOL> db . worldprop . remove ( { '<STR_LIT>' : wid , '<STR_LIT>' : loc . locid } ) <EOL> print ( '<STR_LIT>' % ( lockey , ) ) <EOL> else : <EOL> db . worldprop . remove ( { '<STR_LIT>' : wid , '<STR_LIT>' : loc . locid , '<STR_LIT:key>' : key } ) <EOL> print ( '<STR_LIT>' % ( lockey , key , ) ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if not args : <EOL> args = [ '<STR_LIT:.>' , '<STR_LIT>' ] + world . locationlist <EOL> for val in args : <EOL> if '<STR_LIT:.>' in val : <EOL> lockey , dummy , key = val . partition ( '<STR_LIT:.>' ) <EOL> else : <EOL> lockey , key = ( val , None ) <EOL> if not key : <EOL> key = None <EOL> if not lockey : <EOL> if key is None : <EOL> for key in world . props : <EOL> val = world . props [ key ] <EOL> print ( '<STR_LIT>' % ( key , ) ) <EOL> db . worldprop . update ( { '<STR_LIT>' : wid , '<STR_LIT>' : None , '<STR_LIT:key>' : key } , <EOL> { '<STR_LIT>' : wid , '<STR_LIT>' : None , '<STR_LIT:key>' : key , '<STR_LIT>' : val } , <EOL> upsert = True ) <EOL> else : <EOL> if key not in world . props : <EOL> error ( '<STR_LIT>' % ( '<STR_LIT:*>' , key ) ) <EOL> continue <EOL> val = world . props [ key ] <EOL> print ( '<STR_LIT>' % ( key , ) ) <EOL> db . worldprop . update ( { '<STR_LIT>' : wid , '<STR_LIT>' : None , '<STR_LIT:key>' : key } , <EOL> { '<STR_LIT>' : wid , '<STR_LIT>' : None , '<STR_LIT:key>' : key , '<STR_LIT>' : val } , <EOL> upsert = True ) <EOL> continue <EOL> if lockey == '<STR_LIT>' : <EOL> if key is None : <EOL> for key in world . playerprops : <EOL> val = world . playerprops [ key ] <EOL> print ( '<STR_LIT>' % ( key , ) ) <EOL> db . wplayerprop . update ( { '<STR_LIT>' : wid , '<STR_LIT>' : None , '<STR_LIT:key>' : key } , <EOL> { '<STR_LIT>' : wid , '<STR_LIT>' : None , '<STR_LIT:key>' : key , '<STR_LIT>' : val } , <EOL> upsert = True ) <EOL> else : <EOL> if key not in world . playerprops : <EOL> error ( '<STR_LIT>' % ( '<STR_LIT>' , key ) ) <EOL> continue <EOL> val = world . playerprops [ key ] <EOL> print ( '<STR_LIT>' % ( key , ) ) <EOL> db . wplayerprop . update ( { '<STR_LIT>' : wid , '<STR_LIT>' : None , '<STR_LIT:key>' : key } , <EOL> { '<STR_LIT>' : wid , '<STR_LIT>' : None , '<STR_LIT:key>' : key , '<STR_LIT>' : val } , <EOL> upsert = True ) <EOL> continue <EOL> loc = world . locations . get ( lockey , None ) <EOL> if loc is None : <EOL> error ( '<STR_LIT>' % ( lockey , ) ) <EOL> continue <EOL> if not loc . locid : <EOL> dbloc = db . locations . find_one ( { '<STR_LIT>' : wid , '<STR_LIT:key>' : lockey } ) <EOL> if dbloc : <EOL> loc . locid = dbloc [ '<STR_LIT>' ] <EOL> if dbloc . get ( '<STR_LIT:name>' , None ) != loc . name : <EOL> print ( '<STR_LIT>' % ( loc . key , ) ) <EOL> db . locations . update ( { '<STR_LIT>' : loc . locid } , { '<STR_LIT>' : { '<STR_LIT:name>' : loc . name } } ) <EOL> else : <EOL> print ( '<STR_LIT>' % ( loc . key , ) ) <EOL> dbloc = { <EOL> '<STR_LIT>' : wid , <EOL> '<STR_LIT:key>' : loc . key , <EOL> '<STR_LIT:name>' : loc . name , <EOL> } <EOL> loc . locid = db . locations . insert ( dbloc ) <EOL> if key is None : <EOL> for key in loc . props : <EOL> val = loc . props [ key ] <EOL> val = transform_prop ( world , db , val ) <EOL> print ( '<STR_LIT>' % ( loc . key , key , ) ) <EOL> db . worldprop . update ( { '<STR_LIT>' : wid , '<STR_LIT>' : loc . locid , '<STR_LIT:key>' : key } , <EOL> { '<STR_LIT>' : wid , '<STR_LIT>' : loc . locid , '<STR_LIT:key>' : key , '<STR_LIT>' : val } , <EOL> upsert = True ) <EOL> else : <EOL> if key not in loc . props : <EOL> error ( '<STR_LIT>' % ( loc . key , key ) ) <EOL> continue <EOL> val = loc . props [ key ] <EOL> val = transform_prop ( world , db , val ) <EOL> print ( '<STR_LIT>' % ( loc . key , key , ) ) <EOL> db . worldprop . update ( { '<STR_LIT>' : wid , '<STR_LIT>' : loc . locid , '<STR_LIT:key>' : key } , <EOL> { '<STR_LIT>' : wid , '<STR_LIT>' : loc . locid , '<STR_LIT:key>' : key , '<STR_LIT>' : val } , <EOL> upsert = True ) </s>
