當前位置: 首頁>>代碼示例>>Python>>正文


Python six.binary_type方法代碼示例

本文整理匯總了Python中six.binary_type方法的典型用法代碼示例。如果您正苦於以下問題:Python six.binary_type方法的具體用法?Python six.binary_type怎麽用?Python six.binary_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在six的用法示例。


在下文中一共展示了six.binary_type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _is_compound_key

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def _is_compound_key(key, types=six.string_types + (six.text_type, six.binary_type)):
    '''
    Check for a compound key name

    Parameters
    ----------
    key : string
        The key name to check
    types : list of types, optional
        The types of object to check

    Returns
    -------
    True
        If the key is compound (i.e., contains a '.')
    False
        If the key is not compound

    '''
    return isinstance(key, types) and '.' in key 
開發者ID:sassoftware,項目名稱:python-esppy,代碼行數:22,代碼來源:xdict.py

示例2: alloc_data

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def alloc_data(self, value):
        """
        Allocate a piece of data that will be included in the shellcode body.

        Arguments:
            value(...): The value to add to the shellcode. Can be bytes or
                string type.

        Returns:
            ~pwnypack.types.Offset: The offset used to address the data.
        """

        if isinstance(value, six.binary_type):
            return self._alloc_data(value)
        elif isinstance(value, six.text_type):
            return self._alloc_data(value.encode('utf-8') + b'\0')
        else:
            raise TypeError('No idea how to encode %s' % repr(value)) 
開發者ID:edibledinos,項目名稱:pwnypack,代碼行數:20,代碼來源:base.py

示例3: reg_load_array

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def reg_load_array(self, reg, value):
        temp_reg = self.TEMP_REG[self.target.bits]
        code = []

        if value:
            for item in reversed(value):
                if isinstance(item, (six.text_type, six.binary_type)):
                    item = self.alloc_data(item)

                if isinstance(item, Offset) and not item:
                    item = self.OFFSET_REG

                if not isinstance(item, Register):
                    code.extend(self.reg_load(temp_reg, item))
                    item = temp_reg

                code.extend(self.reg_push(item))

        code.extend(self.reg_load(reg, self.STACK_REG))
        return code 
開發者ID:edibledinos,項目名稱:pwnypack,代碼行數:22,代碼來源:base.py

示例4: _generic_transform

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def _generic_transform(arg, klass, iterables, build_elts):
    if isinstance(arg, klass):
        return arg
    elif isinstance(arg, iterables):
        if not all(isinstance(elt, nodes.Const)
                   for elt in arg.elts):
            # TODO(cpopa): Don't support heterogenous elements.
            # Not yet, though.
            raise UseInferenceDefault()
        elts = [elt.value for elt in arg.elts]
    elif isinstance(arg, nodes.Dict):
        if not all(isinstance(elt[0], nodes.Const)
                   for elt in arg.items):
            raise UseInferenceDefault()
        elts = [item[0].value for item in arg.items]
    elif (isinstance(arg, nodes.Const) and
          isinstance(arg.value, (six.string_types, six.binary_type))):
        elts = arg.value
    else:
        return
    return klass.from_constants(elts=build_elts(elts)) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:23,代碼來源:brain_builtin_inference.py

示例5: default_dist_funcs

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def default_dist_funcs(dist_funcs, feature_example):
        """
        Fills in default distance metrics for fingerprint analyses
        """

        if dist_funcs is None:
            dist_funcs = dict()

        for key in feature_example:
            if key in dist_funcs:
                pass
            if key == 'item':
                pass
            elif isinstance(feature_example[key], (six.string_types, six.binary_type)):
                dist_funcs[key] = 'match'
            elif isinstance(feature_example[key], (int, np.integer, float)) or all([isinstance(i, (int, np.integer, float)) for i in feature_example[key]]):
                dist_funcs[key] = 'euclidean'

        return dist_funcs 
開發者ID:ContextLab,項目名稱:quail,代碼行數:21,代碼來源:helpers.py

示例6: __init__

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def __init__(self, instream):
        if six.PY2:
            # In Python 2, we can't duck type properly because unicode has
            # a 'decode' function, and we'd be double-decoding
            if isinstance(instream, (binary_type, bytearray)):
                instream = instream.decode()
        else:
            if getattr(instream, 'decode', None) is not None:
                instream = instream.decode()

        if isinstance(instream, text_type):
            instream = StringIO(instream)
        elif getattr(instream, 'read', None) is None:
            raise TypeError('Parser must be a string or character stream, not '
                            '{itype}'.format(itype=instream.__class__.__name__))

        self.instream = instream
        self.charstack = []
        self.tokenstack = []
        self.eof = False 
開發者ID:MediaBrowser,項目名稱:plugin.video.emby,代碼行數:22,代碼來源:_parser.py

示例7: _render_data

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def _render_data(el, data):
    if isinstance(data, list):
        for item in data:
            sub_el = etree.SubElement(el, 'item')
            _render_data(sub_el, item)
    elif isinstance(data, dict):
        _render_dict(el, data)
    elif hasattr(data, '__dict__'):
        _render_dict(el, data.__dict__)
    elif isinstance(data, bool):
        el.text = str(data).lower()
    elif isinstance(data, datetime.datetime):
        el.text = _database_to_isoformat(data)
    elif isinstance(data, six.binary_type):
        el.text = data.decode("utf-8")
    elif data is not None:
        el.text = six.text_type(data) 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:19,代碼來源:ec2utils.py

示例8: __init__

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def __init__(self, wpm_filepath, merge_prob=1.):
    """Create a WPM encoder.

    Args:
      wpm_filepath: a path to the file containing the vocabulary.
      merge_prob: the probability of merging tokens while encoding.
    """
    # Load vocabulary file.
    lines = py_utils.ReadFileLines(wpm_filepath)

    self._pieces = []
    for line in lines:
      if isinstance(line, six.binary_type):
        line = six.ensure_text(line, 'utf-8')
      piece = line.strip().split('\t')[0]
      self._pieces.append(piece)
    self._merge_prob = merge_prob 
開發者ID:tensorflow,項目名稱:lingvo,代碼行數:19,代碼來源:wpm_encoder.py

示例9: _generic_transform

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def _generic_transform(arg, klass, iterables, build_elts):
    if isinstance(arg, klass):
        return arg
    elif isinstance(arg, iterables):
        if not all(isinstance(elt, nodes.Const) for elt in arg.elts):
            raise UseInferenceDefault()
        elts = [elt.value for elt in arg.elts]
    elif isinstance(arg, nodes.Dict):
        if not all(isinstance(elt[0], nodes.Const) for elt in arg.items):
            raise UseInferenceDefault()
        elts = [item[0].value for item in arg.items]
    elif isinstance(arg, nodes.Const) and isinstance(
        arg.value, (six.string_types, six.binary_type)
    ):
        elts = arg.value
    else:
        return
    return klass.from_constants(elts=build_elts(elts)) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:20,代碼來源:brain_builtin_inference.py

示例10: __init__

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def __init__(self, message, *args):
        if isinstance(message, binary_type):
            message = message.decode('utf8')
        str_args = ()
        for arg in args:
            if isinstance(arg, webob.Response):
                body = arg.body
                if isinstance(body, binary_type):
                    if arg.charset:
                        arg = body.decode(arg.charset)
                    else:
                        arg = repr(body)
            elif isinstance(arg, binary_type):
                try:
                    arg = arg.decode('utf8')
                except UnicodeDecodeError:
                    arg = repr(arg)
            str_args += (arg,)
        message = message % str_args
        Exception.__init__(self, message) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:22,代碼來源:app.py

示例11: ReadTag

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def ReadTag(buffer, pos):
  """Read a tag from the buffer, and return a (tag_bytes, new_pos) tuple.

  We return the raw bytes of the tag rather than decoding them.  The raw
  bytes can then be used to look up the proper decoder.  This effectively allows
  us to trade some work that would be done in pure-python (decoding a varint)
  for work that is done in C (searching for a byte string in a hash table).
  In a low-level language it would be much cheaper to decode the varint and
  use that, but not in Python.
  """

  start = pos
  while six.indexbytes(buffer, pos) & 0x80:
    pos += 1
  pos += 1
  return (six.binary_type(buffer[start:pos]), pos)


# -------------------------------------------------------------------- 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:21,代碼來源:decoder.py

示例12: _get_kind_name

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def _get_kind_name(item):
  """Returns the kind name in CollectionDef.

  Args:
    item: A data item.

  Returns:
    The string representation of the kind in CollectionDef.
  """
  if isinstance(item, (six.string_types, six.binary_type)):
    kind = "bytes_list"
  elif isinstance(item, six.integer_types):
    kind = "int64_list"
  elif isinstance(item, float):
    kind = "float_list"
  elif isinstance(item, Any):
    kind = "any_list"
  else:
    kind = "node_list"
  return kind 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:22,代碼來源:meta_graph.py

示例13: markdown_and_sanitize

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def markdown_and_sanitize(markdown_string):
  """Takes a markdown string and converts it into sanitized html.

  It uses the table extension; while that's not a part of standard
  markdown, it is sure to be useful for TensorBoard users.

  The sanitizer uses the allowed_tags and attributes specified above. Mostly,
  we ensure that our standard use cases like tables and links are supported.

  Args:
    markdown_string: Markdown string to sanitize

  Returns:
    a string containing sanitized html for input markdown
  """
  # Convert to utf-8 whenever we have a binary input.
  if isinstance(markdown_string, six.binary_type):
    markdown_string = markdown_string.decode('utf-8')

  string_html = markdown.markdown(
      markdown_string, extensions=['markdown.extensions.tables'])
  string_sanitized = bleach.clean(
      string_html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES)
  return string_sanitized 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:26,代碼來源:text_plugin.py

示例14: to_bytes

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def to_bytes(value, encoding='utf-8'):
    """
    Makes sure the value is encoded as a byte string.

    :param value: The Python string value to encode.
    :param encoding: The encoding to use.
    :return: The byte string that was encoded.
    """
    if isinstance(value, six.binary_type):
        return value
    return value.encode(encoding) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:13,代碼來源:_text.py

示例15: encode

# 需要導入模塊: import six [as 別名]
# 或者: from six import binary_type [as 別名]
def encode(value):
    if isinstance(value, six.binary_type):
        return value
    if isinstance(value, six.integer_types):
        return b(str(value))
    if isinstance(value, float):
        return b(repr(value))
    if isinstance(value, six.text_type):
        return value.encode(ENCODING)
    if not isinstance(value, six.string_types):
        return b(value)
    return value 
開發者ID:projecteru,項目名稱:redis-trib.py,代碼行數:14,代碼來源:connection.py


注:本文中的six.binary_type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。