Show More
@@ -373,8 +373,7 b' def push_ipython_script(node):' | |||
|
373 | 373 | ohist = ip.IP.output_hist |
|
374 | 374 | hstart = len(ip.IP.input_hist) |
|
375 | 375 | script = node.script() |
|
376 | ||
|
377 | script = g.splitLines(script + '\n') | |
|
376 | ||
|
378 | 377 | ip.user_ns['_p'] = node |
|
379 | 378 | ip.runlines(script) |
|
380 | 379 | ip.user_ns.pop('_p',None) |
@@ -273,16 +273,27 b' class IPApi:' | |||
|
273 | 273 | """ |
|
274 | 274 | res = [] |
|
275 | 275 | lines = script.splitlines() |
|
276 | ||
|
276 | 277 | level = 0 |
|
277 | 278 | for l in lines: |
|
278 | 279 | lstripped = l.lstrip() |
|
279 | stripped = l.strip() | |
|
280 | stripped = l.strip() | |
|
280 | 281 | if not stripped: |
|
281 | 282 | continue |
|
282 | 283 | newlevel = len(l) - len(lstripped) |
|
283 | if level > 0 and newlevel == 0 and not stripped.endswith(':'): | |
|
284 | def is_secondary_block_start(s): | |
|
285 | if not s.endswith(':'): | |
|
286 | return False | |
|
287 | if (s.startswith('elif') or | |
|
288 | s.startswith('else') or | |
|
289 | s.startswith('except') or | |
|
290 | s.startswith('finally')): | |
|
291 | return True | |
|
292 | ||
|
293 | if level > 0 and newlevel == 0 and not is_secondary_block_start(stripped): | |
|
284 | 294 | # add empty line |
|
285 | 295 | res.append('') |
|
296 | ||
|
286 | 297 | res.append(l) |
|
287 | 298 | level = newlevel |
|
288 | 299 | return '\n'.join(res) + '\n' |
@@ -292,7 +303,7 b' class IPApi:' | |||
|
292 | 303 | else: |
|
293 | 304 | script = '\n'.join(lines) |
|
294 | 305 | clean=cleanup_ipy_script(script) |
|
295 | ||
|
306 | # print "_ip.runlines() script:\n",clean #dbg | |
|
296 | 307 | self.IP.runlines(clean) |
|
297 | 308 | def to_user_ns(self,vars, interactive = True): |
|
298 | 309 | """Inject a group of variables into the IPython user namespace. |
@@ -3,7 +3,7 b'' | |||
|
3 | 3 | <leo_file> |
|
4 | 4 | <leo_header file_format="2" tnodes="0" max_tnode_index="0" clone_windows="0"/> |
|
5 | 5 | <globals body_outline_ratio="0.307814992026"> |
|
6 |
<global_window_position top=" |
|
|
6 | <global_window_position top="257" left="131" height="627" width="1280"/> | |
|
7 | 7 | <global_log_window_position top="0" left="0" height="0" width="0"/> |
|
8 | 8 | </globals> |
|
9 | 9 | <preferences/> |
@@ -38,18 +38,18 b'' | |||
|
38 | 38 | <v t="vivainio.20080219230342"><vh>slist to leo</vh></v> |
|
39 | 39 | </v> |
|
40 | 40 | </v> |
|
41 | <v t="vivainio.20080218195413"><vh>Class tests</vh> | |
|
41 | <v t="vivainio.20080218195413" a="E"><vh>Class tests</vh> | |
|
42 | 42 | <v t="vivainio.20080218200509"><vh>csvr</vh></v> |
|
43 | 43 | <v t="vivainio.20080218191007"><vh>tempfile</vh></v> |
|
44 | 44 | <v t="vivainio.20080218195413.1"><vh>rfile</vh></v> |
|
45 | 45 | <v t="vivainio.20080219225804"><vh>strlist</vh></v> |
|
46 | 46 | </v> |
|
47 | <v t="vivainio.20080222201226" a="V"><vh>IPython script push tests</vh></v> | |
|
47 | 48 | <v t="vivainio.20080218201219" a="E"><vh>Direct variables</vh> |
|
48 | <v t="vivainio.20080222201226"><vh>NewHeadline</vh></v> | |
|
49 | 49 | <v t="vivainio.20080218201219.2"><vh>bar</vh></v> |
|
50 | 50 | </v> |
|
51 | 51 | <v t="vivainio.20080316144536" a="E"><vh>pylab tests</vh> |
|
52 |
<v t="vivainio.20080316145539.2" |
|
|
52 | <v t="vivainio.20080316145539.2"><vh>Generate testarr</vh></v> | |
|
53 | 53 | <v t="vivainio.20080316085925"><vh>testarr</vh></v> |
|
54 | 54 | <v t="vivainio.20080316085950"><vh>Call plotter on testarr</vh></v> |
|
55 | 55 | </v> |
@@ -128,21 +128,45 b' def format_slist(obj):' | |||
|
128 | 128 | <t tx="vivainio.20080222193236">?</t> |
|
129 | 129 | <t tx="vivainio.20080222193236.1">@wrap |
|
130 | 130 | @nocolor</t> |
|
131 | <t tx="vivainio.20080222201226">1+2 | |
|
131 | <t tx="vivainio.20080222201226"># test ipython script 'cleanup' with complex blocks | |
|
132 | 1+2 | |
|
132 | 133 | print "hello" |
|
133 | 134 | 3+4 |
|
134 | 135 | |
|
135 | 136 | def f(x): |
|
136 | 137 | return x.upper() |
|
137 | 138 | |
|
138 | f('hello world') | |
|
139 | 139 | |
|
140 | 140 | if 0: |
|
141 | 141 | print "foo" |
|
142 | 142 | else: |
|
143 | 143 | print "bar" |
|
144 | 144 | |
|
145 | </t> | |
|
145 | def g(): | |
|
146 | pass | |
|
147 | ||
|
148 | g() | |
|
149 | ||
|
150 | if 1: | |
|
151 | if 1: | |
|
152 | print "hello" | |
|
153 | ||
|
154 | print "world" | |
|
155 | ||
|
156 | if 1: | |
|
157 | print "hello" | |
|
158 | ||
|
159 | print "word" | |
|
160 | else: | |
|
161 | print "foo" | |
|
162 | ||
|
163 | print "bar" | |
|
164 | print "baz" | |
|
165 | ||
|
166 | try: | |
|
167 | raise Exception | |
|
168 | except: | |
|
169 | print "exc ok"</t> | |
|
146 | 170 | <t tx="vivainio.20080222202211"></t> |
|
147 | 171 | <t tx="vivainio.20080222202211.1" ipython="7d71005506636f6f7264737101284b0c4bde747102732e">@cl rfile |
|
148 | 172 | hello |
General Comments 0
You need to be logged in to leave comments.
Login now