Exemple #1
0
 def test_custom_move_attribute(self):
     attr = six.MovedAttribute('spam', 'six', 'six', 'u', 'u')
     six.add_move(attr)
     six.remove_move('spam')
     assert not hasattr(six.moves, 'spam')
     attr = six.MovedAttribute('spam', 'six', 'six', 'u', 'u')
     six.add_move(attr)
     from six.moves import spam
     assert spam is six.u
     six.remove_move('spam')
     assert not hasattr(six.moves, 'spam')
Exemple #2
0
 def test_custom_move_attribute(self):
     attr = six.MovedAttribute("spam", "six", "six", "u", "u")
     six.add_move(attr)
     six.remove_move("spam")
     assert not hasattr(six.moves, "spam")
     attr = six.MovedAttribute("spam", "six", "six", "u", "u")
     six.add_move(attr)
     from six.moves import spam
     assert spam is six.u
     six.remove_move("spam")
     assert not hasattr(six.moves, "spam")
Exemple #3
0
 def test_moved_attribute(self):
     attr = six.MovedAttribute("spam", "foo", "bar")
     if six.PY3:
         assert attr.mod == "bar"
     else:
         assert attr.mod == "foo"
     assert attr.attr == "spam"
     attr = six.MovedAttribute("spam", "foo", "bar", "lemma")
     assert attr.attr == "lemma"
     attr = six.MovedAttribute("spam", "foo", "bar", "lemma", "theorm")
     if six.PY3:
         assert attr.attr == "theorm"
     else:
         assert attr.attr == "lemma"
Exemple #4
0
 def test_moved_attribute(self):
     attr = six.MovedAttribute('spam', 'foo', 'bar')
     if six.PY3:
         assert attr.mod == 'bar'
     else:
         assert attr.mod == 'foo'
     assert attr.attr == 'spam'
     attr = six.MovedAttribute('spam', 'foo', 'bar', 'lemma')
     assert attr.attr == 'lemma'
     attr = six.MovedAttribute('spam', 'foo', 'bar', 'lemma', 'theorm')
     if six.PY3:
         assert attr.attr == 'theorm'
     else:
         assert attr.attr == 'lemma'
Exemple #5
0
import io
import itertools
import os
import re
from fnmatch import fnmatch

import attr
import six
import vistir
from packaging.version import LegacyVersion, Version

from .environment import MYPY_RUNNING, PYENV_ROOT
from .exceptions import InvalidPythonVersion

six.add_move(six.MovedAttribute("Iterable", "collections",
                                "collections.abc"))  # type: ignore  # noqa
six.add_move(six.MovedAttribute("Sequence", "collections",
                                "collections.abc"))  # type: ignore  # noqa
# fmt: off
from six.moves import Iterable  # type: ignore  # noqa  # isort:skip
from six.moves import Sequence  # type: ignore  # noqa  # isort:skip
# fmt: on

try:
    from functools import lru_cache
except ImportError:
    from backports.functools_lru_cache import lru_cache  # type: ignore  # noqa

if MYPY_RUNNING:
    from typing import Any, Union, List, Callable, Set, Tuple, Dict, Optional, Iterator
    from attr.validators import _OptionalValidator  # type: ignore
Exemple #6
0
import shutil
import stat
import sys
import toml
import tomlkit
import warnings

import crayons
import parse
import six

from click import echo as click_echo
from first import first
from vistir.misc import fs_str

six.add_move(six.MovedAttribute("Mapping", "collections", "collections.abc"))
six.add_move(six.MovedAttribute("Sequence", "collections", "collections.abc"))
from six.moves import Mapping, Sequence

from vistir.compat import ResourceWarning

try:
    from weakref import finalize
except ImportError:
    try:
        from .vendor.backports.weakref import finalize
    except ImportError:

        class finalize(object):
            def __init__(self, *args, **kwargs):
                logging.warn("weakref.finalize unavailable, not cleaning...")
Exemple #7
0
# -*- coding=utf-8 -*-
import importlib
import os
import sys
from collections import namedtuple
from contextlib import contextmanager

import six

# format: off
six.add_move(six.MovedAttribute("Callable", "collections", "collections.abc"))  # noqa
from six.moves import Callable  # type: ignore  # noqa  # isort:skip

# format: on


class _shims(object):
    CURRENT_PIP_VERSION = "19.1.1"
    BASE_IMPORT_PATH = os.environ.get("PIP_SHIMS_BASE_MODULE", "pip")
    path_info = namedtuple("PathInfo", "path start_version end_version")

    def __dir__(self):
        result = list(self._locations.keys()) + list(self.__dict__.keys())
        result.extend(
            (
                "__file__",
                "__doc__",
                "__all__",
                "__docformat__",
                "__name__",
                "__path__",
Exemple #8
0
import sys

import pip_shims.shims
import six
import six.moves
import tomlkit
import vistir
from six.moves.urllib.parse import urlparse, urlsplit, urlunparse
from vistir.compat import Path, fs_decode
from vistir.path import ensure_mkdir_p, is_valid_url

from .environment import MYPY_RUNNING

# fmt: off
six.add_move(  # type: ignore
    six.MovedAttribute("Mapping", "collections",
                       "collections.abc")  # type: ignore
)  # noqa  # isort:skip
six.add_move(  # type: ignore
    six.MovedAttribute("Sequence", "collections",
                       "collections.abc")  # type: ignore
)  # noqa  # isort:skip
six.add_move(  # type: ignore
    six.MovedAttribute("Set", "collections", "collections.abc")  # type: ignore
)  # noqa  # isort:skip
six.add_move(  # type: ignore
    six.MovedAttribute("ItemsView", "collections",
                       "collections.abc")  # type: ignore
)  # noqa
from six.moves import ItemsView, Mapping, Sequence, Set  # type: ignore  # noqa  # isort:skip
# fmt: on
Exemple #9
0
import time
from xml.etree import cElementTree as et
import six
six.add_move(six.MovedAttribute('html_escape', 'cgi', 'html', 'escape'))
from six.moves import html_escape

from . import Device
from ..color import get_profiles, limit_to_gamut

CAPABILITY_ID2NAME = dict((
    ('10006', "onoff"),
    ('10008', "levelcontrol"),
    ('30008', "sleepfader"),
    ('30009', "levelcontrol_move"),
    ('3000A', "levelcontrol_stop"),
    ('10300', "colorcontrol"),
    ('30301', "colortemperature"),
))
CAPABILITY_NAME2ID = dict(
    (val, cap) for cap, val in CAPABILITY_ID2NAME.items())

# acceptable values for 'onoff'
OFF = 0
ON = 1
TOGGLE = 2


def limit(value, min_val, max_val):
    """Returns value clipped to the range [min_val, max_val]"""
    return max(min_val, min(value, max_val))
Exemple #10
0
import re
import subprocess
from collections import OrderedDict
from fnmatch import fnmatch
from threading import Timer

import attr
import six
from packaging.version import LegacyVersion, Version

from .compat import Path, lru_cache, TimeoutError  # noqa
from .environment import MYPY_RUNNING, PYENV_ROOT, SUBPROCESS_TIMEOUT
from .exceptions import InvalidPythonVersion

six.add_move(
    six.MovedAttribute("Iterable", "collections", "collections.abc")
)  # type: ignore  # noqa
six.add_move(
    six.MovedAttribute("Sequence", "collections", "collections.abc")
)  # type: ignore  # noqa
# fmt: off
from six.moves import Iterable  # type: ignore  # noqa  # isort:skip
from six.moves import Sequence  # type: ignore  # noqa  # isort:skip
# fmt: on

if MYPY_RUNNING:
    from typing import Any, Union, List, Callable, Set, Tuple, Dict, Optional, Iterator
    from attr.validators import _OptionalValidator  # type: ignore
    from .models.path import PathEntry

Exemple #11
0
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from __future__ import absolute_import

import six

moves = [
    six.MovedAttribute("getoutput", "commands", "subprocess"),
]

for m in moves:
    six.add_move(m)

# Here, we can't use six.Moved* methods because being able to import asyncio vs
# trollius is not strictly Py 2 vs Py 3, but rather asyncio for >=3.4, and
# possibly 3.3 with Tulip, and trollius for 2 and <=3.2, and 3.3 without Tulip.
# We can no longer direct assign to six.moves, so let's just leave it here so
# we don't need to keep try/except importing asyncio.
try:
    import asyncio  # noqa
except ImportError:
    import trollius as asyncio  # noqa
import six


six.add_move(
    six.MovedAttribute(
        name='string_letters',
        old_mod='string',
        new_mod='string',
        old_attr='letters',
        new_attr='ascii_letters',
    )
)
Exemple #13
0
import os
import sys

import pip_shims.shims
import six
import tomlkit
import vistir
from six.moves.urllib.parse import urlparse, urlsplit, urlunparse
from vistir.compat import Path
from vistir.path import create_tracked_tempdir, ensure_mkdir_p, is_valid_url

from .environment import MYPY_RUNNING

# fmt: off
six.add_move(six.MovedAttribute(
    "Mapping", "collections",
    "collections.abc"))  # type: ignore  # noqa  # isort:skip
six.add_move(six.MovedAttribute(
    "Sequence", "collections",
    "collections.abc"))  # type: ignore  # noqa  # isort:skip
six.add_move(six.MovedAttribute(
    "Set", "collections",
    "collections.abc"))  # type: ignore  # noqa  # isort:skip
six.add_move(six.MovedAttribute("ItemsView", "collections",
                                "collections.abc"))  # type: ignore  # noqa
from six.moves import ItemsView, Mapping, Sequence, Set  # type: ignore  # noqa  # isort:skip
# fmt: on

if MYPY_RUNNING:
    from typing import (
        Dict,
Exemple #14
0
from fnmatch import fnmatch
from itertools import chain

import attr
import six

import vistir

from .exceptions import InvalidPythonVersion

try:
    from functools import lru_cache
except ImportError:
    from backports.functools_lru_cache import lru_cache

six.add_move(six.MovedAttribute("Iterable", "collections", "collections.abc"))
from six.moves import Iterable


PYTHON_IMPLEMENTATIONS = (
    "python", "ironpython", "jython", "pypy", "anaconda", "miniconda",
    "stackless", "activepython", "micropython"
)
RULES_BASE = ["*{0}", "*{0}?", "*{0}?.?", "*{0}?.?m"]
RULES = [rule.format(impl) for impl in PYTHON_IMPLEMENTATIONS for rule in RULES_BASE]

KNOWN_EXTS = {"exe", "py", "fish", "sh", ""}
KNOWN_EXTS = KNOWN_EXTS | set(
    filter(None, os.environ.get("PATHEXT", "").split(os.pathsep))
)
Exemple #15
0
"""
from __future__ import unicode_literals

import os.path
import sys
import tempfile
import time
from io import open
from unittest import TestCase

import requests
from docopt import DocoptExit
import six

six.add_move(
    six.MovedAttribute('TemporaryDirectory', "backports.tempfile", "tempfile"))
# noinspection PyUnresolvedReferences
from six.moves import TemporaryDirectory

from qPyUtils.debug import start_in_thread
from qPyUtils.system import portforward
import qPyUtils.system.file_system


class TestSystemUtils(TestCase):
    def test_portforward(self):
        # ---------- empty args_in should raise 'Usage'
        with self.assertRaises(DocoptExit):
            del sys.argv[:]
            portforward.main()