(value, to_enc=DEFAULT_ENCODING, from_enc=None)
| 55 | |
| 56 | # Optional from_enc enables transcoding |
| 57 | def to_str(value, to_enc=DEFAULT_ENCODING, from_enc=None): |
| 58 | if isinstance(value, six.binary_type): |
| 59 | if from_enc is None or to_enc == from_enc: |
| 60 | # Unknown input encoding or input and output encoding are the same |
| 61 | return value |
| 62 | value = to_unicode(value, from_enc=from_enc) |
| 63 | if isinstance(value, six.text_type): |
| 64 | return value.encode(to_enc, ENCODING_ERRORS_POLICY) |
| 65 | return six.binary_type(value) |
| 66 | |
| 67 | |
| 68 | def _convert_deep(x, enc, convert, relaxed=True): |
nothing calls this directly
no test coverage detected