!e'dZ ddlmZddlZddlZddlZddlZddl m Z ddl m Z m Z ddlmZddlmZeZgd Zd ZGd d ZGd dZGddeZGddeZGddeZy#e$r ddlmZYuwxYw)z.OAuth classes for use with lazr.restfulclient.) ConfigParser)SafeConfigParserN)oauth1)parse_qs urlencode)HttpAuthorizer)CredentialsFileError) AccessTokenConsumerOAuthAuthorizerSystemWideConsumer1ceZdZdZddZy)r z An OAuth consumer (application).Nc.||_||_||_y)anInitialize :param key: The OAuth consumer key :param secret: The OAuth consumer secret. Don't use this. It's a misfeature, and lazr.restful doesn't expect it. :param application_name: An application name, if different from the consumer key. If present, this will be used in the User-Agent header. N)keysecretapplication_name)selfrrrs D/usr/lib/python3/dist-packages/lazr/restfulclient/authorize/oauth.py__init__zConsumer.__init__8s 0N)__name__ __module__ __qualname____doc__rrrr r 5s * 1rr c2eZdZdZddZdZeZedZy)r zAn OAuth access token.Nc.||_||_||_yN)rrcontext)rrrr"s rrzAccessToken.__init__Js  rcLtd|jfd|jfgS)Noauth_token_secret oauth_token)rrrrs r to_stringzAccessToken.to_stringOs,%t{{3)   rcNt|d}|dd}|dd}|||S)NF)keep_blank_valuesr%rr$)r)clssparamsrrs r from_stringzAccessToken.from_stringYs:!u5]#A&,-a03rr) rrrrrr'__str__ classmethodr-rrrr r Gs(   G  rr ceZdZdZdZeZy) TruthyStringz&A Unicode string which is always true.cy)NTrr&s r__bool__zTruthyString.__bool__dsrN)rrrrr3 __nonzero__rrrr1r1as0Krr1c8eZdZdZdZdfd ZedZxZS)r zA consumer associated with the logged-in user rather than an app. This can be used to share a single OAuth token among multiple desktop applications. The OAuth consumer key will be derived from system information (platform and hostname). zSystem-wide: %s (%s)cDtt| |j||y)a Constructor. :param application_name: An application name. This will be used in the User-Agent header. :param secret: The OAuth consumer secret. Don't use this. It's a misfeature, and lazr.restful doesn't expect it. N)superr r consumer_key)rrr __class__s rrzSystemWideConsumer.__init__ts#  $0   v'7 rc ddl}|j}|dk(rtj}|j |t jfzS#t$rd}YIwxYw)zThe system-wide OAuth consumer key for this computer. This key identifies the platform and the computer's hostname. It does not identify the active user. rNr)distroname Exceptionplatformsystem KEY_FORMATsocket gethostname)rr;distnames rr8zSystemWideConsumer.consumer_keys_  {{}H r>(H(F,>,>,@!AAA  H sA A A )r) rrrrr@rpropertyr8 __classcell__)r9s@rr r js*(J  BBrr cZeZdZdZ d dZedZdZedZ dZ dZ d Z y) r zBA client that signs every outgoing request with OAuth credentials.NcVd|_|t||||_||_||_yr!)consumerr access_token oauth_realm)r consumer_nameconsumer_secretrIrJrs rrzOAuthAuthorizer.__init__s7  $$0@DM)&rci}|j|S|jj|d<|jj|jj|d<|S)zoAny information necessary to identify this user agent. In this case, the OAuth consumer name. oauth_consumer application)rHrr)rr,s ruser_agent_paramsz!OAuthAuthorizer.user_agent_paramssV  == M#'==#4#4 == ) ) 5$(MM$B$BF= ! rct}t|dr |j}n |j}|||j t st dt z|jt d}|jt d}t|||_ |jt d}|jt d}t|||_ y)akLoad credentials from a file-like object. This overrides the consumer and access token given in the constructor and replaces them with the values read from the file. :param readable_file: A file-like object to read the credentials from :type readable_file: Any object supporting the file-like `read()` method read_filezNo configuration for version %sr8rLrI access_secretN) rhasattrrRreadfp has_sectionCREDENTIALS_FILE_VERSIONr getr rHr rI)r readable_fileparserreaderr8rLrIrSs rloadzOAuthAuthorizer.loads"# 6; '%%F]]F}!!":;&14LL zz":NK  ** $&7 !? zz":NK  #;_M ' mDrcn|}t|d}|j||j|S)aConvenience method for loading credentials from a file. Open the file, create the Credentials and load from the file, and finally close the file and return the newly created Credentials instance. :param path: In which file the credential file should be saved. :type path: string :return: The loaded Credentials instance. :rtype: `Credentials` r)openr\close)r*path credentialscredentials_files rload_from_pathzOAuthAuthorizer.load_from_paths8e c?)* rc|j td|j tdt}|j t |j t d|jj|j t d|jj|j t d|jj|j t d|jj|j|y)aHWrite the credentials to the file-like object. :param writable_file: A file-like object to write the credentials to :type writable_file: Any object supporting the file-like `write()` method :raise CredentialsFileError: when there is either no consumer or no access token Nz No consumerzNo access tokenr8rLrIrS) rHr rIr add_sectionrWsetrrwrite)r writable_filerZs rsavezOAuthAuthorizer.saves == &}5 5    $&'89 9!#34 +^T]]=N=NO $&79M9M   $nd6G6G6K6K   $ot7H7H7O7O   ]#rc:tjtj|tjtjztj zt jt jzd}|j||jy)aTConvenience method for saving credentials to a file. Create the file, call self.save(), and close the file. Existing files are overwritten. The resulting file will be readable and writable only by the user. :param path: In which file the credential file should be saved. :type path: string wN) osfdopenr_O_CREATO_TRUNCO_WRONLYstatS_IREADS_IWRITErjr`)rrarcs r save_to_pathzOAuthAuthorizer.save_to_pathsk99 GGbjj(2;;6 -     "# rctj|jj|jjt |j jxsd|j jtj|j}t |j|_ |j|\}}}|jD] \}} | ||< y)z&Sign a request with OAuth credentials.r) client_secretresource_owner_keyresource_owner_secretsignature_methodrealmN) rClientrHrrr1rISIGNATURE_PLAINTEXTrJrxsignitems) r absolute_urimethodbodyheadersclient_signed_headersrvalues rauthorizeRequestz OAuthAuthorizer.authorizeRequests MM  --..+D,=,=,A,A,GRH"&"3"3":":#77""  %11J1J$K!%{{<8>1(..0 !JC GCL !r)NrNOAuthN) rrrrrrDrPr\r/rdrjrurrrrr r sYL '   E@$$8!*!rr )r configparserrr ImportErrorrmr>rArroauthlibr urllib.parserrlazr.restfulclient.authorizerlazr.restfulclient.errorsr type __metaclass____all__rWr r strr1r r rrrrs&5.=  ,7:   11$  43'B'BTV!nV!w.-.sA22 B?B