fix some failing tests

This commit is contained in:
j 2012-09-09 19:28:11 +02:00
parent fcae567823
commit 8ba74a1e4b
10 changed files with 45 additions and 40 deletions

View file

@ -18,7 +18,7 @@ def toAZ(num):
'FOO' 'FOO'
>>> toAZ(1234567890) >>> toAZ(1234567890)
'CYWOQVK' 'CYWOQVJ'
""" """
if num < 1: raise ValueError, "must supply a positive integer" if num < 1: raise ValueError, "must supply a positive integer"
digits = string.letters[26:] digits = string.letters[26:]
@ -74,7 +74,7 @@ def to26(q):
def from26(q): def from26(q):
""" """
Converts an base 26 string to an integer Converts an base 26 string to an integer
>>> from32('A') >>> from26('A')
0 0
""" """
base26 = string.letters[26:] base26 = string.letters[26:]

View file

@ -142,9 +142,9 @@ def decode_html(html):
>>> decode_html('me &amp; you and &#36;&#38;%') >>> decode_html('me &amp; you and &#36;&#38;%')
u'me & you and $&%' u'me & you and $&%'
>>> decode_html('&#x80;') >>> decode_html('&#x80;')
u'' u'\u20ac'
>>> decode_html('Anniversary of Daoud&apos;s Republic') >>> decode_html('Anniversary of Daoud&apos;s Republic')
u'Anniversary of Daoud's Republic' u"Anniversary of Daoud's Republic"
""" """
if type(html) != unicode: if type(html) != unicode:
html = unicode(html)[:] html = unicode(html)[:]
@ -194,33 +194,33 @@ def escape_html(value):
def sanitize_html(html, tags=None, wikilinks=False): def sanitize_html(html, tags=None, wikilinks=False):
''' '''
>>> sanitize_html('http://foo.com, bar') >>> sanitize_html('http://foo.com, bar')
'<a href="http://foo.com">http://foo.com</a>, bar' u'<a href="http://foo.com">http://foo.com</a>, bar'
>>> sanitize_html('http://foo.com/foobar?foo, bar') >>> sanitize_html('http://foo.com/foobar?foo, bar')
'<a href="http://foo.com/foobar?foo">http://foo.com/foobar?foo</a>, bar' u'<a href="http://foo.com/foobar?foo">http://foo.com/foobar?foo</a>, bar'
>>> sanitize_html('(see: www.foo.com)') >>> sanitize_html('(see: www.foo.com)')
'(see: <a href="http://www.foo.com">www.foo.com</a>)' u'(see: <a href="http://www.foo.com">www.foo.com</a>)'
>>> sanitize_html('foo@bar.com') >>> sanitize_html('foo@bar.com')
'<a href="mailto:foo@bar.com">foo@bar.com</a>' u'<a href="mailto:foo@bar.com">foo@bar.com</a>'
>>> sanitize_html(sanitize_html('foo@bar.com')) >>> sanitize_html(sanitize_html('foo@bar.com'))
'<a href="mailto:foo@bar.com">foo@bar.com</a>' u'<a href="mailto:foo@bar.com">foo@bar.com</a>'
>>> sanitize_html('<a href="http://foo.com" onmouseover="alert()">foo</a>') >>> sanitize_html('<a href="http://foo.com" onmouseover="alert()">foo</a>')
'<a href="http://foo.com">foo</a>' u'<a href="http://foo.com">foo</a>'
>>> sanitize_html('<a href="javascript:alert()">foo</a>') >>> sanitize_html('<a href="javascript:alert()">foo</a>')
'&lt;a href="javascript:alert()"&gt;foo' u'&lt;a href="javascript:alert()"&gt;foo'
>>> sanitize_html('[http://foo.com foo]') >>> sanitize_html('[http://foo.com foo]')
'<a href="http://foo.com">foo</a>' u'<a href="http://foo.com">foo</a>'
>>> sanitize_html('<rtl>foo</rtl>') >>> sanitize_html('<rtl>foo</rtl>')
'<div style="direction: rtl">foo</div>' u'<div style="direction: rtl">foo</div>'
>>> sanitize_html('<script>alert()</script>') >>> sanitize_html('<script>alert()</script>')
'&lt;script&gt;alert()&lt;/script&gt;' u'&lt;script&gt;alert()&lt;/script&gt;'
>>> sanitize_html('\'foo\' < \'bar\' && "foo" > "bar"') >>> sanitize_html("'foo' < 'bar' && \"foo\" > \"bar\"")
'\'foo\' &lt; \'bar\' &amp;&amp; "foo" &gt; "bar"' u'\'foo\' &lt; \'bar\' &amp;&amp; "foo" &gt; "bar"'
>>> sanitize_html('<b>foo') >>> sanitize_html('<b>foo')
'<b>foo</b>' u'<b>foo</b>'
>>> sanitize_html('<b>foo</b></b>') >>> sanitize_html('<b>foo</b></b>')
'<b>foo</b>' u'<b>foo</b>'
>>> sanitize_html('Anniversary of Daoud&apos;s Republic') >>> sanitize_html('Anniversary of Daoud&apos;s Republic')
'Anniversary of Daoud&apos;s Republic' u"Anniversary of Daoud's Republic"
''' '''
if not tags: if not tags:
tags = [ tags = [

View file

@ -172,20 +172,25 @@ def parse_item_files(files):
def parse_path(path): def parse_path(path):
''' '''
# all keys # all keys
>>> parse_path('F/Frost, Mark; Lynch, David/Twin Peaks (1991)/Twin Peaks (S01E01) Pilot.European Version.Part 1.Welcome to Twin Peaks.en.fr.MPEG')['path'] >>> parse_path('F/Frost, Mark; Lynch, David/Twin Peaks (1991)/Twin Peaks (S01E01) Pilot.European Version.Part 1.Welcome to Twin Peaks.en.fr.MPEG')['normalizedPath']
'F/Frost, Mark; Lynch, David/Twin Peaks (1991)/Twin Peaks (S01E00) Pilot.European Version.Part 1.Welcome to Twin Peaks.en.fr.mpg' 'F/Frost, Mark; Lynch, David/Twin Peaks (1991)/Twin Peaks (S01E00) Pilot.European Version.Part 1.Welcome to Twin Peaks.en.fr.mpg'
# pop directory title off file name # pop directory title off file name
>>> parse_path('U/Unknown Director/www.xxx.com.._/www.xxx.com....Directors\'s Cut.avi')['version'] >>> parse_path("U/Unknown Director/www.xxx.com.._/www.xxx.com....Director's Cut.avi")['version']
'Director\'s Cut' "Director's Cut"
# handle dots # handle dots
>>> parse_path('U/Unknown Director/Unknown Title (2000)/... Mr. .com....Director\'s Cut.srt')['version'] >>> parse_path("U/Unknown Director/Unknown Title (2000)/... Mr. .com....Director's Cut.srt")['version']
'Director\'s Cut' "Director's Cut"
# multiple years, season zero, multiple episodes, dots in episode title and part title # multiple years, season zero, multiple episodes, dots in episode title and part title
>>> parse_path('G/Groening, Matt/The Simpsons (1989-2012)/The Simpsons (S00E01-02) D.I.Y..Uncensored Version.Part 1.D.I.Y..de.avi')['path'] >>> parse_path('G/Groening, Matt/The Simpsons (1989-2012)/The Simpsons (S00E01-02) D.I.Y..Uncensored Version.Part 1.D.I.Y..de.avi')['normalizedPath']
'G/Groening, Matt/The Simpsons (1989-2012)/The Simpsons (S01E01+02) D.I.Y..Uncensored Version.Part 1.D.I.Y..de.avi' 'G/Groening, Matt/The Simpsons (1989-2012)/The Simpsons (S01E01+02) D.I.Y..Uncensored Version.Part 1.D.I.Y..de.avi'
# handle underscores # handle underscores
>>> parse_path('U/Unknown Director/_com_ 1_0 _ NaN.._/_com_ 1_0 _ NaN....avi')['title'] >>> parse_path('U/Unknown Director/_com_ 1_0 _ NaN.._/_com_ 1_0 _ NaN....avi')['title']
'.com: 1/0 / NaN...' '.com: 1/0 / NaN...'
# TODO: '.com.avi' # TODO: '.com.avi'
''' '''
def parse_title(string): def parse_title(string):

View file

@ -35,7 +35,7 @@ def exists(url, data=None, headers=DEFAULT_HEADERS):
return True return True
return False return False
def headers(url, data=None, headers=DEFAULT_HEADERS): def get_headers(url, data=None, headers=DEFAULT_HEADERS):
try: try:
f = open_url(url, data, headers) f = open_url(url, data, headers)
f.headers['Status'] = "%s" % f.code f.headers['Status'] = "%s" % f.code

View file

@ -405,9 +405,9 @@ def truncate_string(string, length, padding='...', position='right'):
def truncate_words(s, num): def truncate_words(s, num):
"""Truncates a string after a certain number of chacters, but ends with a word """Truncates a string after a certain number of chacters, but ends with a word
>>> truncate_string('Truncates a string after a certain number of chacters, but ends with a word', 23) >>> truncate_words('Truncates a string after a certain number of chacters, but ends with a word', 23)
'Truncates a string...' 'Truncates a string...'
>>> truncate_string('Truncates a string', 23) >>> truncate_words('Truncates a string', 23)
'Truncates a string' 'Truncates a string'
""" """

View file

@ -17,14 +17,14 @@ def get_url(id):
def get_data(id, timeout=ox.cache.cache_timeout, get_imdb=False): def get_data(id, timeout=ox.cache.cache_timeout, get_imdb=False):
''' '''
>>> get_data('1333')['imdbId'] >>> get_data('1333').get('imdbId')
u'0060304' u'0060304'
>>> get_data('236')['posters'][0] >>> get_data('236')['posters'][0]
u'http://criterion_production.s3.amazonaws.com/release_images/1586/ThirdManReplace.jpg' u'http://s3.amazonaws.com/criterion-production/release_images/1586/ThirdManReplace.jpg'
>>> get_data('786')['posters'][0] >>> get_data('786')['posters'][0]
u'http://criterion_production.s3.amazonaws.com/product_images/185/343_box_348x490.jpg' u'http://s3.amazonaws.com/criterion-production/product_images/185/343_box_348x490.jpg'
''' '''
data = { data = {
"url": get_url(id) "url": get_url(id)
@ -60,6 +60,7 @@ def get_data(id, timeout=ox.cache.cache_timeout, get_imdb=False):
data["posters"] = [result.replace("_w100", "")] data["posters"] = [result.replace("_w100", "")]
else: else:
data["posters"] = [] data["posters"] = []
data['posters'] = [re.sub('(\?\d+)$', '', p) for p in data['posters']]
result = find_re(html, "<img alt=\"Film Still\" height=\"252\" src=\"(.*?)\"") result = find_re(html, "<img alt=\"Film Still\" height=\"252\" src=\"(.*?)\"")
if result: if result:
data["stills"] = [result] data["stills"] = [result]

View file

@ -7,10 +7,10 @@ from ox.cache import read_url
def get_video_url(url): def get_video_url(url):
''' '''
>>> getVideoUrl('http://www.dailymotion.com/relevance/search/priere%2Bpour%2Brefuznik/video/x3opar_priere-pour-refuznik-1-jeanluc-goda_shortfilms').split('?auth')[0] >>> get_video_url('http://www.dailymotion.com/relevance/search/priere%2Bpour%2Brefuznik/video/x3opar_priere-pour-refuznik-1-jeanluc-goda_shortfilms').split('?auth')[0]
'http://www.dailymotion.com/cdn/FLV-320x240/video/x3opar_priere-pour-refuznik-1-jean-luc-god_shortfilms.flv' 'http://www.dailymotion.com/cdn/FLV-320x240/video/x3opar_priere-pour-refuznik-1-jean-luc-god_shortfilms.flv'
>>> getVideoUrl('http://www.dailymotion.com/relevance/search/priere%2Bpour%2Brefuznik/video/x3ou94_priere-pour-refuznik-2-jeanluc-goda_shortfilms').split('?auth')[0] >>> get_video_url('http://www.dailymotion.com/relevance/search/priere%2Bpour%2Brefuznik/video/x3ou94_priere-pour-refuznik-2-jeanluc-goda_shortfilms').split('?auth')[0]
'http://www.dailymotion.com/cdn/FLV-320x240/video/x3ou94_priere-pour-refuznik-2-jean-luc-god_shortfilms.flv' 'http://www.dailymotion.com/cdn/FLV-320x240/video/x3ou94_priere-pour-refuznik-2-jean-luc-god_shortfilms.flv'
''' '''
data = read_url(url) data = read_url(url)
@ -19,4 +19,3 @@ def get_video_url(url):
v = unquote(v).split('@@')[0] v = unquote(v).split('@@')[0]
return v return v
return '' return ''

View file

@ -6,7 +6,7 @@ import socket
from urllib import quote from urllib import quote
from ox.cache import read_url from ox.cache import read_url
from ox import find_re, cache, strip_tags, decode_html, getTorrentInfo, int_value, normalize_newlines from ox import find_re, cache, strip_tags, decode_html, get_torrent_info, int_value, normalize_newlines
from ox.normalize import normalize_imdbid from ox.normalize import normalize_imdbid
import ox import ox
@ -85,7 +85,7 @@ def get_data(mininovaId):
if torrent['description']: if torrent['description']:
torrent['description'] = normalize_newlines(decode_html(strip_tags(torrent['description']))).strip() torrent['description'] = normalize_newlines(decode_html(strip_tags(torrent['description']))).strip()
t = read_url(torrent[u'torrent_link']) t = read_url(torrent[u'torrent_link'])
torrent[u'torrent_info'] = getTorrentInfo(t) torrent[u'torrent_info'] = get_torrent_info(t)
return torrent return torrent
class Mininova(Torrent): class Mininova(Torrent):

View file

@ -5,7 +5,7 @@ import re
import feedparser import feedparser
from ox.cache import read_url from ox.cache import read_url
from ox import find_re, strip_tags from ox import find_re, strip_tags
from ox import langCode2To3, langTo3Code from ox.iso import langCode2To3, langTo3Code
def find_subtitles(imdb, parts = 1, language = "eng"): def find_subtitles(imdb, parts = 1, language = "eng"):
if len(language) == 2: if len(language) == 2:

View file

@ -6,7 +6,7 @@ import socket
from urllib import quote, urlencode from urllib import quote, urlencode
from urllib2 import URLError from urllib2 import URLError
from ox import find_re, cache, strip_tags, decode_html, getTorrentInfo, normalize_newlines from ox import find_re, cache, strip_tags, decode_html, get_torrent_info, normalize_newlines
from ox.normalize import normalize_imdbid from ox.normalize import normalize_imdbid
import ox import ox
@ -94,8 +94,8 @@ def get_data(piratebayId):
torrent[u'description'] = find_re(data, '<div class="nfo">(.*?)</div>') torrent[u'description'] = find_re(data, '<div class="nfo">(.*?)</div>')
if torrent[u'description']: if torrent[u'description']:
torrent['description'] = normalize_newlines(decode_html(strip_tags(torrent['description']))).strip() torrent['description'] = normalize_newlines(decode_html(strip_tags(torrent['description']))).strip()
t = _read_url(torrent[u'torrent_link']) t = read_url(torrent[u'torrent_link'])
torrent[u'torrent_info'] = getTorrentInfo(t) torrent[u'torrent_info'] = get_torrent_info(t)
return torrent return torrent
class Thepiratebay(Torrent): class Thepiratebay(Torrent):