Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

formating

  • Loading branch information...
commit 99deea5f0a8ef1848c31526b47a10fe0ec21a823 1 parent 863c1d4
Jacques Uber authored July 24, 2013
60  invtool/search_dispatch.py
... ...
@@ -1,4 +1,5 @@
1 1
 import requests
  2
+import sys
2 3
 
3 4
 try:
4 5
     import simplejson as json
@@ -25,14 +26,15 @@ def build_parser(self, base_parser):
25 26
         )
26 27
 
27 28
         search.add_argument(
28  
-            '--range', '-r', dest='irange', type=str, help="Get information and "
29  
-            "statistics about an IP range. Specify the range using: "
30  
-            "<ip-start>,<ip-end> format (no spaces)", default=None, required=False
  29
+            '--range', '-r', dest='irange', type=str, help="Get information "
  30
+            "and statistics about an IP range. Specify the range using: "
  31
+            "<ip-start>,<ip-end> format (no spaces)", default=None,
  32
+            required=False
31 33
         )
32 34
 
33 35
         search.add_argument(
34  
-            '--display-integers', dest='d_integers', help="Return integers when "
35  
-            "showing free ip ranges.", action='store_true', default=False,
  36
+            '--display-integers', dest='d_integers', help="Return integers "
  37
+            "when showing free ip ranges.", action='store_true', default=False,
36 38
             required=False
37 39
         )
38 40
 
@@ -57,15 +59,16 @@ def irange(self, nas):
57 59
         search = {'start': start, 'end': end}
58 60
         if nas.d_integers:
59 61
             search['format'] = 'integers'
60  
-        resp = requests.get(url, params=search, headers=headers,
61  
-                            auth=auth())
62  
-        if resp.status_code == 500:
63  
-            resp_list = [
64  
-                "CLIENT ERROR! (Please email this output to a code monkey)"
65  
-            ]
66  
-            self.error_out(nas, search, resp, resp_list=resp_list)
67  
-            return
68  
-        results = self.get_resp_dict(resp)
  62
+        resp = requests.get(url, params=search, headers=headers, auth=auth)
  63
+        if nas.DEBUG:
  64
+            sys.stderr.write('method: {0}\nurl: {1}\nparams:{2}\n'.format(
  65
+                'get', url, search
  66
+            ))
  67
+        was_json = nas.p_json
  68
+        nas.p_json = True  # Do this so we can play with the response
  69
+        ret_code, raw_results = self.handle_resp(nas, search, resp)
  70
+        if ret_code:
  71
+            return (ret_code, raw_results)  # repack and go home
69 72
 
70 73
         def display_ranges(free_ranges):
71 74
             ret_list = []
@@ -73,11 +76,12 @@ def display_ranges(free_ranges):
73 76
                 ret_list.append("{0} to {1}".format(fstart, fend))
74 77
             return ret_list
75 78
 
  79
+        results = json.loads(raw_results[0], 'unicode')
76 80
         if not results:
77 81
             return 1, []
78 82
         else:
79  
-            if nas.p_json:
80  
-                return 0, [json.dumps(results, indent=2)]
  83
+            if was_json:
  84
+                return 0, raw_results
81 85
             resp_list = ["# of Used IPs: {0}".format(results['used']),
82 86
                          "# of Unused IPs: {0}".format(results['unused']),
83 87
                          "------ Vacant IP ranges ------"]
@@ -89,20 +93,22 @@ def query(self, nas):
89 93
         url = "{0}{1}".format(REMOTE, tmp_url)
90 94
         headers = {'content-type': 'application/json'}
91 95
         search = {'search': nas.query}
92  
-        resp = requests.get(url, params=search, headers=headers,
93  
-                            auth=auth())
94  
-        if resp.status_code == 500:
95  
-            resp_list = [
96  
-                "CLIENT ERROR! (Please email this output to a code monkey)"
97  
-            ]
98  
-            self.error_out(nas, search, resp, resp_list=resp_list)
99  
-            return
100  
-        results = self.get_resp_dict(resp)
  96
+        resp = requests.get(url, params=search, headers=headers, auth=auth)
  97
+        if nas.DEBUG:
  98
+            sys.stderr.write('method: {0}\nurl: {1}\nparams:{2}\n'.format(
  99
+                'get', url, search
  100
+            ))
  101
+        was_json = nas.p_json
  102
+        nas.p_json = True  # Do this so we can play with the response
  103
+        ret_code, raw_results = self.handle_resp(nas, search, resp)
  104
+        if ret_code:
  105
+            return (ret_code, raw_results)  # repack and go home
  106
+        results = json.loads(raw_results[0], 'unicode')
101 107
         if 'text_response' not in results:
102 108
             return 1, []
103 109
         else:
104  
-            if nas.p_json:
105  
-                return 0, [json.dumps(results, indent=2)]
  110
+            if was_json:
  111
+                return 0, raw_results
106 112
             return 0, [results['text_response']]
107 113
 
108 114
 
1  invtool/tests/kv_tests.py
@@ -23,6 +23,7 @@ class _TestCase(unittest.TestCase):
23 23
 
24 24
         def place_holder(self):
25 25
             # This should create an object that we can use to associate KV's to
  26
+            print "testing {0} ...".format(dispatch.dtype)
26 27
             obj_pk = dispatch.do_test_setup(self)
27 28
 
28 29
             # List the object's KV store and remember the count

0 notes on commit 99deea5

Please sign in to comment.
Something went wrong with that request. Please try again.