File: _string.py

package info (click to toggle)
python-typepy 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: python: 2,886; makefile: 78; sh: 7
file content (20 lines) | stat: -rw-r--r-- 498 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

from mbstrdecoder import MultiByteStrDecoder

from ._interface import AbstractValueConverter


class StringConverter(AbstractValueConverter):
    def force_convert(self):
        try:
            return MultiByteStrDecoder(self._value).unicode_str
        except ValueError:
            return str(self._value)


class NullStringConverter(StringConverter):
    def force_convert(self):
        return super().force_convert()