Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved feedreader.feedreader to feedreader.parser. You now MUST use fe…

…edreader.parser imports.
  • Loading branch information...
commit 343a482cbd9a65cfacb4cb809f793f66b0ae03c0 1 parent fe0bf60
authored September 07, 2009
6  README.rst
Source Rendered
@@ -28,13 +28,13 @@ Usage
28 28
 
29 29
 There are several methods which are usable to parse a feed::
30 30
 
31  
-	from feedreader import from_url
  31
+	from feedreader.parser import from_url
32 32
 	parsed = from_url('http://www.domain.com/rss.xml')
33 33
 
34  
-	from feedreader import from_string
  34
+	from feedreader.parser import from_string
35 35
 	parsed = from_string(open('my.rss', 'r').read())
36 36
 
37  
-	from feedreader import from_file
  37
+	from feedreader.parser import from_file
38 38
 	parsed = from_file(open('my.rss', 'r'))
39 39
 
40 40
 Once you have initialized the parser, you will be able to access supported elements
4  feedreader/__init__.py
@@ -26,6 +26,4 @@ def get_revision():
26 26
         return _get_git_revision(path)
27 27
     return None
28 28
 
29  
-__build__ = get_revision()
30  
-
31  
-from feedreader import *
  29
+__build__ = get_revision()
69  feedreader/feedreader.py
... ...
@@ -1,69 +0,0 @@
1  
-import lxml.objectify
2  
-import httplib
3  
-import urlparse
4  
-
5  
-from utils.dates import *
6  
-from feeds import InvalidFeed
7  
-
8  
-__all__ = ('ParseError', 'InvalidFeed', 'from_string', 'from_url', 'from_file', 'parse_date')
9  
-
10  
-# TODO: change the feeds to a registration model
11  
-from feeds.atom10 import Atom10Feed
12  
-from feeds.rss20 import RSS20Feed
13  
-
14  
-feeds = (RSS20Feed, Atom10Feed)
15  
-
16  
-ACCEPT_HEADER = "application/atom+xml,application/rdf+xml,application/rss+xml,application/x-netcdf,application/xml;q=0.9,text/xml;q=0.2,*/*;q=0.1"
17  
-
18  
-USER_AGENT = 'py-feedreader'
19  
-
20  
-class ParseError(Exception): pass
21  
-
22  
-def _from_parsed(parsed):
23  
-    for feed in feeds:
24  
-        try:
25  
-            result = feed(parsed)
26  
-        except InvalidFeed:
27  
-            pass
28  
-        else:
29  
-            return result
30  
-    raise InvalidFeed(parsed.tag)
31  
-
32  
-def from_string(data, *args, **kwargs):
33  
-    parsed = lxml.objectify.fromstring(data, *args, **kwargs)
34  
-    return _from_parsed(parsed)
35  
-
36  
-def from_file(fp, *args, **kwargs):
37  
-    parsed = lxml.objectify.parse(fp, **kwargs).getroot()
38  
-    return _from_parsed(parsed)
39  
-
40  
-def from_url(url, **kwargs):
41  
-    url = urlparse.urlparse(url)
42  
-    if url.scheme == 'https':
43  
-        conn = httplib.HTTPSConnection
44  
-    elif url.scheme == 'http':
45  
-        conn = httplib.HTTPConnection
46  
-    else:
47  
-        raise NotImplementedError
48  
-    
49  
-    base_url = '%s://%s' % (url.scheme, url.hostname)
50  
-    
51  
-    headers = {
52  
-        'User-Agent': USER_AGENT,
53  
-        'Accept': ACCEPT_HEADER,
54  
-    }
55  
-    connection = conn(url.hostname)
56  
-    method = kwargs.pop('method', 'GET').upper()
57  
-    if method == 'GET':
58  
-        path, query = url.path + '?' + url.query, ''
59  
-    else:
60  
-        path, query = url.path, url.query
61  
-    connection.request(method, path, query, headers)
62  
-    try:
63  
-        response = connection.getresponse()
64  
-    except httplib.BadStatusLine, exc:
65  
-        raise ParseError('Bad status line: %s' % (exc,))
66  
-    
67  
-    if response.status != 200:
68  
-        raise ParseError('%s %s' % (response.status, response.reason))
69  
-    return from_file(response, base_url=base_url)

0 notes on commit 343a482

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