U
    ZfN                     @   sR   d dl mZ d dlmZ e Zdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dS )   )AttributeDict)
exceptionsc                 C   s
   t t| S )N)app_get_asset_urlCONFIGpath r   3/tmp/pip-unpacked-wheel-47crqvv_/dash/_get_paths.pyget_asset_url   s    r
   c                 C   s2   | j r| j }n| j}d|d| jd|gS )N/)Zassets_external_pathrequests_pathname_prefixjoinrstripZassets_url_pathlstrip)configr   prefixr   r   r	   r      s    
r   c                 C   s   t tj| S )a  
    Return a path with `requests_pathname_prefix` prefixed before it.
    Use this function 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
    `dash.get_relative_path('/page-2')` will return `/my-dash-app/page-2`.
    This can be used as an alternative to `get_asset_url` as well with
    `dash.get_relative_path('/assets/logo.png')`

    Use this function with `dash.strip_relative_path` in callbacks that
    deal with `dcc.Location` `pathname` routing.
    That is, your usage may look like:
    ```
    app.layout = html.Div([
        dcc.Location(id='url'),
        html.Div(id='content')
    ])
    @dash.callback(Output('content', 'children'), [Input('url', 'pathname')])
    def display_content(path):
        page_name = dash.strip_relative_path(path)
        if not page_name:  # None or ''
            return html.Div([
                dcc.Link(href=dash.get_relative_path('/page-1')),
                dcc.Link(href=dash.get_relative_path('/page-2')),
            ])
        elif page_name == 'page-1':
            return chapters.page_1
        if page_name == "page-2":
            return chapters.page_2
    ```
    )app_get_relative_pathr   r   r   r   r   r	   get_relative_path   s    %r   c                 C   s^   | dkr|dkrdS | dkr(|dkr(| S | dsDtd| dd| d|dgS )Nr    zf
            Paths that aren't prefixed with a leading / are not supported.
            You supplied: 
            )
startswithr   UnsupportedRelativePathr   r   r   Zrequests_pathnamer   r   r   r	   r   B   s    
r   c                 C   s   t tj| S )a  
    Return a path with `requests_pathname_prefix` and leading and trailing
    slashes stripped from it. Also, if None is passed in, None is returned.
    Use this function with `get_relative_path` in callbacks that deal
    with `dcc.Location` `pathname` routing.
    That is, your usage may look like:
    ```
    app.layout = html.Div([
        dcc.Location(id='url'),
        html.Div(id='content')
    ])
    @dash.callback(Output('content', 'children'), [Input('url', 'pathname')])
    def display_content(path):
        page_name = dash.strip_relative_path(path)
        if not page_name:  # None or ''
            return html.Div([
                dcc.Link(href=dash.get_relative_path('/page-1')),
                dcc.Link(href=dash.get_relative_path('/page-2')),
            ])
        elif page_name == 'page-1':
            return chapters.page_1
        if page_name == "page-2":
            return chapters.page_2
    ```
    Note that `chapters.page_1` will be served if the user visits `/page-1`
    _or_ `/page-1/` since `strip_relative_path` removes the trailing slash.

    Also note that `strip_relative_path` is compatible with
    `get_relative_path` in environments where `requests_pathname_prefix` set.
    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
    `dash.get_relative_path('/page-2')` will return `/my-dash-app/page-2`

    The `pathname` property of `dcc.Location` will return '`/my-dash-app/page-2`'
    to the callback.
    In this case, `dash.strip_relative_path('/my-dash-app/page-2')`
    will return `'page-2'`

    For nested URLs, slashes are still included:
    `dash.strip_relative_path('/page-1/sub-page-1/')` will return
    `page-1/sub-page-1`
    ```
    )app_strip_relative_pathr   r   r   r   r   r	   strip_relative_pathQ   s    /r   c                 C   s   |d krd S | dkr$| | dr6| dkrN| dsNtd| d|  d| dkrz| | drz|| ddd}|dS )Nr   zs
            Paths that aren't prefixed with requests_pathname_prefix are not supported.
            You supplied: z" and requests_pathname_prefix was r   r   r   )r   r   r   r   replacestripr   r   r   r	   r      s0    r   N)_utilsr   r   r   r   r
   r   r   r   r   r   r   r   r   r	   <module>   s   (2