@@ -41,7 +41,7 @@ def check_output(*popenargs, **kwargs):
41
41
def run_command (command , shell = False ):
42
42
''' run a system command and yield output '''
43
43
p = check_output (command , shell = shell )
44
- return p .split ( b' \n ' )
44
+ return p .decode ( "utf-8" ). splitlines ( )
45
45
46
46
try :
47
47
run_command ([PDFTK_PATH ])
@@ -52,8 +52,8 @@ def run_command(command, shell=False):
52
52
def get_num_pages (pdf_path ):
53
53
''' return number of pages in a given PDF file '''
54
54
for line in run_command ([PDFTK_PATH , pdf_path , 'dump_data' ]):
55
- if line .lower ().startswith (b 'numberofpages' ):
56
- return int (line .split (b ':' )[1 ])
55
+ if line .lower ().startswith ('numberofpages' ):
56
+ return int (line .split (':' )[1 ])
57
57
return 0
58
58
59
59
@@ -89,11 +89,7 @@ def dump_data_fields(pdf_path):
89
89
Return list of dicts of all fields in a PDF.
90
90
'''
91
91
cmd = "%s %s dump_data_fields" % (PDFTK_PATH , pdf_path )
92
- # Either can return strings with :
93
- # field_data = map(lambda x: x.decode("utf-8").split(': ', 1), run_command(cmd, True))
94
- # Or return bytes with : (will break tests)
95
- # field_data = map(lambda x: x.split(b': ', 1), run_command(cmd, True))
96
- field_data = map (lambda x : x .decode ("utf-8" ).split (': ' , 1 ), run_command (cmd , True ))
92
+ field_data = map (lambda x : x .split (': ' , 1 ), run_command (cmd , True ))
97
93
fields = [list (group ) for k , group in itertools .groupby (field_data , lambda x : len (x ) == 1 ) if not k ]
98
94
return [dict (f ) for f in fields ]
99
95
0 commit comments