Factories

Factories are used to load SCII resources from file-like objects and paths to file-like objects. Objects must implement read() such that it retrieves all the file contents.

SC2Factory

class sc2reader.factories.SC2Factory(**options)

The SC2Factory class acts as a generic loader interface for all available to sc2reader resources. At current time this includes Replay and Map resources. These resources can be loaded in both singular and plural contexts with:

The load behavior can be configured in three ways:

  • Passing options to the factory constructor
  • Using the configure() method of a factory instance
  • Passing overried options into the load method

See the configure() method for more details on configuration options.

Resources can be loaded in the singular context from the following inputs:

  • URLs - Uses the built-in package urllib
  • File path - Uses the built-in method open
  • File-like object - Must implement .read()
  • DepotFiles - Describes remote Battle.net depot resources

In the plural context the following inputs are acceptable:

  • An iterable of the above inputs
  • Directory path - Uses get_files() with the appropriate extension to fine files.
configure(cls=None, **options)

Configures the factory to use the supplied options. If cls is specified the options will only be applied when loading that class

load_game_summaries(sources, options=None, **new_options)

Loads a collection of s2gs files, returns a generator.

load_game_summary(source, options=None, **new_options)

Loads a single s2gs file. Accepts file path, url, or file object.

load_localization(source, options=None, **new_options)

Loads a single s2ml file. Accepts file path, url, or file object.

load_localizations(sources, options=None, **new_options)

Loads a collection of s2ml files, returns a generator.

load_map(source, options=None, **new_options)

Loads a single s2ma file. Accepts file path, url, or file object.

load_maps(sources, options=None, **new_options)

Loads a collection of s2ma files, returns a generator.

load_replay(source, options=None, **new_options)

Loads a single sc2replay file. Accepts file path, url, or file object.

load_replays(sources, options=None, **new_options)

Loads a collection of sc2replay files, returns a generator.

register_plugin(cls, plugin)

Registers the given Plugin to be run on classes of the supplied name.

reset()

Resets the options to factory defaults

DictCachedSC2Factory

class sc2reader.factories.DictCachedSC2Factory(cache_max_size=0, **options)
Parameters:cache_max_size – The max number of cache entries to hold in memory.

Extends SC2Factory.

Caches remote depot resources in memory. Does not write to the file system. The cache is effectively cleared when the process exits.

FileCachedSC2Factory

class sc2reader.factories.FileCachedSC2Factory(cache_dir, **options)
Parameters:cache_dir – Local directory to cache files in.

Extends SC2Factory.

Caches remote depot resources on the file system in the cache_dir.

DoubleCachedSC2Factory

class sc2reader.factories.DoubleCachedSC2Factory(cache_dir, cache_max_size=0, **options)
Parameters:
  • cache_dir – Local directory to cache files in.
  • cache_max_size – The max number of cache entries to hold in memory.

Extends SC2Factory.

Caches remote depot resources to the file system AND holds a subset of them in memory for more efficient access.