Source

savReaderWriter / savReaderWriter / py3k.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import functools
from ctypes import c_char_p

isPy3k = sys.version_info[0] == 3

try:
    unicode
except NameError:
    basestring = unicode = str  # Python 3

try:
    xrange
except NameError:
    xrange = range

if isPy3k:
    bytes = functools.partial(bytes, encoding="utf-8")

def c_char_py3k(s):
    """Wrapper for ctypes.c_char_p; in Python 3.x, s is converted to a utf-8
    encoded bytestring"""
    if not isPy3k:
        # # for now, keep this, but later change this so Python 2.7 also takes unicode strings as args
        return c_char_p(s)
    else:
        s = s.encode("utf-8") if isinstance(s, str) else s
        return c_char_p(s)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.