Permalink
Browse files

Break up RESTful PUT code from set() for independent use.

  • Loading branch information...
Toru Maesaka
Toru Maesaka committed May 3, 2011
1 parent 7d2b251 commit f822949618932d97ebf6acd043de97bd5b5d273b
Showing with 18 additions and 10 deletions.
  1. +12 −10 kyototycoon/kt_http.py
  2. +6 −0 kyototycoon/kyototycoon.py
View
@@ -60,21 +60,12 @@ def get(self, key):
def set(self, key, value, expire):
if key is None: return False
- headers = {}
- if expire != None:
- expire = int(time.time()) + expire;
- headers["X-Kt-Xt"] = str(expire)
-
if not isinstance(value, str):
value = str(value)
key = urllib.quote(key.encode('UTF-8'))
value = value.encode('UTF-8')
-
- self.conn.request('PUT', key, value, headers)
- rv = self.conn.getresponse()
- body = rv.read()
- return rv.status == 201;
+ return self._rest_put(key, value, expire) == 201
def add(self, key, value, expire):
if key is None: return False
@@ -199,6 +190,17 @@ def _tsv_to_dict(self, tsv_str):
rv[kv[0]] = kv[1]
return rv
+ def _rest_put(self, key, value, expire):
+ headers = {}
+ if expire != None:
+ expire = int(time.time()) + expire;
+ headers["X-Kt-Xt"] = str(expire)
+
+ self.conn.request('PUT', key, value, headers)
+ rv = self.conn.getresponse()
+ body = rv.read()
+ return rv.status
+
# TODO (tmaesaka): Allow using callbacks for these.
def _pack_data(self, data):
return pickle.dumps(data, self.pickle_protocol)
@@ -63,3 +63,9 @@ def remove(self, key):
def get(self, key):
return self.core.get(key)
+
+ def set_int(self, key, value, expire=None):
+ pass
+
+ def get_int(self, key):
+ pass

0 comments on commit f822949

Please sign in to comment.