Skip to content
This repository
Browse code

Change planet:subscription to planet:source, and expand the information

provided in each.
  • Loading branch information...
commit 9fa9fb6117e0e603dd2b01a8223ca8d6d500b21b 1 parent 6c0e24f
authored August 18, 2006

Showing 28 changed files with 195 additions and 51 deletions. Show diff stats Hide diff stats

  1. 6  examples/planet.xslt
  2. 2  planet/__init__.py
  3. 8  planet/config.py
  4. 6  planet/feedparser.py
  5. 18  planet/reconstitute.py
  6. 54  planet/spider.py
  7. 25  planet/splice.py
  8. 1  spider.py
  9. 1  splice.py
  10. 3  tests/data/spider/config.ini
  11. 15  tests/data/splice/cache/example.com,3
  12. 15  tests/data/splice/cache/example.com,4
  13. 0  ...splice/cache/{tag:planet.intertwingly.net,2006:testfeed1,1 → planet.intertwingly.net,2006,testfeed1,1}
  14. 0  ...splice/cache/{tag:planet.intertwingly.net,2006:testfeed1,2 → planet.intertwingly.net,2006,testfeed1,2}
  15. 0  ...splice/cache/{tag:planet.intertwingly.net,2006:testfeed1,3 → planet.intertwingly.net,2006,testfeed1,3}
  16. 0  ...splice/cache/{tag:planet.intertwingly.net,2006:testfeed1,4 → planet.intertwingly.net,2006,testfeed1,4}
  17. 0  ...splice/cache/{tag:planet.intertwingly.net,2006:testfeed2,1 → planet.intertwingly.net,2006,testfeed2,1}
  18. 0  ...splice/cache/{tag:planet.intertwingly.net,2006:testfeed2,2 → planet.intertwingly.net,2006,testfeed2,2}
  19. 0  ...splice/cache/{tag:planet.intertwingly.net,2006:testfeed2,3 → planet.intertwingly.net,2006,testfeed2,3}
  20. 0  ...splice/cache/{tag:planet.intertwingly.net,2006:testfeed2,4 → planet.intertwingly.net,2006,testfeed2,4}
  21. 15  tests/data/splice/cache/planet.intertwingly.net,2006,testfeed3,1
  22. 15  tests/data/splice/cache/planet.intertwingly.net,2006,testfeed3,2
  23. 15  tests/data/splice/cache/sources/tests,data,spider,testfeed1b.atom
  24. 15  tests/data/splice/cache/sources/tests,data,spider,testfeed2.atom
  25. 8  tests/data/splice/cache/sources/tests,data,spider,testfeed3.rss
  26. 5  tests/data/splice/config.ini
  27. 13  tests/test_spider.py
  28. 6  tests/test_splice.py
6  examples/planet.xslt
@@ -19,13 +19,15 @@
19 19
 
20 20
           <h2>Subscriptions</h2>
21 21
           <ul>
22  
-            <xsl:for-each select="planet:subscription">
  22
+            <xsl:for-each select="planet:source">
23 23
               <xsl:sort select="planet:name"/>
24 24
               <li>
25 25
                 <a href="{atom:link[@rel='self']/@href}" title="subscribe">
26 26
                   <img src="images/feed-icon-10x10.png" alt="(feed)"/>
27 27
                 </a>
28  
-                <xsl:value-of select="planet:name"/>
  28
+                <a href="{atom:link[@rel='alternate']/@href}">
  29
+                  <xsl:value-of select="planet:name"/>
  30
+                </a>
29 31
               </li>
30 32
             </xsl:for-each>
31 33
           </ul>
2  planet/__init__.py
... ...
@@ -1,3 +1,5 @@
  1
+xmlns = 'http://planet.intertwingly.net/'
  2
+
1 3
 logger = None
2 4
 
3 5
 def getLogger(level):
8  planet/config.py
@@ -26,7 +26,7 @@
26 26
   * error handling (example: no planet section)
27 27
 """
28 28
 
29  
-import sys
  29
+import os, sys
30 30
 from ConfigParser import ConfigParser
31 31
 
32 32
 parser = ConfigParser()
@@ -83,6 +83,12 @@ def template_files():
83 83
     """ list the templates defined """
84 84
     return parser.get('Planet','template_files').split(' ')
85 85
 
  86
+def cache_sources_directory():
  87
+    if parser.has_option('Planet', 'cache_sources_directory'):
  88
+        parser.get('Planet', 'cache_sources_directory')
  89
+    else:
  90
+        return os.path.join(cache_directory(), 'sources')
  91
+
86 92
 def feeds():
87 93
     """ list the feeds defined """
88 94
     return filter(lambda feed: feed!='Planet' and feed not in template_files(),
6  planet/feedparser.py
@@ -11,7 +11,7 @@
11 11
 Recommended: CJKCodecs and iconv_codec <http://cjkpython.i18n.org/>
12 12
 """
13 13
 
14  
-__version__ = "4.2-pre-" + "$Revision: 1.131 $"[11:16] + "-cvs"
  14
+__version__ = "4.2-pre-" + "$Revision: 1.132 $"[11:16] + "-cvs"
15 15
 __license__ = """Copyright (c) 2002-2006, Mark Pilgrim, All rights reserved.
16 16
 
17 17
 Redistribution and use in source and binary forms, with or without modification,
@@ -2379,12 +2379,16 @@ def handle_data(self, text):
2379 2379
             _BaseHTMLProcessor.handle_data(self, text)
2380 2380
 
2381 2381
     def sanitize_style(self, style):
  2382
+        # disallow urls
  2383
+        style=re.compile('url\s*\(\s*[^\s)]+?\s*\)\s*').sub(' ',style)
  2384
+
2382 2385
         # gauntlet
2383 2386
         if not re.match("""^([:,;#%.\sa-zA-Z0-9!]|\w-\w|'[\s\w]+'|"[\s\w]+"|\([\d,\s]+\))*$""", style): return ''
2384 2387
         if not re.match("^(\s*[-\w]+\s*:\s*[^:;]*(;|$))*$", style): return ''
2385 2388
 
2386 2389
         clean = []
2387 2390
         for prop,value in re.findall("([-\w]+)\s*:\s*([^:;]*)",style):
  2391
+          if not value: continue
2388 2392
           if prop.lower() in self.acceptable_css_properties:
2389 2393
               clean.append(prop + ': ' + value + ';')
2390 2394
           elif prop.split('-')[0].lower() in ['background','border','margin','padding']:
18  planet/reconstitute.py
@@ -18,6 +18,7 @@
18 18
 from xml.dom import minidom
19 19
 from BeautifulSoup import BeautifulSoup
20 20
 from xml.parsers.expat import ExpatError
  21
+import planet
21 22
 
22 23
 illegal_xml_chars = re.compile("[\x01-\x08\x0B\x0C\x0E-\x1F]")
23 24
 
@@ -141,10 +142,9 @@ def content(xentry, name, detail, bozo):
141 142
 
142 143
     xentry.appendChild(xcontent)
143 144
 
144  
-def source(xentry, source, bozo):
  145
+def source(xsource, source, bozo):
145 146
     """ copy source information to the entry """
146  
-    xdoc = xentry.ownerDocument
147  
-    xsource = xdoc.createElement('source')
  147
+    xdoc = xsource.ownerDocument
148 148
 
149 149
     createTextElement(xsource, 'id', source.get('id', None))
150 150
     createTextElement(xsource, 'icon', source.get('icon', None))
@@ -164,16 +164,14 @@ def source(xentry, source, bozo):
164 164
 
165 165
     # propagate planet inserted information
166 166
     for key, value in source.items():
167  
-        if key.startswith('planet:'):
168  
-            createTextElement(xsource, key, value)
169  
-
170  
-    xentry.appendChild(xsource)
  167
+        if key.startswith('planet_'):
  168
+            createTextElement(xsource, key.replace('_',':',1), value)
171 169
 
172 170
 def reconstitute(feed, entry):
173 171
     """ create an entry document from a parsed feed """
174 172
     xdoc=minidom.parseString('<entry xmlns="http://www.w3.org/2005/Atom"/>\n')
175 173
     xentry=xdoc.documentElement
176  
-    xentry.setAttribute('xmlns:planet','http://planet.intertwingly.net/')
  174
+    xentry.setAttribute('xmlns:planet',planet.xmlns)
177 175
 
178 176
     id(xentry, entry)
179 177
     links(xentry, entry)
@@ -191,6 +189,8 @@ def reconstitute(feed, entry):
191 189
     for contributor in entry.get('contributors',[]):
192 190
         author(xentry, 'contributor', contributor)
193 191
 
194  
-    source(xentry, entry.get('source', feed.feed), bozo)
  192
+    xsource = xdoc.createElement('source')
  193
+    source(xsource, entry.get('source', feed.feed), bozo)
  194
+    xentry.appendChild(xsource)
195 195
 
196 196
     return xdoc
54  planet/spider.py
@@ -5,8 +5,9 @@
5 5
 
6 6
 # Standard library modules
7 7
 import time, calendar, re, os
  8
+from xml.dom import minidom
8 9
 # Planet modules
9  
-import config, feedparser, reconstitute
  10
+import planet, config, feedparser, reconstitute
10 11
 
11 12
 try:
12 13
     from xml.dom.ext import PrettyPrint
@@ -40,15 +41,45 @@ def filename(directory, filename):
40 41
 
41 42
     return os.path.join(directory, filename)
42 43
 
  44
+def write(xdoc, out):
  45
+    """ write the document out to disk """
  46
+    file = open(out,'w')
  47
+    try:
  48
+        PrettyPrint(xdoc, file)
  49
+    except:
  50
+        # known reasons for failure include no pretty printer installed,
  51
+        # and absurdly high levels of markup nesting causing Python to
  52
+        # declare infinite recursion.
  53
+        file.seek(0)
  54
+        file.write(xdoc.toxml('utf-8'))
  55
+    file.close()
  56
+    xdoc.unlink()
  57
+
43 58
 def spiderFeed(feed):
44 59
     """ Spider (fetch) a single feed """
45 60
     data = feedparser.parse(feed)
46  
-    cache = config.cache_directory()
  61
+    if not data.feed: return
47 62
 
48  
-    # capture data from the planet configuration file
  63
+    # capture feed and data from the planet configuration file
  64
+    if not data.feed.has_key('links'): data.feed['links'] = list()
  65
+    for link in data.feed.links:
  66
+        if link.rel == 'self': break
  67
+    else:
  68
+        data.feed.links.append(feedparser.FeedParserDict(
  69
+            {'rel':'self', 'type':'application/atom+xml', 'href':feed}))
49 70
     for name, value in config.feed_options(feed).items():
50  
-        data.feed['planet:'+name] = value
  71
+        data.feed['planet_'+name] = value
51 72
     
  73
+    # write the feed info to the cache
  74
+    sources = config.cache_sources_directory()
  75
+    if not os.path.exists(sources): os.makedirs(sources)
  76
+    xdoc=minidom.parseString('''<feed xmlns:planet="%s"
  77
+      xmlns="http://www.w3.org/2005/Atom"/>\n''' % planet.xmlns)
  78
+    reconstitute.source(xdoc.documentElement, data.feed, data.bozo)
  79
+    write(xdoc, filename(sources, feed))
  80
+
  81
+    # write each entry to the cache
  82
+    cache = config.cache_directory()
52 83
     for entry in data.entries:
53 84
         if not entry.has_key('id'):
54 85
             entry['id'] = reconstitute.id(None, entry)
@@ -65,24 +96,11 @@ def spiderFeed(feed):
65 96
                 mtime = time.time()
66 97
             entry['updated_parsed'] = time.gmtime(mtime)
67 98
 
68  
-        xml = reconstitute.reconstitute(data, entry)
69  
-        
70  
-        file = open(out,'w')
71  
-        try:
72  
-            PrettyPrint(reconstitute.reconstitute(data, entry), file)
73  
-        except:
74  
-            # known reasons for failure include no pretty printer installed,
75  
-            # and absurdly high levels of markup nesting causing Python to
76  
-            # declare infinite recursion.
77  
-            file.seek(0)
78  
-            file.write(reconstitute.reconstitute(data, entry).toxml('utf-8'))
79  
-        file.close()
80  
-
  99
+        write(reconstitute.reconstitute(data, entry), out) 
81 100
         os.utime(out, (mtime, mtime))
82 101
 
83 102
 def spiderPlanet(configFile):
84 103
     """ Spider (fetch) an entire planet """
85  
-    import planet
86 104
     config.load(configFile)
87 105
     log = planet.getLogger(config.log_level())
88 106
     planet.setTimeout(config.feed_timeout())
25  planet/splice.py
... ...
@@ -1,8 +1,9 @@
1 1
 """ Splice together a planet from a cache of feed entries """
2 2
 import glob, os
3 3
 from xml.dom import minidom
4  
-import config
  4
+import planet, config, feedparser, reconstitute
5 5
 from reconstitute import createTextElement
  6
+from spider import filename
6 7
 
7 8
 def splice(configFile):
8 9
     """ Splice together a planet from a cache of entries """
@@ -11,7 +12,8 @@ def splice(configFile):
11 12
     log = planet.getLogger(config.log_level())
12 13
 
13 14
     cache = config.cache_directory()
14  
-    dir=[(os.stat(file).st_mtime,file) for file in glob.glob(cache+"/*")]
  15
+    dir=[(os.stat(file).st_mtime,file) for file in glob.glob(cache+"/*")
  16
+        if not os.path.isdir(file)]
15 17
     dir.sort()
16 18
     dir.reverse()
17 19
 
@@ -34,17 +36,14 @@ def splice(configFile):
34 36
         feed.appendChild(entry.documentElement)
35 37
 
36 38
     # insert subscription information
37  
-    feed.setAttribute('xmlns:planet','http://planet.intertwingly.net/')
  39
+    feed.setAttribute('xmlns:planet',planet.xmlns)
  40
+    sources = config.cache_sources_directory()
38 41
     for sub in config.feeds():
39  
-        name = config.feed_options(sub).get('name','')
40  
-        xsub = doc.createElement('planet:subscription')
41  
-        xlink = doc.createElement('link')
42  
-        xlink.setAttribute('rel','self')
43  
-        xlink.setAttribute('href',sub.decode('utf-8'))
44  
-        xsub.appendChild(xlink)
45  
-        xname = doc.createElement('planet:name')
46  
-        xname.appendChild(doc.createTextNode(name.decode('utf-8')))
47  
-        xsub.appendChild(xname)
48  
-        feed.appendChild(xsub)
  42
+        data=feedparser.parse(filename(sources,sub))
  43
+        if not data.feed: continue
  44
+        xdoc=minidom.parseString('''<planet:source xmlns:planet="%s"
  45
+             xmlns="http://www.w3.org/2005/Atom"/>\n''' % planet.xmlns)
  46
+        reconstitute.source(xdoc.documentElement, data.feed, data.bozo)
  47
+        feed.appendChild(xdoc.documentElement)
49 48
 
50 49
     return doc
1  spider.py 100644 → 100755
... ...
@@ -1,3 +1,4 @@
  1
+#!/usr/bin/env python
1 2
 """
2 3
 Main program to run just the spider portion of planet
3 4
 """
1  splice.py 100644 → 100755
... ...
@@ -1,3 +1,4 @@
  1
+#!/usr/bin/env python
1 2
 """
2 3
 Main program to run just the splice portion of planet
3 4
 """
3  tests/data/spider/config.ini
@@ -2,6 +2,9 @@
2 2
 cache_directory = tests/work/spider/cache
3 3
 template_files = 
4 4
 
  5
+[tests/data/spider/testfeed0.atom]
  6
+name = not found
  7
+
5 8
 [tests/data/spider/testfeed1b.atom]
6 9
 name = one
7 10
 
15  tests/data/splice/cache/example.com,3
... ...
@@ -0,0 +1,15 @@
  1
+<?xml version='1.0' encoding='UTF-8'?>
  2
+<entry xmlns='http://www.w3.org/2005/Atom' xmlns:planet='http://planet.intertwingly.net/'>
  3
+  <id>http://example.com/3</id>
  4
+  <link href='http://example.com/3' type='text/html' rel='alternate'/>
  5
+  <title>Earth</title>
  6
+  <summary>the Blue Planet</summary>
  7
+  <updated>2006-01-03T00:00:00Z</updated>
  8
+  <source>
  9
+    <link href='http://intertwingly.net/code/venus/tests/data/spider/testfeed3.rss' type='text/html' rel='alternate'/>
  10
+    <link href='tests/data/spider/testfeed3.rss' type='application/atom+xml' rel='self'/>
  11
+    <subtitle>It’s just data</subtitle>
  12
+    <title>Sam Ruby</title>
  13
+    <planet:name>three</planet:name>
  14
+  </source>
  15
+</entry>
15  tests/data/splice/cache/example.com,4
... ...
@@ -0,0 +1,15 @@
  1
+<?xml version='1.0' encoding='UTF-8'?>
  2
+<entry xmlns='http://www.w3.org/2005/Atom' xmlns:planet='http://planet.intertwingly.net/'>
  3
+  <id>http://example.com/4</id>
  4
+  <link href='http://example.com/4' type='text/html' rel='alternate'/>
  5
+  <title>Mars</title>
  6
+  <summary>the Red Planet</summary>
  7
+  <updated>2006-08-18T18:30:50Z</updated>
  8
+  <source>
  9
+    <link href='http://intertwingly.net/code/venus/tests/data/spider/testfeed3.rss' type='text/html' rel='alternate'/>
  10
+    <link href='tests/data/spider/testfeed3.rss' type='application/atom+xml' rel='self'/>
  11
+    <subtitle>It’s just data</subtitle>
  12
+    <title>Sam Ruby</title>
  13
+    <planet:name>three</planet:name>
  14
+  </source>
  15
+</entry>
0  ...ache/tag:planet.intertwingly.net,2006:testfeed1,1 → ...ce/cache/planet.intertwingly.net,2006,testfeed1,1
File renamed without changes
0  ...ache/tag:planet.intertwingly.net,2006:testfeed1,2 → ...ce/cache/planet.intertwingly.net,2006,testfeed1,2
File renamed without changes
0  ...ache/tag:planet.intertwingly.net,2006:testfeed1,3 → ...ce/cache/planet.intertwingly.net,2006,testfeed1,3
File renamed without changes
0  ...ache/tag:planet.intertwingly.net,2006:testfeed1,4 → ...ce/cache/planet.intertwingly.net,2006,testfeed1,4
File renamed without changes
0  ...ache/tag:planet.intertwingly.net,2006:testfeed2,1 → ...ce/cache/planet.intertwingly.net,2006,testfeed2,1
File renamed without changes
0  ...ache/tag:planet.intertwingly.net,2006:testfeed2,2 → ...ce/cache/planet.intertwingly.net,2006,testfeed2,2
File renamed without changes
0  ...ache/tag:planet.intertwingly.net,2006:testfeed2,3 → ...ce/cache/planet.intertwingly.net,2006,testfeed2,3
File renamed without changes
0  ...ache/tag:planet.intertwingly.net,2006:testfeed2,4 → ...ce/cache/planet.intertwingly.net,2006,testfeed2,4
File renamed without changes
15  tests/data/splice/cache/planet.intertwingly.net,2006,testfeed3,1
... ...
@@ -0,0 +1,15 @@
  1
+<?xml version='1.0' encoding='UTF-8'?>
  2
+<entry xmlns='http://www.w3.org/2005/Atom' xmlns:planet='http://planet.intertwingly.net/'>
  3
+  <id>tag:planet.intertwingly.net,2006:testfeed3/1</id>
  4
+  <link href='http://example.com/1' type='text/html' rel='alternate'/>
  5
+  <title>Mercury</title>
  6
+  <summary>Messenger of the Roman Gods</summary>
  7
+  <updated>2006-01-01T00:00:00Z</updated>
  8
+  <source>
  9
+    <link href='http://intertwingly.net/code/venus/tests/data/spider/testfeed3.rss' type='text/html' rel='alternate'/>
  10
+    <link href='tests/data/spider/testfeed3.rss' type='application/atom+xml' rel='self'/>
  11
+    <subtitle>It’s just data</subtitle>
  12
+    <title>Sam Ruby</title>
  13
+    <planet:name>three</planet:name>
  14
+  </source>
  15
+</entry>
15  tests/data/splice/cache/planet.intertwingly.net,2006,testfeed3,2
... ...
@@ -0,0 +1,15 @@
  1
+<?xml version='1.0' encoding='UTF-8'?>
  2
+<entry xmlns='http://www.w3.org/2005/Atom' xmlns:planet='http://planet.intertwingly.net/'>
  3
+  <id>tag:planet.intertwingly.net,2006:testfeed3/2</id>
  4
+  <link href='http://example.com/2' type='text/html' rel='alternate'/>
  5
+  <title>Venus</title>
  6
+  <summary>the Morning Star</summary>
  7
+  <updated>2006-08-18T18:30:50Z</updated>
  8
+  <source>
  9
+    <link href='http://intertwingly.net/code/venus/tests/data/spider/testfeed3.rss' type='text/html' rel='alternate'/>
  10
+    <link href='tests/data/spider/testfeed3.rss' type='application/atom+xml' rel='self'/>
  11
+    <subtitle>It’s just data</subtitle>
  12
+    <title>Sam Ruby</title>
  13
+    <planet:name>three</planet:name>
  14
+  </source>
  15
+</entry>
15  tests/data/splice/cache/sources/tests,data,spider,testfeed1b.atom
... ...
@@ -0,0 +1,15 @@
  1
+<?xml version='1.0' encoding='UTF-8'?>
  2
+<feed xmlns='http://www.w3.org/2005/Atom' xmlns:planet='http://planet.intertwingly.net/'>
  3
+  <id>tag:planet.intertwingly.net,2006:testfeed1</id>
  4
+  <author>
  5
+    <name>Sam Ruby</name>
  6
+    <email>rubys@intertwingly.net</email>
  7
+    <uri>http://www.intertwingly.net/blog/</uri>
  8
+  </author>
  9
+  <link href='http://intertwingly.net/code/venus/tests/data/spider/testfeed1a.atom' type='application/atom+xml' rel='self'/>
  10
+  <link href='http://www.intertwingly.net/blog/' type='text/html' rel='alternate'/>
  11
+  <subtitle>It’s just data</subtitle>
  12
+  <title>Sam Ruby</title>
  13
+  <updated>2006-06-17T00:15:18Z</updated>
  14
+  <planet:name>one</planet:name>
  15
+</feed>
15  tests/data/splice/cache/sources/tests,data,spider,testfeed2.atom
... ...
@@ -0,0 +1,15 @@
  1
+<?xml version='1.0' encoding='UTF-8'?>
  2
+<feed xmlns='http://www.w3.org/2005/Atom' xmlns:planet='http://planet.intertwingly.net/'>
  3
+  <id>tag:planet.intertwingly.net,2006:testfeed2</id>
  4
+  <author>
  5
+    <name>Sam Ruby</name>
  6
+    <email>rubys@intertwingly.net</email>
  7
+    <uri>http://www.intertwingly.net/blog/</uri>
  8
+  </author>
  9
+  <link href='http://intertwingly.net/code/venus/tests/data/spider/testfeed2.atom' type='application/atom+xml' rel='self'/>
  10
+  <link href='http://www.intertwingly.net/blog/' type='text/html' rel='alternate'/>
  11
+  <subtitle>It’s just data</subtitle>
  12
+  <title>Sam Ruby</title>
  13
+  <updated>2006-06-17T00:15:18Z</updated>
  14
+  <planet:name>two</planet:name>
  15
+</feed>
8  tests/data/splice/cache/sources/tests,data,spider,testfeed3.rss
... ...
@@ -0,0 +1,8 @@
  1
+<?xml version='1.0' encoding='UTF-8'?>
  2
+<feed xmlns='http://www.w3.org/2005/Atom' xmlns:planet='http://planet.intertwingly.net/'>
  3
+  <link href='http://intertwingly.net/code/venus/tests/data/spider/testfeed3.rss' type='text/html' rel='alternate'/>
  4
+  <link href='tests/data/spider/testfeed3.rss' type='application/atom+xml' rel='self'/>
  5
+  <subtitle>It’s just data</subtitle>
  6
+  <title>Sam Ruby</title>
  7
+  <planet:name>three</planet:name>
  8
+</feed>
5  tests/data/splice/config.ini
@@ -3,9 +3,14 @@ name = test planet
3 3
 cache_directory = tests/data/splice/cache
4 4
 template_files = 
5 5
 
  6
+[tests/data/spider/testfeed0.atom]
  7
+name = not found
  8
+
6 9
 [tests/data/spider/testfeed1b.atom]
7 10
 name = one
8 11
 
9 12
 [tests/data/spider/testfeed2.atom]
10 13
 name = two
11 14
 
  15
+[tests/data/spider/testfeed3.rss]
  16
+name = three
13  tests/test_spider.py
@@ -17,6 +17,10 @@ def setUp(self):
17 17
              os.makedirs(workdir)
18 18
     
19 19
     def tearDown(self):
  20
+        for file in glob.glob(workdir+"/sources/*"):
  21
+             os.unlink(file)
  22
+        if os.path.exists(workdir+"/sources"):
  23
+            os.rmdir(workdir+"/sources")
20 24
         for file in glob.glob(workdir+"/*"):
21 25
              os.unlink(file)
22 26
         os.removedirs(workdir)
@@ -36,8 +40,8 @@ def test_spiderFeed(self):
36 40
         spiderFeed(testfeed % '1b')
37 41
         files = glob.glob(workdir+"/*")
38 42
 
39  
-        # verify that exactly four files were produced
40  
-        self.assertEqual(4, len(files))
  43
+        # verify that exactly four files + one sources dir were produced
  44
+        self.assertEqual(5, len(files))
41 45
 
42 46
         # verify that the file names are as expected
43 47
         self.assertTrue(workdir + 
@@ -45,6 +49,7 @@ def test_spiderFeed(self):
45 49
 
46 50
         # verify that the file timestamps match atom:updated
47 51
         for file in files:
  52
+            if file.endswith('/sources'): continue
48 53
             data = feedparser.parse(file)
49 54
             self.assertTrue(data.entries[0].source.planet_name)
50 55
             self.assertEqual(os.stat(file).st_mtime,
@@ -58,8 +63,8 @@ def test_spiderPlanet(self):
58 63
         spiderPlanet(configfile)
59 64
         files = glob.glob(workdir+"/*")
60 65
 
61  
-        # verify that exactly eight files were produced
62  
-        self.assertEqual(12, len(files))
  66
+        # verify that exactly eight files + 1 source dir were produced
  67
+        self.assertEqual(13, len(files))
63 68
 
64 69
         # verify that the file names are as expected
65 70
         self.assertTrue(workdir + 
6  tests/test_splice.py
@@ -9,9 +9,9 @@ class SpliceTest(unittest.TestCase):
9 9
 
10 10
     def test_splice(self):
11 11
         doc = splice(configfile)
12  
-        self.assertEqual(8,len(doc.getElementsByTagName('entry')))
13  
-        self.assertEqual(2,len(doc.getElementsByTagName('planet:subscription')))
14  
-        self.assertEqual(10,len(doc.getElementsByTagName('planet:name')))
  12
+        self.assertEqual(12,len(doc.getElementsByTagName('entry')))
  13
+        self.assertEqual(3,len(doc.getElementsByTagName('planet:source')))
  14
+        self.assertEqual(15,len(doc.getElementsByTagName('planet:name')))
15 15
 
16 16
         self.assertEqual('test planet',
17 17
             doc.getElementsByTagName('title')[0].firstChild.nodeValue)

0 notes on commit 9fa9fb6

Please sign in to comment.
Something went wrong with that request. Please try again.