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


Python builtins.b函数代码示例

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


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

示例1: test_decoding

 def test_decoding(self):
   self.assertEqual(rfc1924_b85decode(mercurial_encoded), mercurial_bytes)
   self.assertEqual(rfc1924_b85decode(random_256_mercurial),
                    random_256_bytes)
   self.assertEqual(rfc1924_b85decode(b('|NsC0')), b('\xff\xff\xff\xff'))
   for a, e in zip(random_bytes_list, rfc_encoded_bytes_list):
     self.assertEqual(rfc1924_b85decode(e), a)
开发者ID:RoboTeddy,项目名称:mom,代码行数:7,代码来源:test_mom_codec_base85.py

示例2: test_query_params_sorted_order

 def test_query_params_sorted_order(self):
     self.assertEqual(
         generate_base_string_query(dict(b=[8, 2, 4], a=1), {}),
         b("a=1&b=2&b=4&b=8"))
     qs = generate_base_string_query(
         dict(a=5, b=6, c=["w", "a", "t", "e", "r"]), {})
     self.assertEqual(qs, b("a=5&b=6&c=a&c=e&c=r&c=t&c=w"))
开发者ID:Eah300muse,项目名称:pyoauth,代码行数:7,代码来源:test_pyoauth_protocol.py

示例3: data_urlparse

def data_urlparse(data_url):
  """
  Parses a data URL into raw bytes and metadata.

  :param data_url:
      The data url string.
      If a mime-type definition is missing in the metadata,
      "text/plain;charset=US-ASCII" will be used as default mime-type.
  :returns:
      A 2-tuple::
          (bytes, mime_type)

      See :func:`mom.http.mimeparse.parse_mime_type` for what ``mime_type``
      looks like.
  """
  if not is_bytes(data_url):
    raise TypeError(
      "data URLs must be ASCII-encoded bytes: got %r" %
      type(data_url).__name__
    )
  metadata, encoded = data_url.rsplit(b(","), 1)
  _, metadata = metadata.split(b("data:"), 1)
  parts = metadata.rsplit(b(";"), 1)
  if parts[-1] == b("base64"):
    decode = base64_decode
    parts = parts[:-1]
  else:
    decode = unquote
  if not parts or not parts[0]:
    parts = [b("text/plain;charset=US-ASCII")]
  mime_type = parse_mime_type(parts[0])
  raw_bytes = decode(encoded)
  return raw_bytes, mime_type
开发者ID:RoboTeddy,项目名称:mom,代码行数:33,代码来源:data.py

示例4: best_match

def best_match(supported, header):
    """Return mime-type with the highest quality ('q') from list of candidates.

    Takes a list of supported mime-types and finds the best match for all the
    media-ranges listed in header. The value of header must be a string that
    conforms to the format of the HTTP Accept: header. The value of 'supported'
    is a list of mime-types. The list of supported mime-types should be sorted
    in order of increasing desirability, in case of a situation where there is
    a tie.

    >>> best_match([b'application/xbel+xml', b'text/xml'],
                   b'text/*;q=0.5,*/*; q=0.1')
    b'text/xml'
    """
    split_header = _filter_blank(header.split(b(',')))
    parsed_header = [parse_media_range(r) for r in split_header]
    weighted_matches = []
    pos = 0
    for mime_type in supported:
        weighted_matches.append((fitness_and_quality_parsed(mime_type,
                                 parsed_header), pos, mime_type))
        pos += 1
    weighted_matches.sort()

    return weighted_matches[-1][0][1] and weighted_matches[-1][2] or b('')
开发者ID:AlonDaks,项目名称:glass-app-backend,代码行数:25,代码来源:mimeparse.py

示例5: test_parsing_no_metadata

 def test_parsing_no_metadata(self):
   raw_bytes, mime_type = data_urlparse(no_meta_data_url)
   self.assertEqual(raw_bytes, png)
   self.assertEqual(mime_type[:2], (b('text'), b('plain')))
   self.assertDictEqual(mime_type[2], {
     b('charset'): b('US-ASCII'),
     })
开发者ID:RoboTeddy,项目名称:mom,代码行数:7,代码来源:test_mom_net_scheme_data.py

示例6: test_overflow_allowed

 def test_overflow_allowed(self):
   self.assertEqual(uint_to_bytes(0xc0ff, fill_size=1, overflow=True),
                    b('\xc0\xff'))
   self.assertEqual(uint_to_bytes(123456789, fill_size=3, overflow=True),
                    b('\x07\x5b\xcd\x15'))
   self.assertEqual(uint_to_bytes(0xf00dc0ffee, fill_size=4,
                                  overflow=True),
                    b('\xf0\x0d\xc0\xff\xee'))
开发者ID:RoboTeddy,项目名称:mom,代码行数:8,代码来源:test_mom_codec_integer.py

示例7: test_when_token_secret_present

 def test_when_token_secret_present(self):
     base_string = generate_base_string(
         HTTP_POST, b("http://example.com/"), self.oauth_params)
     self.assertEqual(generate_plaintext_signature(
         base_string,
         b(""),
         self.oauth_token_secret
     ), b("&token%20test%20secret"))
开发者ID:Eah300muse,项目名称:pyoauth,代码行数:8,代码来源:test_pyoauth_protocol.py

示例8: test_when_neither_secret_present

 def test_when_neither_secret_present(self):
     base_string = generate_base_string(
         HTTP_POST, b("http://example.com/"), self.oauth_params)
     self.assertEqual(generate_plaintext_signature(
         base_string,
         b(""),
         None
     ), b("&"))
开发者ID:Eah300muse,项目名称:pyoauth,代码行数:8,代码来源:test_pyoauth_protocol.py

示例9: test_raises_InvalidHttpRequestError_when_identifier_invalid

    def test_raises_InvalidHttpRequestError_when_identifier_invalid(self):
        temporary_credentials = Credentials(identifier=RFC_TEMPORARY_IDENTIFIER,
                                            shared_secret=RFC_TEMPORARY_SECRET)

        self.assertRaises(InvalidHttpRequestError,
                          _OAuthClient.check_verification_code,
                          temporary_credentials, b("non-matching-token"),
                          b("verification-code"))
开发者ID:Eah300muse,项目名称:pyoauth,代码行数:8,代码来源:test_pyoauth_oauth1_client.py

示例10: test_fill_size

 def test_fill_size(self):
   self.assertEqual(uint_to_bytes(0xc0ff, fill_size=4),
                    b('\x00\x00\xc0\xff'))
   self.assertEqual(uint_to_bytes(0xc0ffee, fill_size=6),
                    b('\x00\x00\x00\xc0\xff\xee'))
   self.assertEqual(uint_to_bytes(123456789, fill_size=6),
                    b('\x00\x00\x07[\xcd\x15'))
   self.assertEqual(uint_to_bytes(123456789, fill_size=7),
                    b('\x00\x00\x00\x07[\xcd\x15'))
开发者ID:RoboTeddy,项目名称:mom,代码行数:9,代码来源:test_mom_codec_integer.py

示例11: setUp

 def setUp(self):
     self.oauth_params = dict(
         oauth_consumer_key=b("9djdj82h48djs9d2"),
         oauth_token=b("kkk9d7dh3k39sjv7"),
         oauth_signature_method=SIGNATURE_METHOD_HMAC_SHA1,
         oauth_timestamp=b("137131201"),
         oauth_nonce=b("7d8f3e4a"),
         oauth_signature=b("bYT5CMsGcbgUdFHObYMEfcx6bsw%3D")
     )
开发者ID:Eah300muse,项目名称:pyoauth,代码行数:9,代码来源:test_pyoauth_protocol.py

示例12: test_raises_InvalidHttpRequestError_when_body_and_GET

 def test_raises_InvalidHttpRequestError_when_body_and_GET(self):
     oauth_params = dict(
         oauth_blah=b("blah"),
     )
     self.assertRaises(InvalidHttpRequestError,
                       _OAuthClient._build_request,
                       HTTP_GET,
                       FOO_URI,
                       None, b("a=b"), {}, oauth_params,
                       OAUTH_REALM, False)
开发者ID:Eah300muse,项目名称:pyoauth,代码行数:10,代码来源:test_pyoauth_oauth1_client.py

示例13: test_codec_equivalence

 def test_codec_equivalence(self):
   # Padding bytes are not preserved (it is acceptable here).
   random_bytes = b("\x00\xbcE\x9a\xda]")
   expected_bytes = b("\xbcE\x9a\xda]")
   self.assertEqual(uint_to_bytes(bytes_to_uint(random_bytes)),
                    expected_bytes)
   self.assertEqual(uint_to_bytes(bytes_to_uint_naive(random_bytes)),
                    expected_bytes)
   self.assertEqual(uint_to_bytes(bytes_to_uint_simple(random_bytes)),
                    expected_bytes)
开发者ID:RoboTeddy,项目名称:mom,代码行数:10,代码来源:test_mom_codec_integer.py

示例14: test_ValueError_when_encoded_length_not_20

  def test_ValueError_when_encoded_length_not_20(self):
    self.assertRaises(ValueError, ipv6_b85decode,
                      b('=r54lj&NUUO~Hi%c2ym0='))
    self.assertRaises(ValueError, ipv6_b85decode,
                      b('=r54lj&NUUO='))

    self.assertRaises(ValueError, ipv6_b85decode_naive,
                      b('=r54lj&NUUO~Hi%c2ym0='))
    self.assertRaises(ValueError, ipv6_b85decode_naive,
                      b('=r54lj&NUUO='))
开发者ID:RoboTeddy,项目名称:mom,代码行数:10,代码来源:test_mom_codec_base85.py

示例15: test_get_authentication_url

 def test_get_authentication_url(self):
     url = self.client.get_authentication_url(self.temporary_credentials,
                                             a="something here",
                                             b=["another thing", 5],
                                             oauth_ignored=b("ignored"))
     self.assertEqual(url,
                      RFC_AUTHENTICATION_URI +
                      b("?a=something%20here"
                      "&b=5"
                      "&b=another%20thing&oauth_token=") +
                      self.temporary_credentials.identifier)
开发者ID:Eah300muse,项目名称:pyoauth,代码行数:11,代码来源:test_pyoauth_oauth1_client.py


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