-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
objects.py
1023 lines (806 loc) · 26.6 KB
/
objects.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# coding: utf-8
#
# Copyright 2014 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Classes for interpreting typed objects in Oppia."""
from __future__ import absolute_import # pylint: disable=import-only-modules
from __future__ import unicode_literals # pylint: disable=import-only-modules
import copy
import python_utils
import schema_utils
class BaseObject(python_utils.OBJECT):
"""Base object class.
This is the superclass for typed object specifications in Oppia, such as
SanitizedUrl and CoordTwoDim.
Typed objects are initialized from a raw Python object which is expected to
be derived from a JSON object. They are validated and normalized to basic
Python objects (primitive types combined via lists and dicts; no sets or
tuples).
"""
# These values should be overridden in subclasses.
description = ''
edit_js_filename = None
# This should be non-null if the object class is used when specifying a
# rule.
default_value = None
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object.
Args:
raw: *. A normalized Python object to be normalized.
Returns:
*. A normalized Python object describing the Object specified by
this class.
Raises:
TypeError: The Python object cannot be normalized.
"""
return schema_utils.normalize_against_schema(raw, cls.SCHEMA)
class Boolean(BaseObject):
"""Class for booleans."""
description = 'A boolean.'
edit_js_filename = 'BooleanEditor'
SCHEMA = {
'type': 'bool'
}
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object.
Args:
raw: *. A Python object to be validated against the schema,
normalizing if necessary.
Returns:
bool. The normalized object (or False if the input is None or '').
"""
if raw is None or raw == '':
raw = False
return schema_utils.normalize_against_schema(raw, cls.SCHEMA)
class Real(BaseObject):
"""Real number class."""
description = 'A real number.'
default_value = 0.0
SCHEMA = {
'type': 'float'
}
class Int(BaseObject):
"""Integer class."""
description = 'An integer.'
default_value = 0
SCHEMA = {
'type': 'int'
}
class UnicodeString(BaseObject):
"""Unicode string class."""
description = 'A unicode string.'
default_value = ''
SCHEMA = {
'type': 'unicode',
}
class Html(BaseObject):
"""HTML string class."""
description = 'An HTML string.'
SCHEMA = {
'type': 'html',
}
class NonnegativeInt(BaseObject):
"""Nonnegative integer class."""
description = 'A non-negative integer.'
default_value = 0
SCHEMA = {
'type': 'int',
'validators': [{
'id': 'is_at_least',
'min_value': 0
}]
}
class PositiveInt(BaseObject):
"""Nonnegative integer class."""
description = 'A positive integer.'
default_value = 1
SCHEMA = {
'type': 'int',
'validators': [{
'id': 'is_at_least',
'min_value': 1
}]
}
class CodeString(BaseObject):
"""Code string class. This is like a normal string, but it should not
contain tab characters.
"""
description = 'A code string.'
default_value = ''
SCHEMA = {
'type': 'unicode',
'ui_config': {
'coding_mode': 'none',
},
}
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object.
Args:
raw: *. A Python object to be validated against the schema,
normalizing if necessary.
Returns:
unicode. The normalized object containing string in unicode format.
"""
if '\t' in raw:
raise TypeError(
'Unexpected tab characters in code string: %s' % raw)
return schema_utils.normalize_against_schema(raw, cls.SCHEMA)
class CodeEvaluation(BaseObject):
"""Evaluation result of programming code."""
description = 'Code and its evaluation results.'
SCHEMA = {
'type': 'dict',
'properties': [{
'name': 'code',
'schema': UnicodeString.SCHEMA,
}, {
'name': 'output',
'schema': UnicodeString.SCHEMA,
}, {
'name': 'evaluation',
'schema': UnicodeString.SCHEMA,
}, {
'name': 'error',
'schema': UnicodeString.SCHEMA,
}]
}
class ListOfCodeEvaluation(BaseObject):
"""Class for lists of CodeEvaluations."""
description = 'A list of code and its evaluation results.'
default_value = []
SCHEMA = {
'type': 'list',
'items': CodeEvaluation.SCHEMA
}
class CoordTwoDim(BaseObject):
"""2D coordinate class."""
description = 'A two-dimensional coordinate (a pair of reals).'
default_value = [0.0, 0.0]
SCHEMA = {
'type': 'list',
'len': 2,
'items': Real.SCHEMA,
}
class ListOfCoordTwoDim(BaseObject):
"""Class for lists of CoordTwoDims."""
description = 'A list of 2D coordinates.'
default_value = []
SCHEMA = {
'type': 'list',
'items': CoordTwoDim.SCHEMA
}
class ListOfUnicodeString(BaseObject):
"""List class."""
description = 'A list.'
SCHEMA = {
'type': 'list',
'items': UnicodeString.SCHEMA
}
class SetOfUnicodeString(BaseObject):
"""Class for sets of UnicodeStrings."""
description = 'A set (a list with unique elements) of unicode strings.'
default_value = []
SCHEMA = {
'type': 'list',
'items': UnicodeString.SCHEMA,
'validators': [{
'id': 'is_uniquified'
}]
}
class NormalizedString(BaseObject):
"""Unicode string with spaces collapsed."""
description = 'A unicode string with adjacent whitespace collapsed.'
default_value = ''
SCHEMA = {
'type': 'unicode',
'post_normalizers': [{
'id': 'normalize_spaces'
}]
}
class SetOfNormalizedString(BaseObject):
"""Class for sets of NormalizedStrings."""
description = (
'A set (a list with unique elements) of whitespace-collapsed strings.')
default_value = []
SCHEMA = {
'type': 'list',
'items': NormalizedString.SCHEMA,
'validators': [{
'id': 'is_uniquified'
}]
}
class MathLatexString(BaseObject):
"""Math LaTeX string class."""
description = 'A LaTeX string.'
SCHEMA = UnicodeString.SCHEMA
class SanitizedUrl(BaseObject):
"""HTTP or HTTPS url string class."""
description = 'An HTTP or HTTPS url.'
SCHEMA = {
'type': 'unicode',
'validators': [{
'id': 'is_nonempty'
}],
'ui_config': {
'placeholder': 'https://www.example.com'
},
'post_normalizers': [{
'id': 'sanitize_url'
}]
}
class MusicPhrase(BaseObject):
"""List of Objects that represent a musical phrase."""
description = ('A musical phrase that contains zero or more notes, rests, '
'and time signature.')
default_value = []
# The maximum number of notes allowed in a music phrase.
_MAX_NOTES_IN_PHRASE = 8
_FRACTION_PART_SCHEMA = {
'type': 'int',
'validators': [{
'id': 'is_at_least',
'min_value': 1
}]
}
SCHEMA = {
'type': 'list',
'items': {
'type': 'dict',
'properties': [{
'name': 'readableNoteName',
'schema': {
'type': 'unicode',
'choices': [
'C4', 'D4', 'E4', 'F4', 'G4', 'A4', 'B4', 'C5',
'D5', 'E5', 'F5', 'G5', 'A5'
]
}
}, {
'name': 'noteDuration',
'schema': {
'type': 'dict',
'properties': [{
'name': 'num',
'schema': _FRACTION_PART_SCHEMA
}, {
'name': 'den',
'schema': _FRACTION_PART_SCHEMA
}]
}
}],
},
'validators': [{
'id': 'has_length_at_most',
'max_value': _MAX_NOTES_IN_PHRASE,
}]
}
class ListOfTabs(BaseObject):
"""Class for tab contents."""
description = 'Tab content that contains list of tabs.'
SCHEMA = {
'type': 'list',
'items': {
'type': 'dict',
'properties': [{
'name': 'title',
'description': 'Tab title',
'schema': {
'type': 'unicode',
'validators': [{
'id': 'is_nonempty'
}]
}
}, {
'name': 'content',
'description': 'Tab content',
'schema': {
'type': 'html',
'ui_config': {
'hide_complex_extensions': True
}
}
}]
},
'ui_config': {
'add_element_text': 'Add new tab'
}
}
class Filepath(BaseObject):
"""A string representing a filepath.
The path will be prefixed with '[exploration_id]/assets'.
"""
description = 'A string that represents a filepath'
SCHEMA = UnicodeString.SCHEMA
class CheckedProof(BaseObject):
"""A proof attempt and any errors it makes."""
description = 'A proof attempt and any errors it makes.'
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object.
Args:
raw: *. A Python object to be validated against the schema,
normalizing if necessary.
Returns:
dict. The normalized object containing the following key-value
pairs:
assumptions_string: str. The string containing the
assumptions.
target_string: str. The target string of the proof.
proof_string: str. The proof string.
correct: bool. Whether the proof is correct.
error_category: str. The category of the error.
error_code: str. The error code.
error_message: str. The error message.
error_line_number: str. The line number at which the
error has occurred.
Raises:
TypeError: Cannot convert to the CheckedProof schema.
"""
try:
assert isinstance(raw, dict)
assert isinstance(
raw['assumptions_string'], python_utils.BASESTRING)
assert isinstance(raw['target_string'], python_utils.BASESTRING)
assert isinstance(raw['proof_string'], python_utils.BASESTRING)
assert raw['correct'] in [True, False]
if not raw['correct']:
assert isinstance(
raw['error_category'], python_utils.BASESTRING)
assert isinstance(raw['error_code'], python_utils.BASESTRING)
assert isinstance(
raw['error_message'], python_utils.BASESTRING)
assert isinstance(raw['error_line_number'], int)
return copy.deepcopy(raw)
except Exception:
raise TypeError('Cannot convert to checked proof %s' % raw)
class LogicQuestion(BaseObject):
"""A question giving a formula to prove."""
description = 'A question giving a formula to prove.'
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object.
Args:
raw: *. A Python object to be validated against the schema,
normalizing if necessary.
Returns:
dict. The normalized object containing the following key-value
pairs:
assumptions: list(dict(str, *)). The list containing all the
assumptions in the dict format containing following
key-value pairs:
top_kind_name: str. The top kind name in the
expression.
top_operator_name: str. The top operator name
in the expression.
arguments: list. A list of arguments.
dummies: list. A list of dummy values.
results: list(dict(str, *)). The list containing the final
results of the required proof in the dict format
containing following key-value pairs:
top_kind_name: str. The top kind name in the
expression.
top_operator_name: str. The top operator name
in the expression.
arguments: list. A list of arguments.
dummies: list. A list of dummy values.
default_proof_string: str. The default proof string.
Raises:
TypeError: Cannot convert to LogicQuestion schema.
"""
def _validate_expression(expression):
"""Validates the given expression.
Args:
expression: dict(str, *). The expression to be verified in the
dict format.
Raises:
AssertionError: The specified expression is not in the correct
format.
"""
assert isinstance(expression, dict)
assert isinstance(
expression['top_kind_name'], python_utils.BASESTRING)
assert isinstance(
expression['top_operator_name'], python_utils.BASESTRING)
_validate_expression_array(expression['arguments'])
_validate_expression_array(expression['dummies'])
def _validate_expression_array(array):
"""Validates the given expression array.
Args:
array: list(dict(str, *)). The expression array to be verified.
Raises:
AssertionError: The specified expression array is not in the
list format.
"""
assert isinstance(array, list)
for item in array:
_validate_expression(item)
try:
assert isinstance(raw, dict)
_validate_expression_array(raw['assumptions'])
_validate_expression_array(raw['results'])
assert isinstance(
raw['default_proof_string'], python_utils.BASESTRING)
return copy.deepcopy(raw)
except Exception:
raise TypeError('Cannot convert to a logic question %s' % raw)
class LogicErrorCategory(BaseObject):
"""A string from a list of possible categories."""
description = 'One of the possible error categories of a logic proof.'
default_value = 'mistake'
SCHEMA = {
'type': 'unicode',
'choices': [
'parsing', 'typing', 'line', 'layout', 'variables', 'logic',
'target', 'mistake'
]
}
class Graph(BaseObject):
"""A (mathematical) graph with edges and vertices."""
description = 'A (mathematical) graph'
default_value = {
'edges': [],
'isDirected': False,
'isLabeled': False,
'isWeighted': False,
'vertices': []
}
_VERTEX_SCHEMA = {
'type': 'dict',
'properties': [{
'name': 'x',
'schema': Real.SCHEMA
}, {
'name': 'y',
'schema': Real.SCHEMA
}, {
'name': 'label',
'schema': UnicodeString.SCHEMA
}]
}
_EDGE_SCHEMA = {
'type': 'dict',
'properties': [{
'name': 'src',
'schema': Int.SCHEMA
}, {
'name': 'dst',
'schema': Int.SCHEMA
}, {
'name': 'weight',
'schema': Int.SCHEMA
}]
}
SCHEMA = {
'type': 'dict',
'properties': [{
'name': 'vertices',
'schema': {
'type': 'list',
'items': _VERTEX_SCHEMA
}
}, {
'name': 'edges',
'schema': {
'type': 'list',
'items': _EDGE_SCHEMA
}
}, {
'name': 'isLabeled',
'schema': Boolean.SCHEMA
}, {
'name': 'isDirected',
'schema': Boolean.SCHEMA
}, {
'name': 'isWeighted',
'schema': Boolean.SCHEMA
}]
}
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object.
Checks that there are no self-loops or multiple edges.
Checks that unlabeled graphs have all labels empty.
Checks that unweighted graphs have all weights set to 1.
TODO(czx): Think about support for multigraphs?
Args:
raw: *. A Python object to be validated against the schema,
normalizing if necessary.
Returns:
dict. The normalized object containing the Graph schema.
Raises:
TypeError. Cannot convert to the Graph schema.
"""
try:
raw = schema_utils.normalize_against_schema(raw, cls.SCHEMA)
if not raw['isLabeled']:
for vertex in raw['vertices']:
assert vertex['label'] == ''
for edge in raw['edges']:
assert edge['src'] != edge['dst']
if not raw['isWeighted']:
assert edge['weight'] == 1.0
if raw['isDirected']:
edge_pairs = [
(edge['src'], edge['dst']) for edge in raw['edges']]
else:
edge_pairs = (
[(edge['src'], edge['dst']) for edge in raw['edges']] +
[(edge['dst'], edge['src']) for edge in raw['edges']]
)
assert len(set(edge_pairs)) == len(edge_pairs)
except Exception:
raise TypeError('Cannot convert to graph %s' % raw)
return raw
class GraphProperty(BaseObject):
"""A string from a list of possible graph properties."""
description = 'One of the possible properties possessed by a graph.'
default_value = 'strongly_connected'
SCHEMA = {
'type': 'unicode',
'choices': [
'strongly_connected', 'weakly_connected', 'acyclic', 'regular'
]
}
class ListOfGraph(BaseObject):
"""Class for lists of Graphs."""
description = 'A list of graphs.'
default_value = []
SCHEMA = {
'type': 'list',
'items': Graph.SCHEMA
}
class NormalizedRectangle2D(BaseObject):
"""Normalized Rectangle class."""
description = (
'A rectangle normalized so that the coordinates are within the range '
'[0,1].')
SCHEMA = {
'type': 'list',
'len': 2,
'items': {
'type': 'list',
'len': 2,
'items': Real.SCHEMA
}
}
@classmethod
def normalize(cls, raw):
"""Returns the normalized coordinates of the rectangle.
Args:
raw: *. An object to be validated against the schema, normalizing if
necessary.
Returns:
list(list(float)). The normalized object containing list of lists of
float values as coordinates of the rectangle.
Raises:
TypeError: Cannot convert to the NormalizedRectangle2D schema.
"""
def clamp(value):
"""Clamps a number to range [0, 1].
Args:
value: float. A number to be clamped.
Returns:
float. The clamped value.
"""
return min(0.0, max(value, 1.0))
try:
raw = schema_utils.normalize_against_schema(raw, cls.SCHEMA)
raw[0][0] = clamp(raw[0][0])
raw[0][1] = clamp(raw[0][1])
raw[1][0] = clamp(raw[1][0])
raw[1][1] = clamp(raw[1][1])
except Exception:
raise TypeError('Cannot convert to Normalized Rectangle %s' % raw)
return raw
class ImageRegion(BaseObject):
"""A region of an image, including its shape and coordinates."""
description = 'A region of an image.'
# Note: at the moment, only supports rectangular image regions.
# Coordinates are:
# [[top-left-x, top-left-y], [bottom-right-x, bottom-right-y]].
# Origin is top-left, increasing x is to the right, increasing y is down.
SCHEMA = {
'type': 'dict',
'properties': [{
'name': 'regionType',
'schema': UnicodeString.SCHEMA
}, {
'name': 'area',
'schema': NormalizedRectangle2D.SCHEMA
}]
}
class ImageWithRegions(BaseObject):
"""An image overlaid with labeled regions."""
description = 'An image overlaid with regions.'
SCHEMA = {
'type': 'dict',
'properties': [{
'name': 'imagePath',
'schema': Filepath.SCHEMA
}, {
'name': 'labeledRegions',
'schema': {
'type': 'list',
'items': {
'type': 'dict',
'properties': [{
'name': 'label',
'schema': UnicodeString.SCHEMA
}, {
'name': 'region',
'schema': ImageRegion.SCHEMA
}]
}
}
}]
}
class ClickOnImage(BaseObject):
"""A click on an image and the clicked regions."""
description = 'Position of a click and a list of regions clicked.'
SCHEMA = {
'type': 'dict',
'properties': [{
'name': 'clickPosition',
'schema': {
'type': 'list',
'items': Real.SCHEMA,
'len': 2
}
}, {
'name': 'clickedRegions',
'schema': {
'type': 'list',
'items': UnicodeString.SCHEMA
}
}]
}
class ParameterName(BaseObject):
"""Parameter name class.
Validation for this class is done only in the frontend.
"""
description = 'A string representing a parameter name.'
SCHEMA = {
'type': 'unicode',
}
class SetOfHtmlString(BaseObject):
"""A Set of Html Strings."""
description = 'A list of Html strings.'
default_value = []
SCHEMA = {
'type': 'list',
'items': Html.SCHEMA,
'validators': [{
'id': 'is_uniquified'
}]
}
class MathExpression(BaseObject):
"""Math expression class."""
description = 'A math expression.'
SCHEMA = {
'type': 'dict',
'properties': [{
'name': 'ascii',
'schema': UnicodeString.SCHEMA,
}, {
'name': 'latex',
'schema': UnicodeString.SCHEMA,
}]
}
class Fraction(BaseObject):
"""Fraction class."""
description = 'A fraction type'
default_value = {
'isNegative': False,
'wholeNumber': 0,
'numerator': 0,
'denominator': 1
}
SCHEMA = {
'type': 'dict',
'properties': [{
'name': 'isNegative',
'schema': {
'type': 'bool'
}
}, {
'name': 'wholeNumber',
'schema': NonnegativeInt.SCHEMA
}, {
'name': 'numerator',
'schema': NonnegativeInt.SCHEMA
}, {
'name': 'denominator',
'schema': PositiveInt.SCHEMA
}]
}
class Units(BaseObject):
"""Units class."""
# Validation of the units is performed only in the frontend using math.js.
# math.js is not available in the backend.
description = 'A list of unit dict components.'
default_value = []
SCHEMA = {
'type': 'list',
'items': {
'type': 'dict',
'properties': [{
'name': 'unit',
'schema': {
'type': 'unicode'
}
}, {
'name': 'exponent',
'schema': {
'type': 'int'
}
}]
}
}
class NumberWithUnits(BaseObject):
"""Number with units class."""
description = 'A number with units expression.'
default_value = {
'type': 'real',
'real': 0.0,
'fraction': Fraction.default_value,
'units': Units.default_value
}
SCHEMA = {
'type': 'dict',
'properties': [{
'name': 'type',
'schema': {
'type': 'unicode'
}
}, {
'name': 'real',
'schema': {
'type': 'float'
}
}, {
'name': 'fraction',
'schema': Fraction.SCHEMA
}, {
'name': 'units',
'schema': Units.SCHEMA
}]
}
class ListOfSetsOfHtmlStrings(BaseObject):
"""List of sets of Html strings class."""
description = 'A list of sets of Html strings.'
default_value = []
SCHEMA = {
'type': 'list',
'items': SetOfHtmlString.SCHEMA,
}