Artifact 5d4534e9ddfe353bc2a37d56ccd8eacf6ac83f56:
Wiki page
[
Underscode] by
ivan
2012-04-10 16:04:45.
0000: 44 20 32 30 31 32 2d 30 34 2d 31 30 54 31 36 3a D 2012-04-10T16:
0010: 30 34 3a 34 35 0a 4c 20 55 6e 64 65 72 73 63 6f 04:45.L Undersco
0020: 64 65 0a 50 20 62 63 64 36 34 34 65 65 61 30 34 de.P bcd644eea04
0030: 33 33 65 62 35 39 36 34 36 34 30 36 66 61 30 63 33eb59646406fa0c
0040: 62 36 33 30 36 33 38 31 37 37 34 62 39 0a 55 20 b6306381774b9.U
0050: 69 76 61 6e 0a 57 20 35 38 35 30 0a 3c 68 31 3e ivan.W 5850.<h1>
0060: 55 6e 64 65 72 73 63 6f 64 65 2c 20 61 20 50 79 Underscode, a Py
0070: 74 68 6f 6e 20 69 64 65 6e 74 69 66 69 65 72 2d thon identifier-
0080: 6c 69 6b 65 20 65 6e 63 6f 64 69 6e 67 3c 2f 68 like encoding</h
0090: 31 3e 0d 0a 0d 0a 3c 64 6c 3e 0d 0a 3c 64 74 3e 1>....<dl>..<dt>
00a0: 41 75 74 68 6f 72 3c 64 64 3e 3c 61 20 68 72 65 Author<dd><a hre
00b0: 66 3d 22 6d 61 69 6c 74 6f 3a 69 76 61 6e 26 23 f="mailto:ivan&#
00c0: 36 34 3b 73 65 6c 69 64 6f 72 2e 6e 65 74 22 3e 64;selidor.net">
00d0: 49 76 61 6e 20 56 69 6c 61 74 61 20 69 20 42 61 Ivan Vilata i Ba
00e0: 6c 61 67 75 65 72 3c 2f 61 3e 0d 0a 3c 64 74 3e laguer</a>..<dt>
00f0: 55 52 4c 3c 64 64 3e 5b 68 74 74 70 73 3a 2f 2f URL<dd>[https://
0100: 65 6c 76 69 6c 2e 6e 65 74 2f 66 6f 73 73 69 6c elvil.net/fossil
0110: 2f 75 6e 64 65 72 73 63 6f 64 65 2f 5d 0d 0a 3c /underscode/]..<
0120: 2f 64 6c 3e 0d 0a 0d 0a 0d 0a 3c 68 32 3e 41 62 /dl>......<h2>Ab
0130: 6f 75 74 20 55 6e 64 65 72 73 63 6f 64 65 3c 2f out Underscode</
0140: 68 32 3e 0d 0a 0d 0a 5b 68 74 74 70 73 3a 2f 2f h2>....[https://
0150: 65 6c 76 69 6c 2e 6e 65 74 2f 66 6f 73 73 69 6c elvil.net/fossil
0160: 2f 75 6e 64 65 72 73 63 6f 64 65 2f 7c 55 6e 64 /underscode/|Und
0170: 65 72 73 63 6f 64 65 5d 20 69 73 20 61 6e 20 65 erscode] is an e
0180: 6e 63 6f 64 69 6e 67 20 77 68 69 63 68 20 69 73 ncoding which is
0190: 0d 0a 63 61 70 61 62 6c 65 20 6f 66 20 72 65 70 ..capable of rep
01a0: 72 65 73 65 6e 74 69 6e 67 20 3c 65 6d 3e 61 6e resenting <em>an
01b0: 79 3c 2f 65 6d 3e 20 55 6e 69 63 6f 64 65 20 73 y</em> Unicode s
01c0: 74 72 69 6e 67 20 61 73 20 61 20 76 61 6c 69 64 tring as a valid
01d0: 20 28 61 6e 64 20 71 75 69 74 65 0d 0a 73 69 6d (and quite..sim
01e0: 69 6c 61 72 29 20 50 79 74 68 6f 6e 20 69 64 65 ilar) Python ide
01f0: 6e 74 69 66 69 65 72 2e 20 20 54 68 65 20 77 61 ntifier. The wa
0200: 79 20 55 6e 69 63 6f 64 65 20 73 74 72 69 6e 67 y Unicode string
0210: 73 20 61 72 65 20 65 6e 63 6f 64 65 64 20 6d 69 s are encoded mi
0220: 6e 69 6d 69 73 65 73 20 74 68 65 0d 0a 63 68 61 nimises the..cha
0230: 6e 63 65 73 20 6f 66 20 63 6c 61 73 68 69 6e 67 nces of clashing
0240: 20 77 69 74 68 20 6f 74 68 65 72 20 65 78 69 73 with other exis
0250: 74 69 6e 67 20 6e 61 6d 65 73 2c 20 77 68 69 6c ting names, whil
0260: 65 20 6e 6f 74 20 6f 62 73 63 75 72 69 6e 67 20 e not obscuring
0270: 74 68 65 0d 0a 72 65 73 75 6c 74 69 6e 67 20 73 the..resulting s
0280: 74 72 69 6e 67 20 74 6f 6f 20 6d 75 63 68 2e 0d tring too much..
0290: 0a 0d 0a 53 6f 6d 65 20 6d 65 74 68 6f 64 20 64 ...Some method d
02a0: 65 63 6f 72 61 74 6f 72 73 20 61 72 65 20 70 72 ecorators are pr
02b0: 6f 76 69 64 65 64 20 77 68 69 63 68 20 61 6c 6c ovided which all
02c0: 6f 77 20 61 72 62 69 74 72 61 72 79 20 6f 62 6a ow arbitrary obj
02d0: 65 63 74 73 20 74 6f 20 62 65 0d 0a 61 63 63 65 ects to be..acce
02e0: 73 73 65 64 20 61 73 20 6e 6f 72 6d 61 6c 20 69 ssed as normal i
02f0: 6e 73 74 61 6e 63 65 20 61 74 74 72 69 62 75 74 nstance attribut
0300: 65 73 2c 20 77 69 74 68 20 6f 70 74 69 6f 6e 61 es, with optiona
0310: 6c 20 74 61 62 2d 63 6f 6d 70 6c 65 74 69 6f 6e l tab-completion
0320: 20 73 75 70 70 6f 72 74 0d 0a 66 6f 72 20 69 6e support..for in
0330: 74 65 72 61 63 74 69 76 65 20 75 73 61 67 65 2e teractive usage.
0340: 20 20 54 68 65 20 73 74 61 6e 64 61 72 64 20 50 The standard P
0350: 79 74 68 6f 6e 20 63 6f 64 65 63 20 41 50 49 20 ython codec API
0360: 69 73 20 61 6c 73 6f 20 73 75 70 70 6f 72 74 65 is also supporte
0370: 64 2e 0d 0a 0d 0a 55 6e 64 65 72 73 63 6f 64 65 d.....Underscode
0380: 2d 65 6e 63 6f 64 65 64 20 28 6f 72 20 3c 65 6d -encoded (or <em
0390: 3e 75 6e 64 65 72 73 63 6f 64 65 64 3c 2f 65 6d >underscoded</em
03a0: 3e 29 20 73 74 72 69 6e 67 73 20 63 61 6e 20 62 >) strings can b
03b0: 65 20 71 75 69 63 6b 6c 79 20 73 70 6f 74 74 65 e quickly spotte
03c0: 64 0d 0a 62 65 63 61 75 73 65 20 74 68 65 79 20 d..because they
03d0: 65 6e 64 20 77 69 74 68 20 61 6e 20 3c 65 6d 3e end with an <em>
03e0: 6f 64 64 3c 2f 65 6d 3e 20 6e 75 6d 62 65 72 20 odd</em> number
03f0: 6f 66 20 75 6e 64 65 72 73 63 6f 72 65 73 2c 20 of underscores,
0400: 61 6e 64 20 74 68 65 79 20 63 6f 6e 74 61 69 6e and they contain
0410: 0d 0a 65 73 63 61 70 65 20 73 65 71 75 65 6e 63 ..escape sequenc
0420: 65 73 20 62 65 67 69 6e 6e 69 6e 67 20 77 69 74 es beginning wit
0430: 68 20 61 6e 20 75 6e 64 65 72 73 63 6f 72 65 20 h an underscore
0440: 77 68 65 72 65 20 63 68 61 72 61 63 74 65 72 73 where characters
0450: 20 6e 6f 74 20 61 6c 6c 6f 77 65 64 20 69 6e 0d not allowed in.
0460: 0a 69 64 65 6e 74 69 66 69 65 72 73 20 77 6f 75 .identifiers wou
0470: 6c 64 20 62 65 20 66 6f 75 6e 64 2e 20 20 53 6f ld be found. So
0480: 6d 65 20 65 78 61 6d 70 6c 65 73 20 6f 66 20 75 me examples of u
0490: 6e 64 65 72 73 63 6f 64 65 64 20 73 74 72 69 6e nderscoded strin
04a0: 67 73 20 61 72 65 3a 0d 0a 0d 0a 3c 75 6c 3e 0d gs are:....<ul>.
04b0: 0a 3c 6c 69 3e 3c 63 6f 64 65 3e 5f 3c 2f 63 6f .<li><code>_</co
04c0: 64 65 3e 20 65 6e 63 6f 64 65 73 20 74 68 65 20 de> encodes the
04d0: 65 6d 70 74 79 20 73 74 72 69 6e 67 2e 0d 0a 3c empty string...<
04e0: 6c 69 3e 3c 63 6f 64 65 3e 66 6f 6f 5f 3c 2f 63 li><code>foo_</c
04f0: 6f 64 65 3e 20 65 6e 63 6f 64 65 73 20 3c 63 6f ode> encodes <co
0500: 64 65 3e 66 6f 6f 3c 2f 63 6f 64 65 3e 2e 0d 0a de>foo</code>...
0510: 3c 6c 69 3e 3c 63 6f 64 65 3e 63 6c 61 73 73 5f <li><code>class_
0520: 3c 2f 63 6f 64 65 3e 20 65 6e 63 6f 64 65 73 20 </code> encodes
0530: 3c 63 6f 64 65 3e 63 6c 61 73 73 3c 2f 63 6f 64 <code>class</cod
0540: 65 3e 2e 0d 0a 3c 6c 69 3e 3c 63 6f 64 65 3e 66 e>...<li><code>f
0550: 6f 6f 5f 5f 62 61 72 5f 3c 2f 63 6f 64 65 3e 20 oo__bar_</code>
0560: 65 6e 63 6f 64 65 73 20 3c 63 6f 64 65 3e 66 6f encodes <code>fo
0570: 6f 20 62 61 72 3c 2f 63 6f 64 65 3e 2e 0d 0a 3c o bar</code>...<
0580: 6c 69 3e 3c 63 6f 64 65 3e 66 6f 6f 5f 78 35 66 li><code>foo_x5f
0590: 62 61 72 5f 3c 2f 63 6f 64 65 3e 20 65 6e 63 6f bar_</code> enco
05a0: 64 65 73 20 3c 63 6f 64 65 3e 66 6f 6f 5f 62 61 des <code>foo_ba
05b0: 72 3c 2f 63 6f 64 65 3e 2e 0d 0a 3c 6c 69 3e 3c r</code>...<li><
05c0: 63 6f 64 65 3e 5f 32 30 30 36 5f 30 39 5f 31 38 code>_2006_09_18
05d0: 5f 3c 2f 63 6f 64 65 3e 2c 20 6c 69 6b 65 20 3c _</code>, like <
05e0: 63 6f 64 65 3e 5f 32 30 30 36 30 39 31 38 5f 3c code>_20060918_<
05f0: 2f 63 6f 64 65 3e 2c 20 65 6e 63 6f 64 65 73 20 /code>, encodes
0600: 3c 63 6f 64 65 3e 32 30 30 36 30 39 31 38 3c 2f <code>20060918</
0610: 63 6f 64 65 3e 2e 0d 0a 3c 6c 69 3e 3c 63 6f 64 code>...<li><cod
0620: 65 3e 5f 78 32 66 62 69 6e 5f 78 32 66 6c 73 5f e>_x2fbin_x2fls_
0630: 3c 2f 63 6f 64 65 3e 2c 20 65 6e 63 6f 64 65 73 </code>, encodes
0640: 20 3c 63 6f 64 65 3e 2f 62 69 6e 2f 6c 73 3c 2f <code>/bin/ls</
0650: 63 6f 64 65 3e 2e 0d 0a 3c 6c 69 3e 3c 63 6f 64 code>...<li><cod
0660: 65 3e 54 68 65 5f 5f 4b 6e 69 67 68 74 73 5f 5f e>The__Knights__
0670: 57 68 6f 5f 5f 53 61 79 5f 5f 5f 75 32 30 31 63 Who__Say___u201c
0680: 4e 69 5f 78 32 31 5f 75 32 30 31 64 5f 3c 2f 63 Ni_x21_u201d_</c
0690: 6f 64 65 3e 20 65 6e 63 6f 64 65 73 20 74 68 65 ode> encodes the
06a0: 20 70 72 6f 70 65 72 6c 79 20 71 75 6f 74 65 64 properly quoted
06b0: 20 3c 63 6f 64 65 3e 54 68 65 20 4b 6e 69 67 68 <code>The Knigh
06c0: 74 73 20 57 68 6f 20 53 61 79 20 e2 80 9c 4e 69 ts Who Say ...Ni
06d0: 21 e2 80 9d 3c 2f 63 6f 64 65 3e 2e 0d 0a 3c 2f !...</code>...</
06e0: 75 6c 3e 0d 0a 0d 0a 41 73 20 79 6f 75 20 73 65 ul>....As you se
06f0: 65 2c 20 75 6e 64 65 72 73 63 6f 64 65 64 20 73 e, underscoded s
0700: 74 72 69 6e 67 73 20 61 72 65 20 71 75 69 74 65 trings are quite
0710: 20 73 69 6d 69 6c 61 72 20 74 6f 20 74 68 65 69 similar to thei
0720: 72 20 64 65 63 6f 64 65 64 0d 0a 63 6f 75 6e 74 r decoded..count
0730: 65 72 70 61 72 74 73 20 77 68 65 6e 20 74 68 65 erparts when the
0740: 73 65 20 61 72 65 20 6d 6f 72 65 20 6f 72 20 6c se are more or l
0750: 65 73 73 20 69 64 65 6e 74 69 66 69 65 72 2d 6c ess identifier-l
0760: 69 6b 65 2c 20 62 75 74 20 63 6f 6d 70 6c 65 78 ike, but complex
0770: 20 73 74 72 69 6e 67 73 0d 0a 63 61 6e 20 73 74 strings..can st
0780: 69 6c 6c 20 62 65 20 68 61 6e 64 6c 65 64 2e 0d ill be handled..
0790: 0a 0d 0a 55 6e 64 65 72 73 63 6f 64 65 20 69 73 ...Underscode is
07a0: 20 61 20 76 65 72 79 20 62 61 73 69 63 20 74 6f a very basic to
07b0: 6f 6c 20 77 68 69 63 68 20 6d 61 79 20 68 61 76 ol which may hav
07c0: 65 20 73 65 76 65 72 61 6c 20 75 73 65 73 3a 0d e several uses:.
07d0: 0a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 41 76 6f ...<ul>..<li>Avo
07e0: 69 64 69 6e 67 20 63 6c 61 73 68 65 73 20 62 65 iding clashes be
07f0: 74 77 65 65 6e 20 6d 65 74 68 6f 64 20 6e 61 6d tween method nam
0800: 65 73 20 61 6e 64 20 74 61 62 6c 65 20 66 69 65 es and table fie
0810: 6c 64 20 6e 61 6d 65 73 20 69 6e 20 4f 52 4d 73 ld names in ORMs
0820: 2e 0d 0a 3c 6c 69 3e 45 6e 61 62 6c 69 6e 67 20 ...<li>Enabling
0830: 69 6e 74 65 72 61 63 74 69 76 65 20 61 74 74 72 interactive attr
0840: 69 62 75 74 65 2d 6c 69 6b 65 20 63 6f 6d 70 6c ibute-like compl
0850: 65 74 69 6f 6e 20 66 6f 72 20 63 68 69 6c 64 72 etion for childr
0860: 65 6e 20 69 6e 0d 0a 68 69 65 72 61 72 63 68 69 en in..hierarchi
0870: 63 61 6c 6c 79 20 61 72 72 61 6e 67 65 64 20 73 cally arranged s
0880: 74 72 75 63 74 75 72 65 73 20 28 44 4f 4d 20 74 tructures (DOM t
0890: 72 65 65 73 2c 20 66 69 6c 65 73 79 73 74 65 6d rees, filesystem
08a0: 73 2e 2e 2e 29 2c 20 77 69 74 68 20 66 75 6c 6c s...), with full
08b0: 0d 0a 55 6e 69 63 6f 64 65 20 73 75 70 70 6f 72 ..Unicode suppor
08c0: 74 2e 0d 0a 3c 6c 69 3e 41 73 20 61 6e 20 61 69 t...<li>As an ai
08d0: 64 20 69 6e 20 74 68 65 20 67 65 6e 65 72 61 74 d in the generat
08e0: 69 6f 6e 20 6f 66 20 52 50 43 20 73 74 75 62 73 ion of RPC stubs
08f0: 20 66 6f 72 20 69 64 65 6e 74 69 66 69 65 72 73 for identifiers
0900: 20 77 68 69 63 68 20 61 72 65 20 6e 6f 74 0d 0a which are not..
0910: 61 6c 6c 6f 77 65 64 20 62 79 20 50 79 74 68 6f allowed by Pytho
0920: 6e 2e 0d 0a 3c 6c 69 3e 43 6f 6d 70 75 74 69 6e n...<li>Computin
0930: 67 20 75 6e 69 71 75 65 20 49 44 73 20 66 6f 72 g unique IDs for
0940: 20 73 65 63 74 69 6f 6e 73 20 69 6e 20 61 75 74 sections in aut
0950: 6f 6d 61 74 69 63 61 6c 6c 79 20 67 65 6e 65 72 omatically gener
0960: 61 74 65 64 20 58 4d 4c 20 6f 72 20 48 54 4d 4c ated XML or HTML
0970: 0d 0a 64 6f 63 75 6d 65 6e 74 73 2e 0d 0a 3c 6c ..documents...<l
0980: 69 3e 4e 61 6d 69 6e 67 20 70 61 67 65 20 68 61 i>Naming page ha
0990: 6e 64 6c 65 72 73 20 66 6f 72 20 77 65 62 20 73 ndlers for web s
09a0: 65 72 76 65 72 20 66 72 61 6d 65 77 6f 72 6b 73 erver frameworks
09b0: 20 6c 69 6b 65 20 43 68 65 72 72 79 50 79 2e 0d like CherryPy..
09c0: 0a 3c 6c 69 3e 2e 2e 2e 20 6a 75 73 74 20 75 73 .<li>... just us
09d0: 65 20 79 6f 75 72 20 69 6d 61 67 69 6e 61 74 69 e your imaginati
09e0: 6f 6e 21 0d 0a 3c 2f 75 6c 3e 0d 0a 0d 0a 54 68 on!..</ul>....Th
09f0: 65 20 55 6e 64 65 72 73 63 6f 64 65 20 70 61 63 e Underscode pac
0a00: 6b 61 67 65 20 69 73 20 72 65 6c 65 61 73 65 64 kage is released
0a10: 20 75 6e 64 65 72 20 74 68 65 20 47 4e 55 20 4c under the GNU L
0a20: 65 73 73 65 72 20 47 65 6e 65 72 61 6c 20 50 75 esser General Pu
0a30: 62 6c 69 63 20 4c 69 63 65 6e 73 65 0d 0a 28 4c blic License..(L
0a40: 47 50 4c 29 20 76 65 72 73 69 6f 6e 20 33 20 6f GPL) version 3 o
0a50: 72 20 6c 61 74 65 72 20 28 73 65 65 20 5b 68 74 r later (see [ht
0a60: 74 70 3a 2f 2f 77 77 77 2e 67 6e 75 2e 6f 72 67 tp://www.gnu.org
0a70: 2f 6c 69 63 65 6e 73 65 73 2f 5d 29 2e 0d 0a 0d /licenses/])....
0a80: 0a 3c 68 32 3e 55 6e 64 65 72 73 63 6f 64 65 64 .<h2>Underscoded
0a90: 20 73 74 72 69 6e 67 73 20 61 73 20 61 74 74 72 strings as attr
0aa0: 69 62 75 74 65 73 3c 2f 68 32 3e 0d 0a 0d 0a 55 ibutes</h2>....U
0ab0: 6e 64 65 72 73 63 6f 64 65 20 70 72 6f 76 69 64 nderscode provid
0ac0: 65 73 20 61 20 6d 6f 64 75 6c 65 20 77 69 74 68 es a module with
0ad0: 20 64 65 63 6f 72 61 74 6f 72 73 20 74 68 61 74 decorators that
0ae0: 20 61 6c 6c 6f 77 20 79 6f 75 20 74 6f 20 75 73 allow you to us
0af0: 65 20 70 6c 61 69 6e 0d 0a 61 74 74 72 69 62 75 e plain..attribu
0b00: 74 65 20 61 63 63 65 73 73 20 61 73 20 61 20 66 te access as a f
0b10: 6c 65 78 69 62 6c 65 20 77 61 79 20 6f 66 20 61 lexible way of a
0b20: 63 63 65 73 73 69 6e 67 20 61 6c 6c 20 6b 69 6e ccessing all kin
0b30: 64 73 20 6f 66 20 22 63 68 69 6c 64 20 6f 62 6a ds of "child obj
0b40: 65 63 74 73 22 0d 0a 77 69 74 68 6f 75 74 20 70 ects"..without p
0b50: 6f 6c 6c 75 74 69 6e 67 20 74 68 65 20 6e 6f 72 olluting the nor
0b60: 6d 61 6c 20 61 74 74 72 69 62 75 74 65 20 6e 61 mal attribute na
0b70: 6d 65 73 70 61 63 65 2c 20 61 6e 64 20 77 69 74 mespace, and wit
0b80: 68 20 6f 70 74 69 6f 6e 61 6c 0d 0a 69 6e 74 65 h optional..inte
0b90: 72 61 63 74 69 76 65 20 63 6f 6d 70 6c 65 74 69 ractive completi
0ba0: 6f 6e 20 69 66 20 79 6f 75 20 77 69 73 68 20 73 on if you wish s
0bb0: 6f 2e 20 20 46 6f 72 20 69 6e 73 74 61 6e 63 65 o. For instance
0bc0: 2c 20 79 6f 75 20 63 61 6e 20 6d 61 6b 65 20 74 , you can make t
0bd0: 68 65 0d 0a 28 73 74 72 69 6e 67 29 20 6b 65 79 he..(string) key
0be0: 73 20 6f 66 20 61 20 64 69 63 74 69 6f 6e 61 72 s of a dictionar
0bf0: 79 20 61 63 63 65 73 73 69 62 6c 65 20 61 73 20 y accessible as
0c00: 61 74 74 72 69 62 75 74 65 73 3a 0d 0a 0d 0a 3c attributes:....<
0c10: 76 65 72 62 61 74 69 6d 3e 0d 0a 66 72 6f 6d 20 verbatim>..from
0c20: 75 6e 64 65 72 73 63 6f 64 65 2e 64 65 63 6f 72 underscode.decor
0c30: 61 74 6f 72 73 20 69 6d 70 6f 72 74 20 70 72 6f ators import pro
0c40: 78 79 5f 6d 65 74 68 6f 64 0d 0a 0d 0a 63 6c 61 xy_method....cla
0c50: 73 73 20 41 74 74 72 69 62 75 74 65 64 44 69 63 ss AttributedDic
0c60: 74 28 64 69 63 74 29 3a 0d 0a 20 20 20 20 40 70 t(dict):.. @p
0c70: 72 6f 78 79 5f 6d 65 74 68 6f 64 28 64 69 63 74 roxy_method(dict
0c80: 2e 5f 5f 67 65 74 69 74 65 6d 5f 5f 29 0d 0a 20 .__getitem__)..
0c90: 20 20 20 64 65 66 20 5f 5f 67 65 74 61 74 74 72 def __getattr
0ca0: 5f 5f 28 73 65 6c 66 2c 20 6e 61 6d 65 29 3a 0d __(self, name):.
0cb0: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 . return
0cc0: 73 75 70 65 72 28 41 74 74 72 69 62 75 74 65 64 super(Attributed
0cd0: 44 69 63 74 2c 20 73 65 6c 66 29 2e 5f 5f 67 65 Dict, self).__ge
0ce0: 74 61 74 74 72 5f 5f 28 6e 61 6d 65 29 0d 0a 0d tattr__(name)...
0cf0: 0a 20 20 20 20 40 70 72 6f 78 79 5f 6d 65 74 68 . @proxy_meth
0d00: 6f 64 28 64 69 63 74 2e 5f 5f 73 65 74 69 74 65 od(dict.__setite
0d10: 6d 5f 5f 29 0d 0a 20 20 20 20 64 65 66 20 5f 5f m__).. def __
0d20: 73 65 74 61 74 74 72 5f 5f 28 73 65 6c 66 2c 20 setattr__(self,
0d30: 6e 61 6d 65 2c 20 76 61 6c 75 65 29 3a 0d 0a 20 name, value):..
0d40: 20 20 20 20 20 20 20 73 75 70 65 72 28 41 74 74 super(Att
0d50: 72 69 62 75 74 65 64 44 69 63 74 2c 20 73 65 6c ributedDict, sel
0d60: 66 29 2e 5f 5f 73 65 74 61 74 74 72 5f 5f 28 6e f).__setattr__(n
0d70: 61 6d 65 2c 20 76 61 6c 75 65 29 0d 0a 0d 0a 20 ame, value)....
0d80: 20 20 20 40 70 72 6f 78 79 5f 6d 65 74 68 6f 64 @proxy_method
0d90: 28 64 69 63 74 2e 5f 5f 64 65 6c 69 74 65 6d 5f (dict.__delitem_
0da0: 5f 29 0d 0a 20 20 20 20 64 65 66 20 5f 5f 64 65 _).. def __de
0db0: 6c 61 74 74 72 5f 5f 28 73 65 6c 66 2c 20 6e 61 lattr__(self, na
0dc0: 6d 65 29 3a 0d 0a 20 20 20 20 20 20 20 20 73 75 me):.. su
0dd0: 70 65 72 28 41 74 74 72 69 62 75 74 65 64 44 69 per(AttributedDi
0de0: 63 74 2c 20 73 65 6c 66 29 2e 5f 5f 64 65 6c 61 ct, self).__dela
0df0: 74 74 72 5f 5f 28 6e 61 6d 65 29 0d 0a 3c 2f 76 ttr__(name)..</v
0e00: 65 72 62 61 74 69 6d 3e 0d 0a 0d 0a 54 68 65 6e erbatim>....Then
0e10: 2c 20 61 63 63 65 73 73 20 74 6f 20 61 6e 20 61 , access to an a
0e20: 74 74 72 69 62 75 74 65 20 77 68 69 63 68 20 6c ttribute which l
0e30: 6f 6f 6b 73 20 6c 69 6b 65 20 61 6e 20 75 6e 64 ooks like an und
0e40: 65 72 73 63 6f 64 65 64 20 73 74 72 69 6e 67 20 erscoded string
0e50: 67 65 74 73 20 74 68 65 0d 0a 6e 61 6d 65 20 64 gets the..name d
0e60: 65 63 6f 64 65 64 20 61 6e 64 20 75 73 65 64 20 ecoded and used
0e70: 61 73 20 61 6e 20 61 72 67 75 6d 65 6e 74 20 74 as an argument t
0e80: 6f 20 3c 63 6f 64 65 3e 5f 5f 67 65 74 69 74 65 o <code>__getite
0e90: 6d 5f 5f 28 29 3c 2f 63 6f 64 65 3e 3a 0d 0a 0d m__()</code>:...
0ea0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 3e 3e 3e .<verbatim>..>>>
0eb0: 20 64 20 3d 20 41 74 74 72 69 62 75 74 65 64 44 d = AttributedD
0ec0: 69 63 74 28 29 0d 0a 3e 3e 3e 20 64 0d 0a 7b 7d ict()..>>> d..{}
0ed0: 0d 0a 3e 3e 3e 20 64 2e 66 6f 6f 20 3d 20 31 0d ..>>> d.foo = 1.
0ee0: 0a 3e 3e 3e 20 64 2e 66 6f 6f 5f 20 3d 20 34 32 .>>> d.foo_ = 42
0ef0: 0d 0a 3e 3e 3e 20 64 2e 66 6f 6f 5f 2c 20 64 5b ..>>> d.foo_, d[
0f00: 27 66 6f 6f 27 5d 2c 20 64 2e 66 6f 6f 0d 0a 28 'foo'], d.foo..(
0f10: 34 32 2c 20 34 32 2c 20 31 29 0d 0a 3e 3e 3e 20 42, 42, 1)..>>>
0f20: 64 0d 0a 7b 75 27 66 6f 6f 27 3a 20 34 32 7d 0d d..{u'foo': 42}.
0f30: 0a 3e 3e 3e 20 64 65 6c 20 64 2e 66 6f 6f 5f 0d .>>> del d.foo_.
0f40: 0a 3e 3e 3e 20 64 0d 0a 7b 7d 0d 0a 3c 2f 76 65 .>>> d..{}..</ve
0f50: 72 62 61 74 69 6d 3e 0d 0a 0d 0a 41 64 64 69 6e rbatim>....Addin
0f60: 67 20 74 61 62 2d 63 6f 6d 70 6c 65 74 69 6f 6e g tab-completion
0f70: 20 6f 6e 20 75 6e 64 65 72 73 63 6f 64 65 64 20 on underscoded
0f80: 61 74 74 72 69 62 75 74 65 73 20 74 6f 20 74 68 attributes to th
0f90: 69 73 20 73 69 6d 70 6c 65 20 65 78 61 6d 70 6c is simple exampl
0fa0: 65 20 69 73 20 61 73 0d 0a 65 61 73 79 20 61 73 e is as..easy as
0fb0: 20 61 70 70 6c 79 69 6e 67 20 73 6f 6d 65 20 72 applying some r
0fc0: 65 61 64 79 2d 74 6f 2d 75 73 65 20 64 65 63 6f eady-to-use deco
0fd0: 72 61 74 6f 72 73 20 6f 6e 20 74 68 65 20 6d 65 rators on the me
0fe0: 74 68 6f 64 73 20 75 73 65 64 20 61 73 20 61 72 thods used as ar
0ff0: 67 75 6d 65 6e 74 73 0d 0a 74 6f 20 3c 63 6f 64 guments..to <cod
1000: 65 3e 70 72 6f 78 79 5f 6d 65 74 68 6f 64 3c 2f e>proxy_method</
1010: 63 6f 64 65 3e 2e 20 20 53 65 65 20 74 68 65 20 code>. See the
1020: 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 documentation of
1030: 0d 0a 74 68 65 20 3c 63 6f 64 65 3e 75 6e 64 65 ..the <code>unde
1040: 72 73 63 6f 64 65 2e 64 65 63 6f 72 61 74 6f 72 rscode.decorator
1050: 73 3c 2f 63 6f 64 65 3e 20 6d 6f 64 75 6c 65 20 s</code> module
1060: 66 6f 72 20 6d 6f 72 65 20 69 6e 66 6f 72 6d 61 for more informa
1070: 74 69 6f 6e 20 61 6e 64 0d 0a 65 78 61 6d 70 6c tion and..exampl
1080: 65 73 2e 0d 0a 0d 0a 3c 68 32 3e 50 79 74 68 6f es.....<h2>Pytho
1090: 6e 20 63 6f 64 65 63 20 41 50 49 20 73 75 70 70 n codec API supp
10a0: 6f 72 74 3c 2f 68 32 3e 0d 0a 0d 0a 53 69 6e 63 ort</h2>....Sinc
10b0: 65 20 74 68 65 20 55 6e 64 65 72 73 63 6f 64 65 e the Underscode
10c0: 20 70 61 63 6b 61 67 65 20 69 73 20 63 6f 6d 70 package is comp
10d0: 6c 69 61 6e 74 20 77 69 74 68 20 74 68 65 20 73 liant with the s
10e0: 74 61 6e 64 61 72 64 20 50 79 74 68 6f 6e 20 63 tandard Python c
10f0: 6f 64 65 63 0d 0a 41 50 49 2c 20 79 6f 75 20 63 odec..API, you c
1100: 61 6e 20 75 73 65 20 55 6e 64 65 72 73 63 6f 64 an use Underscod
1110: 65 20 74 6f 20 65 6e 63 6f 64 65 20 61 6e 64 20 e to encode and
1120: 64 65 63 6f 64 65 20 73 74 72 69 6e 67 73 20 77 decode strings w
1130: 69 74 68 20 74 68 65 20 75 73 75 61 6c 0d 0a 3c ith the usual..<
1140: 63 6f 64 65 3e 75 6e 69 63 6f 64 65 2e 65 6e 63 code>unicode.enc
1150: 6f 64 65 28 29 3c 2f 63 6f 64 65 3e 20 61 6e 64 ode()</code> and
1160: 20 3c 63 6f 64 65 3e 73 74 72 2e 64 65 63 6f 64 <code>str.decod
1170: 65 28 29 3c 2f 63 6f 64 65 3e 20 63 61 6c 6c 73 e()</code> calls
1180: 20 61 74 20 61 6e 79 20 74 69 6d 65 0d 0a 6a 75 at any time..ju
1190: 73 74 20 62 79 20 69 6d 70 6f 72 74 69 6e 67 20 st by importing
11a0: 74 68 65 20 3c 63 6f 64 65 3e 75 6e 64 65 72 73 the <code>unders
11b0: 63 6f 64 65 2e 63 6f 64 65 63 3c 2f 63 6f 64 65 code.codec</code
11c0: 3e 20 73 75 62 70 61 63 6b 61 67 65 20 28 69 74 > subpackage (it
11d0: 20 69 73 20 6e 6f 74 0d 0a 61 75 74 6f 6d 61 74 is not..automat
11e0: 69 63 61 6c 6c 79 20 69 6d 70 6f 72 74 65 64 20 ically imported
11f0: 62 79 20 74 68 65 20 6d 61 69 6e 20 3c 63 6f 64 by the main <cod
1200: 65 3e 75 6e 64 65 72 73 63 6f 64 65 3c 2f 63 6f e>underscode</co
1210: 64 65 3e 20 70 61 63 6b 61 67 65 29 3a 0d 0a 0d de> package):...
1220: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 3e 3e 3e .<verbatim>..>>>
1230: 20 69 6d 70 6f 72 74 20 75 6e 64 65 72 73 63 6f import undersco
1240: 64 65 2e 63 6f 64 65 63 0d 0a 3e 3e 3e 20 70 72 de.codec..>>> pr
1250: 69 6e 74 20 75 27 74 68 69 73 20 69 73 20 5c 75 int u'this is \u
1260: 32 30 31 63 61 20 74 65 73 74 5c 75 32 30 31 64 201ca test\u201d
1270: 27 0d 0a 74 68 69 73 20 69 73 20 e2 80 9c 61 20 '..this is ...a
1280: 74 65 73 74 e2 80 9d 0d 0a 3e 3e 3e 20 75 27 74 test.....>>> u't
1290: 68 69 73 20 69 73 20 5c 75 32 30 31 63 61 20 74 his is \u201ca t
12a0: 65 73 74 5c 75 32 30 31 64 27 2e 65 6e 63 6f 64 est\u201d'.encod
12b0: 65 28 27 75 6e 64 65 72 73 63 6f 64 65 27 29 0d e('underscode').
12c0: 0a 27 74 68 69 73 5f 5f 69 73 5f 5f 5f 75 32 30 .'this__is___u20
12d0: 31 63 61 5f 5f 74 65 73 74 5f 75 32 30 31 64 5f 1ca__test_u201d_
12e0: 27 0d 0a 3e 3e 3e 20 27 74 68 69 73 5f 5f 69 73 '..>>> 'this__is
12f0: 5f 5f 5f 75 32 30 31 63 61 5f 5f 74 65 73 74 5f ___u201ca__test_
1300: 75 32 30 31 64 5f 27 2e 64 65 63 6f 64 65 28 27 u201d_'.decode('
1310: 75 6e 64 65 72 73 63 6f 64 65 27 29 0d 0a 75 27 underscode')..u'
1320: 74 68 69 73 20 69 73 20 5c 75 32 30 31 63 61 20 this is \u201ca
1330: 74 65 73 74 5c 75 32 30 31 64 27 0d 0a 3c 2f 76 test\u201d'..</v
1340: 65 72 62 61 74 69 6d 3e 0d 0a 0d 0a 0d 0a 3c 68 erbatim>......<h
1350: 32 3e 47 65 74 74 69 6e 67 20 55 6e 64 65 72 73 2>Getting Unders
1360: 63 6f 64 65 3c 2f 68 32 3e 0d 0a 0d 0a 59 6f 75 code</h2>....You
1370: 20 63 61 6e 20 64 6f 77 6e 6c 6f 61 64 20 74 68 can download th
1380: 65 20 73 6f 75 72 63 65 20 63 6f 64 65 20 64 69 e source code di
1390: 73 74 72 69 62 75 74 69 6f 6e 20 6f 66 20 55 6e stribution of Un
13a0: 64 65 72 73 63 6f 64 65 20 66 72 6f 6d 20 74 68 derscode from th
13b0: 65 0d 0a 50 79 74 68 6f 6e 20 50 61 63 6b 61 67 e..Python Packag
13c0: 65 20 49 6e 64 65 78 20 61 74 20 5b 68 74 74 70 e Index at [http
13d0: 3a 2f 2f 70 79 70 69 2e 70 79 74 68 6f 6e 2e 6f ://pypi.python.o
13e0: 72 67 2f 5d 2e 20 20 49 74 20 75 73 65 73 20 74 rg/]. It uses t
13f0: 68 65 20 73 74 61 6e 64 61 72 64 0d 0a 3c 63 6f he standard..<co
1400: 64 65 3e 73 65 74 75 70 2e 70 79 3c 2f 63 6f 64 de>setup.py</cod
1410: 65 3e 20 6d 65 74 68 6f 64 20 66 6f 72 20 69 6e e> method for in
1420: 73 74 61 6c 6c 61 74 69 6f 6e 2c 20 72 75 6e 73 stallation, runs
1430: 20 6f 6e 20 61 6e 79 20 70 6c 61 74 66 6f 72 6d on any platform
1440: 20 61 6e 64 20 68 61 73 20 6e 6f 0d 0a 61 64 64 and has no..add
1450: 69 74 69 6f 6e 61 6c 20 64 65 70 65 6e 64 65 6e itional dependen
1460: 63 69 65 73 20 62 75 74 20 50 79 74 68 6f 6e 20 cies but Python
1470: 76 65 72 73 69 6f 6e 20 32 2e 34 20 6f 72 20 67 version 2.4 or g
1480: 72 65 61 74 65 72 2e 0d 0a 0d 0a 59 6f 75 20 6d reater.....You m
1490: 61 79 20 61 6c 73 6f 20 62 65 20 69 6e 74 65 72 ay also be inter
14a0: 65 73 74 65 64 20 69 6e 20 66 6f 6c 6c 6f 77 69 ested in followi
14b0: 6e 67 20 74 68 65 20 64 65 76 65 6c 6f 70 6d 65 ng the developme
14c0: 6e 74 20 6f 66 20 55 6e 64 65 72 73 63 6f 64 65 nt of Underscode
14d0: 3b 20 79 6f 75 20 63 61 6e 0d 0a 6d 61 6b 65 20 ; you can..make
14e0: 61 20 63 6c 6f 6e 65 20 6f 66 20 69 74 73 20 5b a clone of its [
14f0: 68 74 74 70 3a 2f 2f 77 77 77 2e 66 6f 73 73 69 http://www.fossi
1500: 6c 2d 73 63 6d 2e 6f 72 67 2f 7c 46 6f 73 73 69 l-scm.org/|Fossi
1510: 6c 5d 20 72 65 70 6f 73 69 74 6f 72 79 20 61 6e l] repository an
1520: 64 0d 0a 63 68 65 63 6b 6f 75 74 20 69 74 20 77 d..checkout it w
1530: 69 74 68 3a 3a 0d 0a 0d 0a 3c 76 65 72 62 61 74 ith::....<verbat
1540: 69 6d 3e 0d 0a 24 20 66 6f 73 73 69 6c 20 63 6c im>..$ fossil cl
1550: 6f 6e 65 20 68 74 74 70 73 3a 2f 2f 65 6c 76 69 one https://elvi
1560: 6c 2e 6e 65 74 2f 66 6f 73 73 69 6c 2f 75 6e 64 l.net/fossil/und
1570: 65 72 73 63 6f 64 65 2f 20 75 6e 64 65 72 73 63 erscode/ undersc
1580: 6f 64 65 2e 66 6f 73 73 69 6c 0d 0a 24 20 6d 6b ode.fossil..$ mk
1590: 64 69 72 20 75 6e 64 65 72 73 63 6f 64 65 20 26 dir underscode &
15a0: 26 20 63 64 20 75 6e 64 65 72 73 63 6f 64 65 0d & cd underscode.
15b0: 0a 24 20 66 6f 73 73 69 6c 20 6f 70 65 6e 20 2e .$ fossil open .
15c0: 2e 2f 75 6e 64 65 72 73 63 6f 64 65 2e 66 6f 73 ./underscode.fos
15d0: 73 69 6c 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e sil..</verbatim>
15e0: 0d 0a 0d 0a 0d 0a 3c 68 32 3e 48 65 6c 70 69 6e ......<h2>Helpin
15f0: 67 20 55 6e 64 65 72 73 63 6f 64 65 3c 2f 68 32 g Underscode</h2
1600: 3e 0d 0a 0d 0a 49 20 77 6f 75 6c 64 20 6c 69 6b >....I would lik
1610: 65 20 74 6f 20 68 65 61 72 20 79 6f 75 72 20 6f e to hear your o
1620: 70 69 6e 69 6f 6e 73 20 61 6e 64 20 66 65 65 6c pinions and feel
1630: 69 6e 67 73 20 6f 6e 20 55 6e 64 65 72 73 63 6f ings on Undersco
1640: 64 65 2c 20 74 6f 20 6b 6e 6f 77 20 68 6f 77 20 de, to know how
1650: 79 6f 75 0d 0a 75 73 65 64 20 69 74 20 69 6e 20 you..used it in
1660: 79 6f 75 72 20 70 72 6f 6a 65 63 74 73 2c 20 61 your projects, a
1670: 6e 64 20 74 6f 20 68 65 6c 70 20 79 6f 75 20 73 nd to help you s
1680: 6f 6c 76 65 20 79 6f 75 72 20 70 72 6f 62 6c 65 olve your proble
1690: 6d 73 20 77 69 74 68 20 69 74 2e 20 20 49 66 20 ms with it. If
16a0: 79 6f 75 0d 0a 63 6f 6d 65 20 61 63 72 6f 73 73 you..come across
16b0: 20 61 20 62 75 67 20 6f 72 20 79 6f 75 20 68 61 a bug or you ha
16c0: 76 65 20 73 6f 6d 65 20 65 6e 68 61 6e 63 65 6d ve some enhancem
16d0: 65 6e 74 20 70 72 6f 70 6f 73 61 6c 2c 20 70 6c ent proposal, pl
16e0: 65 61 73 65 20 73 65 6e 64 20 6d 65 20 61 6e 0d ease send me an.
16f0: 0a 65 2d 6d 61 69 6c 20 6f 72 20 63 72 65 61 74 .e-mail or creat
1700: 65 20 61 20 74 69 63 6b 65 74 20 61 74 20 5b 68 e a ticket at [h
1710: 74 74 70 73 3a 2f 2f 65 6c 76 69 6c 2e 6e 65 74 ttps://elvil.net
1720: 2f 66 6f 73 73 69 6c 2f 75 6e 64 65 72 73 63 6f /fossil/undersco
1730: 64 65 2f 5d 0d 0a 0a 5a 20 64 37 30 35 66 66 34 de/]...Z d705ff4
1740: 61 37 36 62 35 39 33 64 33 32 61 34 63 64 61 32 a76b593d32a4cda2
1750: 64 32 33 38 31 62 37 34 32 0a d2381b742.