Browse Source

OrderedDict requires extra parens.

pull/24/head
Ben Kurtovic 10 years ago
parent
commit
9b07a5e9dc
1 changed files with 13 additions and 13 deletions
  1. +13
    -13
      copyvios/api.py

+ 13
- 13
copyvios/api.py View File

@@ -21,20 +21,20 @@ _CHECK_ERRORS = {
} }


def _serialize_page(page): def _serialize_page(page):
return OrderedDict(("title", page.title), ("url", page.url))
return OrderedDict((("title", page.title), ("url", page.url)))


def _serialize_source(source, show_skip=True): def _serialize_source(source, show_skip=True):
if not source: if not source:
return OrderedDict(("url", None), ("confidence", 0.0),
("violation", "none"))
return OrderedDict((
("url", None), ("confidence", 0.0), ("violation", "none")))


conf = source.confidence conf = source.confidence
data = OrderedDict(
data = OrderedDict((
("url", source.url), ("url", source.url),
("confidence", conf), ("confidence", conf),
("violation", "suspected" if conf >= T_SUSPECT else ("violation", "suspected" if conf >= T_SUSPECT else
"possible" if conf >= T_POSSIBLE else "none") "possible" if conf >= T_POSSIBLE else "none")
)
))
if show_skip: if show_skip:
data["skipped"] = source.skipped data["skipped"] = source.skipped
return data return data
@@ -44,8 +44,8 @@ def format_api_error(code, info):
info = type(info).__name__ + ": " + str(info) info = type(info).__name__ + ": " + str(info)
elif isinstance(info, unicode): elif isinstance(info, unicode):
info = info.encode("utf8") info = info.encode("utf8")
error_inner = OrderedDict(("code", code), ("info", info))
return OrderedDict(("status", "error"), ("error", error_inner))
error_inner = OrderedDict((("code", code), ("info", info)))
return OrderedDict((("status", "error"), ("error", error_inner)))


def _hook_default(query): def _hook_default(query):
info = u"Unknown action: '{0}'".format(query.action.lower()) info = u"Unknown action: '{0}'".format(query.action.lower())
@@ -73,16 +73,16 @@ def _hook_check(query):
return format_api_error("bad_title", info.format(query.page.title)) return format_api_error("bad_title", info.format(query.page.title))


result = query.result result = query.result
data = OrderedDict(
data = OrderedDict((
("status", "ok"), ("status", "ok"),
("meta", OrderedDict(
("meta", OrderedDict((
("time", result.time), ("time", result.time),
("queries", result.queries), ("queries", result.queries),
("cached", result.cached), ("cached", result.cached),
("redirected", bool(query.redirected_from)) ("redirected", bool(query.redirected_from))
)),
))),
("page", _serialize_page(query.page)) ("page", _serialize_page(query.page))
)
))
if result.cached: if result.cached:
data["meta"]["cache_time"] = result.cache_time data["meta"]["cache_time"] = result.cache_time
if query.redirected_from: if query.redirected_from:
@@ -93,8 +93,8 @@ def _hook_check(query):


def _hook_sites(query): def _hook_sites(query):
langs, projects = get_sites() langs, projects = get_sites()
return OrderedDict(("status", "ok"), ("langs", langs),
("projects", projects))
return OrderedDict((
("status", "ok"), ("langs", langs), ("projects", projects)))


_HOOKS = { _HOOKS = {
"compare": _hook_check, "compare": _hook_check,


Loading…
Cancel
Save