本文整理汇总了Python中pyaid.string.StringUtils.StringUtils.isBinaryType方法的典型用法代码示例。如果您正苦于以下问题:Python StringUtils.isBinaryType方法的具体用法?Python StringUtils.isBinaryType怎么用?Python StringUtils.isBinaryType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyaid.string.StringUtils.StringUtils
的用法示例。
在下文中一共展示了StringUtils.isBinaryType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import isBinaryType [as 别名]
def save(self):
"""save doc..."""
if self.removeIfSavedEmpty and not self.rows:
self.remove()
return
index = 0
names = self.fieldNames
if self.autoIndexFieldName:
names.insert(0, self.autoIndexFieldName)
fieldNames = []
for name in names:
if StringUtils.isTextType(name):
name = name.encode('latin-1')
fieldNames.append(name)
try:
if sys.version < '3':
args = dict(mode='w')
else:
args = dict(mode='w', encoding='utf-8')
with open(self.path, **args) as f:
writer = csv.DictWriter(f, fieldnames=names, dialect=csv.excel)
writer.writeheader()
for row in self.rows:
result = dict()
if self.autoIndexFieldName:
index += 1
result[self.autoIndexFieldName] = index
for key, name in self._fields.items():
value = row.get(key, '')
if StringUtils.isBinaryType(value):
value = StringUtils.toText(value)
result[name] = value
writer.writerow(result)
return True
except Exception as err:
raise
return False
示例2: _generateHeaders
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import isBinaryType [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