3 nf\k@s\dZddlmZddlmZddlmZddlmZddlm Z ee Z Gdd d eZ d S) z NTLM authenticating pool, contributed by erikcederstran Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10 )absolute_import) getLogger)ntlm)HTTPSConnectionPool)HTTPSConnectioncs:eZdZdZdZfddZddZd fd d ZZS) NTLMConnectionPoolzQ Implements an NTLM authentication version of an urllib3 connection pool ZhttpscsLtt|j||||_||_|jdd}|dj|_|d|_||_ dS)z authurl is a random URL on the server that is protected by NTLM. user is the Windows user, probably in the DOMAIN\username format. pw is the password for the user. \rN) superr__init__authurlrawusersplitupperdomainuserpw)selfrrr argskwargsZ user_parts) __class__/usr/lib/python3.6/ntlmpool.pyr s  zNTLMConnectionPool.__init__c Cs|jd7_tjd|j|j|jddi}d}d}t|j|jd}dtj|j ||<tjd ||j d |jd||j }t |j }tjd |j|jtjd |tjd |jdd|_||jd}d}x(|D] } | dddkr| dd}qW|dkrtd|||ftj|\} } tj| |j|j|j| } d| ||<tjd ||j d |jd||j }tjd |j|jtjd t |j tjd |jdd|jdkr|jdkrtdtd|j|jfd|_tjd|S)Nr z3Starting NTLM HTTPS connection no. %d: https://%s%s Connectionz Keep-AliveZ Authorizationzwww-authenticate)hostportzNTLM %szRequest headers: %sZGETzResponse status: %s %szResponse headers: %szResponse data: %s [...]dz, zNTLM z!Unexpected %s response header: %siz3Server rejected request: wrong username or passwordzWrong server response: %s %szConnection established)Znum_connectionslogdebugrr rrrZcreate_NTLM_NEGOTIATE_MESSAGErZrequestZ getresponsedictZ getheadersZstatusreasonreadfpr ExceptionZparse_NTLM_CHALLENGE_MESSAGEZ create_NTLM_AUTHENTICATE_MESSAGErrr) rheadersZ req_headerZ resp_headerZconnresZreshdrZauth_header_valuesZauth_header_valuesZServerChallengeZNegotiateFlagsZauth_msgrrr _new_conn'sZ          zNTLMConnectionPool._new_connNTcs0|dkr i}d|d<tt|j|||||||S)Nz Keep-Aliver)r rurlopen)rmethodZurlZbodyr'ZretriesZredirectZassert_same_host)rrrr,gszNTLMConnectionPool.urlopen)NNr+TT) __name__ __module__ __qualname____doc__schemer r*r, __classcell__rr)rrrs  @rN) r1Z __future__rZloggingrrrZpackages.six.moves.http_clientrr.r rrrrrs