| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
from PySkinObject import PySkinObject |
|---|
| 27 |
import sys |
|---|
| 28 |
import weakref |
|---|
| 29 |
import inline |
|---|
| 30 |
|
|---|
| 31 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 32 |
#~ Class |
|---|
| 33 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 34 |
|
|---|
| 35 |
class import_(inline.inline): |
|---|
| 36 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 37 |
#~ Constants / Variables / Etc. |
|---|
| 38 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 39 |
|
|---|
| 40 |
default_settings = inline.inline.default_settings.copy() |
|---|
| 41 |
default_settings['module'] = None |
|---|
| 42 |
default_settings['from'] = None |
|---|
| 43 |
default_settings['attr'] = None |
|---|
| 44 |
default_settings['reload'] = '0' |
|---|
| 45 |
|
|---|
| 46 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 47 |
#~ Public Methods |
|---|
| 48 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 49 |
|
|---|
| 50 |
def ExecuteXML(self, **Variables): |
|---|
| 51 |
SysPathIdx = len(sys.path) |
|---|
| 52 |
sys.path.insert(SysPathIdx, self.context.__root__) |
|---|
| 53 |
|
|---|
| 54 |
if 'from' in self.source_settings: |
|---|
| 55 |
# Import the module, and then grab the attribute out of it |
|---|
| 56 |
AttrName = self.settings['attr'] |
|---|
| 57 |
module = __import__(self.settings['from'], {}, {}, AttrName) |
|---|
| 58 |
module = getattr(module, AttrName) |
|---|
| 59 |
self.AddNamespace({AttrName: module}) |
|---|
| 60 |
elif 'module' in self.source_settings: |
|---|
| 61 |
# Import the module in a direct fassion |
|---|
| 62 |
ModuleName = self.settings['module'] |
|---|
| 63 |
module = __import__(ModuleName, {}, {}) |
|---|
| 64 |
self.AddNamespace({ModuleName: module}) |
|---|
| 65 |
else: |
|---|
| 66 |
# Just run the contents! |
|---|
| 67 |
module = None |
|---|
| 68 |
# Run the code |
|---|
| 69 |
localvars = Variables.copy() |
|---|
| 70 |
code = compile(self.GetCode(), name, 'exec') |
|---|
| 71 |
exec code in localvars |
|---|
| 72 |
self.AddNamespace(localvars) |
|---|
| 73 |
|
|---|
| 74 |
if module and int(self.settings['reload']): |
|---|
| 75 |
reload(module) |
|---|
| 76 |
|
|---|
| 77 |
sys.path.pop(SysPathIdx) |
|---|
| 78 |
return module |
|---|
| 79 |
|
|---|