当前位置: 首页>>代码示例>>Python>>正文


Python sys.getfilesystemencoding方法代码示例

本文整理汇总了Python中sys.getfilesystemencoding方法的典型用法代码示例。如果您正苦于以下问题:Python sys.getfilesystemencoding方法的具体用法?Python sys.getfilesystemencoding怎么用?Python sys.getfilesystemencoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys的用法示例。


在下文中一共展示了sys.getfilesystemencoding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _rename

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def _rename(src, dst):
            '''
            if not isinstance(src, unicode):
                src = unicode(src, sys.getfilesystemencoding())
            if not isinstance(dst, unicode):
                dst = unicode(dst, sys.getfilesystemencoding())
            '''
            if _rename_atomic(src, dst):
                return True
            retry = 0
            rv = False
            while not rv and retry < 100:
                rv = _MoveFileEx(src, dst, _MOVEFILE_REPLACE_EXISTING |
                                           _MOVEFILE_WRITE_THROUGH)
                if not rv:
                    time.sleep(0.001)
                    retry += 1
            return rv

        # new in Vista and Windows Server 2008 
开发者ID:jojoin,项目名称:cutout,代码行数:22,代码来源:posixemulation.py

示例2: _initial_load

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def _initial_load():
  global _CUR_CONTEXT
  to_assign = {}

  ctx_path = os.environ.get(ENV_KEY)
  if ctx_path:
    if six.PY2:
      ctx_path = ctx_path.decode(sys.getfilesystemencoding())
    _LOGGER.debug('Loading LUCI_CONTEXT: %r', ctx_path)
    try:
      with open(ctx_path, 'r') as f:
        loaded = _to_utf8(json.load(f))
        if _check_ok(loaded):
          to_assign = loaded
    except OSError as ex:
      _LOGGER.error('LUCI_CONTEXT failed to open: %s', ex)
    except IOError as ex:
      _LOGGER.error('LUCI_CONTEXT failed to read: %s', ex)
    except ValueError as ex:
      _LOGGER.error('LUCI_CONTEXT failed to decode: %s', ex)

  _CUR_CONTEXT = to_assign 
开发者ID:luci,项目名称:recipes-py,代码行数:24,代码来源:luci_context.py

示例3: read_history

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def read_history(self):
        if fsutils.isfile(self.history_file):
            fp = fsutils.get_fileptr(self.history_file)
            lines = [line.strip(' \n\r') for line in fp.readlines()]
            for line in lines:
                items = line.split('\t')
                if len(items) == 3:
                    status = int(items[0])
                    path = items[1]
                    try:
                        path = path.decode('utf-8')
                    except Exception:
                        path = path.decode(sys.getfilesystemencoding())
                    finally:
                        path = path.encode('utf-8')
                    timestamp = int(items[2])
                    self.history.append([status, path, timestamp])
            fp.close() 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:20,代码来源:app_history.py

示例4: setPaths

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def setPaths():
    """
    Sets absolute paths for project directories and files
    """

    paths.POCSUITE_DATA_PATH = os.path.join(paths.POCSUITE_ROOT_PATH, "data")

    paths.USER_AGENTS = os.path.join(paths.POCSUITE_DATA_PATH, "user-agents.txt")
    paths.WEAK_PASS = os.path.join(paths.POCSUITE_DATA_PATH, "password-top100.txt")
    paths.LARGE_WEAK_PASS = os.path.join(paths.POCSUITE_DATA_PATH, "password-top1000.txt")

    _ = os.path.join(os.path.expanduser("~"), ".pocsuite")
    paths.POCSUITE_OUTPUT_PATH = getUnicode(paths.get("POCSUITE_OUTPUT_PATH", os.path.join(_, "output")), encoding=sys.getfilesystemencoding())

    paths.POCSUITE_MODULES_PATH = os.path.join(_, "modules")
    paths.POCSUITE_TMP_PATH = os.path.join(paths.POCSUITE_MODULES_PATH, "tmp")
    paths.POCSUITE_HOME_PATH = os.path.expanduser("~")
    paths.POCSUITE_RC_PATH = paths.POCSUITE_HOME_PATH + "/.pocsuiterc" 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:20,代码来源:common.py

示例5: get_filesystem_encoding

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def get_filesystem_encoding():
    """Returns the filesystem encoding that should be used. Note that this is
    different from the Python understanding of the filesystem encoding which
    might be deeply flawed. Do not use this value against Python's unicode APIs
    because it might be different. See :ref:`filesystem-encoding` for the exact
    behavior.

    The concept of a filesystem encoding in generally is not something you
    should rely on. As such if you ever need to use this function except for
    writing wrapper code reconsider.
    """
    global _warned_about_filesystem_encoding
    rv = sys.getfilesystemencoding()
    if has_likely_buggy_unicode_filesystem and not rv or _is_ascii_encoding(rv):
        if not _warned_about_filesystem_encoding:
            warnings.warn(
                "Detected a misconfigured UNIX filesystem: Will use"
                " UTF-8 as filesystem encoding instead of {0!r}".format(rv),
                BrokenFilesystemWarning,
            )
            _warned_about_filesystem_encoding = True
        return "utf-8"
    return rv 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:filesystem.py

示例6: fix_script

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def fix_script(path):
    """Replace #!python with #!/path/to/python
    Return True if file was changed."""
    # XXX RECORD hashes will need to be updated
    if os.path.isfile(path):
        with open(path, 'rb') as script:
            firstline = script.readline()
            if not firstline.startswith(b'#!python'):
                return False
            exename = sys.executable.encode(sys.getfilesystemencoding())
            firstline = b'#!' + exename + os.linesep.encode("ascii")
            rest = script.read()
        with open(path, 'wb') as script:
            script.write(firstline)
            script.write(rest)
        return True 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:wheel.py

示例7: setup_py

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def setup_py(self):
        assert self.source_dir, "No source dir for %s" % self
        try:
            import setuptools  # noqa
        except ImportError:
            if get_installed_version('setuptools') is None:
                add_msg = "Please install setuptools."
            else:
                add_msg = traceback.format_exc()
            # Setuptools is not available
            raise InstallationError(
                "Could not import setuptools which is required to "
                "install from a source distribution.\n%s" % add_msg
            )

        setup_py = os.path.join(self.setup_py_dir, 'setup.py')

        # Python2 __file__ should not be unicode
        if six.PY2 and isinstance(setup_py, six.text_type):
            setup_py = setup_py.encode(sys.getfilesystemencoding())

        return setup_py 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:req_install.py

示例8: make_dokuwiki_pagename

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def make_dokuwiki_pagename(mediawiki_name):
    """
    Convert a canonical mediawiki pagename to a dokuwiki pagename

    Any namespacing that is in the form of a / is replaced with a :
    """
    result = mediawiki_name.replace(" ","_")
    # We have pages that have ':' in them - replace with underscores
    result = result.replace(':', '_')
    result = names.clean_id(camel_to_underscore(result)).replace("/",":")
    # Some of our mediawiki page names begin with a '/', which results in os.path.join assuming the page is an absolute path.
    if result[0] == ':':
      result = result.lstrip(':')
    # Fix any pages that began with a space, because that breaks dokuwiki
    result = result.replace(":_", ":")
    result = codecs.encode(result, sys.getfilesystemencoding(), "replace")
    return result 
开发者ID:projectgus,项目名称:yamdwe,代码行数:19,代码来源:dokuwiki.py

示例9: process_open

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def process_open(command, quotes=(), env=None, sout=subprocess.PIPE, serr=subprocess.PIPE, newlines=True):
    # Linux py2.7 encode as list without quotes no empty element for parameters
    # linux py3.x no encode and as list without quotes no empty element for parameters
    # windows py2.7 encode as string with quotes empty element for parameters is okay
    # windows py 3.x no encode and as string with quotes empty element for parameters is okay
    # separate handling for windows and linux
    if os.name == 'nt':
        for key, element in enumerate(command):
            if key in quotes:
                command[key] = '"' + element + '"'
        exc_command = " ".join(command)
        if sys.version_info < (3, 0):
            exc_command = exc_command.encode(sys.getfilesystemencoding())
    else:
        if sys.version_info < (3, 0):
            exc_command = [x.encode(sys.getfilesystemencoding()) for x in command]
        else:
            exc_command = [x for x in command]

    return subprocess.Popen(exc_command, shell=False, stdout=sout, stderr=serr, universal_newlines=newlines, env=env) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:22,代码来源:subproc_wrapper.py

示例10: check_unrar

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def check_unrar(unrarLocation):
    if not unrarLocation:
        return

    if not os.path.exists(unrarLocation):
        return _('Unrar binary file not found')

    try:
        if sys.version_info < (3, 0):
            unrarLocation = unrarLocation.encode(sys.getfilesystemencoding())
        unrarLocation = [unrarLocation]
        for lines in process_wait(unrarLocation):
            value = re.search('UNRAR (.*) freeware', lines, re.IGNORECASE)
            if value:
                version = value.group(1)
                log.debug("unrar version %s", version)
                break
    except (OSError, UnicodeDecodeError) as err:
        log.exception(err)
        return _('Error excecuting UnRar') 
开发者ID:janeczku,项目名称:calibre-web,代码行数:22,代码来源:helper.py

示例11: get_filesystem_encoding

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def get_filesystem_encoding():
    """
    Returns the filesystem encoding that should be used. Note that this is
    different from the Python understanding of the filesystem encoding which
    might be deeply flawed. Do not use this value against Python's unicode APIs
    because it might be different. See :ref:`filesystem-encoding` for the exact
    behavior.

    The concept of a filesystem encoding in generally is not something you
    should rely on. As such if you ever need to use this function except for
    writing wrapper code reconsider.
    """
    global _warned_about_filesystem_encoding
    rv = sys.getfilesystemencoding()
    if has_likely_buggy_unicode_filesystem and not rv \
       or _is_ascii_encoding(rv):
        if not _warned_about_filesystem_encoding:
            warnings.warn(
                'Detected a misconfigured UNIX filesystem: Will use UTF-8 as '
                'filesystem encoding instead of {0!r}'.format(rv),
                BrokenFilesystemWarning)
            _warned_about_filesystem_encoding = True
        return 'utf-8'
    return rv 
开发者ID:jpush,项目名称:jbox,代码行数:26,代码来源:filesystem.py

示例12: _safe_path

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def _safe_path(self, path):
        enc_warn = "'%s' not %s encodable -- skipping"

        # To avoid accidental trans-codings errors, first to unicode
        u_path = unicode_utils.filesys_decode(path)
        if u_path is None:
            log.warn("'%s' in unexpected encoding -- skipping" % path)
            return False

        # Must ensure utf-8 encodability
        utf8_path = unicode_utils.try_encode(u_path, "utf-8")
        if utf8_path is None:
            log.warn(enc_warn, path, 'utf-8')
            return False

        try:
            # accept is either way checks out
            if os.path.exists(u_path) or os.path.exists(utf8_path):
                return True
        # this will catch any encode errors decoding u_path
        except UnicodeEncodeError:
            log.warn(enc_warn, path, sys.getfilesystemencoding()) 
开发者ID:jpush,项目名称:jbox,代码行数:24,代码来源:egg_info.py

示例13: __init__

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def __init__(self, name, loadfile):
        """
        Load a single plugin
        :param name: module name
        :param loadfile: the main .py file
        :raises Exception: Typically ImportError or OSError
        """

        self.name = name	# Display name.
        self.folder = name	# basename of plugin folder. None for internal plugins.
        self.module = None	# None for disabled plugins.

        if loadfile:
            sys.stdout.write(('loading plugin %s from "%s"\n' % (name.replace('.', '_'), loadfile)).encode('utf-8'))
            with open(loadfile, 'rb') as plugfile:
                module = imp.load_module('plugin_%s' % name.encode('ascii', 'replace').replace('.', '_'), plugfile, loadfile.encode(sys.getfilesystemencoding()),
                                         ('.py', 'r', imp.PY_SOURCE))
                if module.plugin_start.func_code.co_argcount == 0:
                    newname = module.plugin_start()
                else:
                    newname = module.plugin_start(os.path.dirname(loadfile))
                self.name = newname and unicode(newname) or name
                self.module = module
        else:
            sys.stdout.write('plugin %s disabled\n' % name) 
开发者ID:EDCD,项目名称:EDMarketConnector,代码行数:27,代码来源:plug.py

示例14: _check_unicode_filesystem

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def _check_unicode_filesystem(tmpdir):
    filename = tmpdir / ntou('☃', 'utf-8')
    tmpl = 'File system encoding ({encoding}) cannot support unicode filenames'
    msg = tmpl.format(encoding=sys.getfilesystemencoding())
    try:
        io.open(str(filename), 'w').close()
    except UnicodeEncodeError:
        pytest.skip(msg) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:10,代码来源:test_static.py

示例15: ensure_byte_string

# 需要导入模块: import sys [as 别名]
# 或者: from sys import getfilesystemencoding [as 别名]
def ensure_byte_string(value):
    """
    Return the given ``value`` as bytestring.

    If the given ``value`` is not a byte string, but a real unicode string, it
    is encoded with the filesystem encoding (as in
    :func:`sys.getfilesystemencoding()`).
    """
    if not isinstance(value, bytes):
        value = value.encode(sys.getfilesystemencoding())
    return value 
开发者ID:mbusb,项目名称:multibootusb,代码行数:13,代码来源:_util.py


注:本文中的sys.getfilesystemencoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。