Merge lp:~thisfred/u1db/deprecate-simplejson into lp:u1db
- deprecate-simplejson
- Merge into trunk
Proposed by
Eric Casteleijn
on 2012-08-14
| Status: | Merged |
|---|---|
| Approved by: | Eric Casteleijn on 2012-08-14 |
| Approved revision: | 376 |
| Merged at revision: | 377 |
| Proposed branch: | lp:~thisfred/u1db/deprecate-simplejson |
| Merge into: | lp:u1db |
| Diff against target: |
1267 lines (+219/-167) 18 files modified
setup.py (+3/-4) u1db/__init__.py (+29/-28) u1db/backends/__init__.py (+6/-3) u1db/backends/inmemory.py (+5/-2) u1db/backends/sqlite_backend.py (+6/-3) u1db/commandline/client.py (+10/-8) u1db/remote/http_app.py (+10/-7) u1db/remote/http_client.py (+8/-5) u1db/remote/http_database.py (+6/-3) u1db/remote/http_target.py (+8/-5) u1db/remote/oauth_middleware.py (+5/-3) u1db/tests/commandline/test_client.py (+22/-14) u1db/tests/test_backends.py (+10/-10) u1db/tests/test_c_backend.py (+14/-7) u1db/tests/test_http_app.py (+40/-38) u1db/tests/test_http_client.py (+20/-19) u1db/tests/test_http_database.py (+5/-2) u1db/tests/test_oauth_middleware.py (+12/-6) |
| To merge this branch: | bzr merge lp:~thisfred/u1db/deprecate-simplejson |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Roberto Alsina (community) | 2012-08-14 | Approve on 2012-08-14 | |
|
Review via email:
|
|||
Commit Message
Removed simplejson as a hard dependency. It will still be used if present.
Description of the Change
Removed simplejson as a hard dependency. It will still be used if present.
To post a comment you must log in.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === modified file 'setup.py' |
| 2 | --- setup.py 2012-07-03 18:15:07 +0000 |
| 3 | +++ setup.py 2012-08-14 14:33:39 +0000 |
| 4 | @@ -15,7 +15,6 @@ |
| 5 | # You should have received a copy of the GNU Lesser General Public License |
| 6 | # along with u1db. If not, see <http://www.gnu.org/licenses/>. |
| 7 | |
| 8 | -import os |
| 9 | import sys |
| 10 | |
| 11 | |
| 12 | @@ -23,7 +22,7 @@ |
| 13 | try: |
| 14 | from setuptools import setup, Extension, find_packages |
| 15 | except ImportError: |
| 16 | - from distutils.core import setup, Extension, find_packages |
| 17 | + from distutils.core import setup, Extension, find_packages # noqa |
| 18 | import u1db |
| 19 | ext = [] |
| 20 | kwargs = { |
| 21 | @@ -40,7 +39,7 @@ |
| 22 | "package_data": {'': ["*.sql"]}, |
| 23 | "scripts": ['u1db-client', 'u1db-serve'], |
| 24 | "ext_modules": ext, |
| 25 | - "install_requires": ["dirspec", "paste", "simplejson", "routes"], |
| 26 | + "install_requires": ["dirspec", "paste", "routes"], |
| 27 | # informational |
| 28 | "tests_require": ["testtools", "testscenarios", "Cython", |
| 29 | "pyOpenSSL"], |
| 30 | @@ -66,7 +65,7 @@ |
| 31 | } |
| 32 | try: |
| 33 | from Cython.Distutils import build_ext |
| 34 | - except ImportError, e: |
| 35 | + except ImportError: |
| 36 | print "Unable to import Cython, to test the C implementation" |
| 37 | else: |
| 38 | kwargs["cmdclass"] = {"build_ext": build_ext} |
| 39 | |
| 40 | === modified file 'u1db/__init__.py' |
| 41 | --- u1db/__init__.py 2012-08-02 13:26:05 +0000 |
| 42 | +++ u1db/__init__.py 2012-08-14 14:33:39 +0000 |
| 43 | @@ -16,7 +16,11 @@ |
| 44 | |
| 45 | """U1DB""" |
| 46 | |
| 47 | -import simplejson |
| 48 | +try: |
| 49 | + import simplejson as json |
| 50 | +except ImportError: |
| 51 | + import json # noqa |
| 52 | + |
| 53 | from u1db.errors import InvalidJSON, InvalidContent |
| 54 | |
| 55 | __version_info__ = (0, 1, 0) |
| 56 | @@ -385,31 +389,31 @@ |
| 57 | |
| 58 | :ivar doc_id: Unique identifier for this document. |
| 59 | :ivar rev: |
| 60 | - :ivar json: The JSON string for this document. |
| 61 | + :ivar json_string: The JSON string for this document. |
| 62 | :ivar has_conflicts: Boolean indicating if this document has conflicts |
| 63 | """ |
| 64 | |
| 65 | - def __init__(self, doc_id, rev, json, has_conflicts=False): |
| 66 | + def __init__(self, doc_id, rev, json_string, has_conflicts=False): |
| 67 | self.doc_id = doc_id |
| 68 | self.rev = rev |
| 69 | - if json is not None: |
| 70 | + if json_string is not None: |
| 71 | try: |
| 72 | - value = simplejson.loads(json) |
| 73 | - except simplejson.JSONDecodeError: |
| 74 | + value = json.loads(json_string) |
| 75 | + except json.JSONDecodeError: |
| 76 | raise InvalidJSON |
| 77 | if not isinstance(value, dict): |
| 78 | raise InvalidJSON |
| 79 | - self._json = json |
| 80 | + self._json = json_string |
| 81 | self.has_conflicts = has_conflicts |
| 82 | |
| 83 | def same_content_as(self, other): |
| 84 | """Compare the content of two documents.""" |
| 85 | if self._json: |
| 86 | - c1 = simplejson.loads(self._json) |
| 87 | + c1 = json.loads(self._json) |
| 88 | else: |
| 89 | c1 = None |
| 90 | if other._json: |
| 91 | - c2 = simplejson.loads(other._json) |
| 92 | + c2 = json.loads(other._json) |
| 93 | else: |
| 94 | c2 = None |
| 95 | return c1 == c2 |
| 96 | @@ -463,16 +467,16 @@ |
| 97 | size += len(self.doc_id) |
| 98 | return size |
| 99 | |
| 100 | - def set_json(self, json): |
| 101 | + def set_json(self, json_string): |
| 102 | """Set the json serialization of this document.""" |
| 103 | - if json is not None: |
| 104 | + if json_string is not None: |
| 105 | try: |
| 106 | - self._content = simplejson.loads(json) |
| 107 | - except simplejson.JSONDecodeError: |
| 108 | - raise InvalidJSON |
| 109 | - if not isinstance(self._content, dict): |
| 110 | - raise InvalidJSON |
| 111 | - self._json = json |
| 112 | + value = json.loads(json_string) |
| 113 | + except json.JSONDecodeError: |
| 114 | + raise InvalidJSON |
| 115 | + if not isinstance(value, dict): |
| 116 | + raise InvalidJSON |
| 117 | + self._json = json_string |
| 118 | |
| 119 | def make_tombstone(self): |
| 120 | """Make this document into a tombstone.""" |
| 121 | @@ -508,29 +512,26 @@ |
| 122 | def same_content_as(self, other): |
| 123 | """Compare the content of two documents.""" |
| 124 | if self._json: |
| 125 | - c1 = simplejson.loads(self._json) |
| 126 | + c1 = json.loads(self._json) |
| 127 | else: |
| 128 | c1 = self._content |
| 129 | if other._json: |
| 130 | - c2 = simplejson.loads(other._json) |
| 131 | + c2 = json.loads(other._json) |
| 132 | else: |
| 133 | c2 = other._content |
| 134 | return c1 == c2 |
| 135 | |
| 136 | def get_json(self): |
| 137 | """Get the json serialization of this document.""" |
| 138 | - json = super(Document, self).get_json() |
| 139 | - if json is not None: |
| 140 | - return json |
| 141 | + json_string = super(Document, self).get_json() |
| 142 | + if json_string is not None: |
| 143 | + return json_string |
| 144 | if self._content is not None: |
| 145 | - return simplejson.dumps(self._content) |
| 146 | + return json.dumps(self._content) |
| 147 | return None |
| 148 | |
| 149 | def set_json(self, json): |
| 150 | """Set the json serialization of this document.""" |
| 151 | - # TODO: We convert the json in the superclass to check its validity so |
| 152 | - # we might as well set _content here directly since the price is |
| 153 | - # already being paid. |
| 154 | self._content = None |
| 155 | super(Document, self).set_json(json) |
| 156 | |
| 157 | @@ -548,7 +549,7 @@ |
| 158 | def _get_content(self): |
| 159 | """Get the dictionary representing this document.""" |
| 160 | if self._json is not None: |
| 161 | - self._content = simplejson.loads(self._json) |
| 162 | + self._content = json.loads(self._json) |
| 163 | self._json = None |
| 164 | if self._content is not None: |
| 165 | return self._content |
| 166 | @@ -557,7 +558,7 @@ |
| 167 | def _set_content(self, content): |
| 168 | """Set the dictionary representing this document.""" |
| 169 | try: |
| 170 | - tmp = simplejson.dumps(content) |
| 171 | + tmp = json.dumps(content) |
| 172 | except TypeError: |
| 173 | raise InvalidContent( |
| 174 | "Can not be converted to JSON: %r" % (content,)) |
| 175 | |
| 176 | === modified file 'u1db/backends/__init__.py' |
| 177 | --- u1db/backends/__init__.py 2012-08-09 16:03:46 +0000 |
| 178 | +++ u1db/backends/__init__.py 2012-08-14 14:33:39 +0000 |
| 179 | @@ -17,7 +17,10 @@ |
| 180 | """Abstract classes and common implementations for the backends.""" |
| 181 | |
| 182 | import re |
| 183 | -import simplejson |
| 184 | +try: |
| 185 | + import simplejson as json |
| 186 | +except ImportError: |
| 187 | + import json # noqa |
| 188 | import uuid |
| 189 | |
| 190 | import u1db |
| 191 | @@ -85,10 +88,10 @@ |
| 192 | raise NotImplementedError(self._has_conflicts) |
| 193 | |
| 194 | def create_doc(self, content, doc_id=None): |
| 195 | - json = simplejson.dumps(content) |
| 196 | + json_string = json.dumps(content) |
| 197 | if doc_id is None: |
| 198 | doc_id = self._allocate_doc_id() |
| 199 | - doc = self._factory(doc_id, None, json) |
| 200 | + doc = self._factory(doc_id, None, json_string) |
| 201 | self.put_doc(doc) |
| 202 | return doc |
| 203 | |
| 204 | |
| 205 | === modified file 'u1db/backends/inmemory.py' |
| 206 | --- u1db/backends/inmemory.py 2012-08-09 22:22:58 +0000 |
| 207 | +++ u1db/backends/inmemory.py 2012-08-14 14:33:39 +0000 |
| 208 | @@ -16,7 +16,10 @@ |
| 209 | |
| 210 | """The in-memory Database class for U1DB.""" |
| 211 | |
| 212 | -import simplejson |
| 213 | +try: |
| 214 | + import simplejson as json |
| 215 | +except ImportError: |
| 216 | + import json # noqa |
| 217 | |
| 218 | from u1db import ( |
| 219 | Document, |
| 220 | @@ -324,7 +327,7 @@ |
| 221 | |
| 222 | def evaluate_json(self, doc): |
| 223 | """Determine the 'key' after applying this index to the doc.""" |
| 224 | - raw = simplejson.loads(doc) |
| 225 | + raw = json.loads(doc) |
| 226 | return self.evaluate(raw) |
| 227 | |
| 228 | def evaluate(self, obj): |
| 229 | |
| 230 | === modified file 'u1db/backends/sqlite_backend.py' |
| 231 | --- u1db/backends/sqlite_backend.py 2012-08-09 20:46:13 +0000 |
| 232 | +++ u1db/backends/sqlite_backend.py 2012-08-14 14:33:39 +0000 |
| 233 | @@ -18,7 +18,10 @@ |
| 234 | |
| 235 | import errno |
| 236 | import os |
| 237 | -import simplejson |
| 238 | +try: |
| 239 | + import simplejson as json |
| 240 | +except ImportError: |
| 241 | + import json # noqa |
| 242 | from sqlite3 import dbapi2 |
| 243 | import sys |
| 244 | import time |
| 245 | @@ -853,7 +856,7 @@ |
| 246 | def _put_and_update_indexes(self, old_doc, doc): |
| 247 | c = self._db_handle.cursor() |
| 248 | if doc and not doc.is_tombstone(): |
| 249 | - raw_doc = simplejson.loads(doc.get_json()) |
| 250 | + raw_doc = json.loads(doc.get_json()) |
| 251 | else: |
| 252 | raw_doc = {} |
| 253 | if old_doc is not None: |
| 254 | @@ -917,7 +920,7 @@ |
| 255 | for doc_id, doc in self._iter_all_docs(): |
| 256 | if doc is None: |
| 257 | continue |
| 258 | - raw_doc = simplejson.loads(doc) |
| 259 | + raw_doc = json.loads(doc) |
| 260 | self._update_indexes(doc_id, raw_doc, getters, c) |
| 261 | |
| 262 | SQLiteDatabase.register_implementation(SQLitePartialExpandDatabase) |
| 263 | |
| 264 | === modified file 'u1db/commandline/client.py' |
| 265 | --- u1db/commandline/client.py 2012-07-19 19:50:58 +0000 |
| 266 | +++ u1db/commandline/client.py 2012-08-14 14:33:39 +0000 |
| 267 | @@ -18,7 +18,10 @@ |
| 268 | |
| 269 | import argparse |
| 270 | import os |
| 271 | -import simplejson |
| 272 | +try: |
| 273 | + import simplejson as json |
| 274 | +except ImportError: |
| 275 | + import json # noqa |
| 276 | import sys |
| 277 | |
| 278 | from u1db import ( |
| 279 | @@ -172,9 +175,8 @@ |
| 280 | for i, doc in enumerate(conflicts): |
| 281 | if i: |
| 282 | self.stdout.write(",") |
| 283 | - self.stdout.write(simplejson.dumps(dict(rev=doc.rev, |
| 284 | - content=doc.content), |
| 285 | - indent=4)) |
| 286 | + self.stdout.write( |
| 287 | + json.dumps(dict(rev=doc.rev, content=doc.content), indent=4)) |
| 288 | self.stdout.write("]\n") |
| 289 | |
| 290 | client_commands.register(CmdGetDocConflicts) |
| 291 | @@ -480,10 +482,10 @@ |
| 292 | for i, doc in enumerate(docs): |
| 293 | if i: |
| 294 | self.stdout.write(",") |
| 295 | - self.stdout.write(simplejson.dumps(dict( |
| 296 | - id=doc.doc_id, |
| 297 | - rev=doc.rev, |
| 298 | - content=doc.content), indent=4)) |
| 299 | + self.stdout.write( |
| 300 | + json.dumps( |
| 301 | + dict(id=doc.doc_id, rev=doc.rev, content=doc.content), |
| 302 | + indent=4)) |
| 303 | self.stdout.write("]\n") |
| 304 | return |
| 305 | return 1 |
| 306 | |
| 307 | === modified file 'u1db/remote/http_app.py' |
| 308 | --- u1db/remote/http_app.py 2012-07-12 17:21:15 +0000 |
| 309 | +++ u1db/remote/http_app.py 2012-08-14 14:33:39 +0000 |
| 310 | @@ -19,7 +19,10 @@ |
| 311 | import functools |
| 312 | import httplib |
| 313 | import inspect |
| 314 | -import simplejson |
| 315 | +try: |
| 316 | + import simplejson as json |
| 317 | +except ImportError: |
| 318 | + import json # noqa |
| 319 | import sys |
| 320 | import urlparse |
| 321 | |
| 322 | @@ -121,7 +124,7 @@ |
| 323 | |
| 324 | JSON deserialize content to arguments: |
| 325 | w = http_method(content_as_args=True,...)(f) |
| 326 | - w(self, args, content) => args.update(simplejson.loads(content)); |
| 327 | + w(self, args, content) => args.update(json.loads(content)); |
| 328 | f(self, **args) |
| 329 | |
| 330 | Support conversions (e.g int): |
| 331 | @@ -154,7 +157,7 @@ |
| 332 | if content is not None: |
| 333 | if content_as_args: |
| 334 | try: |
| 335 | - args.update(simplejson.loads(content)) |
| 336 | + args.update(json.loads(content)) |
| 337 | except ValueError: |
| 338 | raise BadRequest() |
| 339 | else: |
| 340 | @@ -309,7 +312,7 @@ |
| 341 | return |
| 342 | headers = { |
| 343 | 'x-u1db-rev': doc.rev, |
| 344 | - 'x-u1db-has-conflicts': simplejson.dumps(doc.has_conflicts) |
| 345 | + 'x-u1db-has-conflicts': json.dumps(doc.has_conflicts) |
| 346 | } |
| 347 | if doc.is_tombstone(): |
| 348 | self.responder.send_response_json( |
| 349 | @@ -416,7 +419,7 @@ |
| 350 | # xxx version in headers |
| 351 | if obj_dic is not None: |
| 352 | self._no_initial_obj = False |
| 353 | - self._write(simplejson.dumps(obj_dic) + "\r\n") |
| 354 | + self._write(json.dumps(obj_dic) + "\r\n") |
| 355 | |
| 356 | def finish_response(self): |
| 357 | """finish sending response.""" |
| 358 | @@ -424,7 +427,7 @@ |
| 359 | |
| 360 | def send_response_json(self, status=200, headers={}, **kwargs): |
| 361 | """send and finish response with json object body from keyword args.""" |
| 362 | - content = simplejson.dumps(kwargs) + "\r\n" |
| 363 | + content = json.dumps(kwargs) + "\r\n" |
| 364 | self.send_response_content(content, headers=headers, status=status) |
| 365 | |
| 366 | def send_response_content(self, content, status=200, headers={}): |
| 367 | @@ -451,7 +454,7 @@ |
| 368 | self._write('\r\n') |
| 369 | else: |
| 370 | self._write(',\r\n') |
| 371 | - self._write(simplejson.dumps(entry)) |
| 372 | + self._write(json.dumps(entry)) |
| 373 | |
| 374 | def end_stream(self): |
| 375 | "end stream (array)." |
| 376 | |
| 377 | === modified file 'u1db/remote/http_client.py' |
| 378 | --- u1db/remote/http_client.py 2012-06-25 16:53:15 +0000 |
| 379 | +++ u1db/remote/http_client.py 2012-08-14 14:33:39 +0000 |
| 380 | @@ -18,7 +18,10 @@ |
| 381 | |
| 382 | import httplib |
| 383 | from oauth import oauth |
| 384 | -import simplejson |
| 385 | +try: |
| 386 | + import simplejson as json |
| 387 | +except ImportError: |
| 388 | + import json # noqa |
| 389 | import socket |
| 390 | import ssl |
| 391 | import sys |
| 392 | @@ -33,7 +36,7 @@ |
| 393 | http_errors, |
| 394 | ) |
| 395 | |
| 396 | -from u1db.remote.ssl_match_hostname import ( |
| 397 | +from u1db.remote.ssl_match_hostname import ( # noqa |
| 398 | CertificateError, |
| 399 | match_hostname, |
| 400 | ) |
| 401 | @@ -137,7 +140,7 @@ |
| 402 | return body, headers |
| 403 | elif resp.status in http_errors.ERROR_STATUSES: |
| 404 | try: |
| 405 | - respdic = simplejson.loads(body) |
| 406 | + respdic = json.loads(body) |
| 407 | except ValueError: |
| 408 | pass |
| 409 | else: |
| 410 | @@ -184,7 +187,7 @@ |
| 411 | encoded_params[key] = _encode_query_parameter(value) |
| 412 | url_query += ('?' + urllib.urlencode(encoded_params)) |
| 413 | if body is not None and not isinstance(body, basestring): |
| 414 | - body = simplejson.dumps(body) |
| 415 | + body = json.dumps(body) |
| 416 | content_type = 'application/json' |
| 417 | headers = {} |
| 418 | if content_type: |
| 419 | @@ -203,4 +206,4 @@ |
| 420 | content_type=None): |
| 421 | res, headers = self._request(method, url_parts, params, body, |
| 422 | content_type) |
| 423 | - return simplejson.loads(res), headers |
| 424 | + return json.loads(res), headers |
| 425 | |
| 426 | === modified file 'u1db/remote/http_database.py' |
| 427 | --- u1db/remote/http_database.py 2012-07-26 19:14:26 +0000 |
| 428 | +++ u1db/remote/http_database.py 2012-08-14 14:33:39 +0000 |
| 429 | @@ -16,7 +16,10 @@ |
| 430 | |
| 431 | """HTTPDatabase to access a remote db over the HTTP API.""" |
| 432 | |
| 433 | -import simplejson |
| 434 | +try: |
| 435 | + import simplejson as json |
| 436 | +except ImportError: |
| 437 | + import json # noqa |
| 438 | import uuid |
| 439 | |
| 440 | from u1db import ( |
| 441 | @@ -97,7 +100,7 @@ |
| 442 | else: |
| 443 | raise |
| 444 | doc_rev = headers['x-u1db-rev'] |
| 445 | - has_conflicts = simplejson.loads(headers['x-u1db-has-conflicts']) |
| 446 | + has_conflicts = json.loads(headers['x-u1db-has-conflicts']) |
| 447 | doc = self._factory(doc_id, doc_rev, res) |
| 448 | doc.has_conflicts = has_conflicts |
| 449 | return doc |
| 450 | @@ -111,7 +114,7 @@ |
| 451 | 'GET', ['docs'], { |
| 452 | "doc_ids": doc_ids, "include_deleted": include_deleted, |
| 453 | "check_for_conflicts": check_for_conflicts}) |
| 454 | - for doc_dict in simplejson.loads(res): |
| 455 | + for doc_dict in json.loads(res): |
| 456 | doc = self._factory( |
| 457 | doc_dict['doc_id'], doc_dict['doc_rev'], doc_dict['content']) |
| 458 | doc.has_conflicts = doc_dict['has_conflicts'] |
| 459 | |
| 460 | === modified file 'u1db/remote/http_target.py' |
| 461 | --- u1db/remote/http_target.py 2012-07-06 20:48:40 +0000 |
| 462 | +++ u1db/remote/http_target.py 2012-08-14 14:33:39 +0000 |
| 463 | @@ -16,7 +16,10 @@ |
| 464 | |
| 465 | """SyncTarget API implementation to a remote HTTP server.""" |
| 466 | |
| 467 | -import simplejson |
| 468 | +try: |
| 469 | + import simplejson as json |
| 470 | +except ImportError: |
| 471 | + import json # noqa |
| 472 | |
| 473 | from u1db import ( |
| 474 | Document, |
| 475 | @@ -59,17 +62,17 @@ |
| 476 | data = parts[1:-1] |
| 477 | if data: |
| 478 | line, comma = utils.check_and_strip_comma(data[0]) |
| 479 | - res = simplejson.loads(line) |
| 480 | + res = json.loads(line) |
| 481 | for entry in data[1:]: |
| 482 | if not comma: # missing in between comma |
| 483 | raise BrokenSyncStream |
| 484 | line, comma = utils.check_and_strip_comma(entry) |
| 485 | - entry = simplejson.loads(line) |
| 486 | + entry = json.loads(line) |
| 487 | doc = Document(entry['id'], entry['rev'], entry['content']) |
| 488 | return_doc_cb(doc, entry['gen'], entry['trans_id']) |
| 489 | if parts[-1] != ']': |
| 490 | try: |
| 491 | - partdic = simplejson.loads(parts[-1]) |
| 492 | + partdic = json.loads(parts[-1]) |
| 493 | except ValueError: |
| 494 | pass |
| 495 | else: |
| 496 | @@ -93,7 +96,7 @@ |
| 497 | size = 1 |
| 498 | |
| 499 | def prepare(**dic): |
| 500 | - entry = comma + '\r\n' + simplejson.dumps(dic) |
| 501 | + entry = comma + '\r\n' + json.dumps(dic) |
| 502 | entries.append(entry) |
| 503 | return len(entry) |
| 504 | |
| 505 | |
| 506 | === modified file 'u1db/remote/oauth_middleware.py' |
| 507 | --- u1db/remote/oauth_middleware.py 2012-04-05 13:58:46 +0000 |
| 508 | +++ u1db/remote/oauth_middleware.py 2012-08-14 14:33:39 +0000 |
| 509 | @@ -16,10 +16,12 @@ |
| 510 | """U1DB OAuth authorisation WSGI middleware.""" |
| 511 | import httplib |
| 512 | from oauth import oauth |
| 513 | -import simplejson |
| 514 | +try: |
| 515 | + import simplejson as json |
| 516 | +except ImportError: |
| 517 | + import json # noqa |
| 518 | from urllib import quote |
| 519 | from wsgiref.util import shift_path_info |
| 520 | -import sys |
| 521 | |
| 522 | |
| 523 | sign_meth_HMAC_SHA1 = oauth.OAuthSignatureMethod_HMAC_SHA1() |
| 524 | @@ -47,7 +49,7 @@ |
| 525 | err = {"error": description} |
| 526 | if message: |
| 527 | err['message'] = message |
| 528 | - return [simplejson.dumps(err)] |
| 529 | + return [json.dumps(err)] |
| 530 | |
| 531 | def __call__(self, environ, start_response): |
| 532 | if not environ['PATH_INFO'].startswith('/~/'): |
| 533 | |
| 534 | === modified file 'u1db/tests/commandline/test_client.py' |
| 535 | --- u1db/tests/commandline/test_client.py 2012-07-19 19:50:58 +0000 |
| 536 | +++ u1db/tests/commandline/test_client.py 2012-08-14 14:33:39 +0000 |
| 537 | @@ -17,7 +17,10 @@ |
| 538 | import cStringIO |
| 539 | import os |
| 540 | import sys |
| 541 | -import simplejson |
| 542 | +try: |
| 543 | + import simplejson as json |
| 544 | +except ImportError: |
| 545 | + import json # noqa |
| 546 | import subprocess |
| 547 | |
| 548 | from u1db import ( |
| 549 | @@ -253,7 +256,8 @@ |
| 550 | |
| 551 | def setUp(self): |
| 552 | super(TestCmdGet, self).setUp() |
| 553 | - self.doc = self.db.create_doc_from_json(tests.simple_doc, doc_id='my-test-doc') |
| 554 | + self.doc = self.db.create_doc_from_json( |
| 555 | + tests.simple_doc, doc_id='my-test-doc') |
| 556 | |
| 557 | def test_get_simple(self): |
| 558 | cmd = self.make_command(client.CmdGet) |
| 559 | @@ -292,7 +296,8 @@ |
| 560 | |
| 561 | def setUp(self): |
| 562 | super(TestCmdGetDocConflicts, self).setUp() |
| 563 | - self.doc1 = self.db.create_doc_from_json(tests.simple_doc, doc_id='my-doc') |
| 564 | + self.doc1 = self.db.create_doc_from_json( |
| 565 | + tests.simple_doc, doc_id='my-doc') |
| 566 | self.doc2 = self.make_document('my-doc', 'other:1', '{}', False) |
| 567 | self.db._put_doc_if_newer( |
| 568 | self.doc2, save_conflict=True, replica_uid='r', replica_gen=1, |
| 569 | @@ -302,17 +307,16 @@ |
| 570 | self.db.create_doc_from_json(tests.simple_doc, doc_id='a-doc') |
| 571 | cmd = self.make_command(client.CmdGetDocConflicts) |
| 572 | cmd.run(self.db_path, 'a-doc') |
| 573 | - self.assertEqual([], |
| 574 | - simplejson.loads(cmd.stdout.getvalue())) |
| 575 | + self.assertEqual([], json.loads(cmd.stdout.getvalue())) |
| 576 | self.assertEqual('', cmd.stderr.getvalue()) |
| 577 | |
| 578 | def test_get_doc_conflicts_simple(self): |
| 579 | cmd = self.make_command(client.CmdGetDocConflicts) |
| 580 | cmd.run(self.db_path, 'my-doc') |
| 581 | - self.assertEqual([dict(rev=self.doc2.rev, content=self.doc2.content), |
| 582 | - dict(rev=self.doc1.rev, content=self.doc1.content), |
| 583 | - ], |
| 584 | - simplejson.loads(cmd.stdout.getvalue())) |
| 585 | + self.assertEqual( |
| 586 | + [dict(rev=self.doc2.rev, content=self.doc2.content), |
| 587 | + dict(rev=self.doc1.rev, content=self.doc1.content)], |
| 588 | + json.loads(cmd.stdout.getvalue())) |
| 589 | self.assertEqual('', cmd.stderr.getvalue()) |
| 590 | |
| 591 | def test_get_doc_conflicts_no_db(self): |
| 592 | @@ -354,7 +358,8 @@ |
| 593 | |
| 594 | def setUp(self): |
| 595 | super(TestCmdPut, self).setUp() |
| 596 | - self.doc = self.db.create_doc_from_json(tests.simple_doc, doc_id='my-test-doc') |
| 597 | + self.doc = self.db.create_doc_from_json( |
| 598 | + tests.simple_doc, doc_id='my-test-doc') |
| 599 | |
| 600 | def test_put_simple(self): |
| 601 | cmd = self.make_command(client.CmdPut) |
| 602 | @@ -416,7 +421,8 @@ |
| 603 | |
| 604 | def setUp(self): |
| 605 | super(TestCmdResolve, self).setUp() |
| 606 | - self.doc1 = self.db.create_doc_from_json(tests.simple_doc, doc_id='my-doc') |
| 607 | + self.doc1 = self.db.create_doc_from_json( |
| 608 | + tests.simple_doc, doc_id='my-doc') |
| 609 | self.doc2 = self.make_document('my-doc', 'other:1', '{}', False) |
| 610 | self.db._put_doc_if_newer( |
| 611 | self.doc2, save_conflict=True, replica_uid='r', replica_gen=1, |
| 612 | @@ -477,8 +483,10 @@ |
| 613 | self.db2 = u1db_open(self.db2_path, create=True) |
| 614 | self.addCleanup(self.db2.close) |
| 615 | self.db2._set_replica_uid('test2') |
| 616 | - self.doc = self.db.create_doc_from_json(tests.simple_doc, doc_id='test-id') |
| 617 | - self.doc2 = self.db2.create_doc_from_json(tests.nested_doc, doc_id='my-test-id') |
| 618 | + self.doc = self.db.create_doc_from_json( |
| 619 | + tests.simple_doc, doc_id='test-id') |
| 620 | + self.doc2 = self.db2.create_doc_from_json( |
| 621 | + tests.nested_doc, doc_id='my-test-id') |
| 622 | |
| 623 | def test_sync(self): |
| 624 | cmd = self.make_command(client.CmdSync) |
| 625 | @@ -674,7 +682,7 @@ |
| 626 | cmd = self.make_command(client.CmdGetFromIndex) |
| 627 | retval = cmd.run(self.db_path, "index", ["value"]) |
| 628 | self.assertEqual(retval, None) |
| 629 | - self.assertEqual(sorted(simplejson.loads(cmd.stdout.getvalue())), |
| 630 | + self.assertEqual(sorted(json.loads(cmd.stdout.getvalue())), |
| 631 | sorted([dict(id=doc1.doc_id, |
| 632 | rev=doc1.rev, |
| 633 | content=doc1.content), |
| 634 | |
| 635 | === modified file 'u1db/tests/test_backends.py' |
| 636 | --- u1db/tests/test_backends.py 2012-08-09 22:22:58 +0000 |
| 637 | +++ u1db/tests/test_backends.py 2012-08-14 14:33:39 +0000 |
| 638 | @@ -16,7 +16,10 @@ |
| 639 | |
| 640 | """The backend class for U1DB. This deals with hiding storage details.""" |
| 641 | |
| 642 | -import simplejson |
| 643 | +try: |
| 644 | + import simplejson as json |
| 645 | +except ImportError: |
| 646 | + import json # noqa |
| 647 | from u1db import ( |
| 648 | DocumentBase, |
| 649 | errors, |
| 650 | @@ -144,12 +147,12 @@ |
| 651 | self.assertEqual(doc.rev, new_rev) |
| 652 | |
| 653 | def test_put_non_ascii_key(self): |
| 654 | - content = simplejson.dumps({u'key\xe5': u'val'}) |
| 655 | + content = json.dumps({u'key\xe5': u'val'}) |
| 656 | doc = self.db.create_doc_from_json(content, doc_id='my_doc') |
| 657 | self.assertGetDoc(self.db, 'my_doc', doc.rev, content, False) |
| 658 | |
| 659 | def test_put_non_ascii_value(self): |
| 660 | - content = simplejson.dumps({'key': u'\xe5'}) |
| 661 | + content = json.dumps({'key': u'\xe5'}) |
| 662 | doc = self.db.create_doc_from_json(content, doc_id='my_doc') |
| 663 | self.assertGetDoc(self.db, 'my_doc', doc.rev, content, False) |
| 664 | |
| 665 | @@ -1022,8 +1025,7 @@ |
| 666 | self.db.list_indexes()) |
| 667 | |
| 668 | def test_create_index_on_non_ascii_field_name(self): |
| 669 | - doc = self.db.create_doc_from_json( |
| 670 | - simplejson.dumps({u'\xe5': 'value'})) |
| 671 | + doc = self.db.create_doc_from_json(json.dumps({u'\xe5': 'value'})) |
| 672 | self.db.create_index('test-idx', u'\xe5') |
| 673 | self.assertEqual([doc], self.db.get_from_index('test-idx', 'value')) |
| 674 | |
| 675 | @@ -1038,14 +1040,12 @@ |
| 676 | self.assertEqual([doc], self.db.get_from_index('test-idx', 'value')) |
| 677 | |
| 678 | def test_wildcard_matches_unicode_value(self): |
| 679 | - doc = self.db.create_doc_from_json(simplejson.dumps( |
| 680 | - {"key": u"valu\xe5"})) |
| 681 | + doc = self.db.create_doc_from_json(json.dumps({"key": u"valu\xe5"})) |
| 682 | self.db.create_index('test-idx', 'key') |
| 683 | self.assertEqual([doc], self.db.get_from_index('test-idx', '*')) |
| 684 | |
| 685 | def test_retrieve_unicode_value_from_index(self): |
| 686 | - doc = self.db.create_doc_from_json(simplejson.dumps( |
| 687 | - {"key": u"valu\xe5"})) |
| 688 | + doc = self.db.create_doc_from_json(json.dumps({"key": u"valu\xe5"})) |
| 689 | self.db.create_index('test-idx', 'key') |
| 690 | self.assertEqual( |
| 691 | [doc], self.db.get_from_index('test-idx', u"valu\xe5")) |
| 692 | @@ -1812,7 +1812,7 @@ |
| 693 | |
| 694 | def setUp(self): |
| 695 | super(PythonBackendTests, self).setUp() |
| 696 | - self.simple_doc = simplejson.loads(simple_doc) |
| 697 | + self.simple_doc = json.loads(simple_doc) |
| 698 | |
| 699 | def test_create_doc_with_factory(self): |
| 700 | self.db.set_document_factory(TestAlternativeDocument) |
| 701 | |
| 702 | === modified file 'u1db/tests/test_c_backend.py' |
| 703 | --- u1db/tests/test_c_backend.py 2012-07-19 19:50:58 +0000 |
| 704 | +++ u1db/tests/test_c_backend.py 2012-08-14 14:33:39 +0000 |
| 705 | @@ -14,7 +14,10 @@ |
| 706 | # You should have received a copy of the GNU Lesser General Public License |
| 707 | # along with u1db. If not, see <http://www.gnu.org/licenses/>. |
| 708 | |
| 709 | -import simplejson |
| 710 | +try: |
| 711 | + import simplejson as json |
| 712 | +except ImportError: |
| 713 | + import json # noqa |
| 714 | from u1db import ( |
| 715 | Document, |
| 716 | errors, |
| 717 | @@ -114,7 +117,7 @@ |
| 718 | |
| 719 | def test_create_index_list_on_non_ascii_field_name(self): |
| 720 | self.db = c_backend_wrapper.CDatabase(':memory:') |
| 721 | - doc = self.db.create_doc_from_json(simplejson.dumps({u'\xe5': 'value'})) |
| 722 | + doc = self.db.create_doc_from_json(json.dumps({u'\xe5': 'value'})) |
| 723 | self.db.create_index_list('test-idx', [u'\xe5']) |
| 724 | self.assertEqual([doc], self.db.get_from_index('test-idx', 'value')) |
| 725 | |
| 726 | @@ -132,7 +135,7 @@ |
| 727 | |
| 728 | def test_wildcard_matches_unicode_value(self): |
| 729 | self.db = c_backend_wrapper.CDatabase(':memory:') |
| 730 | - doc = self.db.create_doc_from_json(simplejson.dumps({"key": u"valu\xe5"})) |
| 731 | + doc = self.db.create_doc_from_json(json.dumps({"key": u"valu\xe5"})) |
| 732 | self.db.create_index_list('test-idx', ['key']) |
| 733 | self.assertEqual([doc], self.db.get_from_index('test-idx', '*')) |
| 734 | |
| 735 | @@ -186,10 +189,14 @@ |
| 736 | |
| 737 | def test_get_from_index_list_multi_ordered(self): |
| 738 | self.db = c_backend_wrapper.CDatabase(':memory:') |
| 739 | - doc1 = self.db.create_doc_from_json('{"key": "value3", "key2": "value4"}') |
| 740 | - doc2 = self.db.create_doc_from_json('{"key": "value2", "key2": "value3"}') |
| 741 | - doc3 = self.db.create_doc_from_json('{"key": "value2", "key2": "value2"}') |
| 742 | - doc4 = self.db.create_doc_from_json('{"key": "value1", "key2": "value1"}') |
| 743 | + doc1 = self.db.create_doc_from_json( |
| 744 | + '{"key": "value3", "key2": "value4"}') |
| 745 | + doc2 = self.db.create_doc_from_json( |
| 746 | + '{"key": "value2", "key2": "value3"}') |
| 747 | + doc3 = self.db.create_doc_from_json( |
| 748 | + '{"key": "value2", "key2": "value2"}') |
| 749 | + doc4 = self.db.create_doc_from_json( |
| 750 | + '{"key": "value1", "key2": "value1"}') |
| 751 | self.db.create_index('test-idx', 'key', 'key2') |
| 752 | self.assertEqual( |
| 753 | [doc4, doc3, doc2, doc1], |
| 754 | |
| 755 | === modified file 'u1db/tests/test_http_app.py' |
| 756 | --- u1db/tests/test_http_app.py 2012-07-19 19:50:58 +0000 |
| 757 | +++ u1db/tests/test_http_app.py 2012-08-14 14:33:39 +0000 |
| 758 | @@ -18,7 +18,10 @@ |
| 759 | |
| 760 | import paste.fixture |
| 761 | import sys |
| 762 | -import simplejson |
| 763 | +try: |
| 764 | + import simplejson as json |
| 765 | +except ImportError: |
| 766 | + import json # noqa |
| 767 | import StringIO |
| 768 | |
| 769 | from u1db import ( |
| 770 | @@ -540,21 +543,20 @@ |
| 771 | resp = self.app.get('/') |
| 772 | self.assertEqual(200, resp.status) |
| 773 | self.assertEqual('application/json', resp.header('content-type')) |
| 774 | - self.assertEqual({"version": _u1db_version}, |
| 775 | - simplejson.loads(resp.body)) |
| 776 | + self.assertEqual({"version": _u1db_version}, json.loads(resp.body)) |
| 777 | |
| 778 | def test_create_database(self): |
| 779 | resp = self.app.put('/db1', params='{}', |
| 780 | headers={'content-type': 'application/json'}) |
| 781 | self.assertEqual(200, resp.status) |
| 782 | self.assertEqual('application/json', resp.header('content-type')) |
| 783 | - self.assertEqual({'ok': True}, simplejson.loads(resp.body)) |
| 784 | + self.assertEqual({'ok': True}, json.loads(resp.body)) |
| 785 | |
| 786 | resp = self.app.put('/db1', params='{}', |
| 787 | headers={'content-type': 'application/json'}) |
| 788 | self.assertEqual(200, resp.status) |
| 789 | self.assertEqual('application/json', resp.header('content-type')) |
| 790 | - self.assertEqual({'ok': True}, simplejson.loads(resp.body)) |
| 791 | + self.assertEqual({'ok': True}, json.loads(resp.body)) |
| 792 | |
| 793 | def test_delete_database(self): |
| 794 | resp = self.app.delete('/db0') |
| 795 | @@ -566,7 +568,7 @@ |
| 796 | resp = self.app.get('/db0') |
| 797 | self.assertEqual(200, resp.status) |
| 798 | self.assertEqual('application/json', resp.header('content-type')) |
| 799 | - self.assertEqual({}, simplejson.loads(resp.body)) |
| 800 | + self.assertEqual({}, json.loads(resp.body)) |
| 801 | |
| 802 | def test_valid_database_names(self): |
| 803 | resp = self.app.get('/a-database', expect_errors=True) |
| 804 | @@ -601,7 +603,7 @@ |
| 805 | self.assertEqual(201, resp.status) # created |
| 806 | self.assertEqual('{"x": 1}', doc.get_json()) |
| 807 | self.assertEqual('application/json', resp.header('content-type')) |
| 808 | - self.assertEqual({'rev': doc.rev}, simplejson.loads(resp.body)) |
| 809 | + self.assertEqual({'rev': doc.rev}, json.loads(resp.body)) |
| 810 | |
| 811 | def test_put_doc(self): |
| 812 | doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1') |
| 813 | @@ -612,7 +614,7 @@ |
| 814 | self.assertEqual(200, resp.status) |
| 815 | self.assertEqual('{"x": 2}', doc.get_json()) |
| 816 | self.assertEqual('application/json', resp.header('content-type')) |
| 817 | - self.assertEqual({'rev': doc.rev}, simplejson.loads(resp.body)) |
| 818 | + self.assertEqual({'rev': doc.rev}, json.loads(resp.body)) |
| 819 | |
| 820 | def test_put_doc_too_large(self): |
| 821 | self.http_app.max_request_size = 15000 |
| 822 | @@ -630,7 +632,7 @@ |
| 823 | self.assertEqual(None, doc.content) |
| 824 | self.assertEqual(200, resp.status) |
| 825 | self.assertEqual('application/json', resp.header('content-type')) |
| 826 | - self.assertEqual({'rev': doc.rev}, simplejson.loads(resp.body)) |
| 827 | + self.assertEqual({'rev': doc.rev}, json.loads(resp.body)) |
| 828 | |
| 829 | def test_get_doc(self): |
| 830 | doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1') |
| 831 | @@ -645,8 +647,8 @@ |
| 832 | resp = self.app.get('/db0/doc/not-there', expect_errors=True) |
| 833 | self.assertEqual(404, resp.status) |
| 834 | self.assertEqual('application/json', resp.header('content-type')) |
| 835 | - self.assertEqual({"error": "document does not exist"}, |
| 836 | - simplejson.loads(resp.body)) |
| 837 | + self.assertEqual( |
| 838 | + {"error": "document does not exist"}, json.loads(resp.body)) |
| 839 | self.assertEqual('', resp.header('x-u1db-rev')) |
| 840 | self.assertEqual('false', resp.header('x-u1db-has-conflicts')) |
| 841 | |
| 842 | @@ -658,7 +660,7 @@ |
| 843 | self.assertEqual('application/json', resp.header('content-type')) |
| 844 | self.assertEqual( |
| 845 | {"error": errors.DocumentDoesNotExist.wire_description}, |
| 846 | - simplejson.loads(resp.body)) |
| 847 | + json.loads(resp.body)) |
| 848 | |
| 849 | def test_get_doc_deleted_explicit_exclude(self): |
| 850 | doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1') |
| 851 | @@ -669,7 +671,7 @@ |
| 852 | self.assertEqual('application/json', resp.header('content-type')) |
| 853 | self.assertEqual( |
| 854 | {"error": errors.DocumentDoesNotExist.wire_description}, |
| 855 | - simplejson.loads(resp.body)) |
| 856 | + json.loads(resp.body)) |
| 857 | |
| 858 | def test_get_deleted_doc(self): |
| 859 | doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1') |
| 860 | @@ -679,7 +681,7 @@ |
| 861 | self.assertEqual(404, resp.status) |
| 862 | self.assertEqual('application/json', resp.header('content-type')) |
| 863 | self.assertEqual( |
| 864 | - {"error": errors.DOCUMENT_DELETED}, simplejson.loads(resp.body)) |
| 865 | + {"error": errors.DOCUMENT_DELETED}, json.loads(resp.body)) |
| 866 | self.assertEqual(doc.rev, resp.header('x-u1db-rev')) |
| 867 | self.assertEqual('false', resp.header('x-u1db-has-conflicts')) |
| 868 | |
| 869 | @@ -687,8 +689,8 @@ |
| 870 | resp = self.app.get('/not-there/doc/doc1', expect_errors=True) |
| 871 | self.assertEqual(404, resp.status) |
| 872 | self.assertEqual('application/json', resp.header('content-type')) |
| 873 | - self.assertEqual({"error": "database does not exist"}, |
| 874 | - simplejson.loads(resp.body)) |
| 875 | + self.assertEqual( |
| 876 | + {"error": "database does not exist"}, json.loads(resp.body)) |
| 877 | |
| 878 | def test_get_docs(self): |
| 879 | doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1') |
| 880 | @@ -703,7 +705,7 @@ |
| 881 | "has_conflicts": False}, |
| 882 | {"content": '{"x": 1}', "doc_rev": "db0:1", "doc_id": "doc2", |
| 883 | "has_conflicts": False}] |
| 884 | - self.assertEqual(expected, simplejson.loads(resp.body)) |
| 885 | + self.assertEqual(expected, json.loads(resp.body)) |
| 886 | |
| 887 | def test_get_docs_percent(self): |
| 888 | doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc%1') |
| 889 | @@ -718,7 +720,7 @@ |
| 890 | "has_conflicts": False}, |
| 891 | {"content": '{"x": 1}', "doc_rev": "db0:1", "doc_id": "doc2", |
| 892 | "has_conflicts": False}] |
| 893 | - self.assertEqual(expected, simplejson.loads(resp.body)) |
| 894 | + self.assertEqual(expected, json.loads(resp.body)) |
| 895 | |
| 896 | def test_get_docs_deleted(self): |
| 897 | doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1') |
| 898 | @@ -732,7 +734,7 @@ |
| 899 | expected = [ |
| 900 | {"content": '{"x": 1}', "doc_rev": "db0:1", "doc_id": "doc1", |
| 901 | "has_conflicts": False}] |
| 902 | - self.assertEqual(expected, simplejson.loads(resp.body)) |
| 903 | + self.assertEqual(expected, json.loads(resp.body)) |
| 904 | |
| 905 | def test_get_docs_include_deleted(self): |
| 906 | doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1') |
| 907 | @@ -748,7 +750,7 @@ |
| 908 | "has_conflicts": False}, |
| 909 | {"content": None, "doc_rev": "db0:2", "doc_id": "doc2", |
| 910 | "has_conflicts": False}] |
| 911 | - self.assertEqual(expected, simplejson.loads(resp.body)) |
| 912 | + self.assertEqual(expected, json.loads(resp.body)) |
| 913 | |
| 914 | def test_get_sync_info(self): |
| 915 | self.db0._set_replica_gen_and_trans_id('other-id', 1, 'T-transid') |
| 916 | @@ -761,7 +763,7 @@ |
| 917 | source_replica_uid='other-id', |
| 918 | source_replica_generation=1, |
| 919 | source_transaction_id='T-transid'), |
| 920 | - simplejson.loads(resp.body)) |
| 921 | + json.loads(resp.body)) |
| 922 | |
| 923 | def test_record_sync_info(self): |
| 924 | resp = self.app.put('/db0/sync-from/other-id', |
| 925 | @@ -769,7 +771,7 @@ |
| 926 | headers={'content-type': 'application/json'}) |
| 927 | self.assertEqual(200, resp.status) |
| 928 | self.assertEqual('application/json', resp.header('content-type')) |
| 929 | - self.assertEqual({'ok': True}, simplejson.loads(resp.body)) |
| 930 | + self.assertEqual({'ok': True}, json.loads(resp.body)) |
| 931 | self.assertEqual( |
| 932 | (2, 'T-transid'), |
| 933 | self.db0._get_replica_gen_and_trans_id('other-id')) |
| 934 | @@ -800,9 +802,9 @@ |
| 935 | |
| 936 | args = dict(last_known_generation=0) |
| 937 | body = ("[\r\n" + |
| 938 | - "%s,\r\n" % simplejson.dumps(args) + |
| 939 | - "%s,\r\n" % simplejson.dumps(entries[10]) + |
| 940 | - "%s\r\n" % simplejson.dumps(entries[11]) + |
| 941 | + "%s,\r\n" % json.dumps(args) + |
| 942 | + "%s,\r\n" % json.dumps(entries[10]) + |
| 943 | + "%s\r\n" % json.dumps(entries[11]) + |
| 944 | "]\r\n") |
| 945 | resp = self.app.post('/db0/sync-from/replica', |
| 946 | params=body, |
| 947 | @@ -816,7 +818,7 @@ |
| 948 | last_trans_id = self.db0._get_transaction_log()[-1][1] |
| 949 | self.assertEqual({'new_generation': 2, |
| 950 | 'new_transaction_id': last_trans_id}, |
| 951 | - simplejson.loads(bits[1])) |
| 952 | + json.loads(bits[1])) |
| 953 | self.assertEqual(']', bits[2]) |
| 954 | self.assertEqual('', bits[3]) |
| 955 | self.assertEqual([('replica', 10), ('replica', 11)], gens) |
| 956 | @@ -830,8 +832,8 @@ |
| 957 | } |
| 958 | args = dict(last_known_generation=0) |
| 959 | body = ("[\r\n" + |
| 960 | - "%s,\r\n" % simplejson.dumps(args) + |
| 961 | - "%s\r\n" % simplejson.dumps(entries[10]) + |
| 962 | + "%s,\r\n" % json.dumps(args) + |
| 963 | + "%s\r\n" % json.dumps(entries[10]) + |
| 964 | "]\r\n") |
| 965 | resp = self.app.post('/db0/sync-from/replica', |
| 966 | params=body, |
| 967 | @@ -844,7 +846,7 @@ |
| 968 | doc = self.db0.create_doc_from_json('{"value": "there"}') |
| 969 | doc2 = self.db0.create_doc_from_json('{"value": "there2"}') |
| 970 | args = dict(last_known_generation=0) |
| 971 | - body = "[\r\n%s\r\n]" % simplejson.dumps(args) |
| 972 | + body = "[\r\n%s\r\n]" % json.dumps(args) |
| 973 | resp = self.app.post('/db0/sync-from/replica', |
| 974 | params=body, |
| 975 | headers={'content-type': |
| 976 | @@ -858,14 +860,14 @@ |
| 977 | last_trans_id = self.db0._get_transaction_log()[-1][1] |
| 978 | self.assertEqual({'new_generation': 2, |
| 979 | 'new_transaction_id': last_trans_id}, |
| 980 | - simplejson.loads(parts[1].rstrip(","))) |
| 981 | - part2 = simplejson.loads(parts[2].rstrip(",")) |
| 982 | + json.loads(parts[1].rstrip(","))) |
| 983 | + part2 = json.loads(parts[2].rstrip(",")) |
| 984 | self.assertTrue(part2['trans_id'].startswith('T-')) |
| 985 | self.assertEqual('{"value": "there"}', part2['content']) |
| 986 | self.assertEqual(doc.rev, part2['rev']) |
| 987 | self.assertEqual(doc.doc_id, part2['id']) |
| 988 | self.assertEqual(1, part2['gen']) |
| 989 | - part3 = simplejson.loads(parts[3].rstrip(",")) |
| 990 | + part3 = json.loads(parts[3].rstrip(",")) |
| 991 | self.assertTrue(part3['trans_id'].startswith('T-')) |
| 992 | self.assertEqual('{"value": "there2"}', part3['content']) |
| 993 | self.assertEqual(doc2.rev, part3['rev']) |
| 994 | @@ -875,7 +877,7 @@ |
| 995 | |
| 996 | def test_sync_exchange_error_in_stream(self): |
| 997 | args = dict(last_known_generation=0) |
| 998 | - body = "[\r\n%s\r\n]" % simplejson.dumps(args) |
| 999 | + body = "[\r\n%s\r\n]" % json.dumps(args) |
| 1000 | |
| 1001 | def boom(self, return_doc_cb): |
| 1002 | raise errors.Unavailable |
| 1003 | @@ -893,8 +895,8 @@ |
| 1004 | self.assertEqual(3, len(parts)) |
| 1005 | self.assertEqual('[', parts[0]) |
| 1006 | self.assertEqual({'new_generation': 0, 'new_transaction_id': ''}, |
| 1007 | - simplejson.loads(parts[1].rstrip(","))) |
| 1008 | - self.assertEqual({'error': 'unavailable'}, simplejson.loads(parts[2])) |
| 1009 | + json.loads(parts[1].rstrip(","))) |
| 1010 | + self.assertEqual({'error': 'unavailable'}, json.loads(parts[2])) |
| 1011 | |
| 1012 | |
| 1013 | class TestRequestHooks(tests.TestCase): |
| 1014 | @@ -981,7 +983,7 @@ |
| 1015 | self.assertEqual(409, resp.status) |
| 1016 | self.assertEqual('application/json', resp.header('content-type')) |
| 1017 | self.assertEqual({"error": "revision conflict"}, |
| 1018 | - simplejson.loads(resp.body)) |
| 1019 | + json.loads(resp.body)) |
| 1020 | |
| 1021 | def test_Unavailable(self): |
| 1022 | self.exc = errors.Unavailable |
| 1023 | @@ -991,7 +993,7 @@ |
| 1024 | self.assertEqual(503, resp.status) |
| 1025 | self.assertEqual('application/json', resp.header('content-type')) |
| 1026 | self.assertEqual({"error": "unavailable"}, |
| 1027 | - simplejson.loads(resp.body)) |
| 1028 | + json.loads(resp.body)) |
| 1029 | |
| 1030 | def test_generic_u1db_errors(self): |
| 1031 | self.exc = errors.U1DBError() |
| 1032 | @@ -1001,7 +1003,7 @@ |
| 1033 | self.assertEqual(500, resp.status) |
| 1034 | self.assertEqual('application/json', resp.header('content-type')) |
| 1035 | self.assertEqual({"error": "error"}, |
| 1036 | - simplejson.loads(resp.body)) |
| 1037 | + json.loads(resp.body)) |
| 1038 | |
| 1039 | def test_generic_u1db_errors_hooks(self): |
| 1040 | calls = [] |
| 1041 | |
| 1042 | === modified file 'u1db/tests/test_http_client.py' |
| 1043 | --- u1db/tests/test_http_client.py 2012-08-13 14:24:06 +0000 |
| 1044 | +++ u1db/tests/test_http_client.py 2012-08-14 14:33:39 +0000 |
| 1045 | @@ -17,7 +17,10 @@ |
| 1046 | """Tests for HTTPDatabase""" |
| 1047 | |
| 1048 | from oauth import oauth |
| 1049 | -import simplejson |
| 1050 | +try: |
| 1051 | + import simplejson as json |
| 1052 | +except ImportError: |
| 1053 | + import json # noqa |
| 1054 | from wsgiref import simple_server |
| 1055 | |
| 1056 | from u1db import ( |
| 1057 | @@ -57,7 +60,7 @@ |
| 1058 | ret['CONTENT_TYPE'] = environ['CONTENT_TYPE'] |
| 1059 | content_length = int(environ['CONTENT_LENGTH']) |
| 1060 | ret['body'] = environ['wsgi.input'].read(content_length) |
| 1061 | - return [simplejson.dumps(ret)] |
| 1062 | + return [json.dumps(ret)] |
| 1063 | elif environ['PATH_INFO'].endswith('error_then_accept'): |
| 1064 | if self.errors >= 3: |
| 1065 | start_response( |
| 1066 | @@ -69,10 +72,10 @@ |
| 1067 | ret['CONTENT_TYPE'] = environ['CONTENT_TYPE'] |
| 1068 | content_length = int(environ['CONTENT_LENGTH']) |
| 1069 | ret['body'] = '{"oki": "doki"}' |
| 1070 | - return [simplejson.dumps(ret)] |
| 1071 | + return [json.dumps(ret)] |
| 1072 | self.errors += 1 |
| 1073 | content_length = int(environ['CONTENT_LENGTH']) |
| 1074 | - error = simplejson.loads( |
| 1075 | + error = json.loads( |
| 1076 | environ['wsgi.input'].read(content_length)) |
| 1077 | response = error['response'] |
| 1078 | # In debug mode, wsgiref has an assertion that the status parameter |
| 1079 | @@ -86,11 +89,11 @@ |
| 1080 | return [str(response)] |
| 1081 | else: |
| 1082 | start_response(status, [('Content-Type', 'application/json')]) |
| 1083 | - return [simplejson.dumps(response)] |
| 1084 | + return [json.dumps(response)] |
| 1085 | elif environ['PATH_INFO'].endswith('error'): |
| 1086 | self.errors += 1 |
| 1087 | content_length = int(environ['CONTENT_LENGTH']) |
| 1088 | - error = simplejson.loads( |
| 1089 | + error = json.loads( |
| 1090 | environ['wsgi.input'].read(content_length)) |
| 1091 | response = error['response'] |
| 1092 | # In debug mode, wsgiref has an assertion that the status parameter |
| 1093 | @@ -104,7 +107,7 @@ |
| 1094 | return [str(response)] |
| 1095 | else: |
| 1096 | start_response(status, [('Content-Type', 'application/json')]) |
| 1097 | - return [simplejson.dumps(response)] |
| 1098 | + return [json.dumps(response)] |
| 1099 | elif '/oauth' in environ['PATH_INFO']: |
| 1100 | base_url = self.getURL('').rstrip('/') |
| 1101 | oauth_req = oauth.OAuthRequest.from_request( |
| 1102 | @@ -121,12 +124,10 @@ |
| 1103 | except oauth.OAuthError, e: |
| 1104 | start_response("401 Unauthorized", |
| 1105 | [('Content-Type', 'application/json')]) |
| 1106 | - return [simplejson.dumps({"error": "unauthorized", |
| 1107 | + return [json.dumps({"error": "unauthorized", |
| 1108 | "message": e.message})] |
| 1109 | start_response("200 OK", [('Content-Type', 'application/json')]) |
| 1110 | - return [simplejson.dumps([environ['PATH_INFO'], |
| 1111 | - token.key, |
| 1112 | - params])] |
| 1113 | + return [json.dumps([environ['PATH_INFO'], token.key, params])] |
| 1114 | |
| 1115 | def server_def(self): |
| 1116 | def make_server(host_port, handler, state): |
| 1117 | @@ -181,17 +182,17 @@ |
| 1118 | 'PATH_INFO': '/dbase/echo', |
| 1119 | 'QUERY_STRING': '', |
| 1120 | 'body': '{}', |
| 1121 | - 'REQUEST_METHOD': 'PUT'}, simplejson.loads(res)) |
| 1122 | + 'REQUEST_METHOD': 'PUT'}, json.loads(res)) |
| 1123 | |
| 1124 | res, headers = cli._request('GET', ['doc', 'echo'], {'a': 1}) |
| 1125 | self.assertEqual({'PATH_INFO': '/dbase/doc/echo', |
| 1126 | 'QUERY_STRING': 'a=1', |
| 1127 | - 'REQUEST_METHOD': 'GET'}, simplejson.loads(res)) |
| 1128 | + 'REQUEST_METHOD': 'GET'}, json.loads(res)) |
| 1129 | |
| 1130 | res, headers = cli._request('GET', ['doc', '%FFFF', 'echo'], {'a': 1}) |
| 1131 | self.assertEqual({'PATH_INFO': '/dbase/doc/%FFFF/echo', |
| 1132 | 'QUERY_STRING': 'a=1', |
| 1133 | - 'REQUEST_METHOD': 'GET'}, simplejson.loads(res)) |
| 1134 | + 'REQUEST_METHOD': 'GET'}, json.loads(res)) |
| 1135 | |
| 1136 | res, headers = cli._request('POST', ['echo'], {'b': 2}, 'Body', |
| 1137 | 'application/x-test') |
| 1138 | @@ -199,7 +200,7 @@ |
| 1139 | 'PATH_INFO': '/dbase/echo', |
| 1140 | 'QUERY_STRING': 'b=2', |
| 1141 | 'body': 'Body', |
| 1142 | - 'REQUEST_METHOD': 'POST'}, simplejson.loads(res)) |
| 1143 | + 'REQUEST_METHOD': 'POST'}, json.loads(res)) |
| 1144 | |
| 1145 | def test__request_json(self): |
| 1146 | cli = self.getClient() |
| 1147 | @@ -289,7 +290,7 @@ |
| 1148 | {'status': "403 Forbidden", |
| 1149 | 'response': {"error": "user quota exceeded"}}) |
| 1150 | |
| 1151 | - def test_user_quota_exceeded(self): |
| 1152 | + def test_user_needs_subscription(self): |
| 1153 | cli = self.getClient() |
| 1154 | self.assertRaises(errors.SubscriptionNeeded, |
| 1155 | cli._request_json, 'POST', ['error'], {}, |
| 1156 | @@ -333,15 +334,15 @@ |
| 1157 | tests.token1.key, tests.token1.secret) |
| 1158 | params = {'x': u'\xf0', 'y': "foo"} |
| 1159 | res, headers = cli._request('GET', ['doc', 'oauth'], params) |
| 1160 | - self.assertEqual(['/dbase/doc/oauth', tests.token1.key, params], |
| 1161 | - simplejson.loads(res)) |
| 1162 | + self.assertEqual( |
| 1163 | + ['/dbase/doc/oauth', tests.token1.key, params], json.loads(res)) |
| 1164 | |
| 1165 | # oauth does its own internal quoting |
| 1166 | params = {'x': u'\xf0', 'y': "foo"} |
| 1167 | res, headers = cli._request('GET', ['doc', 'oauth', 'foo bar'], params) |
| 1168 | self.assertEqual( |
| 1169 | ['/dbase/doc/oauth/foo bar', tests.token1.key, params], |
| 1170 | - simplejson.loads(res)) |
| 1171 | + json.loads(res)) |
| 1172 | |
| 1173 | def test_oauth_Unauthorized(self): |
| 1174 | cli = self.getClient() |
| 1175 | |
| 1176 | === modified file 'u1db/tests/test_http_database.py' |
| 1177 | --- u1db/tests/test_http_database.py 2012-07-19 19:50:58 +0000 |
| 1178 | +++ u1db/tests/test_http_database.py 2012-08-14 14:33:39 +0000 |
| 1179 | @@ -17,7 +17,10 @@ |
| 1180 | """Tests for HTTPDatabase""" |
| 1181 | |
| 1182 | import inspect |
| 1183 | -import simplejson |
| 1184 | +try: |
| 1185 | + import simplejson as json |
| 1186 | +except ImportError: |
| 1187 | + import json # noqa |
| 1188 | |
| 1189 | from u1db import ( |
| 1190 | errors, |
| 1191 | @@ -127,7 +130,7 @@ |
| 1192 | |
| 1193 | def test_get_doc_deleted_include_deleted(self): |
| 1194 | self.response_val = errors.HTTPError(404, |
| 1195 | - simplejson.dumps( |
| 1196 | + json.dumps( |
| 1197 | {"error": errors.DOCUMENT_DELETED} |
| 1198 | ), |
| 1199 | {'x-u1db-rev': 'doc-rev-gone', |
| 1200 | |
| 1201 | === modified file 'u1db/tests/test_oauth_middleware.py' |
| 1202 | --- u1db/tests/test_oauth_middleware.py 2012-04-18 19:01:07 +0000 |
| 1203 | +++ u1db/tests/test_oauth_middleware.py 2012-08-14 14:33:39 +0000 |
| 1204 | @@ -17,7 +17,10 @@ |
| 1205 | """Test OAuth wsgi middleware""" |
| 1206 | import paste.fixture |
| 1207 | from oauth import oauth |
| 1208 | -import simplejson |
| 1209 | +try: |
| 1210 | + import simplejson as json |
| 1211 | +except ImportError: |
| 1212 | + import json # noqa |
| 1213 | import time |
| 1214 | |
| 1215 | from u1db import tests |
| 1216 | @@ -33,11 +36,13 @@ |
| 1217 | def setUp(self): |
| 1218 | super(TestAuthMiddleware, self).setUp() |
| 1219 | self.got = [] |
| 1220 | + |
| 1221 | def witness_app(environ, start_response): |
| 1222 | start_response("200 OK", [("content-type", "text/plain")]) |
| 1223 | self.got.append((environ['token_key'], environ['PATH_INFO'], |
| 1224 | environ['QUERY_STRING'])) |
| 1225 | return ["ok"] |
| 1226 | + |
| 1227 | class MyOAuthMiddleware(OAuthMiddleware): |
| 1228 | get_oauth_data_store = lambda self: tests.testingOAuthStore |
| 1229 | |
| 1230 | @@ -45,6 +50,7 @@ |
| 1231 | consumer, token = super(MyOAuthMiddleware, self).verify( |
| 1232 | environ, oauth_req) |
| 1233 | environ['token_key'] = token.key |
| 1234 | + |
| 1235 | self.oauth_midw = MyOAuthMiddleware(witness_app, BASE_URL) |
| 1236 | self.app = paste.fixture.TestApp(self.oauth_midw) |
| 1237 | |
| 1238 | @@ -60,9 +66,9 @@ |
| 1239 | resp = self.app.delete(url, expect_errors=True) |
| 1240 | self.assertEqual(401, resp.status) |
| 1241 | self.assertEqual('application/json', resp.header('content-type')) |
| 1242 | - self.assertEqual({"error": "unauthorized", |
| 1243 | - "message": "Missing OAuth."}, |
| 1244 | - simplejson.loads(resp.body)) |
| 1245 | + self.assertEqual( |
| 1246 | + {"error": "unauthorized", "message": "Missing OAuth."}, |
| 1247 | + json.loads(resp.body)) |
| 1248 | |
| 1249 | def test_oauth_in_query_string(self): |
| 1250 | url = BASE_URL + '/~/foo/doc/doc-id' |
| 1251 | @@ -97,7 +103,7 @@ |
| 1252 | expect_errors=True) |
| 1253 | self.assertEqual(401, resp.status) |
| 1254 | self.assertEqual('application/json', resp.header('content-type')) |
| 1255 | - err = simplejson.loads(resp.body) |
| 1256 | + err = json.loads(resp.body) |
| 1257 | self.assertEqual({"error": "unauthorized", |
| 1258 | "message": err['message']}, |
| 1259 | err) |
| 1260 | @@ -155,6 +161,6 @@ |
| 1261 | self.oauth_midw.timestamp_threshold = 1 |
| 1262 | resp = self.app.delete(oauth_req.to_url(), expect_errors=True) |
| 1263 | self.assertEqual(401, resp.status) |
| 1264 | - err = simplejson.loads(resp.body) |
| 1265 | + err = json.loads(resp.body) |
| 1266 | self.assertIn('Expired timestamp', err['message']) |
| 1267 | self.assertIn('threshold 1', err['message']) |
