/usr/share/pyshared/couchdbkit/consumer/sync.py is in python-couchdbkit 0.6.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | # -*- coding: utf-8 -
#
# This file is part of couchdbkit released under the MIT license.
# See the NOTICE for more information.
from __future__ import with_statement
from .base import ConsumerBase, check_callable
from ..utils import json
__all__ = ['SyncConsumer']
class SyncConsumer(ConsumerBase):
def wait_once(self, cb=None, **params):
if cb is not None:
check_callable(cb)
params.update({"feed": "longpoll"})
resp = self.db.res.get("_changes", **params)
buf = ""
with resp.body_stream() as body:
while True:
data = body.read()
if not data:
break
buf += data
ret = json.loads(buf)
if cb is not None:
cb(ret)
return
return ret
def wait(self, cb, **params):
check_callable(cb)
params.update({"feed": "continuous"})
resp = self.db.res.get("_changes", **params)
with resp.body_stream() as body:
while True:
try:
line = body.readline()
if not line:
break
if line.endswith("\r\n"):
line = line[:-2]
else:
line = line[:-1]
if not line:
continue
cb(json.loads(line))
except (KeyboardInterrupt, SystemExit,):
break
|