mercurial/utils/interfaceutil.py
changeset 42814 2c4f656c8e9f
parent 42813 268662aac075
child 42815 197e7326b8b8
equal deleted inserted replaced
42813:268662aac075 42814:2c4f656c8e9f
     1 # interfaceutil.py - Utilities for declaring interfaces.
       
     2 #
       
     3 # Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com>
       
     4 #
       
     5 # This software may be used and distributed according to the terms of the
       
     6 # GNU General Public License version 2 or any later version.
       
     7 
       
     8 # zope.interface imposes a run-time cost due to module import overhead and
       
     9 # bookkeeping for declaring interfaces. So, we use stubs for various
       
    10 # zope.interface primitives unless instructed otherwise.
       
    11 
       
    12 from __future__ import absolute_import
       
    13 
       
    14 from .. import (
       
    15     encoding,
       
    16 )
       
    17 
       
    18 if encoding.environ.get('HGREALINTERFACES'):
       
    19     from ..thirdparty.zope import (
       
    20         interface as zi,
       
    21     )
       
    22 
       
    23     Attribute = zi.Attribute
       
    24     Interface = zi.Interface
       
    25     implementer = zi.implementer
       
    26 else:
       
    27     class Attribute(object):
       
    28         def __init__(self, __name__, __doc__=''):
       
    29             pass
       
    30 
       
    31     class Interface(object):
       
    32         def __init__(self, name, bases=(), attrs=None, __doc__=None,
       
    33                  __module__=None):
       
    34             pass
       
    35 
       
    36     def implementer(*ifaces):
       
    37         def wrapper(cls):
       
    38             return cls
       
    39 
       
    40         return wrapper