Coverage for src/pyrsslocal/rss/rss_flask_helper.py: 0%

18 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2023-02-02 02:59 +0100

1""" 

2@file 

3@brief Helpers for ``rss_flask.py``. 

4""" 

5 

6import os 

7 

8 

9def root_dir(): 

10 """ 

11 Returns this directory. 

12 @return this path 

13 """ 

14 return os.path.abspath(os.path.dirname(__file__)) 

15 

16 

17def load_page(filename): 

18 """ 

19 Loads the content of a file. 

20 """ 

21 fold = root_dir() 

22 full = os.path.abspath(os.path.join(fold, filename)) 

23 with open(full, "r", encoding="utf8") as f: 

24 content = f.read() 

25 return content 

26 

27 

28def get_text_file(filename): 

29 """ 

30 Returns the content of a text filename. 

31 

32 @param filename relative filename 

33 @return content 

34 """ 

35 src = os.path.join(root_dir(), filename) 

36 with open(src, "r", encoding="utf8") as f: 

37 return f.read() 

38 

39 

40def get_binary_file(filename): 

41 """ 

42 Returns the content of a binary filename. 

43 

44 @param filename relative filename 

45 @return content 

46 """ 

47 src = os.path.join(root_dir(), filename) 

48 with open(src, "rb") as f: 

49 return f.read() 

50 

51# -- HELP BEGIN EXCLUDE -- 

52 

53 

54main_page_content = load_page("rss_reader.html") 

55 

56 

57# -- HELP END EXCLUDE --