示例#1
0
文件: os.py 项目: Daetalus/cpython
def _fscodec():
    encoding = sys.getfilesystemencoding()
    errors = sys.getfilesystemencodeerrors()

    def fsencode(filename):
        """Encode filename (an os.PathLike, bytes, or str) to the filesystem
        encoding with 'surrogateescape' error handler, return bytes unchanged.
        On Windows, use 'strict' error handler if the file system encoding is
        'mbcs' (which is the default encoding).
        """
        filename = fspath(filename)  # Does type-checking of `filename`.
        if isinstance(filename, str):
            return filename.encode(encoding, errors)
        else:
            return filename

    def fsdecode(filename):
        """Decode filename (an os.PathLike, bytes, or str) from the filesystem
        encoding with 'surrogateescape' error handler, return str unchanged. On
        Windows, use 'strict' error handler if the file system encoding is
        'mbcs' (which is the default encoding).
        """
        filename = fspath(filename)  # Does type-checking of `filename`.
        if isinstance(filename, bytes):
            return filename.decode(encoding, errors)
        else:
            return filename

    return fsencode, fsdecode
示例#2
0
 def encode(
     self, text: Union[str, bytes, io.BufferedIOBase, memoryview]
 ) -> Union[str, bytes]:
     encoding = self.encoding if self.encoding else "utf-8"
     contents: Union[str, bytes]
     errors = self.errors
     if not errors:
         try:
             errors = sys.getfilesystemencodeerrors()  # type: ignore
         except AttributeError:
             errors = "surrogateescape"
     if isinstance(text, memoryview):
         if "b" not in self._write_mode:
             contents = text.tobytes().decode(encoding=encoding,
                                              errors=errors)
         else:
             contents = text.tobytes()
     elif isinstance(text, str) and "b" in self._write_mode:
         contents = text.encode(encoding=encoding, errors=errors)
     elif isinstance(text, bytes) and "b" not in self._write_mode:
         contents = text.decode(encoding=encoding, errors=errors)
     elif isinstance(text, io.BufferedIOBase):
         contents = self.encode(text.read())
     elif (isinstance(text, str) and "b" not in self._write_mode) or (
             isinstance(text, bytes) and "b" in self._write_mode):
         return text
     else:
         raise TypeError(f"Invalid type to encode: {text!r}")
     return contents
示例#3
0
 def __init__(self):
     print('looking at some sys functions')
     print(sys.api_version)
     print(sys.argv)
     print(sys.base_exec_prefix)
     print(sys.base_prefix)
     print(sys.builtin_module_names)
     print(sys.byteorder)
     print(sys.copyright)
     print(sys.dllhandle)
     print(sys.exc_info())
     # print(sys.exc_traceback)
     print(sys.executable)
     print(sys.path)
     print(sys.maxsize)
     print(sys.platform)
     print(sys.flags)
     print(sys.float_info)
     print(sys.float_repr_style)
     print(sys._framework)
     print(sys.getdefaultencoding())
     print(sys.getwindowsversion())
     print(sys.getallocatedblocks())
     print(sys.getfilesystemencodeerrors())
     # print(sys.getcheckinterval())
     print(sys.getprofile())
     print(sys.getrecursionlimit())
     print(sys.getswitchinterval())
     print(sys.gettrace())
     print(sys._git)
     print('\n')
     print(sys.getsizeof(self))
示例#4
0
def _fscodec():
    encoding = sys.getfilesystemencoding()
    errors = sys.getfilesystemencodeerrors()

    def fsencode(filename):
        """Encode filename (an os.PathLike, bytes, or str) to the filesystem
        encoding with 'surrogateescape' error handler, return bytes unchanged.
        On Windows, use 'strict' error handler if the file system encoding is
        'mbcs' (which is the default encoding).
        """
        filename = fspath(filename)  # Does type-checking of `filename`.
        if isinstance(filename, str):
            return filename.encode(encoding, errors)
        else:
            return filename

    def fsdecode(filename):
        """Decode filename (an os.PathLike, bytes, or str) from the filesystem
        encoding with 'surrogateescape' error handler, return str unchanged. On
        Windows, use 'strict' error handler if the file system encoding is
        'mbcs' (which is the default encoding).
        """
        filename = fspath(filename)  # Does type-checking of `filename`.
        if isinstance(filename, bytes):
            return filename.decode(encoding, errors)
        else:
            return filename

    return fsencode, fsdecode
示例#5
0
def collect_sys(info_add):
    attributes = (
        '_emscripten_info',
        '_framework',
        'abiflags',
        'api_version',
        'builtin_module_names',
        'byteorder',
        'dont_write_bytecode',
        'executable',
        'flags',
        'float_info',
        'float_repr_style',
        'hash_info',
        'hexversion',
        'implementation',
        'int_info',
        'maxsize',
        'maxunicode',
        'path',
        'platform',
        'platlibdir',
        'prefix',
        'thread_info',
        'version',
        'version_info',
        'winver',
    )
    copy_attributes(info_add, sys, 'sys.%s', attributes)

    call_func(info_add, 'sys.androidapilevel', sys, 'getandroidapilevel')
    call_func(info_add, 'sys.windowsversion', sys, 'getwindowsversion')

    encoding = sys.getfilesystemencoding()
    if hasattr(sys, 'getfilesystemencodeerrors'):
        encoding = '%s/%s' % (encoding, sys.getfilesystemencodeerrors())
    info_add('sys.filesystem_encoding', encoding)

    for name in ('stdin', 'stdout', 'stderr'):
        stream = getattr(sys, name)
        if stream is None:
            continue
        encoding = getattr(stream, 'encoding', None)
        if not encoding:
            continue
        errors = getattr(stream, 'errors', None)
        if errors:
            encoding = '%s/%s' % (encoding, errors)
        info_add('sys.%s.encoding' % name, encoding)

    # Were we compiled --with-pydebug or with #define Py_DEBUG?
    Py_DEBUG = hasattr(sys, 'gettotalrefcount')
    if Py_DEBUG:
        text = 'Yes (sys.gettotalrefcount() present)'
    else:
        text = 'No (sys.gettotalrefcount() missing)'
    info_add('Py_DEBUG', text)
示例#6
0
def collect_sys(info_add):
    attributes = (
        '_framework',
        'abiflags',
        'api_version',
        'builtin_module_names',
        'byteorder',
        'dont_write_bytecode',
        'executable',
        'flags',
        'float_info',
        'float_repr_style',
        'hash_info',
        'hexversion',
        'implementation',
        'int_info',
        'maxsize',
        'maxunicode',
        'path',
        'platform',
        'prefix',
        'thread_info',
        'version',
        'version_info',
        'winver',
    )
    copy_attributes(info_add, sys, 'sys.%s', attributes)

    call_func(info_add, 'sys.androidapilevel', sys, 'getandroidapilevel')
    call_func(info_add, 'sys.windowsversion', sys, 'getwindowsversion')

    encoding = sys.getfilesystemencoding()
    if hasattr(sys, 'getfilesystemencodeerrors'):
        encoding = '%s/%s' % (encoding, sys.getfilesystemencodeerrors())
    info_add('sys.filesystem_encoding', encoding)

    for name in ('stdin', 'stdout', 'stderr'):
        stream = getattr(sys, name)
        if stream is None:
            continue
        encoding = getattr(stream, 'encoding', None)
        if not encoding:
            continue
        errors = getattr(stream, 'errors', None)
        if errors:
            encoding = '%s/%s' % (encoding, errors)
        info_add('sys.%s.encoding' % name, encoding)

    # Were we compiled --with-pydebug or with #define Py_DEBUG?
    Py_DEBUG = hasattr(sys, 'gettotalrefcount')
    if Py_DEBUG:
        text = 'Yes (sys.gettotalrefcount() present)'
    else:
        text = 'No (sys.gettotalrefcount() missing)'
    info_add('Py_DEBUG', text)
示例#7
0
def collect_sys(info_add):
    attributes = (
        '_framework',
        'abiflags',
        'api_version',
        'builtin_module_names',
        'byteorder',
        'dont_write_bytecode',
        'executable',
        'flags',
        'float_info',
        'float_repr_style',
        'hash_info',
        'hexversion',
        'implementation',
        'int_info',
        'maxsize',
        'maxunicode',
        'path',
        'platform',
        'prefix',
        'thread_info',
        'version',
        'version_info',
        'winver',
    )
    copy_attributes(info_add, sys, 'sys.%s', attributes)

    call_func(info_add, 'sys.androidapilevel', sys, 'getandroidapilevel')
    call_func(info_add, 'sys.windowsversion', sys, 'getwindowsversion')

    encoding = sys.getfilesystemencoding()
    if hasattr(sys, 'getfilesystemencodeerrors'):
        encoding = '%s/%s' % (encoding, sys.getfilesystemencodeerrors())
    info_add('sys.filesystem_encoding', encoding)

    for name in ('stdin', 'stdout', 'stderr'):
        stream = getattr(sys, name)
        if stream is None:
            continue
        encoding = getattr(stream, 'encoding', None)
        if not encoding:
            continue
        errors = getattr(stream, 'errors', None)
        if errors:
            encoding = '%s/%s' % (encoding, errors)
        info_add('sys.%s.encoding' % name, encoding)
示例#8
0
文件: os.py 项目: mathio3/5arbachat
def _fscodec():
    encoding = sys.getfilesystemencoding()
    errors = sys.getfilesystemencodeerrors()

    def fsencode(filename):

        filename = fspath(filename)  # Does type-checking of `filename`.
        if isinstance(filename, str):
            return filename.encode(encoding, errors)
        else:
            return filename

    def fsdecode(filename):

        filename = fspath(filename)
        if isinstance(filename, bytes):
            return filename.decode(encoding, errors)
        else:
            return filename

    return fsencode, fsdecode
示例#9
0
 def read_file(
     self,
     path: PATH_TYPES,
     text: bool = True,
     encoding: str = "utf-8",
     errors: Optional[str] = None,
 ) -> Union[str, bytes]:
     """Return the contents of the requested file, either a a bytestring or a unicode
     string depending on whether **text** is True"""
     content: Union[str, bytes]
     if not errors:
         try:
             errors = sys.getfilesystemencodeerrors()
         except AttributeError:
             errors = "surrogateescape"
     kwargs: Dict[str, Any] = {}
     if errors:
         kwargs["errors"] = errors
     content = self.get_object(self.default_container, str(path))
     if text and isinstance(content, bytes):
         content = content.decode(encoding=encoding, **kwargs)
     return content
示例#10
0
 def write_file(
     self,
     path: PATH_TYPES,
     contents: Union[str, bytes, IO],
     encoding: Optional[str] = None,
     errors: Optional[str] = None,
 ) -> None:
     """Write data to the provided path.  If **contents** is a string, the file will
     be opened and written in "r" + "utf-8" mode, if bytes are supplied it will be
     accessed using "rb" mode (i.e. binary write)."""
     if encoding is not None:
         if errors is None:
             try:
                 errors = sys.getfilesystemencodeerrors()
             except AttributeError:
                 errors = "surrogateescape"
         if isinstance(contents, str):
             contents = contents.encode(encoding=encoding, errors=errors)
         elif isinstance(contents, bytes):
             contents = contents.decode(encoding=encoding, errors=errors)
     with self.connection() as conn:
         conn.put_object(self.default_container, str(path), contents)
     return
示例#11
0
def _pathcodec():
    # This works very much like os.fs(en|de)code, except that encoding and error handling
    # remain parameters.
    fs_encoding = sys.getfilesystemencoding()
    fs_errors = sys.getfilesystemencodeerrors()  # probably 'surrogateescape'
    fspath = os.fspath

    def encode_path(path, *, encoding=fs_encoding, errors=fs_errors):
        """Encode a path to bytes."""
        path = fspath(path)
        if isinstance(path, str):
            return path.encode(encoding, errors)
        else:  # pragma: no cover
            return path

    def decode_path(path, *, encoding=fs_encoding, errors=fs_errors):
        """Decode a path to str."""
        path = fspath(path)
        if isinstance(path, bytes):
            return path.decode(encoding, errors)
        else:
            return path

    return encode_path, decode_path
示例#12
0
def listPythonSystem():
    """!
    Function to list information about the installed Python system.

    @return: Dictionary of {attributes: values}.
    """
    try: dllhandle = sys.dllhandle
    except AttributeError: dllhandle = "Not Defined"
    try: androidapilevel = sys.getandroidapilevel()
    except AttributeError: androidapilevel = "Not Defined"
    try: dlopenflags = sys.getdlopenflags()
    except AttributeError: dlopenflags = "Not Defined"
    try: windowsversion_major = sys.getwindowsversion().major 
    except AttributeError: windowsversion_major = "Not Defined"
    try: windowsversion_minor = sys.getwindowsversion().minor 
    except AttributeError: windowsversion_minor = "Not Defined"
    try: windowsversion_build = sys.getwindowsversion().build 
    except AttributeError: windowsversion_build = "Not Defined"
    try: windowsversion_platform = sys.getwindowsversion().platform
    except AttributeError: windowsversion_platform = "Not Defined"
    try: 
        service_pack = sys.getwindowsversion().service_pack
        if service_pack == '': 
            service_pack = 'Not Specified'
    except AttributeError: service_pack = "Not Defined"
    try: winver = sys.winver
    except AttributeError: winver = "Not Defined"
    if sys.thread_info.lock == None:
        thread_info_lock = "Not Defined"
    else:
        thread_info_lock = sys.thread_info.lock
    if sys.thread_info.version == None:
        thread_info_version = "Not Defined"
    else:
        thread_info_version = sys.thread_info.version
    results = {"allocatedblocks": str(sys.getallocatedblocks()),
               "androidapilevel": str(androidapilevel),
               "api_version": str(sys.api_version),
               "base_exec_prefix": str(sys.base_exec_prefix),
               "base_prefix": str(sys.base_prefix),
               "byteorder": str(sys.byteorder),
               "builtin_module_names": ' | '.join(sys.builtin_module_names),
               "defaultencoding": str(sys.getdefaultencoding()),
               "dllhandle": str(dllhandle),
               "dlopenflags": str(dlopenflags),
               "exec_prefix": str(sys.exec_prefix),
               "executable": str(sys.executable),
               "filesystemencoding": str(sys.getfilesystemencoding()),
               "filesystemencodeerrors": str(sys.getfilesystemencodeerrors()),
               "flag_debug": str(sys.flags.debug),
               "flag_inspect": str(sys.flags.inspect), 
               "flag_interactive": str(sys.flags.interactive), 
               "flag_optimize": str(sys.flags.optimize), 
               "flag_dont_write_bytecode": str(sys.flags.dont_write_bytecode), 
               "flag_no_user_site": str(sys.flags.no_user_site), 
               "flag_no_site": str(sys.flags.no_site), 
               "flag_ignore_environment": str(sys.flags.ignore_environment), 
               "flag_verbose": str(sys.flags.verbose), 
               "flag_bytes_warning": str(sys.flags.bytes_warning), 
               "flag_quiet": str(sys.flags.quiet), 
               "flag_has_randomization": str(sys.flags.hash_randomization), 
               "flag_isolated": str(sys.flags.isolated), 
               "flag_dev_mode": str(sys.flags.dev_mode), 
               "flag_utf8_mode": str(sys.flags.utf8_mode),
               "float_info_max": str(sys.float_info.max), 
               "float_info_max_exp": str(sys.float_info.max_exp), 
               "float_info_max_10_exp": str(sys.float_info.max_10_exp), 
               "float_info_min": str(sys.float_info.min), 
               "float_info_min_exp": str(sys.float_info.min_exp), 
               "float_info_min_10_exp": str(sys.float_info.min_10_exp), 
               "float_info_dig": str(sys.float_info.dig), 
               "float_info_mant_dig": str(sys.float_info.mant_dig), 
               "float_info_epsilon": str(sys.float_info.epsilon), 
               "float_info_radix": str(sys.float_info.radix), 
               "float_info_rounds": str(sys.float_info.rounds),
               "float_repr_style": str(sys.float_repr_style),
               "hash_info_width": str(sys.hash_info.width), 
               "hash_info_modulus": str(sys.hash_info.modulus), 
               "hash_info_inf": str(sys.hash_info.inf), 
               "hash_info_nan": str(sys.hash_info.nan), 
               "hash_info_imag": str(sys.hash_info.imag), 
               "hash_info_algorithm": str(sys.hash_info.algorithm), 
               "hash_info_hash_bits": str(sys.hash_info.hash_bits), 
               "hash_info_seed_bits": str(sys.hash_info.seed_bits), 
               "hash_info_cutoff": str(sys.hash_info.cutoff),
               "hexversion": str(sys.hexversion),
               "implementation_name": str(sys.implementation.name),
               "implementation_cache_tag": str(sys.implementation.cache_tag),
               "int_info_bits_per_digit": str(sys.int_info.bits_per_digit), 
               "int_info_sizeof_digit": str(sys.int_info.sizeof_digit),
               "maxsize": str(sys.maxsize),
               "maxunicode": str(sys.maxunicode),
               "platform": str(sys.platform),
               "prefix": str(sys.prefix),
               "recursionlimit": str(sys.getrecursionlimit()),
               "switchinterval": str(sys.getswitchinterval()),
               "thread_info_name": str(sys.thread_info.name),
               "thread_info_lock": str(thread_info_lock),
               "thread_info_version": str(thread_info_version),
               "version_info_major": str(sys.version_info.major), 
               "version_info_minor:": str(sys.version_info.minor), 
               "version_info_micro": str(sys.version_info.micro), 
               "version_info_releaselevel": str(sys.version_info.releaselevel), 
               "version_info_serial": str(sys.version_info.serial),
               "windowsversion_major": str(windowsversion_major),
               "windowsversion_minor": str(windowsversion_minor),
               "windowsversion_build": str(windowsversion_build), 
               "windowsversion_platform": str(windowsversion_platform),
               "windowsversion_service_pack": str(service_pack),               
               "winver": str(sys.winver)}
    return results
示例#13
0
    POWER_TIME_UNLIMITED = -2
else:
    class BatteryTime(enum.IntEnum):
        POWER_TIME_UNKNOWN = -1
        POWER_TIME_UNLIMITED = -2

    globals().update(BatteryTime.__members__)

# --- others

ENCODING = sys.getfilesystemencoding()
if not PY3:
    ENCODING_ERRS = "replace"
else:
    try:
        ENCODING_ERRS = sys.getfilesystemencodeerrors()  # py 3.6
    except AttributeError:
        ENCODING_ERRS = "surrogateescape" if POSIX else "replace"


# ===================================================================
# --- namedtuples
# ===================================================================

# --- for system functions

# psutil.swap_memory()
sswap = namedtuple('sswap', ['total', 'used', 'free', 'percent', 'sin',
                             'sout'])
# psutil.disk_usage()
sdiskusage = namedtuple('sdiskusage', ['total', 'used', 'free', 'percent'])
示例#14
0
print(format(float(s), '.16g'))  # conversion changes value

print(sys.float_repr_style)

# 返回解释器当前分配的内存块数,而不考虑其大小。
print(sys.getallocatedblocks())

# 3.2版后已移除: Use getswitchinterval() instead.
# setcheckinterval().
# print(sys.getcheckinterval())
# 返回解释器的“线程切换间隔。
print(sys.getswitchinterval())  # setswitchinterval().

print(sys.getdefaultencoding())
print(sys.getfilesystemencoding())
print(sys.getfilesystemencodeerrors())


# 返回<object>的引用次数。
# 引用次数会比期望值值多一个,因为它包含getrefcount()参数的临时引用。
class Test():
    pass


t = Test()
print(sys.getrefcount(t))  # t 本身是Test,所以被引用了一次。

print(sys.getrecursionlimit())  # setrecursionlimit().
print(sys.getsizeof(t))

print(sys._getframe(0))
else:

    class BatteryTime(enum.IntEnum):
        POWER_TIME_UNKNOWN = -1
        POWER_TIME_UNLIMITED = -2

    globals().update(BatteryTime.__members__)

# --- others

ENCODING = sys.getfilesystemencoding()
if not PY3:
    ENCODING_ERRS = "replace"
else:
    try:
        ENCODING_ERRS = sys.getfilesystemencodeerrors()  # py 3.6
    except AttributeError:
        ENCODING_ERRS = "surrogateescape" if POSIX else "replace"

# ===================================================================
# --- namedtuples
# ===================================================================

# --- for system functions

# psutil.swap_memory()
sswap = namedtuple('sswap',
                   ['total', 'used', 'free', 'percent', 'sin', 'sout'])
# psutil.disk_usage()
sdiskusage = namedtuple('sdiskusage', ['total', 'used', 'free', 'percent'])
# psutil.disk_io_counters()
示例#16
0
def write_sysinfo(filepath):
    import sys
    import platform

    import subprocess

    import bpy
    import gpu

    # pretty repr
    def prepr(v):
        r = repr(v)
        vt = type(v)
        if vt is bytes:
            r = r[2:-1]
        elif vt is list or vt is tuple:
            r = r[1:-1]
        return r

    with open(filepath, 'w', encoding="utf-8") as output:
        try:
            header = "= Blender %s System Information =\n" % bpy.app.version_string
            lilies = "%s\n\n" % ((len(header) - 1) * "=")
            output.write(lilies[:-1])
            output.write(header)
            output.write(lilies)

            def title(text):
                return "\n%s:\n%s" % (text, lilies)

            # build info
            output.write(title("Blender"))
            output.write(
                "version: %s, branch: %s, commit date: %s %s, hash: %s, type: %s\n"
                % (
                    bpy.app.version_string,
                    prepr(bpy.app.build_branch),
                    prepr(bpy.app.build_commit_date),
                    prepr(bpy.app.build_commit_time),
                    prepr(bpy.app.build_hash),
                    prepr(bpy.app.build_type),
                ))

            output.write(
                "build date: %s, %s\n" %
                (prepr(bpy.app.build_date), prepr(bpy.app.build_time)))
            output.write("platform: %s\n" % prepr(platform.platform()))
            output.write("binary path: %s\n" % prepr(bpy.app.binary_path))
            output.write("build cflags: %s\n" % prepr(bpy.app.build_cflags))
            output.write("build cxxflags: %s\n" %
                         prepr(bpy.app.build_cxxflags))
            output.write("build linkflags: %s\n" %
                         prepr(bpy.app.build_linkflags))
            output.write("build system: %s\n" % prepr(bpy.app.build_system))

            # Python info.
            output.write(title("Python"))
            output.write("version: %s\n" % (sys.version.replace("\n", " ")))
            output.write("file system encoding: %s:%s\n" % (
                sys.getfilesystemencoding(),
                sys.getfilesystemencodeerrors(),
            ))
            output.write("paths:\n")
            for p in sys.path:
                output.write("\t%r\n" % p)

            output.write(title("Python (External Binary)"))
            output.write("binary path: %s\n" % prepr(sys.executable))
            try:
                py_ver = prepr(
                    subprocess.check_output([
                        sys.executable,
                        "--version",
                    ]).strip())
            except Exception as e:
                py_ver = str(e)
            output.write("version: %s\n" % py_ver)
            del py_ver

            output.write(title("Directories"))
            output.write("scripts:\n")
            for p in bpy.utils.script_paths():
                output.write("\t%r\n" % p)
            output.write("user scripts: %r\n" % (bpy.utils.script_path_user()))
            output.write("pref scripts: %r\n" % (bpy.utils.script_path_pref()))
            output.write("datafiles: %r\n" %
                         (bpy.utils.user_resource('DATAFILES')))
            output.write("config: %r\n" % (bpy.utils.user_resource('CONFIG')))
            output.write("scripts : %r\n" %
                         (bpy.utils.user_resource('SCRIPTS')))
            output.write("autosave: %r\n" %
                         (bpy.utils.user_resource('AUTOSAVE')))
            output.write("tempdir: %r\n" % (bpy.app.tempdir))

            output.write(title("FFmpeg"))
            ffmpeg = bpy.app.ffmpeg
            if ffmpeg.supported:
                for lib in ("avcodec", "avdevice", "avformat", "avutil",
                            "swscale"):
                    output.write("%s:%s%r\n" %
                                 (lib, " " * (10 - len(lib)),
                                  getattr(ffmpeg, lib + "_version_string")))
            else:
                output.write("Blender was built without FFmpeg support\n")

            if bpy.app.build_options.sdl:
                output.write(title("SDL"))
                output.write("Version: %s\n" % bpy.app.sdl.version_string)
                output.write("Loading method: ")
                if bpy.app.build_options.sdl_dynload:
                    output.write(
                        "dynamically loaded by Blender (WITH_SDL_DYNLOAD=ON)\n"
                    )
                else:
                    output.write("linked (WITH_SDL_DYNLOAD=OFF)\n")
                if not bpy.app.sdl.available:
                    output.write(
                        "WARNING: Blender could not load SDL library\n")

            output.write(title("Other Libraries"))
            ocio = bpy.app.ocio
            output.write("OpenColorIO: ")
            if ocio.supported:
                if ocio.version_string == "fallback":
                    output.write(
                        "Blender was built with OpenColorIO, " +
                        "but it currently uses fallback color management.\n")
                else:
                    output.write("%s\n" % (ocio.version_string))
            else:
                output.write("Blender was built without OpenColorIO support\n")

            oiio = bpy.app.oiio
            output.write("OpenImageIO: ")
            if ocio.supported:
                output.write("%s\n" % (oiio.version_string))
            else:
                output.write("Blender was built without OpenImageIO support\n")

            output.write("OpenShadingLanguage: ")
            if bpy.app.build_options.cycles:
                if bpy.app.build_options.cycles_osl:
                    from _cycles import osl_version_string
                    output.write("%s\n" % (osl_version_string))
                else:
                    output.write(
                        "Blender was built without OpenShadingLanguage support in Cycles\n"
                    )
            else:
                output.write("Blender was built without Cycles support\n")

            opensubdiv = bpy.app.opensubdiv
            output.write("OpenSubdiv: ")
            if opensubdiv.supported:
                output.write("%s\n" % opensubdiv.version_string)
            else:
                output.write("Blender was built without OpenSubdiv support\n")

            openvdb = bpy.app.openvdb
            output.write("OpenVDB: ")
            if openvdb.supported:
                output.write("%s\n" % openvdb.version_string)
            else:
                output.write("Blender was built without OpenVDB support\n")

            alembic = bpy.app.alembic
            output.write("Alembic: ")
            if alembic.supported:
                output.write("%s\n" % alembic.version_string)
            else:
                output.write("Blender was built without Alembic support\n")

            usd = bpy.app.usd
            output.write("USD: ")
            if usd.supported:
                output.write("%s\n" % usd.version_string)
            else:
                output.write("Blender was built without USD support\n")

            if not bpy.app.build_options.sdl:
                output.write("SDL: Blender was built without SDL support\n")

            if bpy.app.background:
                output.write("\nOpenGL: missing, background mode\n")
            else:
                output.write(title("GPU"))
                output.write("renderer:\t%r\n" % gpu.platform.renderer_get())
                output.write("vendor:\t\t%r\n" % gpu.platform.vendor_get())
                output.write("version:\t%r\n" % gpu.platform.version_get())
                output.write("extensions:\n")

                glext = sorted(gpu.capabilities.extensions_get())

                for l in glext:
                    output.write("\t%s\n" % l)

                output.write(title("Implementation Dependent GPU Limits"))
                output.write("Maximum Batch Vertices:\t%d\n" %
                             gpu.capabilities.max_batch_vertices_get())
                output.write("Maximum Batch Indices:\t%d\n" %
                             gpu.capabilities.max_batch_indices_get())

                output.write("\nGLSL:\n")
                output.write("Maximum Varying Floats:\t%d\n" %
                             gpu.capabilities.max_varying_floats_get())
                output.write("Maximum Vertex Attributes:\t%d\n" %
                             gpu.capabilities.max_vertex_attribs_get())
                output.write("Maximum Vertex Uniform Components:\t%d\n" %
                             gpu.capabilities.max_uniforms_vert_get())
                output.write("Maximum Fragment Uniform Components:\t%d\n" %
                             gpu.capabilities.max_uniforms_frag_get())
                output.write("Maximum Vertex Image Units:\t%d\n" %
                             gpu.capabilities.max_textures_vert_get())
                output.write("Maximum Fragment Image Units:\t%d\n" %
                             gpu.capabilities.max_textures_frag_get())
                output.write("Maximum Pipeline Image Units:\t%d\n" %
                             gpu.capabilities.max_textures_get())

            if bpy.app.build_options.cycles:
                import cycles
                output.write(title("Cycles"))
                output.write(cycles.engine.system_info())

            import addon_utils
            addon_utils.modules()
            output.write(title("Enabled add-ons"))
            for addon in bpy.context.preferences.addons.keys():
                addon_mod = addon_utils.addons_fake_modules.get(addon, None)
                if addon_mod is None:
                    output.write("%s (MISSING)\n" % (addon))
                else:
                    output.write(
                        "%s (version: %s, path: %s)\n" %
                        (addon, addon_mod.bl_info.get(
                            'version', "UNKNOWN"), addon_mod.__file__))
        except Exception as e:
            output.write("ERROR: %s\n" % e)
示例#17
0
import sys

print('python executable:', sys.executable)
print(sys.argv)
assert sys.argv[0].endswith('.py')

assert sys.platform == "linux" or sys.platform == "darwin" or sys.platform == "win32" or sys.platform == "unknown"

assert isinstance(sys.builtin_module_names, tuple)
assert 'sys' in sys.builtin_module_names

assert isinstance(sys.implementation.name, str)
assert isinstance(sys.implementation.cache_tag, str)

assert sys.getfilesystemencoding() == 'utf-8'
assert sys.getfilesystemencodeerrors().startswith('surrogate')

assert sys.byteorder == "little" or sys.byteorder == "big"

assert isinstance(sys.flags, tuple)
assert type(sys.flags).__name__ == "flags"
assert type(sys.flags.optimize) is int
assert sys.flags[3] == sys.flags.optimize
assert sys.maxunicode == 1114111


# Tracing:

def trc(frame, event, arg):
    print('trace event:', frame, event, arg)
示例#18
0
    b'\xff',
    # undecodable from iso8859-3, iso8859-6, iso8859-7, cp424, iso8859-8, cp856
    # and cp857
    b'\xae\xd5'
    # undecodable from UTF-8 (UNIX and Mac OS X)
    b'\xed\xb2\x80', b'\xed\xb4\x80',
    # undecodable from shift_jis, cp869, cp874, cp932, cp1250, cp1251, cp1252,
    # cp1253, cp1254, cp1255, cp1257, cp1258
    b'\x81\x98',
):
    try:
        name.decode(sys.getfilesystemencoding())
    except UnicodeDecodeError:
        try:
            name.decode(sys.getfilesystemencoding(),
                        sys.getfilesystemencodeerrors())
        except UnicodeDecodeError:
            continue
        TESTFN_UNDECODABLE = os.fsencode(TESTFN_ASCII) + name
        break

if FS_NONASCII:
    TESTFN_NONASCII = TESTFN_ASCII + FS_NONASCII
else:
    TESTFN_NONASCII = None
TESTFN = TESTFN_NONASCII or TESTFN_ASCII


def make_bad_fd():
    """
    Create an invalid file descriptor by opening and closing a file and return