CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Thu, 24 Jul 2025 23:19:03 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20110811054358
location: https://web.archive.org/web/20110811054358/https://wiki.python.org/moin/EnumerationProgramming
server-timing: captures_list;dur=0.667457, exclusion.robots;dur=0.027854, exclusion.robots.policy;dur=0.011940, esindex;dur=0.015492, cdx.remote;dur=6.275648, LoadShardBlock;dur=420.358663, PetaboxLoader3.datanode;dur=72.651172, PetaboxLoader3.resolve;dur=314.549226
x-app-server: wwwb-app225
x-ts: 302
x-tr: 460
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app225; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Thu, 24 Jul 2025 23:19:03 GMT
content-type: text/html; charset=utf-8
x-archive-orig-date: Thu, 11 Aug 2011 05:43:58 GMT
x-archive-orig-server: Apache/2.2.16 (Debian)
x-archive-orig-vary: Cookie,User-Agent,Accept-Language
x-archive-orig-set-cookie: MOIN_SESSION_80_ROOT_moin=627da47a01cc36f89dc0af4ebc968eda9e0c08e6; expires=Thu, 11-Aug-2011 06:43:00 GMT; Max-Age=3600; Path=/
x-archive-orig-content-length: 30860
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Thu, 11 Aug 2011 05:43:58 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Sat, 06 May 2006 22:15:09 GMT", ; rel="prev memento"; datetime="Sat, 08 Dec 2007 09:45:08 GMT", ; rel="memento"; datetime="Thu, 11 Aug 2011 05:43:58 GMT", ; rel="next memento"; datetime="Thu, 07 Jul 2022 05:34:34 GMT", ; rel="last memento"; datetime="Sat, 13 Jul 2024 11:02:06 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: WPO-20110811050604-crawl438/WPO-20110811053414-01502.warc.gz
server-timing: captures_list;dur=0.751264, exclusion.robots;dur=0.018688, exclusion.robots.policy;dur=0.009181, esindex;dur=0.011936, cdx.remote;dur=10.848405, LoadShardBlock;dur=399.144104, PetaboxLoader3.resolve;dur=734.570462, PetaboxLoader3.datanode;dur=256.221510, load_resource;dur=602.669641
x-app-server: wwwb-app221
x-ts: 200
x-tr: 1068
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: HIT
server-timing: HIT
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
EnumerationProgramming - PythonInfo Wiki
User
Enumeration Programming
Why, When
This Implementation is really near to the UML description of <<Enumeration>>. It uses new style class.
Code
1 # code is public domain
2
3 class Enumeration(object):
4
5 def __new__(cls, arg):
6 if hasattr(cls, arg):
7 return getattr(cls,arg)
8 else:
9 return object.__new__(cls, arg)
10
11 def __init__(self, name):
12 self._name = name
13 setattr(self.__class__, name, self)
14
15 def __str__(self):
16 return '#%s' % self._name
17
18 def __repr__(self):
19 return "%s('%s')" % (self.__class__.__name__, self._name)
20
21 def getEnumerationSet(cls):
22 result = set()
23 for attr in dir(cls):
24 attr = getattr(cls, attr)
25 if isinstance(attr, Enumeration):
26 result.add(attr)
27 return result
28 getEnumerationSet = classmethod(getEnumerationSet)
Example
1 class PrimaryColorKind(Enumeration):
2 pass
3 PrimaryColorKind('Rouge')
4 PrimaryColorKind('Vert')
5 PrimaryColorKind('Bleu')
6
7 print PrimaryColorKind.Rouge, PrimaryColorKind.Vert, PrimaryColorKind.Bleu
8 print PrimaryColorKind.getEnumerationSet()
9
10 class ColorKind(PrimaryColorKind):
11 pass
12 ColorKind('Violet')
13
14
15 print ColorKind.Rouge, ColorKind.Violet
16 print ColorKind.getEnumerationSet()
17 print repr(ColorKind.Rouge), repr(ColorKind.Violet)
18 assert(ColorKind.Rouge is ColorKind('Rouge'))
output is :
#Rouge #Vert #Bleu Set([PrimaryColorKind('Vert'), PrimaryColorKind('Rouge'), PrimaryColorKind('Bleu')]) #Rouge #Violet Set([PrimaryColorKind('Vert'), PrimaryColorKind('Rouge'), ColorKind('Violet'), PrimaryColorKind('Bleu')]) PrimaryColorKind('Rouge') ColorKind('Violet') mirville Python 79 % python Enumeration.py #Rouge #Vert #Bleu Set([PrimaryColorKind('Vert'), PrimaryColorKind('Rouge'), PrimaryColorKind('Bleu')]) #Rouge #Violet Set([PrimaryColorKind('Vert'), PrimaryColorKind('Rouge'), ColorKind('Violet'), PrimaryColorKind('Bleu')]) PrimaryColorKind('Rouge') ColorKind('Violet')
EnumerationProgramming (last edited 2010-01-07 01:13:07 by vpn-8061f417)