本文整理汇总了Python中pyaid.string.StringUtils.StringUtils.toBytes方法的典型用法代码示例。如果您正苦于以下问题:Python StringUtils.toBytes方法的具体用法?Python StringUtils.toBytes怎么用?Python StringUtils.toBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyaid.string.StringUtils.StringUtils
的用法示例。
在下文中一共展示了StringUtils.toBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readArrayChunk
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toBytes [as 别名]
def readArrayChunk(self, arrayType ='d'):
"""writeArray doc..."""
length = self.readUint32()
data = self.read(length, decode=False)
data = StringUtils.toBytes(data)
a = array(arrayType)
a.fromstring(data)
return a
示例2: _generateHeaders
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toBytes [as 别名]
def _generateHeaders(
cls, keyName, expires =None, eTag =None, maxAge =-1, gzipped =False
):
"""Doc..."""
headers = dict()
if expires:
if StringUtils.isStringType(expires):
headers['Expires'] = StringUtils.toBytes(expires)
elif StringUtils.isBinaryType(expires):
headers['Expires'] = expires
else:
headers['Expires'] = StringUtils.toBytes(
TimeUtils.dateTimeToWebTimestamp(expires))
elif eTag:
headers['ETag'] = StringUtils.toBytes(eTag)
if maxAge > -1:
headers['Cache-Control'] = StringUtils.toBytes(
'max-age=%s; public' % maxAge)
if keyName.endswith('.jpg'):
contentType = MIME_TYPES.JPEG_IMAGE
elif keyName.endswith('.png'):
contentType = MIME_TYPES.PNG_IMAGE
elif keyName.endswith('.gif'):
contentType = MIME_TYPES.GIF_IMAGE
else:
contentType = FileUtils.getMimeType(keyName)
if StringUtils.begins(contentType, ('text/', 'application/')):
contentType = '%s; charset=UTF-8' % contentType
headers['Content-Type'] = contentType
if gzipped:
headers['Content-Encoding'] = 'gzip'
return headers
示例3: toFile
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toBytes [as 别名]
def toFile(cls, path, value, pretty =False, gzipped =False, throwError =False):
try:
res = StringUtils.toStr2(cls.asString(value, pretty=pretty))
if gzipped:
f = gzip.open(path, 'wb')
f.write(StringUtils.toBytes(res))
else:
f = open(path, 'w+')
f.write(res)
f.close()
return True
except Exception as err:
if throwError:
raise
else:
print(err)
return False
示例4: sha256hmac
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toBytes [as 别名]
def sha256hmac(cls, key, text):
"""Returns a HMAC-SHA256 hex hash of the specified text based on the specified key."""
msg = cls.base64Encode(text)
hash = hmac.new(StringUtils.toBytes(key), msg=msg, digestmod=hashlib.sha256).digest()
return cls.base64Encode(hash)