当前位置: 首页>>代码示例>>Python>>正文


Python six.u方法代码示例

本文整理汇总了Python中six.u方法的典型用法代码示例。如果您正苦于以下问题:Python six.u方法的具体用法?Python six.u怎么用?Python six.u使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six的用法示例。


在下文中一共展示了six.u方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testDonostia

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def testDonostia(self):
        httpretty.register_uri(
            httpretty.GET,
            self.geocoder.url,
            body='{"thanks":"For using an OpenCage Data API","status":{"message":"OK","code":200},"rate":{"remaining":2482,"limit":"2500","reset":1402185600},"total_results":7,"results":[{"geometry":{"lat":"43.3213324","lng":"-1.9856227"},"annotations":{},"components":{"postcode":"20001;20002;20003;20004;20005;20006;20007;20008;20009;20010;20011;20012;20013;20014;20015;20016;20017;20018","county":"Donostialdea/Donostia-San Sebasti\u00e1n","state":"Basque Country","country":"Spain","city":"San Sebasti\u00e1n","country_code":"es"},"formatted":"San Sebasti\u00e1n, Donostialdea/Donostia-San Sebasti\u00e1n, 20001;20002;20003;20004;20005;20006;20007;20008;20009;20010;20011;20012;20013;20014;20015;20016;20017;20018, Basque Country, Spain, es","bounds":{"southwest":{"lat":"43.2178373","lng":"-2.086808"},"northeast":{"lng":"-1.8878838","lat":"43.3381344"}}},{"formatted":"Donostia, Irun, Bidasoa Beherea / Bajo Bidasoa, Basque Country, Spain, es","components":{"county":"Bidasoa Beherea / Bajo Bidasoa","state":"Basque Country","country":"Spain","city":"Irun","country_code":"es","road":"Donostia"},"bounds":{"southwest":{"lat":"43.3422299","lng":"-1.8022744"},"northeast":{"lng":"-1.8013452","lat":"43.3449598"}},"geometry":{"lng":"-1.8019153","lat":"43.3432784"},"annotations":{}},{"annotations":{},"geometry":{"lng":"-1.8022744","lat":"43.3422299"},"formatted":"Donostia, Anaka, Irun, Bidasoa Beherea / Bajo Bidasoa, Basque Country, Spain, es","components":{"county":"Bidasoa Beherea / Bajo Bidasoa","state":"Basque Country","country":"Spain","city":"Irun","suburb":"Anaka","country_code":"es","road":"Donostia"},"bounds":{"southwest":{"lng":"-1.8022971","lat":"43.3421635"},"northeast":{"lng":"-1.8022744","lat":"43.3422299"}}},{"geometry":{"lng":"-2.69312049872164","lat":"42.868297"},"annotations":{},"bounds":{"southwest":{"lng":"-2.6933154","lat":"42.8681484"},"northeast":{"lat":"42.8684357","lng":"-2.6929252"}},"formatted":"Donostia kalea, Ibaiondo, Vitoria-Gasteiz, Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria, Basque Country, Spain, es","components":{"county":"Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria","state":"Basque Country","country":"Spain","city":"Vitoria-Gasteiz","suburb":"Ibaiondo","country_code":"es","road":"Donostia kalea"}},{"bounds":{"southwest":{"lng":"-2.6889534","lat":"42.8620967"},"northeast":{"lat":"42.8623764","lng":"-2.6885774"}},"formatted":"Donostia kalea, Lakua, Vitoria-Gasteiz, Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria, Basque Country, Spain, es","components":{"county":"Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria","state":"Basque Country","country":"Spain","city":"Vitoria-Gasteiz","suburb":"Lakua","country_code":"es","road":"Donostia kalea"},"geometry":{"lat":"42.8622515","lng":"-2.68876582144679"},"annotations":{}},{"annotations":{},"geometry":{"lat":"51.5146888","lng":"-0.1609307"},"components":{"restaurant":"Donostia","country":"United Kingdom","state_district":"Greater London","country_code":"gb","county":"London","state":"England","suburb":"Marylebone","city":"City of Westminster","road":"Great Cumberland Mews"},"formatted":"Donostia, Great Cumberland Mews, Marylebone, City of Westminster, London, Greater London, England, United Kingdom, gb","bounds":{"northeast":{"lng":"-0.1608807","lat":"51.5147388"},"southwest":{"lat":"51.5146388","lng":"-0.1609807"}}},{"geometry":{"lat":43.31283,"lng":-1.97499},"annotations":{},"bounds":{"northeast":{"lng":"-1.92020404339","lat":"43.3401603699"},"southwest":{"lat":"43.2644081116","lng":"-2.04920697212"}},"formatted":"San Sebastian, Gipuzkoa, Basque Country, Spain, Donostia / San Sebasti\u00e1n","components":{"county":"Gipuzkoa","state":"Basque Country","country":"Spain","town":"San Sebastian","local administrative area":"Donostia / San Sebasti\u00e1n"}}],"timestamp":{"created_unix":1402136556,"created_http":"Sat, 07 Jun 2014 10:22:36 GMT"},"licenses":[{"name":"CC-BY-SA","url":"http://creativecommons.org/licenses/by-sa/3.0/"},{"name":"ODbL","url":"http://opendatacommons.org/licenses/odbl/summary/"}]}',

        )

        results = self.geocoder.geocode("Donostia")
        self.assertTrue(
            any((abs(result['geometry']['lat'] - 43.300836) < 0.05 and abs(result['geometry']['lng'] - -1.9809529) < 0.05) for result in results),
            msg="Bad result"
        )

        # test that the results are in unicode
        self.assertEqual(results[0]['formatted'], six.u('San Sebasti\xe1n, Donostialdea/Donostia-San Sebasti\xe1n, 20001;20002;20003;20004;20005;20006;20007;20008;20009;20010;20011;20012;20013;20014;20015;20016;20017;20018, Basque Country, Spain, es')) 
开发者ID:OpenCageData,项目名称:python-opencage-geocoder,代码行数:18,代码来源:tests.py

示例2: deaccent

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def deaccent(text):
    """
    Remove accentuation from the given string. Input text is either a unicode string or utf8 encoded bytestring.

    Return input string with accents removed, as unicode.

    >>> deaccent("Šéf chomutovských komunistů dostal poštou bílý prášek")
    u'Sef chomutovskych komunistu dostal postou bily prasek'

    """
    if not isinstance(text, unicode):
        # assume utf8 for byte strings, use default (strict) error handling
        text = text.decode('utf8')
    norm = unicodedata.normalize("NFD", text)
    result = u('').join(ch for ch in norm if unicodedata.category(ch) != 'Mn')
    return unicodedata.normalize("NFC", result) 
开发者ID:loretoparisi,项目名称:word2vec-twitter,代码行数:18,代码来源:word2vecReaderUtils.py

示例3: tokenize

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def tokenize(text, lowercase=False, deacc=False, errors="strict", to_lower=False, lower=False):
    """
    Iteratively yield tokens as unicode strings, optionally also lowercasing them
    and removing accent marks.

    Input text may be either unicode or utf8-encoded byte string.

    The tokens on output are maximal contiguous sequences of alphabetic
    characters (no digits!).

    >>> list(tokenize('Nic nemůže letět rychlostí vyšší, než 300 tisíc kilometrů za sekundu!', deacc = True))
    [u'Nic', u'nemuze', u'letet', u'rychlosti', u'vyssi', u'nez', u'tisic', u'kilometru', u'za', u'sekundu']

    """
    lowercase = lowercase or to_lower or lower
    text = to_unicode(text, errors=errors)
    if lowercase:
        text = text.lower()
    if deacc:
        text = deaccent(text)
    for match in PAT_ALPHABETIC.finditer(text):
        yield match.group() 
开发者ID:loretoparisi,项目名称:word2vec-twitter,代码行数:24,代码来源:word2vecReaderUtils.py

示例4: test__obj_to_readable_str

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def test__obj_to_readable_str():
    def t(obj, expected):
        got = _obj_to_readable_str(obj)
        assert type(got) is str
        assert got == expected
    t(1, "1")
    t(1.0, "1.0")
    t("asdf", "asdf")
    t(six.u("asdf"), "asdf")
    if sys.version_info >= (3,):
        # we can use "foo".encode here b/c this is python 3!
        # a utf-8 encoded euro-sign comes out as a real euro sign.
        t("\u20ac".encode("utf-8"), six.u("\u20ac"))
        # but a iso-8859-15 euro sign can't be decoded, and we fall back on
        # repr()
        t("\u20ac".encode("iso-8859-15"), "b'\\xa4'")
    else:
        t(six.u("\u20ac"), "u'\\u20ac'") 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:contrasts.py

示例5: write_np_values

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def write_np_values(values, f):
    """
    Arguments:
        values: {str: np.array}
        f: filename or filelike object
    """
    with ZipFile(f, 'w') as zf:
        for k, v in values.items():
            # Need to do this because Python zipfile has some odd support for filenames:
            # http://bugs.python.org/issue24110
            if len(k) == 16 and isinstance(k, six.binary_type):  # valid UUID bytes
                zf.writestr(str(uuid.UUID(bytes=k)), v.tostring())
            else:
                zf.writestr(six.u(k), v.tostring())

        zf.writestr(MANIFEST_FILENAME, json_dumps_manifest(values)) 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:18,代码来源:serde_weights.py

示例6: annotate

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def annotate(self, ann):
        """
        @ann: is a protobuf annotation object.
        Actually populate @ann with tokens.
        """
        buf, beg_idx, end_idx = ann.text.lower(), 0, 0
        for i, word in enumerate(self.tokenize(ann.text)):
            token = ann.sentencelessToken.add()
            # These are the bare minimum required for the TokenAnnotation
            token.word = six.u(word)
            token.tokenBeginIndex = i
            token.tokenEndIndex = i+1

            # Seek into the txt until you can find this word.
            try:
                # Try to update beginning index
                beg_idx = buf.index(word, beg_idx)
            except ValueError:
                # Give up -- this will be something random
                end_idx = beg_idx + len(word)

            token.beginChar = beg_idx
            token.endChar = end_idx

            beg_idx, end_idx = end_idx, end_idx 
开发者ID:stanfordnlp,项目名称:python-stanford-corenlp,代码行数:27,代码来源:test_annotator.py

示例7: test_annotator_annotate

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def test_annotator_annotate():
    cases = [(u"RT @ #happyfuncoding: this is a typical Twitter tweet :-)",
              u"rt @ #happyfuncoding : this is a typical twitter tweet :-)".split()),
             (u"HTML entities &amp; other Web oddities can be an &aacute;cute <em class='grumpy'>pain</em> >:(",
              u"html entities and other web oddities can be an ácute".split() + [u"<em class='grumpy'>", u"pain", u"</em>", u">:("]),
             (u"It's perhaps noteworthy that phone numbers like +1 (800) 123-4567, (800) 123-4567, and 123-4567 are treated as words despite their whitespace.",
              u"it's perhaps noteworthy that phone numbers like".split() + [u"+1 (800) 123-4567", u",", u"(800) 123-4567", u",", u"and", u"123-4567"] + u"are treated as words despite their whitespace .".split())
            ]

    annotator = HappyFunTokenizer()

    for text, tokens in cases:
        ann = corenlp.Document()
        ann.text = text
        annotator.annotate(ann)
        tokens_ = [t.word for t in ann.sentencelessToken]
        assert tokens_ == tokens 
开发者ID:stanfordnlp,项目名称:python-stanford-corenlp,代码行数:19,代码来源:test_annotator.py

示例8: test_tokenizer

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def test_tokenizer():
    cases = [(u"RT @ #happyfuncoding: this is a typical Twitter tweet :-)",
              u"rt @ #happyfuncoding : this is a typical twitter tweet :-)".split()),
             (u"HTML entities &amp; other Web oddities can be an &aacute;cute <em class='grumpy'>pain</em> >:(",
              u"html entities and other web oddities can be an ácute".split() + [u"<em class='grumpy'>", u"pain", u"</em>", u">:("]),
             (u"It's perhaps noteworthy that phone numbers like +1 (800) 123-4567, (800) 123-4567, and 123-4567 are treated as words despite their whitespace.",
              u"it's perhaps noteworthy that phone numbers like".split() + [u"+1 (800) 123-4567", u",", u"(800) 123-4567", u",", u"and", u"123-4567"] + u"are treated as words despite their whitespace .".split())
            ]

    annotator = HappyFunTokenizer()
    annotator.start()

    try:
        with corenlp.CoreNLPClient(properties=annotator.properties, annotators="happyfun ssplit pos".split()) as client:
            for text, tokens in cases:
                ann = client.annotate(text)
                tokens_ = [t.word for t in ann.sentence[0].token]
                assert tokens == tokens_
    finally:
        annotator.terminate()
        annotator.join() 
开发者ID:stanfordnlp,项目名称:python-stanford-corenlp,代码行数:23,代码来源:test_annotator.py

示例9: colorize

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def colorize(string, color, bold=False, highlight = False):
    """Return string surrounded by appropriate terminal color codes to
    print colorized text.  Valid colors: gray, red, green, yellow,
    blue, magenta, cyan, white, crimson
    """

    # Import six here so that `utils` has no import-time dependencies.
    # We want this since we use `utils` during our import-time sanity checks
    # that verify that our dependencies (including six) are actually present.
    import six

    attr = []
    num = color2num[color]
    if highlight: num += 10
    attr.append(six.u(str(num)))
    if bold: attr.append(six.u('1'))
    attrs = six.u(';').join(attr)
    return six.u('\x1b[%sm%s\x1b[0m') % (attrs, string) 
开发者ID:ArztSamuel,项目名称:DRL_DeliveryDuel,代码行数:20,代码来源:colorize.py

示例10: _deserialize_primitive

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def _deserialize_primitive(data, klass):
    """Deserializes to primitive type.

    :param data: data to deserialize.
    :param klass: class literal.

    :return: int, long, float, str, bool.
    :rtype: int | long | float | str | bool
    """
    try:
        value = klass(data)
    except UnicodeEncodeError:
        value = six.u(data)
    except TypeError:
        value = data
    return value 
开发者ID:hmajid2301,项目名称:articles,代码行数:18,代码来源:util.py

示例11: prepare_constraint_file

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def prepare_constraint_file(self):
        from pipenv.vendor.vistir.path import create_tracked_tempfile
        constraints_file = create_tracked_tempfile(
            mode="w",
            prefix="pipenv-",
            suffix="-constraints.txt",
            dir=self.req_dir,
            delete=False,
        )
        skip_args = ("build-isolation", "use-pep517", "cache-dir")
        args_to_add = [
            arg for arg in self.pip_args
            if not any(bad_arg in arg for bad_arg in skip_args)
        ]
        if self.sources:
            requirementstxt_sources = " ".join(args_to_add) if args_to_add else ""
            requirementstxt_sources = requirementstxt_sources.replace(" --", "\n--")
            constraints_file.write(u"{0}\n".format(requirementstxt_sources))
        constraints = self.initial_constraints
        constraints_file.write(u"\n".join([c for c in constraints]))
        constraints_file.close()
        return constraints_file.name 
开发者ID:pypa,项目名称:pipenv,代码行数:24,代码来源:utils.py

示例12: test_sci_no_parameters

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def test_sci_no_parameters(self):
        self._prepare_sci_response(EXAMPLE_SCI_REQUEST_RESPONSE)
        self.dc.get_sci_api().send_sci(
            operation="send_message",
            target=DeviceTarget('00000000-00000000-00409dff-ffaabbcc'),
            payload=EXAMPLE_SCI_REQUEST_PAYLOAD)
        request = httpretty.last_request().body.decode('utf8')
        # Strip white space from lines and concatenate request
        request = ''.join([line.strip() for line in request.splitlines()])
        self.assertEqual(request,
                         six.u('<sci_request version="1.0">'
                               '<send_message>'
                               '<targets>'
                               '<device id="00000000-00000000-00409dff-ffaabbcc"/>'
                               '</targets>'
                               '<rci_request version="1.1">'
                               '<query_state>'
                               '<device_stats/>'
                               '</query_state>'
                               '</rci_request>'
                               '</send_message>'
                               '</sci_request>')) 
开发者ID:digidotcom,项目名称:python-devicecloud,代码行数:24,代码来源:test_sci.py

示例13: test_sci_update_firmware_attribute

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def test_sci_update_firmware_attribute(self):

        self._prepare_sci_response(EXAMPLE_UPDATE_FIRMWARE_INVALID_ATTRIBUTE_RESPONSE)
        self.dc.get_sci_api().send_sci(
            operation="update_firmware",
            attribute="filename=\"abcd.bin\"",
            target=DeviceTarget('00000000-00000000-00409dff-ffaabbcc'),
            payload=EXAMPLE_UPDATE_FIRMWARE_INVALID_ATTRIBUTE_REQUEST_PAYLOAD)

        request = httpretty.last_request().body.decode('utf8')
        request = ''.join([line.strip() for line in request.splitlines()])
        self.assertEqual(request,
                         six.u('<sci_request version="1.0">'
                               '<update_firmware filename="abcd.bin">'
                               '<targets>'
                               '<device id="00000000-00000000-00409dff-ffaabbcc"/>'
                               '</targets>'
                               '<data>aHNxcAbAADUct1cAAACAHEBAAAEABEAwAIBAAQAAACOFFzU</data>'
                               '</update_firmware>'
                               '</sci_request>')) 
开发者ID:digidotcom,项目名称:python-devicecloud,代码行数:22,代码来源:test_sci.py

示例14: parse_masked_phone_number

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def parse_masked_phone_number(html, parser=None):
    """Get masked phone number from security check html

    :param html: str: raw html text
    :param parser: bs4.BeautifulSoup: html parser
    :return: tuple of phone prefix and suffix, for example: ('+1234', '89')
    :rtype : tuple
    """
    if parser is None:
        parser = bs4.BeautifulSoup(html, 'html.parser')

    fields = parser.find_all('span', {'class': 'field_prefix'})
    if not fields:
        raise VkParseError(
            'No <span class="field_prefix">...</span> in the \n%s' % html)

    result = []
    for f in fields:
        value = f.get_text().replace(six.u('\xa0'), '')
        result.append(value)
    return tuple(result) 
开发者ID:prawn-cake,项目名称:vk-requests,代码行数:23,代码来源:utils.py

示例15: replace_tags

# 需要导入模块: import six [as 别名]
# 或者: from six import u [as 别名]
def replace_tags(text, token='', encoding=None):
    """Replace all markup tags found in the given `text` by the given token.
    By default `token` is an empty string so it just removes all tags.

    `text` can be a unicode string or a regular string encoded as `encoding`
    (or ``'utf-8'`` if `encoding` is not given.)

    Always returns a unicode string.

    Examples:

    >>> import w3lib.html
    >>> w3lib.html.replace_tags(u'This text contains <a>some tag</a>')
    u'This text contains some tag'
    >>> w3lib.html.replace_tags('<p>Je ne parle pas <b>fran\\xe7ais</b></p>', ' -- ', 'latin-1')
    u' -- Je ne parle pas  -- fran\\xe7ais --  -- '
    >>>

    """

    return _tag_re.sub(token, to_unicode(text, encoding)) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:html.py


注:本文中的six.u方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。