Artifact db426bb1d8b1754e3cc4e6d38ce6cc8ab594a133:
Wiki page
[
Underscode] by
ivan
2011-12-31 16:34:23.
0000: 44 20 32 30 31 31 2d 31 32 2d 33 31 54 31 36 3a D 2011-12-31T16:
0010: 33 34 3a 32 33 2e 30 36 32 0a 4c 20 55 6e 64 65 34:23.062.L Unde
0020: 72 73 63 6f 64 65 0a 55 20 69 76 61 6e 0a 57 20 rscode.U ivan.W
0030: 36 30 30 34 0a 3c 68 31 3e 55 6e 64 65 72 73 63 6004.<h1>Undersc
0040: 6f 64 65 2c 20 61 20 50 79 74 68 6f 6e 20 69 64 ode, a Python id
0050: 65 6e 74 69 66 69 65 72 2d 6c 69 6b 65 20 65 6e entifier-like en
0060: 63 6f 64 69 6e 67 3c 2f 68 31 3e 0d 0a 0d 0a 3c coding</h1>....<
0070: 64 6c 3e 0d 0a 3c 64 74 3e 41 75 74 68 6f 72 3c dl>..<dt>Author<
0080: 64 64 3e 3c 61 20 68 72 65 66 3d 22 6d 61 69 6c dd><a href="mail
0090: 74 6f 3a 69 76 61 6e 26 23 36 34 3b 73 65 6c 69 to:ivan@seli
00a0: 64 6f 72 2e 6e 65 74 22 3e 49 76 61 6e 20 56 69 dor.net">Ivan Vi
00b0: 6c 61 74 61 20 69 20 42 61 6c 61 67 75 65 72 3c lata i Balaguer<
00c0: 2f 61 3e 0d 0a 3c 64 74 3e 55 52 4c 3c 64 64 3e /a>..<dt>URL<dd>
00d0: 5b 68 74 74 70 73 3a 2f 2f 65 6c 76 69 6c 2e 6e [https://elvil.n
00e0: 65 74 2f 66 6f 73 73 69 6c 2f 75 6e 64 65 72 73 et/fossil/unders
00f0: 63 6f 64 65 2f 5d 0d 0a 3c 2f 64 6c 3e 0d 0a 0d code/]..</dl>...
0100: 0a 0d 0a 3c 68 32 3e 41 62 6f 75 74 20 55 6e 64 ...<h2>About Und
0110: 65 72 73 63 6f 64 65 3c 2f 68 32 3e 0d 0a 0d 0a erscode</h2>....
0120: 5b 68 74 74 70 73 3a 2f 2f 65 6c 76 69 6c 2e 6e [https://elvil.n
0130: 65 74 2f 66 6f 73 73 69 6c 2f 75 6e 64 65 72 73 et/fossil/unders
0140: 63 6f 64 65 2f 7c 55 6e 64 65 72 73 63 6f 64 65 code/|Underscode
0150: 5d 20 69 73 20 61 6e 20 65 6e 63 6f 64 69 6e 67 ] is an encoding
0160: 20 77 68 69 63 68 20 69 73 0d 0a 63 61 70 61 62 which is..capab
0170: 6c 65 20 6f 66 20 72 65 70 72 65 73 65 6e 74 69 le of representi
0180: 6e 67 20 3c 65 6d 3e 61 6e 79 3c 2f 65 6d 3e 20 ng <em>any</em>
0190: 55 6e 69 63 6f 64 65 20 73 74 72 69 6e 67 20 61 Unicode string a
01a0: 73 20 61 20 76 61 6c 69 64 20 28 61 6e 64 20 71 s a valid (and q
01b0: 75 69 74 65 0d 0a 73 69 6d 69 6c 61 72 29 20 50 uite..similar) P
01c0: 79 74 68 6f 6e 20 69 64 65 6e 74 69 66 69 65 72 ython identifier
01d0: 2e 20 20 54 68 65 20 77 61 79 20 55 6e 69 63 6f . The way Unico
01e0: 64 65 20 73 74 72 69 6e 67 73 20 61 72 65 20 65 de strings are e
01f0: 6e 63 6f 64 65 64 20 6d 69 6e 69 6d 69 73 65 73 ncoded minimises
0200: 20 74 68 65 0d 0a 63 68 61 6e 63 65 73 20 6f 66 the..chances of
0210: 20 63 6c 61 73 68 69 6e 67 20 77 69 74 68 20 6f clashing with o
0220: 74 68 65 72 20 65 78 69 73 74 69 6e 67 20 6e 61 ther existing na
0230: 6d 65 73 2c 20 77 68 69 6c 65 20 6e 6f 74 20 6f mes, while not o
0240: 62 73 63 75 72 69 6e 67 20 74 68 65 0d 0a 72 65 bscuring the..re
0250: 73 75 6c 74 69 6e 67 20 73 74 72 69 6e 67 20 74 sulting string t
0260: 6f 6f 20 6d 75 63 68 2e 0d 0a 0d 0a 53 6f 6d 65 oo much.....Some
0270: 20 6d 65 74 68 6f 64 20 64 65 63 6f 72 61 74 6f method decorato
0280: 72 73 20 61 72 65 20 70 72 6f 76 69 64 65 64 20 rs are provided
0290: 77 68 69 63 68 20 61 6c 6c 6f 77 20 61 72 62 69 which allow arbi
02a0: 74 72 61 72 79 20 6f 62 6a 65 63 74 73 20 74 6f trary objects to
02b0: 20 62 65 0d 0a 61 63 63 65 73 73 65 64 20 61 73 be..accessed as
02c0: 20 6e 6f 72 6d 61 6c 20 69 6e 73 74 61 6e 63 65 normal instance
02d0: 20 61 74 74 72 69 62 75 74 65 73 2c 20 77 69 74 attributes, wit
02e0: 68 20 6f 70 74 69 6f 6e 61 6c 20 74 61 62 2d 63 h optional tab-c
02f0: 6f 6d 70 6c 65 74 69 6f 6e 20 73 75 70 70 6f 72 ompletion suppor
0300: 74 0d 0a 66 6f 72 20 69 6e 74 65 72 61 63 74 69 t..for interacti
0310: 76 65 20 75 73 61 67 65 2e 20 20 54 68 65 20 73 ve usage. The s
0320: 74 61 6e 64 61 72 64 20 50 79 74 68 6f 6e 20 63 tandard Python c
0330: 6f 64 65 63 20 41 50 49 20 69 73 20 61 6c 73 6f odec API is also
0340: 20 73 75 70 70 6f 72 74 65 64 2e 0d 0a 0d 0a 55 supported.....U
0350: 6e 64 65 72 73 63 6f 64 65 2d 65 6e 63 6f 64 65 nderscode-encode
0360: 64 20 28 6f 72 20 3c 65 6d 3e 75 6e 64 65 72 73 d (or <em>unders
0370: 63 6f 64 65 64 3c 2f 65 6d 3e 29 20 73 74 72 69 coded</em>) stri
0380: 6e 67 73 20 63 61 6e 20 62 65 20 71 75 69 63 6b ngs can be quick
0390: 6c 79 20 73 70 6f 74 74 65 64 0d 0a 62 65 63 61 ly spotted..beca
03a0: 75 73 65 20 74 68 65 79 20 65 6e 64 20 77 69 74 use they end wit
03b0: 68 20 61 6e 20 3c 65 6d 3e 6f 64 64 3c 2f 65 6d h an <em>odd</em
03c0: 3e 20 6e 75 6d 62 65 72 20 6f 66 20 75 6e 64 65 > number of unde
03d0: 72 73 63 6f 72 65 73 2c 20 61 6e 64 20 74 68 65 rscores, and the
03e0: 79 20 63 6f 6e 74 61 69 6e 0d 0a 65 73 63 61 70 y contain..escap
03f0: 65 20 73 65 71 75 65 6e 63 65 73 20 62 65 67 69 e sequences begi
0400: 6e 6e 69 6e 67 20 77 69 74 68 20 61 6e 20 75 6e nning with an un
0410: 64 65 72 73 63 6f 72 65 20 77 68 65 72 65 20 63 derscore where c
0420: 68 61 72 61 63 74 65 72 73 20 6e 6f 74 20 61 6c haracters not al
0430: 6c 6f 77 65 64 20 69 6e 0d 0a 69 64 65 6e 74 69 lowed in..identi
0440: 66 69 65 72 73 20 77 6f 75 6c 64 20 62 65 20 66 fiers would be f
0450: 6f 75 6e 64 2e 20 20 53 6f 6d 65 20 65 78 61 6d ound. Some exam
0460: 70 6c 65 73 20 6f 66 20 75 6e 64 65 72 73 63 6f ples of undersco
0470: 64 65 64 20 73 74 72 69 6e 67 73 20 61 72 65 3a ded strings are:
0480: 0d 0a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 63 ....<ul>..<li><c
0490: 6f 64 65 3e 5f 3c 2f 63 6f 64 65 3e 20 65 6e 63 ode>_</code> enc
04a0: 6f 64 65 73 20 74 68 65 20 65 6d 70 74 79 20 73 odes the empty s
04b0: 74 72 69 6e 67 2e 0d 0a 3c 6c 69 3e 3c 63 6f 64 tring...<li><cod
04c0: 65 3e 66 6f 6f 5f 3c 2f 63 6f 64 65 3e 20 65 6e e>foo_</code> en
04d0: 63 6f 64 65 73 20 3c 63 6f 64 65 3e 66 6f 6f 3c codes <code>foo<
04e0: 2f 63 6f 64 65 3e 2e 0d 0a 3c 6c 69 3e 3c 63 6f /code>...<li><co
04f0: 64 65 3e 63 6c 61 73 73 5f 3c 2f 63 6f 64 65 3e de>class_</code>
0500: 20 65 6e 63 6f 64 65 73 20 3c 63 6f 64 65 3e 63 encodes <code>c
0510: 6c 61 73 73 3c 2f 63 6f 64 65 3e 2e 0d 0a 3c 6c lass</code>...<l
0520: 69 3e 3c 63 6f 64 65 3e 66 6f 6f 5f 5f 62 61 72 i><code>foo__bar
0530: 5f 3c 2f 63 6f 64 65 3e 20 65 6e 63 6f 64 65 73 _</code> encodes
0540: 20 3c 63 6f 64 65 3e 66 6f 6f 20 62 61 72 3c 2f <code>foo bar</
0550: 63 6f 64 65 3e 2e 0d 0a 3c 6c 69 3e 3c 63 6f 64 code>...<li><cod
0560: 65 3e 66 6f 6f 5f 78 35 66 62 61 72 5f 3c 2f 63 e>foo_x5fbar_</c
0570: 6f 64 65 3e 20 65 6e 63 6f 64 65 73 20 3c 63 6f ode> encodes <co
0580: 64 65 3e 66 6f 6f 5f 62 61 72 3c 2f 63 6f 64 65 de>foo_bar</code
0590: 3e 2e 0d 0a 3c 6c 69 3e 3c 63 6f 64 65 3e 5f 32 >...<li><code>_2
05a0: 30 30 36 5f 30 39 5f 31 38 5f 3c 2f 63 6f 64 65 006_09_18_</code
05b0: 3e 2c 20 6c 69 6b 65 20 3c 63 6f 64 65 3e 5f 32 >, like <code>_2
05c0: 30 30 36 30 39 31 38 5f 3c 2f 63 6f 64 65 3e 2c 0060918_</code>,
05d0: 20 65 6e 63 6f 64 65 73 20 3c 63 6f 64 65 3e 32 encodes <code>2
05e0: 30 30 36 30 39 31 38 3c 2f 63 6f 64 65 3e 2e 0d 0060918</code>..
05f0: 0a 3c 6c 69 3e 3c 63 6f 64 65 3e 5f 78 32 66 62 .<li><code>_x2fb
0600: 69 6e 5f 78 32 66 6c 73 5f 3c 2f 63 6f 64 65 3e in_x2fls_</code>
0610: 2c 20 65 6e 63 6f 64 65 73 20 3c 63 6f 64 65 3e , encodes <code>
0620: 2f 62 69 6e 2f 6c 73 3c 2f 63 6f 64 65 3e 2e 0d /bin/ls</code>..
0630: 0a 3c 6c 69 3e 3c 63 6f 64 65 3e 54 68 65 5f 5f .<li><code>The__
0640: 4b 6e 69 67 68 74 73 5f 5f 57 68 6f 5f 5f 53 61 Knights__Who__Sa
0650: 79 5f 5f 5f 75 32 30 31 63 4e 69 5f 78 32 31 5f y___u201cNi_x21_
0660: 75 32 30 31 64 5f 3c 2f 63 6f 64 65 3e 20 65 6e u201d_</code> en
0670: 63 6f 64 65 73 20 74 68 65 20 70 72 6f 70 65 72 codes the proper
0680: 6c 79 20 71 75 6f 74 65 64 20 3c 63 6f 64 65 3e ly quoted <code>
0690: 54 68 65 20 4b 6e 69 67 68 74 73 20 57 68 6f 20 The Knights Who
06a0: 53 61 79 20 e2 80 9c 4e 69 21 e2 80 9d 3c 2f 63 Say ...Ni!...</c
06b0: 6f 64 65 3e 2e 0d 0a 3c 2f 75 6c 3e 0d 0a 0d 0a ode>...</ul>....
06c0: 41 73 20 79 6f 75 20 73 65 65 2c 20 75 6e 64 65 As you see, unde
06d0: 72 73 63 6f 64 65 64 20 73 74 72 69 6e 67 73 20 rscoded strings
06e0: 61 72 65 20 71 75 69 74 65 20 73 69 6d 69 6c 61 are quite simila
06f0: 72 20 74 6f 20 74 68 65 69 72 20 64 65 63 6f 64 r to their decod
0700: 65 64 0d 0a 63 6f 75 6e 74 65 72 70 61 72 74 73 ed..counterparts
0710: 20 77 68 65 6e 20 74 68 65 73 65 20 61 72 65 20 when these are
0720: 6d 6f 72 65 20 6f 72 20 6c 65 73 73 20 69 64 65 more or less ide
0730: 6e 74 69 66 69 65 72 2d 6c 69 6b 65 2c 20 62 75 ntifier-like, bu
0740: 74 20 63 6f 6d 70 6c 65 78 20 73 74 72 69 6e 67 t complex string
0750: 73 0d 0a 63 61 6e 20 73 74 69 6c 6c 20 62 65 20 s..can still be
0760: 68 61 6e 64 6c 65 64 2e 0d 0a 0d 0a 55 6e 64 65 handled.....Unde
0770: 72 73 63 6f 64 65 20 69 73 20 61 20 76 65 72 79 rscode is a very
0780: 20 62 61 73 69 63 20 74 6f 6f 6c 20 77 68 69 63 basic tool whic
0790: 68 20 6d 61 79 20 68 61 76 65 20 73 65 76 65 72 h may have sever
07a0: 61 6c 20 75 73 65 73 3a 0d 0a 0d 0a 3c 75 6c 3e al uses:....<ul>
07b0: 0d 0a 3c 6c 69 3e 41 76 6f 69 64 69 6e 67 20 63 ..<li>Avoiding c
07c0: 6c 61 73 68 65 73 20 62 65 74 77 65 65 6e 20 6d lashes between m
07d0: 65 74 68 6f 64 20 6e 61 6d 65 73 20 61 6e 64 20 ethod names and
07e0: 74 61 62 6c 65 20 66 69 65 6c 64 20 6e 61 6d 65 table field name
07f0: 73 20 69 6e 20 4f 52 4d 73 2e 0d 0a 3c 6c 69 3e s in ORMs...<li>
0800: 45 6e 61 62 6c 69 6e 67 20 69 6e 74 65 72 61 63 Enabling interac
0810: 74 69 76 65 20 61 74 74 72 69 62 75 74 65 2d 6c tive attribute-l
0820: 69 6b 65 20 63 6f 6d 70 6c 65 74 69 6f 6e 20 66 ike completion f
0830: 6f 72 20 63 68 69 6c 64 72 65 6e 20 69 6e 0d 0a or children in..
0840: 68 69 65 72 61 72 63 68 69 63 61 6c 6c 79 20 61 hierarchically a
0850: 72 72 61 6e 67 65 64 20 73 74 72 75 63 74 75 72 rranged structur
0860: 65 73 20 28 44 4f 4d 20 74 72 65 65 73 2c 20 66 es (DOM trees, f
0870: 69 6c 65 73 79 73 74 65 6d 73 2e 2e 2e 29 2c 20 ilesystems...),
0880: 77 69 74 68 20 66 75 6c 6c 0d 0a 55 6e 69 63 6f with full..Unico
0890: 64 65 20 73 75 70 70 6f 72 74 2e 0d 0a 3c 6c 69 de support...<li
08a0: 3e 41 73 20 61 6e 20 61 69 64 20 69 6e 20 74 68 >As an aid in th
08b0: 65 20 67 65 6e 65 72 61 74 69 6f 6e 20 6f 66 20 e generation of
08c0: 52 50 43 20 73 74 75 62 73 20 66 6f 72 20 69 64 RPC stubs for id
08d0: 65 6e 74 69 66 69 65 72 73 20 77 68 69 63 68 20 entifiers which
08e0: 61 72 65 20 6e 6f 74 0d 0a 61 6c 6c 6f 77 65 64 are not..allowed
08f0: 20 62 79 20 50 79 74 68 6f 6e 2e 0d 0a 3c 6c 69 by Python...<li
0900: 3e 43 6f 6d 70 75 74 69 6e 67 20 75 6e 69 71 75 >Computing uniqu
0910: 65 20 49 44 73 20 66 6f 72 20 73 65 63 74 69 6f e IDs for sectio
0920: 6e 73 20 69 6e 20 61 75 74 6f 6d 61 74 69 63 61 ns in automatica
0930: 6c 6c 79 20 67 65 6e 65 72 61 74 65 64 20 58 4d lly generated XM
0940: 4c 20 6f 72 20 48 54 4d 4c 0d 0a 64 6f 63 75 6d L or HTML..docum
0950: 65 6e 74 73 2e 0d 0a 3c 6c 69 3e 4e 61 6d 69 6e ents...<li>Namin
0960: 67 20 70 61 67 65 20 68 61 6e 64 6c 65 72 73 20 g page handlers
0970: 66 6f 72 20 77 65 62 20 73 65 72 76 65 72 20 66 for web server f
0980: 72 61 6d 65 77 6f 72 6b 73 20 6c 69 6b 65 20 43 rameworks like C
0990: 68 65 72 72 79 50 79 2e 0d 0a 3c 6c 69 3e 2e 2e herryPy...<li>..
09a0: 2e 20 6a 75 73 74 20 75 73 65 20 79 6f 75 72 20 . just use your
09b0: 69 6d 61 67 69 6e 61 74 69 6f 6e 21 0d 0a 3c 2f imagination!..</
09c0: 75 6c 3e 0d 0a 0d 0a 54 68 65 20 55 6e 64 65 72 ul>....The Under
09d0: 73 63 6f 64 65 20 70 61 63 6b 61 67 65 20 69 73 scode package is
09e0: 20 72 65 6c 65 61 73 65 64 20 75 6e 64 65 72 20 released under
09f0: 74 68 65 20 47 4e 55 20 4c 65 73 73 65 72 20 47 the GNU Lesser G
0a00: 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 20 4c 69 eneral Public Li
0a10: 63 65 6e 73 65 0d 0a 28 4c 47 50 4c 29 20 76 65 cense..(LGPL) ve
0a20: 72 73 69 6f 6e 20 33 20 6f 72 20 6c 61 74 65 72 rsion 3 or later
0a30: 20 28 73 65 65 20 5b 68 74 74 70 3a 2f 2f 77 77 (see [http://ww
0a40: 77 2e 67 6e 75 2e 6f 72 67 2f 6c 69 63 65 6e 73 w.gnu.org/licens
0a50: 65 73 2f 5d 29 2e 0d 0a 0d 0a 3c 68 32 3e 55 6e es/]).....<h2>Un
0a60: 64 65 72 73 63 6f 64 65 64 20 73 74 72 69 6e 67 derscoded string
0a70: 73 20 61 73 20 61 74 74 72 69 62 75 74 65 73 3c s as attributes<
0a80: 2f 68 32 3e 0d 0a 0d 0a 55 6e 64 65 72 73 63 6f /h2>....Undersco
0a90: 64 65 20 70 72 6f 76 69 64 65 73 20 61 20 6d 6f de provides a mo
0aa0: 64 75 6c 65 20 77 69 74 68 20 64 65 63 6f 72 61 dule with decora
0ab0: 74 6f 72 73 20 74 68 61 74 20 61 6c 6c 6f 77 20 tors that allow
0ac0: 79 6f 75 20 74 6f 20 75 73 65 20 70 6c 61 69 6e you to use plain
0ad0: 0d 0a 61 74 74 72 69 62 75 74 65 20 61 63 63 65 ..attribute acce
0ae0: 73 73 20 61 73 20 61 20 66 6c 65 78 69 62 6c 65 ss as a flexible
0af0: 20 77 61 79 20 6f 66 20 61 63 63 65 73 73 69 6e way of accessin
0b00: 67 20 61 6c 6c 20 6b 69 6e 64 73 20 6f 66 20 22 g all kinds of "
0b10: 63 68 69 6c 64 20 6f 62 6a 65 63 74 73 22 0d 0a child objects"..
0b20: 77 69 74 68 6f 75 74 20 70 6f 6c 6c 75 74 69 6e without pollutin
0b30: 67 20 74 68 65 20 6e 6f 72 6d 61 6c 20 61 74 74 g the normal att
0b40: 72 69 62 75 74 65 20 6e 61 6d 65 73 70 61 63 65 ribute namespace
0b50: 2c 20 61 6e 64 20 77 69 74 68 20 6f 70 74 69 6f , and with optio
0b60: 6e 61 6c 0d 0a 69 6e 74 65 72 61 63 74 69 76 65 nal..interactive
0b70: 20 63 6f 6d 70 6c 65 74 69 6f 6e 20 69 66 20 79 completion if y
0b80: 6f 75 20 77 69 73 68 20 73 6f 2e 20 20 46 6f 72 ou wish so. For
0b90: 20 69 6e 73 74 61 6e 63 65 2c 20 79 6f 75 20 63 instance, you c
0ba0: 61 6e 20 6d 61 6b 65 20 74 68 65 0d 0a 28 73 74 an make the..(st
0bb0: 72 69 6e 67 29 20 6b 65 79 73 20 6f 66 20 61 20 ring) keys of a
0bc0: 64 69 63 74 69 6f 6e 61 72 79 20 61 63 63 65 73 dictionary acces
0bd0: 73 69 62 6c 65 20 61 73 20 61 74 74 72 69 62 75 sible as attribu
0be0: 74 65 73 3a 0d 0a 0d 0a 3c 76 65 72 62 61 74 69 tes:....<verbati
0bf0: 6d 3e 0d 0a 66 72 6f 6d 20 75 6e 64 65 72 73 63 m>..from undersc
0c00: 6f 64 65 2e 64 65 63 6f 72 61 74 6f 72 73 20 69 ode.decorators i
0c10: 6d 70 6f 72 74 20 70 72 6f 78 79 5f 6d 65 74 68 mport proxy_meth
0c20: 6f 64 0d 0a 0d 0a 63 6c 61 73 73 20 41 74 74 72 od....class Attr
0c30: 69 62 75 74 65 64 44 69 63 74 28 64 69 63 74 29 ibutedDict(dict)
0c40: 3a 0d 0a 20 20 20 20 40 70 72 6f 78 79 5f 6d 65 :.. @proxy_me
0c50: 74 68 6f 64 28 64 69 63 74 2e 5f 5f 67 65 74 69 thod(dict.__geti
0c60: 74 65 6d 5f 5f 29 0d 0a 20 20 20 20 64 65 66 20 tem__).. def
0c70: 5f 5f 67 65 74 61 74 74 72 5f 5f 28 73 65 6c 66 __getattr__(self
0c80: 2c 20 6e 61 6d 65 29 3a 0d 0a 20 20 20 20 20 20 , name):..
0c90: 20 20 72 65 74 75 72 6e 20 73 75 70 65 72 28 41 return super(A
0ca0: 74 74 72 69 62 75 74 65 64 44 69 63 74 2c 20 73 ttributedDict, s
0cb0: 65 6c 66 29 2e 5f 5f 67 65 74 61 74 74 72 5f 5f elf).__getattr__
0cc0: 28 6e 61 6d 65 29 0d 0a 0d 0a 20 20 20 20 40 70 (name).... @p
0cd0: 72 6f 78 79 5f 6d 65 74 68 6f 64 28 64 69 63 74 roxy_method(dict
0ce0: 2e 5f 5f 73 65 74 69 74 65 6d 5f 5f 29 0d 0a 20 .__setitem__)..
0cf0: 20 20 20 64 65 66 20 5f 5f 73 65 74 61 74 74 72 def __setattr
0d00: 5f 5f 28 73 65 6c 66 2c 20 6e 61 6d 65 2c 20 76 __(self, name, v
0d10: 61 6c 75 65 29 3a 0d 0a 20 20 20 20 20 20 20 20 alue):..
0d20: 73 75 70 65 72 28 41 74 74 72 69 62 75 74 65 64 super(Attributed
0d30: 44 69 63 74 2c 20 73 65 6c 66 29 2e 5f 5f 73 65 Dict, self).__se
0d40: 74 61 74 74 72 5f 5f 28 6e 61 6d 65 2c 20 76 61 tattr__(name, va
0d50: 6c 75 65 29 0d 0a 0d 0a 20 20 20 20 40 70 72 6f lue).... @pro
0d60: 78 79 5f 6d 65 74 68 6f 64 28 64 69 63 74 2e 5f xy_method(dict._
0d70: 5f 64 65 6c 69 74 65 6d 5f 5f 29 0d 0a 20 20 20 _delitem__)..
0d80: 20 64 65 66 20 5f 5f 64 65 6c 61 74 74 72 5f 5f def __delattr__
0d90: 28 73 65 6c 66 2c 20 6e 61 6d 65 29 3a 0d 0a 20 (self, name):..
0da0: 20 20 20 20 20 20 20 73 75 70 65 72 28 41 74 74 super(Att
0db0: 72 69 62 75 74 65 64 44 69 63 74 2c 20 73 65 6c ributedDict, sel
0dc0: 66 29 2e 5f 5f 64 65 6c 61 74 74 72 5f 5f 28 6e f).__delattr__(n
0dd0: 61 6d 65 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d ame)..</verbatim
0de0: 3e 0d 0a 0d 0a 54 68 65 6e 2c 20 61 63 63 65 73 >....Then, acces
0df0: 73 20 74 6f 20 61 6e 20 61 74 74 72 69 62 75 74 s to an attribut
0e00: 65 20 77 68 69 63 68 20 6c 6f 6f 6b 73 20 6c 69 e which looks li
0e10: 6b 65 20 61 6e 20 75 6e 64 65 72 73 63 6f 64 65 ke an underscode
0e20: 64 20 73 74 72 69 6e 67 20 67 65 74 73 20 74 68 d string gets th
0e30: 65 0d 0a 6e 61 6d 65 20 64 65 63 6f 64 65 64 20 e..name decoded
0e40: 61 6e 64 20 75 73 65 64 20 61 73 20 61 6e 20 61 and used as an a
0e50: 72 67 75 6d 65 6e 74 20 74 6f 20 3c 63 6f 64 65 rgument to <code
0e60: 3e 5f 5f 67 65 74 69 74 65 6d 5f 5f 28 29 3c 2f >__getitem__()</
0e70: 63 6f 64 65 3e 3a 0d 0a 0d 0a 3c 76 65 72 62 61 code>:....<verba
0e80: 74 69 6d 3e 0d 0a 3e 3e 3e 20 64 20 3d 20 41 74 tim>..>>> d = At
0e90: 74 72 69 62 75 74 65 64 44 69 63 74 28 29 0d 0a tributedDict()..
0ea0: 3e 3e 3e 20 64 0d 0a 7b 7d 0d 0a 3e 3e 3e 20 64 >>> d..{}..>>> d
0eb0: 2e 66 6f 6f 20 3d 20 31 0d 0a 3e 3e 3e 20 64 2e .foo = 1..>>> d.
0ec0: 66 6f 6f 5f 20 3d 20 34 32 0d 0a 3e 3e 3e 20 64 foo_ = 42..>>> d
0ed0: 2e 66 6f 6f 5f 2c 20 64 5b 27 66 6f 6f 27 5d 2c .foo_, d['foo'],
0ee0: 20 64 2e 66 6f 6f 0d 0a 28 34 32 2c 20 34 32 2c d.foo..(42, 42,
0ef0: 20 31 29 0d 0a 3e 3e 3e 20 64 0d 0a 7b 75 27 66 1)..>>> d..{u'f
0f00: 6f 6f 27 3a 20 34 32 7d 0d 0a 3e 3e 3e 20 64 65 oo': 42}..>>> de
0f10: 6c 20 64 2e 66 6f 6f 5f 0d 0a 3e 3e 3e 20 64 0d l d.foo_..>>> d.
0f20: 0a 7b 7d 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e .{}..</verbatim>
0f30: 0d 0a 0d 0a 41 64 64 69 6e 67 20 74 61 62 2d 63 ....Adding tab-c
0f40: 6f 6d 70 6c 65 74 69 6f 6e 20 6f 6e 20 75 6e 64 ompletion on und
0f50: 65 72 73 63 6f 64 65 64 20 61 74 74 72 69 62 75 erscoded attribu
0f60: 74 65 73 20 74 6f 20 74 68 69 73 20 73 69 6d 70 tes to this simp
0f70: 6c 65 20 65 78 61 6d 70 6c 65 20 69 73 20 61 73 le example is as
0f80: 0d 0a 65 61 73 79 20 61 73 20 61 70 70 6c 79 69 ..easy as applyi
0f90: 6e 67 20 73 6f 6d 65 20 72 65 61 64 79 2d 74 6f ng some ready-to
0fa0: 2d 75 73 65 20 64 65 63 6f 72 61 74 6f 72 73 20 -use decorators
0fb0: 6f 6e 20 74 68 65 20 6d 65 74 68 6f 64 73 20 75 on the methods u
0fc0: 73 65 64 20 61 73 20 61 72 67 75 6d 65 6e 74 73 sed as arguments
0fd0: 0d 0a 74 6f 20 3c 63 6f 64 65 3e 70 72 6f 78 79 ..to <code>proxy
0fe0: 5f 6d 65 74 68 6f 64 3c 2f 63 6f 64 65 3e 2e 20 _method</code>.
0ff0: 20 53 65 65 20 74 68 65 20 64 6f 63 75 6d 65 6e See the documen
1000: 74 61 74 69 6f 6e 20 6f 66 0d 0a 74 68 65 20 3c tation of..the <
1010: 63 6f 64 65 3e 75 6e 64 65 72 73 63 6f 64 65 2e code>underscode.
1020: 64 65 63 6f 72 61 74 6f 72 73 3c 2f 63 6f 64 65 decorators</code
1030: 3e 20 6d 6f 64 75 6c 65 20 66 6f 72 20 6d 6f 72 > module for mor
1040: 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 6e e information an
1050: 64 0d 0a 65 78 61 6d 70 6c 65 73 2e 0d 0a 0d 0a d..examples.....
1060: 3c 68 32 3e 50 79 74 68 6f 6e 20 63 6f 64 65 63 <h2>Python codec
1070: 20 41 50 49 20 73 75 70 70 6f 72 74 3c 2f 68 32 API support</h2
1080: 3e 0d 0a 0d 0a 53 69 6e 63 65 20 74 68 65 20 55 >....Since the U
1090: 6e 64 65 72 73 63 6f 64 65 20 70 61 63 6b 61 67 nderscode packag
10a0: 65 20 69 73 20 63 6f 6d 70 6c 69 61 6e 74 20 77 e is compliant w
10b0: 69 74 68 20 74 68 65 20 73 74 61 6e 64 61 72 64 ith the standard
10c0: 20 50 79 74 68 6f 6e 20 63 6f 64 65 63 0d 0a 41 Python codec..A
10d0: 50 49 2c 20 79 6f 75 20 63 61 6e 20 75 73 65 20 PI, you can use
10e0: 55 6e 64 65 72 73 63 6f 64 65 20 74 6f 20 65 6e Underscode to en
10f0: 63 6f 64 65 20 61 6e 64 20 64 65 63 6f 64 65 20 code and decode
1100: 73 74 72 69 6e 67 73 20 77 69 74 68 20 74 68 65 strings with the
1110: 20 75 73 75 61 6c 0d 0a 3c 63 6f 64 65 3e 75 6e usual..<code>un
1120: 69 63 6f 64 65 2e 65 6e 63 6f 64 65 28 29 3c 2f icode.encode()</
1130: 63 6f 64 65 3e 20 61 6e 64 20 3c 63 6f 64 65 3e code> and <code>
1140: 73 74 72 2e 64 65 63 6f 64 65 28 29 3c 2f 63 6f str.decode()</co
1150: 64 65 3e 20 63 61 6c 6c 73 20 61 74 20 61 6e 79 de> calls at any
1160: 20 74 69 6d 65 0d 0a 6a 75 73 74 20 62 79 20 69 time..just by i
1170: 6d 70 6f 72 74 69 6e 67 20 74 68 65 20 3c 63 6f mporting the <co
1180: 64 65 3e 75 6e 64 65 72 73 63 6f 64 65 2e 63 6f de>underscode.co
1190: 64 65 63 3c 2f 63 6f 64 65 3e 20 73 75 62 70 61 dec</code> subpa
11a0: 63 6b 61 67 65 20 28 69 74 20 69 73 20 6e 6f 74 ckage (it is not
11b0: 0d 0a 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 20 ..automatically
11c0: 69 6d 70 6f 72 74 65 64 20 62 79 20 74 68 65 20 imported by the
11d0: 6d 61 69 6e 20 3c 63 6f 64 65 3e 75 6e 64 65 72 main <code>under
11e0: 73 63 6f 64 65 3c 2f 63 6f 64 65 3e 20 70 61 63 scode</code> pac
11f0: 6b 61 67 65 29 3a 0d 0a 0d 0a 3c 76 65 72 62 61 kage):....<verba
1200: 74 69 6d 3e 0d 0a 3e 3e 3e 20 69 6d 70 6f 72 74 tim>..>>> import
1210: 20 75 6e 64 65 72 73 63 6f 64 65 2e 63 6f 64 65 underscode.code
1220: 63 0d 0a 3e 3e 3e 20 70 72 69 6e 74 20 75 27 74 c..>>> print u't
1230: 68 69 73 20 69 73 20 5c 75 32 30 31 63 61 20 74 his is \u201ca t
1240: 65 73 74 5c 75 32 30 31 64 27 0d 0a 74 68 69 73 est\u201d'..this
1250: 20 69 73 20 e2 80 9c 61 20 74 65 73 74 e2 80 9d is ...a test...
1260: 0d 0a 3e 3e 3e 20 75 27 74 68 69 73 20 69 73 20 ..>>> u'this is
1270: 5c 75 32 30 31 63 61 20 74 65 73 74 5c 75 32 30 \u201ca test\u20
1280: 31 64 27 2e 65 6e 63 6f 64 65 28 27 75 6e 64 65 1d'.encode('unde
1290: 72 73 63 6f 64 65 27 29 0d 0a 27 74 68 69 73 5f rscode')..'this_
12a0: 5f 69 73 5f 5f 5f 75 32 30 31 63 61 5f 5f 74 65 _is___u201ca__te
12b0: 73 74 5f 75 32 30 31 64 5f 27 0d 0a 3e 3e 3e 20 st_u201d_'..>>>
12c0: 27 74 68 69 73 5f 5f 69 73 5f 5f 5f 75 32 30 31 'this__is___u201
12d0: 63 61 5f 5f 74 65 73 74 5f 75 32 30 31 64 5f 27 ca__test_u201d_'
12e0: 2e 64 65 63 6f 64 65 28 27 75 6e 64 65 72 73 63 .decode('undersc
12f0: 6f 64 65 27 29 0d 0a 75 27 74 68 69 73 20 69 73 ode')..u'this is
1300: 20 5c 75 32 30 31 63 61 20 74 65 73 74 5c 75 32 \u201ca test\u2
1310: 30 31 64 27 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 01d'..</verbatim
1320: 3e 0d 0a 0d 0a 0d 0a 3c 68 32 3e 47 65 74 74 69 >......<h2>Getti
1330: 6e 67 20 55 6e 64 65 72 73 63 6f 64 65 3c 2f 68 ng Underscode</h
1340: 32 3e 0d 0a 0d 0a 59 6f 75 20 63 61 6e 20 64 6f 2>....You can do
1350: 77 6e 6c 6f 61 64 20 74 68 65 20 73 6f 75 72 63 wnload the sourc
1360: 65 20 63 6f 64 65 20 64 69 73 74 72 69 62 75 74 e code distribut
1370: 69 6f 6e 20 6f 66 20 55 6e 64 65 72 73 63 6f 64 ion of Underscod
1380: 65 20 66 72 6f 6d 20 74 68 65 0d 0a 50 79 74 68 e from the..Pyth
1390: 6f 6e 20 50 61 63 6b 61 67 65 20 49 6e 64 65 78 on Package Index
13a0: 20 61 74 20 5b 68 74 74 70 3a 2f 2f 70 79 70 69 at [http://pypi
13b0: 2e 70 79 74 68 6f 6e 2e 6f 72 67 2f 5d 2e 20 20 .python.org/].
13c0: 49 74 20 75 73 65 73 20 74 68 65 20 73 74 61 6e It uses the stan
13d0: 64 61 72 64 0d 0a 3c 63 6f 64 65 3e 73 65 74 75 dard..<code>setu
13e0: 70 2e 70 79 3c 2f 63 6f 64 65 3e 20 6d 65 74 68 p.py</code> meth
13f0: 6f 64 20 66 6f 72 20 69 6e 73 74 61 6c 6c 61 74 od for installat
1400: 69 6f 6e 2c 20 72 75 6e 73 20 6f 6e 20 61 6e 79 ion, runs on any
1410: 20 70 6c 61 74 66 6f 72 6d 20 61 6e 64 20 68 61 platform and ha
1420: 73 20 6e 6f 0d 0a 61 64 64 69 74 69 6f 6e 61 6c s no..additional
1430: 20 64 65 70 65 6e 64 65 6e 63 69 65 73 20 62 75 dependencies bu
1440: 74 20 50 79 74 68 6f 6e 20 76 65 72 73 69 6f 6e t Python version
1450: 20 32 2e 34 20 6f 72 20 67 72 65 61 74 65 72 2e 2.4 or greater.
1460: 0d 0a 0d 0a 59 6f 75 20 6d 61 79 20 61 6c 73 6f ....You may also
1470: 20 62 65 20 69 6e 74 65 72 65 73 74 65 64 20 69 be interested i
1480: 6e 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 65 20 n following the
1490: 64 65 76 65 6c 6f 70 6d 65 6e 74 20 6f 66 20 55 development of U
14a0: 6e 64 65 72 73 63 6f 64 65 3b 20 79 6f 75 20 63 nderscode; you c
14b0: 61 6e 0d 0a 6d 61 6b 65 20 61 20 63 6c 6f 6e 65 an..make a clone
14c0: 20 6f 66 20 69 74 73 20 5b 68 74 74 70 3a 2f 2f of its [http://
14d0: 77 77 77 2e 66 6f 73 73 69 6c 2d 73 63 6d 2e 6f www.fossil-scm.o
14e0: 72 67 2f 7c 46 6f 73 73 69 6c 5d 20 72 65 70 6f rg/|Fossil] repo
14f0: 73 69 74 6f 72 79 20 61 6e 64 0d 0a 63 68 65 63 sitory and..chec
1500: 6b 6f 75 74 20 69 74 20 77 69 74 68 3a 3a 0d 0a kout it with::..
1510: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 24 20 ..<verbatim>..$
1520: 66 6f 73 73 69 6c 20 63 6c 6f 6e 65 20 68 74 74 fossil clone htt
1530: 70 73 3a 2f 2f 65 6c 76 69 6c 2e 6e 65 74 2f 66 ps://elvil.net/f
1540: 6f 73 73 69 6c 2f 75 6e 64 65 72 73 63 6f 64 65 ossil/underscode
1550: 2f 20 75 6e 64 65 72 73 63 6f 64 65 2e 66 6f 73 / underscode.fos
1560: 73 69 6c 0d 0a 24 20 6d 6b 64 69 72 20 75 6e 64 sil..$ mkdir und
1570: 65 72 73 63 6f 64 65 20 26 26 20 63 64 20 75 6e erscode && cd un
1580: 64 65 72 73 63 6f 64 65 0d 0a 24 20 66 6f 73 73 derscode..$ foss
1590: 69 6c 20 6f 70 65 6e 20 2e 2e 2f 75 6e 64 65 72 il open ../under
15a0: 73 63 6f 64 65 2e 66 6f 73 73 69 6c 0d 0a 3c 2f scode.fossil..</
15b0: 76 65 72 62 61 74 69 6d 3e 0d 0a 0d 0a 0d 0a 3c verbatim>......<
15c0: 68 32 3e 48 65 6c 70 69 6e 67 20 55 6e 64 65 72 h2>Helping Under
15d0: 73 63 6f 64 65 3c 2f 68 32 3e 0d 0a 0d 0a 54 68 scode</h2>....Th
15e0: 65 72 65 20 69 73 20 61 20 64 69 73 63 75 73 73 ere is a discuss
15f0: 69 6f 6e 20 67 72 6f 75 70 20 66 6f 72 20 55 6e ion group for Un
1600: 64 65 72 73 63 6f 64 65 20 61 74 20 47 6f 6f 67 derscode at Goog
1610: 6c 65 20 47 72 6f 75 70 73 3a 0d 0a 5b 68 74 74 le Groups:..[htt
1620: 70 3a 2f 2f 67 72 6f 75 70 73 2e 67 6f 6f 67 6c p://groups.googl
1630: 65 2e 63 6f 6d 2f 67 72 6f 75 70 2f 75 6e 64 65 e.com/group/unde
1640: 72 73 63 6f 64 65 5d 0d 0a 0d 0a 49 74 20 77 6f rscode]....It wo
1650: 75 6c 64 20 62 65 20 67 72 65 61 74 20 74 6f 20 uld be great to
1660: 64 69 73 63 75 73 73 20 79 6f 75 72 20 6f 70 69 discuss your opi
1670: 6e 69 6f 6e 73 20 61 6e 64 20 66 65 65 6c 69 6e nions and feelin
1680: 67 73 20 6f 6e 20 55 6e 64 65 72 73 63 6f 64 65 gs on Underscode
1690: 20 69 6e 20 74 68 65 0d 0a 67 72 6f 75 70 2c 20 in the..group,
16a0: 74 6f 20 6b 6e 6f 77 20 68 6f 77 20 79 6f 75 20 to know how you
16b0: 75 73 65 64 20 69 74 20 69 6e 20 79 6f 75 72 20 used it in your
16c0: 70 72 6f 6a 65 63 74 2c 20 61 6e 64 20 74 6f 20 project, and to
16d0: 68 65 6c 70 20 73 6f 6c 76 69 6e 67 20 79 6f 75 help solving you
16e0: 72 73 20 61 6e 64 0d 0a 6f 74 68 65 72 73 27 20 rs and..others'
16f0: 70 72 6f 62 6c 65 6d 73 20 74 68 65 72 65 21 20 problems there!
1700: 20 49 66 20 79 6f 75 20 63 6f 6d 65 20 61 63 72 If you come acr
1710: 6f 73 73 20 61 20 62 75 67 20 6f 72 20 79 6f 75 oss a bug or you
1720: 20 68 61 76 65 20 73 6f 6d 65 20 65 6e 68 61 6e have some enhan
1730: 63 65 6d 65 6e 74 0d 0a 70 72 6f 70 6f 73 61 6c cement..proposal
1740: 2c 20 79 6f 75 27 72 65 20 65 6e 63 6f 75 72 61 , you're encoura
1750: 67 65 64 20 74 6f 20 77 72 69 74 65 20 74 6f 20 ged to write to
1760: 74 68 65 20 67 72 6f 75 70 20 6f 72 20 63 72 65 the group or cre
1770: 61 74 65 20 61 20 74 69 63 6b 65 74 20 61 74 0d ate a ticket at.
1780: 0a 5b 68 74 74 70 73 3a 2f 2f 65 6c 76 69 6c 2e .[https://elvil.
1790: 6e 65 74 2f 66 6f 73 73 69 6c 2f 75 6e 64 65 72 net/fossil/under
17a0: 73 63 6f 64 65 2f 5d 0d 0a 0a 5a 20 35 31 31 34 scode/]...Z 5114
17b0: 62 65 63 33 64 37 64 39 64 34 36 39 38 37 37 62 bec3d7d9d469877b
17c0: 32 34 32 63 33 39 33 33 66 31 31 35 0a 242c3933f115.