Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to port to pythom 3 #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions orbeon_xml_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

# from . import tests
from . import builder
6 changes: 3 additions & 3 deletions orbeon_xml_api/builder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.



from lxml import etree

Expand All @@ -10,7 +10,7 @@
BooleanControl, AnyUriControl, EmailControl, DecimalControl, \
Select1Control, OpenSelect1Control, SelectControl, ImageAnnotationControl
from utils import generate_xml_root, unaccent_unicode

#.ITERITEMS ARE MADE TO ITEMS()
# `xforms:` types are here for backwards compatibility.
XF_TYPE_CONTROL = {
'xf:string': StringControl,
Expand Down
4 changes: 2 additions & 2 deletions orbeon_xml_api/controls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.



from datetime import datetime, time
from lxml import etree
Expand Down
86 changes: 69 additions & 17 deletions orbeon_xml_api/runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.



import re
from lxml import etree
Expand Down Expand Up @@ -128,28 +128,80 @@ def set_value(self, name, value):

def merge(self, builder_obj, **kwargs):
# TODO Move and rebuild into RunnerCopyBuilderMerge (class)
parser = etree.XMLParser(ns_clean=True, encoding='utf-8')
root = etree.XML('<?xml version="1.0" encoding="UTF-8"?><form></form>', parser)

no_copy_prefix = kwargs.get('no_copy_prefix', None)

parents = {}
merged_form = builder_obj.get_form_instance_raw()
merged_form = etree.fromstring(merged_form)

for element in merged_form.iter():
tag = element.tag
if tag not in ['annotation', 'image']:
if isinstance(tag, basestring):
if no_copy_prefix and tag.startswith(no_copy_prefix):
pass
else:
ov = self.xml_root.xpath('//%s' % tag)
if len(ov) > 0 and ov[0].text:
if len(ov[0].text.strip()) > 0:
element.text = ov[0].text

merge_form_xml = etree.tostring(merged_form)
for tag, element in builder_obj.controls.iteritems():
if tag in self.builder.controls.keys():
# k_: Known elements (present in original runner/builder)
k_control = self.builder.controls.get(tag, False)

if not k_control:
continue

k_parent_control = k_control._parent
k_form_element = self.get_form_element(tag)

# Sections (escpecially)
if k_parent_control is None and tag not in parents:
parents[tag] = etree.Element(tag)
root.append(parents[tag])

# Controls
if k_form_element is not None:
if k_parent_control is not None and hasattr(k_parent_control, '_bind') and k_parent_control._bind.name not in parents:
k_el_parent = etree.Element(k_parent_control._bind.name)
parents[k_parent_control._bind.name] = k_el_parent
root.append(k_el_parent)

if no_copy_prefix is not None and re.search(r"^%s" % no_copy_prefix, tag) is not None:
# Instead of the Runner control, add the Builder model_instance
parents[k_parent_control._bind.name].append(k_control._model_instance)
else:
parents[k_parent_control._bind.name].append(k_form_element)
# root.append(k_form_element)
else:
# n_: New elements
n_new_control = builder_obj.controls.get(tag, False)

if not n_new_control:
continue

n_parent_control = n_new_control._parent

# Sections (escpecially) don't have a parent, hence it's <form> root.
if n_parent_control is None and tag not in parents:
parents[tag] = etree.Element(tag)
root.append(parents[tag])
elif n_parent_control is not None and hasattr(n_parent_control, '_bind') and n_parent_control._bind.name not in parents:
if n_parent_control._bind.name in builder_obj._form:
n_parent_form_element = builder_obj._form[n_parent_control._bind.name]
n_el_parent = etree.Element(n_parent_form_element.tag)
parents[n_parent_control._bind.name] = n_el_parent
root.append(n_el_parent)

# Initialize parent
if hasattr(n_parent_control, '_bind') and n_parent_control._bind.name not in parents:
parents[n_parent_control._bind.name] = None

# Controls
if hasattr(n_parent_control, '_bind') and n_parent_control._bind.name in parents and n_new_control and n_new_control._model_instance is not None:
parents[n_parent_control._bind.name].append(n_new_control._model_instance)
elif n_new_control and hasattr(n_new_control._parent, '_bind'):
parents[n_new_control._parent._bind.name] = n_new_control._model_instance

# Unicode support
merge_form_xml = etree.tostring(root)
merge_form_xml = bytes(bytearray(merge_form_xml, encoding='utf-8'))
merged_runner = Runner(merge_form_xml, builder_obj)

return merged_runner


class RunnerForm:

def __init__(self, runner):
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/runner_copy_builder_merge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

class RunnerCopyBuilderMerge:

def __init__(self, runner, builder, **kwargs):
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/benchmark_performance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

import unittest

from ..builder import Builder
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from ..test_common import CommonTestCase
from ...controls import *
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_autocomplete.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import StringControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_checkbox_input.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import BooleanControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_checkboxes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase
from ..controls import SelectControl

Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_currency.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import DecimalControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_date.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from datetime import datetime
from lxml import etree

Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_datetime.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from datetime import datetime
from lxml import etree

Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_dropdown.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase
from ..controls import Select1Control

Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_dropdown_date.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from datetime import datetime

from . import CommonTestCase
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_dynamic_data_dropdown.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import StringControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_email.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import StringControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_fields_date.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from datetime import datetime
from lxml import etree

Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_file_attachment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase


Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_htmlarea.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import StringControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_image_annotation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from collections import OrderedDict
from lxml import etree

Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_image_attachment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import AnyUriControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_input.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import StringControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_input_counter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import StringControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_link_button.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase


Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_multiple_list.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from lxml import etree

from . import CommonTestCase
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_number.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import DecimalControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_open_select1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase
from ..controls import OpenSelect1Control

Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_output.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import StringControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_radio_buttons.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import Select1Control
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_secret.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import StringControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_standard_button.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase


Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_static_image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from collections import OrderedDict
from . import CommonTestCase

Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_textarea.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import StringControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_textarea_counter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from . import CommonTestCase

from ..controls import StringControl
Expand Down
4 changes: 0 additions & 4 deletions orbeon_xml_api/tests/controls/test_time.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Bob Leers (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from datetime import datetime
from lxml import etree

Expand Down
Loading