Ë
    ¹ûàgò  ã                   ó˜   — d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d d	lmZ  G d
„ de«      Z G d„ de«      Zy)é    N)Úurlparse)Úsettings)ÚPermissionDenied)Úmail_managers)ÚHttpResponsePermanentRedirect)Úis_valid_path)ÚMiddlewareMixin)Úescape_leading_slashesc                   ó,   — e Zd ZdZeZd„ Zd„ Zd„ Zd„ Z	y)ÚCommonMiddlewarea  
    "Common" middleware for taking care of some basic operations:

        - Forbid access to User-Agents in settings.DISALLOWED_USER_AGENTS

        - URL rewriting: Based on the APPEND_SLASH and PREPEND_WWW settings,
          append missing slashes and/or prepends missing "www."s.

            - If APPEND_SLASH is set and the initial URL doesn't end with a
              slash, and it is not found in urlpatterns, form a new URL by
              appending a slash at the end. If this new URL is found in
              urlpatterns, return an HTTP redirect to this new URL; otherwise
              process the initial URL as usual.

          This behavior can be customized by subclassing CommonMiddleware and
          overriding the response_redirect_class attribute.
    c                 ó´  — |j                   j                  d«      }|�1t        j                  D ]  }|j	                  |«      sŒt        d«      ‚ |j                  «       }t        j                  rj|rg|j                  d«      sU| j                  |«      r| j                  |«      }n|j                  «       }| j                  |j                  › d|› |› �«      S yyy)z‚
        Check for denied User-Agents and rewrite the URL based on
        settings.APPEND_SLASH and settings.PREPEND_WWW
        ÚHTTP_USER_AGENTNzForbidden user agentzwww.z://www.)ÚMETAÚgetr   ÚDISALLOWED_USER_AGENTSÚsearchr   Úget_hostÚPREPEND_WWWÚ
startswithÚshould_redirect_with_slashÚget_full_path_with_slashÚget_full_pathÚresponse_redirect_classÚscheme)ÚselfÚrequestÚ
user_agentÚuser_agent_regexÚhostÚpaths         úV/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/django/middleware/common.pyÚprocess_requestz CommonMiddleware.process_request"   sÖ   € ð —\‘\×%Ñ%Ð&7Ó8ˆ
ØÐ!Ü$,×$CÑ$Cò CÐ Ø#×*Ñ*¨:Õ6Ü*Ð+AÓBÐBðCð
 ×ÑÓ!ˆä×Ò¡D°·±ÀÔ1Hð
 ×.Ñ.¨wÔ7Ø×4Ñ4°WÓ=‘à×,Ñ,Ó.�à×/Ñ/°7·>±>Ð2BÀ'È$ÈÐPTÈvÐ0VÓWÐWð 2I DÐó    c                 ó  — t         j                  rr|j                  j                  d«      sWt	        |dd«      }t        |j                  |«      s4t        d|j                  z  |«      }|r|j                  }t	        |dd«      S y)z˜
        Return True if settings.APPEND_SLASH is True and appending a slash to
        the request path turns an invalid path into a valid one.
        ú/ÚurlconfNz%s/Úshould_append_slashTF)r   ÚAPPEND_SLASHÚ	path_infoÚendswithÚgetattrr   Úfunc)r   r   r&   ÚmatchÚviews        r!   r   z+CommonMiddleware.should_redirect_with_slash>   st   € ô
 × Ò ¨×):Ñ):×)CÑ)CÀCÔ)HÜ˜g y°$Ó7ˆGÜ  ×!2Ñ!2°GÔ<Ü% e¨g×.?Ñ.?Ñ&?ÀÓI�ÙØ Ÿ:™:�DÜ" 4Ð)>ÀÓEÐEØr#   c                 óÔ   — |j                  d¬«      }t        |«      }t        j                  r:|j                  dv r,t        d|j                  |j                  «       |z   dœz  «      ‚|S )zÈ
        Return the full path of the request with a trailing slash appended.

        Raise a RuntimeError if settings.DEBUG is True and request.method is
        DELETE, POST, PUT, or PATCH.
        T)Úforce_append_slash)ÚDELETEÚPOSTÚPUTÚPATCHa"  You called this URL via %(method)s, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining %(method)s data. Change your form to point to %(url)s (note the trailing slash), or set APPEND_SLASH=False in your Django settings.)ÚmethodÚurl)r   r
   r   ÚDEBUGr5   ÚRuntimeErrorr   )r   r   Únew_paths      r!   r   z)CommonMiddleware.get_full_path_with_slashL   sr   € ð ×(Ñ(¸DÐ(ÓAˆä)¨(Ó3ˆÜ�>Š>˜gŸn™nÐ0RÑRÜðMð &Ÿn™nØ"×+Ñ+Ó-°Ñ8ññó
ð 
ð ˆr#   c                 ó  — |j                   dk(  r1| j                  |«      r | j                  | j                  |«      «      S |j                  s<|j                  d«      s+t        t        |j                  «      «      |j                  d<   |S )z¥
        When the status code of the response is 404, it may redirect to a path
        with an appended slash if should_redirect_with_slash() returns True.
        é”  zContent-Length)
Ústatus_coder   r   r   Ú	streamingÚ
has_headerÚstrÚlenÚcontentÚheaders)r   r   Úresponses      r!   Úprocess_responsez!CommonMiddleware.process_responsed   sz   € ð ×Ñ 3Ò&¨4×+JÑ+JÈ7Ô+SØ×/Ñ/°×0MÑ0MÈgÓ0VÓWÐWð ×!Ò!¨(×*=Ñ*=Ð>NÔ*OÜ14´S¸×9IÑ9IÓ5JÓ1KˆH×ÑÐ-Ñ.àˆr#   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r"   r   r   rD   © r#   r!   r   r      s$   „ ñð$ <ÐòXò8òó0r#   r   c                   ó   — e Zd Zd„ Zd„ Zd„ Zy)ÚBrokenLinkEmailsMiddlewarec                 ó¾  — |j                   dk(  rÍt        j                  s½|j                  «       }|j	                  «       }|j
                  j                  dd«      }| j                  ||||«      sm|j
                  j                  dd«      }|j
                  j                  dd«      }t        d| j                  ||«      rdnd›d	|›�d
|›d|›d|›d|›d�	d¬«       |S )z=Send broken link emails for relevant 404 NOT FOUND responses.r;   ÚHTTP_REFERERÚ r   z<none>ÚREMOTE_ADDRzBroken z	INTERNAL zlink on z
Referrer: z
Requested URL: z
User agent: z
IP address: ú
T)Úfail_silently)
r<   r   r7   r   r   r   r   Úis_ignorable_requestr   Úis_internal_request)r   r   rC   Údomainr    ÚrefererÚuaÚips           r!   rD   z+BrokenLinkEmailsMiddleware.process_responsew   sÕ   € à×Ñ 3Ò&¬x¯~ª~Ø×%Ñ%Ó'ˆFØ×(Ñ(Ó*ˆDØ—l‘l×&Ñ& ~°rÓ:ˆGà×,Ñ,¨W°d¸FÀGÔLØ—\‘\×%Ñ%Ð&7¸ÓB�Ø—\‘\×%Ñ% m°XÓ>�Ýð
  $×7Ñ7¸ÀÔHñ (à!#ñ$ñ ñò +2²4ººRðAà"&õð ˆr#   c                 ól   — t        t        j                  dt        j                  |«      z  |«      «      S )ze
        Return True if the referring URL is the same domain as the current
        request.
        z^https?://%s/)ÚboolÚrer-   Úescape)r   rT   rU   s      r!   rS   z.BrokenLinkEmailsMiddleware.is_internal_request‘   s(   € ô ”B—H‘H˜_¬r¯y©y¸Ó/@Ñ@À'ÓJÓKÐKr#   c                 ó&  ‡— |syt         j                  r‰j                  d«      r	|‰dd k(  ry| j                  ||«      sd|v ryt	        |«      }|j
                  d|fv r|j                  ‰k(  ryt        ˆfd„t         j                  D «       «      S )z·
        Return True if the given request *shouldn't* notify the site managers
        according to project settings or in situations outlined by the inline
        comments.
        Tr%   Néÿÿÿÿú?rN   c              3   ó@   •K  — | ]  }|j                  ‰«      –— Œ y ­w)N)r   )Ú.0ÚpatternÚuris     €r!   ú	<genexpr>zBBrokenLinkEmailsMiddleware.is_ignorable_request.<locals>.<genexpr>²   s   øè ø€ ÒR¨7�7—>‘> #×&ÑRùs   ƒ)	r   r(   r*   rS   r   Únetlocr    ÚanyÚIGNORABLE_404_URLS)r   r   rb   rT   rU   Úparsed_referers     `   r!   rR   z/BrokenLinkEmailsMiddleware.is_ignorable_request™   s‘   ø€ ñ Øô × Ò  S§\¡\°#Ô%6¸7ÀcÈ#È2ÀhÒ;NØð ×'Ñ'¨°Ô8¸SÀG¹^Øô " 'Ó*ˆØ× Ñ  R¨ LÑ0°^×5HÑ5HÈCÒ5OØäÓR´h×6QÑ6QÔRÓRÐRr#   N)rE   rF   rG   rD   rS   rR   rI   r#   r!   rK   rK   v   s   „ òò4LóSr#   rK   )rZ   Úurllib.parser   Údjango.confr   Údjango.core.exceptionsr   Údjango.core.mailr   Údjango.httpr   Údjango.urlsr   Údjango.utils.deprecationr	   Údjango.utils.httpr
   r   rK   rI   r#   r!   ú<module>rp      s=   ðÛ 	Ý !å  Ý 3Ý *Ý 5Ý %Ý 4Ý 4ôf�ô fôR<S õ <Sr#   