Adjust lxml import.

This commit is contained in:
Edward Betts 2023-05-14 16:04:53 +00:00
parent be2de5dc1a
commit b1625115ad
1 changed files with 4 additions and 4 deletions

View File

@ -6,6 +6,7 @@ from time import sleep, time
import flask_login import flask_login
import GeoIP import GeoIP
import lxml
import maxminddb import maxminddb
import requests import requests
import sqlalchemy import sqlalchemy
@ -23,7 +24,6 @@ from flask import (
stream_with_context, stream_with_context,
url_for, url_for,
) )
from lxml import etree
from requests_oauthlib import OAuth1Session from requests_oauthlib import OAuth1Session
from sqlalchemy import func from sqlalchemy import func
from sqlalchemy.sql.expression import update from sqlalchemy.sql.expression import update
@ -824,7 +824,7 @@ def process_edit(changeset_id, e):
if r.status_code == 410 or r.content == b"": if r.status_code == 410 or r.content == b"":
return "deleted" return "deleted"
root = etree.fromstring(r.content) root = lxml.etree.fromstring(r.content)
existing = root.find('.//tag[@k="wikidata"]') existing = root.find('.//tag[@k="wikidata"]')
if e["op"] == "add" and existing is not None: if e["op"] == "add" and existing is not None:
return "already_added" return "already_added"
@ -836,14 +836,14 @@ def process_edit(changeset_id, e):
root[0].set("changeset", str(changeset_id)) root[0].set("changeset", str(changeset_id))
if e["op"] == "add": if e["op"] == "add":
tag = etree.Element("tag", k="wikidata", v=qid) tag = lxml.etree.Element("tag", k="wikidata", v=qid)
root[0].append(tag) root[0].append(tag)
if e["op"] == "remove": if e["op"] == "remove":
root[0].remove(existing) root[0].remove(existing)
if e["op"] == "change": if e["op"] == "change":
existing.set("v", qid) existing.set("v", qid)
element_data = etree.tostring(root) element_data = lxml.etree.tostring(root)
try: try:
success = edit.save_element(osm_type, osm_id, element_data) success = edit.save_element(osm_type, osm_id, element_data)
except requests.exceptions.HTTPError as e: except requests.exceptions.HTTPError as e: