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
=== modified file 'desktopcouch/records/server_base.py'
--- desktopcouch/records/server_base.py 2010-11-17 17:49:54 +0000
+++ desktopcouch/records/server_base.py 2010-11-18 18:35:08 +0000
@@ -32,20 +32,10 @@
3232
33# please keep desktopcouch python 2.5 compatible for now33# please keep desktopcouch python 2.5 compatible for now
3434
35# pylint can't deal with failing imports even when they're handled
36# pylint: disable=F0401
37try:
38 # Python 2.5
39 import simplejson as json
40except ImportError:
41 # Python 2.6+
42 import json
43# pylint: enable=F0401
44
45from oauth import oauth35from oauth import oauth
4636
47from couchdb import Server37from couchdb import Server
48from couchdb.client import ResourceNotFound, ResourceConflict, uri as couchdburi38from couchdb.client import ResourceNotFound, ResourceConflict
49from couchdb.design import ViewDefinition39from couchdb.design import ViewDefinition
50from desktopcouch.records.record import Record40from desktopcouch.records.record import Record
51import logging41import logging
@@ -72,17 +62,6 @@
72 div, mod = divmod(num, base)62 div, mod = divmod(num, base)
73 return baseN(div, base).lstrip("0") + numerals[mod]63 return baseN(div, base).lstrip("0") + numerals[mod]
7464
75def get_changes(self, changes_since):
76 """This method is used to monkey patch the database to provide a
77 get_changes method"""
78 # Can't use self._server.resource.get() directly because
79 # it encodes "/".
80 uri = couchdburi(
81 self.resource.uri, "_changes",
82 since=changes_since)
83 resp, data = self.resource.http.request(uri, "GET", "", {})
84 return resp, data
85
8665
87def transform_to_records(view_results):66def transform_to_records(view_results):
88 """Transform view resulst into Record objects."""67 """Transform view resulst into Record objects."""
@@ -227,8 +206,6 @@
227 raise NoSuchDatabase(self._database_name)206 raise NoSuchDatabase(self._database_name)
228 if self.db is None:207 if self.db is None:
229 self.db = self._server[self._database_name]208 self.db = self._server[self._database_name]
230 if not hasattr(self.db, 'get_changes'):
231 setattr(self.db.__class__, 'get_changes', get_changes)
232 else:209 else:
233 # Monkey-patch the object the user already uses. Oook!210 # Monkey-patch the object the user already uses. Oook!
234 new_db = self._server[self._database_name]211 new_db = self._server[self._database_name]
@@ -613,6 +590,14 @@
613 self.report_changes(lambda **k: l.append(k), niceness=niceness)590 self.report_changes(lambda **k: l.append(k), niceness=niceness)
614 return l591 return l
615592
593 def _get_changes(self, changes_since=None):
594 """Get changes feed from couchdb."""
595 # Can't use self._server.resource.get() directly because
596 # it encodes "/".
597 if not changes_since is None:
598 return self.db.resource.get('_changes', since=changes_since)
599 return self.db.resource.get('_changes')
600
616 def report_changes(self, function_to_send_changes_to, niceness=10):601 def report_changes(self, function_to_send_changes_to, niceness=10):
617 """Check to see if there are any changes on this database since last602 """Check to see if there are any changes on this database since last
618 call (or since this object was instantiated), call a function for each,603 call (or since this object was instantiated), call a function for each,
@@ -641,11 +626,7 @@
641 now = time()626 now = time()
642 call_count = 0627 call_count = 0
643 if not niceness or now > self._changes_last_used + niceness:628 if not niceness or now > self._changes_last_used + niceness:
644 resp, data = self.db.get_changes(self._changes_since)629 structure = self._get_changes(self._changes_since)[1]
645 if resp["status"] != '200':
646 raise IOError(
647 "HTTP response code %s.\n%s" % (resp["status"], data))
648 structure = json.loads(data)
649 for change in structure.get("results"): # pylint: disable=E1103630 for change in structure.get("results"): # pylint: disable=E1103
650 # kw-args can't have unicode keys631 # kw-args can't have unicode keys
651 change_encoded_keys = dict(632 change_encoded_keys = dict(

Subscribers

People subscribed via source and target branches