##// END OF EJS Templates
vcs: Move VCSMiddleware up to pyramid layer as wrapper around pylons app....
vcs: Move VCSMiddleware up to pyramid layer as wrapper around pylons app. The VCSMiddleware is now moved to the pyramid layer and acts as a fallback if pyramid does not find a view to handle the request.

File last commit:

r1:854a839a default
r581:5c1ed3a7 default
Show More
keyedinstance.py
36 lines | 1.1 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 #!/usr/bin/env python
# -*- coding: utf-8 -*-
class KeyedInstance(object):
"""A class whose instances have a unique identifier of some sort
No two instances with the same unique ID should exist - if we try to create
a second instance, the first should be returned.
"""
_instances = {}
def __new__(cls, *p, **k):
instances = cls._instances
clskey = str(cls)
if clskey not in instances:
instances[clskey] = {}
instances = instances[clskey]
key = cls._key(*p, **k)
if key not in instances:
instances[key] = super(KeyedInstance, cls).__new__(cls)
return instances[key]
@classmethod
def _key(cls, *p, **k):
"""Given a unique identifier, return a dictionary key
This should be overridden by child classes, to specify which parameters
should determine an object's uniqueness
"""
raise NotImplementedError()
@classmethod
def clear(cls):
# Allow cls.clear() as well as uniqueInstance.clear(cls)
if str(cls) in cls._instances:
del cls._instances[str(cls)]