HEX
Server: LiteSpeed
System: Linux srv1.dhviews.com 5.14.0-570.23.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jun 24 11:27:16 EDT 2025 x86_64
User: bdedition (1723)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.9/site-packages/wordfence/wordpress/theme.py
import os
from typing import Optional, Dict

from .extension import Extension, ExtensionLoader


THEME_HEADER_FIELDS = {
        'Name': 'Theme Name',
        'ThemeURI': 'Theme URI',
        'Description': 'Description',
        'Author': 'Author',
        'AuthorURI': 'Author URI',
        'Version': 'Version',
        'Template': 'Template',
        'Status': 'Status',
        'Tags': 'Tags',
        'TextDomain': 'Text Domain',
        'DomainPath': 'Domain Path',
        'RequiresWP': 'Requires at least',
        'RequiresPHP': 'Requires PHP'
    }


class Theme(Extension):
    pass


class ThemeLoader(ExtensionLoader):

    def __init__(self, directory: str, allow_io_errors: bool = False):
        super().__init__(
                'theme',
                directory=directory,
                header_fields=THEME_HEADER_FIELDS,
                allow_io_errors=allow_io_errors
            )

    def _initialize_extension(
                self,
                slug: str,
                version: Optional[str],
                header: Dict[str, str],
                path: bytes
            ):
        return Theme(
                slug=slug,
                version=version,
                header=header,
                path=path
            )

    def _process_entry(self, entry: os.DirEntry) -> Optional[Theme]:
        if not entry.is_dir():
            return None
        path = os.path.join(entry.path, b'style.css')
        if not os.path.isfile(path):
            return None
        slug = os.fsdecode(entry.name)
        return self.load(slug, path, base_path=entry.path)