Ejemplo n.º 1
0
def nevowify(filename, linkrel, ext, url, templ, options=None, outfileGenerator=tree.getOutputFileName):
    if options is None:
        options = {}
    pclass = options['pageclass']
    pclass = reflect.namedObject(pclass)
    page = pclass(docFactory=loaders.htmlfile(filename))
    s = page.renderString()
    s = ____wait(s)

    newFilename = outfileGenerator(filename, ext)

    if options.has_key('nolore'):
        f = open(newFilename, 'w')
        f.write(s)
        f.close()
        return

    doc = parseStringAndReport(s)
    clonedNode = templ.cloneNode(1)
    tree.munge(doc, clonedNode, linkrel, os.path.dirname(filename), filename, ext,
               url, options, outfileGenerator)
    tree.makeSureDirectoryExists(newFilename)
    f = open(newFilename, 'wb')
    clonedNode.writexml(f)
    f.close()
Ejemplo n.º 2
0
 def __init__(self, methodName):
     if type(methodName) is types.StringType:
         self.testClass = reflect.namedObject('.'.join(methodName.split('.')[:-1]))
         methodName = methodName.split('.')[-1]
     else:
         self.testClass = methodName.im_class
         self.methodName = methodName.__name__
Ejemplo n.º 3
0
    def unjelly(self, obj):
        if type(obj) is not list:
            return obj
        jelTypeBytes = obj[0]
        if not self.taster.isTypeAllowed(jelTypeBytes):
            raise InsecureJelly(jelTypeBytes)
        regClass = unjellyableRegistry.get(jelTypeBytes)
        if regClass is not None:
            method = getattr(_createBlank(regClass), "unjellyFor", regClass)
            return self._maybePostUnjelly(method(self, obj))
        regFactory = unjellyableFactoryRegistry.get(jelTypeBytes)
        if regFactory is not None:
            return self._maybePostUnjelly(regFactory(self.unjelly(obj[1])))

        jelTypeText = nativeString(jelTypeBytes)
        thunk = getattr(self, '_unjelly_%s' % jelTypeText, None)
        if thunk is not None:
            return thunk(obj[1:])
        else:
            nameSplit = jelTypeText.split('.')
            modName = '.'.join(nameSplit[:-1])
            if not self.taster.isModuleAllowed(modName):
                raise InsecureJelly(
                    "Module %s not allowed (in type %s)." % (modName, jelTypeText))
            clz = namedObject(jelTypeText)
            if not self.taster.isClassAllowed(clz):
                raise InsecureJelly("Class %s not allowed." % jelTypeText)
            return self._genericUnjelly(clz, obj[1])
Ejemplo n.º 4
0
 def handleInput(self, identifier, *args):
     if identifier == "close":
         if DEBUG:
             print "CLIENT ACKED CLOSE"
         ## This happens in a callLater(0) from the original request
         self.onClosed.callback(None)
         self.closed = True
         self.onClosed = defer.Deferred()
     if DEBUG:
         print "Dispatching event to observer", identifier, args
     try:
         ## If the identifier provided is the fully-qualified name of a callable,
         ## The function was registered with no closure and we can get to it
         ## easily.
         named = reflect.namedObject(identifier)
         named = getattr(named, "callit", named)
         try:
             named(self, *args)
         except:
             log.err()
     except (AttributeError, ValueError):
         if DEBUG:
             print "Observers", self.events._subscribers
         try:
             self.events.publish(identifier, *(self,) + args)
         except:
             log.err()
Ejemplo n.º 5
0
 def receiveChild(self, obj, ready_deferred=None):
     assert not isinstance(obj, Deferred)
     assert ready_deferred is None
     if self.finished:
         raise BananaError("FunctionUnslicer only accepts one string")
     self.finished = True
     self.func = reflect.namedObject(obj)
Ejemplo n.º 6
0
def autocrud(nodes, name, modelFQN):

    model = reflect.namedObject(modelFQN)

    schema = [a for a in dir(model) if isinstance(getattr(model, a), PropertyColumn)]

    if "id" not in schema:
        print "Sorry, this code isn't clever enough to auto-crud models with no id"
        return

    listCols = ["id"]
    if "name" in schema:
        listCols.append("name")

    crudCols = schema[:]
    crudCols.remove("id")

    if "name" in crudCols:
        crudCols.remove("name")
        crudCols.insert(0, "name")

    listColumns = ", ".join('"%s"' % c for c in listCols)
    crudColumns = textwrap.fill(", ".join('"%s"' % c for c in crudCols))

    nodeContent = crudTemplate % {
        "listColumns": listColumns,
        "crudColumns": crudColumns,
        "model": modelFQN.rsplit(".", 1)[1],
        "node": name,
    }

    skeleton.createNode(nodes, name, createIndex=False, nodeContent=nodeContent)
Ejemplo n.º 7
0
 def _unjelly_function(self, rest):
     modSplit = string.split(rest[0], '.')
     modName = string.join(modSplit[:-1], '.')
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("Module not allowed: %s"% modName)
     function = namedObject(rest[0])
     return function
Ejemplo n.º 8
0
Archivo: jobs.py Proyecto: D3f0/txscada
    def remote_registerClasses(self, *args):
        """
        Instructs my broker to register the classes specified by the
        argument(s).

        The classes will be registered for B{all} jobs, and are specified by
        their string representations::
        
            <package(s).module.class>
        
        """
        modules = []
        for stringRep in args:
            # Load the class for the string representation
            cls = reflect.namedObject(stringRep)
            # Register instances of the class, including its type and module
            pb.setUnjellyableForClass(stringRep, cls)
            if cls.__module__ not in modules:
                modules.append(cls.__module__)
        # Try to build the modules for the classes in case they've changed
        # since the last run
        for module in modules:
            try:
                rebuild(reflect.namedModule(module), doLog=False)
            except:
                pass
Ejemplo n.º 9
0
 def receiveClose(self):
     klass = reflect.namedObject(self.classname)
     assert type(klass) == types.ClassType # TODO: new-style classes
     obj = instance(klass, {})
     setInstanceState(obj, self.d)
     self.protocol.setObject(self.count, obj)
     self.deferred.callback(obj)
     return obj, None
Ejemplo n.º 10
0
 def receiveChild(self, obj, ready_deferred=None):
     assert not isinstance(obj, Deferred)
     assert ready_deferred is None
     if self.finished:
         raise BananaError("ClassUnslicer only accepts one string")
     self.finished = True
     # TODO: taste here!
     self.klass = reflect.namedObject(obj)
Ejemplo n.º 11
0
 def _unjelly_function(self, rest):
     modSplit = rest[0].split('.')
     modName = '.'.join(modSplit[:-1])
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("Module not allowed: %s"% modName)
     # XXX do I need an isFunctionAllowed?
     function = namedObject(rest[0])
     return function
Ejemplo n.º 12
0
 def _unjelly_function(self, rest):
     modSplit = string.split(rest[0], '.')
     # if len(rest) > 0: warn("reference numbers will be out of sync")
     modName = string.join(modSplit[:-1], '.')
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("Module not allowed: %s"% modName)
     # XXX do I need an isFunctionAllowed?
     function = namedObject(rest[0])
     self.resolveReference(function)
     return function
Ejemplo n.º 13
0
 def unjelly(self, obj):
     if type(obj) is not types.ListType:
         return obj
     self.references.append(_theNullRef)
     jelType = obj[0]
     if not self.taster.isTypeAllowed(jelType):
         raise InsecureJelly(jelType)
     regClass = unjellyableRegistry.get(jelType)
     if regClass is not None:
         if isinstance(regClass, ClassType):
             inst = _Dummy() # XXX chomp, chomp
             self.resolveReference(inst)
             inst.__class__ = regClass
             val = inst.unjellyFor(self,obj)
         else:
             refid = self.getRefId()
             self.resolveReference(NotKnown())
             val = regClass(self, obj) # this is how it ought to be done
             self.resolveReference(val, refid)
         if hasattr(val, 'postUnjelly'):
             self.postCallbacks.append(inst.postUnjelly)
         return val
     regFactory = unjellyableFactoryRegistry.get(jelType)
     if regFactory is not None:
         refid = self.getRefId()
         self.resolveReference(NotKnown())
         state = self.unjelly(obj[1])
         inst = regFactory(state)
         if hasattr(inst, 'postUnjelly'):
             self.postCallbacks.append(inst.postUnjelly)
         return self.resolveReference(inst, refid)
     thunk = getattr(self, '_unjelly_%s'%jelType, None)
     if thunk is not None:
         ret = thunk(obj[1:])
     else:
         nameSplit = string.split(jelType, '.')
         modName = string.join(nameSplit[:-1], '.')
         if not self.taster.isModuleAllowed(modName):
             raise InsecureJelly("Module %s not allowed." % modName)
         clz = namedObject(jelType)
         if not self.taster.isClassAllowed(clz):
             raise InsecureJelly("Class %s not allowed." % jelType)
         if hasattr(clz, "__setstate__"):
             ret = instance(clz, {})
             self.resolveReference(ret)
             state = self.unjelly(obj[1])
             ret.__setstate__(state)
         else:
             ret = instance(clz, {})
             self.resolveReference(ret)
             state = self.unjelly(obj[1])
             ret.__dict__ = state
         if hasattr(clz, 'postUnjelly'):
             self.postCallbacks.append(ret.postUnjelly)
     return ret
Ejemplo n.º 14
0
 def _unjelly_class(self, rest):
     clist = string.split(rest[0], '.')
     modName = string.join(clist[:-1], '.')
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("module %s not allowed" % modName)
     klaus = namedObject(rest[0])
     if type(klaus) is not types.ClassType:
         raise InsecureJelly("class %s unjellied to something that isn't a class: %s" % (repr(name), repr(klaus)))
     if not self.taster.isClassAllowed(klaus):
         raise InsecureJelly("class not allowed: %s" % qual(klaus))
     return klaus
Ejemplo n.º 15
0
 def _unjelly_class(self, rest):
     clist = rest[0].split(".")
     modName = ".".join(clist[:-1])
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("module %s not allowed" % modName)
     klaus = namedObject(rest[0])
     objType = type(klaus)
     if objType not in (types.ClassType, types.TypeType):
         raise InsecureJelly("class %r unjellied to something that isn't a class: %r" % (rest[0], klaus))
     if not self.taster.isClassAllowed(klaus):
         raise InsecureJelly("class not allowed: %s" % qual(klaus))
     return klaus
Ejemplo n.º 16
0
 def _unjelly_class(self, rest):
     clist = string.split(rest[0], '.')
     modName = string.join(clist[:-1], '.')
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("module %s not allowed" % modName)
     klaus = namedObject(rest[0])
     if type(klaus) is not types.ClassType:
         raise InsecureJelly(
             "class %s unjellied to something that isn't a class: %s" %
             (repr(name), repr(klaus)))
     if not self.taster.isClassAllowed(klaus):
         raise InsecureJelly("class not allowed: %s" % qual(klaus))
     return klaus
Ejemplo n.º 17
0
    def removeComponent(self, component):
        """
        Remove the given component from me entirely, for all interfaces for which
        it has been registered.

        @return: a list of the interfaces that were removed.
        """
        l = []
        for k, v in self._adapterCache.items():
            if v is component:
                del self._adapterCache[k]
                l.append(reflect.namedObject(k))
        return l
Ejemplo n.º 18
0
    def removeComponent(self, component):
        """
        Remove the given component from me entirely, for all interfaces for which
        it has been registered.

        @return: a list of the interfaces that were removed.
        """
        l = []
        for k, v in self._adapterCache.items():
            if v is component:
                del self._adapterCache[k]
                l.append(reflect.namedObject(k))
        return l
Ejemplo n.º 19
0
 def _unjelly_class(self, rest):
     clist = string.split(rest[0], '.')
     # if len(rest) > 0: warn("reference numbers will be out of sync")
     modName = string.join(clist[:-1], '.')
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("module %s not allowed" % modName)
     klaus = namedObject(rest[0])
     if type(klaus) is not types.ClassType:
         raise InsecureJelly("class %s unjellied to something that isn't a class: %s" % (repr(name), repr(klaus)))
     if not self.taster.isClassAllowed(klaus):
         raise InsecureJelly("class not allowed: %s" % qual(klaus))
     self.resolveReference(klaus)
     return klaus
Ejemplo n.º 20
0
 def unjelly(self, obj):
     if type(obj) is not types.ListType:
         return obj
     jelType = obj[0]
     if not self.taster.isTypeAllowed(jelType):
         raise InsecureJelly(jelType)
     regClass = unjellyableRegistry.get(jelType)
     if regClass is not None:
         if isinstance(regClass, ClassType):
             inst = _Dummy() # XXX chomp, chomp
             inst.__class__ = regClass
             method = inst.unjellyFor
         elif isinstance(regClass, type):
             # regClass.__new__ does not call regClass.__init__
             inst = regClass.__new__(regClass)
             method = inst.unjellyFor
         else:
             method = regClass # this is how it ought to be done
         val = method(self, obj)
         if hasattr(val, 'postUnjelly'):
             self.postCallbacks.append(inst.postUnjelly)
         return val
     regFactory = unjellyableFactoryRegistry.get(jelType)
     if regFactory is not None:
         state = self.unjelly(obj[1])
         inst = regFactory(state)
         if hasattr(inst, 'postUnjelly'):
             self.postCallbacks.append(inst.postUnjelly)
         return inst
     thunk = getattr(self, '_unjelly_%s'%jelType, None)
     if thunk is not None:
         ret = thunk(obj[1:])
     else:
         nameSplit = jelType.split('.')
         modName = '.'.join(nameSplit[:-1])
         if not self.taster.isModuleAllowed(modName):
             raise InsecureJelly(
                 "Module %s not allowed (in type %s)." % (modName, jelType))
         clz = namedObject(jelType)
         if not self.taster.isClassAllowed(clz):
             raise InsecureJelly("Class %s not allowed." % jelType)
         if hasattr(clz, "__setstate__"):
             ret = _newInstance(clz)
             state = self.unjelly(obj[1])
             ret.__setstate__(state)
         else:
             state = self.unjelly(obj[1])
             ret = _newInstance(clz, state)
         if hasattr(clz, 'postUnjelly'):
             self.postCallbacks.append(ret.postUnjelly)
     return ret
Ejemplo n.º 21
0
 def unjelly(self, obj):
     if type(obj) is not types.ListType:
         return obj
     jelType = obj[0]
     if not self.taster.isTypeAllowed(jelType):
         raise InsecureJelly(jelType)
     regClass = unjellyableRegistry.get(jelType)
     if regClass is not None:
         if isinstance(regClass, ClassType):
             inst = _Dummy()  # XXX chomp, chomp
             inst.__class__ = regClass
             method = inst.unjellyFor
         elif isinstance(regClass, type):
             # regClass.__new__ does not call regClass.__init__
             inst = regClass.__new__(regClass)
             method = inst.unjellyFor
         else:
             method = regClass  # this is how it ought to be done
         val = method(self, obj)
         if hasattr(val, 'postUnjelly'):
             self.postCallbacks.append(inst.postUnjelly)
         return val
     regFactory = unjellyableFactoryRegistry.get(jelType)
     if regFactory is not None:
         state = self.unjelly(obj[1])
         inst = regFactory(state)
         if hasattr(inst, 'postUnjelly'):
             self.postCallbacks.append(inst.postUnjelly)
         return inst
     thunk = getattr(self, '_unjelly_%s' % jelType, None)
     if thunk is not None:
         ret = thunk(obj[1:])
     else:
         nameSplit = jelType.split('.')
         modName = '.'.join(nameSplit[:-1])
         if not self.taster.isModuleAllowed(modName):
             raise InsecureJelly("Module %s not allowed (in type %s)." %
                                 (modName, jelType))
         clz = namedObject(jelType)
         if not self.taster.isClassAllowed(clz):
             raise InsecureJelly("Class %s not allowed." % jelType)
         if hasattr(clz, "__setstate__"):
             ret = _newInstance(clz, {})
             state = self.unjelly(obj[1])
             ret.__setstate__(state)
         else:
             state = self.unjelly(obj[1])
             ret = _newInstance(clz, state)
         if hasattr(clz, 'postUnjelly'):
             self.postCallbacks.append(ret.postUnjelly)
     return ret
Ejemplo n.º 22
0
def run():
    config = Options()
    try:
        config.parseOptions()
    except usage.error as e:
        print("{}:  {}".format(sys.argv[0], e))
        print()
        c = getattr(config, 'subOptions', config)
        print(str(c))
        sys.exit(1)

    subconfig = config.subOptions
    subcommandFunction = reflect.namedObject(subconfig.subcommandFunction)
    sys.exit(subcommandFunction(subconfig))
Ejemplo n.º 23
0
    def receiveClose(self):
        # you could attempt to do some value-checking here, but there would
        # probably still be holes

        #obj = Dummy()
        klass = reflect.namedObject(self.classname)
        assert type(klass) == types.ClassType  # TODO: new-style classes
        obj = instance(klass, {})

        setInstanceState(obj, self.d)

        self.protocol.setObject(self.count, obj)
        self.deferred.callback(obj)
        return obj, None
Ejemplo n.º 24
0
def run():
    config = Options()
    try:
        config.parseOptions()
    except usage.error as e:
        log.msg("%s:  %s" % (sys.argv[0], e))
        log.msg()
        c = getattr(config, 'subOptions', config)
        log.msg(str(c))
        sys.exit(1)

    subconfig = config.subOptions
    subcommandFunction = reflect.namedObject(subconfig.subcommandFunction)
    sys.exit(subcommandFunction(subconfig))
Ejemplo n.º 25
0
    def receiveClose(self):
        # you could attempt to do some value-checking here, but there would
        # probably still be holes

        #obj = Dummy()
        klass = reflect.namedObject(self.classname)
        assert type(klass) == types.ClassType # TODO: new-style classes
        obj = instance(klass, {})

        setInstanceState(obj, self.d)

        self.protocol.setObject(self.count, obj)
        self.deferred.callback(obj)
        return obj, None
Ejemplo n.º 26
0
 def _unjelly_class(self, rest):
     clist = rest[0].split('.')
     modName = '.'.join(clist[:-1])
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("module %s not allowed" % modName)
     klaus = namedObject(rest[0])
     objType = type(klaus)
     if objType not in (types.ClassType, types.TypeType):
         raise InsecureJelly(
             "class %r unjellied to something that isn't a class: %r" %
             (rest[0], klaus))
     if not self.taster.isClassAllowed(klaus):
         raise InsecureJelly("class not allowed: %s" % qual(klaus))
     return klaus
Ejemplo n.º 27
0
def run():
    config = Options()
    try:
        config.parseOptions()
    except usage.error as e:
        print("%s:  %s" % (sys.argv[0], e))
        print()
        c = getattr(config, 'subOptions', config)
        print(str(c))
        sys.exit(1)

    subconfig = config.subOptions
    subcommandFunction = reflect.namedObject(subconfig.subcommandFunction)
    sys.exit(subcommandFunction(subconfig))
Ejemplo n.º 28
0
 def _unjelly_class(self, rest):
     cname = nativeString(rest[0])
     clist = cname.split(nativeString('.'))
     modName = nativeString('.').join(clist[:-1])
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("module %s not allowed" % modName)
     klaus = namedObject(cname)
     objType = type(klaus)
     if objType not in (_OldStyleClass, type):
         raise InsecureJelly(
             "class %r unjellied to something that isn't a class: %r" % (
                 cname, klaus))
     if not self.taster.isClassAllowed(klaus):
         raise InsecureJelly("class not allowed: %s" % qual(klaus))
     return klaus
Ejemplo n.º 29
0
 def _unjelly_class(self, rest):
     cname = nativeString(rest[0])
     clist = cname.split(nativeString('.'))
     modName = nativeString('.').join(clist[:-1])
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("module %s not allowed" % modName)
     klaus = namedObject(cname)
     objType = type(klaus)
     if objType not in (_OldStyleClass, type):
         raise InsecureJelly(
             "class %r unjellied to something that isn't a class: %r" %
             (cname, klaus))
     if not self.taster.isClassAllowed(klaus):
         raise InsecureJelly("class not allowed: %s" % qual(klaus))
     return klaus
Ejemplo n.º 30
0
 def _unjelly_class(self, rest):
     clist = string.split(rest[0], '.')
     # if len(rest) > 0: warn("reference numbers will be out of sync")
     modName = string.join(clist[:-1], '.')
     if not self.taster.isModuleAllowed(modName):
         raise InsecureJelly("module %s not allowed" % modName)
     klaus = namedObject(rest[0])
     if type(klaus) is not types.ClassType:
         raise InsecureJelly(
             "class %s unjellied to something that isn't a class: %s" %
             (repr(name), repr(klaus)))
     if not self.taster.isClassAllowed(klaus):
         raise InsecureJelly("class not allowed: %s" % qual(klaus))
     self.resolveReference(klaus)
     return klaus
Ejemplo n.º 31
0
def run():
    config = Options()
    check_functional_environment(buildbot.config)
    try:
        config.parseOptions(sys.argv[1:])
    except usage.error as e:
        print("%s:  %s" % (sys.argv[0], e))
        print()

        c = getattr(config, 'subOptions', config)
        print(str(c))
        sys.exit(1)

    subconfig = config.subOptions
    subcommandFunction = reflect.namedObject(subconfig.subcommandFunction)
    sys.exit(subcommandFunction(subconfig))
Ejemplo n.º 32
0
    def setup(self):
        assert not self.impl

        # imports are done locally so that we don't try to import
        # implementation-specific modules unless they're required.
        typ = self.config.mq.get('type', 'simple')
        assert typ in self.classes # this is checked by MasterConfig
        self.impl_type = typ
        cls = namedObject(self.classes[typ])
        self.impl = cls(self.highscore, self.config)

        # set up the impl as a child service
        self.impl.setServiceParent(self)

        # copy the methods onto this object for ease of access
        self.produce = self.impl.produce
        self.consume = self.impl.consume
Ejemplo n.º 33
0
    def applyUpgrade(self, fp):
        """
        Apply the data upgrade .py files to the database.
        """

        # Find the module function we need to execute
        try:
            module = getModule(__name__)
            module = ".".join(module.name.split(".")[:-1]) + ".upgrades." + fp.basename()[:-3] + ".doUpgrade"
            doUpgrade = namedObject(module)
        except ImportError:
            msg = "Failed data upgrade: %s" % (fp.basename()[:-4],)
            self.log.error(msg)
            raise RuntimeError(msg)

        self.log.warn("Applying data upgrade: {module}", module=module)
        yield doUpgrade(self.sqlStore)
Ejemplo n.º 34
0
    def applyUpgrade(self, fp):
        """
        Apply the data upgrade .py files to the database.
        """

        # Find the module function we need to execute
        try:
            module = getModule(__name__)
            module = ".".join(module.name.split(".")[:-1]) + ".upgrades." + fp.basename()[:-3] + ".doUpgrade"
            doUpgrade = namedObject(module)
        except ImportError:
            msg = "Failed data upgrade: %s" % (fp.basename()[:-4],)
            self.log_error(msg)
            raise RuntimeError(msg)

        self.log_warn("Applying data upgrade: %s" % (module,))
        yield doUpgrade(self.sqlStore)
Ejemplo n.º 35
0
    def setup(self):
        assert not self.impl

        # imports are done locally so that we don't try to import
        # implementation-specific modules unless they're required.
        typ = self.config.mq.get('type', 'simple')
        assert typ in self.classes  # this is checked by MasterConfig
        self.impl_type = typ
        cls = namedObject(self.classes[typ])
        self.impl = cls(self.highscore, self.config)

        # set up the impl as a child service
        self.impl.setServiceParent(self)

        # copy the methods onto this object for ease of access
        self.produce = self.impl.produce
        self.consume = self.impl.consume
Ejemplo n.º 36
0
 def removeComponent(self, component):
     """
     Remove the given component from me entirely, for all interfaces for which
     it has been registered.
     @return: a list of the interfaces that were removed.
     """
     if (isinstance(component, types.ClassType) or
         isinstance(component, types.TypeType)):
         warnings.warn("passing interface to removeComponent, you probably want unsetComponent", DeprecationWarning, 1)
         self.unsetComponent(component)
         return [component]
     l = []
     for k, v in self._adapterCache.items():
         if v is component:
             del self._adapterCache[k]
             l.append(reflect.namedObject(k))
     return l
Ejemplo n.º 37
0
    def removeComponent(self, component):
        """
        Remove the given component from me entirely, for all interfaces for which
        it has been registered.

        @return: a list of the interfaces that were removed.
        """
        if (isinstance(component, types.ClassType) or
            isinstance(component, types.TypeType)):
            warnings.warn("passing interface to removeComponent, you probably want unsetComponent", DeprecationWarning, 1)
            self.unsetComponent(component)
            return [component]
        l = []
        for k, v in self._adapterCache.items():
            if v is component:
                del self._adapterCache[k]
                l.append(reflect.namedObject(k))
        return l
Ejemplo n.º 38
0
Archivo: worker.py Proyecto: 0004c/VTK
    def _buildFailure(self, error, errorClass, frames):
        """
        Helper to build a C{Failure} with some traceback.

        @param error: An C{Exception} instance.

        @param error: The class name of the C{error} class.

        @param frames: A flat list of strings representing the information need
            to approximatively rebuild C{Failure} frames.

        @return: A L{Failure} instance with enough information about a test
           error.
        """
        errorType = namedObject(errorClass)
        failure = Failure(error, errorType)
        for i in range(0, len(frames), 3):
            failure.frames.append(
                (frames[i], frames[i + 1], int(frames[i + 2]), [], []))
        return failure
Ejemplo n.º 39
0
    def _buildFailure(self, error, errorClass, frames):
        """
        Helper to build a C{Failure} with some traceback.

        @param error: An C{Exception} instance.

        @param error: The class name of the C{error} class.

        @param frames: A flat list of strings representing the information need
            to approximatively rebuild C{Failure} frames.

        @return: A L{Failure} instance with enough information about a test
           error.
        """
        errorType = namedObject(errorClass)
        failure = Failure(error, errorType)
        for i in range(0, len(frames), 3):
            failure.frames.append(
                (frames[i], frames[i + 1], int(frames[i + 2]), [], []))
        return failure
Ejemplo n.º 40
0
    def setup(self):
        assert not self.impl

        # imports are done locally so that we don't try to import
        # implementation-specific modules unless they're required.
        typ = self.master.config.mq['type']
        assert typ in self.classes  # this is checked by MasterConfig
        self.impl_type = typ
        cls = namedObject(self.classes[typ]['class'])
        self.impl = cls()

        # set up the impl as a child service
        self.impl.setServiceParent(self)

        # configure it (early)
        self.impl.reconfigServiceWithBuildbotConfig(self.master.config)

        # copy the methods onto this object for ease of access
        self.produce = self.impl.produce
        self.startConsuming = self.impl.startConsuming
Ejemplo n.º 41
0
 def handleInput(self, identifier, *args):
     if identifier == 'close':
         if DEBUG: print "CLIENT ACKED CLOSE"
         self.onClosed.callback(None)
         self.closed = True
         self.onClosed = defer.Deferred()
     if DEBUG: print "Dispatching event to observer", identifier, args
     try:
         named = reflect.namedObject(identifier)
         named = getattr(named, 'callit', named)
         try:
             named(self, *args)
         except:
             log.err()
     except (AttributeError, ValueError):
         if DEBUG: print "Observers", self.events._subscribers
         try:
             self.events.publish(identifier, *(self, ) + args)
         except:
             log.err()
Ejemplo n.º 42
0
    def setup(self):
        assert not self.impl

        # imports are done locally so that we don't try to import
        # implementation-specific modules unless they're required.
        typ = self.master.config.mq['type']
        assert typ in self.classes  # this is checked by MasterConfig
        self.impl_type = typ
        cls = namedObject(self.classes[typ]['class'])
        self.impl = cls()

        # set up the impl as a child service
        self.impl.setServiceParent(self)

        # configure it (early)
        self.impl.reconfigServiceWithBuildbotConfig(self.master.config)

        # copy the methods onto this object for ease of access
        self.produce = self.impl.produce
        self.startConsuming = self.impl.startConsuming
Ejemplo n.º 43
0
def autocrud(nodes, name, modelFQN):

    model = reflect.namedObject(modelFQN)

    schema = [
        a for a in dir(model) if isinstance(getattr(model, a), PropertyColumn)
    ]

    if 'id' not in schema:
        print "Sorry, this code isn't clever enough to auto-crud models with no id"
        return

    listCols = ["id"]
    if 'name' in schema:
        listCols.append("name")

    crudCols = schema[:]
    crudCols.remove('id')

    if 'name' in crudCols:
        crudCols.remove('name')
        crudCols.insert(0, 'name')

    listColumns = ", ".join('"%s"' % c for c in listCols)
    crudColumns = textwrap.fill(", ".join('"%s"' % c for c in crudCols))

    nodeContent = crudTemplate % {
        'listColumns': listColumns,
        'crudColumns': crudColumns,
        'model': modelFQN.rsplit('.', 1)[1],
        'node': name
    }

    skeleton.createNode(nodes,
                        name,
                        createIndex=False,
                        nodeContent=nodeContent)
Ejemplo n.º 44
0
 def handleInput(self, identifier, *args):
     if identifier == 'close':
         if DEBUG: print "CLIENT ACKED CLOSE"
         ## This happens in a callLater(0) from the original request
         self.onClosed.callback(None)
         self.closed = True
         self.onClosed = defer.Deferred()
     if DEBUG: print "Dispatching event to observer", identifier, args
     try:
         ## If the identifier provided is the fully-qualified name of a callable,
         ## The function was registered with no closure and we can get to it
         ## easily.
         named = reflect.namedObject(identifier)
         named = getattr(named, 'callit', named)
         try:
             named(self, *args)
         except:
             log.err()
     except (AttributeError, ValueError):
         if DEBUG: print "Observers", self.events._subscribers
         try:
             self.events.publish(identifier, *(self, ) + args)
         except:
             log.err()
Ejemplo n.º 45
0
    def unjellyAO(self, ao):
        """Unjelly an Abstract Object and everything it contains.
        I return the real object.
        """
        self.stack.append(ao)
        t = type(ao)
        if t is types.InstanceType:
            #Abstract Objects
            c = ao.__class__
            if c is Module:
                return reflect.namedModule(ao.name)

            elif c in [Class, Function] or issubclass(c, type):
                return reflect.namedObject(ao.name)

            elif c is InstanceMethod:
                im_name = ao.name
                im_class = reflect.namedObject(ao.klass)
                im_self = self.unjellyAO(ao.instance)
                if im_name in im_class.__dict__:
                    if im_self is None:
                        return getattr(im_class, im_name)
                    elif isinstance(im_self, crefutil.NotKnown):
                        return crefutil._InstanceMethod(
                            im_name, im_self, im_class)
                    else:
                        return new.instancemethod(im_class.__dict__[im_name],
                                                  im_self, im_class)
                else:
                    raise TypeError("instance method changed")

            elif c is Instance:
                klass = reflect.namedObject(ao.klass)
                state = self.unjellyAO(ao.state)
                if hasattr(klass, "__setstate__"):
                    inst = new.instance(klass, {})
                    self.callAfter(inst.__setstate__, state)
                else:
                    inst = new.instance(klass, state)
                return inst

            elif c is Ref:
                o = self.unjellyAO(ao.obj)  #THIS IS CHANGING THE REF OMG
                refkey = ao.refnum
                ref = self.references.get(refkey)
                if ref is None:
                    self.references[refkey] = o
                elif isinstance(ref, crefutil.NotKnown):
                    ref.resolveDependants(o)
                    self.references[refkey] = o
                elif refkey is None:
                    # This happens when you're unjellying from an AOT not read from source
                    pass
                else:
                    raise ValueError(
                        "Multiple references with the same ID: %s, %s, %s!" %
                        (ref, refkey, ao))
                return o

            elif c is Deref:
                num = ao.refnum
                ref = self.references.get(num)
                if ref is None:
                    der = crefutil._Dereference(num)
                    self.references[num] = der
                    return der
                return ref

            elif c is Copyreg:
                loadfunc = reflect.namedObject(ao.loadfunc)
                d = self.unjellyLater(ao.state).addCallback(
                    lambda result, _l: apply(_l, result), loadfunc)
                return d

        #Types

        elif t in _SIMPLE_BUILTINS:
            return ao

        elif t is types.ListType:
            l = []
            for x in ao:
                l.append(None)
                self.unjellyInto(l, len(l) - 1, x)
            return l

        elif t is types.TupleType:
            l = []
            tuple_ = tuple
            for x in ao:
                l.append(None)
                if isinstance(self.unjellyInto(l,
                                               len(l) - 1, x),
                              crefutil.NotKnown):
                    tuple_ = crefutil._Tuple
            return tuple_(l)

        elif t is types.DictType:
            d = {}
            for k, v in ao.items():
                kvd = crefutil._DictKeyAndValue(d)
                self.unjellyInto(kvd, 0, k)
                self.unjellyInto(kvd, 1, v)
            return d

        else:
            raise TypeError("Unsupported AOT type: %s" % t)

        del self.stack[-1]
Ejemplo n.º 46
0
def getFactory(command):
    factory_name = commandRegistry[command]
    factory = reflect.namedObject(factory_name)
    return factory
Ejemplo n.º 47
0
def command(options, function):
    "Run a site-specific command"
    obj = reflect.namedObject(function)
    obj()
Ejemplo n.º 48
0
    ]

    def opt_version(self):
        import buildbot
        print "Buildbot version: %s" % buildbot.version
        usage.Options.opt_version(self)

    def opt_verbose(self):
        from twisted.python import log
        log.startLogging(sys.stderr)

    def postOptions(self):
        if not hasattr(self, 'subOptions'):
            raise usage.UsageError("must specify a command")


def run():
    config = Options()
    try:
        config.parseOptions(sys.argv[1:])
    except usage.error, e:
        print "%s:  %s" % (sys.argv[0], e)
        print
        c = getattr(config, 'subOptions', config)
        print str(c)
        sys.exit(1)

    subconfig = config.subOptions
    subcommandFunction = reflect.namedObject(subconfig.subcommandFunction)
    sys.exit(subcommandFunction(subconfig))
Ejemplo n.º 49
0
    def unjellyNode(self, node):
        if node.tagName.lower() == "none":
            retval = None
        elif node.tagName == "string":
            # XXX FIXME this is obviously insecure
            # if you doubt:
            # >>> unjellyFromXML('''<string value="h&quot;+str(__import__(&quot;sys&quot;))+&quot;i" />''')
            # "h<module 'sys' (built-in)>i"

            # XXX Freevo changes:
            # wrap this around 'Unicode()'
            retval = Unicode(str(eval('"%s"' % node.getAttribute("value"))))
        elif node.tagName == "int":
            retval = int(node.getAttribute("value"))
        elif node.tagName == "float":
            retval = float(node.getAttribute("value"))
        elif node.tagName == "longint":
            retval = long(node.getAttribute("value"))
        elif node.tagName == "bool":
            retval = int(node.getAttribute("value"))
            if retval:
                retval = True
            else:
                retval = False
        elif node.tagName == "module":
            retval = namedModule(str(node.getAttribute("name")))
        elif node.tagName == "class":
            retval = namedClass(str(node.getAttribute("name")))
        elif node.tagName == "unicode":
            retval = unicode(str(node.getAttribute("value")).replace("\\n", "\n").replace("\\t", "\t"), "raw_unicode_escape")
        elif node.tagName == "function":
            retval = namedObject(str(node.getAttribute("name")))
        elif node.tagName == "method":
            im_name = node.getAttribute("name")
            im_class = namedClass(node.getAttribute("class"))
            im_self = self.unjellyNode(getValueElement(node))
            if im_class.__dict__.has_key(im_name):
                if im_self is None:
                    retval = getattr(im_class, im_name)
                elif isinstance(im_self, NotKnown):
                    retval = _InstanceMethod(im_name, im_self, im_class)
                else:
                    retval = instancemethod(im_class.__dict__[im_name],
                                            im_self,
                                            im_class)
            else:
                raise Exception("instance method changed")
        elif node.tagName == "tuple":
            l = []
            tupFunc = tuple
            for subnode in node.childNodes:
                if isinstance(subnode, Element):
                    l.append(None)
                    if isinstance(self.unjellyInto(l, len(l)-1, subnode), NotKnown):
                        tupFunc = _Tuple
            retval = tupFunc(l)
        elif node.tagName == "list":
            l = []
            finished = 1
            for subnode in node.childNodes:
                if isinstance(subnode, Element):
                    l.append(None)
                    self.unjellyInto(l, len(l)-1, subnode)
            retval = l
        elif node.tagName == "dictionary":
            d = {}
            keyMode = 1
            for subnode in node.childNodes:
                if isinstance(subnode, Element):
                    if keyMode:
                        kvd = _DictKeyAndValue(d)
                        if not subnode.getAttribute("role") == "key":
                            raise Exception("Unjellying Error: key role not set")
                        self.unjellyInto(kvd, 0, subnode)
                    else:
                        self.unjellyInto(kvd, 1, subnode)
                    keyMode = not keyMode
            retval = d
        elif node.tagName == "instance":
            className = node.getAttribute("class")
            clasz = namedClass(className)
            if issubclass(clasz, DOMJellyable):
                retval = instance(clasz, {})
                retval.unjellyFromDOM(self, node)
            else:
                state = self.unjellyNode(getValueElement(node))
                if hasattr(clasz, "__setstate__"):
                    inst = instance(clasz, {})
                    inst.__setstate__(state)
                else:
                    inst = instance(clasz, state)
                retval = inst
        elif node.tagName == "reference":
            refkey = node.getAttribute("key")
            retval = self.references.get(refkey)
            if retval is None:
                der = _Dereference(refkey)
                self.references[refkey] = der
                retval = der
        elif node.tagName == "copyreg":
            nodefunc = namedObject(node.getAttribute("loadfunc"))
            loaddef = self.unjellyLater(getValueElement(node)).addCallback(
                lambda result, _l: apply(_l, result), nodefunc)
            retval = loaddef
        else:
            raise Exception("Unsupported Node Type: %s" % str(node.tagName))
        if node.hasAttribute("reference"):
            refkey = node.getAttribute("reference")
            ref = self.references.get(refkey)
            if ref is None:
                self.references[refkey] = retval
            elif isinstance(ref, NotKnown):
                ref.resolveDependants(retval)
                self.references[refkey] = retval
            else:
                assert 0, "Multiple references with the same ID!"
        return retval
Ejemplo n.º 50
0
    def makeService(self, options):

        siteDir = FilePath(options['siteDir'])

        sys.path.insert(0, siteDir.path)

        if options.subCommand == "skeleton":
            print "Creating skeleton..."
            from warp.tools import skeleton
            skeleton.createSkeleton(siteDir)
            raise SystemExit

        configModule = reflect.namedModule(options['config'])
        config = configModule.config
        runtime.config.update(config)
        runtime.config['siteDir'] = siteDir
        runtime.config['warpDir'] = FilePath(runtime.__file__).parent()
        store.setupStore()
        translate.loadMessages()

        if options.subCommand == "node":
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import skeleton
            skeleton.createNode(nodes, options.subOptions['name'])
            raise SystemExit

        elif options.subCommand == 'crud':
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import autocrud
            autocrud.autocrud(nodes, options.subOptions['name'],
                              options.subOptions['model'])
            raise SystemExit

        elif options.subCommand == 'adduser':
            from warp.tools import adduser
            adduser.addUser()
            raise SystemExit

        factory = site.WarpSite(resource.WarpResourceWrapper())
        runtime.config['warpSite'] = factory

        if hasattr(configModule, 'startup'):
            configModule.startup()

        if options.subCommand == "console":
            import code
            locals = {'store': runtime.store}
            c = code.InteractiveConsole(locals)
            c.interact()
            raise SystemExit

        if options.subCommand == 'command':
            obj = reflect.namedObject(options.subOptions['fqn'])
            obj()
            raise SystemExit

        if config.get('ssl'):
            from warp.webserver import sslcontext
            service = internet.SSLServer(config['port'], factory,
                                         sslcontext.ServerContextFactory())
        else:
            service = internet.TCPServer(config["port"], factory)

        if hasattr(configModule, 'mungeService'):
            service = configModule.mungeService(service)

        return service
Ejemplo n.º 51
0
def getFactory(command):
    factory_name = commandRegistry[command]
    factory = reflect.namedObject(factory_name)
    return factory
Ejemplo n.º 52
0
    ]

    def opt_version(self):
        import buildbot
        print "Buildbot version: %s" % buildbot.__version__
        usage.Options.opt_version(self)

    def opt_verbose(self):
        from twisted.python import log
        log.startLogging(sys.stderr)

    def postOptions(self):
        if not hasattr(self, 'subOptions'):
            raise usage.UsageError("must specify a command")


def run():
    config = Options()
    try:
        config.parseOptions(sys.argv[1:])
    except usage.error, e:
        print "%s:  %s" % (sys.argv[0], e)
        print
        c = getattr(config, 'subOptions', config)
        print str(c)
        sys.exit(1)

    subconfig = config.subOptions
    subcommandFunction = reflect.namedObject(subconfig.subcommandFunction)
    sys.exit(subcommandFunction(subconfig))
Ejemplo n.º 53
0
def pick_django_signal():
    return namedObject("django.db.models.signals." +
                       random.choice(django_signal_names))
Ejemplo n.º 54
0
    def unjellyNode(self, node):
        if node.tagName.lower() == "none":
            retval = None
        elif node.tagName == "string":
            # XXX FIXME this is obviously insecure
            # if you doubt:
            # >>> unjellyFromXML('''<string value="h&quot;+str(__import__(&quot;sys&quot;))+&quot;i" />''')
            # "h<module 'sys' (built-in)>i"

            # XXX Freevo changes:
            # wrap this around 'Unicode()'
            retval = Unicode(str(eval('"%s"' % node.getAttribute("value"))))
        elif node.tagName == "int":
            retval = int(node.getAttribute("value"))
        elif node.tagName == "float":
            retval = float(node.getAttribute("value"))
        elif node.tagName == "longint":
            retval = long(node.getAttribute("value"))
        elif node.tagName == "bool":
            retval = int(node.getAttribute("value"))
            if retval:
                retval = True
            else:
                retval = False
        elif node.tagName == "module":
            retval = namedModule(str(node.getAttribute("name")))
        elif node.tagName == "class":
            retval = namedClass(str(node.getAttribute("name")))
        elif node.tagName == "unicode":
            retval = unicode(
                str(node.getAttribute("value")).replace("\\n", "\n").replace(
                    "\\t", "\t"), "raw_unicode_escape")
        elif node.tagName == "function":
            retval = namedObject(str(node.getAttribute("name")))
        elif node.tagName == "method":
            im_name = node.getAttribute("name")
            im_class = namedClass(node.getAttribute("class"))
            im_self = self.unjellyNode(getValueElement(node))
            if im_class.__dict__.has_key(im_name):
                if im_self is None:
                    retval = getattr(im_class, im_name)
                elif isinstance(im_self, NotKnown):
                    retval = _InstanceMethod(im_name, im_self, im_class)
                else:
                    retval = instancemethod(im_class.__dict__[im_name],
                                            im_self, im_class)
            else:
                raise "instance method changed"
        elif node.tagName == "tuple":
            l = []
            tupFunc = tuple
            for subnode in node.childNodes:
                if isinstance(subnode, Element):
                    l.append(None)
                    if isinstance(self.unjellyInto(l,
                                                   len(l) - 1, subnode),
                                  NotKnown):
                        tupFunc = _Tuple
            retval = tupFunc(l)
        elif node.tagName == "list":
            l = []
            finished = 1
            for subnode in node.childNodes:
                if isinstance(subnode, Element):
                    l.append(None)
                    self.unjellyInto(l, len(l) - 1, subnode)
            retval = l
        elif node.tagName == "dictionary":
            d = {}
            keyMode = 1
            for subnode in node.childNodes:
                if isinstance(subnode, Element):
                    if keyMode:
                        kvd = _DictKeyAndValue(d)
                        if not subnode.getAttribute("role") == "key":
                            raise "Unjellying Error: key role not set"
                        self.unjellyInto(kvd, 0, subnode)
                    else:
                        self.unjellyInto(kvd, 1, subnode)
                    keyMode = not keyMode
            retval = d
        elif node.tagName == "instance":
            className = node.getAttribute("class")
            clasz = namedClass(className)
            if issubclass(clasz, DOMJellyable):
                retval = instance(clasz, {})
                retval.unjellyFromDOM(self, node)
            else:
                state = self.unjellyNode(getValueElement(node))
                if hasattr(clasz, "__setstate__"):
                    inst = instance(clasz, {})
                    inst.__setstate__(state)
                else:
                    inst = instance(clasz, state)
                retval = inst
        elif node.tagName == "reference":
            refkey = node.getAttribute("key")
            retval = self.references.get(refkey)
            if retval is None:
                der = _Dereference(refkey)
                self.references[refkey] = der
                retval = der
        elif node.tagName == "copyreg":
            nodefunc = namedObject(node.getAttribute("loadfunc"))
            loaddef = self.unjellyLater(getValueElement(node)).addCallback(
                lambda result, _l: apply(_l, result), nodefunc)
            retval = loaddef
        else:
            raise "Unsupported Node Type: %s" % str(node.tagName)
        if node.hasAttribute("reference"):
            refkey = node.getAttribute("reference")
            ref = self.references.get(refkey)
            if ref is None:
                self.references[refkey] = retval
            elif isinstance(ref, NotKnown):
                ref.resolveDependants(retval)
                self.references[refkey] = retval
            else:
                assert 0, "Multiple references with the same ID!"
        return retval
Ejemplo n.º 55
0
def load_plugin(name, highscore, config):
    cls = namedObject('highscore.plugins.%s.Plugin' % (name,))
    plugin = cls(highscore, config)
    plugin.setServiceParent(highscore)
    return plugin