Skip to content

Commit

Permalink
fix xmlrpc error when transport non-utf8 content binux#15
Browse files Browse the repository at this point in the history
fix callback not work bug in handler
add test for fetcher save
  • Loading branch information
binux committed Mar 11, 2014
1 parent 6559fc0 commit ac8da00
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion fetcher/tornado_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,20 @@ def quit(self):

def xmlrpc_run(self, port=24444, bind='127.0.0.1', logRequests=False):
from SimpleXMLRPCServer import SimpleXMLRPCServer
from xmlrpclib import Binary
import cPickle as pickle

server = SimpleXMLRPCServer((bind, port), allow_none=True, logRequests=logRequests)
server.register_introspection_functions()
server.register_multicall_functions()

server.register_function(self.quit, '_quit')
server.register_function(self.size)
server.register_function(self.sync_fetch, 'fetch')
def sync_fetch(task):
result = self.sync_fetch(task)
result = Binary(pickle.dumps(result))
return result
server.register_function(sync_fetch, 'fetch')
def dump_counter(_time, _type):
return self._cnt[_time].to_dict(_type)
server.register_function(dump_counter, 'counter')
Expand Down
2 changes: 1 addition & 1 deletion libs/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _crawl(self, url, **kwargs):
task['fetch'] = fetch

process = {}
for key in ('callback'):
for key in ('callback', ):
if key in kwargs and kwargs[key] is not None:
process[key] = kwargs[key]
if process:
Expand Down
3 changes: 2 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ def run_processor():

def run_webui():
import xmlrpclib
import cPickle as pickle
scheduler_rpc = xmlrpclib.ServerProxy('http://localhost:%d' % scheduler_xmlrpc_port)
fetch_rpc = xmlrpclib.ServerProxy('http://localhost:%d' % fetcher_xmlrpc_port)

from webui.app import app
app.config['fetch'] = lambda task: fetch_rpc.fetch(task)
app.config['fetch'] = lambda task: pickle.loads(fetch_rpc.fetch(task).data)
app.config['projectdb'] = get_projectdb
app.config['scheduler_rpc'] = scheduler_rpc
app.run()
Expand Down
2 changes: 2 additions & 0 deletions test/test_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TestTaskDB(unittest.TestCase):
'a': 'b'
},
'timeout': 60,
'save': 'abc',
},
'process': {
'callback': 'callback',
Expand All @@ -44,6 +45,7 @@ def test_http_get(self):
result = self.fetcher.sync_fetch(self.sample_task_http)
self.assertEqual(result['status_code'], 200)
self.assertEqual(result['orig_url'], self.sample_task_http['url'])
self.assertEqual(result['save'], self.sample_task_http['fetch']['save'])
self.assertIn('content', result)
content = json.loads(result['content'])
self.assertIn('headers', content)
Expand Down

0 comments on commit ac8da00

Please sign in to comment.