本文整理汇总了Python中six.add_move函数的典型用法代码示例。如果您正苦于以下问题:Python add_move函数的具体用法?Python add_move怎么用?Python add_move使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_move函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom_move_module
def test_custom_move_module(self):
attr = six.MovedModule("spam", "six", "six")
six.add_move(attr)
six.remove_move("spam")
assert not hasattr(six.moves, "spam")
attr = six.MovedModule("spam", "six", "six")
six.add_move(attr)
from six.moves import spam
assert spam is six
six.remove_move("spam")
assert not hasattr(six.moves, "spam")
示例2: test_custom_move_attribute
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")
示例3: TestMakePrefixes
#!/usr/bin/env python
import shutil
import tempfile
from unittest import TestCase
import six
six.add_move(six.MovedModule('mock', 'mock', 'unittest.mock'))
from six.moves import mock
from ansibullbot.utils.component_tools import AnsibleComponentMatcher as ComponentMatcher
from ansibullbot.utils.component_tools import make_prefixes
from ansibullbot.utils.git_tools import GitRepoWrapper
from ansibullbot.utils.file_tools import FileIndexer
from ansibullbot.utils.systemtools import run_command
class TestMakePrefixes(TestCase):
def test_simple_path_is_split_correctly(self):
fp = u'lib/ansible/foo/bar'
prefixes = make_prefixes(fp)
assert len(prefixes) == len(fp)
assert fp in prefixes
assert prefixes[0] == fp
assert prefixes[-1] == u'l'
class GitShallowRepo(GitRepoWrapper):
"""Perform a shallow copy"""
示例4: limit
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))
示例5: add_move
# This file is part of reddit_api.
#
# reddit_api is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# reddit_api is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with reddit_api. If not, see <http://www.gnu.org/licenses/>.
from six import MovedAttribute, add_move
add_move(MovedAttribute("HTTPError", "urllib2", "urllib.error"))
add_move(MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"))
add_move(MovedAttribute("Request", "urllib2", "urllib.request"))
add_move(MovedAttribute("URLError", "urllib2", "urllib.error"))
add_move(MovedAttribute("build_opener", "urllib2", "urllib.request"))
add_move(MovedAttribute("quote", "urllib2", "urllib.parse"))
add_move(MovedAttribute("urlencode", "urllib", "urllib.parse"))
add_move(MovedAttribute("urljoin", "urlparse", "urllib.parse"))
示例6:
import six
six.add_move(six.MovedModule('mox', 'mox', 'mox3.mox'))
示例7: add_move
from __future__ import print_function
import time
from six.moves import xrange
from six import add_move, MovedModule
add_move(MovedModule('autopy', 'autopy', 'autopy3'))
from six.moves import autopy
def take_screenshot(filename, delay):
for i in xrange(1, delay+1):
time.sleep(1)
print(i)
autopy.bitmap.capture_screen().save(filename)
autopy.alert.alert('A screenshot has been saved.')
示例8:
# 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
示例9: formatter_help_inline
"""formatters we use
"""
# stdlib
import cgi
# pypi
import formencode
import six
six.add_move(six.MovedAttribute("html_escape", "cgi", "html", "escape", "escape"))
from six.moves import html_escape
def formatter_help_inline(error):
"""
Formatter that escapes the error, wraps the error in a span with
class ``help-inline``, and doesn't add a ``<br>`` ; somewhat compatible with twitter's bootstrap
"""
return '<span class="help-inline">%s</span>\n' % formencode.rewritingparser.html_quote(error)
def formatter_hidden(error):
"""
returns a hidden field with the error in the name
"""
return '<input type="hidden" name="%s" />\n' % html_escape(error)
def formatter_nobr(error):
"""
This is a variant of the htmlfill `default_formatter`, in which a trailing <br/> is not included
示例10: add_move
def add_move(mod):
_six.add_move(mod)
# https://bitbucket.org/gutworth/six/issues/116/enable-importing-from-within-custom
_six._importer._add_module(mod, "moves." + mod.name)
示例11: add_move
import os
import unittest
from six import add_move, MovedModule
add_move(MovedModule('test_support', 'test.test_support', 'test.support'))
from six.moves import test_support
import vcr
from ..orbital_gateway import Order, Profile, Reversal
from .live_orbital_gateway_certification import Certification
TEST_DATA_DIR = os.path.dirname(__file__)
def create_sequence(current_value):
# if we are here
while True:
yield str(current_value)
current_value += 1
class TestProfileFunctions(unittest.TestCase):
def setUp(self):
# setup test env vars
self.env = test_support.EnvironmentVarGuard()
self.env.set('ORBITAL_PASSWORD', 'potato')
self.env.set('ORBITAL_MERCHANT_ID', '1234')
self.env.set('ORBITAL_USERNAME', 'yeah')
self.c = Certification(
示例12: add_moves
def add_moves():
add_move(MovedAttribute('HTTPError', 'urllib2', 'urllib.error'))
add_move(MovedAttribute('HTTPCookieProcessor', 'urllib2',
'urllib.request'))
add_move(MovedAttribute('Request', 'urllib2', 'urllib.request'))
add_move(MovedAttribute('URLError', 'urllib2', 'urllib.error'))
add_move(MovedAttribute('build_opener', 'urllib2', 'urllib.request'))
add_move(MovedAttribute('quote', 'urllib2', 'urllib.parse'))
add_move(MovedAttribute('urlencode', 'urllib', 'urllib.parse'))
add_move(MovedAttribute('urljoin', 'urlparse', 'urllib.parse'))
示例13:
# from http://stackoverflow.com/questions/28215214/how-to-add-custom-renames-in-six
import six
mod = six.MovedModule('mock', 'mock', 'unittest.mock')
six.add_move(mod)
six._importer._add_module(mod, "moves." + mod.name)
# issue open at https://bitbucket.org/gutworth/six/issue/116/enable-importing-from-within-custom
示例14: Copyright
#
# Copyright (c) 2019, the cclib development team
#
# This file is part of cclib (http://cclib.github.io) and is distributed under
# the terms of the BSD 3-Clause License.
"""Unit tests for the logfileparser module."""
import io
import os
import sys
import tempfile
import unittest
from six import add_move, MovedModule
add_move(MovedModule('mock', 'mock', 'unittest.mock'))
from six.moves import mock
from six.moves.urllib.request import urlopen
import numpy
import cclib
__filedir__ = os.path.dirname(__file__)
__filepath__ = os.path.realpath(__filedir__)
__datadir__ = os.path.join(__filepath__, "..", "..")
class FileWrapperTest(unittest.TestCase):
def test_file_seek(self):
示例15: MovedModule
__all__ = ['utf8_cat']
from six import PY3
from six import MovedModule
from six import MovedAttribute
from six import add_move
attributes = [
MovedModule('xmlrpc_client', 'xmlrpclib', 'xmlrpc.client'),
MovedAttribute('HTTPError', 'urllib2', 'urllib.error'),
MovedAttribute('URLError', 'urllib2', 'urllib.error'),
MovedAttribute('Request', 'urllib2', 'urllib.request'),
MovedAttribute('urlopen', 'urllib2', 'urllib.request'),
MovedAttribute('urllib_version', 'urllib2', 'urllib.request', '__version__'),
MovedAttribute('urlparse', 'urlparse', 'urllib.parse'),
]
for attr in attributes:
add_move(attr)
del attr
del attributes
if PY3:
def utf8_cat(f):
"""Read the given file in utf8 encoding"""
return open(f, encoding='utf8').read()
else:
def utf8_cat(f):
"""Read the given file in utf8 encoding"""
return open(f).read().decode('utf8')