File: simpledb.py

package info (click to toggle)
python-scrapy 0.8-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,904 kB
  • ctags: 2,981
  • sloc: python: 15,349; xml: 199; makefile: 68; sql: 64; sh: 34
file content (19 lines) | stat: -rw-r--r-- 547 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Helper functions for Amazon SimpleDB"""

from datetime import datetime

def to_sdb_value(obj):
    """Convert the given object to proper value to store in Amazon SimpleDB"""
    if isinstance(obj, bool):
        return u'%d' % obj
    elif isinstance(obj, (int, long)):
        return "%016d" % obj
    elif isinstance(obj, datetime):
        return obj.isoformat()
    elif isinstance(obj, basestring):
        return obj
    elif obj is None:
        return u''
    else:
        raise TypeError("Unsupported Type: %s" % type(obj).__name__)