Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
00fbcfa9
Commit
00fbcfa9
authored
Nov 27, 2000
by
Michel Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added pretty printing of interfaces
parent
9f5148ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
lib/python/Interface/pprint.py
lib/python/Interface/pprint.py
+68
-0
No files found.
lib/python/Interface/pprint.py
0 → 100644
View file @
00fbcfa9
import
string
""" Pretty-Print an Interface object as structured text (Yum) """
def
justify_and_indent
(
text
,
level
,
width
=
72
):
""" strip newlines, indent and justify text """
lines
=
[]
line
=
" "
*
level
text
=
string
.
split
(
string
.
strip
(
string
.
translate
(
text
,
string
.
maketrans
(
"
\
r
\
n
"
,
" "
))))
for
word
in
text
:
line
=
string
.
join
([
line
,
word
])
if
len
(
line
)
>
width
:
lines
.
append
(
line
)
line
=
" "
*
level
else
:
lines
.
append
(
line
)
return
string
.
join
(
lines
,
"
\
n
"
)
def
build_signature
(
meth
):
""" this is a lot of work just to build a signature... """
sig
=
"("
for
v
in
meth
.
positional
:
sig
=
sig
+
v
if
v
in
meth
.
optional
.
keys
():
sig
=
sig
+
"=%s"
%
`meth.optional[v]`
sig
=
sig
+
", "
if
meth
.
varargs
:
sig
=
sig
+
"*args, "
if
meth
.
kwargs
:
sig
=
sig
+
"**kws, "
# slice off the last comma and space
if
meth
.
positional
or
meth
.
varargs
or
meth
.
kwargs
:
sig
=
sig
[:
-
2
]
sig
=
sig
+
")"
return
sig
def
interface_as_stx
(
I
):
outp
=
"%s
\
n
\
n
"
%
I
.
__name__
level
=
1
if
I
.
__doc__
:
outp
=
outp
+
justify_and_indent
(
I
.
__doc__
,
level
)
+
"
\
n
\
n
"
if
I
.
__bases__
:
outp
=
outp
+
(
" "
*
level
)
+
"This interface extends:
\
n
\
n
"
level
=
level
+
1
for
b
in
I
.
__bases__
:
item
=
"o %s"
%
b
.
__name__
outp
=
outp
+
justify_and_indent
(
item
,
level
)
+
"
\
n
\
n
"
level
=
level
-
1
level
=
level
+
1
for
name
,
desc
in
I
.
namesAndDescriptions
():
item
=
"%s%s -- %s"
%
(
name
,
build_signature
(
desc
),
desc
.
__doc__
)
outp
=
outp
+
justify_and_indent
(
item
,
level
)
+
"
\
n
\
n
"
return
outp
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