示例#1
0
 def _load(
     self,
     main: Union[bytes, str] = "",
     levels: Union[bytes, str] = "",
     xor: bool = False,
     follow_os: bool = True,
 ) -> Database:
     main = self._decode(main, xor=xor, follow_os=follow_os)
     levels = self._decode(levels, xor=xor, follow_os=follow_os)
     return Database(main, levels)
示例#2
0
    def _local_dump(
        self,
        db: Database,
        main: Optional[PathLike] = None,
        levels: Optional[PathLike] = None,
        main_file: PathLike = MAIN,
        levels_file: PathLike = LEVELS,
    ) -> None:
        main_path = _config_path(main, main_file)
        levels_path = _config_path(levels, levels_file)

        files = (main_path, levels_path)

        for file, part in zip(files, db.as_tuple()):

            with open(file, "w") as data_file:
                data_file.write(encode_save(part.dump(), needs_xor=True))
示例#3
0
    def _dump(self,
              db: Database,
              connect: bool = True,
              xor: bool = False,
              follow_os: bool = True) -> Union[str, Tuple[str, str]]:
        if follow_os:
            global encode_save  # pull from global
        else:
            encode_save = Coder.encode_save

        parts = []

        for part in db.as_tuple():
            parts.append(encode_save(part.dump(), needs_xor=xor))

        main, levels, *_ = parts

        if connect:
            return main + ";" + levels
        else:
            return main, levels
示例#4
0
    def make_db(self, main: str = "", levels: str = "") -> Database:
        """Create a database from string parts.

        This method should be used if you already have XML strings, or it can be used
        as a more understandable way of doing ``gd.api.Database()`` creation:

        .. code-block:: python3

            db = gd.api.save.make_db()  # or supply arguments

        Parameters
        ----------

        main: :class:`str`
            A string containing main XML part of the save.
        levels: :class:`str`
            A string containing levels XML part of the save.

        Returns
        -------
        :class:`.api.Database`
            Database object containing loaded data.
        """
        return Database(main, levels)