def is_user_dup(user_id, doc_id): if user_id is None or doc_id is None: return True url = USER_DUP_API_FORMANT % (SERVER_ADDRESS, user_id, doc_id) resp = download(url) if resp is None or resp.status != 200: _LOGGER.error("[Dedup] Unexcepted result from dedup service. (url: %s status %d)" % (url, resp.status if resp else 0)) return False try: data = simplejson.loads(resp.body) if isinstance(data, dict) and 'dup' in data: return data['dup'] except simplejson.JSONDecodeError, err: _LOGGER.error("[Dedup] Failed to load response from dedup service. (url: %s body %s)" % (url, resp.body)) _LOGGER.error("[Dedup] err: %s traceback %s" % (err, traceback.format_exc())) return False
def is_user_dup(user_id, doc_id): if user_id is None or doc_id is None: return True url = USER_DUP_API_FORMANT % (SERVER_ADDRESS, user_id, doc_id) resp = download(url) if resp is None or resp.status != 200: _LOGGER.error( "[Dedup] Unexcepted result from dedup service. (url: %s status %d)" % (url, resp.status if resp else 0)) return False try: data = simplejson.loads(resp.body) if isinstance(data, dict) and 'dup' in data: return data['dup'] except simplejson.JSONDecodeError, err: _LOGGER.error( "[Dedup] Failed to load response from dedup service. (url: %s body %s)" % (url, resp.body)) _LOGGER.error("[Dedup] err: %s traceback %s" % (err, traceback.format_exc())) return False
def _get_original_link(link): resp = download(link, follow_redirect=False) if resp is None: return link return resp.original_url or link