Commits

Simon Cross  committed b4862ec

Add .get/set_encoders/decoders and set client._solr in __init__.

  • Participants
  • Parent commits b92904e

Comments (0)

Files changed (1)

File txriak/client.py

         self._r = r_value
         self._w = w_value
         self._dw = dw_value
+        self._encoders = {'application/json': json.dumps,
+                          'text/json': json.dumps}
+        self._decoders = {'application/json': json.loads,
+                          'text/json': json.loads}
+        self._solr = None
 
     def get_r(self):
         """
         self._client_id = client_id
         return self
 
+    def get_encoder(self, content_type):
+        """
+        Get the encoding function for the provided content type.
+        """
+        if content_type in self._encoders:
+            return self._encoders[content_type]
+
+    def set_encoder(self, content_type, encoder):
+        """
+        Set the encoding function for the provided content type.
+
+        :param encoder:
+        :type encoder: function
+        """
+        self._encoders[content_type] = encoder
+        return self
+
+    def get_decoder(self, content_type):
+        """
+        Get the decoding function for the provided content type.
+        """
+        if content_type in self._decoders:
+            return self._decoders[content_type]
+
+    def set_decoder(self, content_type, decoder):
+        """
+        Set the decoding function for the provided content type.
+
+        :param decoder:
+        :type decoder: function
+        """
+        self._decoders[content_type] = decoder
+        return self
+
     def bucket(self, name):
         """
         Get the bucket by the specified name. Since buckets always exist,