Exemplo n.º 1
0
    def test_sanitize_file_name(self):
        monkeypatch = MonkeyPatch()
        monkeypatch.setattr('os.path.isfile', lambda _: True)
        file_name = 'what/ever.exe'
        file_src = '~/' + file_name
        received = file_utils.sanitize_file_name(file_src)

        home = os.path.expanduser("~")
        expected = os.path.join(home, file_name)

        assert expected == received
        monkeypatch.undo()
Exemplo n.º 2
0
    def plot_to_file(self, file_name, dpi, fig_size=None):
        '''
        Plot to a file.

        :param file_name: the image file name
        :param dpi: the desired dpi resolution
        :param fig_size: fig_size ratio
        :return:
        '''
        file_name = file_utils.sanitize_file_name(file_name, False)

        b = self.plot_to_buffer(dpi, fig_size)
        if b != '':
            self._write_image(b, file_name)
Exemplo n.º 3
0
    def get_file_header(file_src):
        file_src = file_utils.sanitize_file_name(file_src)

        if os.path.getsize(file_src) < 4:
            return None

        with open(file_src, "rb") as f:
            magic = f.read(4)

        if magic == FileHeaderParser.MAGIC_ELF_FILE_BYTES:
            return 'ELF'
        elif magic[0:2] == FileHeaderParser.MAGIC_PE_FILE_BYTES:
            return 'PE'
        else:
            return None
Exemplo n.º 4
0
    def plot_to_dynamic_size_file(self, file_name, dpi, width, height):
        '''
        Plot to a file with dynamic width and height

        :param file_name: the image file name
        :param dpi: the desired dpi resolution
        :param width: the desired width
        :param height: the desired height
        :return:
        '''

        file_name = file_utils.sanitize_file_name(file_name, False)

        b = self.plot_to_dynamic_size_buffer(dpi, width, height)
        if b != '':
            self._write_image(b, file_name)
Exemplo n.º 5
0
 def _set_file_attributes(self, file_name):
     file_name = file_utils.sanitize_file_name(file_name)
     self._file_size = os.path.getsize(file_name)
     self._short_filename = os.path.basename(file_name)
Exemplo n.º 6
0
    def __init__(self, file_src):
        self._file_path = file_utils.sanitize_file_name(file_src)
        self.cs_regions = self._parse_regions_with_code_scanner()

        self.x_regions = self._parse_x_regions_with_header_parser()
Exemplo n.º 7
0
 def test_sanitize_file_name_no_file(self):
     file_src = '~/sdfgsdfgdsfg'
     with pytest.raises(IOError):
         file_utils.sanitize_file_name(file_src)