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


Python JSON.asString方法代码示例

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


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

示例1: _createSetupFile

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def _createSetupFile(self, binPath):
        path = FileUtils.createPath(binPath, 'setup.py', isFile=True)
        scriptPath = inspect.getabsfile(self.applicationClass)

        try:
            sourcePath = PyGlassEnvironment.getPyGlassResourcePath(
                '..', 'setupSource.txt', isFile=True)
            f      = open(sourcePath, 'r+')
            source = f.read()
            f.close()
        except Exception as err:
            print(err)
            return None

        try:
            f = open(path, 'w+')
            f.write(source.replace(
                '##SCRIPT_PATH##', StringUtils.escapeBackSlashes(scriptPath)
            ).replace(
                '##RESOURCES##', StringUtils.escapeBackSlashes(JSON.asString(self.resources))
            ).replace(
                '##INCLUDES##', StringUtils.escapeBackSlashes(JSON.asString(self.siteLibraries))
            ).replace(
                '##ICON_PATH##', StringUtils.escapeBackSlashes(self._createIcon(binPath))
            ).replace(
                '##APP_NAME##', self.appDisplayName
            ).replace(
                '##SAFE_APP_NAME##', self.appDisplayName.replace(' ', '_') ))
            f.close()
        except Exception as err:
            print(err)
            return None

        return path
开发者ID:sernst,项目名称:PyGlass,代码行数:36,代码来源:PyGlassApplicationCompiler.py

示例2: add

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def add(self, *args, **kwargs):
        """Adds value to the existing item, replacing existing entries.

        @@@param value:string
            The value argument can be a single value.

        @@@param group:string
            The name of the group in which to add the value. Default of None adds the value to the
            root group.
        """

        value = ArgsUtils.get('value', None, kwargs, args, 0)
        if value is None:
            value = u''
        elif isinstance(value, dict) or isinstance(value, list):
            value = JSON.asString(value)
        else:
            value = unicode(value)

        group = ArgsUtils.get('group', None, kwargs, args, 1)
        once  = ArgsUtils.get('once', False, kwargs)

        if group:
            target        = self._tempSubs if once else self._subs
            target[group] = value
        else:
            if once:
                self._tempRoot = value
            else:
                self._root = value
开发者ID:sernst,项目名称:StaticFlow,代码行数:32,代码来源:SingleValuedDataOrganizer.py

示例3: _writeImpl

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def _writeImpl(self, value, *args, **kwargs):
        if not value:
            return u''
        elif isinstance(value, dict) or isinstance(value, list):
            value = JSON.asString(value)
        elif not isinstance(value, basestring):
            value = str(value)
        value = value.replace("'", "\'").replace('\n',' ')

        offset = value.find('\'')
        while offset != -1:
            if offset == 0 or value[offset-1] != '\\':
                value = value[:offset] + '\\' + value[offset:]
            offset = value.find('\'', offset + 1)

        if not value:
            kwargs['writeEmpty'] = False
            for j in self._joins:
                v = j.write(*args, **kwargs)
                if v:
                    return v

            if not ArgsUtils.get('writeEmpty', True, kwargs):
                return None

        return u'%s=\'%s\'' % (self._name, value)
开发者ID:sernst,项目名称:StaticFlow,代码行数:28,代码来源:SingleValuedAttributeDataOrganizer.py

示例4: _setEnvValue

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def _setEnvValue(cls, key, value):
        settings = cls._getEnvValue(None) if cls._ENV_SETTINGS is None else cls._ENV_SETTINGS
        if settings is None:
            settings = dict()
            cls._ENV_SETTINGS = settings

        if isinstance(key, basestring):
            key = [key]

        src = settings
        for k in key[:-1]:
            src = src[k]
        src[key[-1]] = value

        envPath = cls.getRootLocalResourcePath(cls._GLOBAL_SETTINGS_FILE, isFile=True)
        envDir  = os.path.dirname(envPath)
        if not os.path.exists(envDir):
            os.makedirs(envDir)

        f = open(envPath, 'w+')
        try:
            f.write(JSON.asString(cls._ENV_SETTINGS))
        except Exception, err:
            print 'ERROR: Unable to write environmental settings file at: ' + envPath
            return False
开发者ID:hannahp,项目名称:PyGlass,代码行数:27,代码来源:PyGlassEnvironment.py

示例5: flush

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def flush(self):
        if not self._buffer:
            return

        if sys.platform.startswith('win'):
            return

        items = []
        for b in self._buffer:
            try:
                d    = DictUtils.merge(self._meta, b['data'])
                item = b['prefix'] + ' ' + JSON.asString(d)
            except Exception as err:
                item = '>> EXCEPTION: JSON ENCODING FAILED >> ' + str(err).replace('\n', '\t')

            try:
                item = item.encode('utf8', 'ignore')
            except Exception as err:
                item = '>> EXCEPTION: UNICODE DECODING FAILED >> ' + str(err).replace('\n', '\t')

            items.append(item)

        count   = self._fileCount
        offset  = random.randint(0, count - 1)
        success = False
        path    = self.getReportFolder() + self._timeCode + '/'
        if not os.path.exists(path):
            os.makedirs(path)

        for i in range(count):
            index = (i + offset) % count
            p     = path + str(index) + '.report'
            lock  = FileLock(p)
            if lock.i_am_locking() and i < count - 1:
                continue

            try:
                lock.acquire()
            except Exception:
                continue

            try:
                out = StringUtils.toUnicode('\n'.join(items) + '\n')
                f   = open(p, 'a+')
                f.write(out.encode('utf8'))
                f.close()
                success = True
            except Exception as err:
                print("REPORTER ERROR: Unable to write report file.")
                print(err)

            lock.release()
            if success:
                break

        self.clear()
        return success
开发者ID:sernst,项目名称:PyAid,代码行数:59,代码来源:Reporter.py

示例6: _storeBuildSnapshot

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def _storeBuildSnapshot(self):
        if not self._buildSnapshot:
            return

        snap = dict()
        for n,v in self._buildSnapshot.iteritems():
            if n in ['parent']:
                continue

            snap[n] = v

        settings = SettingsConfig(CompilerDeckEnvironment.projectSettingsPath, pretty=True)
        settings.set(['BUILD', 'LAST_SNAPSHOT'], JSON.asString(snap))
开发者ID:sernst,项目名称:CompilerDeck,代码行数:15,代码来源:DeckCompileWidget.py

示例7: _createErrorResult

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def _createErrorResult(self, code =None, info =None, data=None):
        out = dict(
            success=False,
            error=True,
            code=code if code else 'COMMUNICATOR_ERROR',
            info=info if info else 'Unknown error occurred.',
            data=data )

        # Keep errors to the 50 most recent to prevent memory overloads on long sessions.
        while len(self._errors) > 49:
            self._errors.pop(0)
        self._errors.append(out)

        return JSON.asString(out)
开发者ID:sernst,项目名称:PyGlass,代码行数:16,代码来源:PyGlassCommunicator.py

示例8: _createAttr

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def _createAttr(self, name, value):
        if not value:
            return u''
        elif isinstance(value, dict) or isinstance(value, list):
            value = JSON.asString(value)
        elif not isinstance(value, basestring):
            value = str(value)
        value = value.replace("'", "\'").replace('\n',' ')

        offset = value.find('\'')
        while offset != -1:
            if offset == 0 or value[offset-1] != '\\':
                value = value[:offset] + '\\' + value[offset:]
            offset = value.find('\'', offset + 1)

        return u'%s%s=\'%s\'' % (self._prefix, name, value)
开发者ID:sernst,项目名称:StaticFlow,代码行数:18,代码来源:AttributeDataOrganizer.py

示例9: flush

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def flush(self):
        if not self._buffer:
            return

        if sys.platform.startswith('win'):
            return

        items = []
        for b in self._buffer:
            try:
                d    = dict(self._meta.items() + b['data'].items())
                item = b['prefix'] + u' ' + JSON.asString(d)
            except Exception, err:
                item = '>> EXCEPTION: JSON ENCODING FAILED >> ' + str(err).replace('\n', '\t')

            try:
                item = item.encode('utf8', 'ignore')
            except Exception, err:
                item = '>> EXCEPTION: UNICODE DECODING FAILED >> ' + str(err).replace('\n', '\t')
开发者ID:hannahp,项目名称:PyAid,代码行数:21,代码来源:Reporter.py

示例10: handle

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def handle(self):
        try:
            data = self.rfile.readline().strip()
            self._log.write('HANDLE: ' + str(data))
            try:
                result = self._respondImpl(JSON.fromString(unquote(data)))
            except Exception as err:
                self._log.writeError('RESPOND FAILURE', err)
                if self.returnResponse:
                    self.wfile.write(JSON.asString({'error':1}))
                return

            if self.returnResponse:
                out = {'error':0}
                if result:
                    out['payload'] = result
                self.wfile.write(out)
        except Exception as err:
            self._log.write('HANDLE FAILURE', err)

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

示例11: _createSuccessResult

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
 def _createSuccessResult(self, payload):
     return JSON.asString(dict(
         success=True,
         error=False,
         payload=payload
     ))
开发者ID:hannahp,项目名称:PyGlass,代码行数:8,代码来源:PyGlassCommunicator.py

示例12: sha256hmacSign

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
 def sha256hmacSign(cls, key, **kwargs):
     return cls.sha256hmac(key, JSON.asString(kwargs))
开发者ID:sernst,项目名称:PyAid,代码行数:4,代码来源:HashUtils.py

示例13: _renderImpl

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
    def _renderImpl(self, **kwargs):
        if self._processor.globalVars:
            self._processor.globalVars.includeTwitterWidgetAPI = True

        a         = self.attrs
        q         = a.get(TagAttributesEnum.SEARCH, '@vizme', kwargs)
        start     = a.get(TagAttributesEnum.START, None, kwargs)
        stop      = a.get(TagAttributesEnum.STOP, None, kwargs)
        skips     = a.get(TagAttributesEnum.IGNORE, None, kwargs)
        height    = a.getAsEnumerated(TagAttributesEnum.HEIGHT, GeneralSizeEnum, GeneralSizeEnum.medium)
        title     = a.get(TagAttributesEnum.TITLE, '', kwargs)
        subtitle  = a.get(TagAttributesEnum.SUBTITLE, '', kwargs)
        count     = a.get(TagAttributesEnum.COUNT + TagAttributesEnum.TWEETS, 10, kwargs)
        scrollbar = a.getAsBool(TagAttributesEnum.SCROLL, count > 5, kwargs)
        interval  = a.getAsInt(TagAttributesEnum.TIME, 5, kwargs)
        loop      = a.getAsBool(TagAttributesEnum.LOOP, interval > 0, kwargs)

        if not isinstance(q, list):
            q = [q]
        user = len(q) == 1 and q[0].startswith('@') and not StringUtils.contains(q[0], [' ', ','])
        q = u' OR '.join(q)

        if height in ['none', 'm']:
            height = 300
        elif height == 'xxs':
            height = 100
        elif height == 'xs':
            height = 175
        elif height == 's':
            height = 250
        elif height == 'l':
            height = 375
        elif height == 'xl':
            height = 450
        elif height == 'xxl':
            height = 525
        else:
            height = 300

        if skips:
            user = False
            q += u' ' + (u'-' + skips if isinstance(skips, basestring) else u' -'.join(skips))

        if start or stop:
            user = False
            if start:
                q += u' since:' + start

            if stop:
                q += u' until:' + stop


        data = {
            'id':a.id.get(),
            'version':2,
            'width':'auto',
            'height':height,
            'interval':1000*interval,
            'theme': {
                'shell': {
                    'background': a.backColors.baseColor.web,
                    'color': a.focalColors.highlightColor.web
                },

                'tweets': {
                    'background': a.backColors.baseColor.web,
                    'color': a.focalColors.baseColor.web,
                    'links': a.focalColors.linkColor.web
                }
            },
            'features': {
                'scrollbar':scrollbar,
                'loop':loop,
                'live':interval > 0,
                'behavior':  u'all' if user else u'default'
            },

            'type': 'profile' if user else 'search'
        }

        if user:
            a.render['setUser'] = u'.setUser("' + q + u'")'
            data['rpp']         = count
        else:
            a.render['setUser'] = u''
            data['search']      = q
            data['title']       = subtitle.capitalize() if subtitle else string.capwords(q)
            data['subject']     = title.capitalize() if title else string.capwords(q.split(' ')[0])

        a.render['twitterData'] = JSON.asString(data).replace("'", "\\'")
开发者ID:sernst,项目名称:StaticFlow,代码行数:92,代码来源:TwitterTag.py

示例14: callJavascript

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
 def callJavascript(self, function, data =None):
     frame = self._webView.page().mainFrame()
     frame.addToJavaScriptWindowObject(self.javaScriptID, self)
     frame.evaluateJavaScript(
         u'try{ window.%s(%s); } catch (e) {}' % (function, JSON.asString(data) if data else u'')
     )
开发者ID:hannahp,项目名称:PyGlass,代码行数:8,代码来源:PyGlassCommunicator.py

示例15: _writeImpl

# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import asString [as 别名]
 def _writeImpl(self, value, kwargs):
     return JSON.asString(value)
开发者ID:sernst,项目名称:StaticFlow,代码行数:4,代码来源:KeyDataOrganizer.py


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