Commit 7b1a6faa authored by Emmanuel Gil Peyrot's avatar Emmanuel Gil Peyrot Committed by Link Mauve

Util: Fix circular import by moving get_form() to the dataforms module

parent 739e2127
Pipeline #5661 passed with stages
in 48 seconds
......@@ -105,6 +105,22 @@ def extend_form(node):
return SimpleDataForm(extend=node)
def get_form(node, form_type):
forms = node.getTags('x', namespace=Namespace.DATA)
if not forms:
return None
for form in forms:
form = extend_form(node=form)
field = form.vars.get('FORM_TYPE')
if field is None:
continue
if field.value == form_type:
return form
return None
class DataField(ExtendedNode):
"""
Keeps data about one field - var, field type, labels, instructions... Base
......
......@@ -25,9 +25,9 @@ from nbxmpp.structs import ChangePasswordResult
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
from nbxmpp.util import raise_error
from nbxmpp.util import get_form
from nbxmpp.const import REGISTER_FIELDS
from nbxmpp.modules.bits_of_binary import parse_bob_data
from nbxmpp.modules.dataforms import get_form
from nbxmpp.modules.dataforms import extend_form
from nbxmpp.modules.dataforms import create_field
from nbxmpp.modules.dataforms import SimpleDataForm
......
......@@ -46,7 +46,6 @@ from nbxmpp.structs import PresenceProperties
from nbxmpp.structs import CommonError
from nbxmpp.structs import HTTPUploadError
from nbxmpp.structs import StanzaMalformedError
from nbxmpp.modules.dataforms import extend_form
from nbxmpp.third_party.hsluv import hsluv_to_rgb
log = logging.getLogger('nbxmpp.util')
......@@ -342,22 +341,6 @@ def generate_id():
return str(uuid.uuid4())
def get_form(stanza, form_type):
forms = stanza.getTags('x', namespace=Namespace.DATA)
if not forms:
return None
for form in forms:
form = extend_form(node=form)
field = form.vars.get('FORM_TYPE')
if field is None:
continue
if field.value == form_type:
return form
return None
def validate_stream_header(stanza, domain, is_websocket):
attrs = stanza.getAttrs()
if attrs.get('from') != domain:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment