Ejemplo n.º 1
0
def registerAdapter(adapterFactory, origInterface, *interfaceClasses):
    from nevow.util import _namedAnyWithBuiltinTranslation, _NamedAnyError

    isStr = type(adapterFactory) is str
    if (type(origInterface) is str) != isStr:
        raise ValueError(
            "Either all arguments must be strings or all must be objects.")

    for interfaceClass in interfaceClasses:
        if (type(interfaceClass) is str) != isStr:
            raise ValueError(
                "Either all arguments must be strings or all must be objects.")

    if isStr:
        # print "registerAdapter:",adapterFactory, origInterface, interfaceClasses
        adapterFactory = _namedAnyWithBuiltinTranslation(adapterFactory)
        origInterface = _namedAnyWithBuiltinTranslation(origInterface)
        interfaceClasses = [
            _namedAnyWithBuiltinTranslation(x) for x in interfaceClasses
        ]

    if 'nevow.inevow.ISerializable' in interfaceClasses or [
            o for o in interfaceClasses
            if getattr(o, '__name__', None) == 'ISerializable'
    ]:
        warnings.warn(
            "ISerializable is deprecated. Please use nevow.flat.registerFlattener instead.",
            stacklevel=2)
        from nevow import flat
        flat.registerFlattener(adapterFactory, origInterface)
    _registerAdapter(adapterFactory, origInterface, *interfaceClasses)
Ejemplo n.º 2
0
def load(S):
    for line in S.split('\n'):
        line = line.strip()
        if line and not line.startswith('#'):
            (a, o, i) = line.split()
            registerAdapter(_namedAnyWithBuiltinTranslation(a),
                            _namedAnyWithBuiltinTranslation(clean(o)),
                            _namedAnyWithBuiltinTranslation(i))
Ejemplo n.º 3
0
def load(S):
    for line in S.split('\n'):
        line = line.strip()
        if line and not line.startswith('#'):
            (a, o, i) = line.split()
            registerAdapter(_namedAnyWithBuiltinTranslation(a),
                            _namedAnyWithBuiltinTranslation(clean(o)),
                            _namedAnyWithBuiltinTranslation(i))
Ejemplo n.º 4
0
def registerFlattener(flattener, forType):
    """Register a function, 'flattener', which will be invoked when an object of type 'forType'
    is encountered in the stan dom. This function should return or yield strings, or objects
    for which there is also a flattener registered.
    
    flattener should take (original, ctx) where original is the object to flatten.
    """
    if type(flattener) is str or type(forType) is str:
        assert type(flattener) is str and type(forType) is str, "Must pass both strings or no strings to registerFlattener"
        flattener = util._namedAnyWithBuiltinTranslation(flattener)
        forType = util._namedAnyWithBuiltinTranslation(forType)

    if not isinstance(forType, interface.InterfaceClass):
        forType = declarations.implementedBy(forType)
        
    tpc.globalRegistry.register([forType], ISerializable, 'nevow.flat', flattener)
Ejemplo n.º 5
0
def registerFlattener(flattener, forType):
    """Register a function, 'flattener', which will be invoked when an object of type 'forType'
    is encountered in the stan dom. This function should return or yield strings, or objects
    for which there is also a flattener registered.
    
    flattener should take (original, ctx) where original is the object to flatten.
    """
    if type(flattener) is str or type(forType) is str:
        assert type(flattener) is str and type(
            forType
        ) is str, "Must pass both strings or no strings to registerFlattener"
        flattener = util._namedAnyWithBuiltinTranslation(flattener)
        forType = util._namedAnyWithBuiltinTranslation(forType)

    if not isinstance(forType, interface.InterfaceClass):
        forType = declarations.implementedBy(forType)

    tpc.globalRegistry.register([forType], ISerializable, 'nevow.flat',
                                flattener)