NameError:未定义全局名称'has_no_changeset'

技术标签: Python  句法

OK - Python Newbie在这里 - 我假设我正在做一些真正愚蠢的事情,你能告诉我它是什么,所以我们都可以继续我们的生活吗?

我得到了错误 NameError: global name 'has_no_changeset' is not defined 在第55行(我尝试调用该函数的位置 has_no_changeset).

from genshi.builder import tag

from trac.core import implements,Component
from trac.ticket.api import ITicketManipulator
from trac.ticket.default_workflow import ConfigurableTicketWorkflow
from trac.perm import IPermissionRequestor
from trac.config import Option, ListOption
import re

revision = "$Rev$"
url = "$URL$"

class CloseActionController(Component):
    """Support for close checking.

    If a ticket is closed, it is NOT allowed if ALL the following conditions apply: 
     a) ticket is 'bug' ticket
     b) resolution status is 'fixed'
     c) none of the ticket's changes include a comment containing a changeset, i.e. regex "\[\d+\]"
     d) the ticket does not have the keyword 'web'
    """

    implements(ITicketManipulator)

    # ITicketManipulator methods

    def prepare_ticket(req, ticket, fields, actions):
        """Not currently called, but should be provided for future
        compatibility."""
        return


    def has_no_changeset(ticket):
        db = self.env.get_db_cnx()
        cursor = db.cursor()

        cursor.execute("SELECT newvalue FROM ticket_change WHERE ticket=%s AND field='comment'", (str(ticket.id).encode('ascii','replace'),))

        for newvalue, in cursor:
            if re.search("\[\d{5,}\]", newvalue):
                return False

        return True

    def validate_ticket(me, req, ticket):
        """Validate a ticket after it's been populated from user input.

        Must return a list of `(field, message)` tuples, one for each problem
        detected. `field` can be `None` to indicate an overall problem with the

        ticket. Therefore, a return value of `[]` means everything is OK."""

        if ticket['type'] == 'bug' and ticket['resolution'] == 'fixed':
          if ticket['keywords'] == None or ticket['keywords'].find('web') == -1:
            if has_no_changeset(ticket):
              return [(None, 'You can only close a bug ticket as "fixed" if you refer to a changeset somewhere within the ticket, e.g. with [12345]!')]

        return[]

看答案

您需要明确指定 self (或在您的情况下, me)在参考当前类的方法时:

if me.has_no_changeset(ticket):

你正在使用 me 代替 self - 这是合法的,但非常令人沮丧。应调用成员函数的第一个参数 self:

def validate_ticket(self, req, ticket):
    # [...]
    if self.has_no_changeset(ticket):

智能推荐

未定义宏或宏的相关问题

已经提示了,宏要放在预编译头中 所以,把宏剪切到预编译头中,也就是stdafx.h文件。注意,宏要放在各个头文件之前哦! 即把你的cpp源文件,要include的文件和宏,全放入stdafx.h。而你只需include这个stdafx.h就够了。...

matlab运行报错:未定义函数或变量 'crtbp'

这是缺少遗传算法需要的一个谢菲尔德工具箱,网上下载后按照安装步骤安装好后成功解决。 一下是安装工具包步骤,参考自周杰伦今天喝奶茶了吗,哈哈哈博客。具体安装步骤如下: 链接:https://pan.baidu.com/s/1ex6auJZ6Pmtk_flRGZF1iw 密码:81nk 可下载MATLAB的gatbx安装包   1.下载后,解压。 2.将解压后的gatbx文件夹移到MATLA...

matlab未定义变量或类vision.GeometricTransformEstimator

(1)首先查找是否真的含有这个包,命令行查找:which  vision.GeometricTransformEstimator (2)没有,把vision这个替换下,否则转(3) (3)查看是否添加到了路径 如果没有添加入路径就好了。 (4)刷新下当前的路径, preferences ---->matlab--->常规 (5)重启matlab。...

tp5 volist标签显示未定义变量

很多人会遇到这样的问题,在tp5中,使用volist标签的的时候,id的值是未定义变量。如下图 在这个例子中,$cate总是显示未定义变量。然后查看一下手册 也没有太大不一样的,仔细一看就看出差别了。就是<>和{}两个标签的使用。用{}标签才是正确的。 以后写代码看手册的时候要仔细一点咯。...

无意中发现看书也是一种美

2012年4月25日晚,翻翻自己喜欢的一门语言学习书(python参考手册),无意中发现书中夹着之前的明信片(有一次和同事一起去前门邓丽君音乐生活馆留下来的),感觉学习也是一种美!于是乎拍下这不经意的时刻,哈哈!...

猜你喜欢

香橙派OrangePi PC Plus开发板连接USB以太网卡测试说明

1) 目前测试过能用的 USB 以太网卡如下所示,其中 RTL8153 USB 千兆网卡插入开 发板的 USB 2.0 Host 接口中测试可以正常使用,但是速率是达不到千兆的,这点请 注意   2) 首先将 USB 网卡插入开发板的 USB 接口中,然后在 USB 网卡中插入网线,确 保网线能正常上网,如果通过 dmesg 命令可以看到下面的 log 信息,说明 USB 网卡...

计算机网络基础:Vlan,网关,dns吗,子网掩码等!面试必备!

很多朋友多次问到什么是网关、dns、子网掩码,三层交换机,它们定位的用途;确实,因为网络技术在弱电中确实应用非常广泛,我们平时在 vip 技术群中也是不断的讨论到网关、vlan、三层交换机或子网掩码等问题,今天我们就一起用通俗方式一次性了解清楚。 一、什么是 vlan? VLAN 中文是 “虚拟局域网”。LAN 可以是由少数几台家用计算机构成的网络,也可以是数以百计的计算机...

乐播科技冯森:我为什么不看好Android电视游戏

(乐播科技的三位创始人,从右往左依次为:冯森、廖峰、陈锡华) 电视在家居生活中扮演的角色重新获得了人们的认知,这块屏幕成为巨头们谋划的方向,其中一个属性便是家庭的娱乐中心。但在国内,各种基于Android平台的电视和盒子又面临游戏内容缺乏的窘境。当然,很多人或者团队都在努力着希望完善这个生态系统,但是好像没有那么简单。 另一方面,苹果系统已经是非常成熟的平台,各类iOS游戏的质量也很高。于是,来自...

Java使用阿里云OSS对象存储上传图片

该案例是OSS Java SDK的示例程序,您可以修改endpoint、accessKeyId、accessKeySecret、bucketName后直接运行。 本示例中的并不包括OSS Java SDK的所有功能,详细功能及使用方法,请参看“SDK手册 > Java-SDK”, 链接地址是:https://help.aliyun.com/document_detai...

很多.net 程序员不知道又非常重要的 .net高级调试技巧.调试别人的dll方法内的变量...

事情是这样的, 最近需要开发Orcale的数据库. 于是使用了EF 加上 Oracle.ManagedDataAccess.Client 这个Oracle.ManagedDataAccess 很好用, 不需要orcale 客户端就能用. 但是这个类库有个地方不是非常好用. 数据读取出了问题,它的提示非常非常让人气愤. 啥调试信息都没有..只有一个提示 “类型转换异常”. 大...

问答精选

How to extract beta coefficients for interaction effect in R?

I am examining the interaction between a continuous variable (bloodq) and a categorical variable with three levels (ER, RB, and WB). In order to see how the betas differ across tissue types, I would l...

what is the difference between Flatten() and GlobalAveragePooling2D() in keras

I want to pass the output of ConvLSTM and Conv2D to a Dense Layer in Keras, what is the difference between using global average pooling and flatten Both is working in my case. That both seem to work d...

How to invoke a test step with inputs at runtime from groovy script in SOAP UI?

I am writing a validation groovy script for a test step, intended to test a SOAP Web Service. Now, I want to call the same test step, with different input value from the groovy script. Is it possible?...

Wicket pagestore results wrong page

I have a problem with my web application with wicket. I am using wicket 6.14. I can't say exactly what the problem is, but I can describe the problem. I am using a self written pagestore, which uses h...

Unity load files from outside of resources folder

In unity is it possible to load a resource that is out side of the resources folder. I want the user to be able to set a textAsset variable from a file outside of the Assets directory entirely. You ca...

相关问题

相关文章

热门文章

推荐文章

相关标签

推荐问答