2

in many libraries that I was using, there are functions that are basically not doing anything and have docstrings. How are they used then? I want to figure out somethings, but when I look up source code, there is nothing in it.

How does it work?, is this metaclass approach ? I want to know understand this, not solve runtime problem.

Example of this class / functions, not much in it...

# fafreplay.py
# encoding: utf-8
# module fafreplay
# from /home/greg/anaconda3/lib/python3.7/site-packages/fafreplay.cpython-35m-x86_64-linux-gnu.so
# by generator 1.147
""" Supreme Commander Forged Alliance replay parser """

# imports
import commands as commands # <module 'commands'>

# functions

def body_offset(replay, bytes=None, bytearray=None): # real signature unknown; restored from __doc__
    """
    body_offset(replay: Union[bytes, bytearray]) -> int

    Find the offset at which the body starts by parsing the header.
    Raises `ReplayReadError` if the header data is malformed.
    """
    return 0

def body_ticks(body, bytes=None, bytearray=None): # real signature unknown; restored from __doc__
    """
    body_ticks(body: Union[bytes, bytearray]) -> int

    Count the number of ticks in the replay body without checking for desyncs.
    Raises `ReplayReadError` if the body data is malformed.
    """
    return 0

# classes

class Parser(object):
    # no doc
    def parse(self, *args, **kwargs): # real signature unknown
        """ Parse a replay """
        pass

    def parse_body(self, *args, **kwargs): # real signature unknown
        """
        Parse a replay body. This implies that the header has already been parsed in order for
        `data` to be at the correct offset.
        """
        pass

    def parse_header(self, *args, **kwargs): # real signature unknown
        """ Parse a replay header """
        pass

    def __init__(self, *args, **kwargs): # real signature unknown
        pass

    @staticmethod # known case of __new__
    def __new__(*args, **kwargs): # real signature unknown
        """ Create and return a new object.  See help(type) for accurate signature. """
        pass


class ReplayReadError(Exception):
    # no doc
    def __init__(self, *args, **kwargs): # real signature unknown
        pass

    __weakref__ = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """list of weak references to the object (if defined)"""



class ReplayDesyncedError(ReplayReadError):
    # no doc
    def __init__(self, *args, **kwargs): # real signature unknown
        pass


# variables with complex values

__all__ = [
    '__doc__',
    'Parser',
    'ReplayReadError',
    'ReplayDesyncedError',
    'body_offset',
    'body_ticks',
    'commands',
]

__loader__ = None # (!) real value is '<_frozen_importlib_external.ExtensionFileLoader object at 0x7f643cf3ed10>'

__spec__ = None # (!) real value is "ModuleSpec(name='fafreplay', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7f643cf3ed10>, origin='/home/greg/anaconda3/lib/python3.7/site-packages/fafreplay.cpython-37m-x86_64-linux-gnu.so')"

library link: https://libraries.io/pypi/faf-replay-parser/0.4.0 pip install faf-replay-parser==0.4.0

I am using this library in my code:

# my_file.py
from fafreplay import body_offset, body_ticks
ticks = body_ticks(data)

which results in error:

Traceback (most recent call last):
  File "/home/greg/_Local/git/faf-replay-analyzer/src/replay_reader.py", line 39, in <module>
    ticks = body_ticks(data)
fafreplay.ReplayReadError: Invalid command!
Grzegorz Krug
  • 186
  • 2
  • 11

0 Answers0