11# -*- coding: utf-8 -*-
2- # Copyright (C) 2013, 2015, 2017 Rocky Bernstein <rocky@gnu.org>
2+ # Copyright (C) 2013, 2015, 2017, 2021 Rocky Bernstein <rocky@gnu.org>
33#
44# This program is free software: you can redistribute it and/or modify
55# it under the terms of the GNU General Public License as published by
1717counts, to parse a string for an integer, or check a string for an
1818on/off setting value.
1919'''
20- import os , sys , tempfile
21- import pyficache
20+ import sys , tempfile
2221
2322def source_tempfile_remap (prefix , text ):
23+ print ("Hi rocky!" )
2424 fd = tempfile .NamedTemporaryFile (suffix = '.py' ,
2525 prefix = prefix ,
26- delete = False )
26+ delete = False ,
27+ tempdir = None )
2728 with fd :
2829 fd .write (bytes (text , 'UTF-8' ))
2930 fd .close ()
@@ -43,26 +44,6 @@ def deparse_fn(code):
4344 raise
4445 return None
4546
46- def deparse_getline (code , filename , line_number , opts ):
47- # Would love to figure out how to deparse the entire module
48- # but with all many-time rewritten import stuff, I still
49- # can't figure out how to get from "<frozen importlib>" to
50- # the module's code.
51- # So for now, we'll have to do this on a function by function
52- # bases. Fortunately pyficache has the ability to remap line
53- # numbers
54- text = deparse_fn (code )
55- if text :
56- prefix = os .path .basename (filename ) + "_"
57- remapped_filename = source_tempfile_remap (prefix , text )
58- lines = text .split ("\n " )
59- first_line = code .co_firstlineno
60- pyficache .remap_file_lines (filename , remapped_filename ,
61- range (first_line , first_line + len (lines )),
62- 1 )
63- return remapped_filename , pyficache .getline (filename , line_number , opts )
64- return None , None
65-
6647def get_an_int (errmsg , arg , msg_on_error , min_value = None , max_value = None ):
6748 """Another get_int() routine, this one simpler and less stylized
6849 than get_int(). We eval arg return it as an integer value or
@@ -207,28 +188,28 @@ def want_different_line(cmd, default):
207188# Demo it
208189if __name__ == '__main__' :
209190 def errmsg (msg ):
210- print "** " , msg
191+ print ( "** " , msg )
211192 return
212193
213194 def msg (m ):
214- print m
215- print get_int (errmsg , '1+2' ) # 3
216- print get_int (errmsg , None ) # 1
217- print get_an_int (errmsg , '6*1' , '6*1 is okay' ) # 6
218- print get_an_int (errmsg , '0' , '0 is too small' , 1 ) # errmsg
219- print get_an_int (errmsg , '5+a' , '5+a is no good' ) # errmsg
195+ print ( m )
196+ print ( get_int (errmsg , '1+2' ) ) # 3
197+ print ( get_int (errmsg , None ) ) # 1
198+ print ( get_an_int (errmsg , '6*1' , '6*1 is okay' ) ) # 6
199+ print ( get_an_int (errmsg , '0' , '0 is too small' , 1 ) ) # errmsg
200+ print ( get_an_int (errmsg , '5+a' , '5+a is no good' ) ) # errmsg
220201 try :
221202 get_int (errmsg , 'pi' )
222203 except ValueError :
223- print "Good - 'pi' is not an integer"
204+ print ( "Good - 'pi' is not an integer" )
224205 pass
225206
226207 import inspect
227208 curframe = inspect .currentframe ()
228209
229- print want_different_line ("s+" , False )
230- print want_different_line ("s-" , True )
231- print want_different_line ("s" , False )
232- print want_different_line ("s" , True )
233- print want_different_line ("s" , True )
210+ print ( want_different_line ("s+" , False ) )
211+ print ( want_different_line ("s-" , True ) )
212+ print ( want_different_line ("s" , False ) )
213+ print ( want_different_line ("s" , True ) )
214+ print ( want_different_line ("s" , True ) )
234215 pass
0 commit comments