-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathsettings.py
More file actions
54 lines (46 loc) · 1.43 KB
/
settings.py
File metadata and controls
54 lines (46 loc) · 1.43 KB
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
# encoding: utf-8
"""
|SettingsPart| and closely related objects
"""
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
import os
from ..opc.constants import CONTENT_TYPE as CT
from ..opc.packuri import PackURI
from ..opc.part import XmlPart
from ..oxml import parse_xml
from ..settings import Settings
class SettingsPart(XmlPart):
"""
Document-level settings part of a WordprocessingML (WML) package.
"""
@classmethod
def default(cls, package):
"""
Return a newly created settings part, containing a default
`w:settings` element tree.
"""
partname = PackURI('/word/settings.xml')
content_type = CT.WML_SETTINGS
element = parse_xml(cls._default_settings_xml())
return cls(partname, content_type, element, package)
@property
def settings(self):
"""
A |Settings| proxy object for the `w:settings` element in this part,
containing the document-level settings for this document.
"""
return Settings(self.element)
@classmethod
def _default_settings_xml(cls):
"""
Return a bytestream containing XML for a default settings part.
"""
path = os.path.join(
os.path.split(__file__)[0], '..', 'templates',
'default-settings.xml'
)
with open(path, 'rb') as f:
xml_bytes = f.read()
return xml_bytes