
    Ri                     P    d Z ddlZddlmZ ddlmZ 	 d
dZ	 ddZddZd Z	d	 Z
y)ae  Code to access resources at ExPASy over the WWW.

See https://www.expasy.org/


Functions:
 - get_prodoc_entry  Interface to the get-prodoc-entry CGI script.
 - get_prosite_entry Interface to the get-prosite-entry CGI script.
 - get_prosite_raw   Interface to the get-prosite-raw CGI script.
 - get_sprot_raw     Interface to the get-sprot-raw CGI script.

    N)	HTTPError)urlopenc                 "    t        | d|        S )a  Get a text handle to a PRODOC entry at ExPASy in HTML format.

    >>> from Bio import ExPASy
    >>> import os
    >>> with ExPASy.get_prodoc_entry('PDOC00001') as in_handle:
    ...     html = in_handle.read()
    ...
    >>> with open("myprodocrecord.html", "w") as out_handle:
    ...     length = out_handle.write(html)
    ...
    >>> os.remove("myprodocrecord.html")  # tidy up

    For a non-existing key XXX, ExPASy returns an HTML-formatted page
    containing this text: 'There is currently no PROSITE entry for'
    ?_openidcgis     K/home/agent/.friday_env/lib/python3.12/site-packages/Bio/ExPASy/__init__.pyget_prodoc_entryr          $ C5"    c                 "    t        | d|        S )a  Get a text handle to a PROSITE entry at ExPASy in HTML format.

    >>> from Bio import ExPASy
    >>> import os
    >>> with ExPASy.get_prosite_entry('PS00001') as in_handle:
    ...     html = in_handle.read()
    ...
    >>> with open("myprositerecord.html", "w") as out_handle:
    ...     length = out_handle.write(html)
    ...
    >>> os.remove("myprositerecord.html")  # tidy up

    For a non-existing key XXX, ExPASy returns an HTML-formatted page
    containing this text: 'There is currently no PROSITE entry for'
    r   r   r	   s     r   get_prosite_entryr   -   r   r   c                     	 t        d|  d      }|j                  dk(  rt        d|  d      d|S # t        $ r$}|j                  dk(  rt        d| z        d d}~ww xY w)	ah  Get a text handle to a raw PROSITE or PRODOC record at ExPASy.

    The cgi argument is deprecated due to changes in the ExPASy
    website.

    >>> from Bio import ExPASy
    >>> from Bio.ExPASy import Prosite
    >>> with ExPASy.get_prosite_raw('PS00001') as handle:
    ...     record = Prosite.read(handle)
    ...
    >>> print(record.accession)
    PS00001

    This function raises a ValueError if the identifier does not exist:

    >>> handle = ExPASy.get_prosite_raw("DOES_NOT_EXIST")
    Traceback (most recent call last):
        ...
    ValueError: Failed to find entry 'DOES_NOT_EXIST' on ExPASy

    zhttps://prosite.expasy.org/.txt  z#Failed to find entry '%s' on ExPASyNzhttps://www.expasy.org/zFailed to find entry 'z' on ExPASy)r   r   code
ValueErrorurl)r
   r   handle	exceptions       r   get_prosite_rawr   B   sz    ,4RD=> zz..1"[ABLM  >>S BRGHdR	s   2 	AAAc                     	 t        d|  d      }|S # t        $ r$}|j                  dv rt        d|  d      d d}~ww xY w)a  Get a text handle to a raw SwissProt entry at ExPASy.

    For an ID of XXX, fetches http://www.uniprot.org/uniprot/XXX.txt
    (as per the https://www.expasy.org/expasy_urls.html documentation).

    >>> from Bio import ExPASy
    >>> from Bio import SwissProt
    >>> with ExPASy.get_sprot_raw("O23729") as handle:
    ...     record = SwissProt.read(handle)
    ...
    >>> print(record.entry_name)
    CHS3_BROFI

    This function raises a ValueError if the identifier does not exist:

    >>> ExPASy.get_sprot_raw("DOES_NOT_EXIST")
    Traceback (most recent call last):
        ...
    ValueError: Failed to find SwissProt entry 'DOES_NOT_EXIST'

    zhttp://www.uniprot.org/uniprot/r   )i  r   z Failed to find SwissProt entry ''N)r   r   r   r   )r
   r   r   s      r   get_sprot_rawr   e   sZ    ,8DAB M  >>Z'?t1EFDP	s    	A ;A c                 l    t        |       }t        j                  |d      }|j                  |_        |S )z?Open URL and convert to text assuming UTF-8 encoding (PRIVATE).zUTF-8)encoding)r   ioTextIOWrapperr   )r   r   text_handles      r   r   r      s.    S\F""6G<KjjKOr   )z;https://prosite.expasy.org/cgi-bin/prosite/get-prodoc-entry)z<https://prosite.expasy.org/cgi-bin/prosite/get-prosite-entry)N)__doc__r    urllib.errorr   urllib.requestr   r   r   r   r   r    r   r   <module>r'      s<    
 " " J , K * F@r   