Changes between Version 60 and Version 61 of DeveloperGuidelines/CodeConventions


Ignore:
Timestamp:
01/26/16 12:10:22 (9 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/CodeConventions

    v60 v61  
    103103
    104104{{{
    105     s = s3_unicode(s)
    106 }}}
    107 
    108 4) We assume that any (external) function we call may attempt to convert input by calling str() - so we generally deliver all strings as utf-8 encoded str to prevent !UnicodeDecodeErrors. This can be done by:
     105    s_slice = s3_unicode(s)[:4]
     106}}}
     107
     1084) To ensure correct behavior of lower() and upper() conversion, we convert into unicode first, using s3_unicode:
     109
     110{{{
     111   s_lowercase = s3_unicode(s).lower().encode("utf-8")
     112}}}
     113
     1145) We assume that any (external) function we call may attempt to convert input by calling str() - so we generally deliver all strings as utf-8 encoded str to prevent !UnicodeDecodeErrors. This can be done by:
    109115
    110116{{{
     
    118124}}}
    119125
    120 5) System-strings (like table or field names, attribute names, etc.) should never contain non-ASCII characters, so that they safely pass through str().
    121 
    122 6) In reading XML, we follow the encoding specified in the XML declaration rather than making assumptions about the encoding. For all other sources, we
     1266) System-strings (like table or field names, attribute names, etc.) should never contain non-ASCII characters, so that they safely pass through str().
     127
     1287) In reading XML, we follow the encoding specified in the XML declaration rather than making assumptions about the encoding. For all other sources, we
    123129assume utf-8 (see 2). In exports, we always write utf-8.
    124130
    125 7) All code is utf-8 encoded, so that all string constants are automatically utf-8 encoded str. We do not use u"..." for string constants.
    126 
    127 8) Note that, in Python 2, str.lower() and str.upper() may not work correctly for some unicode characters (e.g. "Ẽ".lower() gives "Ẽ" again - instead of "ẽ"), depending on the server locale setting. To ensure correct behavior, we must convert into unicode first, using s3_unicode:
    128 
    129 {{{
    130    s_lowercase = s3_unicode(s).lower().encode("utf-8")
    131 }}}
     1318) All code is utf-8 encoded, so that all string constants are automatically utf-8 encoded str. We do not use u"..." for string constants.
    132132=== Tools ===
    133133