예제 #1
0
    def generate_captcha(self, req):
        fragment = tag.script(type='text/javascript',
                              src='https://www.google.com/recaptcha/api/'
                                  'challenge?k=%s' % self.public_key)

        # note - this is not valid XHTML!
        fragment.append(
            tag.noscript(
                tag.iframe(src='https://www.google.com/recaptcha/'
                               'api/noscript?k=%s' % self.public_key,
                           height=300, width=500, frameborder=0),
                tag.br(),
                tag.textarea(name='recaptcha_challenge_field', rows=3, cols=40),
                tag.input(type='hidden', name='recaptcha_response_field',
                          value='manual_challenge'),
                tag.br(),
                tag.input(type='submit', value=_("Submit"))
            )
        )

        return None, fragment
예제 #2
0
 def _wiki_edit(self, req, stream):
     tags = ' '.join(self._page_tags(req))
     # TRANSLATOR: Label text for link to '/tags'.
     link = tag.a(_("view all tags"), href=req.href.tags())
     # TRANSLATOR: ... (view all tags)
     insert = tag(
         tag_("Tag under: (%(tags_link)s)", tags_link=link), tag.br(),
         tag.input(id='tags',
                   type='text',
                   name='tags',
                   size='50',
                   value=req.args.get('tags', tags)))
     insert = tag.div(tag.label(insert), class_='field')
     return stream | Transformer('//div[@id="changeinfo1"]').append(insert)
예제 #3
0
파일: wiki.py 프로젝트: jier38/TracSite
 def _post_process_request_wiki_edit(self, req):
     tags = ' '.join(self._page_tags(req))
     # TRANSLATOR: Label text for link to '/tags'.
     link = tag.a(_("view all tags"), href=req.href.tags())
     # TRANSLATOR: ... (view all tags)
     insert = tag(
         tag_("Tag under: (%(tags_link)s)", tags_link=link), tag.br(),
         tag.input(id='tags',
                   type='text',
                   name='tags',
                   size='50',
                   value=req.args.get('tags', tags)))
     insert = tag.div(tag.label(insert), class_='field')
     filter_lst = []
     # xpath = //div[@id="changeinfo1"]
     xform = JTransformer('div#changeinfo1')
     filter_lst.append(xform.append(Markup(insert)))
     self._add_jtransform(req, filter_lst)
예제 #4
0
    def _launch(self, encoded_input, *args):
        """Launch a process (cmd), and returns exitcode, stdout + stderr"""
        # Note: subprocess.Popen doesn't support unicode options arguments
        # (http://bugs.python.org/issue1759845) so we have to encode them.
        # Anyway, dot expects utf-8 or the encoding specified with -Gcharset.
        cmd, T, o = [args[0]], '', ''
        if 'gnuplot' not in cmd[0]:
            cmd = [arg for arg in args]
        else:
            for arg in args:
                if arg[:2] == '-o': o = arg[2:]
                elif arg[:2] == '-T': T = arg[2:]

        p = subprocess.Popen(cmd,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        if 'gnuplot' in cmd[0]:
            p.stdin.write(("set terminal %s transparent\nset output '%s'\n" %
                           (T, o)).encode('utf-8'))
        if encoded_input:
            p.stdin.write(encoded_input)
        p.stdin.close()
        out = p.stdout.read()
        err = p.stderr.read()
        failure = p.wait() != 0
        if failure or err or out:
            return (failure,
                    tag.p(tag.br(), _("The command:"),
                          tag.pre(repr(' '.join(cmd))),
                          (_("succeeded but emitted the following output:"),
                           _("failed with the following output:"))[failure],
                          out and tag.pre(repr(out)), err
                          and tag.pre(repr(err))))
        else:
            return (False, None)
예제 #5
0
    def render_property(self, name, mode, context, props):

        def sha_link(sha, label=None):
            # sha is assumed to be a non-abbreviated 40-chars sha id
            try:
                reponame = context.resource.parent.id
                repos = RepositoryManager(self.env).get_repository(reponame)
                cset = repos.get_changeset(sha)
                if label is None:
                    label = repos.display_rev(sha)

                return tag.a(label, class_='changeset',
                             title=shorten_line(cset.message),
                             href=context.href.changeset(sha, repos.reponame))

            except Exception as e:
                return tag.a(sha, class_='missing changeset',
                             title=to_unicode(e), rel='nofollow')

        if name == 'Branches':
            branches = props[name]

            # simple non-merge commit
            return tag(*intersperse(', ', (sha_link(rev, label)
                                           for label, rev in branches)))

        elif name in ('Parents', 'Children'):
            revs = props[name] # list of commit ids

            if name == 'Parents' and len(revs) > 1:
                # we got a merge...
                current_sha = context.resource.id
                reponame = context.resource.parent.id

                parent_links = intersperse(', ',
                                           ((sha_link(rev),
                      ' (',
                      tag.a(_("diff"),
                            title=_("Diff against this parent (show the "
                                    "changes merged from the other parents)"),
                            href=context.href.changeset(current_sha, reponame,
                                                        old=rev)),
                      ')')
                     for rev in revs))

                return tag(list(parent_links),
                           tag.br(),
                           tag.span(Markup(_("Note: this is a <strong>merge"
                                             "</strong> changeset, the "
                                             "changes displayed below "
                                             "correspond to the merge "
                                             "itself.")),
                                    class_='hint'),
                           tag.br(),
                           tag.span(Markup(_("Use the <code>(diff)</code> "
                                             "links above to see all the "
                                             "changes relative to each "
                                             "parent.")),
                                    class_='hint'))

            # simple non-merge commit
            return tag(*intersperse(', ', map(sha_link, revs)))

        elif name in ('git-committer', 'git-author'):
            user_, time_ = props[name]
            _str = "%s (%s)" % (
                Chrome(self.env).format_author(context.req, user_),
                format_datetime(time_, tzinfo=context.req.tz))
            return unicode(_str)

        raise TracError(_("Internal error"))