How to use the future.utils.PY3 function in future

To help you get started, we’ve selected a few future examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyglet / pyglet / tests / extlibs / future / py2_3 / future / backports / urllib / request.py View on Github external
return result

def urlcleanup():
    for temp_file in _url_tempfiles:
        try:
            os.unlink(temp_file)
        except EnvironmentError:
            pass

    del _url_tempfiles[:]
    global _opener
    if _opener:
        _opener = None

if PY3:
    _cut_port_re = re.compile(r":\d+$", re.ASCII)
else:
    _cut_port_re = re.compile(r":\d+$")

def request_host(request):

    """Return request-host, as defined by RFC 2965.

    Variation from RFC: returned value is lowercased, for convenient
    comparison.

    """
    url = request.full_url
    host = urlparse(url)[1]
    if host == "":
        host = request.get_header("Host", "")
github pyglet / pyglet / tests / extlibs / future / py2_3 / future / moves / urllib / __init__.py View on Github external
from __future__ import absolute_import
from future.utils import PY3

if not PY3:
    __future_module__ = True
github konstellation-io / science-toolkit / vscode / extensions / ms-python.python-2020.3.69010 / pythonFiles / lib / python / future / backports / urllib / request.py View on Github external
return result

def urlcleanup():
    for temp_file in _url_tempfiles:
        try:
            os.unlink(temp_file)
        except EnvironmentError:
            pass

    del _url_tempfiles[:]
    global _opener
    if _opener:
        _opener = None

if PY3:
    _cut_port_re = re.compile(r":\d+$", re.ASCII)
else:
    _cut_port_re = re.compile(r":\d+$")

def request_host(request):

    """Return request-host, as defined by RFC 2965.

    Variation from RFC: returned value is lowercased, for convenient
    comparison.

    """
    url = request.full_url
    host = urlparse(url)[1]
    if host == "":
        host = request.get_header("Host", "")
github konstellation-io / science-toolkit / vscode / extensions / ms-python.python-2020.3.69010 / pythonFiles / lib / python / future / types / newbytes.py View on Github external
import string
import copy

from future.utils import istext, isbytes, PY2, PY3, with_metaclass
from future.types import no, issubset
from future.types.newobject import newobject

if PY2:
    from collections import Iterable
else:
    from collections.abc import Iterable


_builtin_bytes = bytes

if PY3:
    # We'll probably never use newstr on Py3 anyway...
    unicode = str


class BaseNewBytes(type):
    def __instancecheck__(cls, instance):
        if cls == newbytes:
            return isinstance(instance, _builtin_bytes)
        else:
            return issubclass(instance.__class__, cls)


def _newchr(x):
    if isinstance(x, str):  # this happens on pypy
        return x.encode('ascii')
    else:
github cea-sec / ivre / ivre / db / sql / tables.py View on Github external
def bind_processor(self, dialect):
        if PY3:
            def process(value):
                return self.python_type(
                    b"" if not value else utils.ip2bin(value)
                )
        else:
            def process(value):
                if not value:
                    return self.python_type(b"")
                if isinstance(value, str) and INTERNAL_IP_PY2.search(value):
                    return self.python_type(value)
                return self.python_type(utils.encode_hex(utils.ip2bin(value)))
        return process
github khalim19 / gimp-plugin-export-layers / pygimplib / lib / future / future / moves / urllib / parse.py View on Github external
from __future__ import absolute_import
from future.standard_library import suspend_hooks

from future.utils import PY3

if PY3:
    from urllib.parse import *
else:
    __future_module__ = True
    from urlparse import (ParseResult, SplitResult, parse_qs, parse_qsl,
                          urldefrag, urljoin, urlparse, urlsplit,
                          urlunparse, urlunsplit)
    
    # we use this method to get at the original py2 urllib before any renaming
    # quote = sys.py2_modules['urllib'].quote
    # quote_plus = sys.py2_modules['urllib'].quote_plus
    # unquote = sys.py2_modules['urllib'].unquote
    # unquote_plus = sys.py2_modules['urllib'].unquote_plus
    # urlencode = sys.py2_modules['urllib'].urlencode
    # splitquery = sys.py2_modules['urllib'].splitquery
    
    with suspend_hooks():
github khalim19 / gimp-plugin-export-layers / pygimplib / lib / future / future / moves / http / server.py View on Github external
from __future__ import absolute_import
from future.utils import PY3

if PY3:
    from http.server import *
else:
    __future_module__ = True
    from BaseHTTPServer import *
    from CGIHTTPServer import *
    from SimpleHTTPServer import *
    try:
        from CGIHTTPServer import _url_collapse_path     # needed for a test
    except ImportError:
        try:
            # Python 2.7.0 to 2.7.3
            from CGIHTTPServer import (
                _url_collapse_path_split as _url_collapse_path)
        except ImportError:
            # Doesn't exist on Python 2.6.x. Ignore it.
            pass
github PythonCharmers / python-future / src / tkinter / font.py View on Github external
from __future__ import absolute_import

from future.utils import PY3

if PY3:
    from tkinter.font import *
else:
    try:
        from tkFont import *
    except ImportError:
        raise ImportError('The tkFont module is missing. Does your Py2 '
                          'installation include tkinter?')
github cea-sec / miasm / miasm2 / core / bin_stream.py View on Github external
def __str__(self):
        if PY3:
            return repr(self)
        return self.__bytes__()
github khalim19 / gimp-plugin-export-layers / export_layers / pygimplib / _lib / future / future / moves / pickle.py View on Github external
from __future__ import absolute_import
from future.utils import PY3

if PY3:
    from pickle import *
else:
    __future_module__ = True
    try:
        from cPickle import *
    except ImportError:
        from pickle import *