-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Cramer
committed
Sep 5, 2009
1 parent
f6b6f85
commit 442e342
Showing
6 changed files
with
130 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1 +1,3 @@ | |||
*.pyc | *.pyc | ||
/build | |||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
Copyright (c) 2009, David Cramer <dcramer@gmail.com> | |||
All rights reserved. | |||
|
|||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | |||
|
|||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | |||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | |||
|
|||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
include setup.py README.rst LICENSE MANIFEST.in | |||
global-exclude *~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,69 +1,31 @@ | |||
import lxml.objectify | import os.path | ||
import httplib | |||
import urlparse | |||
|
|
||
from feedreader.utils.dates import * | __all__ = ('__version__', '__build__') | ||
from feedreader.feeds import InvalidFeed | |||
|
|
||
__all__ = ('ParseError', 'InvalidFeed', 'from_string', 'from_url', 'from_file', 'parse_date') | __version__ = (0, 1) | ||
|
|
||
# TODO: change the feeds to a registration model | def _get_git_revision(path): | ||
from feedreader.feeds.atom10 import Atom10Feed | revision_file = os.path.join(path, 'refs', 'heads', 'master') | ||
from feedreader.feeds.rss20 import RSS20Feed | if not os.path.exists(revision_file): | ||
|
return None | ||
feeds = (RSS20Feed, Atom10Feed) | fh = open(revision_file, 'r') | ||
|
|||
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" | |||
|
|||
USER_AGENT = 'py-feedreader' | |||
|
|||
class ParseError(Exception): pass | |||
|
|||
def _from_parsed(parsed): | |||
for feed in feeds: | |||
try: | |||
result = feed(parsed) | |||
except InvalidFeed: | |||
pass | |||
else: | |||
return result | |||
raise InvalidFeed(parsed.tag) | |||
|
|||
def from_string(data, *args, **kwargs): | |||
parsed = lxml.objectify.fromstring(data, *args, **kwargs) | |||
return _from_parsed(parsed) | |||
|
|||
def from_file(fp, *args, **kwargs): | |||
parsed = lxml.objectify.parse(fp, **kwargs).getroot() | |||
return _from_parsed(parsed) | |||
|
|||
def from_url(url, **kwargs): | |||
url = urlparse.urlparse(url) | |||
if url.scheme == 'https': | |||
conn = httplib.HTTPSConnection | |||
elif url.scheme == 'http': | |||
conn = httplib.HTTPConnection | |||
else: | |||
raise NotImplementedError | |||
|
|||
base_url = '%s://%s' % (url.scheme, url.hostname) | |||
|
|||
headers = { | |||
'User-Agent': USER_AGENT, | |||
'Accept': ACCEPT_HEADER, | |||
} | |||
connection = conn(url.hostname) | |||
method = kwargs.pop('method', 'GET').upper() | |||
if method == 'GET': | |||
path, query = url.path + '?' + url.query, '' | |||
else: | |||
path, query = url.path, url.query | |||
connection.request(method, path, query, headers) | |||
try: | try: | ||
response = connection.getresponse() | return fh.read() | ||
except httplib.BadStatusLine, exc: | finally: | ||
raise ParseError('Bad status line: %s' % (exc,)) | fh.close() | ||
|
|
||
if response.status != 200: | def get_revision(): | ||
raise ParseError('%s %s' % (response.status, response.reason)) | """ | ||
return from_file(response, base_url=base_url) | :returns: Revision number of this branch/checkout, if available. None if | ||
no revision number can be determined. | |||
""" | |||
package_dir = os.path.dirname(__file__) | |||
checkout_dir = os.path.normpath(os.path.join(package_dir, '..')) | |||
path = os.path.join(checkout_dir, '.git') | |||
if os.path.exists(path): | |||
return _get_git_revision(path) | |||
return None | |||
|
|||
__build__ = get_revision() | |||
|
|||
from feedreader import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,69 @@ | |||
import lxml.objectify | |||
import httplib | |||
import urlparse | |||
|
|||
from feedreader.utils.dates import * | |||
from feedreader.feeds import InvalidFeed | |||
|
|||
__all__ = ('ParseError', 'InvalidFeed', 'from_string', 'from_url', 'from_file', 'parse_date') | |||
|
|||
# TODO: change the feeds to a registration model | |||
from feedreader.feeds.atom10 import Atom10Feed | |||
from feedreader.feeds.rss20 import RSS20Feed | |||
|
|||
feeds = (RSS20Feed, Atom10Feed) | |||
|
|||
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" | |||
|
|||
USER_AGENT = 'py-feedreader' | |||
|
|||
class ParseError(Exception): pass | |||
|
|||
def _from_parsed(parsed): | |||
for feed in feeds: | |||
try: | |||
result = feed(parsed) | |||
except InvalidFeed: | |||
pass | |||
else: | |||
return result | |||
raise InvalidFeed(parsed.tag) | |||
|
|||
def from_string(data, *args, **kwargs): | |||
parsed = lxml.objectify.fromstring(data, *args, **kwargs) | |||
return _from_parsed(parsed) | |||
|
|||
def from_file(fp, *args, **kwargs): | |||
parsed = lxml.objectify.parse(fp, **kwargs).getroot() | |||
return _from_parsed(parsed) | |||
|
|||
def from_url(url, **kwargs): | |||
url = urlparse.urlparse(url) | |||
if url.scheme == 'https': | |||
conn = httplib.HTTPSConnection | |||
elif url.scheme == 'http': | |||
conn = httplib.HTTPConnection | |||
else: | |||
raise NotImplementedError | |||
|
|||
base_url = '%s://%s' % (url.scheme, url.hostname) | |||
|
|||
headers = { | |||
'User-Agent': USER_AGENT, | |||
'Accept': ACCEPT_HEADER, | |||
} | |||
connection = conn(url.hostname) | |||
method = kwargs.pop('method', 'GET').upper() | |||
if method == 'GET': | |||
path, query = url.path + '?' + url.query, '' | |||
else: | |||
path, query = url.path, url.query | |||
connection.request(method, path, query, headers) | |||
try: | |||
response = connection.getresponse() | |||
except httplib.BadStatusLine, exc: | |||
raise ParseError('Bad status line: %s' % (exc,)) | |||
|
|||
if response.status != 200: | |||
raise ParseError('%s %s' % (response.status, response.reason)) | |||
return from_file(response, base_url=base_url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
#!/usr/bin/env python | |||
|
|||
from setuptools import setup, find_packages | |||
|
|||
import feedreader | |||
|
|||
setup( | |||
name='feedreader', | |||
version=".".join(map(str, idmapper.__version__)), | |||
author='David Cramer', | |||
author_email='dcramer@gmail.com', | |||
url='http://github.com/dcramer/feedreader', | |||
install_requires=[ | |||
'lxml', | |||
'python-dateutil', | |||
], | |||
description = 'An identify mapper for the Django ORM', | |||
packages=find_packages(), | |||
include_package_data=True, | |||
) |