forked from SpiderOak/ZipStream
-
Notifications
You must be signed in to change notification settings - Fork 33
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
12 changed files
with
734 additions
and
429 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 |
---|---|---|
|
@@ -34,3 +34,5 @@ nosetests.xml | |
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
*.zip |
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,10 @@ | ||
language: python | ||
python: | ||
- "2.6" | ||
- "2.7" | ||
- "3.2" | ||
- "3.3" | ||
- "pypy" | ||
install: | ||
- "pip install ." | ||
script: nosetests |
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
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,25 @@ | ||
import os | ||
import zipstream | ||
import zipfile | ||
|
||
|
||
f = open('test.zip', 'wb') | ||
|
||
with zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) as z: | ||
z.write('LICENSE') | ||
z.write('LICENSE', arcname='stuff/LICENSE') | ||
|
||
for root, directories, files in os.walk('zipstream'): | ||
for filename in files: | ||
path = os.path.join(root, filename) | ||
z.write(path, path) | ||
|
||
with open('test.zip', 'wb') as f: | ||
for chunk in z: | ||
f.write(chunk) | ||
|
||
f.close() | ||
|
||
|
||
with zipfile.ZipFile('test.zip') as z: | ||
z.testzip() |
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 |
---|---|---|
@@ -1,13 +1,18 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
from setuptools import setup, find_packages | ||
import zipstream | ||
|
||
from distutils.core import setup | ||
|
||
setup( | ||
name='zipstream', | ||
version='1.0.1', | ||
description='SpiderOak ZipStream Module', | ||
author='SpiderOak Team', | ||
author_email='[email protected]', | ||
url='http://www.spideroak.com', | ||
py_modules=['zipstream'], | ||
version=zipstream.__version__, | ||
description='Zipfile generator', | ||
author='Allan Lei', | ||
author_email='[email protected]', | ||
url='https://github.com/allanlei/python-zipstream', | ||
packages=find_packages(), | ||
keywords='zip streaming', | ||
|
||
test_suite='nose.collector', | ||
tests_require = ['nose'], | ||
) |
Empty file.
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,80 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import unittest | ||
import zipstream | ||
|
||
|
||
class PointerIOTestCase(unittest.TestCase): | ||
def test_init_no_args(self): | ||
zipstream.PointerIO() | ||
|
||
def test_init_mode(self): | ||
try: | ||
zipstream.PointerIO('wb') | ||
except Exception as err: | ||
self.fail(err) | ||
|
||
for mode in ['w', 'r', 'rb', 'a', 'ab']: | ||
self.assertRaises(Exception, zipstream.PointerIO, mode=mode) | ||
|
||
for mode in ['w', 'wb''r', 'rb', 'a', 'ab']: | ||
self.assertRaises(Exception, zipstream.PointerIO, mode=mode + '+') | ||
|
||
def test_has_fileobj_attrs(self): | ||
fileobj = zipstream.PointerIO() | ||
|
||
self.assertTrue(hasattr(fileobj, 'write')) | ||
self.assertTrue(hasattr(fileobj, 'close')) | ||
self.assertTrue(hasattr(fileobj, 'tell')) | ||
|
||
def test_write_bytes(self): | ||
fileobj = zipstream.PointerIO() | ||
data = b'Im a little tea pot' | ||
try: | ||
fileobj.write(data) | ||
except Exception as err: | ||
self.fail(err) | ||
self.assertEqual(fileobj.tell(), 19) | ||
|
||
def test_write_unicode(self): | ||
fileobj = zipstream.PointerIO() | ||
data = 'Im a little tea pot' | ||
try: | ||
fileobj.write(data) | ||
except Exception as err: | ||
self.fail(err) | ||
self.assertEqual(fileobj.tell(), 19) | ||
|
||
|
||
fileobj = zipstream.PointerIO() | ||
data = '幋 儳鑤 寱懤擨 拻敁柧' | ||
try: | ||
fileobj.write(data) | ||
except Exception as err: | ||
self.fail(err) | ||
self.assertEqual(fileobj.tell(), 30) | ||
|
||
def test_write_non_string_type(self): | ||
fileobj = zipstream.PointerIO() | ||
data = None | ||
self.assertRaises(TypeError, fileobj.write, data) | ||
|
||
fileobj = zipstream.PointerIO() | ||
data = [] | ||
self.assertRaises(TypeError, fileobj.write, data) | ||
|
||
fileobj = zipstream.PointerIO() | ||
data = tuple() | ||
self.assertRaises(TypeError, fileobj.write, data) | ||
|
||
fileobj = zipstream.PointerIO() | ||
data = 1 | ||
self.assertRaises(TypeError, fileobj.write, data) | ||
|
||
fileobj = zipstream.PointerIO() | ||
data = 1.00 | ||
self.assertRaises(TypeError, fileobj.write, data) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,59 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals, print_function | ||
|
||
import os | ||
import tempfile | ||
import unittest | ||
import zipstream | ||
import zipfile | ||
|
||
|
||
class ZipInfoTestCase(unittest.TestCase): | ||
pass | ||
|
||
|
||
class ZipStreamTestCase(unittest.TestCase): | ||
def setUp(self): | ||
self.fileobjs = [ | ||
tempfile.NamedTemporaryFile(delete=False, suffix='.txt'), | ||
tempfile.NamedTemporaryFile(delete=False, suffix='.py'), | ||
] | ||
|
||
def tearDown(self): | ||
for fileobj in self.fileobjs: | ||
fileobj.close() | ||
os.remove(fileobj.name) | ||
|
||
def test_init_no_args(self): | ||
zipstream.ZipFile() | ||
|
||
def test_init_mode(self): | ||
try: | ||
zipstream.ZipFile(mode='w') | ||
except Exception as err: | ||
self.fail(err) | ||
|
||
for mode in ['wb', 'r', 'rb', 'a', 'ab']: | ||
self.assertRaises(Exception, zipstream.ZipFile, mode=mode) | ||
|
||
for mode in ['wb', 'r', 'rb', 'a', 'ab']: | ||
self.assertRaises(Exception, zipstream.ZipFile, mode=mode + '+') | ||
|
||
def test_write_file(self): | ||
z = zipstream.ZipFile(mode='w') | ||
for fileobj in self.fileobjs: | ||
z.write(fileobj.name) | ||
|
||
f = tempfile.NamedTemporaryFile(suffix='zip', delete=False) | ||
for chunk in z: | ||
f.write(chunk) | ||
f.close() | ||
|
||
z2 = zipfile.ZipFile(f.name, 'r') | ||
z2.testzip() | ||
|
||
os.remove(f.name) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,6 @@ | ||
[tox] | ||
envlist = py26, py27, py32, py33, pypy | ||
|
||
[testenv] | ||
deps=nose | ||
commands = nosetests {posargs} |
Oops, something went wrong.
The documentation mentions the ZipStream class everywhere (without import). But I cannot find this class anywhere in the project. Should ZipStream be replaced with zipstream.ZipFile?