本文整理汇总了Python中pyaid.string.StringUtils.StringUtils.toUnicode方法的典型用法代码示例。如果您正苦于以下问题:Python StringUtils.toUnicode方法的具体用法?Python StringUtils.toUnicode怎么用?Python StringUtils.toUnicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyaid.string.StringUtils.StringUtils
的用法示例。
在下文中一共展示了StringUtils.toUnicode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prettyPrint
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def prettyPrint(target, indentLevel =1):
indent = '\n' + (indentLevel*' ')
s = '\n'
if isinstance(target, list):
index = 0
for t in target:
try:
v = StringUtils.toUnicode(t)
except Exception:
v = '<UNPRINTABLE>'
s += '%s[%s]: %s' % (indent, index, v)
return s
if isinstance(target, dict):
for n,v in target.items():
try:
v = StringUtils.toUnicode(v)
except Exception:
v = '<UNPRINTABLE>'
s += '%s%s: %s' % (indent, n, v)
return s
items = dir(target)
for n in items:
v = getattr(target, n)
try:
v = StringUtils.toUnicode(v)
except Exception:
v = '<UNPRINTABLE>'
s += '%s%s: %s' % (indent, n, v)
return s
示例2: getPrefix
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def getPrefix(self, *args, **kwargs):
if self._locationPrefix:
item = self.getStackData()[-1]
loc = ' -> %s #%s]' % (item['file'], StringUtils.toUnicode(item['line']))
else:
loc = ']'
if self._app and self._app.pyramidApp:
wsgi = self._app.environ
initials = self._INITIALS_RX.sub('', ArgsUtils.get('REMOTE_USER', '', wsgi))
if initials:
initials += ' | '
domainName = ArgsUtils.get('SERVER_NAME', '', wsgi)
uriPath = ArgsUtils.get(
'REQUEST_URI',
ArgsUtils.get('HTTP_REQUEST_URI', '', wsgi), wsgi)
info = ' <' + initials + domainName + uriPath + '>'
else:
info = ''
threadID = ThreadUtils.getCurrentID()
return StringUtils.toUnicode(
TimeUtils.toFormat('[%a %H:%M <%S.%f>') + '<' + threadID + '>' + info + loc)
示例3: createErrorMessage
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def createErrorMessage(cls, message, error):
try:
errorType = StringUtils.toUnicode(sys.exc_info()[0])
except Exception:
try:
errorType = str(sys.exc_info()[0])
except Exception:
errorType = '[[UNABLE TO PARSE]]'
try:
errorValue = StringUtils.toUnicode(sys.exc_info()[1])
except Exception:
try:
errorValue = str(sys.exc_info()[1])
except Exception:
errorValue = '[[UNABLE TO PARSE]]'
try:
error = StringUtils.toUnicode(error)
except Exception as err:
try:
error = str(err)
except Exception:
error = '[[UNABLE TO PARSE]]'
try:
es = '%s\n TYPE: %s\n VALUE: %s\nERROR: %s\n' % (
cls.formatAsString(message), errorType, errorValue, error)
except Exception:
try:
es = '%s\n [[ERROR ATTRIBUTE PARSING FAILURE]]' % cls.formatAsString(message)
except Exception:
es = 'FAILED TO PARSE EXCEPTION'
return es
示例4: insertColumn
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def insertColumn(self, sheetname, columnname, columnnumber):
"""Inserts a new empty column into the current doc.
@param sheetname: The name of the sheet to be added to.
@type sheetname: string
@param columnname: The name of the new column to be added
@type columnname: string
@param columnnumber: Where to insert the new column (= how many come before it?)
@type columnnumber: int
"""
sheets = self._doc.spreadsheet.getElementsByType(Table)
for sheet in sheets:
if sheet.getAttribute('name') == sheetname:
rownum = 0
rows = sheet.getElementsByType(TableRow)
for row in rows:
colNum = 0
cells = row.getElementsByType(TableCell)
for cell in cells:
if colNum == columnnumber:
newCell = TableCell()
if rownum == 0:
p = P()
p.addText(StringUtils.toUnicode(columnname))
newCell.addElement(p)
else:
p = P()
p.addText(StringUtils.toUnicode(''))
newCell.addElement(p)
row.insertBefore(newCell, cell)
colNum += 1
rownum += 1
示例5: asWebRgbOpacity
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def asWebRgbOpacity(self, opacity =None):
c = self.asRgb(output=tuple)
return 'rgba(%s, %s, %s, %s)' % (
StringUtils.toUnicode(c[0]),
StringUtils.toUnicode(c[1]),
StringUtils.toUnicode(c[2]),
StringUtils.toUnicode(100.0*(self._opacity if opacity is None else opacity)) + '%' )
示例6: formatAsString
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def formatAsString(cls, src, indentLevel =0):
indents = ' '*indentLevel
if isinstance(src, (list, tuple)):
out = [StringUtils.toUnicode('%s%s' % (indents, src[0]))]
indents += ' '
lines = []
maxIndex = 0
for item in src[1:]:
item = StringUtils.toUnicode(item)
index = item.find(':')
index = index if index != -1 and index < 12 else 0
maxIndex = max(index, maxIndex)
lines.append([index, item])
for item in lines:
if item[0] > 0:
out.append(indents + (' '*max(0, maxIndex - item[0])) + item[1])
else:
out.append(indents + item[1])
return StringUtils.toUnicode('\n'.join(out))
else:
return StringUtils.toUnicode(indents + src)
示例7: createUploadPolicy
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def createUploadPolicy(self, key, durationSeconds, maxSizeBytes):
"""Returns a S3 upload policy and signature for this bucket with the specified key. """
return self._conn.build_post_form_args(
bucket_name=StringUtils.toUnicode(self.bucketName),
key=StringUtils.toUnicode(key),
expires_in=durationSeconds,
acl=StringUtils.toUnicode('private'),
max_content_length=maxSizeBytes)
示例8: __str__
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def __str__(self):
modelInfo = self._getReprString()
return '<%s[%s] cts[%s] upts[%s]%s>' % (
self.__class__.__name__,
StringUtils.toUnicode(self.i),
StringUtils.toUnicode(self.cts.strftime('%m-%d-%y %H:%M:%S') if self.cts else 'None'),
StringUtils.toUnicode(self.upts.strftime('%m-%d-%y %H:%M:%S') if self.upts else 'None'),
(' %s' % modelInfo) if modelInfo else '')
示例9: getPrefix
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def getPrefix(self, *args, **kwargs):
if self._locationPrefix:
item = self.getStackData()[-1]
loc = ' -> %s #%s]' % (item['file'], StringUtils.toUnicode(item['line']))
else:
loc = ']'
return StringUtils.toUnicode(
self.getTime(self.timezone).strftime('[%a %H:%M <%S.%f>') + loc)
示例10: getUidTimecode
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def getUidTimecode(cls, prefix=None, suffix=None):
""" Creates a timecode down to the microsecond for use in creating unique UIDs. """
out = Base64.to64(cls.getNowSeconds()) + "-" + Base64.to64(datetime.microsecond)
return (
((StringUtils.toUnicode(prefix) + "-") if prefix else "")
+ out
+ (("-" + StringUtils.toUnicode(suffix)) if suffix else "")
)
示例11: _compileUiFile
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def _compileUiFile(self, path, filename):
"""Doc..."""
source = FileUtils.createPath(path, filename, isFile=True)
if self._verbose:
self._log.write('COMPILING: ' + source)
if PyGlassEnvironment.isWindows:
uicCommand = FileUtils.createPath(self._pythonPath, 'Scripts', 'pyside-uic.exe')
else:
uicCommand = 'pyside-uic'
cmd = '%s %s' % (uicCommand, source)
pipe = subprocess.Popen(
cmd,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, error = pipe.communicate()
if pipe.returncode or error:
self._log.write('ERROR: Failed to compile %s widget: %s' % (str(source), str(error)))
return False
out = StringUtils.toUnicode(out)
res = WidgetUiCompiler._CLASS_NAME_RE.search(out)
if not res:
self._log.write('ERROR: Failed to find widget class name for ' + str(source))
return False
out = WidgetUiCompiler._CLASS_NAME_RE.sub('PySideUiFileSetup', out, 1)
res = WidgetUiCompiler._SETUP_UI_RE.search(out)
if not res:
self._log.write('ERROR: Failed to find widget setupUi method for ' + str(source))
return False
targetName = res.groupdict().get('parentName')
out = WidgetUiCompiler._SETUP_UI_RE.sub('\g<parentName>', out, 1)
res = WidgetUiCompiler._RETRANSLATE_RE.search(out)
if not res:
self._log.write('ERROR: Failed to find widget retranslateUi method for ' + str(source))
return False
out = WidgetUiCompiler._RETRANSLATE_RE.sub('\g<parentName>', out, 1)
out = StringUtils.toUnicode(out)
out = WidgetUiCompiler._SELF_RE.sub(targetName + '.', out)
dest = FileUtils.createPath(path, filename[:-3] + '.py', isFile=True)
if os.path.exists(dest):
os.remove(dest)
f = open(dest, 'w+')
f.write(out)
f.close()
py_compile.compile(dest)
return True
示例12: openSpreadsheet
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def openSpreadsheet(self):
"""(Re)Loads the spreadsheet."""
self._doc = load(self._filepath)
rows = self._doc.spreadsheet.getElementsByType(TableRow)
dataWidth = 1
# Determine data-width (as opposed to trailing blank cells)
cells = rows[0].getElementsByType(TableCell)
for cell in cells[1:]:
pl = cell.getElementsByType(P)
if len(pl) > 0 and (pl[0].firstChild) and len(StringUtils.toUnicode(pl[0].firstChild)) > 0:
dataWidth += 1
else:
break
# Expand out / decompress repeated cells (e.g. number-columns-repeated="2")
for row in rows:
cells = row.getElementsByType(TableCell)
colNum = 0
for cell in cells:
if colNum < dataWidth:
repeated = int(cell.getAttribute('numbercolumnsrepeated') or 0)
pl = cell.getElementsByType(P)
if repeated > 1:
if len(pl) > 0 and pl[0].firstChild and len(StringUtils.toUnicode(pl[0].firstChild)) > 0:
for i in range(repeated):
c = TableCell()
p = P()
p.addText(StringUtils.toUnicode(pl[0].firstChild))
c.addElement(p)
row.insertBefore(c, cell)
row.removeChild(cell)
else:
for i in range(min(repeated, dataWidth-colNum)):
c = TableCell()
p = P()
p.addText(StringUtils.toUnicode(''))
c.addElement(p)
row.insertBefore(c, cell)
row.removeChild(cell)
else:
row.removeChild(cell)
colNum += 1
# Add a constant 3 trailing columns
for i in range(3):
c = TableCell()
p = P()
p.addText(StringUtils.toUnicode(''))
c.addElement(p)
row.addElement(c)
示例13: unpack
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def unpack(self, dataType, length):
data = StringUtils.unicodeToStr(self.read(length))
assert len(data) == length, \
u"[UNPACK ERROR]: Unexpected end of stream [%s | %s]" % (
StringUtils.toUnicode(len(data)), StringUtils.toUnicode(length))
try:
return struct.unpack(StringUtils.unicodeToStr(self.endianess + dataType), data)[0]
except struct.error:
print(len(data))
print(u"Unable to unpack '%r'" % data)
raise
示例14: logMessageToString
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def logMessageToString(
cls, logMessage, includePrefix =True, includeStack =True, prefixSeparator ='\n ',
stackSeparator ='\n'
):
out = []
if includePrefix and 'prefix' in logMessage:
out.append(StringUtils.toUnicode(logMessage['prefix']) + prefixSeparator)
out.append(StringUtils.toUnicode(logMessage['log']))
if includeStack and 'stack' in logMessage:
out.append(stackSeparator + StringUtils.toUnicode(logMessage['stack']))
return ''.join(out)
示例15: _buildHttpsReply
# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import toUnicode [as 别名]
def _buildHttpsReply(self, parent, request, url, operation, data, page):
headers = dict()
for header in request.rawHeaderList():
headers[StringUtils.toUnicode(header)] = StringUtils.toUnicode(request.rawHeader(header))
if data:
data = data.readAll()
thread = HttpsRemoteExecutionThread(
parent=self,
operation=operation,
data=data,
headers=headers,
url=url.toString())
thread.completeSignal.signal.connect(self._handleHttpsResult)
thread.start()