當前位置: 首頁>>代碼示例>>Python>>正文


Python six.PY2屬性代碼示例

本文整理匯總了Python中setuptools.extern.six.PY2屬性的典型用法代碼示例。如果您正苦於以下問題:Python six.PY2屬性的具體用法?Python six.PY2怎麽用?Python six.PY2使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在setuptools.extern.six的用法示例。


在下文中一共展示了six.PY2屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _try_str

# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import PY2 [as 別名]
def _try_str(val):
        """
        On Python 2, much of distutils relies on string values being of
        type 'str' (bytes) and not unicode text. If the value can be safely
        encoded to bytes using the default encoding, prefer that.

        Why the default encoding? Because that value can be implicitly
        decoded back to text if needed.

        Ref #1653
        """
        if not six.PY2:
            return val
        try:
            return val.encode()
        except UnicodeEncodeError:
            pass
        return val 
開發者ID:ali5h,項目名稱:rules_pip,代碼行數:20,代碼來源:dist.py

示例2: read_manifest

# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import PY2 [as 別名]
def read_manifest(self):
        """Read the manifest file (named by 'self.manifest') and use it to
        fill in 'self.filelist', the list of files to include in the source
        distribution.
        """
        log.info("reading manifest file '%s'", self.manifest)
        manifest = open(self.manifest, 'rb')
        for line in manifest:
            # The manifest must contain UTF-8. See #303.
            if not six.PY2:
                try:
                    line = line.decode('UTF-8')
                except UnicodeDecodeError:
                    log.warn("%r not UTF-8 decodable -- skipping" % line)
                    continue
            # ignore comments and blank lines
            line = line.strip()
            if line.startswith('#') or not line:
                continue
            self.filelist.append(line)
        manifest.close() 
開發者ID:ali5h,項目名稱:rules_pip,代碼行數:23,代碼來源:sdist.py

示例3: get_ext_filename

# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import PY2 [as 別名]
def get_ext_filename(self, fullname):
        filename = _build_ext.get_ext_filename(self, fullname)
        if fullname in self.ext_map:
            ext = self.ext_map[fullname]
            use_abi3 = (
                not six.PY2
                and getattr(ext, 'py_limited_api')
                and get_abi3_suffix()
            )
            if use_abi3:
                so_ext = get_config_var('EXT_SUFFIX')
                filename = filename[:-len(so_ext)]
                filename = filename + get_abi3_suffix()
            if isinstance(ext, Library):
                fn, ext = os.path.splitext(filename)
                return self.shlib_compiler.library_filename(fn, libtype)
            elif use_stubs and ext._links_to_dynamic:
                d, fn = os.path.split(filename)
                return os.path.join(d, 'dl-' + fn)
        return filename 
開發者ID:ali5h,項目名稱:rules_pip,代碼行數:22,代碼來源:build_ext.py

示例4: handle_display_options

# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import PY2 [as 別名]
def handle_display_options(self, option_order):
        """If there were any non-global "display-only" options
        (--help-commands or the metadata display options) on the command
        line, display the requested info and return true; else return
        false.
        """
        import sys

        if six.PY2 or self.help_commands:
            return _Distribution.handle_display_options(self, option_order)

        # Stdout may be StringIO (e.g. in tests)
        import io
        if not isinstance(sys.stdout, io.TextIOWrapper):
            return _Distribution.handle_display_options(self, option_order)

        # Don't wrap stdout if utf-8 is already the encoding. Provides
        #  workaround for #334.
        if sys.stdout.encoding.lower() in ('utf-8', 'utf8'):
            return _Distribution.handle_display_options(self, option_order)

        # Print metadata in UTF-8 no matter the platform
        encoding = sys.stdout.encoding
        errors = sys.stdout.errors
        newline = sys.platform != 'win32' and '\n' or None
        line_buffering = sys.stdout.line_buffering

        sys.stdout = io.TextIOWrapper(
            sys.stdout.detach(), 'utf-8', errors, newline, line_buffering)
        try:
            return _Distribution.handle_display_options(self, option_order)
        finally:
            sys.stdout = io.TextIOWrapper(
                sys.stdout.detach(), encoding, errors, newline, line_buffering)


# Install it throughout the distutils 
開發者ID:jpush,項目名稱:jbox,代碼行數:39,代碼來源:dist.py

示例5: load_launcher_manifest

# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import PY2 [as 別名]
def load_launcher_manifest(name):
    manifest = pkg_resources.resource_string(__name__, 'launcher manifest.xml')
    if six.PY2:
        return manifest % vars()
    else:
        return manifest.decode('utf-8') % vars() 
開發者ID:jpush,項目名稱:jbox,代碼行數:8,代碼來源:easy_install.py

示例6: handle_display_options

# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import PY2 [as 別名]
def handle_display_options(self, option_order):
        """If there were any non-global "display-only" options
        (--help-commands or the metadata display options) on the command
        line, display the requested info and return true; else return
        false.
        """
        import sys

        if six.PY2 or self.help_commands:
            return _Distribution.handle_display_options(self, option_order)

        # Stdout may be StringIO (e.g. in tests)
        import io
        if not isinstance(sys.stdout, io.TextIOWrapper):
            return _Distribution.handle_display_options(self, option_order)

        # Don't wrap stdout if utf-8 is already the encoding. Provides
        #  workaround for #334.
        if sys.stdout.encoding.lower() in ('utf-8', 'utf8'):
            return _Distribution.handle_display_options(self, option_order)

        # Print metadata in UTF-8 no matter the platform
        encoding = sys.stdout.encoding
        errors = sys.stdout.errors
        newline = sys.platform != 'win32' and '\n' or None
        line_buffering = sys.stdout.line_buffering

        sys.stdout = io.TextIOWrapper(
            sys.stdout.detach(), 'utf-8', errors, newline, line_buffering)
        try:
            return _Distribution.handle_display_options(self, option_order)
        finally:
            sys.stdout = io.TextIOWrapper(
                sys.stdout.detach(), encoding, errors, newline, line_buffering) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:36,代碼來源:dist.py

示例7: _add_defaults_data_files

# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import PY2 [as 別名]
def _add_defaults_data_files(self):
        try:
            if six.PY2:
                sdist_add_defaults._add_defaults_data_files(self)
            else:
                super()._add_defaults_data_files()
        except TypeError:
            log.warn("data_files contains unexpected objects") 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:10,代碼來源:sdist.py

示例8: build_module

# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import PY2 [as 別名]
def build_module(self, module, module_file, package):
        if six.PY2 and isinstance(package, six.string_types):
            # avoid errors on Python 2 when unicode is passed (#190)
            package = package.split('.')
        outfile, copied = orig.build_py.build_module(self, module, module_file,
                                                     package)
        if copied:
            self.__updated_files.append(outfile)
        return outfile, copied 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:11,代碼來源:build_py.py

示例9: scan_module

# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import PY2 [as 別名]
def scan_module(egg_dir, base, name, stubs):
    """Check whether module possibly uses unsafe-for-zipfile stuff"""

    filename = os.path.join(base, name)
    if filename[:-1] in stubs:
        return True  # Extension module
    pkg = base[len(egg_dir) + 1:].replace(os.sep, '.')
    module = pkg + (pkg and '.' or '') + os.path.splitext(name)[0]
    if six.PY2:
        skip = 8  # skip magic & date
    elif sys.version_info < (3, 7):
        skip = 12  # skip magic & date & file size
    else:
        skip = 16  # skip magic & reserved? & date & file size
    f = open(filename, 'rb')
    f.read(skip)
    code = marshal.load(f)
    f.close()
    safe = True
    symbols = dict.fromkeys(iter_symbols(code))
    for bad in ['__file__', '__path__']:
        if bad in symbols:
            log.warn("%s: module references %s", module, bad)
            safe = False
    if 'inspect' in symbols:
        for bad in [
            'getsource', 'getabsfile', 'getsourcefile', 'getfile'
            'getsourcelines', 'findsource', 'getcomments', 'getframeinfo',
            'getinnerframes', 'getouterframes', 'stack', 'trace'
        ]:
            if bad in symbols:
                log.warn("%s: module MAY be using inspect.%s", module, bad)
                safe = False
    return safe 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:36,代碼來源:bdist_egg.py

示例10: handle_display_options

# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import PY2 [as 別名]
def handle_display_options(self, option_order):
        """If there were any non-global "display-only" options
        (--help-commands or the metadata display options) on the command
        line, display the requested info and return true; else return
        false.
        """
        import sys

        if six.PY2 or self.help_commands:
            return _Distribution.handle_display_options(self, option_order)

        # Stdout may be StringIO (e.g. in tests)
        if not isinstance(sys.stdout, io.TextIOWrapper):
            return _Distribution.handle_display_options(self, option_order)

        # Don't wrap stdout if utf-8 is already the encoding. Provides
        #  workaround for #334.
        if sys.stdout.encoding.lower() in ('utf-8', 'utf8'):
            return _Distribution.handle_display_options(self, option_order)

        # Print metadata in UTF-8 no matter the platform
        encoding = sys.stdout.encoding
        errors = sys.stdout.errors
        newline = sys.platform != 'win32' and '\n' or None
        line_buffering = sys.stdout.line_buffering

        sys.stdout = io.TextIOWrapper(
            sys.stdout.detach(), 'utf-8', errors, newline, line_buffering)
        try:
            return _Distribution.handle_display_options(self, option_order)
        finally:
            sys.stdout = io.TextIOWrapper(
                sys.stdout.detach(), encoding, errors, newline, line_buffering) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:35,代碼來源:dist.py


注:本文中的setuptools.extern.six.PY2屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。