Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
18cb9498
Commit
18cb9498
authored
Oct 10, 2009
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bring old demo up-to-date.
parent
58d2f268
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
32 deletions
+31
-32
Demo/scripts/pp.py
Demo/scripts/pp.py
+31
-32
No files found.
Demo/scripts/pp.py
View file @
18cb9498
...
...
@@ -22,7 +22,6 @@
# - except for -n/-p, run directly from the file if at all possible
import
sys
import
string
import
getopt
FS
=
''
...
...
@@ -36,7 +35,7 @@ PFLAG = 0
try
:
optlist
,
ARGS
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'acde:F:np'
)
except
getopt
.
error
,
msg
:
sys
.
stderr
.
write
(
sys
.
argv
[
0
]
+
': '
+
msg
+
'
\
n
'
)
sys
.
stderr
.
write
(
'%s: %s
\
n
'
%
(
sys
.
argv
[
0
],
msg
)
)
sys
.
exit
(
2
)
for
option
,
optarg
in
optlist
:
...
...
@@ -47,7 +46,7 @@ for option, optarg in optlist:
elif
option
==
'-d'
:
DFLAG
=
1
elif
option
==
'-e'
:
for
line
in
string
.
splitfields
(
optarg
,
'
\
n
'
):
for
line
in
optarg
.
split
(
'
\
n
'
):
SCRIPT
.
append
(
line
)
elif
option
==
'-F'
:
FS
=
optarg
...
...
@@ -81,31 +80,31 @@ if CFLAG:
elif
NFLAG
:
# Note that it is on purpose that AFLAG and PFLAG are
# tested dynamically each time through the loop
prologue
=
[
\
'LINECOUNT = 0'
,
\
'for FILE in ARGS:'
,
\
'
\
t
if FILE ==
\
'
-
\
'
:'
,
\
'
\
t
\
t
FP = sys.stdin'
,
\
'
\
t
else:'
,
\
'
\
t
\
t
FP = open(FILE,
\
'
r
\
'
)'
,
\
'
\
t
LINENO = 0'
,
\
'
\
t
while 1:'
,
\
'
\
t
\
t
LINE = FP.readline()'
,
\
'
\
t
\
t
if not LINE: break'
,
\
'
\
t
\
t
LINENO = LINENO + 1'
,
\
'
\
t
\
t
LINECOUNT = LINECOUNT + 1'
,
\
'
\
t
\
t
L = LINE[:-1]'
,
\
'
\
t
\
t
aflag = AFLAG'
,
\
'
\
t
\
t
if aflag:'
,
\
'
\
t
\
t
\
t
if FS: F =
string.splitfields(L, FS)'
,
\
'
\
t
\
t
\
t
else: F =
string.split(L)'
\
prologue
=
[
'LINECOUNT = 0'
,
'for FILE in ARGS:'
,
'
\
t
if FILE ==
\
'
-
\
'
:'
,
'
\
t
\
t
FP = sys.stdin'
,
'
\
t
else:'
,
'
\
t
\
t
FP = open(FILE,
\
'
r
\
'
)'
,
'
\
t
LINENO = 0'
,
'
\
t
while 1:'
,
'
\
t
\
t
LINE = FP.readline()'
,
'
\
t
\
t
if not LINE: break'
,
'
\
t
\
t
LINENO = LINENO + 1'
,
'
\
t
\
t
LINECOUNT = LINECOUNT + 1'
,
'
\
t
\
t
L = LINE[:-1]'
,
'
\
t
\
t
aflag = AFLAG'
,
'
\
t
\
t
if aflag:'
,
'
\
t
\
t
\
t
if FS: F =
L.split(FS)'
,
'
\
t
\
t
\
t
else: F =
L.split()'
]
epilogue
=
[
\
'
\
t
\
t
if not PFLAG: continue'
,
\
'
\
t
\
t
if aflag:'
,
\
'
\
t
\
t
\
t
if FS: print
string.joinfields(F, FS)'
,
\
'
\
t
\
t
\
t
else: print
string.join(F)'
,
\
'
\
t
\
t
else: print L'
,
\
epilogue
=
[
'
\
t
\
t
if not PFLAG: continue'
,
'
\
t
\
t
if aflag:'
,
'
\
t
\
t
\
t
if FS: print
FS.join(F)'
,
'
\
t
\
t
\
t
else: print
\
'
\
'
.join(F)'
,
'
\
t
\
t
else: print L'
,
]
else
:
prologue
=
[
'if 1:'
]
...
...
@@ -114,10 +113,10 @@ else:
# Note that we indent using tabs only, so that any indentation style
# used in 'command' will come out right after re-indentation.
program
=
string
.
joinfields
(
prologue
,
'
\
n
'
)
+
'
\
n
'
program
=
'
\
n
'
.
join
(
prologue
)
+
'
\
n
'
for
line
in
SCRIPT
:
program
=
program
+
(
'
\
t
\
t
'
+
line
+
'
\
n
'
)
program
=
program
+
(
string
.
joinfields
(
epilogue
,
'
\
n
'
)
+
'
\
n
'
)
program
+=
'
\
t
\
t
'
+
line
+
'
\
n
'
program
+=
'
\
n
'
.
join
(
epilogue
)
+
'
\
n
'
import
tempfile
fp
=
tempfile
.
NamedTemporaryFile
()
...
...
@@ -125,6 +124,6 @@ fp.write(program)
fp
.
flush
()
if
DFLAG
:
import
pdb
pdb
.
run
(
'execfile(%r)'
%
(
tfn
,))
pdb
.
run
(
'execfile(%r)'
%
(
fp
.
name
,))
else
:
execfile
(
tfn
)
execfile
(
fp
.
name
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment