Files
witness-fracture/.venv/lib/python3.12/site-packages/internetarchive/__pycache__/account.cpython-312.pyc
T

147 lines
9.3 KiB
Plaintext
Raw Normal View History

2025-06-23 17:55:02 -05:00
Ë
’»YhÖ"ãó€—ddlZddlmZmZddlmZmZmZmZddl Z ddl
m Z ddl m
Z
ddlmZ eGd„d««Zy) éN)Ú dataclassÚfield)ÚClassVarÚDictÚListÚOptional)Ú get_session)ÚAccountAPIError)ÚArchiveSessionc óD—eZdZUdZeed<eed<eed<eed<eed<eed<eeed<eed <eed
<eed <ee ¬ «Z
e ed
<dZ eed<ddiZ
eeeefed<ddiZeeeefed<defd„Z d&dedeeefdeeefd
ee dej(f
d„Ze d&deded
ee ddfd„«Ze d&deded
ee defd„«Ze d&d ed
ee ddfd!„«Z d'd"eed
ee dej(fd#„Z d'd"eed
ee dej(fd$„Zdefd%„Zy)(ÚAccountad
A class for interacting with user accounts on the Internet Archive.
Note:
This class requires administrative privileges.
This class provides methods to:
- Fetch account details using various identifiers (e.g., email, screenname, itemname).
- Lock and unlock accounts.
- Convert account data to a dictionary for serialization.
Example Usage:
>>> from internetarchive.account import Account
>>> account = Account.from_account_lookup('email', 'foo@example.com')
>>> account.lock(comment="Locked spam account")
>>> print(account.to_dict())
ÚlockedÚverifiedÚemailÚcanonical_emailÚitemnameÚ
screennameÚ
notificationsÚhas_disability_accessÚ lastloginÚ
createdate)Údefault_factoryÚsessionz/services/xauthn/Ú API_BASE_URLÚopÚinfoÚAPI_INFO_PARAMSÚ lock_unlockÚAPI_LOCK_UNLOCK_PARAMSÚreturncóL—d|jj›|j›�S)z@Dynamically construct the API base URL using the session's host.úhttps://)rÚhostr©Úselfs ú`/mnt/c/fieldcraft/witness-fracture/.venv/lib/python3.12/site-packages/internetarchive/account.pyÚ_get_api_base_urlzAccount._get_api_base_url:s%€à˜$Ÿ,™,×+Ñ+Ð,¨T×->Ñ->Ð,?Ð@Ð@óNÚendpointÚparamsÚdatacó�—|xs |j}d|j›|›�}|j|||¬«}|j«|S)aÌ
Helper method to make API requests.
Args:
endpoint: The API endpoint to call.
params: Query parameters for the request.
data: Data to send in the request body.
session: Optional session to use for the request. Defaults to self.session.
Returns:
The response from the API.
Raises:
requests.exceptions.RequestException: If the API request fails.
r"©r*r+)rr#ÚpostÚraise_for_status)r%r)r*r+rÚurlÚresponses r&Ú_post_api_requestzAccount._post_api_request>sK€ð,Ò)˜TŸ\™\ˆØ˜Ÿ™˜ x jÐ1ˆØ—<‘< ¨F¸�<Ó>ˆØ×!Ñ!Ô#؈r(Úidentifier_typeÚ
identifiercóL—|j|||«}|j||«S)a‚
Factory method to initialize an Account using an identifier type and value.
Args:
identifier_type: The type of identifier (e.g., 'email', 'screenname').
identifier: The value of the identifier (e.g., 'foo@example.com').
session: Optional session to use for the request.
Returns:
An instance of Account.
)Ú_fetch_account_data_from_apiÚ from_json)Úclsr3r4rÚ json_datas r&Úfrom_account_lookupzAccount.from_account_lookupZs*€ð$×4Ñ4°_ÀjÐRYÓZˆ Ø�}‰}˜Y¨Ó0Ð0r(cóê—||i}|xs
t«} |jd|j›|j›�|jt j |«¬«}|j«|j «}|jd«s|jd«st|jdd«|¬«‚|dS#tjj$r}td|›�«‚d}~wwxYw) a<
Fetches account data from the API using an identifier type and value.
Args:
identifier_type: The type of identifier (e.g., 'email', 'screenname').
identifier: The value of the identifier (e.g., 'foo@example.com').
session: Optional session to use for the request.
Returns:
A dictionary containing the account data.
Raises:
requests.exceptions.RequestException: If the API request fails.
ValueError: If the API response is invalid or missing required data.
r"r-ÚerrorÚvaluesz
Unknown error)Ú
error_datazFailed to fetch account data: N)
r r.r#rrÚjsonÚdumpsr/Úgetr
ÚrequestsÚ
exceptionsÚRequestException)r8r3r4rr+r1ÚjÚes r&r6z$Account._fetch_account_data_from_apiosã€ð,  Ð,ˆØÒ*œ[›]ˆð HØ—|‘|ؘ7Ÿ<™<˜.¨×)9Ñ)9Ð(:Ð;Ø×*Ñ*Ü—Z‘Z Ó%ð$óˆHð
× %Ñ %Ô 'Ø—
‘
“ˆAØ�u‰u�WŒ~ Q§U¡U¨8¤_Ü% a§e¡e¨G°_Ó&EÐRSÔTÐTØ�X‘;Ð øÜ×"Ñ"×3Ñ3ò HÜ!Ð$BÀ1À#Ð"FÓGÐ Gûð Hús”B-CÃC2ÃC-Ã-C2r9c
ó—gd¢}|D]}||vsŒtd|›�«‚|€ t«}n't|t«st dt |«›�«‚||d|d|d|d|d|d |d
|d |d |d
|¬« S)ad
Factory method to initialize an Account using JSON data.
Args:
json_data: A dictionary containing account data.
session: Optional session to use for the request.
Returns:
An instance of Account.
Raises:
ValueError: If required fields are missing in the JSON data.
)
rrrrrrrrrrz.Missing required requried_field in JSON data: z3Expected session to be of type ArchiveSession, got rrrrrrrrrr) rrrrrrrrrrr)Ú
ValueErrorr Ú
isinstancer Ú TypeErrorÚtype)r8r9rÚrequired_fieldsÚrequried_fields r&r7zAccount.from_json–s΀ò& 
ˆð.ò dˆNØ YÒ.Ü Ð#QÐR`ÐQaÐ!bÓcÐcð dð
ˆ?Ü!“m‰GܘG¤^Ô4ÜÐQÔRVÐW^ÓR_ÐQ`ÐaÓbÐ báØ˜XÑ&ؘzÑ*ؘGÑ$Ø%Ð&7Ñ8ؘzÑ*Ø  Ñ.Ø# OÑ4Ø"+Ð,CÑ"DØ  Ñ,Ø  Ñ.Øô 
ð
r(Úcommentcó€—|jddœ}|r||d<|j|j|j||¬«S)zê
Lock the account.
Args:
comment: An optional comment for the lock operation.
session: Optional session to use for the request.
Returns:
The response from the API.
Ú1©rÚis_lockÚcomments©r*r+r©rr2rr©r%rNrr+s r&Úlockz Account.lockÍóO€ð!ŸM™M°cÑ:ˆÙ Ø&ˆD�Ñ Ø×%Ñ%Ø × Ñ Ø×.Ñ.ØØð &ó
ð
r(có€—|jddœ}|r||d<|j|j|j||¬«S)zî
Unlock the account.
Args:
comment: An optional comment for the unlock operation.
session: Optional session to use for the request.
Returns:
The response from the API.
Ú0rQrSrTrUrVs r&ÚunlockzAccount.unlockärXr(c óä—|j|j|j|j|j|j
|j |j|j|jdœ
S)z“
Converts the Account instance to a dictionary.
Returns:
A dictionary representation of the Account instance.
©
rrrrrrrrrrr]r$s r&Úto_dictzAccount.to_dictûsZ€ð—k‘kØŸ
™
Ø—Z‘ZØ#×3Ñ3ØŸ
™
ØŸ/™/Ø!×/Ñ/Ø%)×%?Ñ%?ØŸ™ØŸ/™/ñ 
ð
r()N)NN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__ÚboolÚ__annotations__Ústrrrr rr rrrrrr'rrBÚResponser2Ú classmethodr:r6r7rWr[r^©r(r&r
r
s4…ñð"
ƒL؃NØ ƒJØÓ؃M؃Oؘ‘9ÓØÓØƒN؃OÙ#°KÔ@€Gˆ^Ó@à+€L�#Ó+Ø15°v°€O�X˜d 3¨ 8™nÑ-Ó>Ø8<¸mÐ7LИH T¨#¨s¨(¡^Ñ4ÓLðA 3óAð-1ñ àðð�S˜#�X‘ðð�3˜�8‰nð ð
˜.Ñ)ð ð
× Ñ ó
ð8ð