-
Notifications
You must be signed in to change notification settings - Fork 15
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
Showing
4 changed files
with
67 additions
and
0 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 | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
:maxdepth: 2 | ||
|
||
libearth/compat | ||
libearth/feed | ||
libearth/repository | ||
libearth/schema | ||
libearth/session | ||
|
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
.. automodule:: libearth.feed | ||
:members: |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""":mod:`libearth.feed` --- Feed list | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
""" | ||
|
||
from .compat import xrange | ||
|
||
class Feed(object): | ||
def __init__(self, path=None): | ||
"""Initializer of Feed list | ||
when path is None, it doesn't save opml file. just use memory | ||
""" | ||
#TODO: save with file, load with file | ||
self.path = path | ||
self.feedlist = {} | ||
|
||
def __len__(self): | ||
return len(self.feedlist) | ||
|
||
def __repr__(self): | ||
return '<{0.__module__}.{0.__name__} using {1}>'.format(type(self), self.path) | ||
|
||
def add_feed(self, title, url): | ||
if url in self.feedlist: | ||
raise AlreadyExistException("{0} is already Exist".format(title)) | ||
self.feedlist[url] = {'title': title} | ||
|
||
def remove_feed(self, url): | ||
"""Remove feed from feed list | ||
:returns: :const:`True` when successfuly removed. :const:`False` when have not to or failed to remove. | ||
:rtype: :class:`bool` | ||
""" | ||
if url not in self.feedlist: | ||
return False | ||
else: | ||
self.feedlist.pop(url) | ||
return True | ||
|
||
class AlreadyExistException(Exception): | ||
pass |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pytest import raises | ||
|
||
from libearth.compat import xrange | ||
from libearth.feed import Feed, AlreadyExistException | ||
|
||
def test_count_empty_list(): | ||
f = Feed() | ||
assert len(f) == 0 | ||
|
||
def test_count_duplicated_url(): | ||
f = Feed() | ||
with raises(AlreadyExistException): | ||
for i in xrange(30): | ||
f.add_feed('title', 'url') | ||
|
||
assert len(f) == 1 | ||
|
||
def test_count_after_remove(): | ||
f = Feed() | ||
f.add_feed('title', 'url') | ||
f.remove_feed('url') | ||
|
||
assert len(f) == 0 |