Example #1
0
def find(s, name):
    """ To find an object with a certain name.
    """
    for n in s:
        if ssdf.isstruct(s):
            v = s[n]
        else:
            v = n
            n = None
        
        res = None
        if n == name:
            return v
        elif ssdf.isstruct(v) or isinstance(v, dict):
            res = find(v, name)
        elif isinstance(v, (list, tuple)):
            res = find(v, name)
        elif n:
            print(n)
        if res:
            return res
Example #2
0
    def __init__(self, info=None):

        # ----- Fixed parameters that define a shell -----

        # scriptFile is used to define the mode. If given, we run in
        # script-mode. Otherwise we run in interactive mode.

        # The name of this shell config. Can be used to name the kernel
        self.name = 'Python'

        # The executable. This can be '/usr/bin/python3.1' or
        # 'c:/program files/python2.6/python.exe', etc.
        # The "[default]" is a placeholder text that is replaced at the last
        # moment with iep.defaultInterpreterExe()
        self.exe = '[default]'

        # The GUI toolkit to embed the event loop of.
        # Instantiate with a value that is settable
        self.gui = iep.defaultInterpreterGui() or 'none'

        # The Python path. Paths should be separated by newlines.
        # '$PYTHONPATH' is replaced by environment variable by broker
        self.pythonPath = ''

        # The path of the current project, the kernel will prepend this
        # to the sys.path. The broker could prepend to PYTHONPATH, but
        # in this way it is more explicit (kernel can tell the user that
        # the project path was prepended).
        self.projectPath = ''

        # The full filename of the script to run.
        # If given, the kernel should run in script-mode.
        # The kernel will check whether this file exists, and will
        # revert to interactive mode if it doesn't.
        self.scriptFile = ''

        # Interactive-mode only:

        # The initial directory. Only used for interactive-mode; in
        # script-mode the initial directory is the dir of the script.
        self.startDir = ''

        # The Startup script (only used for interactive-mode).
        # - Empty string means run nothing,
        # - Single line means file name
        # - multiple lines means source code.
        # - '$PYTHONSTARTUP' uses the code in that file. Broker replaces this.
        self.startupScript = ''

        # Load info from ssdf struct. Make sure they are all strings
        if info:
            # Get struct
            if isinstance(info, dict):
                s = info
            elif ssdf.isstruct(info):
                s = info
            elif isinstance(info, str):
                s = ssdf.loads(info)
            else:
                raise ValueError(
                    'Kernel info should be a string or ssdf struct, not %s' %
                    str(type(info)))
            # Inject values
            for key in s:
                val = s[key]
                if not val:
                    val = ''
                self[key] = val
Example #3
0
 def __init__(self, info=None):
     
     # ----- Fixed parameters that define a shell -----
     
     # scriptFile is used to define the mode. If given, we run in 
     # script-mode. Otherwise we run in interactive mode.
     
     # The name of this shell config. Can be used to name the kernel
     self.name = 'Python'
     
     # The executable. This can be '/usr/bin/python3.1' or 
     # 'c:/program files/python2.6/python.exe', etc.
     self.exe = ''
     
     # The GUI toolkit to embed the event loop of. 
     # Instantiate with a value that is settable
     self.gui = 'Auto'
     
     # The Python path. Paths should be separated by newlines.
     # '$PYTHONPATH' is replaced by environment variable by broker
     self.pythonPath = ''
     
     # The path of the current project, the kernel will prepend this 
     # to the sys.path. The broker could prepend to PYTHONPATH, but
     # in this way it is more explicit (kernel can tell the user that
     # the project path was prepended).
     self.projectPath = ''
     
     # The full filename of the script to run. 
     # If given, the kernel should run in script-mode.
     # The kernel will check whether this file exists, and will
     # revert to interactive mode if it doesn't.
     self.scriptFile = ''
     
     # Interactive-mode only:
     
     # The initial directory. Only used for interactive-mode; in
     # script-mode the initial directory is the dir of the script.
     self.startDir = '' 
     
     # The Startup script (only used for interactive-mode).
     # - Empty string means run nothing, 
     # - Single line means file name
     # - multiple lines means source code.
     # - '$PYTHONSTARTUP' uses the code in that file. Broker replaces this.
     self.startupScript = ''
     
     # Additional command line arguments, set by the kernel
     self.argv = ''
     
     # Additional environment variables
     self.environ = ''
     
     # Load info from ssdf struct. Make sure they are all strings
     if info:
         # Get struct
         if isinstance(info, dict):
             s = info
         elif ssdf.isstruct(info):
             s = info
         elif isinstance(info, str):
             s = ssdf.loads(info)
         else:
             raise ValueError('Kernel info should be a string or ssdf struct, not %s' % str(type(info)))
         # Inject values
         for key in s:
             val = s[key]
             if not val:
                 val = ''
             self[key] = val