
    Mf-                     (   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlmZm	Z	 d dl
mZ 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  e            Z e j                    Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#	 	 	 	 	 	 	 	 	 	 ddZ$dS )    N)fnmatch)Pathisfilejoin)parse_qs   )	_validate)AttributeDict)get_relative_path)context_value)get_appc                   
 t           j        
g d}|                     d          d         }g }t          j                            
          r 
fdt          j        
          D             }d}d}|D ]e}|                    d          \  }}}	|	                                |v r4||k    s||	                    dd          k    r|c S |dk    r|}|d	k    r|}f|r|S |S )
z
    Return:
    - A page specific image: `assets/<module>.<extension>` is used, e.g. `assets/weekly_analytics.png`
    - A generic app image at `assets/app.<extension>`
    - A logo at `assets/logo.<extension>`
    )apngavifgifjpegjpgpngsvgwebp.c                 N    g | ]!}t          t          |                    |"S  r   ).0fassets_folders     J/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/dash/_pages.py
<listcomp>z _infer_image.<locals>.<listcomp>$   s@     
 
 
F4q;Q;Q4R4R

 
 
    N_-applogo)
CONFIGr   splitospathexistslistdir	partitionlowerreplace)modulevalid_extensionspage_idfiles_in_assetsapp_file	logo_filefnfn_without_extensionr"   	extensionr   s             @r   _infer_imager8      s'    (MSSSll3#GO	w~~m$$ 

 
 
 
z-00
 
 
 HI  -/\\#->->*a?? 000$//'7??3+D+DDD			#u,,#v--	 r!   c                     |                      d          d                             dd                                          S )Nr   r   r"    )r'   r.   
capitalizemodule_names    r   _module_name_to_page_namer>   >   s7    S!!"%--c377BBDDDr!   c                    |t           j        rt          t          t           j                  j                  }|                     |          d                             dd                              dd                                          }nS|                     dd                              dd                                          }nt          j	        dd|          }|
                    d          sd|z   n|}|S )Nr   r"   r#   r   /<.*?>none)r&   pages_folderstrr   namer'   r.   r-   resub
startswith)r=   templatepages_moduler)   s       r   _infer_pathrK   B   s     		KtF$788=>>L!!,//3c""c""	 D &&sC0088cBBHHJJDD vgvx00!__S11;3::tDKr!   c                 x    | t           j        v o,t          t           j        |          j                  j        dk    S )Nz__init__.py)sysmodulesr   __file__rE   r<   s    r   _module_name_is_packagerP   V   s4    s{" 	J[)2338MIr!   c                     t          |                               dd                              t          j                                      t          j        d          S )Nz.py r   )rD   r.   stripr(   sep)r)   s    r   _path_to_module_namerU   ]   s@    t99UB''--bf55==bfcJJJr!   c                    |                      t          j                  d         }t          |          }t          j                            t          j                  }t          j                            |          r"t          j        t          |          d          }nt          j        }t          |          }| d| }t          t          j                  rt          j         d| }|S )Nr   r   )r'   r&   rC   rU   flaskhelpersget_root_pathrE   rH   lenrP   )	page_pathrelative_pathr/   	proj_rootparent_pathparent_moduler=   s          r   _infer_module_namer`   a   s    OOF$788<M!-00F++FK88I%%i00 *)#i..*:*:;)(55M"--V--Kv{++ 544{44r!   c                     | r*t          |           dk    r| d         dk    r| dd          } ni S i }t          |                                           D ]'\  }}t          |          dk    r|d         n|}|||<   (|S )Nr   ?r	   )rZ   r   items)search	parsed_qskvs       r   _parse_query_stringrh   r   s     #f++//fQi3&6&6	I6""((**  AFFaKKAaDDQ	!r!   c                 V   t          j        dd|          }t          j        dd|          }t          | |          sdS t          j        d|          }t          j        ||           }t	          |d         t
                    r|d         n|}t          t          ||                    S )z
    creates the dict of path variables passed to the layout
    e.g. path_template= "/asset/<asset_id>"
         if pathname provided by the browser is "/assets/a100"
         returns **{"asset_id": "a100"}
    rA   *z(.*)Nz<(.*?)>r   )rF   rG   r   findall
isinstancetupledictzip)pathnamepath_templatewildcard_patternvar_pattern	var_names	variabless         r   _parse_path_variablesrv      s     vgsM::&&-88K 8-.. t 
9m44I 
;11I *9Q< ? ?N	!YIIy))***r!   c                       fd}|S )Nc                  0    t          j         d          S )Ni-  )code)rW   redirect)redirect_tos   r   rz   z+_create_redirect_function.<locals>.redirect   s    ~k4444r!   r   )r{   rz   s   ` r   _create_redirect_functionr|      s#    5 5 5 5 5 Or!   c           
          t                      }| ret          |           rX| D ]W}|                    |          }|j                            ||t          |                    |                               Td S d S d S )N)r   rZ   r   serveradd_url_ruler|   )redirect_fromr)   r$   rz   fullnames        r   _set_redirectr      s    
))C ]++ % 	 	H,,X66HJ##)#*?*?*E*EFF      	 	r!   c           
      B   t          j                                        d          rdS t          j        t                     t          t          j        |           ||||nt          | |          |||nt          |                     }|	                    |||n|d                     |j	        d|r|nd|||
d| |	                    |||nt          |           |           |	                    t          |	|d	                   
           |t          | <   |d         rt          j        |d                    |
|
t          |          d<   t          d t                                          D                       }t                                          D ]5}|d	         dk    r|sdn|d         |d<   t!          |d	                   |d<   6t#          t                                          d           D ]"}t                              |d                    #dS )a  
    Assigns the variables to `dash.page_registry` as an `OrderedDict`
    (ordered by `order`).

    `dash.page_registry` is used by `pages_plugin` to set up the layouts as
    a multi-page Dash app. This includes the URL routing callbacks
    (using `dcc.Location`) and the HTML templates to include title,
    meta description, and the meta description image.

    `dash.page_registry` can also be used by Dash developers to create the
    page navigation links or by template authors.

    - `module`:
       The module path where this page's `layout` is defined. Often `__name__`.

    - `path`:
       URL Path, e.g. `/` or `/home-page`.
       If not supplied, will be inferred from the `path_template` or `module`,
       e.g. based on path_template: `/asset/<asset_id` to `/asset/none`
       e.g. based on module: `pages.weekly_analytics` to `/weekly-analytics`

    - `relative_path`:
        The path with `requests_pathname_prefix` prefixed before it.
        Use this path when specifying local URL paths that will work
        in environments regardless of what `requests_pathname_prefix` is.
        In some deployment environments, like Dash Enterprise,
        `requests_pathname_prefix` is set to the application name,
        e.g. `my-dash-app`.
        When working locally, `requests_pathname_prefix` might be unset and
        so a relative URL like `/page-2` can just be `/page-2`.
        However, when the app is deployed to a URL like `/my-dash-app`, then
        `relative_path` will be `/my-dash-app/page-2`.

    - `path_template`:
       Add variables to a URL by marking sections with <variable_name>. The layout function
       then receives the <variable_name> as a keyword argument.
       e.g. path_template= "/asset/<asset_id>"
            then if pathname in browser is "/assets/a100" then layout will receive **{"asset_id":"a100"}

    - `name`:
       The name of the link.
       If not supplied, will be inferred from `module`,
       e.g. `pages.weekly_analytics` to `Weekly analytics`

    - `order`:
       The order of the pages in `page_registry`.
       If not supplied, then the filename is used and the page with path `/` has
       order `0`

    - `title`:
       (string or function) The name of the page <title>. That is, what appears in the browser title.
       If not supplied, will use the supplied `name` or will be inferred by module,
       e.g. `pages.weekly_analytics` to `Weekly analytics`

    - `description`:
       (string or function) The <meta type="description"></meta>.
       If not supplied, then nothing is supplied.

    - `image`:
       The meta description image used by social media platforms.
       If not supplied, then it looks for the following images in `assets/`:
        - A page specific image: `assets/<module>.<extension>` is used, e.g. `assets/weekly_analytics.png`
        - A generic app image at `assets/app.<extension>`
        - A logo at `assets/logo.<extension>`
        When inferring the image file, it will look for the following extensions:
        APNG, AVIF, GIF, JPEG, JPG, PNG, SVG, WebP.

    -  `image_url`:
       Overrides the image property and sets the `<image>` meta tag to the provided image URL.

    - `redirect_from`:
       A list of paths that should redirect to this page.
       For example: `redirect_from=['/v2', '/v3']`

    - `layout`:
       The layout function or component for this page.
       If not supplied, then looks for `layout` from within the supplied `module`.

    - `**kwargs`:
       Arbitrary keyword arguments that can be stored

    ***

    `page_registry` stores the original property that was passed in under
    `supplied_<property>` and the coerced property under `<property>`.
    For example, if this was called:
    ```
    register_page(
        'pages.historical_outlook',
        name='Our historical view',
        custom_key='custom value'
    )
    ```
    Then this will appear in `page_registry`:
    ```
    OrderedDict([
        (
            'pages.historical_outlook',
            dict(
                module='pages.historical_outlook',

                supplied_path=None,
                path='/historical-outlook',

                supplied_name='Our historical view',
                name='Our historical view',

                supplied_title=None,
                title='Our historical view'

                supplied_layout=None,
                layout=<function pages.historical_outlook.layout>,

                custom_key='custom value'
            )
        ),
    ])
    ```
    ignore_register_pageN)r/   supplied_pathrq   r)   supplied_namerE   rE   )supplied_titletitlerR   )descriptionordersupplied_ordersupplied_layout)supplied_imageimage	image_urlr)   )r   rq   layoutc              3   *   K   | ]}|d          duV  dS )r   Nr   )r   ps     r   	<genexpr>z register_page.<locals>.<genexpr>[  s>        ,-
4'     r!   r@   r   r   r   r\   c                 d    t          |                     d| d                             | d         fS )Nr   r/   )rD   get)is    r   <lambda>zregister_page.<locals>.<lambda>h  s)    s155!H+66778E r!   )keyr/   r   )r   r   r
   validate_use_pagesr&   rn   validate_module_namerK   r>   updater8   r   PAGE_REGISTRYvalidate_templateanyvaluesr   sortedmove_to_end)r/   r)   rq   rE   r   r   r   r   r   r   r   kwargspageorder_suppliedr   s                  r   register_pager      s   J 566  (((-f55#%TT;v}+M+M%TT+DV+L+L  D 	KK)uutF|     DK #.6KKB	 
    	KK)uu|F/C/C    
 	KKmM4<HHKIII M&O ;#D$9:::*0fh'   1>1E1E1G1G    N !!## : :6c!!.!AAa@P>Q 	
'
 /qy99/ EE   2 2 	!!$x.1111	2 2r!   )
NNNNNNNNNN)%collectionsr(   rF   rM   r   pathlibr   os.pathr   r   urllib.parser   rW   rR   r
   _utilsr   
_get_pathsr   _callback_contextr   _get_appr   r&   OrderedDictr   r8   r>   rK   rP   rU   r`   rh   rv   r|   r   r   r   r!   r   <module>r      s       				 				 



                             ! ! ! ! ! !        ! ! ! ! ! ! ) ) ) ) ) ) , , , , , ,       
''))$ $ $NE E E  (  K K K  "
 
 
+ + +6  	 	 	 
	


}2 }2 }2 }2 }2 }2r!   