Logo Search packages:      
Sourcecode: matplotlib version File versions  Download package

def configobj::Section::decode (   self,
  encoding 
)

Decode all strings and values to unicode, using the specified encoding.

Works with subsections and list values.

Uses the ``walk`` method.

Testing ``encode`` and ``decode``.
>>> m = ConfigObj(a)
>>> m.decode('ascii')
>>> def testuni(val):
...     for entry in val:
...         if not isinstance(entry, unicode):
...             print >> sys.stderr, type(entry)
...             raise AssertionError, 'decode failed.'
...         if isinstance(val[entry], dict):
...             testuni(val[entry])
...         elif not isinstance(val[entry], unicode):
...             raise AssertionError, 'decode failed.'
>>> testuni(m)
>>> m.encode('ascii')
>>> a == m
1

Definition at line 867 of file configobj.py.

00867                               :
        """
        Decode all strings and values to unicode, using the specified encoding.
        
        Works with subsections and list values.
        
        Uses the ``walk`` method.
        
        Testing ``encode`` and ``decode``.
        >>> m = ConfigObj(a)
        >>> m.decode('ascii')
        >>> def testuni(val):
        ...     for entry in val:
        ...         if not isinstance(entry, unicode):
        ...             print >> sys.stderr, type(entry)
        ...             raise AssertionError, 'decode failed.'
        ...         if isinstance(val[entry], dict):
        ...             testuni(val[entry])
        ...         elif not isinstance(val[entry], unicode):
        ...             raise AssertionError, 'decode failed.'
        >>> testuni(m)
        >>> m.encode('ascii')
        >>> a == m
        1
        """
        warn('use of ``decode`` is deprecated.', DeprecationWarning)
        def decode(section, key, encoding=encoding, warn=True):
            """ """
            val = section[key]
            if isinstance(val, (list, tuple)):
                newval = []
                for entry in val:
                    newval.append(entry.decode(encoding))
            elif isinstance(val, dict):
                newval = val
            else:
                newval = val.decode(encoding)
            newkey = key.decode(encoding)
            section.rename(key, newkey)
            section[newkey] = newval
        # using ``call_on_sections`` allows us to modify section names
        self.walk(decode, call_on_sections=True)

    def encode(self, encoding):


Generated by  Doxygen 1.6.0   Back to index