def show(args): "displaying bugs" tmpl = template.get_template('view', '/issue.txt') for bug_no in args.bugs: if args.browse: webbrowser.open_new_tab("https://github.com/%s/issues/%d" % (args.project, bug_no)) continue try: bug = args.api("show", bug_no) except RuntimeError as error: if "Issue #%s not found" % bug_no in error.args[0]: yield utils.fail("Issue %r not found" % bug_no) break else: raise if args.full: comments = args.api("comments", bug.number) else: comments = [] if args.patch and bug.pull_request_url: request, body = args._http.request(bug.patch_url) patch = body.decode(charset_from_headers(request)) else: patch = None yield tmpl.render(bug=bug, comments=comments, full=True, patch=patch)
def request(self, uri, method='GET', body=None, headers=None, redirections=5, connection_type=None): file = os.path.join(HTTP_DATA_DIR, httplib2.safename(uri)) if os.path.exists(file): response = message_from_file(open(file)) headers = httplib2.Response(response) body = bytes(response.get_payload(), charset_from_headers(headers)) return (headers, body) else: return (httplib2.Response({"status": "404"}), "Resource %r unavailable from test data store" % file)
def request_mock(uri, method='GET', body=None, headers=None, redirections=5, connection_type=None): """Http mock side effect that returns saved entries. Implementation tests should never span network boundaries. """ file = os.path.join("tests/data", httplib2.safename(uri)) if os.path.exists(file): response = message_from_file(open(file)) headers = httplib2.Response(response) body = bytes(response.get_payload(), charset_from_headers(headers)) return (headers, body) else: return (httplib2.Response({"status": "404"}), "Resource %r unavailable from test data store" % file)
def utf_test(): d = {'content-type': 'application/json; charset=utf-8'} eq_("utf-8", charset_from_headers(d))
def no_match_test(): d = {} eq_("ascii", charset_from_headers(d))
def no_match_test(): d = {} assert_equals("ascii", charset_from_headers(d))