[原文]P115
At this point, it's worth digging a little further into SGMLParser. I've claimed repeatedly (and you've taken it on faith so far) that SGMLParser looks for and calls specific methods for each tag, if they exist. For instance, you just saw the definition of start_pre and end_pre to handle
and. But how does this happen? Well, it's not magic, it's just good Python coding.
[pope译]
在这点上,值得深入SGML。我多次提及SGMLParser 为每个tag 寻找调用对应的方法,如果此方法存在。之前,你只看到处理
和的 start_pre 和 end_pre.但是这个如何发生呢?well,它不是魔法,那只是python的代码。
[?]嘻嘻,那是如何发生的呢?这个not magic 的Python coding is what?我很感兴趣啊!
[net 译 来源: http://woodpecker.org.cn/diveintopython/html_processing/dialect.html ]
到了这个地方,有必要对 SGMLParser 更深入一层。我已经多次声明 (到目前为止您应已经把它做为信条了) ,就是 SGMLParser 查找每一个标记并且如果存在特定的方法就调用它们。例如:我们刚刚看到处理 和
[popexizhi:
it's worth digging a little further into SGMLParser.
[pope译]值得深入SGML
[net 译]有必要对 SGMLParser 更深入一层
[popexizhi] pope的翻译少了 a little further ,不如“更深入一层”准确。
and you've taken it on faith so far
[popexizhi]自己忘记翻译了,net给出的是“到目前为止您应已经把它做为信条了”
looks for and calls specific methods for each tag,if they exist
[pope译]为每个tag 寻找调用对应的方法,如果此方法存在。
[net 译]查找每一个标记并且如果存在特定的方法就调用它们。
[popexizhi] if they exist 是针对 call ,net的翻译是对的,自己的只是执意句子,没做特殊处理,表达不准确。
it's just good Python coding.
[pope译] 那只是python的代码。
[net 译]只不过是出色的 Python 编码。
[popexizhi] net译的很漂亮,good Python coding 出色的Python 编码。
]
[原文]P115
def finish_starttag(self, tag, attrs): 1
try:
method = getattr(self, 'start_' + tag) 2
except AttributeError: 3
try:
method = getattr(self, 'do_' + tag) 4
except AttributeError: 5
self.unknown_starttag(tag, attrs)
return −1
else: 6
self.handle_starttag(tag, method, attrs)
return 0
else: 7
self.stack.append(tag)
self.handle_starttag(tag, method, attrs)
return 1
def handle_starttag(self, tag, method, attrs):
method(attrs) 8
1
[原文]P115
At this point, SGMLParser has already found a start tag and parsed the attribute list. The only thing left to do is figure out whether there is a specific handler method for this tag, or whether you should fall back on the default method (unknown_starttag).
[pope译] 在这点上,SGMLParser 查找 tag 的开始标记 和 从语法上分析参数列表。唯一剩下要做的(left to do) 是 理解(figure out) 对this tag 是否有特殊的处理方法,还是你需要返回默认的方法unknown_starttage.
[net 译 来源: http://woodpecker.org.cn/diveintopython/html_processing/dialect.html ]
此处,SGMLParser 已经找到了一个开始标记,并且分析出属性列表。唯一要做的事情就是检查对于这个标记是否存在一个特别的处理方法,否则我们就应该求助于缺省方法 (unknown_starttag) 。
[popexizhi:
has already found a start tag and parsed the attribute list
[pope译] 查找 tag 的开始标记 和 从语法上分析参数列表
[net 译]已经找到了一个开始标记,并且分析出属性列表。
[popexizhi] has already found 完成时,pope没翻译出来; parse 分析(从语法上是可以省略的,是的!)至于 attribute 是 传入的参数,是tag的属性,这里之前说的是tag, 所以从互文同级上讲也是翻译为属性才合适的。参数嘛?应该是parameter ,或者arguments 才合适吧!
is figure out
[pope译] 理解
[net 译]检查
[popexizhi]查了一下韦氏字典 [ http://www.merriam-webster.com/dictionary/figure%20out ] 解释figure out 中有discover 或 solve 应该是discover 吧!
fall back on the default method
[popexizhi] net给的是求助,这个是意译了,也说的过去吧。
]
没有评论:
发表评论