-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler_registry.py
68 lines (62 loc) · 2.58 KB
/
handler_registry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from .base_handler import BaseFileHandler
from .handlers import TextFileHandler, ElfFileHandler, PythonFileHandler
from .handlers import PerlFileHandler, CplusFileHandler, JavaFileHandler
from .handlers import RustFileHandler, RubyFileHandler, ObjectivecFileHandler
from .handlers import JvmFileHandler, OctetStreamFileHandler
from .handlers import SharedLibFileHandler, ArchiveLibFileHandler
from .handlers import MachOSFileHandler
HANDLER_REGISTRY = {
# Plan Text and String
'text/plain': TextFileHandler,
'text/x-makefile': TextFileHandler,
'text/markdown': TextFileHandler,
'text/css': TextFileHandler,
'text/html': TextFileHandler,
'text/xml': TextFileHandler,
'text/csv': TextFileHandler,
'application/pls+xml': TextFileHandler,
'application/x-mpegurl': TextFileHandler,
'application/json': TextFileHandler,
'text/x-tex': TextFileHandler,
'text/vtt': TextFileHandler,
'text/x-asm': TextFileHandler,
'text/x-m4': TextFileHandler,
'text/x-shellscript': TextFileHandler,
'text/cache-manifest': TextFileHandler,
'text/javascript': TextFileHandler,
'application/javascript': TextFileHandler,
'application/json': TextFileHandler,
'application/x-sh': TextFileHandler,
'application/x-tex': TextFileHandler,
'application/x-texinfo': TextFileHandler,
'application/xml': TextFileHandler,
'application/postscript': TextFileHandler,
'application/cu-seeme': TextFileHandler,
'application/x-msdownload': TextFileHandler,
# Pygments based extraction
'text/x-c': CplusFileHandler,
'text/x-c++': CplusFileHandler,
'text/x-python': PythonFileHandler,
'application/x-python-code': PythonFileHandler,
'text/x-script.python': PythonFileHandler,
'text/x-perl': PerlFileHandler,
'text/x-java-source': JavaFileHandler,
'application/java-vm': JvmFileHandler,
'text/rust': RustFileHandler,
'text/x-rust': RustFileHandler,
'application/rls-services+xml': RustFileHandler,
'text/ruby': RubyFileHandler,
'text/x-ruby': RubyFileHandler,
'text/x-objective-c': ObjectivecFileHandler,
# Library Specific
'application/octet-stream': OctetStreamFileHandler,
'application/x-executable': ElfFileHandler,
'application/x-sharedlib': SharedLibFileHandler,
'application/x-archive': ArchiveLibFileHandler,
'application/x-mach-binary': MachOSFileHandler,
}
def register_handler(mime_type, handler_class):
"""Registers a new handler for a given MIME type."""
HANDLER_REGISTRY[mime_type] = handler_class
def get_handler(mime_type):
return HANDLER_REGISTRY.get(mime_type)