Update unrar2 from 0.99.3 to 0.99.6

This commit is contained in:
Alexandre Beloin 2015-01-21 21:15:23 -05:00
parent 91cb8d885c
commit d2f49a0759
22 changed files with 1571 additions and 1479 deletions

View File

@ -2,3 +2,6 @@ f2570b5f7205f1433661a9508f464f691cf63389 0.97
d3595b2c9a1aec510f8ae1dcfef1eb8562a77fc0 0.99.1
d23822f936c663784c5edda09cd5a6effe1e882d 0.99.2
855a137f51581bd6d7a79264856020aa52fd0b66 0.99.3
160655e623388d65c35ac4c8e271b58566e8a489 0.99.4
8225eb999c02735d0aead538870c91270d41df0c 0.99.5
734f8f605597616bc102b60ca1e959d3a0ace5b6 0.99.6

View File

@ -1,27 +0,0 @@
Metadata-Version: 1.1
Name: pyUnRAR2
Version: 0.99.3
Summary: Improved Python wrapper around the free UnRAR.dll
Home-page: http://code.google.com/py-unrar2
Author: Konstantin Yegupov
Author-email: yk4ever@gmail.com
License: MIT
Description: pyUnRAR2 is a ctypes based wrapper around the free UnRAR.dll.
It is an modified version of Jimmy Retzlaff's pyUnRAR - more simple,
stable and foolproof.
Notice that it has INCOMPATIBLE interface.
It enables reading and unpacking of archives created with the
RAR/WinRAR archivers. There is a low-level interface which is very
similar to the C interface provided by UnRAR. There is also a
higher level interface which makes some common operations easier.
Platform: Windows
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Win32 (MS Windows)
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Archiving :: Compression

View File

@ -1,14 +1,15 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: package UnRAR2</title>
<meta charset="utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>UnRAR2</strong></big></big> (version 0.99.2)</font></td
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>UnRAR2</strong></big></big> (version 0.99.5)</font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/rainman/dev/py-unrar2/UnRAR2/__init__.py">/home/rainman/dev/py-unrar2/UnRAR2/__init__.py</a></font></td></tr></table>
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:///Z:/py-unrar2/unrar2/__init__.py">z:\py-unrar2\unrar2\__init__.py</a></font></td></tr></table>
<p><tt>pyUnRAR2&nbsp;is&nbsp;a&nbsp;ctypes&nbsp;based&nbsp;wrapper&nbsp;around&nbsp;the&nbsp;free&nbsp;UnRAR.dll.&nbsp;<br>
&nbsp;<br>
It&nbsp;is&nbsp;an&nbsp;modified&nbsp;version&nbsp;of&nbsp;Jimmy&nbsp;Retzlaff's&nbsp;pyUnRAR&nbsp;-&nbsp;more&nbsp;simple,<br>
@ -40,7 +41,7 @@ higher&nbsp;level&nbsp;interface&nbsp;which&nbsp;makes&nbsp;some&nbsp;common&nbs
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="UnRAR2.unix.html#RarFileImplementation">UnRAR2.unix.RarFileImplementation</a>(<a href="__builtin__.html#object">__builtin__.object</a>)
<dt><font face="helvetica, arial"><a href="UnRAR2.windows.html#RarFileImplementation">UnRAR2.windows.RarFileImplementation</a>(<a href="__builtin__.html#object">__builtin__.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="UnRAR2.html#RarFile">RarFile</a>
@ -57,12 +58,12 @@ higher&nbsp;level&nbsp;interface&nbsp;which&nbsp;makes&nbsp;some&nbsp;common&nbs
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="RarFile">class <strong>RarFile</strong></a>(<a href="UnRAR2.unix.html#RarFileImplementation">UnRAR2.unix.RarFileImplementation</a>)</font></td></tr>
<font color="#000000" face="helvetica, arial"><a name="RarFile">class <strong>RarFile</strong></a>(<a href="UnRAR2.windows.html#RarFileImplementation">UnRAR2.windows.RarFileImplementation</a>)</font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="UnRAR2.html#RarFile">RarFile</a></dd>
<dd><a href="UnRAR2.unix.html#RarFileImplementation">UnRAR2.unix.RarFileImplementation</a></dd>
<dd><a href="UnRAR2.windows.html#RarFileImplementation">UnRAR2.windows.RarFileImplementation</a></dd>
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
</dl>
<hr>
@ -96,6 +97,9 @@ If&nbsp;"condition"&nbsp;is&nbsp;omitted,&nbsp;all&nbsp;files&nbsp;are&nbsp;extr
&nbsp;<br>
Returns&nbsp;list&nbsp;of&nbsp;RarInfos&nbsp;for&nbsp;extracted&nbsp;files.</tt></dd></dl>
<dl><dt><a name="RarFile-get_volume"><strong>get_volume</strong></a>(self)</dt><dd><tt>Determine&nbsp;which&nbsp;volume&nbsp;is&nbsp;it&nbsp;in&nbsp;a&nbsp;multi-volume&nbsp;archive.&nbsp;Returns&nbsp;None&nbsp;if&nbsp;it's&nbsp;not&nbsp;a&nbsp;<br>
multi-volume&nbsp;archive,&nbsp;0-based&nbsp;volume&nbsp;number&nbsp;otherwise.</tt></dd></dl>
<dl><dt><a name="RarFile-infoiter"><strong>infoiter</strong></a>(self)</dt><dd><tt>Iterate&nbsp;over&nbsp;all&nbsp;the&nbsp;files&nbsp;in&nbsp;the&nbsp;archive,&nbsp;generating&nbsp;RarInfos.<br>
&nbsp;<br>
&gt;&gt;&gt;&nbsp;import&nbsp;os<br>
@ -122,17 +126,15 @@ If&nbsp;"condition"&nbsp;is&nbsp;omitted,&nbsp;all&nbsp;files&nbsp;are&nbsp;retu
Returns&nbsp;list&nbsp;of&nbsp;tuples&nbsp;(<a href="#RarInfo">RarInfo</a>&nbsp;info,&nbsp;str&nbsp;contents)</tt></dd></dl>
<hr>
Methods inherited from <a href="UnRAR2.unix.html#RarFileImplementation">UnRAR2.unix.RarFileImplementation</a>:<br>
<dl><dt><a name="RarFile-call"><strong>call</strong></a>(self, cmd, options<font color="#909090">=[]</font>, files<font color="#909090">=[]</font>)</dt></dl>
Methods inherited from <a href="UnRAR2.windows.html#RarFileImplementation">UnRAR2.windows.RarFileImplementation</a>:<br>
<dl><dt><a name="RarFile-destruct"><strong>destruct</strong></a>(self)</dt></dl>
<dl><dt><a name="RarFile-escaped_password"><strong>escaped_password</strong></a>(self)</dt></dl>
<dl><dt><a name="RarFile-init"><strong>init</strong></a>(self, password<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="RarFile-make_sure_ready"><strong>make_sure_ready</strong></a>(self)</dt></dl>
<hr>
Data descriptors inherited from <a href="UnRAR2.unix.html#RarFileImplementation">UnRAR2.unix.RarFileImplementation</a>:<br>
Data descriptors inherited from <a href="UnRAR2.windows.html#RarFileImplementation">UnRAR2.windows.RarFileImplementation</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
@ -189,6 +191,6 @@ Data descriptors defined here:<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>__version__</strong> = '0.99.2'<br>
<strong>in_windows</strong> = False</td></tr></table>
<td width="100%"><strong>__version__</strong> = '0.99.5'<br>
<strong>in_windows</strong> = True</td></tr></table>
</body></html>

BIN
lib/unrar2/[test].rar Normal file

Binary file not shown.

2
lib/unrar2/[test].txt Normal file
View File

@ -0,0 +1,2 @@
test
test

View File

@ -33,7 +33,7 @@ similar to the C interface provided by UnRAR. There is also a
higher level interface which makes some common operations easier.
"""
__version__ = '0.99.3'
__version__ = '0.99.6'
try:
WindowsError
@ -75,8 +75,6 @@ class RarInfo(object):
self.datetime = data['datetime']
self.comment = data['comment']
def __str__(self):
try :
arcName = self.rarfile.archiveName
@ -159,6 +157,11 @@ class RarFile(RarFileImplementation):
checker = condition2checker(condition)
return RarFileImplementation.extract(self, checker, path, withSubpath, overwrite)
def get_volume(self):
"""Determine which volume is it in a multi-volume archive. Returns None if it's not a
multi-volume archive, 0-based volume number otherwise."""
return RarFileImplementation.get_volume(self)
def condition2checker(condition):
"""Converts different condition types to callback"""
if type(condition) in [str, unicode]:

View File

@ -1,7 +1,10 @@
import os, sys
import os,sys,inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)
import UnRAR2
from UnRAR2.rar_exceptions import *
import unrar2 as UnRAR2
from unrar2.rar_exceptions import *
def cleanup(dir='test'):
@ -15,6 +18,7 @@ def cleanup(dir='test'):
# basic test
cleanup()
rarc = UnRAR2.RarFile('test.rar')
assert rarc.get_volume() == None
rarc.infolist()
assert rarc.comment == "This is a test."
for info in rarc.infoiter():
@ -28,6 +32,21 @@ del rarc
assert (str(saveinfo)=="""<RarInfo "test" in "[ARCHIVE_NO_LONGER_LOADED]">""")
cleanup()
# shell-unsafe-name test
cleanup()
rarc = UnRAR2.RarFile('[test].rar')
rarc.infolist()
for info in rarc.infoiter():
saveinfo = info
assert (str(info)=="""<RarInfo "[test].txt" in "[test].rar">""")
break
rarc.extract()
assert os.path.exists('[test].txt')
del rarc
assert (str(saveinfo)=="""<RarInfo "[test].txt" in "[ARCHIVE_NO_LONGER_LOADED]">""")
cleanup()
# extract all the files in test.rar
cleanup()
UnRAR2.RarFile('test.rar').extract()
@ -108,6 +127,15 @@ except IncorrectRARPassword:
assert not os.path.exists('test'+os.sep+'top_secret_xxx_file.txt')
assert errored
cleanup()
errored = False
try:
UnRAR2.RarFile('test_protected_files.rar').extract()
except IncorrectRARPassword:
errored = True
assert not os.path.exists('test'+os.sep+'top_secret_xxx_file.txt')
assert errored
cleanup()
# extract files from an archive with protected headers
cleanup()
@ -122,6 +150,27 @@ except IncorrectRARPassword:
assert not os.path.exists('test'+os.sep+'top_secret_xxx_file.txt')
assert errored
cleanup()
errored = False
try:
UnRAR2.RarFile('test_protected_headers.rar').extract()
except IncorrectRARPassword:
errored = True
assert not os.path.exists('test'+os.sep+'top_secret_xxx_file.txt')
assert errored
cleanup()
# check volume number
cleanup()
rarc1 = UnRAR2.RarFile('test_volumes.part1.rar')
assert rarc1.get_volume() == 0
rarc2 = UnRAR2.RarFile('test_volumes.part2.rar')
assert rarc2.get_volume() == 1
cleanup()
rarc1 = UnRAR2.RarFile('test_volumes_old.rar')
assert rarc1.get_volume() == 0
rarc2 = UnRAR2.RarFile('test_volumes_old.r00')
assert rarc2.get_volume() == 1
cleanup()
# make sure docstring examples are working
import doctest

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -74,13 +74,13 @@ class RarFileImplementation(object):
accum = []
source = iter(stdoutdata.splitlines())
line = ''
while not (line.startswith('UNRAR')):
while (line.find('RAR ') == -1):
line = source.next()
signature = line
# The code below is mighty flaky
# and will probably crash on localized versions of RAR
# but I see no safe way to rewrite it using a CLI tool
if signature.startswith("UNRAR 4"):
if signature.find("RAR 4") > -1:
rar_executable_version = 4
while not (line.startswith('Comment:') or line.startswith('Pathname/Comment')):
if line.strip().endswith('is not RAR archive'):
@ -94,7 +94,7 @@ class RarFileImplementation(object):
self.comment = '\n'.join(accum[:-1])
else:
self.comment = None
elif signature.startswith("UNRAR 5"):
elif signature.find("RAR 5") > -1:
rar_executable_version = 5
line = source.next()
while not line.startswith('Archive:'):
@ -155,6 +155,7 @@ class RarFileImplementation(object):
data['isdir'] = 'd' in attr.lower()
data['datetime'] = time.strptime(fields[3]+" "+fields[4], '%d-%m-%y %H:%M')
data['comment'] = None
data['volume'] = None
yield data
accum = []
i += 1
@ -170,6 +171,7 @@ class RarFileImplementation(object):
data['isdir'] = 'd' in attr.lower()
data['datetime'] = time.strptime(fields[2]+" "+fields[3], '%d-%m-%y %H:%M')
data['comment'] = None
data['volume'] = None
yield data
i += 1
line = source.next()
@ -215,4 +217,41 @@ class RarFileImplementation(object):
def destruct(self):
pass
def get_volume(self):
command = "v" if rar_executable_version == 4 else "l"
stdoutdata, stderrdata = self.call(command, ['c-']).communicate()
for line in stderrdata.splitlines():
if line.strip().startswith("Cannot open"):
raise FileOpenError
source = iter(stdoutdata.splitlines())
line = ''
while not line.startswith('-----------'):
if line.strip().endswith('is not RAR archive'):
raise InvalidRARArchive
if line.startswith("CRC failed") or line.startswith("Checksum error"):
raise IncorrectRARPassword
line = source.next()
line = source.next()
if rar_executable_version == 4:
while not line.startswith('-----------'):
line = source.next()
line = source.next()
items = line.strip().split()
if len(items)>4 and items[4]=="volume":
return int(items[5]) - 1
else:
return None
elif rar_executable_version == 5:
while not line.startswith('-----------'):
line = source.next()
line = source.next()
items = line.strip().split()
if items[1]=="volume":
return int(items[2]) - 1
else:
return None

View File

@ -25,7 +25,7 @@
from __future__ import generators
import ctypes, ctypes.wintypes
import os, os.path, sys
import os, os.path, sys, re
import Queue
import time
@ -43,6 +43,7 @@ ERAR_EREAD = 18
ERAR_EWRITE = 19
ERAR_SMALL_BUF = 20
ERAR_UNKNOWN = 21
ERAR_MISSING_PASSWORD = 22
RAR_OM_LIST = 0
RAR_OM_EXTRACT = 1
@ -66,6 +67,9 @@ dll_name = "unrar.dll"
if architecture_bits == 64:
dll_name = "x64\\unrar64.dll"
volume_naming1 = re.compile("\.r([0-9]{2})$")
volume_naming2 = re.compile("\.([0-9]{3}).rar$")
volume_naming3 = re.compile("\.part([0-9]+).rar$")
try:
unrar = ctypes.WinDLL(os.path.join(os.path.split(__file__)[0], 'UnRARDLL', dll_name))
@ -188,7 +192,7 @@ class RarInfoIterator(object):
self.index = 0
self.headerData = RARHeaderDataEx()
self.res = RARReadHeaderEx(self.arc._handle, ctypes.byref(self.headerData))
if self.res==ERAR_BAD_DATA:
if self.res in [ERAR_BAD_DATA, ERAR_MISSING_PASSWORD]:
raise IncorrectRARPassword
self.arc.lockStatus = "locked"
self.arc.needskip = False
@ -208,7 +212,7 @@ class RarInfoIterator(object):
data = {}
data['index'] = self.index
data['filename'] = self.headerData.FileName
data['filename'] = self.headerData.FileNameW
data['datetime'] = DosDateTimeToTimeTuple(self.headerData.FileTime)
data['isdir'] = ((self.headerData.Flags & 0xE0) == 0xE0)
data['size'] = self.headerData.UnpSize + (self.headerData.UnpSizeHigh << 32)
@ -252,6 +256,7 @@ class RarFileImplementation(object):
self.lockStatus = "ready"
self.isVolume = archiveData.Flags & 1
def destruct(self):
@ -277,7 +282,7 @@ class RarFileImplementation(object):
c_callback = UNRARCALLBACK(reader._callback)
RARSetCallback(self._handle, c_callback, 1)
tmpres = RARProcessFile(self._handle, RAR_TEST, None, None)
if tmpres==ERAR_BAD_DATA:
if tmpres in [ERAR_BAD_DATA, ERAR_MISSING_PASSWORD]:
raise IncorrectRARPassword
self.needskip = False
res.append((info, reader.get_result()))
@ -299,11 +304,29 @@ class RarFileImplementation(object):
target = checkres
if overwrite or (not os.path.exists(target)):
tmpres = RARProcessFile(self._handle, RAR_EXTRACT, None, target)
if tmpres==ERAR_BAD_DATA:
if tmpres in [ERAR_BAD_DATA, ERAR_MISSING_PASSWORD]:
raise IncorrectRARPassword
self.needskip = False
res.append(info)
return res
def get_volume(self):
if not self.isVolume:
return None
headerData = RARHeaderDataEx()
res = RARReadHeaderEx(self._handle, ctypes.byref(headerData))
arcName = headerData.ArcNameW
match3 = volume_naming3.search(arcName)
if match3 != None:
return int(match3.group(1)) - 1
match2 = volume_naming3.search(arcName)
if match2 != None:
return int(match2.group(1))
match1 = volume_naming1.search(arcName)
if match1 != None:
return int(match1.group(1)) + 1
return 0

View File

@ -1,19 +1,19 @@
# Author: Mr_Orange <mr_orange@hotmail.it>
#
# This file is part of SickRage.
# This file is part of SickGear.
#
# SickRage is free software: you can redistribute it and/or modify
# SickGear is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SickRage is distributed in the hope that it will be useful,
# SickGear is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
import re
import datetime
@ -35,6 +35,11 @@ from sickbeard.helpers import sanitizeSceneName
class TorrentDayProvider(generic.TorrentProvider):
urls = {'base_url': 'https://torrentday.eu',
'login': 'https://torrentday.eu/torrents/',
'search': 'https://torrentday.eu/V3/API/API.php',
'download': 'https://torrentday.eu/download.php/%s/%s'
}
def __init__(self):
@ -54,12 +59,6 @@ class TorrentDayProvider(generic.TorrentProvider):
self.cache = TorrentDayCache(self)
self.urls = {'base_url': 'http://www.td.af',
'login': 'http://www.td.af/torrents/',
'search': 'http://www.td.af/V3/API/API.php',
'download': 'http://www.td.af/download.php/%s/%s'
}
self.url = self.urls['base_url']
self.cookies = None
@ -84,7 +83,9 @@ class TorrentDayProvider(generic.TorrentProvider):
return True
if self._uid and self._hash:
requests.utils.add_dict_to_cookiejar(self.session.cookies, self.cookies)
else:
login_params = {'username': self.username,
@ -93,9 +94,6 @@ class TorrentDayProvider(generic.TorrentProvider):
'submit.y': 0
}
if not self.session:
self.session = requests.Session()
try:
response = self.session.post(self.urls['login'], data=login_params, timeout=30, verify=False)
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
@ -110,7 +108,6 @@ class TorrentDayProvider(generic.TorrentProvider):
logger.log(u'Invalid username or password for ' + self.name + ', Check your settings!', logger.ERROR)
return False
try:
if requests.utils.dict_from_cookiejar(self.session.cookies)['uid'] and requests.utils.dict_from_cookiejar(self.session.cookies)['pass']:
self._uid = requests.utils.dict_from_cookiejar(self.session.cookies)['uid']
self._hash = requests.utils.dict_from_cookiejar(self.session.cookies)['pass']
@ -119,9 +116,8 @@ class TorrentDayProvider(generic.TorrentProvider):
'pass': self._hash
}
return True
except:
pass
else:
logger.log(u'Unable to obtain cookie for TorrentDay', logger.ERROR)
return False
@ -169,7 +165,7 @@ class TorrentDayProvider(generic.TorrentProvider):
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name_helpers.sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': ep_obj.scene_season,
'episodenumber': ep_obj.scene_episode} + ' %s' % add_string
'episodenumber': ep_obj.scene_episode}
search_string['Episode'].append(re.sub('\s+', ' ', ep_string))
@ -183,7 +179,7 @@ class TorrentDayProvider(generic.TorrentProvider):
freeleech = '&free=on' if self.freeleech else ''
if not self._doLogin():
return results
return []
for mode in search_params.keys():
for search_string in search_params[mode]:
@ -283,6 +279,8 @@ class TorrentDayCache(tvcache.TVCache):
def _getRSSData(self):
search_params = {'RSS': ['']}
return {'entries': self.provider._doSearch(search_params)}
return self.provider._doSearch(search_params)
provider = TorrentDayProvider()