Пример #1
0
def printglobals():
    import inspect
    import types

    modules = []
    functions = []
    classes = []
    others = []

    for key, val in globals().iteritems():
        if key.startswith('_'):
            pass
        elif inspect.ismodule(val):
            modules.append((key, utils.first_line(val.__doc__)))
        elif inspect.isroutine(val):
            functions.append((key, utils.first_line(val.__doc__)))
        elif inspect.isclass(val):
            classes.append((key, utils.first_line(val.__doc__)))
        else:
            others.append((key,str(type(val))))

    def formatit(item, maxlen=60):
        if len(item) > maxlen:
            return item[:maxlen-3]+'...'
        return item

    if modules:
        print('Modules:')
        for item in modules:
            print '  %-15s  %s' % (item[0], formatit(item[1]))

    if functions:
        print('\nFunctions:')
        for item in functions:
            print '  %-15s  %s' % (item[0], formatit(item[1]))

    if classes:
        print('\nClasses:')
        for item in classes:
            print '  %-15s  %s' % (item[0], formatit(item[1]))

    if others:
        print('\nOthers:')
        for item in others:
            print '  %-15s  %s' % (item[0], formatit(item[1]))
Пример #2
0
 def _loadscript(self, name):
     """
         imports module and append it to global list or channel list
         doesn't raise anything
         returns:
             0 if module could not be loaded
             1 if it was loaded, but no import was necessary
             2 if it was loaded, but import was necessary
     """
     if name in g_scripts:
         return 1
     else:
         try:
             module = import_module("sqrl3.scripts." + name)
         except Exception as e:
             self.onexception("error while importing '%s': %s" % (name, e), unexpected=True)
             return 0
         handlers = {}
         defcommands = {}
         for _, func in inspect.getmembers(module, inspect.isfunction):
             if hasattr(func, "mtype"):
                 if func.commands:
                     # for @onprivmsg("title, "ti"):
                     # g_scripts["title"] += {"title": func, "ti": func}
                     # g_meta["title"] += Meta("title", "my cute module", {"title": "my cute title"})
                     defcommands[func.commands[0]] = None if func.__doc__ is None else first_line(func.__doc__)
                     for command in func.commands:
                         assert command not in handlers, "cannot define the same command twice"
                         handlers[command] = func
                 else:
                     # for @onprivmsg:
                     # g_scripts["title"] += {Privmsg: func}
                     assert func.mtype not in handlers, "cannot have more than one handler for the same message type"
                     handlers[func.mtype] = func
             elif hasattr(func, "ttype"):
                 # for @onload:
                 # g_scripts["title"] += {irc.Irc.onload: func}
                 assert func.ttype not in handlers, "really, what are you doing?"
                 handlers[func.ttype] = func
         g_scripts[name] = handlers
         g_meta[name] = Meta(name=name, doc=None if module.__doc__ is None else first_line(module.__doc__), commands=defcommands)
         return 2
Пример #3
0
 def _read(self, f):
     line = utils.first_line(f)
     return line.split()
Пример #4
0
 def _read(self, f):
     data = [int(i) for i in utils.first_line(f).split()]
     assert len(data) == 6
     return data
Пример #5
0
 def _read(self, f):
     n, m = utils.first_line(f).split()
     return int(n), int(m)
Пример #6
0
 def _read(self, f):
     k, N = utils.first_line(f).split()
     return int(k), int(N)
 def _read(self, f):
     return utils.first_line(f)