Skip to content
Snippets Groups Projects
Select Git revision
  • docs
  • master default protected
  • 8978
  • 8938
  • benchmark-all-commits
  • debian_package
  • onepython
  • benchmark_elasticsearch
  • buildpackage
  • debian/platform-0.9
  • release/0.9.x
  • feature/streaming-transfer
  • debian/experimental-0.9
  • debian/experimental
  • debian/platform-0.8
  • bug/remove-unicode-conversion
  • release/0.8.x
  • release/0.7.x
  • release/bitmask-0.9.x-alpha
  • debian/platform-0.7
  • 0.10.5
  • 0.10.4
  • 0.9.6post3
  • 0.10.3
  • 0.10.2
  • 0.10.1
  • 0.10.0
  • 0.9.3post3
  • 0.9.6post2
  • 0.9.6post1
  • 0.9.6
  • 0.9.5
  • 0.9.3
  • 0.9.2
  • 0.9.1
  • 0.9.0
  • 0.9.0rc1
  • 0.8.1
  • 0.8.0
  • 0.7.4
40 results

README.rst

Blame
  • Forked from leap / soledad
    Source project has a limited visibility.
    abstract.py 1.45 KiB
    import abc
    import os
    import re
    from typing import Set, Dict, Union
    
    assert Set  # make pyflakes happy
    
    
    class AbstractParser(abc.ABC):
        """ This is the base class of every parser.
        It might yield `ValueError` on instantiation on invalid files,
        and `RuntimeError` when something went wrong in `remove_all`.
        """
        meta_list = set()  # type: Set[str]
        mimetypes = set()  # type: Set[str]
    
        def __init__(self, filename: str) -> None:
            """
            :raises ValueError: Raised upon an invalid file
            """
            if re.search('^[a-z0-9./]', filename) is None:
                # Some parsers are calling external binaries,
                # this prevents shell command injections
                filename = os.path.join('.', filename)
    
            self.filename = filename
            fname, extension = os.path.splitext(filename)
    
            # Special case for tar.gz, tar.bz2, … files
            if fname.endswith('.tar') and len(fname) > 4:
                fname, extension = fname[:-4], '.tar' + extension
    
            self.output_filename = fname + '.cleaned' + extension
            self.lightweight_cleaning = False
            self.sandbox = True
    
        @abc.abstractmethod
        def get_meta(self) -> Dict[str, Union[str, dict]]:
            """Return all the metadata of the current file"""
    
        @abc.abstractmethod
        def remove_all(self) -> bool:
            """
            Remove all the metadata of the current file
    
            :raises RuntimeError: Raised if the cleaning process went wrong.
            """