示例#1
0
def _select_progress_class(preferred, fallback):
    encoding = getattr(preferred.file, "encoding", None)

    # If we don't know what encoding this file is in, then we'll just assume
    # that it doesn't support unicode and use the ASCII bar.
    if not encoding:
        return fallback

    # Collect all of the possible characters we want to use with the preferred
    # bar.
    characters = [
        getattr(preferred, "empty_fill", six.text_type()),
        getattr(preferred, "fill", six.text_type()),
    ]
    characters += list(getattr(preferred, "phases", []))

    # Try to decode the characters we're using for the bar using the encoding
    # of the given file, if this works then we'll assume that we can use the
    # fancier bar and if not we'll fall back to the plaintext bar.
    try:
        six.text_type().join(characters).encode(encoding)
    except UnicodeEncodeError:
        return fallback
    else:
        return preferred
示例#2
0
def _select_progress_class(preferred, fallback):
    encoding = getattr(preferred.file, "encoding", None)

    # If we don't know what encoding this file is in, then we'll just assume
    # that it doesn't support unicode and use the ASCII bar.
    if not encoding:
        return fallback

    # Collect all of the possible characters we want to use with the preferred
    # bar.
    characters = [
        getattr(preferred, "empty_fill", six.text_type()),
        getattr(preferred, "fill", six.text_type()),
    ]
    characters += list(getattr(preferred, "phases", []))

    # Try to decode the characters we're using for the bar using the encoding
    # of the given file, if this works then we'll assume that we can use the
    # fancier bar and if not we'll fall back to the plaintext bar.
    try:
        six.text_type().join(characters).encode(encoding)
    except UnicodeEncodeError:
        return fallback
    else:
        return preferred
示例#3
0
def format_for_json(packages, options):
    data = []
    for dist in packages:
        info = {
            'name': dist.project_name,
            'version': six.text_type(dist.version),
        }
        if options.outdated:
            info['latest_version'] = six.text_type(dist.latest_version)
            info['latest_filetype'] = dist.latest_filetype
        data.append(info)
    return json.dumps(data)
示例#4
0
def format_for_json(packages, options):
    data = []
    for dist in packages:
        info = {
            'name': dist.project_name,
            'version': six.text_type(dist.version),
        }
        if options.outdated:
            info['latest_version'] = six.text_type(dist.latest_version)
            info['latest_filetype'] = dist.latest_filetype
        data.append(info)
    return json.dumps(data)
示例#5
0
def format_for_json(packages, options):
    data = []
    for dist in packages:
        info = {"name": dist.project_name, "version": six.text_type(dist.version)}
        if options.verbose >= 1:
            info["location"] = dist.location
            info["installer"] = get_installer(dist)
        if options.outdated:
            info["latest_version"] = six.text_type(dist.latest_version)
            info["latest_filetype"] = dist.latest_filetype
        data.append(info)
    return json.dumps(data)
示例#6
0
def format_for_json(packages, options):
    data = []
    for dist in packages:
        info = {
            'name': dist.project_name,
            'version': six.text_type(dist.version),
        }
        if options.verbose >= 1:
            info['location'] = dist.location
            info['installer'] = get_installer(dist)
        if options.outdated:
            info['latest_version'] = six.text_type(dist.latest_version)
            info['latest_filetype'] = dist.latest_filetype
        data.append(info)
    return DealJson.dumps(data)
示例#7
0
def _get_win_folder_with_pywin32(csidl_name):
    from win32com.shell import shellcon, shell
    directory = shell.SHGetFolderPath(0, getattr(shellcon, csidl_name), 0, 0)
    # Try to make this a unicode path because SHGetFolderPath does
    # not return unicode strings when there is unicode data in the
    # path.
    try:
        directory = six.text_type(directory)

        # Downgrade to short path name if have highbit chars. See
        # <http://bugs.activestate.com/show_bug.cgi?id=85099>.
        has_high_char = False
        for c in directory:
            if ord(c) > 255:
                has_high_char = True
                break
        if has_high_char:
            try:
                import win32api
                directory = win32api.GetShortPathName(directory)
            except ImportError:
                pass
    except UnicodeError:
        pass
    return directory
示例#8
0
def _get_win_folder_with_pywin32(csidl_name):
    from win32com.shell import shellcon, shell
    directory = shell.SHGetFolderPath(0, getattr(shellcon, csidl_name), 0, 0)
    # Try to make this a unicode path because SHGetFolderPath does
    # not return unicode strings when there is unicode data in the
    # path.
    try:
        directory = six.text_type(directory)

        # Downgrade to short path name if have highbit chars. See
        # <http://bugs.activestate.com/show_bug.cgi?id=85099>.
        has_high_char = False
        for c in directory:
            if ord(c) > 255:
                has_high_char = True
                break
        if has_high_char:
            try:
                import win32api
                directory = win32api.GetShortPathName(directory)
            except ImportError:
                pass
    except UnicodeError:
        pass
    return directory
示例#9
0
文件: utils.py 项目: daburnett1/Barky
def force_text(s):
    """
    Return a string representing `s`.
    """
    if s is None:
        return ""
    if not isinstance(s, six.string_types):
        return six.text_type(s)
    return s
示例#10
0
文件: _base.py 项目: LoveShun/wc
def to_text(s, blank_if_none=True):
    """Wrapper around six.text_type to convert None to empty string"""
    if s is None:
        if blank_if_none:
            return ""
        else:
            return None
    elif isinstance(s, text_type):
        return s
    else:
        return text_type(s)
示例#11
0
def to_text(s, blank_if_none=True):
    """Wrapper around six.text_type to convert None to empty string"""
    if s is None:
        if blank_if_none:
            return ""
        else:
            return None
    elif isinstance(s, text_type):
        return s
    else:
        return text_type(s)
示例#12
0
文件: _base.py 项目: LoveShun/wc
    def startTag(self, namespace, name, attrs):
        assert namespace is None or isinstance(namespace, string_types), type(namespace)
        assert isinstance(name, string_types), type(name)
        assert all((namespace is None or isinstance(namespace, string_types)) and
                   isinstance(name, string_types) and
                   isinstance(value, string_types)
                   for (namespace, name), value in attrs.items())

        return {"type": "StartTag",
                "name": text_type(name),
                "namespace": to_text(namespace),
                "data": dict(((to_text(namespace, False), to_text(name)),
                              to_text(value, False))
                             for (namespace, name), value in attrs.items())}
示例#13
0
def create_basic_sdist_for_package(
    script, name, version, extra_files=None
):
    files = {
        "setup.py": """
            from setuptools import find_packages, setup
            setup(name={name!r}, version={version!r})
        """,
    }

    # Some useful shorthands
    archive_name = "{name}-{version}.tar.gz".format(
        name=name, version=version
    )

    # Replace key-values with formatted values
    for key, value in list(files.items()):
        del files[key]
        key = key.format(name=name)
        files[key] = textwrap.dedent(value).format(
            name=name, version=version
        ).strip()

    # Add new files after formatting
    if extra_files:
        files.update(extra_files)

    for fname in files:
        path = script.temp_path / fname
        path.parent.mkdir(exist_ok=True, parents=True)
        path.write_bytes(ensure_binary(files[fname]))

    # The base_dir cast is required to make `shutil.make_archive()` use
    # Unicode paths on Python 2, making it able to properly archive
    # files with non-ASCII names.
    retval = script.scratch_path / archive_name
    generated = shutil.make_archive(
        retval,
        'gztar',
        root_dir=script.temp_path,
        base_dir=text_type(os.curdir),
    )
    shutil.move(generated, retval)

    shutil.rmtree(script.temp_path)
    script.temp_path.mkdir()

    return retval
示例#14
0
    def startTag(self, namespace, name, attrs):
        assert namespace is None or isinstance(namespace,
                                               string_types), type(namespace)
        assert isinstance(name, string_types), type(name)
        assert all(
            (namespace is None or isinstance(namespace, string_types)) and
            isinstance(name, string_types) and isinstance(value, string_types)
            for (namespace, name), value in attrs.items())

        return {
            "type":
            "StartTag",
            "name":
            text_type(name),
            "namespace":
            to_text(namespace),
            "data":
            dict(((to_text(namespace, False), to_text(name)),
                  to_text(value, False))
                 for (namespace, name), value in attrs.items())
        }
示例#15
0
文件: _base.py 项目: LoveShun/wc
    def entity(self, name):
        assert isinstance(name, string_types), type(name)

        return {"type": "Entity", "name": text_type(name)}
示例#16
0
文件: _base.py 项目: LoveShun/wc
    def comment(self, data):
        assert isinstance(data, string_types), type(data)

        return {"type": "Comment", "data": text_type(data)}
示例#17
0
                    yield token
            yield self.endTag(name)

from xml.dom import Node

DOCUMENT = Node.DOCUMENT_NODE
DOCTYPE = Node.DOCUMENT_TYPE_NODE
TEXT = Node.TEXT_NODE
ELEMENT = Node.ELEMENT_NODE
COMMENT = Node.COMMENT_NODE
ENTITY = Node.ENTITY_NODE
UNKNOWN = "<#UNKNOWN#>"
=======
        assert isinstance(data, string_types), type(data)

        return {"type": "Comment", "data": text_type(data)}

    def doctype(self, name, publicId=None, systemId=None, correct=True):
        assert is_text_or_none(name), type(name)
        assert is_text_or_none(publicId), type(publicId)
        assert is_text_or_none(systemId), type(systemId)

        return {"type": "Doctype",
                "name": to_text(name),
                "publicId": to_text(publicId),
                "systemId": to_text(systemId),
                "correct": to_text(correct)}

    def entity(self, name):
        assert isinstance(name, string_types), type(name)
示例#18
0
文件: __init__.py 项目: zhongyan6/pip
def create_basic_wheel_for_package(script,
                                   name,
                                   version,
                                   depends=None,
                                   extras=None,
                                   extra_files=None):
    if depends is None:
        depends = []
    if extras is None:
        extras = {}
    files = {
        "{name}/__init__.py": """
            __version__ = {version!r}
            def hello():
                return "Hello From {name}"
        """,
        "{dist_info}/DESCRIPTION": """
            UNKNOWN
        """,
        "{dist_info}/WHEEL": """
            Wheel-Version: 1.0
            Generator: pip-test-suite
            Root-Is-Purelib: true
            Tag: py2-none-any
            Tag: py3-none-any


        """,
        "{dist_info}/METADATA": """
            Metadata-Version: 2.0
            Name: {name}
            Version: {version}
            Summary: UNKNOWN
            Home-page: UNKNOWN
            Author: UNKNOWN
            Author-email: UNKNOWN
            License: UNKNOWN
            Platform: UNKNOWN
            {requires_dist}

            UNKNOWN
        """,
        "{dist_info}/top_level.txt": """
            {name}
        """,
        # Have an empty RECORD because we don't want to be checking hashes.
        "{dist_info}/RECORD": ""
    }

    # Some useful shorthands
    archive_name = "{name}-{version}-py2.py3-none-any.whl".format(
        name=name, version=version)
    dist_info = "{name}-{version}.dist-info".format(name=name, version=version)

    requires_dist = "\n".join(
        ["Requires-Dist: {}".format(pkg) for pkg in depends] +
        ["Provides-Extra: {}".format(pkg) for pkg in extras.keys()] + [
            "Requires-Dist: {}; extra == \"{}\"".format(pkg, extra)
            for extra in extras for pkg in extras[extra]
        ])

    # Replace key-values with formatted values
    for key, value in list(files.items()):
        del files[key]
        key = key.format(name=name, dist_info=dist_info)
        files[key] = textwrap.dedent(value).format(
            name=name, version=version, requires_dist=requires_dist).strip()

    # Add new files after formatting
    if extra_files:
        files.update(extra_files)

    for fname in files:
        path = script.temp_path / fname
        path.parent.mkdir(exist_ok=True, parents=True)
        path.write_bytes(ensure_binary(files[fname]))

    # The base_dir cast is required to make `shutil.make_archive()` use
    # Unicode paths on Python 2, making it able to properly archive
    # files with non-ASCII names.
    retval = script.scratch_path / archive_name
    generated = shutil.make_archive(
        retval,
        'zip',
        root_dir=script.temp_path,
        base_dir=text_type(os.curdir),
    )
    shutil.move(generated, retval)

    shutil.rmtree(script.temp_path)
    script.temp_path.mkdir()

    return retval
示例#19
0
 def _make_hash_value(self, user, timestamp):
     return (text_type(user.pk) + text_type(timestamp) +
             text_type(user.is_active))
示例#20
0
 def _make_hash_value(self, user, timestamp):
     return (six.text_type(user.pk) + six.text_type(timestamp) +
             six.text_type(user.profile.email_confirmed))
示例#21
0
    def entity(self, name):
        assert isinstance(name, string_types), type(name)

        return {"type": "Entity", "name": text_type(name)}
示例#22
0
    def comment(self, data):
        assert isinstance(data, string_types), type(data)

        return {"type": "Comment", "data": text_type(data)}