ue_pe_web/scripts/03_server/src_students_10/myserver/file.py
2024-03-21 21:43:49 +01:00

90 lines
2.1 KiB
Python

######################################################################
# Copyright (c) Adrien Luxey-Bitri, Boris Baldassari
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
######################################################################
"""
A package for learning network programming in Python.
This module (file) manages operations relative to the file system.
"""
import os.path as path
def resolve_location(res:str, root: str):
"""Returns the path of a resource relative to the root and its extension.
Returns ("", "") if the concatenated path does not exist.
"index.html" is appended to directory paths.
Parameters
----------
res: str
The queried resource path.
root: str
The root directory where to look into for res.
Returns
-------
str
The full disk path of the resource if it exists, or "".
str
The extension of the resource if it exists, or "".
"""
pass
def resolve_path(res:str, root: str):
"""Returns the full disk path of a resource relative to the root.
Beware that resources in a request start with a leading '/'.
If the request points to a directory, then append "index.html" to
the path.
Returns "" if the concatenated path does not exist.
Parameters
----------
res: str
The queried resource path.
root: str
The root directory where to look into for res.
Returns
-------
str
The full disk path of the resource if it exists, or "".
"""
pass
def get_resource(res_path: str):
"""Returns a resource at res_path, its content type and an HTTP code.
The HTTP status code is always 200, as we have already checked the file is present.
Parameters
----------
- res_path: str
Requested resource string.
Returns
-------
bytes
The resource content if it exists (code == 200).
int
A HTTP status code.
"""
pass