How to use simplegeneric - 8 common examples

To help you get started, we’ve selected a few simplegeneric examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github owenmorris / chandler / chandler / parcels / osaf / sharing / eim.py View on Github external
@generic
def typeinfo_for(context):
    """Return the relevant ``sharing.TypeInfo`` for `context`

    `context` may be a URI string, a ``sharing.TypeInfo``, ``sharing.Field``,
    or ``schema.Descriptor`` (e.g. ``schema.One``, etc.).  object.  It can also
    be any object registered as a type alias using ``sharing.typedef()``.

    The return value is a ``sharing.TypeInfo``.  If no type information is
    available for `context`, raise ``sharing.UnknownType``
    """
    raise UnknownType(context)
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / aspect.py View on Github external
class ItemPaintHovered(object):
    """
    Paints on top of all items, just for the hovered item (see painter.HoveredItemPainter)
    """

    def __init__(self, item, view):
        self.item = item
        self.view = view

    def paint(self, context, selected):
        pass


PaintHovered = generic(ItemPaintHovered)
github owenmorris / chandler / chandler / parcels / osaf / sharing / eim.py View on Github external
def add_converter(context, from_type, converter):
    """Register `converter` for converting `from_type` in `context`"""
    # XXX if converters cached by record types, add hooks here for updating
    gf = get_converter(context)
    if not get_converter.has_object(context):
        gf = generic(gf)    # extend base function
        get_converter.when_object(context)(lambda context: gf)
    gf.when_type(from_type)(converter)
github owenmorris / chandler / chandler / parcels / osaf / sharing / eim.py View on Github external
@generic
def get_converter(context):
    """Return a conversion function for encoding in the `context` type context
    """
    ctx = typeinfo_for(context)

    if isinstance(context,type) and issubclass(context, TypeInfo):
        # prevent infinite recursion for unregistered primitive types
        # if this error occurs, somebody added a new primitive type without
        # creating a base conversion function for it
        raise AssertionError("Unregistered metatype", ctx)

    return get_converter(ctx)
github owenmorris / chandler / chandler / parcels / osaf / sharing / eim.py View on Github external
@generic
def format_field(context, value):
    """Format a value based on a field or typeinfo"""
    return value
github owenmorris / chandler / chandler / parcels / osaf / sharing / eim.py View on Github external
def subtype(typeinfo, *args, **kw):
    """XXX"""
    newti = typeinfo_for(typeinfo).clone(*args, **kw)
    gf = generic(get_converter(typeinfo))
    get_converter.when_object(newti)(lambda ctx:gf)
    return newti
github owenmorris / chandler / chandler / parcels / osaf / sharing / eim.py View on Github external
@generic
def default_converter(value):
    raise TypeError(
        "No converter registered for values of type %r" % type(value)
    )
github owenmorris / chandler / chandler / parcels / osaf / sharing / eim.py View on Github external
def create_default_converter(t):
    converter = generic(default_converter)
    converter.when_object(NoChange)(lambda val: val)
    converter.when_object(Inherit)(lambda val: val)
    converter.when_object(None)(lambda val: val)
    get_converter.when_object(t)(lambda ctx: converter)

simplegeneric

Simple generic functions (similar to Python's own len(), pickle.dump(), etc.)

ZPL-2.1
Latest version published 13 years ago

Package Health Score

49 / 100
Full package analysis

Popular simplegeneric functions