~ubuntu-branches/ubuntu/raring/python-boto/raring-proposed

« back to all changes in this revision

Viewing changes to boto/sdb/db/blob.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Moser
  • Date: 2010-01-05 15:12:37 UTC
  • mfrom: (4.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100105151237-skgxjkyogir1vl0k
Tags: 1.9b-1ubuntu1
* merge Loic's changes made in 1.8d-1ubuntu2
* Rename Vcs-* to XS-Debian-Vcs-*.
* Run testsuite during build but ignore failures since it currently doesn't
  pass.
* Add ${misc:Depends}.
* Add XB-Python-Version: ${python:Versions}.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
20
# IN THE SOFTWARE.
21
21
 
 
22
 
22
23
class Blob(object):
23
 
    """
24
 
    Blob object
25
 
    """
 
24
    """Blob object"""
26
25
    def __init__(self, value=None, file=None, id=None):
27
 
        self.file = file
 
26
        self._file = file
28
27
        self.id = id
29
28
        self.value = value
30
29
 
 
30
    @property
 
31
    def file(self):
 
32
        from StringIO import StringIO
 
33
        if self._file:
 
34
            f = self._file
 
35
        else:
 
36
            f = StringIO(self.value)
 
37
        return f
 
38
 
31
39
    def __str__(self):
32
 
        return str(self.read())
 
40
        if hasattr(self.file, "get_contents_as_string"):
 
41
            return str(self.file.get_contents_as_string())
 
42
        else:
 
43
            return str(self.file.getvalue())
33
44
 
34
45
    def read(self):
35
 
        if not self.value:
36
 
            self.value = self.file.read()
37
 
        return self.value
 
46
        return self.file.read()
 
47
 
 
48
    def readline(self):
 
49
        return self.file.readline()
 
50
 
 
51
    def next(self):
 
52
        return sefl.file.next()
 
53
 
 
54
    def __iter__(self):
 
55
        return iter(self.file)
 
56
 
 
57
    @property
 
58
    def size(self):
 
59
        if self._file:
 
60
            return self._file.size
 
61
        elif self.value:
 
62
            return len(self.value)
 
63
        else:
 
64
            return 0