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


Python Request.perm方法代码示例

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


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

示例1: test_index_and_search

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import perm [as 别名]
 def test_index_and_search(self):
     self.out.update_index()
     req = Request(self._make_environ(), None)
     req.session = {'tz': 'UTC'}
     req.perm = Mock(has_permission= lambda x: True)
     results = [i for i in self.out.get_search_results(req, ('hello',), ('irclogs',))]
     self.assertEqual(20, len(results))
     self.assertEqual(self.dt.hour, results[0][2].hour)
     req.session = {'tz': 'America/New_York'}
     req.perm = Mock(has_permission= lambda x: True)
     results = [i for i in self.out.get_search_results(req, ('hello',), ('irclogs',))]
     self.assertEqual(20, len(results))
     est = timezone('America/New_York')
     expect_dt = est.normalize(self.dt.astimezone(est))
     sorted_results = sorted(results, key=operator.itemgetter(2))
     self.assertEqual(expect_dt, sorted_results[0][2])
开发者ID:dokipen,项目名称:trac-irclogs-plugin,代码行数:18,代码来源:search.py

示例2: _test_import

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import perm [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

示例3: test_timezones

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import perm [as 别名]
 def test_timezones(self):
     self.out.config.set('irclogs', 'timezone', 'America/New_York')
     self.out.update_index()
     req = Request(self._make_environ(), None)
     req.session = {'tz': 'America/New_York'}
     req.perm = Mock(has_permission= lambda x: True)
     results = [i for i in self.out.get_search_results(req, ('hello',), ('irclogs',))]
     self.assertEqual(20, len(results))
     self.assertEqual((self.dt.hour-5+24)%24, results[0][2].hour)
开发者ID:dokipen,项目名称:trac-irclogs-plugin,代码行数:11,代码来源:search.py

示例4: _test_preview

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import perm [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

示例5: _make_req

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import perm [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

示例6: test_update

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import perm [as 别名]
 def test_update(self):
     self.out.update_index()
     req = Request(self._make_environ(), None)
     req.session = {'tz': 'UTC'}
     req.perm = Mock(has_permission= lambda x: True)
     results = [i for i in self.out.get_search_results(req, ('hello',), ('irclogs',))]
     self.assertEqual(20, len(results))
     self.out.update_index()
     results = [i for i in self.out.get_search_results(req, ('hello',), ('irclogs',))]
     self.assertEqual(40, len(results))
     self.out.update_index()
     results = [i for i in self.out.get_search_results(req, ('hello',), ('irclogs',))]
     self.assertEqual(60, len(results))
     self.out.update_index()
     results = [i for i in self.out.get_search_results(req, ('hello',), ('irclogs',))]
     self.assertEqual(80, len(results))
开发者ID:dokipen,项目名称:trac-irclogs-plugin,代码行数:18,代码来源:search.py

示例7: invoke

# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import perm [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.perm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。