本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)