コード例 #1
0
ファイル: tests.py プロジェクト: sjl421/djblets
 def test_markdown_escape_gt_blockquotes(self):
     """Testing markdown_escape with '>' for blockquotes"""
     self.assertEqual(markdown_escape('>'), r'\>')
     self.assertEqual(markdown_escape('> foo'), r'\> foo')
     self.assertEqual(markdown_escape('  > foo'), r'  \> foo')
     self.assertEqual(markdown_escape('> > foo'), r'\> \> foo')
     self.assertEqual(markdown_escape('  > > foo'), r'  \> \> foo')
コード例 #2
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_gt_blockquotes(self):
     """Testing markdown_escape with '>' for blockquotes"""
     self.assertEqual(markdown_escape('>'), r'\>')
     self.assertEqual(markdown_escape('> foo'), r'\> foo')
     self.assertEqual(markdown_escape('  > foo'), r'  \> foo')
     self.assertEqual(markdown_escape('> > foo'), r'\> \> foo')
     self.assertEqual(markdown_escape('  > > foo'), r'  \> \> foo')
コード例 #3
0
ファイル: tests.py プロジェクト: sjl421/djblets
 def test_markdown_escape_parens(self):
     """Testing markdown_escape with '(' and ')' placement"""
     self.assertEqual(markdown_escape('[name](link)'), r'\[name\]\(link\)')
     self.assertEqual(markdown_escape('(link)'), r'(link)')
     self.assertEqual(markdown_escape('](link)'), r'\](link)')
     self.assertEqual(markdown_escape('[foo] ](link)'),
                      r'\[foo\] \](link)')
コード例 #4
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_parens(self):
     """Testing markdown_escape with '(' and ')' placement"""
     self.assertEqual(markdown_escape('[name](link)'), r'\[name\]\(link\)')
     self.assertEqual(markdown_escape('(link)'), r'(link)')
     self.assertEqual(markdown_escape('](link)'), r'\](link)')
     self.assertEqual(markdown_escape('[foo] ](link)'),
                      r'\[foo\] \](link)')
コード例 #5
0
    def update_from_pending_change(self, commit_id, changeset):
        """Updates the data from a server-side pending changeset.

        This will fetch the metadata from the server and update the fields on
        the review request.
        """
        if not changeset:
            raise InvalidChangeNumberError()

        # If the SCM supports changesets, they should always include a number,
        # summary and description, parsed from the changeset description. Some
        # specialized systems may support the other fields, but we don't want
        # to clobber the user-entered values if they don't.
        self.commit = commit_id
        description = changeset.description
        testing_done = changeset.testing_done

        if self.description_rich_text:
            description = markdown_escape(description)

        if self.testing_done_rich_text:
            testing_done = markdown_escape(testing_done)

        self.summary = changeset.summary
        self.description = description

        if testing_done:
            self.testing_done = testing_done

        if changeset.branch:
            self.branch = changeset.branch

        if changeset.bugs_closed:
            self.bugs_closed = ','.join(changeset.bugs_closed)
コード例 #6
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_underscores(self):
     """Testing markdown_escape with '_' placement"""
     self.assertEqual(markdown_escape('_foo_'), r'\_foo\_')
     self.assertEqual(markdown_escape('__foo__'), r'\_\_foo\_\_')
     self.assertEqual(markdown_escape(' _foo_ '), r' \_foo\_ ')
     self.assertEqual(markdown_escape('f_o_o'), r'f_o_o')
     self.assertEqual(markdown_escape('_f_o_o'), r'\_f_o_o')
     self.assertEqual(markdown_escape('f_o_o_'), r'f_o_o\_')
     self.assertEqual(markdown_escape('foo_ _bar'), r'foo\_ \_bar')
     self.assertEqual(markdown_escape('foo__bar'), r'foo__bar')
     self.assertEqual(markdown_escape('foo\n_bar'), 'foo\n\\_bar')
     self.assertEqual(markdown_escape('(_foo_)'), r'(\_foo\_)')
コード例 #7
0
ファイル: tests.py プロジェクト: sjl421/djblets
 def test_markdown_escape_underscores(self):
     """Testing markdown_escape with '_' placement"""
     self.assertEqual(markdown_escape('_foo_'), r'\_foo\_')
     self.assertEqual(markdown_escape('__foo__'), r'\_\_foo\_\_')
     self.assertEqual(markdown_escape(' _foo_ '), r' \_foo\_ ')
     self.assertEqual(markdown_escape('f_o_o'), r'f_o_o')
     self.assertEqual(markdown_escape('_f_o_o'), r'\_f_o_o')
     self.assertEqual(markdown_escape('f_o_o_'), r'f_o_o\_')
     self.assertEqual(markdown_escape('foo_ _bar'), r'foo\_ \_bar')
     self.assertEqual(markdown_escape('foo__bar'), r'foo__bar')
     self.assertEqual(markdown_escape('foo\n_bar'), 'foo\n\\_bar')
     self.assertEqual(markdown_escape('(_foo_)'), r'(\_foo\_)')
コード例 #8
0
def markdown_escape_field(obj, field_name):
    """Escapes Markdown text in a model or dictionary's field.

    This is a convenience around markdown_escape to escape the contents of
    a particular field in a model or dictionary.
    """
    if isinstance(obj, Model):
        setattr(obj, field_name,
                djblets_markdown.markdown_escape(getattr(obj, field_name)))
    elif isinstance(obj, dict):
        obj[field_name] = djblets_markdown.markdown_escape(obj[field_name])
    else:
        raise TypeError('Unexpected type %r passed to markdown_escape_field' %
                        obj)
コード例 #9
0
ファイル: markdown_utils.py プロジェクト: chipx86/reviewboard
def markdown_escape_field(obj, field_name):
    """Escapes Markdown text in a model or dictionary's field.

    This is a convenience around markdown_escape to escape the contents of
    a particular field in a model or dictionary.
    """
    if isinstance(obj, Model):
        setattr(obj, field_name,
                djblets_markdown.markdown_escape(getattr(obj, field_name)))
    elif isinstance(obj, dict):
        obj[field_name] = djblets_markdown.markdown_escape(obj[field_name])
    else:
        raise TypeError('Unexpected type %r passed to markdown_escape_field'
                        % obj)
コード例 #10
0
    def update_from_committed_change(self, commit_id):
        """Updates from a committed change present on the server.

        Fetches the commit message and diff from the repository and sets the
        relevant fields.
        """
        commit = self.repository.get_change(commit_id)
        summary, message = commit.split_message()
        message = message.strip()

        self.commit = commit_id
        self.summary = summary.strip()

        if self.description_rich_text:
            self.description = markdown_escape(message)
        else:
            self.description = message

        DiffSet.objects.create_from_data(
            repository=self.repository,
            diff_file_name='diff',
            diff_file_contents=commit.diff.encode('utf-8'),
            parent_diff_file_name=None,
            parent_diff_file_contents=None,
            diffset_history=self.get_review_request().diffset_history,
            basedir='/',
            request=None)
コード例 #11
0
ファイル: tests.py プロジェクト: sjl421/djblets
 def test_markdown_escape_plusses(self):
     """Testing markdown_escape with '+' placement"""
     self.assertEqual(
         markdown_escape('+ List item\n'
                         'a + b'),
         ('\\+ List item\n'
          'a + b'))
コード例 #12
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_plusses(self):
     """Testing markdown_escape with '+' placement"""
     self.assertEqual(
         markdown_escape('+ List item\n'
                         'a + b'),
         ('\\+ List item\n'
          'a + b'))
コード例 #13
0
 def test_markdown_escape_atx_headers(self):
     """Testing markdown_escape with '#' placement"""
     self.assertEqual(
         markdown_escape('### Header\n'
                         '  ## Header ##\n'
                         'Not # a header'), ('\\#\\#\\# Header\n'
                                             '  \\#\\# Header ##\n'
                                             'Not # a header'))
コード例 #14
0
ファイル: tests.py プロジェクト: sjl421/djblets
 def test_markdown_escape_asterisks(self):
     """Testing markdown_escape with '*' placement"""
     self.assertEqual(markdown_escape('*foo*'), r'\*foo\*')
     self.assertEqual(markdown_escape('**foo**'), r'\*\*foo\*\*')
     self.assertEqual(markdown_escape(' *foo* '), r' \*foo\* ')
     self.assertEqual(markdown_escape('f*o*o'), r'f*o*o')
     self.assertEqual(markdown_escape('f*o*o*'), r'f*o*o\*')
     self.assertEqual(markdown_escape('foo* *bar'), r'foo\* \*bar')
     self.assertEqual(markdown_escape('foo**bar'), r'foo**bar')
     self.assertEqual(markdown_escape('foo\n*bar'), 'foo\n\\*bar')
コード例 #15
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_asterisks(self):
     """Testing markdown_escape with '*' placement"""
     self.assertEqual(markdown_escape('*foo*'), r'\*foo\*')
     self.assertEqual(markdown_escape('**foo**'), r'\*\*foo\*\*')
     self.assertEqual(markdown_escape(' *foo* '), r' \*foo\* ')
     self.assertEqual(markdown_escape('f*o*o'), r'f*o*o')
     self.assertEqual(markdown_escape('f*o*o*'), r'f*o*o\*')
     self.assertEqual(markdown_escape('foo* *bar'), r'foo\* \*bar')
     self.assertEqual(markdown_escape('foo**bar'), r'foo**bar')
     self.assertEqual(markdown_escape('foo\n*bar'), 'foo\n\\*bar')
コード例 #16
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_atx_headers(self):
     """Testing markdown_escape with '#' placement"""
     self.assertEqual(
         markdown_escape('### Header\n'
                         '  ## Header ##\n'
                         'Not # a header'),
         ('\\#\\#\\# Header\n'
          '  \\#\\# Header ##\n'
          'Not # a header'))
コード例 #17
0
 def test_markdown_escape_periods(self):
     """Testing markdown_escape with '.' placement"""
     self.assertEqual(
         markdown_escape('Line. 1.\n'
                         '1. Line. 2.\n'
                         '1.2. Line. 3.\n'
                         '  1. Line. 4.'), ('Line. 1.\n'
                                            '1\\. Line. 2.\n'
                                            '1.2. Line. 3.\n'
                                            '  1\\. Line. 4.'))
コード例 #18
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_periods(self):
     """Testing markdown_escape with '.' placement"""
     self.assertEqual(
         markdown_escape('Line. 1.\n'
                         '1. Line. 2.\n'
                         '1.2. Line. 3.\n'
                         '  1. Line. 4.'),
         ('Line. 1.\n'
          '1\\. Line. 2.\n'
          '1.2. Line. 3.\n'
          '  1\\. Line. 4.'))
コード例 #19
0
def markdown_escape(text):
    """Escapes text for use in Markdown.

    This will escape the provided text so that none of the characters will
    be rendered specially by Markdown.

    This is deprecated. Please use djblets.markdown.markdown_escape instead.
    """
    warnings.warn('reviewboard.reviews.markdown_utils.markdown_escape is '
                  'deprecated. Please use djblets.markdown.markdown_escape.',
                  RemovedInReviewBoard40Warning)

    return djblets_markdown.markdown_escape(text)
コード例 #20
0
def markdown_escape(text):
    """Escapes text for use in Markdown.

    This will escape the provided text so that none of the characters will
    be rendered specially by Markdown.

    This is deprecated. Please use djblets.markdown.markdown_escape instead.
    """
    warnings.warn('reviewboard.reviews.markdown_utils.markdown_escape is '
                  'deprecated. Please use djblets.markdown.markdown_escape.',
                  DeprecationWarning)

    return djblets_markdown.markdown_escape(text)
コード例 #21
0
 def test_markdown_escape_hyphens(self):
     """Testing markdown_escape with '-' placement"""
     self.assertEqual(
         markdown_escape('Header\n'
                         '------\n'
                         '\n'
                         '- List item\n'
                         '  - List item\n'
                         'Just hyp-henated'), ('Header\n'
                                               '\\-\\-\\-\\-\\-\\-\n'
                                               '\n'
                                               '\\- List item\n'
                                               '  \\- List item\n'
                                               'Just hyp-henated'))
コード例 #22
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_hyphens(self):
     """Testing markdown_escape with '-' placement"""
     self.assertEqual(
         markdown_escape('Header\n'
                         '------\n'
                         '\n'
                         '- List item\n'
                         '  - List item\n'
                         'Just hyp-henated'),
         ('Header\n'
          '\\-\\-\\-\\-\\-\\-\n'
          '\n'
          '\\- List item\n'
          '  \\- List item\n'
          'Just hyp-henated'))
コード例 #23
0
ファイル: mixins.py プロジェクト: CharanKamal-CLI/reviewboard
    def _normalize_text(self, text, field_is_rich_text, force_text_type):
        """Normalizes text to the proper format.

        This considers the requested text format, and whether or not the
        value should be set for rich text.
        """
        assert force_text_type

        if text is not None:
            if force_text_type == self.TEXT_TYPE_PLAIN and field_is_rich_text:
                text = markdown_unescape(text)
            elif (force_text_type == self.TEXT_TYPE_MARKDOWN and
                  not field_is_rich_text):
                text = markdown_escape(text)
            elif force_text_type == self.TEXT_TYPE_HTML:
                if field_is_rich_text:
                    text = render_markdown(text)
                else:
                    text = escape(text)

        return text
コード例 #24
0
ファイル: mixins.py プロジェクト: pds-support/reviewboard
    def _normalize_text(self, text, field_is_rich_text, force_text_type):
        """Normalizes text to the proper format.

        This considers the requested text format, and whether or not the
        value should be set for rich text.
        """
        assert force_text_type

        if text is not None:
            if force_text_type == self.TEXT_TYPE_PLAIN and field_is_rich_text:
                text = markdown_unescape(text)
            elif (force_text_type == self.TEXT_TYPE_MARKDOWN and
                  not field_is_rich_text):
                text = markdown_escape(text)
            elif force_text_type == self.TEXT_TYPE_HTML:
                if field_is_rich_text:
                    text = render_markdown(text)
                else:
                    text = escape(text)

        return text
コード例 #25
0
def normalize_text_for_edit(user, text, rich_text, escape_html=True):
    """Normalizes text, converting it for editing.

    This will normalize text for editing based on the rich_text flag and
    the user settings.

    If the text is not in Markdown and the user edits in Markdown by default,
    this will return the text escaped for edit. Otherwise, the text is
    returned as-is.
    """
    if text is None:
        return ''

    if not rich_text and is_rich_text_default_for_user(user):
        # This isn't rich text, but it's going to be edited as rich text,
        # so escape it.
        text = djblets_markdown.markdown_escape(text)

    if escape_html:
        text = escape(text)

    return text
コード例 #26
0
ファイル: markdown_utils.py プロジェクト: chipx86/reviewboard
def normalize_text_for_edit(user, text, rich_text, escape_html=True):
    """Normalizes text, converting it for editing.

    This will normalize text for editing based on the rich_text flag and
    the user settings.

    If the text is not in Markdown and the user edits in Markdown by default,
    this will return the text escaped for edit. Otherwise, the text is
    returned as-is.
    """
    if text is None:
        return ''

    if not rich_text and is_rich_text_default_for_user(user):
        # This isn't rich text, but it's going to be edited as rich text,
        # so escape it.
        text = djblets_markdown.markdown_escape(text)

    if escape_html:
        text = escape(text)

    return text
コード例 #27
0
ファイル: tests.py プロジェクト: sjl421/djblets
 def test_markdown_escape_gt_text(self):
     """Testing markdown_escape with '>' for standard text"""
     self.assertEqual(markdown_escape('<foo>'), r'<foo>')
コード例 #28
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape(self):
     """Testing markdown_escape"""
     self.assertEqual(markdown_escape(self.UNESCAPED_TEXT),
                      self.ESCAPED_TEXT)
コード例 #29
0
ファイル: tests.py プロジェクト: sjl421/djblets
 def test_markdown_escape_gt_autolinks(self):
     """Testing markdown_escape with '>' for autolinks"""
     self.assertEqual(markdown_escape('<http://www.example.com>'),
                      r'<http://www.example.com\>')
コード例 #30
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_gt_autoemail(self):
     """Testing markdown_escape with '>' for autoemails"""
     self.assertEqual(markdown_escape('<*****@*****.**>'),
                      r'<[email protected]\>')
コード例 #31
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_gt_autolinks(self):
     """Testing markdown_escape with '>' for autolinks"""
     self.assertEqual(markdown_escape('<http://www.example.com>'),
                      r'<http://www.example.com\>')
コード例 #32
0
ファイル: tests.py プロジェクト: sjl421/djblets
 def test_markdown_escape_gt_autoemail(self):
     """Testing markdown_escape with '>' for autoemails"""
     self.assertEqual(markdown_escape('<*****@*****.**>'),
                      r'<[email protected]\>')
コード例 #33
0
ファイル: tests.py プロジェクト: halvorlu/djblets
 def test_markdown_escape_gt_text(self):
     """Testing markdown_escape with '>' for standard text"""
     self.assertEqual(markdown_escape('<foo>'), r'<foo>')
コード例 #34
0
ファイル: tests.py プロジェクト: sjl421/djblets
 def test_markdown_escape(self):
     """Testing markdown_escape"""
     self.assertEqual(markdown_escape(self.UNESCAPED_TEXT),
                      self.ESCAPED_TEXT)