当前位置: 首页>>代码示例>>Python>>正文


Python Request.authname方法代码示例

本文整理汇总了Python中trac.web.api.Request.authname方法的典型用法代码示例。如果您正苦于以下问题:Python Request.authname方法的具体用法?Python Request.authname怎么用?Python Request.authname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.web.api.Request的用法示例。


在下文中一共展示了Request.authname方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _test_import

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import authname [as 别名]
 def _test_import(self, env, filename, sheet = 1):
     req = Request({'SERVER_PORT': 0, 'SERVER_NAME': 'any', 'wsgi.url_scheme': 'any', 'wsgi.input': 'any', 'REQUEST_METHOD': 'GET' }, lambda x, y: _printme)
     try:
        from trac.test import MockPerm
        req.perm = MockPerm()
     except ImportError:
        pass
     req.authname = 'testuser'
     req.hdf = HDFWrapper([]) # replace by this if you want to generate HTML: req.hdf = HDFWrapper(loadpaths=chrome.get_all_templates_dirs())
     db = env.get_db_cnx()
     cursor = db.cursor()
     _exec(cursor, "select * from enum")
     enums_before = cursor.fetchall()
     _exec(cursor, "select * from component")
     components_before = cursor.fetchall()
     #print enums_before
     # when testing, always use the same time so that the results are comparable
     #print "importing " + filename + " with tickettime " + str(ImporterTestCase.TICKET_TIME)
     template, content_type = ImportModule(env)._do_import(filename, sheet, req, filename, ImporterTestCase.TICKET_TIME)
     #sys.stdout = tempstdout
     #req.display(template, content_type or 'text/html')
     #open('/tmp/out.html', 'w').write(req.hdf.render(template, None))
     _exec(cursor, "select * from ticket")
     tickets = cursor.fetchall()
     _exec(cursor, "select * from ticket_custom")
     tickets_custom = cursor.fetchall()
     _exec(cursor, "select * from ticket_change")
     tickets_change = cursor.fetchall()
     _exec(cursor, "select * from enum")
     enums = [f for f in set(cursor.fetchall()) - set(enums_before)]
     _exec(cursor, "select * from component")
     components = [f for f in set(cursor.fetchall()) - set(components_before)]
     pp = pprint.PrettyPrinter(indent=4)
     return pp.pformat([ tickets, tickets_custom, tickets_change, enums, components ])
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:36,代码来源:test.py

示例2: dummy_request

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import authname [as 别名]
def dummy_request(env, cookies_from=None, query=None):
    environ = {
        'trac.base_url': env.base_url,
        'wsgi.url_scheme': 'http',
        'wsgi.input': BytesIO(),
        'SCRIPT_NAME': '/trac.cgi',
        'REQUEST_METHOD': 'GET',
        'SERVER_NAME': 'example.org',
        'SERVER_PORT': '80',
        'HTTP_HOST': 'example.org',
        }
    if query:
        environ['QUERY_STRING'] = urlencode(query)
    if cookies_from:
        outcookie = cookies_from.outcookie
        cookie = '; '.join('%s=%s' % (name, morsel.value)
                           for name, morsel in outcookie.items())
        environ['HTTP_COOKIE'] = cookie
    start_response = mock.Mock(name='start_response')
    req = Request(environ, start_response)
    req.session = {}
    req.chrome = {'warnings': [], 'notices': []}
    req.redirect = mock.Mock(name='req.redirect', spec=())
    req.authname = 'anonymous'
    return req
开发者ID:trac-hacks,项目名称:trac-oidc,代码行数:27,代码来源:test_trac_oidc.py

示例3: _test_preview

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import authname [as 别名]
 def _test_preview(self, env, filename):
     req = Request({'SERVER_PORT': 0, 'SERVER_NAME': 'any', 'wsgi.url_scheme': 'any', 'wsgi.input': 'any', 'REQUEST_METHOD': 'GET' }, lambda x, y: _printme)
     try:
        from trac.test import MockPerm
        req.perm = MockPerm()
     except ImportError:
        pass
     req.authname = 'testuser'
     req.hdf = HDFWrapper([]) # replace by this if you want to generate HTML: req.hdf = HDFWrapper(loadpaths=chrome.get_all_templates_dirs())
     template, content_type = ImportModule(env)._do_preview(filename, 1, req)
     #sys.stdout = tempstdout
     #req.display(template, content_type or 'text/html')
     #open('/tmp/out.html', 'w').write(req.hdf.render(template, None))
     return str(req.hdf) + "\n"
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:16,代码来源:test.py

示例4: _make_req

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import authname [as 别名]
def _make_req(environ, start_response, args={}, arg_list=(), authname='admin',
              form_token='A' * 40, chrome={'links': {}, 'scripts': []},
              perm=MockPerm(), session={}, tz=utc, locale=None, **kwargs):
    req = Request(environ, start_response)
    req.args = args
    req.arg_list = arg_list
    req.authname = authname
    req.form_token = form_token
    req.chrome = chrome
    req.perm = perm
    req.session = session
    req.tz = tz
    req.locale = locale
    for name, value in kwargs.iteritems():
        setattr(req, name, value)
    return req
开发者ID:pkdevbox,项目名称:trac,代码行数:18,代码来源:api.py

示例5: test_saved_custom_query_redirect

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import authname [as 别名]
    def test_saved_custom_query_redirect(self):
        query = u'query:?type=résumé'
        with self.env.db_transaction as db:
            cursor = db.cursor()
            cursor.execute("INSERT INTO report (title,query,description) "
                           "VALUES (%s,%s,%s)", ('redirect', query, ''))
            id = db.get_last_id(cursor, 'report')

        headers_sent = {}
        def start_response(status, headers):
            headers_sent.update(dict(headers))
        environ = self._make_environ()
        req = Request(environ, start_response)
        req.authname = 'anonymous'
        req.session = Mock(save=lambda: None)
        self.assertRaises(RequestDone,
                          self.report_module._render_view, req, id)
        self.assertEqual('http://example.org/trac/query?' + \
                         'type=r%C3%A9sum%C3%A9&report=' + str(id),
                         headers_sent['Location'])
开发者ID:pkdevbox,项目名称:trac,代码行数:22,代码来源:report.py

示例6: invoke

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import authname [as 别名]
    def invoke(self, chgset):

        # regular expressions
        ticket_prefix = "(?:#|(?:ticket|issue|bug)[: ]?)"
        if self.intertrac:  # TODO: split to separate function?
            # find intertrac links
            intertrac = {}
            aliases = {}
            for key, value in self.env.config.options("intertrac"):
                if "." in key:
                    name, type_ = key.rsplit(".", 1)
                    if type_ == "url":
                        intertrac[name] = value
                else:
                    aliases.setdefault(value, []).append(key)
            intertrac = dict([(value, [key] + aliases.get(key, [])) for key, value in intertrac.items()])
            project = os.path.basename(self.env.path)

            if "/%s" % project in intertrac:  # TODO:  checking using base_url for full paths:
                ticket_prefix = "(?:%s):%s" % ("|".join(intertrac["/%s" % project]), ticket_prefix)
            else:  # hopefully sesible default:
                ticket_prefix = "%s:%s" % (project, ticket_prefix)

        ticket_reference = ticket_prefix + "[0-9]+"
        ticket_command = r"(?P<action>[A-Za-z]*).?" "(?P<ticket>%s(?:(?:[, &]*|[ ]?and[ ]?)%s)*)" % (
            ticket_reference,
            ticket_reference,
        )
        ticket_command = r"%s%s%s" % (re.escape(self.envelope_open), ticket_command, re.escape(self.envelope_close))
        command_re = re.compile(ticket_command, re.IGNORECASE)
        ticket_re = re.compile(ticket_prefix + "([0-9]+)", re.IGNORECASE)

        # other variables
        msg = "(In [%s]) %s" % (chgset.rev, chgset.message)
        now = chgset.date
        supported_cmds = {}  # TODO: this could become an extension point
        supported_cmds.update(dict([(key, self._cmdClose) for key in self.cmd_close]))
        supported_cmds.update(dict([(key, self._cmdRefs) for key in self.cmd_refs]))

        cmd_groups = command_re.findall(msg)

        tickets = {}
        for cmd, tkts in cmd_groups:
            func = supported_cmds.get(cmd.lower(), None)
            if func:
                for tkt_id in ticket_re.findall(tkts):
                    tickets.setdefault(tkt_id, []).append(func)

        for tkt_id, cmds in tickets.iteritems():
            try:
                db = self.env.get_db_cnx()

                ticket = Ticket(self.env, int(tkt_id), db)
                for cmd in cmds:
                    cmd(ticket)

                # determine comment sequence number
                cnum = 0
                tm = TicketModule(self.env)
                for change in tm.grouped_changelog_entries(ticket, db):
                    if change["permanent"]:
                        cnum += 1

                # validate the ticket

                # fake a request
                # XXX cargo-culted environ from
                # http://trac.edgewall.org/browser/trunk/trac/web/tests/api.py
                environ = {
                    "wsgi.url_scheme": "http",
                    "wsgi.input": StringIO(""),
                    "SERVER_NAME": "0.0.0.0",
                    "REQUEST_METHOD": "POST",
                    "SERVER_PORT": 80,
                    "SCRIPT_NAME": "/" + self.env.project_name,
                    "REMOTE_USER": chgset.author,
                    "QUERY_STRING": "",
                }
                req = Request(environ, None)
                req.args["comment"] = msg
                req.authname = chgset.author
                req.perm = PermissionCache(self.env, req.authname)
                for manipulator in tm.ticket_manipulators:
                    manipulator.validate_ticket(req, ticket)
                msg = req.args["comment"]
                ticket.save_changes(chgset.author, msg, now, db, cnum + 1)
                db.commit()

                tn = TicketNotifyEmail(self.env)
                tn.notify(ticket, newticket=0, modtime=now)

            except Exception, e:
                message = "Unexpected error while processing ticket ID %s: %s" % (tkt_id, repr(e))
                print >>sys.stderr, message
                self.env.log.error("TicketChanger: " + message)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:97,代码来源:ticketchanger.py


注:本文中的trac.web.api.Request.authname方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。