You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by hw...@apache.org on 2010/08/04 17:31:14 UTC

svn commit: r982301 - in /labs/mouse: guesser/binary.py mouse.py sources.py

Author: hwright
Date: Wed Aug  4 15:31:14 2010
New Revision: 982301

URL: http://svn.apache.org/viewvc?rev=982301&view=rev
Log:
When requesting file contents from an Item, return them as a file-like object.
This allows us to use this object as input other methods which expect file-like
objects.

Modified:
    labs/mouse/guesser/binary.py
    labs/mouse/mouse.py
    labs/mouse/sources.py

Modified: labs/mouse/guesser/binary.py
URL: http://svn.apache.org/viewvc/labs/mouse/guesser/binary.py?rev=982301&r1=982300&r2=982301&view=diff
==============================================================================
--- labs/mouse/guesser/binary.py (original)
+++ labs/mouse/guesser/binary.py Wed Aug  4 15:31:14 2010
@@ -74,12 +74,13 @@ def is_binary(item):
 
   # Time to attempt a brute-force divination
   high_bytes = 0
-  for c in item.get_content()[0:100]:
+  content = item.get_content().read(100)
+  for c in content:
     if ord(c) > _non_ascii_threshold or ord(c) <= _ascii_char_threshold:
       high_bytes += 1
 
   if (high_bytes * _high_bytes_ratio) > \
-            (min(100, len(item.get_content())) * _total_read_ratio):
+            (min(100, len(content)) * _total_read_ratio):
     return True
 
   # we've exhausted our options, so this file must not be binary

Modified: labs/mouse/mouse.py
URL: http://svn.apache.org/viewvc/labs/mouse/mouse.py?rev=982301&r1=982300&r2=982301&view=diff
==============================================================================
--- labs/mouse/mouse.py (original)
+++ labs/mouse/mouse.py Wed Aug  4 15:31:14 2010
@@ -60,7 +60,7 @@ class Resource(object):
 
     if hasattr(self._result, 'include_sample') and self._result.include_sample:
       child = ElementTree.SubElement(elem, 'header-sample')
-      child.text = self._item.get_content()
+      child.text = self._item.get_content().read()
 
     if hasattr(self._result, 'header_name') and self._result.header_name:
       child = ElementTree.SubElement(elem, 'header-type')

Modified: labs/mouse/sources.py
URL: http://svn.apache.org/viewvc/labs/mouse/sources.py?rev=982301&r1=982300&r2=982301&view=diff
==============================================================================
--- labs/mouse/sources.py (original)
+++ labs/mouse/sources.py Wed Aug  4 15:31:14 2010
@@ -31,6 +31,8 @@ import os
 import tarfile
 import zipfile
 
+import cStringIO as StringIO
+
 
 class _UnknownArchiveError(Exception):
   '''An exception to communicate we've discovered a type of archive we can't
@@ -58,7 +60,7 @@ class Item(object):
     '''Return the contents of this item.'''
     if not self._content:
       self._content = self.file.read()
-    return self._content
+    return StringIO.StringIO(self._content)
 
 
 def _get_dir_gen(target):



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org