Merge lp:~thisfred/desktopcouch/kill-the-monkey into lp:desktopcouch

Proposed by Eric Casteleijn
Status: Merged
Approved by: Eric Casteleijn
Approved revision: 213
Merged at revision: 213
Proposed branch: lp:~thisfred/desktopcouch/kill-the-monkey
Merge into: lp:desktopcouch
Diff against target: 80 lines (+10/-29)
1 file modified
desktopcouch/records/server_base.py (+10/-29)
To merge this branch: bzr merge lp:~thisfred/desktopcouch/kill-the-monkey
Reviewer Review Type Date Requested Status
Vincenzo Di Somma (community) Approve
Chad Miller (community) Approve
Review via email: mp+41000@code.launchpad.net

Commit message

Remove an unnecessary monkey patch to python-couchdb.

Description of the change

Remove an unnecessary monkey patch.

BAD MONKEY! MONKEY SEE? MONKEY DO! MONKEY WILL DESTROY YOU!

To post a comment you must log in.
Revision history for this message
Chad Miller (cmiller) wrote :

59 + """This method is used to monkey patch the database to provide a
60 + get_changes method"""

review: Needs Fixing
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Ah, oops yes :) fix pushed.

Revision history for this message
Chad Miller (cmiller) :
review: Approve
Revision history for this message
Vincenzo Di Somma (vds) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

Attempt to merge into lp:desktopcouch failed due to conflicts:

text conflict in desktopcouch/records/server_base.py

213. By Eric Casteleijn

remerged trunk and resolved conflict

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/records/server_base.py'
2--- desktopcouch/records/server_base.py 2010-11-17 17:49:54 +0000
3+++ desktopcouch/records/server_base.py 2010-11-18 18:35:08 +0000
4@@ -32,20 +32,10 @@
5
6 # please keep desktopcouch python 2.5 compatible for now
7
8-# pylint can't deal with failing imports even when they're handled
9-# pylint: disable=F0401
10-try:
11- # Python 2.5
12- import simplejson as json
13-except ImportError:
14- # Python 2.6+
15- import json
16-# pylint: enable=F0401
17-
18 from oauth import oauth
19
20 from couchdb import Server
21-from couchdb.client import ResourceNotFound, ResourceConflict, uri as couchdburi
22+from couchdb.client import ResourceNotFound, ResourceConflict
23 from couchdb.design import ViewDefinition
24 from desktopcouch.records.record import Record
25 import logging
26@@ -72,17 +62,6 @@
27 div, mod = divmod(num, base)
28 return baseN(div, base).lstrip("0") + numerals[mod]
29
30-def get_changes(self, changes_since):
31- """This method is used to monkey patch the database to provide a
32- get_changes method"""
33- # Can't use self._server.resource.get() directly because
34- # it encodes "/".
35- uri = couchdburi(
36- self.resource.uri, "_changes",
37- since=changes_since)
38- resp, data = self.resource.http.request(uri, "GET", "", {})
39- return resp, data
40-
41
42 def transform_to_records(view_results):
43 """Transform view resulst into Record objects."""
44@@ -227,8 +206,6 @@
45 raise NoSuchDatabase(self._database_name)
46 if self.db is None:
47 self.db = self._server[self._database_name]
48- if not hasattr(self.db, 'get_changes'):
49- setattr(self.db.__class__, 'get_changes', get_changes)
50 else:
51 # Monkey-patch the object the user already uses. Oook!
52 new_db = self._server[self._database_name]
53@@ -613,6 +590,14 @@
54 self.report_changes(lambda **k: l.append(k), niceness=niceness)
55 return l
56
57+ def _get_changes(self, changes_since=None):
58+ """Get changes feed from couchdb."""
59+ # Can't use self._server.resource.get() directly because
60+ # it encodes "/".
61+ if not changes_since is None:
62+ return self.db.resource.get('_changes', since=changes_since)
63+ return self.db.resource.get('_changes')
64+
65 def report_changes(self, function_to_send_changes_to, niceness=10):
66 """Check to see if there are any changes on this database since last
67 call (or since this object was instantiated), call a function for each,
68@@ -641,11 +626,7 @@
69 now = time()
70 call_count = 0
71 if not niceness or now > self._changes_last_used + niceness:
72- resp, data = self.db.get_changes(self._changes_since)
73- if resp["status"] != '200':
74- raise IOError(
75- "HTTP response code %s.\n%s" % (resp["status"], data))
76- structure = json.loads(data)
77+ structure = self._get_changes(self._changes_since)[1]
78 for change in structure.get("results"): # pylint: disable=E1103
79 # kw-args can't have unicode keys
80 change_encoded_keys = dict(

Subscribers

People subscribed via source and target branches