From 221c3725f109ed5a6126c1f406cda68f55d95894 Mon Sep 17 00:00:00 2001 From: "willmcgugan@gmail.com" Date: Thu, 13 Mar 2014 18:47:17 +0000 Subject: Test fixes and preparations for 0.5.0 release git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@887 67cdc799-7952-0410-af00-57a81ceafa0f --- fs/appdirfs.py | 1 + fs/commands/runner.py | 16 ++++++++++------ fs/expose/xmlrpc.py | 12 ++++++++++++ fs/iotools.py | 2 -- fs/memoryfs.py | 29 ++++++++++++++--------------- fs/rpcfs.py | 3 ++- fs/tests/__init__.py | 4 ++-- 7 files changed, 41 insertions(+), 26 deletions(-) (limited to 'fs') diff --git a/fs/appdirfs.py b/fs/appdirfs.py index ff7dd69..86d8082 100644 --- a/fs/appdirfs.py +++ b/fs/appdirfs.py @@ -21,6 +21,7 @@ __all__ = ['UserDataFS', 'UserCacheFS', 'UserLogFS'] + class UserDataFS(OSFS): """A filesystem for per-user application data.""" def __init__(self, appname, appauthor=None, version=None, roaming=False, create=True): diff --git a/fs/commands/runner.py b/fs/commands/runner.py index c5c7e6f..57d6e99 100644 --- a/fs/commands/runner.py +++ b/fs/commands/runner.py @@ -1,17 +1,19 @@ import warnings warnings.filterwarnings("ignore") -import sys -from optparse import OptionParser from fs.opener import opener, OpenerError, Opener from fs.errors import FSError from fs.path import splitext, pathsplit, isdotfile, iswildcard + +import re +import sys import platform -from collections import defaultdict import six +from optparse import OptionParser +from collections import defaultdict -if platform.system() == 'Windows': +if platform.system() == 'Windows': def getTerminalSize(): try: ## {{{ http://code.activestate.com/recipes/440694/ (r3) @@ -32,13 +34,12 @@ if platform.system() == 'Windows': sizex = right - left + 1 sizey = bottom - top + 1 else: - sizex, sizey = 80, 25 # can't determine actual size - return default values + sizex, sizey = 80, 25 # can't determine actual size - return default values return sizex, sizey except: return 80, 25 else: - def getTerminalSize(): def ioctl_GWINSZ(fd): try: @@ -65,11 +66,13 @@ else: pass return 80, 25 + def _unicode(text): if not isinstance(text, unicode): return text.decode('ascii', 'replace') return text + class Command(object): usage = '' @@ -146,6 +149,7 @@ class Command(object): if not self.terminal_colors: return text re_fs = r'(\S*?://\S*)' + def repl(matchobj): fs_url = matchobj.group(0) return self.wrap_link(fs_url) diff --git a/fs/expose/xmlrpc.py b/fs/expose/xmlrpc.py index 4a29564..fd78a32 100644 --- a/fs/expose/xmlrpc.py +++ b/fs/expose/xmlrpc.py @@ -31,6 +31,16 @@ class RPCFSInterface(object): the contents of files. """ + # info keys are restricted to a subset known to work over xmlrpc + # This fixes an issue with transporting Longs on Py3 + _allowed_info = ["size", + "created_time", + "modified_time", + "accessed_time", + "st_size", + "st_mode", + "type"] + def __init__(self, fs): super(RPCFSInterface, self).__init__() self.fs = fs @@ -118,6 +128,8 @@ class RPCFSInterface(object): def getinfo(self, path): path = self.decode_path(path) info = self.fs.getinfo(path) + info = dict((k, v) for k, v in info.iteritems() + if k in self._allowed_info) return info def desc(self, path): diff --git a/fs/iotools.py b/fs/iotools.py index fcf4818..f2e0f6e 100644 --- a/fs/iotools.py +++ b/fs/iotools.py @@ -188,8 +188,6 @@ def make_bytes_io(data, encoding=None, errors=None): return io.BytesIO(data) - - def copy_file_to_fs(f, fs, path, encoding=None, errors=None, progress_callback=None, chunk_size=64 * 1024): """Copy an open file to a path on an FS""" if progress_callback is None: diff --git a/fs/memoryfs.py b/fs/memoryfs.py index d48cf9f..9a87db3 100644 --- a/fs/memoryfs.py +++ b/fs/memoryfs.py @@ -31,6 +31,7 @@ def _check_mode(mode, mode_chars): return False return True + class MemoryFile(object): def seek_and_lock(f): @@ -71,7 +72,6 @@ class MemoryFile(object): finally: lock.release() - assert self.mem_file is not None, "self.mem_file should have a value" def __str__(self): @@ -163,7 +163,7 @@ class MemoryFile(object): def __enter__(self): return self - def __exit__(self,exc_type,exc_value,traceback): + def __exit__(self, exc_type, exc_value, traceback): self.close() return False @@ -218,7 +218,7 @@ class DirEntry(object): if self.isfile(): return "" % self.name elif self.isdir(): - return "" % "".join( "%s: %s" % (k, v.desc_contents()) for k, v in self.contents.iteritems()) + return "" % "".join("%s: %s" % (k, v.desc_contents()) for k, v in self.contents.iteritems()) def isdir(self): return self.type == "dir" @@ -248,24 +248,23 @@ class DirEntry(object): self.mem_file = StringIO() self.mem_file.write(data) -class MemoryFS(FS): +class MemoryFS(FS): """An in-memory filesystem. """ - _meta = {'thread_safe' : True, - 'network' : False, + _meta = {'thread_safe': True, + 'network': False, 'virtual': False, - 'read_only' : False, - 'unicode_paths' : True, - 'case_insensitive_paths' : False, - 'atomic.move' : False, - 'atomic.copy' : False, - 'atomic.makedir' : True, - 'atomic.rename' : True, - 'atomic.setcontents' : False, - } + 'read_only': False, + 'unicode_paths': True, + 'case_insensitive_paths': False, + 'atomic.move': False, + 'atomic.copy': False, + 'atomic.makedir': True, + 'atomic.rename': True, + 'atomic.setcontents': False} def _make_dir_entry(self, *args, **kwargs): return self.dir_entry_factory(*args, **kwargs) diff --git a/fs/rpcfs.py b/fs/rpcfs.py index eecdbf0..00ba86a 100644 --- a/fs/rpcfs.py +++ b/fs/rpcfs.py @@ -305,7 +305,8 @@ class RPCFS(FS): @synchronize def getinfo(self, path): path = self.encode_path(path) - return self.proxy.getinfo(path) + info = self.proxy.getinfo(path) + return info @synchronize def desc(self, path): diff --git a/fs/tests/__init__.py b/fs/tests/__init__.py index d99c1b1..3aa8ec8 100644 --- a/fs/tests/__init__.py +++ b/fs/tests/__init__.py @@ -163,8 +163,8 @@ class FSTestCases(object): b("to you, good sir!")), chunk_size=2) self.assertEquals(self.fs.getcontents( "hello", "rb"), b("to you, good sir!")) - self.fs.setcontents("hello", b"") - self.assertEquals(self.fs.getcontents("hello", "rb"), "") + self.fs.setcontents("hello", b("")) + self.assertEquals(self.fs.getcontents("hello", "rb"), b("")) def test_setcontents_async(self): # setcontents() should accept both a string... -- cgit v1.2.1