本文整理汇总了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
示例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
示例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