File: _pydev_filesystem_encoding.py

package info (click to toggle)
pydevd 3.4.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,892 kB
  • sloc: python: 77,580; cpp: 1,873; sh: 374; makefile: 50; ansic: 4
file content (43 lines) | stat: -rw-r--r-- 1,101 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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys


def __getfilesystemencoding():
    """
    Note: there's a copy of this method in interpreterInfo.py
    """
    try:
        ret = sys.getfilesystemencoding()
        if not ret:
            raise RuntimeError("Unable to get encoding.")
        return ret
    except:
        try:
            # Handle Jython
            from java.lang import System  # @UnresolvedImport

            env = System.getProperty("os.name").lower()
            if env.find("win") != -1:
                return "ISO-8859-1"  # mbcs does not work on Jython, so, use a (hopefully) suitable replacement
            return "utf-8"
        except:
            pass

        # Only available from 2.3 onwards.
        if sys.platform == "win32":
            return "mbcs"
        return "utf-8"


def getfilesystemencoding():
    try:
        ret = __getfilesystemencoding()

        # Check if the encoding is actually there to be used!
        if hasattr("", "encode"):
            "".encode(ret)
        if hasattr("", "decode"):
            "".decode(ret)

        return ret
    except:
        return "utf-8"