File: util.py

package info (click to toggle)
python-srsly 2.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,256 kB
  • sloc: python: 17,567; ansic: 1,434; sh: 12; makefile: 6
file content (14 lines) | stat: -rw-r--r-- 301 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from __future__ import unicode_literals

try:
    unicode
except NameError:
    unicode = str


def ensure_bytes(string):
    """Ensure a string is returned as a bytes object, encoded as utf8."""
    if isinstance(string, unicode):
        return string.encode("utf8")
    else:
        return string