core package

Submodules

Module contents

Provides core functionality that doesn’t fit into any other package.

classcore.AutoUnload(*args,**kwargs)[source]

Bases:object

Class used to auto unload specific instances.

Each inheriting class must implement an _unload_instance method.

core.BoostPythonClass

alias ofclass

classcore.ConfigFile(path,encoding='utf-8',comment_prefix='//',as_strings=False)[source]

Bases:list

Class used to parse a configuration file.

__init__(path,encoding='utf-8',comment_prefix='//',as_strings=False)[source]

Parses the given configuation file path.

Parameters:
  • path (Path) – The path of the file to parse.

  • encoding (str) – The encoding to use when opening the file.

  • comment_prefix (str) – The prefix of end line comments.

  • as_strings (bool) – Whether the parsed lines should be stored as strings rather thanargument lists.

classcore.GameConfigObj(infile,*args,**kwargs)[source]

Bases:ConfigObj

Class used to parse specific game data.

__init__(infile,*args,**kwargs)[source]

Helper class that merges the given file with engine/game files.

classcore.OutputReturn

Bases:enum

BLOCK=_core.OutputReturn.BLOCK
CONTINUE=_core.OutputReturn.CONTINUE
names={'BLOCK':_core.OutputReturn.BLOCK,'CONTINUE':_core.OutputReturn.CONTINUE}
values={0:_core.OutputReturn.BLOCK,1:_core.OutputReturn.CONTINUE}
classcore.Tokenize(string,comment_prefix=None)[source]

Bases:list

Parses the arguments from the given string.

__init__(string,comment_prefix=None)[source]

Splits the arguments from the given string.

classcore.WeakAutoUnload(*args,**kwargs)[source]

Bases:AutoUnload

Subclass of AutoUnload used to store weak references to instances.

core.check_info_output(output)[source]

Return whether the output ofspinfo has been modified.

Parameters:

output (str) – The output ofspinfo.

Raises:

ValueError – Raised if the checksum was not found in the output.

Returns:

True if the output has been modified.

Return type:

bool

core.console_message((str)arg1)None:

Output a message to the server console.

core.create_checksum(data,ignore_wchars=True)[source]

Create an MD5 checksum for the given string.

Parameters:
  • data (str) – The string for which a checksum should be created.

  • ignore_wchars (bool) – IfTrue whitespace characters are ignored.

Return type:

str

core.echo_console(text)[source]

Echo a message to the server’s console.

Note

Unlikeconsole_message, this function automatically adds a newlineat the end of the message.

Parameters:

text (str) – Message to print to the console.

core.get_core_modules()list:

Return a list of all modules exposed by Source.Python’s core.

Return type:

list

core.get_interface((str)arg1,(str)arg2)object:

Retrieve an interface from a library.

core.get_public_ip()[source]

Return the server’s public IPv4.

Return type:

str

Note

This functions makes a call tohttp://api.ipify.org to retrieve the public IP.

core.ignore_unicode_errors(errors='ignore')[source]

Overwrite thestrict codecs error handler temporarily.

This is useful e.g. if the engine truncates a string, which results in astring that contains a splitted multi-byte character at the end of thestring.

Parameters:

errors (str) – Error handler that will be looked up viacodecs.lookup_error().

Raises:

LookupError – Raised if the error handler was not found.

Example:

importmemory# Allocate four bytes to create an erroneous stringptr=memory.alloc(4)# Write data to the memory that will usually result in a# UnicodeDecodeErrorptr.set_uchar(ord('a'),0)ptr.set_uchar(ord('b'),1)ptr.set_uchar(226,2)# Add the invalid byteptr.set_uchar(0,3)# Indicate the end of the stringwithignore_unicode_errors():# Read the data as a string. Now, it will only print 'ab', because# the invalid byte has been removed/ignored.print(ptr.get_string_array())
core.server_output(action=_core.OutputReturn.CONTINUE)[source]

Gather all server output sent during the execution of the with-statement.

Parameters:

action (OutputReturn) – Determines what happens with the output.

Return type:

list

Returns:

A list that will be filled with a tuple for every line that is beinglogged. The tuple contains the severity and the message.

Example:

fromcvarsimportcvarfromcoreimportserver_outputfromcoreimportOutputReturnstatus=cvar.find_command('status')withserver_output(OutputReturn.BLOCK)asoutput:status()# Print everything that was logged by the 'status' commandprint(output)

Output:

[(_core.MessageSeverity.MESSAGE,'hostname: Counter-Strike: Global Offensive\n'),(_core.MessageSeverity.MESSAGE,'version : 1.35.8.4/13584 513/6771 secure  [A:1:2435270659:8640]\n'),(_core.MessageSeverity.MESSAGE,'udp/ip  : 192.168.178.60:27015  (public ip: 46.83.158.27)\n'),(_core.MessageSeverity.MESSAGE,'os      :  Windows\n'),(_core.MessageSeverity.MESSAGE,'type    :  community dedicated\n'),(_core.MessageSeverity.MESSAGE,'players : 0 humans, 0 bots (20/0 max) (hibernating)\n\n'),(_core.MessageSeverity.MESSAGE,'# userid name uniqueid connected ping loss state rate'),(_core.MessageSeverity.MESSAGE,' adr'),(_core.MessageSeverity.MESSAGE,'\n'),(_core.MessageSeverity.MESSAGE,'#end\n')]
core.core_plugin_manager

The singleton object of the_CorePluginManager class.