Onionr/onionr/utils/readstatic.py

36 lines
1.1 KiB
Python
Raw Normal View History

2019-09-22 02:45:36 +00:00
"""
Onionr - Private P2P Communication
module to get static directory and read static data files
"""
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from typing import Union
2019-07-18 17:40:48 +00:00
import os
2019-09-22 02:45:36 +00:00
def get_static_dir()->str:
2019-09-23 22:56:05 +00:00
return os.path.dirname(os.path.realpath(__file__)) + '/../../static-data/'
2019-09-22 02:45:36 +00:00
def read_static(file:str, ret_bin:bool=False)->Union[str, bytes]:
2019-07-30 05:19:22 +00:00
static_file = get_static_dir() + file
2019-07-18 17:40:48 +00:00
if ret_bin:
mode = 'rb'
else:
mode = 'r'
with open(static_file, mode) as f:
data = f.read()
2019-09-22 02:45:36 +00:00
return data