Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a97946

Browse files
Sumesh MuraliAshwin Rajeev
Sumesh Murali
authored and
Ashwin Rajeev
committed
cleaned up
1 parent8a17186 commit5a97946

File tree

14 files changed

+159
-6
lines changed

14 files changed

+159
-6
lines changed

‎.idea/.gitignore‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎.idea/inspectionProfiles/Project_Default.xml‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎.idea/inspectionProfiles/profiles_settings.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎.idea/misc.xml‎

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎.idea/modules.xml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎.idea/selectorlib.iml‎

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎.idea/vcs.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎docs/conf.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,3 @@
158158
'One line description of project.',
159159
'Miscellaneous'),
160160
]
161-
162-
163-

‎selectorlib/exceptions.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
classUnsupportedItemType(Exception):
2+
pass

‎selectorlib/selectorlib.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
importyaml
44
importinspect
55

6+
from .exceptionsimportUnsupportedItemType
7+
68

79
defextract_field(element,item_type,attribute=None,formatter=None):
810
ifitem_type=='Text':
@@ -16,6 +18,12 @@ def extract_field(element, item_type, attribute=None, formatter=None):
1618
content=element.attrib.get(attribute)
1719
elifitem_type=='Image':
1820
content=element.attrib.get('src')
21+
else:
22+
raiseUnsupportedItemType(
23+
f'Item Type "{item_type}" is not supported.'
24+
f' Supported item_types are ["Text", "Link", "HTML", "Attribute",'
25+
f' "Image"]'
26+
)
1927
ifformatter:
2028
content=formatter.format(content)
2129
returncontent
@@ -24,6 +32,7 @@ def extract_field(element, item_type, attribute=None, formatter=None):
2432
classExtractor:
2533
"""selector class"""
2634
def__init__(self,config,formatters=None):
35+
self._validate_config(config)
2736
self.config=config
2837
ifformatters:
2938
formatters= [i()ifinspect.isclass(i)elseiforiinformatters]
@@ -113,3 +122,17 @@ def _get_child_item(self, field_config, element):
113122
child_value=self._extract_selector(children_config[field],element)
114123
child_item[field]=child_value
115124
returnchild_item
125+
126+
def_validate_config(self,config):
127+
ifnotisinstance(config,dict):
128+
raiseTypeError("Expected <dict> for config")
129+
130+
valid_field_types= {'Text','Link','HTML','Image','Attribute'}
131+
forfield_name,field_configinconfig.items():
132+
iffield_config.get('type')notinvalid_field_types:
133+
raiseUnsupportedItemType(
134+
f'Item Type "{field_config.get("type")}" for Field '
135+
f'"{field_name}" is not supported. Supported item_types'
136+
f' are ["Text", "Link", "HTML", "Attribute",'
137+
f' "Image"]'
138+
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp