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


Python Common.getBytesIOString方法代码示例

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


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

示例1: toUri

# 需要导入模块: from pyndn.util.common import Common [as 别名]
# 或者: from pyndn.util.common.Common import getBytesIOString [as 别名]
    def toUri(self):
        """
        Return a string representation of the exclude values.

        :return: The string representation.
        :rtype: string
        """
        if len(self._entries) == 0:
            return ""

        result = BytesIO()
        didFirst = False
        for entry in self._entries:
            if didFirst:
                # write is required to take a byte buffer.
                result.write(Exclude._comma)

            if entry.getType() == Exclude.ANY:
                # write is required to take a byte buffer.
                result.write(Exclude._star)
            else:
                entry.getComponent().toEscapedString(result)
            didFirst = True

        return Common.getBytesIOString(result)
开发者ID:WeiqiJust,项目名称:NDN-total,代码行数:27,代码来源:exclude.py

示例2: toHex

# 需要导入模块: from pyndn.util.common import Common [as 别名]
# 或者: from pyndn.util.common.Common import getBytesIOString [as 别名]
    def toHex(self, result = None):
        """
        Return the hex representation of the bytes in array.

        :param BytesIO result: (optional) The BytesIO stream to write to. If
          omitted, return a str with the result.
        :return: The hex string (only if result is omitted).
        :rtype: str
        """
        if result == None:
            if self._array == None:
                return ""

            result = BytesIO()
            self.toHex(result)
            return Common.getBytesIOString(result)

        if self._array == None:
            return

        array = self.buf()
        hexBuffer = bytearray(2)
        for i in range(len(array)):
            # Get the hex string and transfer to hexBuffer for writing.
            hex = "%02x" % array[i]
            hexBuffer[0] = ord(hex[0])
            hexBuffer[1] = ord(hex[1])
            result.write(hexBuffer)
开发者ID:,项目名称:,代码行数:30,代码来源:

示例3: toEscapedString

# 需要导入模块: from pyndn.util.common import Common [as 别名]
# 或者: from pyndn.util.common.Common import getBytesIOString [as 别名]
    def toEscapedString(value, result = None):
        """
        Convert value to a string, escaping characters according to the NDN URI 
        Scheme. This also adds "..." to a value with zero or more ".".
        
        :param value: The buffer with the value to escape.
        :type value: An array type with int elements
        :param BytesIO result: (optional) The BytesIO stream to write to.  If 
          omitted, return a str with the result.
        :return: The result as a string (only if result is omitted).
        :rtype: str
        """
        if result == None:
            result = BytesIO()
            Name.toEscapedString(value, result)
            return Common.getBytesIOString(result)            
            
        gotNonDot = False
        for i in range(len(value)):
            if value[i] != ord('.'):
                gotNonDot = True
                break

        charBuffer = bytearray(1)
        if not gotNonDot:
            charBuffer[0] = ord('.')
            # Special case for component of zero or more periods. Add 3 periods.
            for i in range(len(value) + 3):
                result.write(charBuffer)
        else:
            hexBuffer = bytearray(3)
            hexBuffer[0] = ord('%')
            for i in range(len(value)):
                x = value[i]
                # Check for 0-9, A-Z, a-z, (+), (-), (.), (_)
                if ((x >= 0x30 and x <= 0x39) or (x >= 0x41 and x <= 0x5a) or
                    (x >= 0x61 and x <= 0x7a) or x == 0x2b or x == 0x2d or
                    x == 0x2e or x == 0x5f):
                    charBuffer[0] = x
                    # write is required to take a byte buffer.
                    result.write(charBuffer)
                else:
                    # Write '%' followed by the hex value.
                    hex = "%02X" % x
                    hexBuffer[1]  = ord(hex[0])
                    hexBuffer[2]  = ord(hex[1])
                    # write is required to take a byte buffer.
                    result.write(hexBuffer)
开发者ID:sanchitgupta05,项目名称:PyNDN2,代码行数:50,代码来源:name.py

示例4: toUri

# 需要导入模块: from pyndn.util.common import Common [as 别名]
# 或者: from pyndn.util.common.Common import getBytesIOString [as 别名]
   def toUri(self):
       """
       Encode this name as a URI according to the NDN URI Scheme.
       
       :return: The encoded URI.
       :rtype: str
       """
       if len(self._components) == 0:
           return "/"
 
       result = BytesIO()
       for component in self._components:
           # write is required to take a byte buffer.
           result.write(Name._slash)
           component.toEscapedString(result)
 
       return Common.getBytesIOString(result)
开发者ID:sanchitgupta05,项目名称:PyNDN2,代码行数:19,代码来源:name.py

示例5: toHex

# 需要导入模块: from pyndn.util.common import Common [as 别名]
# 或者: from pyndn.util.common.Common import getBytesIOString [as 别名]
    def toHex(self):
        """
        Return the hex representation of the bytes in array.

        :return: The hex string.
        :rtype: str
        """
        if self._array == None:
            return ""

        array = self.buf()
        result = BytesIO()
        hexBuffer = bytearray(2)
        for i in range(len(array)):
            # Get the hex string and transfer to hexBuffer for writing.
            hex = "%02X" % array[i]
            hexBuffer[0] = ord(hex[0])
            hexBuffer[1] = ord(hex[1])
            result.write(hexBuffer)

        return Common.getBytesIOString(result)
开发者ID:cawka,项目名称:PyNDN2,代码行数:23,代码来源:blob.py


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