本文整理汇总了Python中xpcom.server.UnwrapObject.lint_with_text方法的典型用法代码示例。如果您正苦于以下问题:Python UnwrapObject.lint_with_text方法的具体用法?Python UnwrapObject.lint_with_text怎么用?Python UnwrapObject.lint_with_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xpcom.server.UnwrapObject
的用法示例。
在下文中一共展示了UnwrapObject.lint_with_text方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KoXBLCompileLinter
# 需要导入模块: from xpcom.server import UnwrapObject [as 别名]
# 或者: from xpcom.server.UnwrapObject import lint_with_text [as 别名]
class KoXBLCompileLinter(object):
_com_interfaces_ = [components.interfaces.koILinter]
_reg_desc_ = "Komodo XBL Compile Linter"
_reg_clsid_ = "{4e023df3-4fda-4c74-abe0-b6623d72862e}"
_reg_contractid_ = "@activestate.com/koLinter?language=XBL;1"
_reg_categories_ = [
("category-komodo-linter", 'XBL'),
]
def __init__(self):
koLintService = components.classes["@activestate.com/koLintService;1"].getService(components.interfaces.koILintService)
self._html_linter = koLintService.getLinterForLanguage("HTML")
self._js_linter = UnwrapObject(koLintService.getLinterForLanguage("JavaScript"))
def lint(self, request):
try:
return UnwrapObject(self._html_linter).lint(request,
linters={"JavaScript":self})
except:
log.exception("Error linting XBL")
# We can't use standard JS linting to handle XBL methods,
# so wrap the JSLinter, and filter out results complaining
# about return stmts outside functions.
def lint_with_text(self, request, text):
#log.debug("XBL text: %s", text)
jsResults = self._js_linter.lint_with_text(request, text)
#log.debug("XBL lint results: %s",
# [str(x) for x in jsResults.getResults()])
fixedResults = koLintResults()
for res in jsResults.getResults():
if 'return not in function' not in res.description:
fixedResults.addResult(res)
return fixedResults
示例2: KoRHTMLLinter
# 需要导入模块: from xpcom.server import UnwrapObject [as 别名]
# 或者: from xpcom.server.UnwrapObject import lint_with_text [as 别名]
class KoRHTMLLinter(object):
_com_interfaces_ = [components.interfaces.koILinter]
_reg_desc_ = "RHTML Template Linter"
_reg_clsid_ = "{c7f2d724-5991-4df3-965b-12db942a4ad2}"
_reg_contractid_ = "@activestate.com/koLinter?language=RHTML;1"
_reg_categories_ = [
("category-komodo-linter", 'RHTML'),
]
def __init__(self):
koLintService = components.classes["@activestate.com/koLintService;1"].getService(components.interfaces.koILintService)
self._ruby_linter = UnwrapObject(koLintService.getLinterForLanguage("Ruby"))
self._html_linter = koLintService.getLinterForLanguage("HTML")
_RHTMLMatcher = re.compile(r'''(
(?:<%=?.*?(?:-?%>|$))
|(?:[^<]+|(?:<(?!%)))+ # Other non-RHTML
|.)''', # Catchall
re.VERBOSE|re.DOTALL)
_blockTagRE = re.compile(r'(<%)(=?)(.*?)((?:-?%>|$))', re.DOTALL)
def _fixRubyPart(self, text):
parts = self._RHTMLMatcher.findall(text)
if not parts:
return ""
i = 0
lim = len(parts)
rubyTextParts = []
while i < lim:
part = parts[i]
if part.startswith("<%"):
m = self._blockTagRE.match(part)
if not m:
rubyTextParts.append(self._spaceOutNonNewlines(part))
else:
emitText = m.group(2) == "="
log.debug("part %d: part:%s, emitText:%r", i, part, emitText)
rubyTextParts.append(self._spaceOutNonNewlines(m.group(1)))
if emitText:
rubyTextParts.append(self._spaceOutNonNewlines(' Proc.new { '))
else:
rubyTextParts.append(' ')
rubyTextParts.append(m.group(3))
rubyTextParts.append(self._spaceOutNonNewlines(m.group(4)))
if emitText:
rubyTextParts.append(self._spaceOutNonNewlines('}.call; '))
else:
rubyTextParts.append(self._spaceOutNonNewlines(part))
i += 1
return "".join(rubyTextParts)
_nonNewlineMatcher = re.compile(r'[^\r\n]')
def _spaceOutNonNewlines(self, markup):
return self._nonNewlineMatcher.sub(' ', markup)
_tplPatterns = ("RHTML", re.compile('<%='), re.compile(r'%>\s*\Z', re.DOTALL), 'Proc.new {', '}.call;')
def lint(self, request):
from codeintel2.rubycile import rails_role_from_path
# With the "squelching" the multi-language linter does to pull
# <% and %>-like tokens out of the lint input stream, there's no
# need to map all Ruby code to RHTML
if rails_role_from_path(request.koDoc.displayPath):
TPLInfo = list(self._tplPatterns) + [{"supportRERB": True}]
else:
TPLInfo = self._tplPatterns
return UnwrapObject(self._html_linter).lint(request, TPLInfo=TPLInfo)
def lint_with_text(self, request, text):
log.debug("rhtml lint: %s", text)
rubyText = self._fixRubyPart(text)
if not rubyText.strip():
return
rubyLintResults = self._resetLines(self._ruby_linter.lint_with_text(request, rubyText),
text)
return rubyLintResults
def _resetLines(self, lintResults, text):
from koLintResults import koLintResults
lines = text.splitlines()
fixedResults = koLintResults()
for res in lintResults.getResults():
try:
targetLine = lines[res.lineEnd - 1]
except IndexError:
log.exception("can't index %d lines at %d", len(lines), res.lineEnd - 1)
pass # Keep the original lintResult
else:
if res.columnEnd > len(targetLine):
res.columnEnd = len(targetLine)
fixedResults.addResult(res)
return fixedResults
示例3: KoKomodoSnippetLinter
# 需要导入模块: from xpcom.server import UnwrapObject [as 别名]
# 或者: from xpcom.server.UnwrapObject import lint_with_text [as 别名]
class KoKomodoSnippetLinter(object):
_com_interfaces_ = [components.interfaces.koILinter]
_reg_desc_ = "EJS Template Linter"
_reg_clsid_ = "{597b8e69-c0bd-4f27-be01-7e07d26120de}"
_reg_contractid_ = "@activestate.com/koLinter?language=Komodo%20Snippet;1"
_reg_categories_ = [
("category-komodo-linter", 'Komodo Snippet'),
]
def __init__(self):
self._jsLinter = UnwrapObject(components.classes["@activestate.com/koLintService;1"].getService(
components.interfaces.koILintService).getLinterForLanguage("JavaScript"))
def lint(self, request):
return self.lint_with_text(request, request.content)
def _escapeVerbatimLine(self, s):
return s.replace('\\', '\\\\').replace("'", "\\'")
def _addVerbatimPieces(self, finalPieces, s):
for line in s.splitlines(True):
lead = line.splitlines()[0]
nl = line[len(lead):]
if lead:
piece = "__ViewO.push('" + self._escapeVerbatimLine(lead)
if nl:
piece += "\\n');" + nl
else:
piece += "');"
finalPieces.append(piece)
elif nl:
finalPieces.append(nl)
def _addJSPieces(self, finalPieces, s):
# This is simple
finalPieces.append(s)
def _addEmittedPieces(self, finalPieces, s):
finalPieces.append("__ViewO.push(%s);" % (s))
# for line in s.splitlines():
# finalPieces.append("__ViewO.push(%s);\n" % (line,))
# states:
# 0: default
# 1: emitted JS
# 2: control JS
# 3: EJS comment block
_dot_to_space_re = re.compile(r'[^\r\n]')
def lint_with_text(self, request, text):
# Pull out the EJS parts and wrap into a single JS file
textAsBytes = text.encode("utf-8")
lim = len(textAsBytes)
finalPieces = ["var __ViewO = []; "]
i = 0
state = 0
results = koLintResults()
textLines = textAsBytes.splitlines()
lineNum = 1
haveJS = False
while i < lim:
if state == 0:
idx = textAsBytes.find("<%", i)
if idx == -1:
thisBit = textAsBytes[i:]
else:
thisBit = textAsBytes[i:idx]
lineNum += thisBit.count("\n")
self._addVerbatimPieces(finalPieces, thisBit)
if idx == -1:
break
try:
c = textAsBytes[idx + 2]
if c == '=':
haveJS = True
elif c == '#':
haveJS = True
elif c == '%':
pass # stay at state 0
else:
raise IndexError()
i = idx + 3
finalPieces.append(" ")
except IndexError:
state = 2
i = idx + 2
finalPieces.append(" ")
else:
idx = textAsBytes.find("%%>", i)
if idx >= 0:
finalPieces.append(" ")
i = idx + 3
continue
idx = textAsBytes.find("%>", i)
if idx == -1:
thisBit = textAsBytes[i:]
else:
thisBit = textAsBytes[i:idx]
lineNum += thisBit.count("\n")
if state == 1:
#.........这里部分代码省略.........