text
stringlengths
1
93.6k
# todo: elif snak.type in ('geo-shape', 'tabular-data'):
elif snak.type == 'monolingualtext':
lang, _, text = value.partition(':')
literal = self.valid_text_literal(text)
if literal:
monotext = WbMonolingualText(literal, lang)
snak.setTarget(monotext)
return True
else:
invalid_report()
elif snak.type == 'globe-coordinate':
match = self.globeR.fullmatch(value)
if match:
coord = Coordinate(
*map(float, match.groups()),
precision=1e-4, # hardcoded as in claimit.py
site=self.repo)
snak.setTarget(coord)
return True
else:
invalid_report()
else:
pywikibot.warning(f'"{snak.type}" datatype is not supported yet')
return False
def set_target(self, snak, value):
try:
return self._set_target(snak, value)
except APIError:
pass # warning was printed down the stack
except WikiBaseError as e:
pywikibot.error(e)
return False
def handle_line(self, line):
comment_match = self.commentR.search(line)
if comment_match:
summary = comment_match[1]
line = line[:comment_match.start()]
else:
summary = None
split = line.split('\t')
first = split[0]
if first != 'CREATE' and (len(split) < 3 or len(split) % 2 == 0):
pywikibot.warning(f'Invalid line: {line}')
return
if first == 'MERGE':
entity_from, entity_to = map(self.parse_entity, split[1:3])
entity_from.mergeInto(entity_to, summary=summary)
return
minus = False
if first == 'CREATE':
# the orig. QS only supports creating items
self.last = item = pywikibot.ItemPage(self.repo)
elif first == 'LAST':
item = self.last
if self.last is None:
pywikibot.warning('"LAST" magic word used without "CREATE"')
return
else:
minus = first.startswith('-')
if minus:
first = first[1:]
try:
item = self.repo.get_entity_for_entity_id(first)
except NoWikibaseEntityError as e:
pywikibot.error(e)
return
# TODO: this is currently unused but might become handy
# if consecutive edits to an item are squashed
self.current = item
pred = split[1]
if pred.startswith(tuple(self.attr_mapping)) and not minus:
literal = self.valid_text_literal(split[2], allow_empty=True)
if literal is None:
pywikibot.warning(f'Invalid literal for {pred}-command')
return
init, lang = pred[0], pred[1:]
key = self.attr_mapping[init]['key']
callback = self.attr_mapping[init].get(
'callback',
lambda data, key, value: data.update({key: value}))
callback(getattr(self.current, key), lang, literal)
try:
self.current.editEntity(summary=summary)
except OtherPageSaveError:
pass
return
# assume the predicate is a property
# fixme: ideally, validation would be done upstream
# claim = pywikibot.Claim(self.repo, prop)
try:
obj = self.repo.get_entity_for_entity_id(pred)