core package¶
Submodules¶
Module contents¶
Provides core functionality that doesn’t fit into any other package.
- class core.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 of
class
- class core.ConfigFile(path, encoding='utf-8', comment_prefix='//', as_strings=False)[source]¶
Bases:
list
Class used to parse a configuration file.
- class core.GameConfigObj(infile, *args, **kwargs)[source]¶
Bases:
ConfigObj
Class used to parse specific game data.
- class core.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}¶
- class core.Tokenize(string, comment_prefix=None)[source]¶
Bases:
list
Parses the arguments from the given string.
- class core.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 of
sp info
has been modified.- Parameters:
output (str) – The output of
sp info
.- Raises:
ValueError – Raised if the checksum was not found in the output.
- Returns:
True
if the output has been modified.- Return type:
- 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.
- core.echo_console(text)[source]¶
Echo a message to the server’s console.
Note
Unlike
console_message
, this function automatically adds a newline at 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:
- 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:
Note
This functions makes a call to
http://api.ipify.org
to retrieve the public IP.
- core.ignore_unicode_errors(errors='ignore')[source]¶
Overwrite the
strict
codecs error handler temporarily.This is useful e.g. if the engine truncates a string, which results in a string that contains a splitted multi-byte character at the end of the string.
- Parameters:
errors (str) – Error handler that will be looked up via
codecs.lookup_error()
.- Raises:
LookupError – Raised if the error handler was not found.
Example:
import memory # Allocate four bytes to create an erroneous string ptr = memory.alloc(4) # Write data to the memory that will usually result in a # UnicodeDecodeError ptr.set_uchar(ord('a'), 0) ptr.set_uchar(ord('b'), 1) ptr.set_uchar(226, 2) # Add the invalid byte ptr.set_uchar(0, 3) # Indicate the end of the string with ignore_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:
- Returns:
A list that will be filled with a tuple for every line that is being logged. The tuple contains the severity and the message.
Example:
from cvars import cvar from core import server_output from core import OutputReturn status = cvar.find_command('status') with server_output(OutputReturn.BLOCK) as output: status() # Print everything that was logged by the 'status' command print(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.