예제 #1
0
파일: __init__.py 프로젝트: jensl/critic
    def loadOldLines(self, highlighted=False, request_highlight=False, highlight_mode="legacy"):
        """Load the lines of the old version of the file, optionally highlighted."""

        from diff.parse import splitlines

        if self.old_sha1 is None or self.old_sha1 == '0' * 40:
            self.old_plain = []
            self.old_highlighted = []
            return
        elif self.old_mode and self.old_mode == "160000":
            self.old_plain = "Subproject commit %s" % self.old_sha1
            self.old_highlighted = splitlines(syntaxhighlight.wrap(
                self.old_plain, highlight_mode))
            return

        if highlighted:
            if self.old_highlighted and self.old_is_highlighted:
                return
            else:
                self.old_is_highlighted = True
                language = self.getLanguage(use_content="old")
                data = syntaxhighlight.readHighlight(
                    self.repository, self.old_sha1, self.path, language,
                    request=request_highlight, mode=highlight_mode)
                self.old_highlighted = splitlines(data)
                self.old_eof_eol = data and data[-1] in "\n\r"
        else:
            if self.old_plain: return
            else:
                data = self.repository.fetch(self.old_sha1).data
                self.old_plain = splitlines(data)
                self.old_eof_eol = data and data[-1] in "\n\r"
예제 #2
0
    def loadNewLines(self, highlighted=False, request_highlight=False):
        """Load the lines of the new version of the file, optionally highlighted."""

        from diff.parse import splitlines

        if self.new_sha1 is None or self.new_sha1 == '0' * 40:
            self.new_plain = []
            self.new_highlighted = []
            return
        elif self.new_mode and self.new_mode == "160000":
            self.new_plain = self.new_highlighted = ["Subproject commit %s" % self.new_sha1]
            return

        if highlighted:
            if self.new_highlighted and self.new_is_highlighted: return
            else:
                self.new_is_highlighted = True
                language = self.getLanguage(use_content="new")
                if language:
                    data = syntaxhighlight.readHighlight(self.repository, self.new_sha1, self.path, language, request=request_highlight)
                elif self.new_highlighted: return
                else:
                    data = htmlutils.htmlify(textutils.decode(self.repository.fetch(self.new_sha1).data))
                self.new_highlighted = splitlines(data)
                self.new_eof_eol = data and data[-1] in "\n\r"
        else:
            if self.new_plain: return
            else:
                data = self.repository.fetch(self.new_sha1).data
                self.new_plain = splitlines(data)
                self.new_eof_eol = data and data[-1] in "\n\r"
예제 #3
0
    def loadNewLines(self, highlighted=False, request_highlight=False):
        """Load the lines of the new version of the file, optionally highlighted."""

        from diff.parse import splitlines

        if self.new_sha1 is None or self.new_sha1 == '0' * 40:
            self.new_plain = []
            self.new_highlighted = []
            return
        elif self.new_mode and self.new_mode == "160000":
            self.new_plain = self.new_highlighted = [
                "Subproject commit %s" % self.new_sha1
            ]
            return

        if highlighted:
            if self.new_highlighted and self.new_is_highlighted: return
            else:
                self.new_is_highlighted = True
                language = self.getLanguage(use_content="new")
                if language:
                    data = syntaxhighlight.readHighlight(
                        self.repository,
                        self.new_sha1,
                        self.path,
                        language,
                        request=request_highlight)
                elif self.new_highlighted:
                    return
                else:
                    data = htmlutils.htmlify(
                        textutils.decode(
                            self.repository.fetch(self.new_sha1).data))
                self.new_highlighted = splitlines(data)
                self.new_eof_eol = data and data[-1] in "\n\r"
        else:
            if self.new_plain: return
            else:
                data = self.repository.fetch(self.new_sha1).data
                self.new_plain = splitlines(data)
                self.new_eof_eol = data and data[-1] in "\n\r"
예제 #4
0
    def loadOldLines(self,
                     highlighted=False,
                     request_highlight=False,
                     highlight_mode="legacy"):
        """Load the lines of the old version of the file, optionally highlighted."""

        from diff.parse import splitlines

        if self.old_sha1 is None or self.old_sha1 == '0' * 40:
            self.old_plain = []
            self.old_highlighted = []
            return
        elif self.old_mode and self.old_mode == "160000":
            self.old_plain = "Subproject commit %s" % self.old_sha1
            self.old_highlighted = splitlines(
                syntaxhighlight.wrap(self.old_plain, highlight_mode))
            return

        if highlighted:
            if self.old_highlighted and self.old_is_highlighted:
                return
            else:
                self.old_is_highlighted = True
                language = self.getLanguage(use_content="old")
                data = syntaxhighlight.readHighlight(self.repository,
                                                     self.old_sha1,
                                                     self.path,
                                                     language,
                                                     request=request_highlight,
                                                     mode=highlight_mode)
                self.old_highlighted = splitlines(data)
                self.old_eof_eol = data and data[-1] in "\n\r"
        else:
            if self.old_plain: return
            else:
                data = self.repository.fetch(self.old_sha1).data
                self.old_plain = splitlines(data)
                self.old_eof_eol = data and data[-1] in "\n\r"