ÿØÿà JFIF    ÿÛ „ ( %!1!%*+...983,7(-.- lib64/python2.7/Demo/metaclasses/Enum.pyc000064400000014043152360644470014062 0ustar00 ^c@smdZddlZdd dYZdd dYZedd iZdZed kriendS( sCEnumeration metaclass. XXX This is very much a work in progress. iNt EnumMetaClasscBs)eZdZdZdZdZRS(shMetaclass 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. cCsx)|D]!}|jtk rtdqqWtd|}||_||_i|_x3|jD]%\}}t||||j|)tN( t __class__Rt TypeErrortfiltert__name__t __bases__t_EnumMetaClass__dicttitemst EnumInstance(tselftnametbasestdicttbasetkeytvalue((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt__init__s    cCs|dkr|jjSy|j|SWnMtk rwx=|jD].}yt||SWqBtk roqBqBXqBWnXt|dS(sReturn an enumeration value. For example, Color.red returns the value corresponding to red. XXX Perhaps the values should be created in the constructor? This looks in the class dictionary and if it is not found there asks the base classes. The special attribute __members__ returns the list of names defined in this class (it does not merge in the names defined in base classes). t __members__N(R tkeystKeyErrorR tgetattrtAttributeError(R RR((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt __getattr__0s    cCs|j}|jrB|dtjtd|jdd}n|jrg}x:|jjD])\}}|jd|t|fqaWd|tj|df}n|S(Nt(cSs|jS(N(R(R((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyRPRs, t)s%s: %ss%s: {%s}( RR tstringtjointmapR R tappendtint(R tstlistRR((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt__repr__Ms  0 !(Rt __module__t__doc__RRR$(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR s  R cBs;eZdZdZdZdZdZdZRS(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? cCs||_||_||_dS(N(t_EnumInstance__classnamet_EnumInstance__enumnamet_EnumInstance__value(R t classnametenumnameR((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyRes  cCs|jS(N(R)(R ((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt__int__jscCsd|j|j|jfS(NsEnumInstance(%r, %r, %r)(R'R(R)(R ((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR$ms cCsd|j|jfS(Ns%s.%s(R'R((R ((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt__str__rscCst|jt|S(N(tcmpR)R!(R tother((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt__cmp__us(RR%R&RR,R$R-R0(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR Zs      RcCsdtfdY}|jGHt|GH|j|jkGH|j|jkGH|jdkGH|jdkGHd|fdY}|jGH|jGH|j|jkGHdtfdY}d ||fd Y}|jGH|jGH|GH|GH|GH|GHdS( NtColorcBseZdZdZdZRS(iii(RR%tredtgreentblue(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR1siit ExtendedColorcBs&eZdZdZdZdZdZRS(iiiii(RR%twhitetorangetyellowtpurpletblack(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR5s t OtherColorcBseZdZdZRS(ii(RR%R6R4(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR;st MergedColorcBseZRS((RR%(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR<s(RR2tdirR4R7R6(R1R5R;R<((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt_test~s& t__main__((((R&RRR RR>R(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyts Q! * lib64/python2.7/Demo/newmetaclasses/Enum.pyc000064400000015407152362457040014576 0ustar00 ^c@sdZdefdYZdefdYZdefdYZdddYZd dd YZd Zd Z e d kree ndS(sEnumeration metaclass.t EnumMetaclasscBs)eZdZdZdZdZRS(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. cCstt|j|||g|_xk|jD]]}|jdoS|jds2t||||}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(R R ((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyt __getattr__s cCsd}}g|jD]*}t|tr|tk r|j^q}|r`ddj|}ng|jD]}d|t||f^qj}|rddj|}nd|j||fS(Nts(%s)s, s%s: %ds: {%s}s%s%s%s(t __bases__t isinstanceRtEnumt__name__tjoinRtgetattr(R ts1ts2tbaset 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 tFullEnumMetaclasscBseZdZdZRS(snMetaclass for full enumerations. A full enumeration displays all the values defined in base classes. cCs|tt|j|||xY|jD]N}t|tr&x6|jD](}||jkrE|jj|qEqEWq&q&WdS(N(RR$Rt__mro__RRRR (R R R RtobjR((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR4s (RR"R#R(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR$.sRcBs2eZdZdZdZdZdZRS(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__(R t 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.pyR1XscCsdtfdY}|jGHt|jGH|j|jkGH|j|jkGH|jdkGH|jdkGHd|fdY}|jGH|jGH|j|jkGHdtfdY}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<vst MergedColorcBseZRS((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&cCsdtfdY}|jGHt|jGH|j|jkGH|j|jkGH|jdkGH|jdkGHd|fdY}|jGH|jGH|j|jkGHdtfdY}d ||fd Y}|jGH|jGH|GH|GH|GH|GHdS( NR2cBseZdZdZdZRS(iii(RR"R3R4R5(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR2siiR6cBs&eZdZdZdZdZdZRS(iiiii(RR"R7R8R9R:R;(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyR6s 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_test2s&t__main__N((( R#ttypeRR$R'RRR1R?R@R(((s0/usr/lib64/python2.7/Demo/newmetaclasses/Enum.pyts+ * * usr/lib64/python2.7/Demo/metaclasses/Enum.pyc000064400000014043152405511740014664 0ustar00 ^c@smdZddlZdd dYZdd dYZedd iZdZed kriendS( sCEnumeration metaclass. XXX This is very much a work in progress. iNt EnumMetaClasscBs)eZdZdZdZdZRS(shMetaclass 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. cCsx)|D]!}|jtk rtdqqWtd|}||_||_i|_x3|jD]%\}}t||||j|)tN( t __class__Rt TypeErrortfiltert__name__t __bases__t_EnumMetaClass__dicttitemst EnumInstance(tselftnametbasestdicttbasetkeytvalue((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt__init__s    cCs|dkr|jjSy|j|SWnMtk rwx=|jD].}yt||SWqBtk roqBqBXqBWnXt|dS(sReturn an enumeration value. For example, Color.red returns the value corresponding to red. XXX Perhaps the values should be created in the constructor? This looks in the class dictionary and if it is not found there asks the base classes. The special attribute __members__ returns the list of names defined in this class (it does not merge in the names defined in base classes). t __members__N(R tkeystKeyErrorR tgetattrtAttributeError(R RR((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt __getattr__0s    cCs|j}|jrB|dtjtd|jdd}n|jrg}x:|jjD])\}}|jd|t|fqaWd|tj|df}n|S(Nt(cSs|jS(N(R(R((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyRPRs, t)s%s: %ss%s: {%s}( RR tstringtjointmapR R tappendtint(R tstlistRR((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt__repr__Ms  0 !(Rt __module__t__doc__RRR$(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR s  R cBs;eZdZdZdZdZdZdZRS(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? cCs||_||_||_dS(N(t_EnumInstance__classnamet_EnumInstance__enumnamet_EnumInstance__value(R t classnametenumnameR((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyRes  cCs|jS(N(R)(R ((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt__int__jscCsd|j|j|jfS(NsEnumInstance(%r, %r, %r)(R'R(R)(R ((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR$ms cCsd|j|jfS(Ns%s.%s(R'R((R ((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt__str__rscCst|jt|S(N(tcmpR)R!(R tother((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt__cmp__us(RR%R&RR,R$R-R0(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR Zs      RcCsdtfdY}|jGHt|GH|j|jkGH|j|jkGH|jdkGH|jdkGHd|fdY}|jGH|jGH|j|jkGHdtfdY}d ||fd Y}|jGH|jGH|GH|GH|GH|GHdS( NtColorcBseZdZdZdZRS(iii(RR%tredtgreentblue(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR1siit ExtendedColorcBs&eZdZdZdZdZdZRS(iiiii(RR%twhitetorangetyellowtpurpletblack(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR5s t OtherColorcBseZdZdZRS(ii(RR%R6R4(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR;st MergedColorcBseZRS((RR%(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyR<s(RR2tdirR4R7R6(R1R5R;R<((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyt_test~s& t__main__((((R&RRR RR>R(((s-/usr/lib64/python2.7/Demo/metaclasses/Enum.pyts Q! *