Current File : /home/mmdealscpanel/yummmdeals.com/newmetaclasses.zip
PK{��Za�Q���
Eiffel.pyonu�[����
��^c@s�dZddlmZdefd��YZdefd��YZddd��YZd	efd
��YZ	defd��YZ
d
�Zedkr�ee�ee
�ndS(s6Support Eiffel-style preconditions and postconditions.i����(tFunctionTypetEiffelBaseMetaClasscBs eZd�Zed��ZRS(cCs,|j|�tt|�j||||�S(N(tconvert_methodstsuperRt__new__(tmetatnametbasestdict((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyRs
cCs�g}xZ|j�D]L\}}|jd�s_|jd�r@qt|t�r|j|�qqWx`|D]X}|jd|�}|jd|�}|s�|rj|j||||�||<qjqjWdS(s�Replace functions in dict with EiffelMethod wrappers.

        The dict is modified in place.

        If a method ends in _pre or _post, it is removed from the dict
        regardless of whether there is a corresponding method.
        t_pret_posts%s_pres%s_postN(t	iteritemstendswitht
isinstancetfunctiontappendtgettmake_eiffel_method(tclsRtmethodstktvtmtpretpost((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyRs

(t__name__t
__module__RtclassmethodR(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyRs	tEiffelMetaClass1cBseZed��ZRS(cs1���fd�}�jr-�j|_n|S(NcsK�r�|||�n�|||�}�rG�||||�n|S(N((tselftargstkwargstx(tfuncRR(s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pytmethod's(t__doc__(R!RRR"((R!RRs2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR%s	(RRtstaticmethodR(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR"stEiffelMethodWrappercBseZd�Zd�ZRS(cCs||_||_dS(N(t_instt_descr(Rtinsttdescr((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyt__init__6s	cOs|jj|j||�S(N(R't
callmethodR&(RRR((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyt__call__:s(RRR*R,(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR%4s	tEiffelDescriptorcBs#eZd�Zd�Zd�ZRS(cCs7||_||_||_|j|_|j|_dS(N(t_funcR	R
RR#(RR!RR((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR*?s
			cCs
t||�S(N(R%(RtobjR((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyt__get__GscCsZ|jr|j|||�n|j|||�}|jrV|j||||�n|S(N(R	R.R
(RR(RRR ((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR+Js		(RRR*R0R+(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR-=s		tEiffelMetaClass2cBseZeZRS((RRR-R(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR1Rscs�dd�fd��Y}d|fd��Y}d|f�fd��Y�|�}|jd�|jd�y|jd�Wntk
r�nX��}y|jd�Wntk
r�nXy|jd	�Wntk
r�nX|jd
�dS(NtEiffelcseZ�ZRS((RRt
__metaclass__((t	metaclass(s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR2XstTestcBs,eZd�Zd�Zd�Zd�ZRS(cSs|dS(sMake it a little largeri((Rtarg((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR]scSs|dS(sMake it a little largeri((RR6((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pytm2ascSsdS(N((RR6((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pytm2_preescSsdS(N((RtresultR6((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pytm2_posths(RRRR7R8R:(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR5[s			tSubcs eZd�Z�fd�ZRS(cSs|dS(Ni((RR6((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR7lscst�|�j||�dS(N(RR:(RtResultR6(R;(s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR:ns(RRR7R:((R;(s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR;ks	iii
i((RR7tAssertionError(R4R2R5ttts((R;R4s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyt_testWs(	


	

t__main__N((
R#ttypesRRttypeRRR%tobjectR-R1R@R(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyt<module>s		4
PK{��Z�|�rr
Eiffel.pycnu�[����
��^c@s�dZddlmZdefd��YZdefd��YZddd��YZd	efd
��YZ	defd��YZ
d
�Zedkr�ee�ee
�ndS(s6Support Eiffel-style preconditions and postconditions.i����(tFunctionTypetEiffelBaseMetaClasscBs eZd�Zed��ZRS(cCs,|j|�tt|�j||||�S(N(tconvert_methodstsuperRt__new__(tmetatnametbasestdict((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyRs
cCs�g}xo|j�D]a\}}|jd�s=|jd�rUt|t�stt�qt|t�r|j|�qqWx`|D]X}|jd|�}|jd|�}|s�|r|j||||�||<qqWdS(s�Replace functions in dict with EiffelMethod wrappers.

        The dict is modified in place.

        If a method ends in _pre or _post, it is removed from the dict
        regardless of whether there is a corresponding method.
        t_pret_posts%s_pres%s_postN(t	iteritemstendswitht
isinstancetfunctiontAssertionErrortappendtgettmake_eiffel_method(tclsRtmethodstktvtmtpretpost((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyRs

(t__name__t
__module__RtclassmethodR(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyRs	tEiffelMetaClass1cBseZed��ZRS(cs1���fd�}�jr-�j|_n|S(NcsK�r�|||�n�|||�}�rG�||||�n|S(N((tselftargstkwargstx(tfuncRR(s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pytmethod's(t__doc__(R"RRR#((R"RRs2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR%s	(RRtstaticmethodR(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR"stEiffelMethodWrappercBseZd�Zd�ZRS(cCs||_||_dS(N(t_instt_descr(Rtinsttdescr((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyt__init__6s	cOs|jj|j||�S(N(R(t
callmethodR'(RRR ((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyt__call__:s(RRR+R-(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR&4s	tEiffelDescriptorcBs#eZd�Zd�Zd�ZRS(cCs7||_||_||_|j|_|j|_dS(N(t_funcR	R
RR$(RR"RR((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR+?s
			cCs
t||�S(N(R&(RtobjR((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyt__get__GscCsZ|jr|j|||�n|j|||�}|jrV|j||||�n|S(N(R	R/R
(RR)RR R!((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR,Js		(RRR+R1R,(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR.=s		tEiffelMetaClass2cBseZeZRS((RRR.R(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR2Rscsdd�fd��Y}d|fd��Y}d|f�fd��Y�|�}|jd�|jd�y|jd�Wntk
r�n
Xts�t���}y|jd�Wntk
r�n
Xts�t�y|jd	�Wntk
r�n
Xts
t�|jd
�dS(NtEiffelcseZ�ZRS((RRt
__metaclass__((t	metaclass(s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR3XstTestcBs,eZd�Zd�Zd�Zd�ZRS(cSs|dS(sMake it a little largeri((Rtarg((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR]scSs|dS(sMake it a little largeri((RR7((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pytm2ascSs|dkst�dS(Ni(R(RR7((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pytm2_preescSs||kst�dS(N(R(RtresultR7((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pytm2_posths(RRRR8R9R;(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR6[s			tSubcs eZd�Z�fd�ZRS(cSs|dS(Ni((RR7((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR8lscs/t�|�j||�|dks+t�dS(Nid(RR;R(RtResultR7(R<(s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR;ns(RRR8R;((R<(s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyR<ks	iii
i((RR8RtFalse(R5R3R6ttts((R<R5s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyt_testWs.	


	

t__main__N((
R$ttypesRRttypeRRR&tobjectR.R2RAR(((s2/usr/lib64/python2.7/Demo/newmetaclasses/Eiffel.pyt<module>s		4
PK{��Ze@�P��	Eiffel.pynu�[���"""Support Eiffel-style preconditions and postconditions."""

from types import FunctionType as function

class EiffelBaseMetaClass(type):

    def __new__(meta, name, bases, dict):
        meta.convert_methods(dict)
        return super(EiffelBaseMetaClass, meta).__new__(meta, name, bases,
                                                        dict)

    @classmethod
    def convert_methods(cls, dict):
        """Replace functions in dict with EiffelMethod wrappers.

        The dict is modified in place.

        If a method ends in _pre or _post, it is removed from the dict
        regardless of whether there is a corresponding method.
        """
        # find methods with pre or post conditions
        methods = []
        for k, v in dict.iteritems():
            if k.endswith('_pre') or k.endswith('_post'):
                assert isinstance(v, function)
            elif isinstance(v, function):
                methods.append(k)
        for m in methods:
            pre = dict.get("%s_pre" % m)
            post = dict.get("%s_post" % m)
            if pre or post:
                dict[m] = cls.make_eiffel_method(dict[m], pre, post)

class EiffelMetaClass1(EiffelBaseMetaClass):
    # an implementation of the "eiffel" meta class that uses nested functions

    @staticmethod
    def make_eiffel_method(func, pre, post):
        def method(self, *args, **kwargs):
            if pre:
                pre(self, *args, **kwargs)
            x = func(self, *args, **kwargs)
            if post:
                post(self, x, *args, **kwargs)
            return x

        if func.__doc__:
            method.__doc__ = func.__doc__

        return method

class EiffelMethodWrapper:

    def __init__(self, inst, descr):
        self._inst = inst
        self._descr = descr

    def __call__(self, *args, **kwargs):
        return self._descr.callmethod(self._inst, args, kwargs)

class EiffelDescriptor(object):

    def __init__(self, func, pre, post):
        self._func = func
        self._pre = pre
        self._post = post

        self.__name__ = func.__name__
        self.__doc__ = func.__doc__

    def __get__(self, obj, cls):
        return EiffelMethodWrapper(obj, self)

    def callmethod(self, inst, args, kwargs):
        if self._pre:
            self._pre(inst, *args, **kwargs)
        x = self._func(inst, *args, **kwargs)
        if self._post:
            self._post(inst, x, *args, **kwargs)
        return x

class EiffelMetaClass2(EiffelBaseMetaClass):
    # an implementation of the "eiffel" meta class that uses descriptors

    make_eiffel_method = EiffelDescriptor

def _test(metaclass):
    class Eiffel:
        __metaclass__ = metaclass

    class Test(Eiffel):

        def m(self, arg):
            """Make it a little larger"""
            return arg + 1

        def m2(self, arg):
            """Make it a little larger"""
            return arg + 1

        def m2_pre(self, arg):
            assert arg > 0

        def m2_post(self, result, arg):
            assert result > arg

    class Sub(Test):
        def m2(self, arg):
            return arg**2
        def m2_post(self, Result, arg):
            super(Sub, self).m2_post(Result, arg)
            assert Result < 100

    t = Test()
    t.m(1)
    t.m2(1)
    try:
        t.m2(0)
    except AssertionError:
        pass
    else:
        assert False

    s = Sub()
    try:
        s.m2(1)
    except AssertionError:
        pass # result == arg
    else:
        assert False
    try:
        s.m2(10)
    except AssertionError:
        pass # result ==  100
    else:
        assert False
    s.m2(5)

if __name__ == "__main__":
    _test(EiffelMetaClass1)
    _test(EiffelMetaClass2)
PK{��Zm�zEnum.pynu�[���"""Enumeration metaclass."""

class EnumMetaclass(type):
    """Metaclass for enumeration.

    To define your own enumeration, do something like

    class Color(Enum):
        red = 1
        green = 2
        blue = 3

    Now, Color.red, Color.green and Color.blue behave totally
    different: they are enumerated values, not integers.

    Enumerations cannot be instantiated; however they can be
    subclassed.
    """

    def __init__(cls, name, bases, dict):
        super(EnumMetaclass, cls).__init__(name, bases, dict)
        cls._members = []
        for attr in dict.keys():
            if not (attr.startswith('__') and attr.endswith('__')):
                enumval = EnumInstance(name, attr, dict[attr])
                setattr(cls, attr, enumval)
                cls._members.append(attr)

    def __getattr__(cls, name):
        if name == "__members__":
            return cls._members
        raise AttributeError, name

    def __repr__(cls):
        s1 = s2 = ""
        enumbases = [base.__name__ for base in cls.__bases__
                     if isinstance(base, EnumMetaclass) and not base is Enum]
        if enumbases:
            s1 = "(%s)" % ", ".join(enumbases)
        enumvalues = ["%s: %d" % (val, getattr(cls, val))
                      for val in cls._members]
        if enumvalues:
            s2 = ": {%s}" % ", ".join(enumvalues)
        return "%s%s%s" % (cls.__name__, s1, s2)

class FullEnumMetaclass(EnumMetaclass):
    """Metaclass for full enumerations.

    A full enumeration displays all the values defined in base classes.
    """

    def __init__(cls, name, bases, dict):
        super(FullEnumMetaclass, cls).__init__(name, bases, dict)
        for obj in cls.__mro__:
            if isinstance(obj, EnumMetaclass):
                for attr in obj._members:
                    # XXX inefficient
                    if not attr in cls._members:
                        cls._members.append(attr)

class EnumInstance(int):
    """Class to represent an enumeration value.

    EnumInstance('Color', 'red', 12) prints as 'Color.red' and behaves
    like the integer 12 when compared, but doesn't support arithmetic.

    XXX Should it record the actual enumeration rather than just its
    name?
    """

    def __new__(cls, classname, enumname, value):
        return int.__new__(cls, value)

    def __init__(self, classname, enumname, value):
        self.__classname = classname
        self.__enumname = enumname

    def __repr__(self):
        return "EnumInstance(%s, %s, %d)" % (self.__classname, self.__enumname,
                                             self)

    def __str__(self):
        return "%s.%s" % (self.__classname, self.__enumname)

class Enum:
    __metaclass__ = EnumMetaclass

class FullEnum:
    __metaclass__ = FullEnumMetaclass

def _test():

    class Color(Enum):
        red = 1
        green = 2
        blue = 3

    print Color.red

    print repr(Color.red)
    print Color.red == Color.red
    print Color.red == Color.blue
    print Color.red == 1
    print Color.red == 2

    class ExtendedColor(Color):
        white = 0
        orange = 4
        yellow = 5
        purple = 6
        black = 7

    print ExtendedColor.orange
    print ExtendedColor.red

    print Color.red == ExtendedColor.red

    class OtherColor(Enum):
        white = 4
        blue = 5

    class MergedColor(Color, OtherColor):
        pass

    print MergedColor.red
    print MergedColor.white

    print Color
    print ExtendedColor
    print OtherColor
    print MergedColor

def _test2():

    class Color(FullEnum):
        red = 1
        green = 2
        blue = 3

    print Color.red

    print repr(Color.red)
    print Color.red == Color.red
    print Color.red == Color.blue
    print Color.red == 1
    print Color.red == 2

    class ExtendedColor(Color):
        white = 0
        orange = 4
        yellow = 5
        purple = 6
        black = 7

    print ExtendedColor.orange
    print ExtendedColor.red

    print Color.red == ExtendedColor.red

    class OtherColor(FullEnum):
        white = 4
        blue = 5

    class MergedColor(Color, OtherColor):
        pass

    print MergedColor.red
    print MergedColor.white

    print Color
    print ExtendedColor
    print OtherColor
    print MergedColor

if __name__ == '__main__':
    _test()
    _test2()
PK{��Z�;o�Enum.pycnu�[����
��^c@s�dZdefd��YZdefd��YZdefd��YZddd��YZd	dd
��YZd�Zd�Z	e
d
kr�e�e	�ndS(sEnumeration metaclass.t
EnumMetaclasscBs)eZdZd�Zd�Zd�ZRS(sgMetaclass for enumeration.

    To define your own enumeration, do something like

    class Color(Enum):
        red = 1
        green = 2
        blue = 3

    Now, Color.red, Color.green and Color.blue behave totally
    different: they are enumerated values, not integers.

    Enumerations cannot be instantiated; however they can be
    subclassed.
    cCs�tt|�j|||�g|_xk|j�D]]}|jd�oS|jd�s2t||||�}t|||�|jj	|�q2q2WdS(Nt__(
tsuperRt__init__t_memberstkeyst
startswithtendswithtEnumInstancetsetattrtappend(tclstnametbasestdicttattrtenumval((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyRs	cCs |dkr|jSt|�dS(Nt__members__(RtAttributeError(RR((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt__getattr__scCs�d}}g|jD]*}t|t�r|tk	r|j^q}|r`ddj|�}ng|jD]}d|t||�f^qj}|r�ddj|�}nd|j||fS(Nts(%s)s, s%s: %ds: {%s}s%s%s%s(t	__bases__t
isinstanceRtEnumt__name__tjoinRtgetattr(Rts1ts2tbaset	enumbasestvalt
enumvalues((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt__repr__"s
*,(Rt
__module__t__doc__RRR!(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyRs			tFullEnumMetaclasscBseZdZd�ZRS(snMetaclass for full enumerations.

    A full enumeration displays all the values defined in base classes.
    cCs|tt|�j|||�xY|jD]N}t|t�r&x6|jD](}||jkrE|jj|�qEqEWq&q&WdS(N(RR$Rt__mro__RRRR
(RRR
RtobjR((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR4s(RR"R#R(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR$.sRcBs2eZdZd�Zd�Zd�Zd�ZRS(sClass to represent an enumeration value.

    EnumInstance('Color', 'red', 12) prints as 'Color.red' and behaves
    like the integer 12 when compared, but doesn't support arithmetic.

    XXX Should it record the actual enumeration rather than just its
    name?
    cCstj||�S(N(tintt__new__(Rt	classnametenumnametvalue((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR(GscCs||_||_dS(N(t_EnumInstance__classnamet_EnumInstance__enumname(tselfR)R*R+((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyRJs	cCsd|j|j|fS(NsEnumInstance(%s, %s, %d)(R,R-(R.((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR!NscCsd|j|jfS(Ns%s.%s(R,R-(R.((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt__str__Rs(RR"R#R(RR!R/(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR=s
			RcBseZeZRS((RR"Rt
__metaclass__(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyRUstFullEnumcBseZeZRS((RR"R$R0(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR1XscCs�dtfd��Y}|jGHt|j�GH|j|jkGH|j|jkGH|jdkGH|jdkGHd|fd��Y}|jGH|jGH|j|jkGHdtfd��Y}d	||fd
��Y}|jGH|jGH|GH|GH|GH|GHdS(NtColorcBseZdZdZdZRS(iii(RR"tredtgreentblue(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR2]siit
ExtendedColorcBs&eZdZdZdZdZdZRS(iiiii(RR"twhitetorangetyellowtpurpletblack(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR6js
t
OtherColorcBseZdZdZRS(ii(RR"R7R5(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR<vstMergedColorcBseZRS((RR"(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR=zs(RR3treprR5R8R7(R2R6R<R=((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt_test[s&cCs�dtfd��Y}|jGHt|j�GH|j|jkGH|j|jkGH|jdkGH|jdkGHd|fd��Y}|jGH|jGH|j|jkGHdtfd��Y}d	||fd
��Y}|jGH|jGH|GH|GH|GH|GHdS(NR2cBseZdZdZdZRS(iii(RR"R3R4R5(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR2�siiR6cBs&eZdZdZdZdZdZRS(iiiii(RR"R7R8R9R:R;(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR6�s
R<cBseZdZdZRS(ii(RR"R7R5(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR<�sR=cBseZRS((RR"(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR=�s(R1R3R>R5R8R7(R2R6R<R=((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt_test2�s&t__main__N(((R#ttypeRR$R'RRR1R?R@R(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt<module>s+	*	*PK{��Z�;o�Enum.pyonu�[����
��^c@s�dZdefd��YZdefd��YZdefd��YZddd��YZd	dd
��YZd�Zd�Z	e
d
kr�e�e	�ndS(sEnumeration metaclass.t
EnumMetaclasscBs)eZdZd�Zd�Zd�ZRS(sgMetaclass for enumeration.

    To define your own enumeration, do something like

    class Color(Enum):
        red = 1
        green = 2
        blue = 3

    Now, Color.red, Color.green and Color.blue behave totally
    different: they are enumerated values, not integers.

    Enumerations cannot be instantiated; however they can be
    subclassed.
    cCs�tt|�j|||�g|_xk|j�D]]}|jd�oS|jd�s2t||||�}t|||�|jj	|�q2q2WdS(Nt__(
tsuperRt__init__t_memberstkeyst
startswithtendswithtEnumInstancetsetattrtappend(tclstnametbasestdicttattrtenumval((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyRs	cCs |dkr|jSt|�dS(Nt__members__(RtAttributeError(RR((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt__getattr__scCs�d}}g|jD]*}t|t�r|tk	r|j^q}|r`ddj|�}ng|jD]}d|t||�f^qj}|r�ddj|�}nd|j||fS(Nts(%s)s, s%s: %ds: {%s}s%s%s%s(t	__bases__t
isinstanceRtEnumt__name__tjoinRtgetattr(Rts1ts2tbaset	enumbasestvalt
enumvalues((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt__repr__"s
*,(Rt
__module__t__doc__RRR!(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyRs			tFullEnumMetaclasscBseZdZd�ZRS(snMetaclass for full enumerations.

    A full enumeration displays all the values defined in base classes.
    cCs|tt|�j|||�xY|jD]N}t|t�r&x6|jD](}||jkrE|jj|�qEqEWq&q&WdS(N(RR$Rt__mro__RRRR
(RRR
RtobjR((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR4s(RR"R#R(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR$.sRcBs2eZdZd�Zd�Zd�Zd�ZRS(sClass to represent an enumeration value.

    EnumInstance('Color', 'red', 12) prints as 'Color.red' and behaves
    like the integer 12 when compared, but doesn't support arithmetic.

    XXX Should it record the actual enumeration rather than just its
    name?
    cCstj||�S(N(tintt__new__(Rt	classnametenumnametvalue((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR(GscCs||_||_dS(N(t_EnumInstance__classnamet_EnumInstance__enumname(tselfR)R*R+((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyRJs	cCsd|j|j|fS(NsEnumInstance(%s, %s, %d)(R,R-(R.((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR!NscCsd|j|jfS(Ns%s.%s(R,R-(R.((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt__str__Rs(RR"R#R(RR!R/(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR=s
			RcBseZeZRS((RR"Rt
__metaclass__(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyRUstFullEnumcBseZeZRS((RR"R$R0(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR1XscCs�dtfd��Y}|jGHt|j�GH|j|jkGH|j|jkGH|jdkGH|jdkGHd|fd��Y}|jGH|jGH|j|jkGHdtfd��Y}d	||fd
��Y}|jGH|jGH|GH|GH|GH|GHdS(NtColorcBseZdZdZdZRS(iii(RR"tredtgreentblue(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR2]siit
ExtendedColorcBs&eZdZdZdZdZdZRS(iiiii(RR"twhitetorangetyellowtpurpletblack(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR6js
t
OtherColorcBseZdZdZRS(ii(RR"R7R5(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR<vstMergedColorcBseZRS((RR"(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR=zs(RR3treprR5R8R7(R2R6R<R=((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt_test[s&cCs�dtfd��Y}|jGHt|j�GH|j|jkGH|j|jkGH|jdkGH|jdkGHd|fd��Y}|jGH|jGH|j|jkGHdtfd��Y}d	||fd
��Y}|jGH|jGH|GH|GH|GH|GHdS(NR2cBseZdZdZdZRS(iii(RR"R3R4R5(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR2�siiR6cBs&eZdZdZdZdZdZRS(iiiii(RR"R7R8R9R:R;(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR6�s
R<cBseZdZdZRS(ii(RR"R7R5(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR<�sR=cBseZRS((RR"(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR=�s(R1R3R>R5R8R7(R2R6R<R=((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt_test2�s&t__main__N(((R#ttypeRR$R'RRR1R?R@R(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt<module>s+	*	*PK{��Za�Q���
Eiffel.pyonu�[���PK{��Z�|�rr
Eiffel.pycnu�[���PK{��Ze@�P��	�0Eiffel.pynu�[���PK{��Zm�zu?Enum.pynu�[���PK{��Z�;o��PEnum.pycnu�[���PK{��Z�;o��kEnum.pyonu�[���PK�0�