@@ -49,6 +49,15 @@ def _extract_zip(filename: str, target_dir: str, /) -> None:
4949 fp .write (archive .read (name ))
5050
5151
52+ def _load_theme_conf (theme_dir : os .PathLike [str ] | str ) -> configparser .RawConfigParser :
53+ c = configparser .RawConfigParser ()
54+ config_file_path = path .join (theme_dir , _THEME_CONF )
55+ if not os .path .isfile (config_file_path ):
56+ raise ThemeError (__ ('theme configuration file %r not found' ) % config_file_path )
57+ c .read (config_file_path , encoding = 'utf-8' )
58+ return c
59+
60+
5261class Theme :
5362 """A Theme is a set of HTML templates and configurations.
5463
@@ -69,19 +78,22 @@ def __init__(self, name: str, theme_path: str, theme_factory: HTMLThemeFactory)
6978 self ._theme_dir = path .join (self ._root_dir , name )
7079 _extract_zip (theme_path , self ._theme_dir )
7180
72- self .config = configparser .RawConfigParser ()
73- config_file_path = path .join (self ._theme_dir , _THEME_CONF )
74- if not os .path .isfile (config_file_path ):
75- raise ThemeError (__ ('theme configuration file %r not found' ) % config_file_path )
76- self .config .read (config_file_path , encoding = 'utf-8' )
81+ self .config = _load_theme_conf (self ._theme_dir )
7782
7883 try :
7984 inherit = self .config .get ('theme' , 'inherit' )
8085 except configparser .NoSectionError as exc :
8186 raise ThemeError (__ ('theme %r doesn\' t have "theme" setting' ) % name ) from exc
8287 except configparser .NoOptionError as exc :
8388 raise ThemeError (__ ('theme %r doesn\' t have "inherit" setting' ) % name ) from exc
84-
89+ self ._load_ancestor_theme (inherit , theme_factory , name )
90+
91+ def _load_ancestor_theme (
92+ self ,
93+ inherit : str ,
94+ theme_factory : HTMLThemeFactory ,
95+ name : str ,
96+ ) -> None :
8597 if inherit != 'none' :
8698 try :
8799 self ._base = theme_factory .create (inherit )
0 commit comments