2828"""
2929
3030
31- from __future__ import print_function
3231
3332import os
3433import ast
@@ -65,7 +64,7 @@ def glom_cli(target, spec, indent, debug, inspect):
6564 try :
6665 result = glom .glom (target , spec )
6766 except GlomError as ge :
68- print ('%s: %s' % ( ge .__class__ .__name__ , ge ) )
67+ print (f' { ge .__class__ .__name__ } : { ge } ' )
6968 return 1
7069
7170 if not indent :
@@ -170,10 +169,10 @@ def mw_get_target(next_, posargs_, target_file, target_format, spec_file, spec_f
170169 raise UsageError ('expected spec file or spec argument, not both' )
171170 elif spec_file :
172171 try :
173- with open (spec_file , 'r' ) as f :
172+ with open (spec_file ) as f :
174173 spec_text = f .read ()
175- except IOError as ose :
176- raise UsageError ('could not read spec file %r , got: %s' % ( spec_file , ose ) )
174+ except OSError as ose :
175+ raise UsageError (f 'could not read spec file { spec_file !r } , got: { ose } ' )
177176
178177 if not spec_text :
179178 spec = Path ()
@@ -195,9 +194,9 @@ def mw_get_target(next_, posargs_, target_file, target_format, spec_file, spec_f
195194 target_text = sys .stdin .read ()
196195 elif target_file :
197196 try :
198- target_text = open (target_file , 'r' ).read ()
199- except IOError as ose :
200- raise UsageError ('could not read target file %r , got: %s' % ( target_file , ose ) )
197+ target_text = open (target_file ).read ()
198+ except OSError as ose :
199+ raise UsageError (f 'could not read target file { target_file !r } , got: { ose } ' )
201200 elif not target_text and not isatty (sys .stdin ):
202201 target_text = sys .stdin .read ()
203202
@@ -218,7 +217,7 @@ def _from_glom_import_star():
218217
219218def _eval_python_full_spec (py_text ):
220219 name = '__cli_glom_spec__'
221- code_str = '%s = %s' % ( name , py_text )
220+ code_str = f' { name } = { py_text } '
222221 env = _from_glom_import_star ()
223222 spec = _compile_code (code_str , name = name , env = env )
224223 return spec
0 commit comments