File tree Expand file tree Collapse file tree 2 files changed +10
-22
lines changed
Expand file tree Collapse file tree 2 files changed +10
-22
lines changed Original file line number Diff line number Diff line change 77from __future__ import absolute_import
88
99from . import OxmlElement
10- from .exceptions import InvalidXmlError
1110from .ns import qn
12- from .simpletypes import ST_DecimalNumber
13- from .xmlchemy import BaseOxmlElement , RequiredAttribute
11+ from .simpletypes import ST_DecimalNumber , ST_OnOff
12+ from .xmlchemy import BaseOxmlElement , OptionalAttribute , RequiredAttribute
1413
1514
1615class CT_DecimalNumber (BaseOxmlElement ):
@@ -35,25 +34,7 @@ class CT_OnOff(BaseOxmlElement):
3534 Used for ``<w:b>``, ``<w:i>`` elements and others, containing a bool-ish
3635 string in its ``val`` attribute, xsd:boolean plus 'on' and 'off'.
3736 """
38- @property
39- def val (self ):
40- val = self .get (qn ('w:val' ))
41- if val is None :
42- return True
43- elif val in ('0' , 'false' , 'off' ):
44- return False
45- elif val in ('1' , 'true' , 'on' ):
46- return True
47- raise InvalidXmlError ("expected xsd:boolean, got '%s'" % val )
48-
49- @val .setter
50- def val (self , value ):
51- val = qn ('w:val' )
52- if bool (value ) is True :
53- if val in self .attrib :
54- del self .attrib [val ]
55- else :
56- self .set (val , '0' )
37+ val = OptionalAttribute ('w:val' , ST_OnOff , default = True )
5738
5839
5940class CT_String (BaseOxmlElement ):
Original file line number Diff line number Diff line change @@ -177,6 +177,13 @@ class ST_DecimalNumber(XsdInt):
177177 pass
178178
179179
180+ class ST_OnOff (XsdBoolean ):
181+
182+ @classmethod
183+ def convert_from_xml (cls , str_value ):
184+ return str_value in ('1' , 'true' , 'on' )
185+
186+
180187class ST_PositiveCoordinate (XsdLong ):
181188
182189 @classmethod
You can’t perform that action at this time.
0 commit comments