Ability to delete desc, content, title in feeds
parent
145f59b546
commit
050be7690d
61
feeds.py
61
feeds.py
|
@ -102,6 +102,11 @@ class FeedBase(object):
|
||||||
self.root.append(element)
|
self.root.append(element)
|
||||||
return element
|
return element
|
||||||
|
|
||||||
|
def xdel(self, path):
|
||||||
|
match = self.xget(path)
|
||||||
|
if match is not None:
|
||||||
|
return match.getparent().remove(match)
|
||||||
|
|
||||||
def tostring(self, **k):
|
def tostring(self, **k):
|
||||||
""" Returns string using lxml. Arguments passed to tostring """
|
""" Returns string using lxml. Arguments passed to tostring """
|
||||||
return etree.tostring(self.xml, pretty_print=True, **k)
|
return etree.tostring(self.xml, pretty_print=True, **k)
|
||||||
|
@ -122,6 +127,10 @@ class FeedDescriptor(object):
|
||||||
setter = getattr(instance, 'set%s' % self.name.title())
|
setter = getattr(instance, 'set%s' % self.name.title())
|
||||||
return setter(value)
|
return setter(value)
|
||||||
|
|
||||||
|
def __delete__(self, instance):
|
||||||
|
deleter = getattr(instance, 'del%s' % self.name.title())
|
||||||
|
return deleter()
|
||||||
|
|
||||||
class FeedList(object):
|
class FeedList(object):
|
||||||
"""
|
"""
|
||||||
Class to map a list of xml elements against a list of matching objects,
|
Class to map a list of xml elements against a list of matching objects,
|
||||||
|
@ -220,6 +229,9 @@ class FeedParser(FeedBase):
|
||||||
def setTitle(self, value):
|
def setTitle(self, value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def delTitle(self):
|
||||||
|
self.title = ""
|
||||||
|
|
||||||
|
|
||||||
def getDesc(self):
|
def getDesc(self):
|
||||||
pass
|
pass
|
||||||
|
@ -227,6 +239,9 @@ class FeedParser(FeedBase):
|
||||||
def setDesc(self, value):
|
def setDesc(self, value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def delDesc(self):
|
||||||
|
self.desc = ""
|
||||||
|
|
||||||
|
|
||||||
def getItems(self):
|
def getItems(self):
|
||||||
return []
|
return []
|
||||||
|
@ -234,6 +249,9 @@ class FeedParser(FeedBase):
|
||||||
def setItems(self, value):
|
def setItems(self, value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def delItems(self):
|
||||||
|
pass
|
||||||
|
|
||||||
title = FeedDescriptor('title')
|
title = FeedDescriptor('title')
|
||||||
description = desc = FeedDescriptor('desc')
|
description = desc = FeedDescriptor('desc')
|
||||||
items = FeedListDescriptor('items')
|
items = FeedListDescriptor('items')
|
||||||
|
@ -251,6 +269,9 @@ class FeedParserRSS(FeedParser):
|
||||||
return self.xval('rssfake:title|title')
|
return self.xval('rssfake:title|title')
|
||||||
|
|
||||||
def setTitle(self, value):
|
def setTitle(self, value):
|
||||||
|
if not value:
|
||||||
|
return self.xdel('rssfake:title|title')
|
||||||
|
|
||||||
table = { 'rdf:rdf': 'rssfake:title',
|
table = { 'rdf:rdf': 'rssfake:title',
|
||||||
'channel': 'title'}
|
'channel': 'title'}
|
||||||
element = self.xgetCreate(table)
|
element = self.xgetCreate(table)
|
||||||
|
@ -258,9 +279,13 @@ class FeedParserRSS(FeedParser):
|
||||||
|
|
||||||
|
|
||||||
def getDesc(self):
|
def getDesc(self):
|
||||||
|
print 'YEAH'
|
||||||
return self.xval('rssfake:description|description')
|
return self.xval('rssfake:description|description')
|
||||||
|
|
||||||
def setDesc(self, value):
|
def setDesc(self, value):
|
||||||
|
if not value:
|
||||||
|
return self.xdel('rssfake:description|description')
|
||||||
|
|
||||||
table = { 'rdf:rdf': 'rssfake:description',
|
table = { 'rdf:rdf': 'rssfake:description',
|
||||||
'channel': 'description'}
|
'channel': 'description'}
|
||||||
element = self.xgetCreate(table)
|
element = self.xgetCreate(table)
|
||||||
|
@ -283,6 +308,9 @@ class FeedParserAtom(FeedParser):
|
||||||
return self.xval('atom:title|atom03:title')
|
return self.xval('atom:title|atom03:title')
|
||||||
|
|
||||||
def setTitle(self, value):
|
def setTitle(self, value):
|
||||||
|
if not value:
|
||||||
|
return self.xval('atom:title|atom03:title')
|
||||||
|
|
||||||
table = { 'atom:feed': 'atom:title',
|
table = { 'atom:feed': 'atom:title',
|
||||||
'atom03:feed': 'atom03:title'}
|
'atom03:feed': 'atom03:title'}
|
||||||
element = self.xgetCreate(table)
|
element = self.xgetCreate(table)
|
||||||
|
@ -293,6 +321,9 @@ class FeedParserAtom(FeedParser):
|
||||||
return self.xval('atom:subtitle|atom03:subtitle')
|
return self.xval('atom:subtitle|atom03:subtitle')
|
||||||
|
|
||||||
def setDesc(self, value):
|
def setDesc(self, value):
|
||||||
|
if not value:
|
||||||
|
return self.xdel('atom:subtitle|atom03:subtitle')
|
||||||
|
|
||||||
table = { 'atom:feed': 'atom:subtitle',
|
table = { 'atom:feed': 'atom:subtitle',
|
||||||
'atom03:feed': 'atom03:subtitle'}
|
'atom03:feed': 'atom03:subtitle'}
|
||||||
element = self.xgetCreate(table)
|
element = self.xgetCreate(table)
|
||||||
|
@ -316,6 +347,9 @@ class FeedItem(FeedBase):
|
||||||
def setTitle(self):
|
def setTitle(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def delTitle(self):
|
||||||
|
self.title = ""
|
||||||
|
|
||||||
|
|
||||||
def getLink(self):
|
def getLink(self):
|
||||||
return ""
|
return ""
|
||||||
|
@ -323,6 +357,9 @@ class FeedItem(FeedBase):
|
||||||
def setLink(self, value):
|
def setLink(self, value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def delLink(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def getDesc(self):
|
def getDesc(self):
|
||||||
return ""
|
return ""
|
||||||
|
@ -330,6 +367,9 @@ class FeedItem(FeedBase):
|
||||||
def setDesc(self, value):
|
def setDesc(self, value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def delDesc(self):
|
||||||
|
self.desc = ""
|
||||||
|
|
||||||
|
|
||||||
def getContent(self):
|
def getContent(self):
|
||||||
return ""
|
return ""
|
||||||
|
@ -337,6 +377,9 @@ class FeedItem(FeedBase):
|
||||||
def setContent(self, value):
|
def setContent(self, value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def delContent(self):
|
||||||
|
self.content = ""
|
||||||
|
|
||||||
|
|
||||||
title = FeedDescriptor('title')
|
title = FeedDescriptor('title')
|
||||||
link = FeedDescriptor('link')
|
link = FeedDescriptor('link')
|
||||||
|
@ -360,6 +403,9 @@ class FeedItemRSS(FeedItem):
|
||||||
return self.xval('rssfake:title|title')
|
return self.xval('rssfake:title|title')
|
||||||
|
|
||||||
def setTitle(self, value):
|
def setTitle(self, value):
|
||||||
|
if not value:
|
||||||
|
return self.xdel('rssfake:title|title')
|
||||||
|
|
||||||
table = { 'rdf:rdf': 'rssfake:title',
|
table = { 'rdf:rdf': 'rssfake:title',
|
||||||
'channel': 'title'}
|
'channel': 'title'}
|
||||||
element = self.xgetCreate(table)
|
element = self.xgetCreate(table)
|
||||||
|
@ -380,6 +426,9 @@ class FeedItemRSS(FeedItem):
|
||||||
return self.xval('rssfake:description|description')
|
return self.xval('rssfake:description|description')
|
||||||
|
|
||||||
def setDesc(self, value):
|
def setDesc(self, value):
|
||||||
|
if not value:
|
||||||
|
return self.xdel('rssfake:description|description')
|
||||||
|
|
||||||
table = { 'rdf:rdf': 'rssfake:description',
|
table = { 'rdf:rdf': 'rssfake:description',
|
||||||
'channel': 'description'}
|
'channel': 'description'}
|
||||||
element = self.xgetCreate(table)
|
element = self.xgetCreate(table)
|
||||||
|
@ -390,6 +439,9 @@ class FeedItemRSS(FeedItem):
|
||||||
return self.xval('content:encoded')
|
return self.xval('content:encoded')
|
||||||
|
|
||||||
def setContent(self, value):
|
def setContent(self, value):
|
||||||
|
if not value:
|
||||||
|
return self.r('content:encoded')
|
||||||
|
|
||||||
table = { 'rdf:rdf': 'content:encoded',
|
table = { 'rdf:rdf': 'content:encoded',
|
||||||
'channel': 'content:encoded'}
|
'channel': 'content:encoded'}
|
||||||
element = self.xgetCreate(table)
|
element = self.xgetCreate(table)
|
||||||
|
@ -403,6 +455,9 @@ class FeedItemAtom(FeedItem):
|
||||||
return self.xval('atom:title|atom03:title')
|
return self.xval('atom:title|atom03:title')
|
||||||
|
|
||||||
def setTitle(self, value):
|
def setTitle(self, value):
|
||||||
|
if not value:
|
||||||
|
return self.xdel('atom:title|atom03:title')
|
||||||
|
|
||||||
table = { 'atom:feed': 'atom:title',
|
table = { 'atom:feed': 'atom:title',
|
||||||
'atom03:feed': 'atom03:title'}
|
'atom03:feed': 'atom03:title'}
|
||||||
element = self.xgetCreate(table)
|
element = self.xgetCreate(table)
|
||||||
|
@ -428,6 +483,9 @@ class FeedItemAtom(FeedItem):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def setDesc(self, value):
|
def setDesc(self, value):
|
||||||
|
if not value:
|
||||||
|
return self.xdel('atom:summary|atom03:summary')
|
||||||
|
|
||||||
table = { 'atom:feed': 'atom:summary',
|
table = { 'atom:feed': 'atom:summary',
|
||||||
'atom03:feed': 'atom03:summary'}
|
'atom03:feed': 'atom03:summary'}
|
||||||
element = self.xgetCreate(table)
|
element = self.xgetCreate(table)
|
||||||
|
@ -445,6 +503,9 @@ class FeedItemAtom(FeedItem):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def setContent(self, value):
|
def setContent(self, value):
|
||||||
|
if not value:
|
||||||
|
return self.xdel('atom:content|atom03:content')
|
||||||
|
|
||||||
table = { 'atom:feed': 'atom:content',
|
table = { 'atom:feed': 'atom:content',
|
||||||
'atom03:feed': 'atom03:content'}
|
'atom03:feed': 'atom03:content'}
|
||||||
element = self.xgetCreate(table)
|
element = self.xgetCreate(table)
|
||||||
|
|
Loading…
Reference in New Issue