Ejemplo n.º 1
0
 def rest(self,
          method,
          uri,
          data=None,
          status_codes=None,
          parse=True,
          **kwargs):
     """ Rest helpers
 """
     r = self.pool.request_encode_body(method,
                                       uri,
                                       fields=data,
                                       encode_multipart=False)
     if not r.status in (status_codes if status_codes else (200, 201)):
         print cl('\n---------\nURI / REQUEST TYPE : %s %s' % (uri, method),
                  'red')
         print cl(data, 'red')
         print r.headers
         raise Exception, "Invalid status code: %s" % r.status
     if not parse:
         " return raw urllib3 response"
         return r
     if not self.debug_loads:
         " return parsed edn"
         return loads(r.data)
     "time edn parse time and return parsed edn"
     return self.debug(loads,
                       args=(r_data, ),
                       kwargs={},
                       fmt='<<< parsed edn datastruct in {ms}ms',
                       color='green')
Ejemplo n.º 2
0
def loadedn(f):
    """ this function tries to load something as edn: file, filename, string """
    if isinstance(f, basestring):
        try:
            f = open(f)
        except IOError as e:
            return clj.loads(f)
    return clj.load(f)
Ejemplo n.º 3
0
def loadedn(f):
    """ this function tries to load something as edn: file, filename, string """
    if isinstance(f, basestring):
        try:
            f = open(f)
        except IOError as e:
            return clj.loads(f)
    return clj.load(f)
Ejemplo n.º 4
0
 def rest(self, method, uri, data=None, status_codes=None, parse=True, **kwargs):
   """ Rest helpers
   """
   r = self.pool.request_encode_body(method, uri, fields=data, encode_multipart=False)
   if not r.status in (status_codes if status_codes else (200,201)):
     print cl('\n---------\nURI / REQUEST TYPE : %s %s' % (uri, method), 'red')
     print cl(data, 'red')
     print r.headers
     raise Exception, "Invalid status code: %s" % r.status
   if not parse: 
     " return raw urllib3 response"
     return r
   if not self.debug_loads:
     " return parsed edn"
     return loads(r.data)
   "time edn parse time and return parsed edn"
   return self.debug(loads, args=(r_data, ), kwargs={},
         fmt='<<< parsed edn datastruct in {ms}ms', color='green')
Ejemplo n.º 5
0
Archivo: edn.py Proyecto: DanSeraf/spyd
 def unpack(data):
     return clj.loads(data)
Ejemplo n.º 6
0
 def test_all_data(self):
     for k,v in self.data.items():
         self.assertEqual(clj.loads(k), v)
Ejemplo n.º 7
0
#! /usr/bin/env python

import clj
import time

s = "[1 2 3 true false nil {:a 21.3 :b 43.2} \"Hello\"]"

t1 = time.time()
for i in range(10000):
  clj.loads(s)

print time.time()-t1