Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
version 0.5.2 bump with nt bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ergoithz committed Feb 28, 2017
1 parent 901e4c7 commit 2862926
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ browsepy

.. image:: http://img.shields.io/pypi/v/browsepy.svg?style=flat-square
:target: https://pypi.python.org/pypi/browsepy/
:alt: Version: 0.5.1
:alt: Version: 0.5.2

.. image:: https://img.shields.io/badge/python-2.7%2B%2C%203.3%2B-FFC100.svg?style=flat-square
:target: https://pypi.python.org/pypi/browsepy/
Expand Down
2 changes: 1 addition & 1 deletion browsepy/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# -*- coding: UTF-8 -*-

__app__ = "browsepy"
__version__ = "0.5.1"
__version__ = "0.5.2"
__license__ = 'MIT'
__author__ = "Felipe A. Hernandez <[email protected]>"
5 changes: 2 additions & 3 deletions browsepy/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,18 +599,17 @@ def choose_filename(self, filename, attempts=999):
new_filename = alternative_filename(filename)
return new_filename

def _listdir(self):
def _listdir(self, precomputed_stats=os.name == 'nt'):
'''
Iter unsorted entries on this directory.
:yields: Directory or File instance for each entry in directory
:ytype: Node
'''
precomputed_stats = os.name == 'nt'
for entry in compat.scandir(self.path):
kwargs = {'path': entry.path, 'app': self.app, 'parent': self}
if precomputed_stats and not entry.is_symlink():
kwargs['stats'] = entry.stats()
kwargs['stats'] = entry.stat()
if entry.is_dir(follow_symlinks=True):
yield self.directory_class(**kwargs)
continue
Expand Down
46 changes: 43 additions & 3 deletions browsepy/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,16 +675,56 @@ def tearDown(self):
shutil.rmtree(self.workbench)
test_utils.clear_flask_context()

def textfile(self, name, text):
tmp_txt = os.path.join(self.workbench, name)
with open(tmp_txt, 'w') as f:
f.write(text)
return tmp_txt

def test_iter_listdir(self):
directory = self.module.Directory(path=self.workbench, app=self.app)

tmp_txt = self.textfile('somefile.txt', 'a')

content = list(directory._listdir(precomputed_stats=True))
self.assertEqual(len(content), 1)
self.assertEqual(content[0].size, '1 B')
self.assertEqual(content[0].path, tmp_txt)

content = list(directory._listdir(precomputed_stats=False))
self.assertEqual(len(content), 1)
self.assertEqual(content[0].size, '1 B')
self.assertEqual(content[0].path, tmp_txt)

def test_check_forbidden_filename(self):
cff = self.module.check_forbidden_filename
self.assertFalse(cff('myfilename', destiny_os='posix'))
self.assertTrue(cff('.', destiny_os='posix'))
self.assertTrue(cff('..', destiny_os='posix'))
self.assertTrue(cff('::', destiny_os='posix'))
self.assertTrue(cff('/', destiny_os='posix'))
self.assertTrue(cff('com1', destiny_os='nt'))
self.assertTrue(cff('LPT2', destiny_os='nt'))
self.assertTrue(cff('nul', destiny_os='nt'))
self.assertFalse(cff('com1', destiny_os='posix'))

def test_secure_filename(self):
sf = self.module.secure_filename
self.assertEqual(sf('a/a'), 'a')
self.assertEqual(sf('//'), '')
self.assertEqual(sf('c:\\', destiny_os='nt'), '')
self.assertEqual(sf('c:\\COM1', destiny_os='nt'), '')
self.assertEqual(sf('COM1', destiny_os='nt'), '')
self.assertEqual(sf('COM1', destiny_os='posix'), 'COM1')

def test_mime(self):
f = self.module.File('non_working_path', app=self.app)
self.assertEqual(f.mimetype, 'application/octet-stream')

f = self.module.File('non_working_path_with_ext.txt', app=self.app)
self.assertEqual(f.mimetype, 'text/plain')

tmp_txt = os.path.join(self.workbench, 'ascii_text_file')
with open(tmp_txt, 'w') as f:
f.write('ascii text')
tmp_txt = self.textfile('ascii_text_file', 'ascii text')

# test file command
f = self.module.File(tmp_txt, app=self.app)
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
# The short X.Y version.
version = '0.5'
# The full version, including alpha/beta/rc tags.
release = '0.5.1'
release = '0.5.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
name=meta_app,
version=meta_version,
url='https://github.com/ergoithz/browsepy',
download_url='https://github.com/ergoithz/browsepy/archive/0.5.1.tar.gz',
download_url='https://github.com/ergoithz/browsepy/archive/0.5.2.tar.gz',
license=meta_license,
author='Felipe A. Hernandez',
author_email='[email protected]',
Expand Down

0 comments on commit 2862926

Please sign in to comment.