def post(path, query, body): logger.debug('handling incoming request - %s', 'None' if None == body else body) if None == body: return 400, 'Bad Request', 'book id expected', None try: decoded = helpers.decode_urlencoding(body) arguments = __extract_arguments(decoded) if 'idList' not in arguments: return 400, 'Bad Request', 'book id expected', None id_str = arguments['idList'] logger.debug('id list extracted - %s', id_str) if '' == id_str.strip(): return 400, 'Bad Request', 'book id expected', None ''' if (not book_id.isdigit()): return 400, 'Bad Request', 'book id expected', None ''' except: return 500, 'Internal Server Error', 'unknown error', None try: return 200, 'OK', da.query_books(id_str), { 'Content-Type': 'application/json;charset=UTF-8'} return 200, 'OK', 'Test', None except: return 500, 'Internal Server Error' 'database error', None
def decrypt(cipher, priv): global logger cipher = helpers.decode_urlencoding(cipher) cipher = int(cipher, 16) logger.debug('cipher = %d', cipher) cipher = rsa.transform.int2bytes(cipher) return rsa.decrypt(cipher, priv)
def decrypt(cipher, priv): global logger if '' == cipher: logger.warn('Null cipher') return None try: cipher = helpers.decode_urlencoding(cipher) cipher = int(cipher, 16) except: logger.warn('Unrecognized cipher = %s', cipher) return None logger.debug('cipher = %d', cipher) cipher = rsa.transform.int2bytes(cipher) return rsa.decrypt(cipher, priv)
def get(url, headers, body): query = headers.get('QUERY') if query == None or query.strip() == '': return 400, 'Bad Request', 'query field is not found.', None params = dict((n,v) for n, v in (i.split('=', 1) for i in query.split('&'))) if 'query' not in params: return 400, 'Bad Request', 'query field is not found.', None text = params['query'] search_query = helpers.decode_urlencoding(text) # helpers.log_search_query(search_query) global logger logger.debug('incoming query: %s', text) terms = seg_txt(search_query) logger.debug('terms from query: %s', terms) database = xapian.Database('../indexes/') enquire = xapian.Enquire(database) l = [] for term in terms: l.append(term) q = xapian.Query(xapian.Query.OP_OR, l) enquire.set_query(q) matches = enquire.get_mset(0, 100) print '%i results found.' % matches.get_matches_estimated() print 'Result - %i:' % matches.size() r = [] for m in matches: # print '%i: %i%% docid=%i [%s]' % (m.rank + 1, m.percent, m.docid,\ # m.document.get_data()) r.append(m.document.get_data()) print json.dumps(r) return 200, 'OK', json.dumps(r), None