PyH源码解析(4)
增加兄弟Tag对象
这个实际上就是Tag对象的序列,如下所示:
>>> a=div('a1')+div('a2')+div('a3')
>>> print(a)
<div>
a1
</div>
<div>
a2
</div>
<div>
a3
</div>
其实现原理就是重载了+
操作符,上面例子中的返回对象a是一个特殊的Tag对象,它没有tagname,它的isSeq属性为True,表示它容纳了一个Tag的序列。
为Tag对象追加内容和子对象
这里使用了<<
符号,如下示例:
>>> a=div()
>>> a<<'test'
>>> a<<div(id='abc')
>>> print(a)
<div>
test
<div id="abc">
</div>
</div>
其实现原理很简单,就是直接调用self.addObj()即可。只不过需要注意的是,其返回对象是其子Tag对象,以便<<
可以连续使用。另外需要注意的是,如果追加的tag是一个序列Tag对象,则把它展开,每一个成员作为子Tag追加。
Exclusive offer GET 5 STEEM Airdrop
Join our Site and get 5 steem airdrop on your steem account. The Campaign has start for attract new user to use our service and mass adoption.
Get 5 STEEM NOW CLICK HERE
WARNING - The message you received from @redwanmiazee10 is a CONFIRMED SCAM!
DO NOT FOLLOW any instruction and DO NOT CLICK on any link in the comment!
For more information about this scam, read this post:
https://steemit.com/steemit/@arcange/phishing-site-reported-steembottracker-dot-trade
If you find my work to protect you and the community valuable, please consider to upvote this warning or to vote for my witness.