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


Python StringUtils.strToUnicode方法代码示例

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


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

示例1: found_terminator

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def found_terminator(self):
        if self.handling:
            return

        self.set_terminator(None) # connections sometimes over-send
        self.handling = True
        # noinspection PyTypeChecker
        self._chunk.writeString(''.join(self._data))
        self._chunk.position = 0
        self._requestFlags    = self._chunk.readUint32()
        self._message        = StringUtils.strToUnicode(str(self._chunk.read(-1)))
        self.handle_request()
开发者ID:sernst,项目名称:Nimble,代码行数:14,代码来源:NimbleRouter.py

示例2: append

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def append(self, text):
        #self.statusText.moveCursor(QtGui.QTextCursor.End)
        #self.statusText.insertHtml(StringUtils.strToUnicode(text))
        self.statusText.append(StringUtils.strToUnicode(text))

        self.statusText.moveCursor(QtGui.QTextCursor.End)
        self.statusText.moveCursor(QtGui.QTextCursor.StartOfLine)

        print(u'\n' + 60*u'-')
        print(text)
        print(u'--- RESULT ---')
        print(self.statusText.toHtml())
开发者ID:sernst,项目名称:Cadence,代码行数:14,代码来源:StatusWidget.py

示例3: createLogMessage

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def createLogMessage(
            cls, logValue, traceStack, shaveStackTrace, htmlEscape, prefix =None, **kwargs
    ):
        """ Formats log message data into a string for output """
        doIndent = kwargs.get('indent', True)

        if doIndent:
            logValue = cls.formatAsString(logValue)
        elif isinstance(logValue, (list, tuple)):
            logValue = '\n'.join(logValue)

        if htmlEscape:
            logValue = StringUtils.htmlEscape(logValue)

        if doIndent:
            logValue = logValue.replace('\n', '\n    ')
        logValue = StringUtils.strToUnicode(logValue)

        if not StringUtils.isStringType(logValue):
            logValue = 'FAILED TO LOG RESPONSE'

        out = {'log':logValue}

        if prefix:
            logPrefix = StringUtils.strToUnicode(prefix)
            if not StringUtils.isStringType(logPrefix):
                logPrefix = 'FAILED TO CREATE PREFIX'
            out['prefix'] = logPrefix

        if traceStack:
            logStack = StringUtils.strToUnicode(
                'Stack Trace:\n' + cls.getFormattedStackTrace(shaveStackTrace))
            if not StringUtils.isStringType(logStack):
                logStack = 'FAILED TO CREATE STACK'
            out['stack'] = logStack

        return out
开发者ID:sernst,项目名称:PyAid,代码行数:39,代码来源:Logger.py

示例4: cleanBytesToText

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def cleanBytesToText(cls, source, inPlace =True):
        """cleanBytesToText doc..."""

        out = source if inPlace else dict()
        from pyaid.list.ListUtils import ListUtils
        for n, v in cls.iter(source):
            if isinstance(v, (tuple, list)):
                v = ListUtils.cleanBytesToText(v, inPlace=inPlace)
            elif isinstance(v, dict):
                v = cls.cleanBytesToText(v)
            else:
                v = StringUtils.strToUnicode(v, force=False)

            out[StringUtils.toStrStr(n)] = v

        return out
开发者ID:sernst,项目名称:PyAid,代码行数:18,代码来源:DictUtils.py

示例5: itemsToUnicode

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def itemsToUnicode(cls, target, inPlace =False):
        """ Iterates through the elements of the target list and converts each of them to unicode
            strings, including decoding byte strings to unicode strings."""

        from pyaid.string.StringUtils import StringUtils

        output = target if inPlace else []
        index  = 0

        while index < len(target):
            source = target[index]
            if StringUtils.isStringType(source):
                output[index] = StringUtils.strToUnicode(source)
            else:
                output[index] = StringUtils.toUnicode(source)

        return output
开发者ID:sernst,项目名称:PyAid,代码行数:19,代码来源:ListUtils.py

示例6: prettyPrint

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def prettyPrint(cls, source, separator = ', '):
        """prettyPrint doc..."""
        out = []

        from pyaid.dict.DictUtils import DictUtils

        for v in source:
            if isinstance(v, (list, tuple)):
                v = cls.prettyPrint(v, separator=',')
            if isinstance(v, dict):
                v = DictUtils.prettyPrint(v)
            elif isinstance(v, StringUtils.BINARY_TYPE):
                v = StringUtils.strToUnicode(v)
            else:
                v = StringUtils.toUnicode(v)
            out.append(v)

        return '[%s]' % separator.join(out)
开发者ID:sernst,项目名称:PyAid,代码行数:20,代码来源:ListUtils.py

示例7: cleanBytesToText

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def cleanBytesToText(cls, source, inPlace =True):
        """cleanBytesToText doc..."""

        out = source if inPlace else []
        from pyaid.dict.DictUtils import DictUtils
        for i in range(len(source)):
            v = source[i]
            if isinstance(v, (tuple, list)):
                v = cls.cleanBytesToText(v, inPlace=inPlace)
            elif isinstance(v, dict):
                v = DictUtils.cleanBytesToText(v, inPlace=inPlace)
            else:
                v = StringUtils.strToUnicode(v, force=False)

            if inPlace:
                out[i] = v
            else:
                out.append(v)

        return out
开发者ID:sernst,项目名称:PyAid,代码行数:22,代码来源:ListUtils.py

示例8: itemsToString

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def itemsToString(cls, target, inPlace =False, toUnicode =True):
        """ Iterates through the elements of the target list and converts each of them to binary
            strings, including decoding unicode strings to byte strings."""

        from pyaid.string.StringUtils import StringUtils

        output = target if inPlace else (target + [])
        index  = 0

        while index < len(target):
            source = target[index]
            if StringUtils.isStringType(source):
                if toUnicode:
                    output[index] = StringUtils.strToUnicode(source)
                else:
                    output[index] = StringUtils.unicodeToStr(source, force=True)
            else:
                output[index] = str(source)
            index += 1

        return output
开发者ID:sernst,项目名称:PyAid,代码行数:23,代码来源:ListUtils.py

示例9: prettyPrint

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def prettyPrint(cls, source, delimiter = ' | ', separator = ': '):
        if not source:
            return '[EMPTY]'

        from pyaid.list.ListUtils import ListUtils
        out = []
        for n,v in cls.iter(source):
            n = StringUtils.toUnicode(n)

            if isinstance(v, dict):
                v = '{ ' + cls.prettyPrint(v, delimiter=delimiter, separator=separator) + ' }'
            elif isinstance(v, StringUtils.BINARY_TYPE):
                v = StringUtils.strToUnicode(v)
            elif isinstance(v, (list, tuple)):
                v = ListUtils.prettyPrint(v)
            else:
                v = StringUtils.toUnicode(v)

            out.append(n + separator + v)

        out.sort(key=StringUtils.TEXT_TYPE.lower)
        return delimiter.join(out)
开发者ID:sernst,项目名称:PyAid,代码行数:24,代码来源:DictUtils.py

示例10: _reformat

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
 def _reformat(cls, src):
     out = dict()
     for n,v in DictUtils.iter(src):
         n = StringUtils.strToUnicode(n)
         out[n] = cls._reformatValue(v)
     return out
开发者ID:sernst,项目名称:PyAid,代码行数:8,代码来源:JSON.py

示例11: _sendRemote

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def _sendRemote(self, nimbleData):
        responseFlags = 0
        message       = u''
        retry         = NimbleEnvironment.REMOTE_RETRY_COUNT

        while retry > 0:
            try:
                self.open()
            except Exception as err:
                failure = [
                    '[ERROR | NIMBLE COMMUNICATION] Unable to open connection',
                    err ]
                retry -= 1
                if retry == 0:
                    if not nimble.quietFailure:
                        NimbleEnvironment.logError(failure[0], failure[1])
                    return None
                continue

            try:
                serialData = nimbleData.serialize()
            except Exception as err:
                failure = [
                    '[ERROR | NIMBLE COMMUNICATION] Unable to serialize data for transmission',
                    err ]
                if not nimble.quietFailure:
                    NimbleEnvironment.logError(failure[0], failure[1])
                return None

            try:
                self._chunk.clear()
                self._chunk.writeUint32(NimbleEnvironment.CONNECTION_FLAGS)
                self._chunk.writeString(serialData + NimbleEnvironment.TERMINATION_IDENTIFIER)
                self._socket.sendall(self._chunk.byteArray)
            except Exception as err:
                failure = [
                    '[ERROR | NIMBLE COMMUNICATION] Unable to send data',
                    err ]
                self.close()
                retry -= 1
                if retry == 0:
                    if not nimble.quietFailure:
                        NimbleEnvironment.logError(failure[0], failure[1])
                    return None
                continue

            try:
                self._chunk.clear()
                b = SocketUtils.receiveInChunks(
                    self._socket,
                    chunkSize=NimbleEnvironment.SOCKET_RESPONSE_CHUNK_SIZE)
                self._chunk.writeString(b)
                self._chunk.position = 0
                responseFlags  = self._chunk.readUint32()
                message        = StringUtils.strToUnicode(self._chunk.read(-1))

                # Break while loop on successful reading of the result
                if message is not None:
                    break

            except Exception as err:
                if not nimble.quietFailure:
                    NimbleEnvironment.logError(
                        '[ERROR | NIMBLE COMMUNICATION] Unable to read response', err)
                self.close()
                return None

        try:
            if not (responseFlags & ConnectionFlags.KEEP_ALIVE):
                self.close()
        except Exception as err:
            if not nimble.quietFailure:
                NimbleEnvironment.logError(
                    '[ERROR | NIMBLE COMMUNICATION] Unable to close connection', err)

        try:
            return NimbleData.fromMessage(message)
        except Exception as err:
            if not nimble.quietFailure:
                NimbleEnvironment.logError(
                    '[ERROR | NIMBLE COMMUNICATION] Response data parsing failure', err)
            return None
开发者ID:sernst,项目名称:Nimble,代码行数:84,代码来源:NimbleConnection.py

示例12: _runImpl

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import strToUnicode [as 别名]
    def _runImpl(self):
        model   = Tracks_SiteMap.MASTER
        session = self._session if self._session else model.createSession()

        try:
            self._log.write(u'<h1>Beginning Sitemap Import...</h1>')
            if self._path is None or not os.path.exists(self._path):
                self._log.write(u'<h2>Invalid or missing path</h2>')
                return 1

            # Delete all existing rows
            rowCount = session.query(model).count()
            if rowCount > 0:
                session.query(model).delete()

            with open(self._path, 'rU') as f:
                try:
                    reader = csv.reader(
                        f,
                        delimiter=StringUtils.toStr2(','),
                        quotechar=StringUtils.toStr2('"'))
                except Exception as err:
                    self._writeError({
                        'message':u'ERROR: Unable to read CSV file "%s"' % self._path,
                        'error':err })
                    return

                if reader is None:
                    self._writeError({
                        'message':u'ERROR: Failed to create CSV reader for file "%s"' % self._path })
                    return

                for row in reader:
                    # Skip any rows that don't start with the proper numeric index value, which
                    # includes the header row (if it exists) with the column names
                    try:
                        index = int(row[0])
                    except Exception as err:
                        continue

                    rowDict = dict()
                    for column in Reflection.getReflectionList(SitemapCsvColumnEnum):
                        value = row[column.index]
                        value = StringUtils.strToUnicode(value)

                        if value != u'' or value is None:
                            rowDict[column.name] = value

                    self._fromSpreadsheetEntry(rowDict, session)

        except Exception as err:
            if not self._session:
                session.rollback()
                session.close()

            self._log.writeError(u'ERROR: Sitemap Importing Error', err)
            return 1

        if self._session is None:
            session.commit()
            session.close()

        self._log.write(u'<h1>Sitemap Import Complete</h1>')
        return 0
开发者ID:sernst,项目名称:Cadence,代码行数:66,代码来源:SitemapImporterRemoteThread.py


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