~thenewme91/microfiber/lp823288

« back to all changes in this revision

Viewing changes to microfiber.py

  • Committer: Jason Gerard DeRose
  • Date: 2011-04-06 10:03:37 UTC
  • Revision ID: jderose@novacut.com-20110406100337-f6tr9riycbczq6ry
Reworked CouchBase.json() so it works with pre-encoded JSON str and bytes

Show diffs side-by-side

added added

removed removed

Lines of Context:
430
430
        Make a PUT or POST request with a JSON body.
431
431
        """
432
432
        url = self.path(*parts, **options)
433
 
        body = (None if obj is None else dumps(obj))
434
 
        headers = {'Content-Type': 'application/json'}
435
 
        return self.request(method, url, body, headers)
 
433
        if isinstance(obj, dict):
 
434
            obj = dumps(obj)
 
435
        elif isinstance(obj, str):
 
436
            obj = obj.encode('utf-8')
 
437
        return self.request(method, url, obj,
 
438
            {'Content-Type': 'application/json'}
 
439
        )
436
440
 
437
441
    def post(self, obj, *parts, **options):
438
442
        """