def wrap_http_for_jwt_access(credentials, http):
orig_request_method = http.request<EOL>wrap_http_for_auth(credentials, http)<EOL>authenticated_request_method = http.request<EOL>def new_request(uri, method='<STR_LIT:GET>', body=None, headers=None,<EOL>redirections=httplib2.DEFAULT_MAX_REDIRECTS,<EOL>connection_type=None):<EOL><INDENT>if '<STR_LIT>' in credentials._kwargs:<EOL><INDENT>if (credentials.access_token is None or<EOL>credentials.access_token_expired):<EOL><INDENT>credentials.refresh(None)<EOL><DEDENT>return request(authenticated_request_method, uri,<EOL>method, body, headers, redirections,<EOL>connection_type)<EOL><DEDENT>else:<EOL><INDENT>headers = _initialize_headers(headers)<EOL>_apply_user_agent(headers, credentials.user_agent)<EOL>uri_root = uri.split('<STR_LIT:?>', <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>token, unused_expiry = credentials._create_token({'<STR_LIT>': uri_root})<EOL>headers['<STR_LIT>'] = '<STR_LIT>' + token<EOL>return request(orig_request_method, uri, method, body,<EOL>clean_headers(headers),<EOL>redirections, connection_type)<EOL><DEDENT><DEDENT>http.request = new_request<EOL>http.request.credentials = credentials<EOL>
Prepares an HTTP object's request method for JWT access.

    Wraps HTTP requests with logic to catch auth failures (typically
    identified via a 401 status code). In the event of failure, tries
    to refresh the token used and then retry the original request.

    Args:
        credentials: _JWTAccessCredentials, the credentials used to identify
                     a service account that uses JWT access tokens.
        http: httplib2.Http, an http object to be used to make
              auth requests.