wibiti/uncompyle2 — Issue #5: problem uncompyling (2)
Author: lblanquet
Created: 2011-12-10 12:04:38+00:00
State: open

Code :
def create_mappings(metadata,create_file=False):
global mapping_stub
cl=['from sqlalchemy.orm import *','from context import CONTEXT','metadata=CONTEXT.DB.metadata'];mp=[]
cl.append(str_stub)
mp_popo=['from data_session import session_obj']
for t in sort_by_depends(metadata):
if '_depends' in t.info and not t.name.startswith('model_') and t.info.get('has_object_model',False):
cl.append(t.info['mapping_sources'][0])
mp.append('CONTEXT.logger.debug("Mapping \\"%s\\" .. ")' % t.name)
mp.append(t.info['mapping_sources'][1])
mp_popo.append(t.info['mapping_sources'][2])

if create_file:
main_dir=util.get_main_dir()
sys.path.append(main_dir)
if not os.path.exists(main_dir+'/application/object_mappings/__init__.py'):
util.forcedirs(main_dir+'/application/object_mappings')
with file(main_dir+'/application/object_mappings/__init__.py','w') as f:
pass
f=file(main_dir+'/application/object_mappings/_object_mappings.py','w');f.write('\n'.join(cl));f.write('\n'.join(mp));f.close()
f=file(main_dir+'/application/object_mappings/_object_popo.py','w');f.write('\n'.join(mp_popo));f.close()
import application.object_mappings._object_mappings as _object_mappings
import application.object_mappings._object_popo as _object_popo
#Session = sqa.orm.sessionmaker(bind=metadata.bind)
#session=Session()
mapping_stub=_object_mappings.mapping_stub
for t in metadata.tables.values():
if '_depends' in t.info and not t.name.startswith('model_') and t.info.get('has_object_model',False):
t._obj=getattr(_object_mappings,'O'+t.name)
t._obj.__metadata=metadata
t._plain_obj=getattr(_object_popo,'popo_O'+t.name)
t._plain_obj._cls_=t._obj

Failure:

def create_mappings--- This code section failed: ---
0	LOAD_CONST 'from sqlalchemy.orm import *'
3	LOAD_CONST 'from context import CONTEXT'
6	LOAD_CONST 'metadata=CONTEXT.DB.metadata'
9	BUILD_LIST_3 ''
12	STORE_FAST 'cl'
15	BUILD_LIST_0 ''
18	STORE_FAST 'mp'
21	LOAD_FAST 'cl'
24	LOAD_ATTR 'append'
27	LOAD_GLOBAL 'str_stub'
30	CALL_FUNCTION_1 ''
33	POP_TOP ''
34	LOAD_CONST 'from data_session import session_obj'
37	BUILD_LIST_1 ''
40	STORE_FAST 'mp_popo'
43	SETUP_LOOP '216'
46	LOAD_GLOBAL 'sort_by_depends'
49	LOAD_FAST 'metadata'
52	CALL_FUNCTION_1 ''
55	GET_ITER ''
56	FOR_ITER '215'
59	STORE_FAST 't'
62	LOAD_CONST '_depends'
65	LOAD_FAST 't'
68	LOAD_ATTR 'info'
71	COMPARE_OP 'in'
74	POP_JUMP_IF_FALSE '56'
77	LOAD_FAST 't'
80	LOAD_ATTR 'name'
83	LOAD_ATTR 'startswith'
86	LOAD_CONST 'model_'
89	CALL_FUNCTION_1 ''
92	UNARY_NOT ''
93	POP_JUMP_IF_FALSE '56'
96	LOAD_FAST 't'
99	LOAD_ATTR 'info'
102	LOAD_ATTR 'get'
105	LOAD_CONST 'has_object_model'
108	LOAD_GLOBAL 'False'
111	CALL_FUNCTION_2 ''
114_0	COME_FROM '74'
114_1	COME_FROM '93'
114	POP_JUMP_IF_FALSE '56'
117	LOAD_FAST 'cl'
120	LOAD_ATTR 'append'
123	LOAD_FAST 't'
126	LOAD_ATTR 'info'
129	LOAD_CONST 'mapping_sources'
132	BINARY_SUBSCR ''
133	LOAD_CONST ''
136	BINARY_SUBSCR ''
137	CALL_FUNCTION_1 ''
140	POP_TOP ''
141	LOAD_FAST 'mp'
144	LOAD_ATTR 'append'
147	LOAD_CONST 'CONTEXT.logger.debug("Mapping \\"%s\\" .. ")'
150	LOAD_FAST 't'
153	LOAD_ATTR 'name'
156	BINARY_MODULO ''
157	CALL_FUNCTION_1 ''
160	POP_TOP ''
161	LOAD_FAST 'mp'
164	LOAD_ATTR 'append'
167	LOAD_FAST 't'
170	LOAD_ATTR 'info'
173	LOAD_CONST 'mapping_sources'
176	BINARY_SUBSCR ''
177	LOAD_CONST 1
180	BINARY_SUBSCR ''
181	CALL_FUNCTION_1 ''
184	POP_TOP ''
185	LOAD_FAST 'mp_popo'
188	LOAD_ATTR 'append'
191	LOAD_FAST 't'
194	LOAD_ATTR 'info'
197	LOAD_CONST 'mapping_sources'
200	BINARY_SUBSCR ''
201	LOAD_CONST 2
204	BINARY_SUBSCR ''
205	CALL_FUNCTION_1 ''
208	POP_TOP ''
209	JUMP_BACK '56'
212	JUMP_BACK '56'
215_0	COME_FROM '56'
215	POP_BLOCK ''
216_0	COME_FROM '43'
216	LOAD_FAST 'create_file'
219	POP_JUMP_IF_FALSE '447'
222	LOAD_GLOBAL 'util'
225	LOAD_ATTR 'get_main_dir'
228	CALL_FUNCTION_0 ''
231	STORE_FAST 'main_dir'
234	LOAD_GLOBAL 'sys'
237	LOAD_ATTR 'path'
240	LOAD_ATTR 'append'
243	LOAD_FAST 'main_dir'
246	CALL_FUNCTION_1 ''
249	POP_TOP ''
250	LOAD_GLOBAL 'os'
253	LOAD_ATTR 'path'
256	LOAD_ATTR 'exists'
259	LOAD_FAST 'main_dir'
262	LOAD_CONST '/application/object_mappings/__init__.py'
265	BINARY_ADD ''
266	CALL_FUNCTION_1 ''
269	POP_JUMP_IF_TRUE '320'
272	LOAD_GLOBAL 'util'
275	LOAD_ATTR 'forcedirs'
278	LOAD_FAST 'main_dir'
281	LOAD_CONST '/application/object_mappings'
284	BINARY_ADD ''
285	CALL_FUNCTION_1 ''
288	POP_TOP ''
289	LOAD_GLOBAL 'file'
292	LOAD_FAST 'main_dir'
295	LOAD_CONST '/application/object_mappings/__init__.py'
298	BINARY_ADD ''
299	LOAD_CONST 'w'
302	CALL_FUNCTION_2 ''
305	SETUP_WITH '315'
308	STORE_FAST 'f'
311	POP_BLOCK ''
312	LOAD_CONST ''
315_0	COME_FROM '305'
315	WITH_CLEANUP ''
316	END_FINALLY ''
317	JUMP_FORWARD '320'
320_0	COME_FROM '317'
320	LOAD_GLOBAL 'file'
323	LOAD_FAST 'main_dir'
326	LOAD_CONST '/application/object_mappings/_object_mappings.py'
329	BINARY_ADD ''
330	LOAD_CONST 'w'
333	CALL_FUNCTION_2 ''
336	STORE_FAST 'f'
339	LOAD_FAST 'f'
342	LOAD_ATTR 'write'
345	LOAD_CONST '\n'
348	LOAD_ATTR 'join'
351	LOAD_FAST 'cl'
354	CALL_FUNCTION_1 ''
357	CALL_FUNCTION_1 ''
360	POP_TOP ''
361	LOAD_FAST 'f'
364	LOAD_ATTR 'write'
367	LOAD_CONST '\n'
370	LOAD_ATTR 'join'
373	LOAD_FAST 'mp'
376	CALL_FUNCTION_1 ''
379	CALL_FUNCTION_1 ''
382	POP_TOP ''
383	LOAD_FAST 'f'
386	LOAD_ATTR 'close'
389	CALL_FUNCTION_0 ''
392	POP_TOP ''
393	LOAD_GLOBAL 'file'
396	LOAD_FAST 'main_dir'
399	LOAD_CONST '/application/object_mappings/_object_popo.py'
402	BINARY_ADD ''
403	LOAD_CONST 'w'
406	CALL_FUNCTION_2 ''
409	STORE_FAST 'f'
412	LOAD_FAST 'f'
415	LOAD_ATTR 'write'
418	LOAD_CONST '\n'
421	LOAD_ATTR 'join'
424	LOAD_FAST 'mp_popo'
427	CALL_FUNCTION_1 ''
430	CALL_FUNCTION_1 ''
433	POP_TOP ''
434	LOAD_FAST 'f'
437	LOAD_ATTR 'close'
440	CALL_FUNCTION_0 ''
443	POP_TOP ''
444	JUMP_FORWARD '447'
447_0	COME_FROM '444'
447	LOAD_CONST -1
450	LOAD_CONST ''
453	IMPORT_NAME 'application.object_mappings._object_mappings'
456	LOAD_ATTR 'object_mappings'
459	LOAD_ATTR '_object_mappings'
462	STORE_FAST '_object_mappings'
465	LOAD_CONST -1
468	LOAD_CONST ''
471	IMPORT_NAME 'application.object_mappings._object_popo'
474	LOAD_ATTR 'object_mappings'
477	LOAD_ATTR '_object_popo'
480	STORE_FAST '_object_popo'
483	LOAD_FAST '_object_mappings'
486	LOAD_ATTR 'mapping_stub'
489	STORE_GLOBAL 'mapping_stub'
492	SETUP_LOOP '653'
495	LOAD_FAST 'metadata'
498	LOAD_ATTR 'tables'
501	LOAD_ATTR 'values'
504	CALL_FUNCTION_0 ''
507	GET_ITER ''
508	FOR_ITER '652'
511	STORE_FAST 't'
514	LOAD_CONST '_depends'
517	LOAD_FAST 't'
520	LOAD_ATTR 'info'
523	COMPARE_OP 'in'
526	POP_JUMP_IF_FALSE '508'
529	LOAD_FAST 't'
532	LOAD_ATTR 'name'
535	LOAD_ATTR 'startswith'
538	LOAD_CONST 'model_'
541	CALL_FUNCTION_1 ''
544	UNARY_NOT ''
545	POP_JUMP_IF_FALSE '508'
548	LOAD_FAST 't'
551	LOAD_ATTR 'info'
554	LOAD_ATTR 'get'
557	LOAD_CONST 'has_object_model'
560	LOAD_GLOBAL 'False'
563	CALL_FUNCTION_2 ''
566_0	COME_FROM '526'
566_1	COME_FROM '545'
566	POP_JUMP_IF_FALSE '508'
569	LOAD_GLOBAL 'getattr'
572	LOAD_FAST '_object_mappings'
575	LOAD_CONST 'O'
578	LOAD_FAST 't'
581	LOAD_ATTR 'name'
584	BINARY_ADD ''
585	CALL_FUNCTION_2 ''
588	LOAD_FAST 't'
591	STORE_ATTR '_obj'
594	LOAD_FAST 'metadata'
597	LOAD_FAST 't'
600	LOAD_ATTR '_obj'
603	STORE_ATTR '__metadata'
606	LOAD_GLOBAL 'getattr'
609	LOAD_FAST '_object_popo'
612	LOAD_CONST 'popo_O'
615	LOAD_FAST 't'
618	LOAD_ATTR 'name'
621	BINARY_ADD ''
622	CALL_FUNCTION_2 ''
625	LOAD_FAST 't'
628	STORE_ATTR '_plain_obj'
631	LOAD_FAST 't'
634	LOAD_ATTR '_obj'
637	LOAD_FAST 't'
640	LOAD_ATTR '_plain_obj'
643	STORE_ATTR '_cls_'
646	JUMP_BACK '508'
649	JUMP_BACK '508'
652_0	COME_FROM '508'
652	POP_BLOCK ''
653_0	COME_FROM '492'

Syntax error at or near `POP_BLOCK' token at offset 311