Django

Code

Changeset 6463

Show
Ignore:
Timestamp:
10/07/07 11:35:32 (1 year ago)
Author:
mtredinnick
Message:

Documented the strings_only param to smart_unicode() and force_unicode().

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/unicode.txt

    r5614 r6463  
    111111for converting back and forth between Unicode and bytestrings. 
    112112 
    113     * ``smart_unicode(s, encoding='utf-8', errors='strict')`` converts its 
    114       input to a Unicode string. The ``encoding`` parameter specifies the input 
    115       encoding. (For example, Django uses this internally when processing form 
    116       input data, which might not be UTF-8 encoded.) The ``errors`` parameter 
    117       takes any of the values that are accepted by Python's ``unicode()`` 
    118       function for its error handling. 
     113    * ``smart_unicode(s, encoding='utf-8', strings_only=False, errors='strict')`` 
     114      converts its input to a Unicode string. The ``encoding`` parameter 
     115      specifies the input encoding. (For example, Django uses this internally 
     116      when processing form input data, which might not be UTF-8 encoded.) The 
     117      ``strings_only`` parameter, if set to True, will result in Python 
     118      numbers, booleans and ``None`` not being converted to a string (they keep 
     119      their original types). The ``errors`` parameter takes any of the values 
     120      that are accepted by Python's ``unicode()`` function for its error 
     121      handling. 
    119122 
    120123      If you pass ``smart_unicode()`` an object that has a ``__unicode__`` 
    121124      method, it will use that method to do the conversion. 
    122125 
    123     * ``force_unicode(s, encoding='utf-8', errors='strict')`` is identical to 
    124       ``smart_unicode()`` in almost all cases. The difference is when th
    125       first argument is a `lazy translation`_ instance. While 
     126    * ``force_unicode(s, encoding='utf-8', strings_only=False, errors='strict')`` 
     127      is identical to ``smart_unicode()`` in almost all cases. The differenc
     128      is when the first argument is a `lazy translation`_ instance. While 
    126129      ``smart_unicode()`` preserves lazy translations, ``force_unicode()`` 
    127130      forces those objects to a Unicode string (causing the translation to 
     
    133136    * ``smart_str(s, encoding='utf-8', strings_only=False, errors='strict')`` 
    134137      is essentially the opposite of ``smart_unicode()``. It forces the first 
    135       argument to a bytestring. The ``strings_only`` parameter, if set to True, 
    136       will result in Python integers, booleans and ``None`` not being 
    137       converted to a string (they keep their original types). This is slightly 
    138       different semantics from Python's builtin ``str()`` function, but the 
    139       difference is needed in a few places within Django's internals. 
     138      argument to a bytestring. The ``strings_only`` parameter has the same 
     139      behaviour as for ``smart_unicode()`` and ``force_unicode()``. This is 
     140      slightly different semantics from Python's builtin ``str()`` function, 
     141      but the difference is needed in a few places within Django's internals. 
    140142 
    141143Normally, you'll only need to use ``smart_unicode()``. Call it as early as