예제 #1
0
 def type(self, args):
     args_splitted = args.split(" ", maxsplit=1)
     if len(args) == 0:
         print(TYPE_USAGE)
         return
     elif len(args_splitted) == 1:
         encoding = 'ascii'
         file_name = args_splitted[0]
     else:
         encoding = args_splitted[0]
         file_name = " ".join(args_splitted[1:])
     file = self.find(file_name, priority="file")
     if file is None:
         raise DirectoryBrowserError('File "' + file_name + '" not found.')
     if file.is_directory:
         raise DirectoryBrowserError('"' + file_name + '" is a directory.')
     bytes_parser = BytesParser(file.get_file_content(self._fat_editor))
     if len(args_splitted) == 1:
         text = bytes_parser. \
             parse_ascii_string_replace_errors(0, len(bytes_parser))
     else:
         text = bytes_parser.parse_string(0,
                                          len(bytes_parser),
                                          encoding=encoding)
     print(text)
예제 #2
0
 def test_parse_string_end(self):
     parser = BytesParser("Hello, world!".encode(encoding=ASCII))
     self.assertEqual("world!", parser.parse_string(7, 6, encoding=ASCII))
예제 #3
0
 def test_parse_string_middle(self):
     parser = BytesParser("I love Python".encode(encoding=ASCII))
     self.assertEqual("love", parser.parse_string(2, 4, encoding=ASCII))
예제 #4
0
 def test_parse_string_start(self):
     parser = BytesParser("Я love Python".encode(encoding=UTF16))
     self.assertEqual("Я love", parser.parse_string(0, 14, encoding=UTF16))