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


Python six.u函数代码示例

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


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

示例1: frozenset_string

def frozenset_string(value, seen):
    if value:
        return u('frozenset({%s})') % (u(', ').join(sorted(
            show(c, seen) for c in value
        )))
    else:
        return repr(value)
开发者ID:rbtcollins,项目名称:hypothesis,代码行数:7,代码来源:show.py

示例2: info

 def info(self):
     if self.project is not None:
         return six.u("join project '%s'") % self.project.pid
     elif self.name:
         return six.u("create project '%s'") % self.name
     else:
         return six.u("create/join a project")
开发者ID:brianmay,项目名称:karaage,代码行数:7,代码来源:models.py

示例3: test_non_bytes

 def test_non_bytes(self):
     padder = padding.PKCS7(128).padder()
     with pytest.raises(TypeError):
         padder.update(six.u("abc"))
     unpadder = padding.PKCS7(128).unpadder()
     with pytest.raises(TypeError):
         unpadder.update(six.u("abc"))
开发者ID:CThaw90,项目名称:SDNHeaderAuthentication,代码行数:7,代码来源:test_padding.py

示例4: check_username_for_new_account

def check_username_for_new_account(person, username, machine_category):
    """ Check the new username for a new account. If the username  is
    in use, raises :py:exc:`UsernameTaken`.

    :param person: Owner of new account.
    :param username: Username to validate.
    :param machine_category: Machine category for new account.
    """

    query = Account.objects.filter(
        username__exact=username,
        machine_category=machine_category,
        date_deleted__isnull=True)

    if query.count() > 0:
        raise UsernameTaken(
            six.u('Username already in use on machine category %s.')
            % machine_category)

    if machine_category_account_exists(username, machine_category):
        raise UsernameTaken(
            six.u('Username is already in datastore for machine category %s.')
            % machine_category)

    return username
开发者ID:Karaage-Cluster,项目名称:karaage-debian,代码行数:25,代码来源:utils.py

示例5: parseBalance

 def parseBalance(cls_, statement, stmt_ofx, bal_tag_name, bal_attr, bal_date_attr, bal_type_string):
     bal_tag = stmt_ofx.find(bal_tag_name)
     if hasattr(bal_tag, "contents"):
         balamt_tag = bal_tag.find('balamt')
         dtasof_tag = bal_tag.find('dtasof')
         if hasattr(balamt_tag, "contents"):
             try:
                 setattr(statement, bal_attr, decimal.Decimal(
                     balamt_tag.contents[0].strip()))
             except (IndexError, decimal.InvalidOperation):
                 ex = sys.exc_info()[1]
                 statement.warnings.append(
                     six.u("%s balance amount was empty for %s") % (bal_type_string, stmt_ofx))
                 if cls_.fail_fast:
                     raise OfxParserException("Empty %s balance" % bal_type_string)
         if hasattr(dtasof_tag, "contents"):
             try:
                 setattr(statement, bal_date_attr, cls_.parseOfxDateTime(
                     dtasof_tag.contents[0].strip()))
             except IndexError:
                 statement.warnings.append(
                     six.u("%s balance date was empty for %s") % (bal_type_string, stmt_ofx))
                 if cls_.fail_fast:
                     raise
             except ValueError:
                 statement.warnings.append(
                     six.u("%s balance date was not allowed for %s") % (bal_type_string, stmt_ofx))
                 if cls_.fail_fast:
                     raise
开发者ID:an613,项目名称:ofxparse,代码行数:29,代码来源:ofxparse.py

示例6: __init__

   def __init__(self, authid = None, authrole = None, authmethod = None, authprovider = None):
      """
      Ctor.

      :param authid: The authentication ID the client is assigned, e.g. `"joe"` or `"[email protected]"`.
      :type authid: str
      :param authrole: The authentication role the client is assigned, e.g. `"anonymous"`, `"user"` or `"com.myapp.user"`.
      :type authrole: str
      :param authmethod: The authentication method that was used to authenticate the client, e.g. `"cookie"` or `"wampcra"`.
      :type authmethod: str
      :param authprovider: The authentication provider that was used to authenticate the client, e.g. `"mozilla-persona"`.
      :type authprovider: str
      """
      if six.PY2:
         if type(authid) == str:
            authid = six.u(authid)
         if type(authrole) == str:
            authrole = six.u(authrole)
         if type(authmethod) == str:
            authmethod = six.u(authmethod)
         if type(authprovider) == str:
            authprovider = six.u(authprovider)

      assert(authid is None or type(authid) == six.text_type)
      assert(authrole is None or type(authrole) == six.text_type)
      assert(authmethod is None or type(authmethod) == six.text_type)
      assert(authprovider is None or type(authprovider) == six.text_type)

      self.authid = authid
      self.authrole = authrole
      self.authmethod = authmethod
      self.authprovider = authprovider
开发者ID:BanzaiMan,项目名称:AutobahnPython,代码行数:32,代码来源:types.py

示例7: _build_illegal_xml_regex

    def _build_illegal_xml_regex():
        """Constructs a regex to match all illegal xml characters.

        Expects to be used against a unicode string."""
        # Construct the range pairs of invalid unicode characters.
        illegal_chars_u = [
            (0x00, 0x08), (0x0B, 0x0C), (0x0E, 0x1F), (0x7F, 0x84),
            (0x86, 0x9F), (0xFDD0, 0xFDDF), (0xFFFE, 0xFFFF)]

        # For wide builds, we have more.
        if sys.maxunicode >= 0x10000:
            illegal_chars_u.extend(
                [(0x1FFFE, 0x1FFFF), (0x2FFFE, 0x2FFFF), (0x3FFFE, 0x3FFFF),
                 (0x4FFFE, 0x4FFFF), (0x5FFFE, 0x5FFFF), (0x6FFFE, 0x6FFFF),
                 (0x7FFFE, 0x7FFFF), (0x8FFFE, 0x8FFFF), (0x9FFFE, 0x9FFFF),
                 (0xAFFFE, 0xAFFFF), (0xBFFFE, 0xBFFFF), (0xCFFFE, 0xCFFFF),
                 (0xDFFFE, 0xDFFFF), (0xEFFFE, 0xEFFFF), (0xFFFFE, 0xFFFFF),
                 (0x10FFFE, 0x10FFFF)])

        # Build up an array of range expressions.
        illegal_ranges = [
            "%s-%s" % (six.unichr(low), six.unichr(high))
            for (low, high) in illegal_chars_u]

        # Compile the regex
        return re.compile(six.u('[%s]') % six.u('').join(illegal_ranges))
开发者ID:llvm-project,项目名称:lldb,代码行数:26,代码来源:xunit.py

示例8: test_encode

 def test_encode(self):
     # _encode must encode unicode strings
     self.assertEqual(_encode(six.u('привет')),
                      six.u('привет').encode('utf-8'))
     # _encode must return byte strings unchanged
     self.assertEqual(_encode(six.u('привет').encode('utf-8')),
                      six.u('привет').encode('utf-8'))
开发者ID:alexanderlukanin13,项目名称:coolname,代码行数:7,代码来源:test_impl.py

示例9: test_unicode_names

 def test_unicode_names(self):
     """ Unicode field names for for read and write """
     self.assertArrayEqual(self.dset[six.u('a')], self.data['a'])
     self.dset[six.u('a')] = 42
     data = self.data.copy()
     data['a'] = 42
     self.assertArrayEqual(self.dset[six.u('a')], data['a'])
开发者ID:CaptainAL,项目名称:Spyder,代码行数:7,代码来源:test_slicing.py

示例10: test_wrong_encoding

 def test_wrong_encoding(self):
     string = String()
     unknown_char = u("\ufffd") * (2 if six.PY3 else 4)
     self.assert_equal(
         string.decode(u("ündecödäble").encode("utf-8"), "ascii"),
         u("%(u)sndec%(u)sd%(u)sble") % {"u": unknown_char}
     )
开发者ID:DasIch,项目名称:awwparse,代码行数:7,代码来源:positionals.py

示例11: address

 def address(self, qs, out):
     """simple single entry per line in the format of:
         "full name" <[email protected]>;
     """
     out.write(six.u("\n").join(six.u('"%s" <%s>;' % (full_name(**ent), ent['email']))
                                for ent in qs).encode(self.encoding))
     out.write("\n")
开发者ID:55minutes,项目名称:django-extensions,代码行数:7,代码来源:export_emails.py

示例12: load

    def load(self, name, package=__package__):
        if name in self.plugins:
            msg = u("Not loading already loaded plugin: {0}").format(name)
            self.logger.warn(msg)
            return msg

        try:
            fqplugin = "{0}.{1}".format(package, name)
            if fqplugin in sys.modules:
                reload(sys.modules[fqplugin])

            m = safe__import__(name, globals(), locals(), package)

            p1 = lambda x: isclass(x) and issubclass(x, BasePlugin)  # noqa
            p2 = lambda x: x is not BasePlugin  # noqa
            predicate = lambda x: p1(x) and p2(x)  # noqa
            plugins = getmembers(m, predicate)

            for name, Plugin in plugins:
                instance = Plugin(*self.init_args, **self.init_kwargs)
                instance.register(self)
                self.logger.debug(u("Registered Component: {0}").format(instance))
                if name not in self.plugins:
                    self.plugins[name] = set()
                self.plugins[name].add(instance)

            msg = u("Loaded plugin: {0}").format(name)
            self.logger.info(msg)
            return msg
        except Exception, e:
            msg = u("Could not load plugin: {0} Error: {1}").format(name, e)
            self.logger.error(msg)
            self.logger.error(format_exc())
            return msg
开发者ID:MrSwiss,项目名称:charla,代码行数:34,代码来源:__init__.py

示例13: test_unicode_password

 def test_unicode_password(self):
     j = jenkins.Jenkins('{0}'.format(self.base_url),
                         six.u('nonascii'),
                         six.u('\xe9\u20ac'))
     self.assertEqual(j.server, self.make_url(''))
     self.assertEqual(j.auth, b'Basic bm9uYXNjaWk6w6nigqw=')
     self.assertEqual(j.crumb, None)
开发者ID:AssiNET,项目名称:python-jenkins,代码行数:7,代码来源:test_jenkins.py

示例14: test_unicode_deserialize

 def test_unicode_deserialize(self):
     """
     UnicodeAttribute.deserialize
     """
     attr = UnicodeAttribute()
     self.assertEqual(attr.deserialize('foo'), six.u('foo'))
     self.assertEqual(attr.deserialize(u'foo'), six.u('foo'))
开发者ID:BCVisin,项目名称:PynamoDB,代码行数:7,代码来源:test_attributes.py

示例15: set_bool

def set_bool(x):
    if isinstance(x, bool):
        return x
    elif isinstance(x, integer_types):
        return x != 0
    else:
        return text_type(x).strip().lower() not in {u('0'), b('0'), u('n'), b('n'), u('no'), b('no'), u('f'), b('f'), u('false'), b('false')}
开发者ID:jcking,项目名称:libucd,代码行数:7,代码来源:properties.py


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