FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-ivi/doc/exec.py at master · python-ivi/python-ivi · GitHub
This repository was archived by the owner on Feb 2, 2026. It is now read-only.
python-ivi
/
python-ivi
Public archive
Notifications
You must be signed in to change notification settings
Fork
129
Star
237
Code
Issues
32
Pull requests
14
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-ivi
/
doc
/
exec.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (27 loc) · 1.2 KB
Breadcrumbs
python-ivi
/
doc
/
exec.py
Copy path
File metadata and controls
34 lines (27 loc) · 1.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import
sys
from
os
.
path
import
basename
try
:
from
StringIO
import
StringIO
except
ImportError
:
from
io
import
StringIO
from
sphinx
.
util
.
compat
import
Directive
from
docutils
import
nodes
,
statemachine
class
ExecDirective
(
Directive
):
"""Execute the specified python code and insert the output into the document"""
has_content
=
True
def
run
(
self
):
oldStdout
,
sys
.
stdout
=
sys
.
stdout
,
StringIO
()
tab_width
=
self
.
options
.
get
(
'tab-width'
,
self
.
state
.
document
.
settings
.
tab_width
)
source
=
self
.
state_machine
.
input_lines
.
source
(
self
.
lineno
-
self
.
state_machine
.
input_offset
-
1
)
try
:
exec
(
'
\n
'
.
join
(
self
.
content
))
text
=
sys
.
stdout
.
getvalue
()
lines
=
statemachine
.
string2lines
(
text
,
tab_width
,
convert_whitespace
=
True
)
self
.
state_machine
.
insert_input
(
lines
,
source
)
return
[]
except
Exception
:
return
[
nodes
.
error
(
None
,
nodes
.
paragraph
(
text
=
"Unable to execute python code at %s:%d:"
%
(
basename
(
source
),
self
.
lineno
)),
nodes
.
paragraph
(
text
=
str
(
sys
.
exc_info
()[
1
])))]
finally
:
sys
.
stdout
=
oldStdout
def
setup
(
app
):
app
.
add_directive
(
'exec'
,
ExecDirective
)
Back
|
FazBrowse Home
|
New Git URL