當前位置: 首頁>>代碼示例>>Python>>正文


Python KoLintResult.encodedDescription方法代碼示例

本文整理匯總了Python中koLintResult.KoLintResult.encodedDescription方法的典型用法代碼示例。如果您正苦於以下問題:Python KoLintResult.encodedDescription方法的具體用法?Python KoLintResult.encodedDescription怎麽用?Python KoLintResult.encodedDescription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在koLintResult.KoLintResult的用法示例。


在下文中一共展示了KoLintResult.encodedDescription方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: lint_with_text

# 需要導入模塊: from koLintResult import KoLintResult [as 別名]
# 或者: from koLintResult.KoLintResult import encodedDescription [as 別名]
    def lint_with_text(self, request, text):
        if not text.strip():
            return None
        cwd = request.cwd
        env = koprocessutils.getUserEnv()
        settingsDir = env.get("DJANGO_SETTINGS_MODULE", None)
        if not settingsDir:
            settingsDir = self._getSettingsDir(cwd)
        if settingsDir:
            # Save the current buffer to a temporary file.
            tmpFileName = tempfile.mktemp()
            fout = open(tmpFileName, 'wb')
            try:
                fout.write(text)
                fout.close()

                #XXX: How to tell whether we're using Python or Python3?
                prefName = "pythonExtraPaths"
                pythonPath =  request.prefset.getString(prefName, "")
                pythonPathEnv = env.get("PYTHONPATH", "")
                if pythonPathEnv:
                    if pythonPath:
                        pythonPath += os.pathsep + pythonPathEnv
                    else:
                        pythonPath = pythonPathEnv
                if pythonPath:
                    if sys.platform.startswith("win"):
                        pythonPath = pythonPath.replace('\\', '/')
                    env["PYTHONPATH"] = pythonPath
                elif env.has_key("PYTHONPATH"):
                    del env["PYTHONPATH"]

                results = koLintResults()
                pythonExe = self._pythonInfo.getExecutableFromDocument(request.koDoc)
                argv = [pythonExe, self._djangoLinterPath,
                        tmpFileName, settingsDir]
                p = process.ProcessOpen(argv, cwd=cwd, env=env, stdin=None)
                output, error = p.communicate()
                #log.debug("Django output: output:[%s], error:[%s]", output, error)
                retval = p.returncode
            finally:
                os.unlink(tmpFileName)
            if retval == 1:
                if error:
                    results.addResult(self._buildResult(text, error))
                else:
                    results.addResult(self._buildResult(text, "Unexpected error"))
        else:
            result = KoLintResult()
            result.lineStart = 1
            result.lineEnd = 1
            result.columnStart = 1
            result.columnEnd = 1 + len(text.splitlines(1)[0])
            result.description = "Can't find settings.py for this Django file"
            result.encodedDescription = result.description
            result.severity = result.SEV_ERROR
            results = koLintResults()
            results.addResult(result)
        return results
開發者ID:ball6847,項目名稱:openkomodo,代碼行數:61,代碼來源:koDjango_UDL_Language.py

示例2: _fixPerlPart

# 需要導入模塊: from koLintResult import KoLintResult [as 別名]
# 或者: from koLintResult.KoLintResult import encodedDescription [as 別名]
 def _fixPerlPart(self, text):
     parts = self._masonMatcher.findall(text)
     if not parts:
         return "", []
     i = 0
     lim = len(parts)
     perlTextParts = []
     masonLintResults = []
     eols = ("\n", "\r\n")
     
     # states
     currTags = []
     perlTags = ('init', 'perl', 'once') # drop code for other tags.
     lineNo = i
     while i < lim:
         part = parts[i]
         if part in eols:
             perlTextParts.append(part)
         elif part.startswith("%") and (i == 0 or parts[i - 1].endswith("\n")):
             m = self._perlLineRE.match(part)
             if not m:
                 perlTextParts.append(self._spaceOutNonNewlines(part))
             else:
                 perlTextParts.append(self._spaceOutNonNewlines(m.group(1)))
                 perlTextParts.append(m.group(2))
         elif part.startswith("<"):
             m = self._blockTagRE.match(part)
             if m:
                 payload = m.group(2)
                 if m.group(1):
                     unexpectedEndTag = None
                     if currTags:
                         currTag = currTags[-1]
                         if currTag == payload:
                             currTags.pop()
                         else:
                             # Recover by removing everything up to and including the tag
                             unexpectedEndTag = currTags[-1]
                             for idx in range(len(currTags) - 1, -1, -1):
                                 if currTags[idx] == payload:
                                     del currTags[idx:-1]
                                     break
                     else:
                         unexpectedEndTag = "not in a tag block"
                     if unexpectedEndTag is not None:
                         lr = KoLintResult()
                         lr.lineStart = lr.lineEnd = lineNo + 1
                         lr.columnStart = 1
                         lr.columnEnd = 1 + len(text.splitlines()[lineNo])
                         if unexpectedEndTag == "not in a tag block":
                             lr.description = "Got end tag %s, not in a tag" % part
                         else:
                             lr.description = "Expected </%%%s>, got %s" % (
                                 unexpectedEndTag, part)
                         lr.encodedDescription = lr.description
                         lr.severity = lr.SEV_WARNING
                         masonLintResults.append(lr)
                 else:
                     currTags.append(payload)
                 perlTextParts.append(self._spaceOutNonNewlines(part))
             else:
                 m = self._exprRE.match(part)
                 if not m:
                     perlTextParts.append(self._spaceOutNonNewlines(part))
                 else:
                     perlTextParts.append(self._spaceOutNonNewlines(m.group(1)))
                     payload = m.group(2)
                     if payload.startswith("#"):
                         perlTextParts.append(payload) # One big comment
                     elif "|" not in payload:
                         perlTextParts.append("print " + payload + ";");
                     else:
                         # Filters aren't perl syntax, so punt
                         perlTextParts.append(self._spaceOutNonNewlines(m.group(2)))
                     perlTextParts.append(self._spaceOutNonNewlines(m.group(3)))
         else:
             # We only copy things out under certain circumstances
             if not currTags or currTags[-1] not in perlTags:
                 perlTextParts.append(self._spaceOutNonNewlines(part))
             else:
                 perlTextParts.append(part)
         i += 1
         lineNo += part.count("\n")
     return "".join(perlTextParts), masonLintResults
開發者ID:Acidburn0zzz,項目名稱:KomodoEdit,代碼行數:86,代碼來源:koMason_UDL_Language.py

示例3: lint_with_text

# 需要導入模塊: from koLintResult import KoLintResult [as 別名]
# 或者: from koLintResult.KoLintResult import encodedDescription [as 別名]
    def lint_with_text(self, request, text):
        if not text.strip():
            return None
        cwd = request.cwd
        env = koprocessutils.getUserEnv()
        settingsDir = env.get("DJANGO_SETTINGS_MODULE", None)
        if not settingsDir:
            # Django wants to do something like "import project.settings", which
            # means "project/settings.py" needs to exist. First, try to find it.
            settingsDir = self._getSettingsDir(cwd)
            # Ultimately, Komodo's Django linter (djangoLinter.py) sets the
            # DJANGO_SETTINGS_MODULE env variable to be the basename of
            # "settingsDir", which needs to be a module in the PYTHONPATH (which
            # the linter will append the dirname of "settingsDir" to). Append
            # ".settings" so when Django tries to do something like
            # "import project.settings", it will behave as expected.
            settingsDir += ".settings"
        if settingsDir:
            # Save the current buffer to a temporary file.
            tmpFileName = tempfile.mktemp()
            fout = open(tmpFileName, 'wb')
            try:
                fout.write(text)
                fout.close()

                #XXX: How to tell whether we're using Python or Python3?
                prefName = "pythonExtraPaths"
                pythonPath =  request.prefset.getString(prefName, "")
                pythonPathEnv = env.get("PYTHONPATH", "")
                if pythonPathEnv:
                    if pythonPath:
                        pythonPath += os.pathsep + pythonPathEnv
                    else:
                        pythonPath = pythonPathEnv
                if pythonPath:
                    if sys.platform.startswith("win"):
                        pythonPath = pythonPath.replace('\\', '/')
                    env["PYTHONPATH"] = pythonPath
                elif env.has_key("PYTHONPATH"):
                    del env["PYTHONPATH"]

                # First try to use Python2 to run the django linter. If django
                # is not found, use Python3 instead.
                results = koLintResults()
                pythonExe = self._pythonInfo.getExecutableFromDocument(request.koDoc)
                djangoLinterPath = self._djangoLinterPath
                if pythonExe:
                    p = process.ProcessOpen([pythonExe, "-c", "import django"], env=env, stdin=None)
                    output, error = p.communicate()
                    #log.debug("Django output: output:[%s], error:[%s]", output, error)
                    if error.find('ImportError:') >= 0 and \
                       self._python3Info.getExecutableFromDocument(request.koDoc):
                        pythonExe = self._python3Info.getExecutableFromDocument(request.koDoc)
                        djangoLinterPath = self._djangoLinter3Path
                else:
                    pythonExe = self._python3Info.getExecutableFromDocument(request.koDoc)
                    djangoLinterPath = self._djangoLinter3Path
                #log.debug("pythonExe = " + pythonExe)
                #log.debug("djangoLinterPath = " + djangoLinterPath)
                argv = [pythonExe, djangoLinterPath,
                        tmpFileName, settingsDir]
                p = process.ProcessOpen(argv, cwd=cwd, env=env, stdin=None)
                output, error = p.communicate()
                retval = p.returncode
                #log.debug("Django output: output:[%s], error:[%s], retval:%d", output, error)
            finally:
                os.unlink(tmpFileName)
            if error:
                results.addResult(self._buildResult(text, error))
            elif retval != 0:
                results.addResult(self._buildResult(text, "Unexpected error"))
        else:
            result = KoLintResult()
            result.lineStart = 1
            result.lineEnd = 1
            result.columnStart = 1
            result.columnEnd = 1 + len(text.splitlines(1)[0])
            result.description = "Can't find settings.py for this Django file"
            result.encodedDescription = result.description
            result.severity = result.SEV_ERROR
            results = koLintResults()
            results.addResult(result)
        return results
開發者ID:Defman21,項目名稱:KomodoEdit,代碼行數:85,代碼來源:koDjango_UDL_Language.py


注:本文中的koLintResult.KoLintResult.encodedDescription方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。