def test_username_validation(self): "Check username validators deny relevant usernames" # Should not accept Unicode by default, lest users pick names like this if not uses_database("mysql"): # TODO As of Mar 2019, mysql does not pass this test due to collation problems # that has not been possible to resolve result, error = DefaultAccount.validate_username('¯\_(ツ)_/¯') self.assertFalse(result, "Validator allowed kanji in username.") # Should not allow duplicate username result, error = DefaultAccount.validate_username(self.account.name) self.assertFalse(result, "Duplicate username should not have passed validation.") # Should not allow username too short result, error = DefaultAccount.validate_username('xx') self.assertFalse(result, "2-character username passed validation.")
def func(self): "Starts the processor." caller = self.caller args = self.args if not args: caller.msg("Usage: @batchcode[/interactive/debug] <path.to.file>") return python_path = self.args debug = 'debug' in self.switches #parse indata file try: codes = BATCHCODE.parse_file(python_path) except UnicodeDecodeError as err: caller.msg(_UTF8_ERROR % (python_path, err)) return except IOError: string = "'%s' not found.\nYou have to supply the python path\n" \ "from one of the defined batch-file directories\n (%s)." caller.msg(string % (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS))) return if not codes: caller.msg("File %s seems empty of functional code." % python_path) return switches = self.switches # Store work data in cache caller.ndb.batch_stack = codes caller.ndb.batch_stackptr = 0 caller.ndb.batch_pythonpath = python_path caller.ndb.batch_batchmode = "batch_code" caller.ndb.batch_debug = debug caller.cmdset.add(BatchSafeCmdSet) if 'inter' in switches or 'interactive'in switches: # Allow more control over how batch file is executed # Set interactive state directly caller.cmdset.add(BatchInteractiveCmdSet) caller.msg("\nBatch-code processor - Interactive mode for %s ..." % python_path) show_curr(caller) else: caller.msg("Running Batch-code processor - Automatic mode for %s ..." % python_path) procpool = False if "PythonProcPool" in utils.server_services(): if utils.uses_database("sqlite3"): caller.msg("Batchprocessor disabled ProcPool under SQLite3.") else: procpool = True if procpool: # run in parallel process def callback(r): caller.msg(" {GBatchfile '%s' applied." % python_path) purge_processor(caller) def errback(e): caller.msg(" {RError from processor: '%s'" % e) purge_processor(caller) utils.run_async(_PROCPOOL_BATCHCODE_SOURCE, codes=codes, caller=caller, at_return=callback, at_err=errback) else: # un in-process (will block) for inum in range(len(codes)): # loop through the batch file if not batch_code_exec(caller): return step_pointer(caller, 1) # clean out the safety cmdset and clean out all other # temporary attrs. string = " Batchfile '%s' applied." % python_path caller.msg("{G%s" % string) purge_processor(caller)
def func(self): """Starts the processor.""" caller = self.caller args = self.args if not args: caller.msg("Usage: @batchcode[/interactive/debug] <path.to.file>") return python_path = self.args debug = 'debug' in self.switches # parse indata file try: codes = BATCHCODE.parse_file(python_path) except UnicodeDecodeError as err: caller.msg(_UTF8_ERROR % (python_path, err)) return except IOError: string = "'%s' not found.\nYou have to supply the python path\n" \ "from one of the defined batch-file directories\n (%s)." caller.msg( string % (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS))) return if not codes: caller.msg("File %s seems empty of functional code." % python_path) return switches = self.switches # Store work data in cache caller.ndb.batch_stack = codes caller.ndb.batch_stackptr = 0 caller.ndb.batch_pythonpath = python_path caller.ndb.batch_batchmode = "batch_code" caller.ndb.batch_debug = debug # we use list() here to create a new copy of cmdset_stack caller.ndb.batch_cmdset_backup = list(caller.cmdset.cmdset_stack) caller.cmdset.add(BatchSafeCmdSet) if 'inter' in switches or 'interactive' in switches: # Allow more control over how batch file is executed # Set interactive state directly caller.cmdset.add(BatchInteractiveCmdSet) caller.msg("\nBatch-code processor - Interactive mode for %s ..." % python_path) show_curr(caller) else: caller.msg( "Running Batch-code processor - Automatic mode for %s ..." % python_path) procpool = False if "PythonProcPool" in utils.server_services(): if utils.uses_database("sqlite3"): caller.msg( "Batchprocessor disabled ProcPool under SQLite3.") else: procpool = True if procpool: # run in parallel process def callback(r): caller.msg(" |GBatchfile '%s' applied." % python_path) purge_processor(caller) def errback(e): caller.msg(" |RError from processor: '%s'" % e) purge_processor(caller) utils.run_async(_PROCPOOL_BATCHCODE_SOURCE, codes=codes, caller=caller, at_return=callback, at_err=errback) else: # un in-process (will block) for _ in range(len(codes)): # loop through the batch file if not batch_code_exec(caller): return step_pointer(caller, 1) # clean out the safety cmdset and clean out all other # temporary attrs. string = " Batchfile '%s' applied." % python_path caller.msg("|G%s" % string) purge_processor(caller)
def func(self): "Starts the processor." caller = self.caller args = self.args if not args: caller.msg("Usage: @batchcommands[/interactive] <path.to.file>") return python_path = self.args #parse indata file try: commands = BATCHCMD.parse_file(python_path) except UnicodeDecodeError as err: caller.msg(_UTF8_ERROR % (python_path, err)) return except IOError as err: string = "'%s' not found.\nYou have to supply the python path " string += "of the file relative to \none of your batch-file directories (%s)." caller.msg( string % (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS))) return if not commands: caller.msg("File %s seems empty of valid commands." % python_path) return switches = self.switches # Store work data in cache caller.ndb.batch_stack = commands caller.ndb.batch_stackptr = 0 caller.ndb.batch_pythonpath = python_path caller.ndb.batch_batchmode = "batch_commands" caller.cmdset.add(BatchSafeCmdSet) if 'inter' in switches or 'interactive' in switches: # Allow more control over how batch file is executed # Set interactive state directly caller.cmdset.add(BatchInteractiveCmdSet) caller.msg( "\nBatch-command processor - Interactive mode for %s ..." % python_path) show_curr(caller) else: caller.msg( "Running Batch-command processor - Automatic mode for %s (this might take some time) ..." % python_path) procpool = False if "PythonProcPool" in utils.server_services(): if utils.uses_database("sqlite3"): caller.msg( "Batchprocessor disabled ProcPool under SQLite3.") else: procpool = True if procpool: # run in parallel process def callback(r): caller.msg(" {GBatchfile '%s' applied." % python_path) purge_processor(caller) def errback(e): caller.msg(" {RError from processor: '%s'" % e) purge_processor(caller) utils.run_async(_PROCPOOL_BATCHCMD_SOURCE, commands=commands, caller=caller, at_return=callback, at_err=errback) else: # run in-process (might block) for inum in range(len(commands)): # loop through the batch file if not batch_cmd_exec(caller): return step_pointer(caller, 1) # clean out the safety cmdset and clean out all other # temporary attrs. string = " Batchfile '%s' applied." % python_path caller.msg("{G%s" % string) purge_processor(caller)
version = conn.fetchone() return version and str(version[0]) or "" # initialization and helpers _GA = object.__getattribute__ _SA = object.__setattr__ _FROM_MODEL_MAP = None _TO_MODEL_MAP = None _SESSION_HANDLER = None _IS_PACKED_DBOBJ = lambda o: type(o) == tuple and len(o) == 4 and o[ 0] == '__packed_dbobj__' _IS_PACKED_SESSION = lambda o: type(o) == tuple and len(o) == 3 and o[ 0] == '__packed_session__' if uses_database("mysql") and _get_mysql_db_version() < '5.6.4': # mysql <5.6.4 don't support millisecond precision _DATESTRING = "%Y:%m:%d-%H:%M:%S:000000" else: _DATESTRING = "%Y:%m:%d-%H:%M:%S:%f" def _TO_DATESTRING(obj): """ Creates datestring hash. Args: obj (Object): Database object. Returns: datestring (str): A datestring hash.
from evennia.server.models import ServerConfig from evennia.utils.utils import to_str, uses_database from evennia.utils import logger __all__ = ("to_pickle", "from_pickle", "do_pickle", "do_unpickle") PICKLE_PROTOCOL = 2 # initialization and helpers _GA = object.__getattribute__ _SA = object.__setattr__ _FROM_MODEL_MAP = None _TO_MODEL_MAP = None _IS_PACKED_DBOBJ = lambda o: type(o) == tuple and len(o) == 4 and o[0] == '__packed_dbobj__' if uses_database("mysql") and ServerConfig.objects.get_mysql_db_version() < '5.6.4': # mysql <5.6.4 don't support millisecond precision _DATESTRING = "%Y:%m:%d-%H:%M:%S:000000" else: _DATESTRING = "%Y:%m:%d-%H:%M:%S:%f" def _TO_DATESTRING(obj): """ Creates datestring hash. Args: obj (Object): Database object. Returns: datestring (str): A datestring hash.
from evennia.utils.utils import to_str, uses_database from evennia.utils import logger __all__ = ("to_pickle", "from_pickle", "do_pickle", "do_unpickle") PICKLE_PROTOCOL = 2 # initialization and helpers _GA = object.__getattribute__ _SA = object.__setattr__ _FROM_MODEL_MAP = None _TO_MODEL_MAP = None _IS_PACKED_DBOBJ = lambda o: type(o) == tuple and len(o) == 4 and o[ 0] == '__packed_dbobj__' if uses_database( "mysql") and ServerConfig.objects.get_mysql_db_version() < '5.6.4': # mysql <5.6.4 don't support millisecond precision _DATESTRING = "%Y:%m:%d-%H:%M:%S:000000" else: _DATESTRING = "%Y:%m:%d-%H:%M:%S:%f" def _TO_DATESTRING(obj): """ Creates datestring hash. Args: obj (Object): Database object. Returns: datestring (str): A datestring hash.
from django.db import connection conn = connection.cursor() conn.execute("SELECT VERSION()") version = conn.fetchone() return version and str(version[0]) or "" # initialization and helpers _GA = object.__getattribute__ _SA = object.__setattr__ _FROM_MODEL_MAP = None _TO_MODEL_MAP = None _SESSION_HANDLER = None _IS_PACKED_DBOBJ = lambda o: type(o) == tuple and len(o) == 4 and o[0] == '__packed_dbobj__' _IS_PACKED_SESSION = lambda o: type(o) == tuple and len(o) == 3 and o[0] == '__packed_session__' if uses_database("mysql") and _get_mysql_db_version() < '5.6.4': # mysql <5.6.4 don't support millisecond precision _DATESTRING = "%Y:%m:%d-%H:%M:%S:000000" else: _DATESTRING = "%Y:%m:%d-%H:%M:%S:%f" def _TO_DATESTRING(obj): """ Creates datestring hash. Args: obj (Object): Database object. Returns: datestring (str): A datestring hash.
caller.cmdset.add(BatchSafeCmdSet) if 'inter' in switches or 'interactive' in switches: # Allow more control over how batch file is executed # Set interactive state directly caller.cmdset.add(BatchInteractiveCmdSet) caller.msg("\nBatch-command processor - Interactive mode for %s ..." % python_path) show_curr(caller) else: caller.msg("Running Batch-command processor - Automatic mode for %s (this might take some time) ..." % python_path) procpool = False if "PythonProcPool" in utils.server_services(): if utils.uses_database("sqlite3"): caller.msg("Batchprocessor disabled ProcPool under SQLite3.") else: procpool = True if procpool: # run in parallel process def callback(r): caller.msg(" {GBatchfile '%s' applied." % python_path) purge_processor(caller) def errback(e): caller.msg(" {RError from processor: '%s'" % e) purge_processor(caller) utils.run_async(_PROCPOOL_BATCHCMD_SOURCE,
# Set interactive state directly caller.cmdset.add(BatchInteractiveCmdSet) caller.msg( "\nBatch-command processor - Interactive mode for %s ..." % python_path) show_curr(caller) else: caller.msg( "Running Batch-command processor - Automatic mode for %s (this might take some time) ..." % python_path) procpool = False if "PythonProcPool" in utils.server_services(): if utils.uses_database("sqlite3"): caller.msg( "Batchprocessor disabled ProcPool under SQLite3.") else: procpool = True if procpool: # run in parallel process def callback(r): caller.msg(" {GBatchfile '%s' applied." % python_path) purge_processor(caller) def errback(e): caller.msg(" {RError from processor: '%s'" % e) purge_processor(caller)