Ejemplo n.º 1
0
    async def get_departures(
        self,
        station_id: str,
        direction_id: Optional[str] = None,
        max_journeys: int = 20,
        products: Optional[List[str]] = None,
    ) -> RMVtravel:
        """Fetch data from rmv.de."""
        url = self.build_journey_query(station_id, direction_id, max_journeys,
                                       products)
        xml = await self._query_rmv_api(url)
        self.obj = extract_data_from_xml(xml)

        try:
            self.now = self.current_time()
        except RMVtransportDataError:
            _LOGGER.debug("XML contains unexpected data %s",
                          objectify.dump(self.obj)[:100])
            raise

        self.journeys.clear()
        try:
            for journey in self.obj.SBRes.JourneyList.Journey:
                self.journeys.append(RMVjourney(journey, self.now))
        except AttributeError as err:
            _LOGGER.debug("Extract journeys: %s",
                          objectify.dump(self.obj.SBRes))
            raise RMVtransportError(err) from err

        return self.travel_data()
Ejemplo n.º 2
0
    def test_password_callback(self):
        """
        `dataloadtool_export()` should use the password callback.
        """
        # One member with a password, and one without.
        m1 = self.create_member_partial(commit=False)
        m2 = self.create_member_partial(commit=False)
        m1.gender = 'F'
        m2.gender = 'M'
        m1.save()
        m2.save()

        expected = self.expected_consumers([m1, m2])
        expected.Consumer[0].UserAccount.LoginCredentials.Password = '******'
        del expected.Consumer[1].UserAccount.LoginCredentials.Password
        objectify.deannotate(expected, cleanup_namespaces=True)

        def mock_password(given_member):
            # XXX: Unsaved objects compare equal by default, so lookup by id instead.
            passwords = {m1.username: '******', m2.username: None}
            self.assertIn(given_member.username, passwords,
                          'Called with unexpected member: {0!r}'.format(given_member))
            return passwords[given_member.username]

        consumers = self._dataloadtool_export(Member.objects.filter(pk__in=(m1.pk, m2.pk)),
                                              password_callback=mock_password)
        self.assertEqual(
            objectify.dump(expected),
            objectify.dump(consumers))
Ejemplo n.º 3
0
 def test_nomembers(self):
     """
     The command should at least run, and produce an empty list of records.
     """
     xml = self._call_command()  # zero Consumer records won't validate
     self.assertEqual(
         objectify.dump(objectify.fromstring(xml)),
         objectify.dump(objectify.E.Consumers()))
Ejemplo n.º 4
0
 def test_load_of_voe_v2(self):
     with open(datapaths.swift_bat_grb_pos_v2, 'rb') as f:
         vff = vp.load(f)
     with open(datapaths.swift_bat_grb_pos_v2, 'rb') as f:
         vfs = vp.loads(f.read())
     self.assertEqual(objectify.dump(vff), objectify.dump(vfs))
     self.assertEqual(vfs.tag, 'VOEvent')
     self.assertEqual(vfs.attrib['ivorn'],
                      'ivo://nasa.gsfc.gcn/SWIFT#BAT_GRB_Pos_532871-729')
Ejemplo n.º 5
0
 def test_load_of_voe_v2(self):
     with open(datapaths.swift_bat_grb_pos_v2, 'rb') as f:
         vff = vp.load(f)
     with open(datapaths.swift_bat_grb_pos_v2, 'rb') as f:
         vfs = vp.loads(f.read())
     self.assertEqual(objectify.dump(vff), objectify.dump(vfs))
     self.assertEqual(vfs.tag, 'VOEvent')
     self.assertEqual(vfs.attrib['ivorn'],
                      'ivo://nasa.gsfc.gcn/SWIFT#BAT_GRB_Pos_532871-729')
Ejemplo n.º 6
0
 def loadXML(self, file):
     fp = open(str(file), 'r')
     xml = fp.read()
     fp.close
     try:
         brcm_cfg = objectify.fromstring(xml, self.parser)
     except:
         brcm_cfg = objectify.fromstring(xml, self.parser)
         print objectify.dump(brcm_cfg)
         return None
     return brcm_cfg
Ejemplo n.º 7
0
    def test_dataloadtool_export_unicode(self):
        """
        `dataloadtool_export()` should handle non-ASCII data.
        """
        member = self.create_member_partial(commit=False)
        member.gender = 'F'
        member.first_name = u'fïrstnâmé'
        member.save()

        consumers = self._dataloadtool_export(Member.objects.filter(pk=member.pk))
        self.assertEqual(
            objectify.dump(self.expected_consumers([member])),
            objectify.dump(consumers))
Ejemplo n.º 8
0
    def test_dataloadtool_export(self):
        """
        Validate `dataloadtool_export()` against the schema and expected data.
        """
        members = [self.create_member_partial(commit=False), self.create_member_partial(commit=False)]
        members[0].gender = 'F'
        members[1].gender = 'M'
        members[0].save()
        members[1].save()

        consumers = self._dataloadtool_export(Member.objects.filter(pk__in=(members[0].pk, members[1].pk)))
        self.assertEqual(
            objectify.dump(self.expected_consumers(members)),
            objectify.dump(consumers))
Ejemplo n.º 9
0
 def to_dict(self, xml_data):
     obj = objectify.fromstring(xml_data)
     
     if 'name' in objectify.dump(obj):
         self.dict["name"] = str(obj.name)
         
     if 'vcpus' in objectify.dump(obj):
         self.dict["vcpus"] = int(obj.vcpus)
         
     if 'ram' in objectify.dump(obj):
         self.dict["ram"] = int(obj.ram)
         
     if 'disk' in objectify.dump(obj):
         self.dict["disk"] = int(obj.disk)
         
     if 'swap' in objectify.dump(obj):
         self.dict["swap"] = int(obj.swap)
         
     if 'public' in objectify.dump(obj):
         self.dict["public"] = bool(obj.public)
         
     if 'promoted' in objectify.dump(obj):
         self.dict["promoted"] = bool(obj.promoted)
     
     nodes = []
     if 'node' in objectify.dump(obj):
         for node in obj.node:
             nodes.append(str(node))
     self.dict["nodes"]=nodes
     
     return self.dict
Ejemplo n.º 10
0
def recognize(audio_buffer):
    response = requests.post(
        'https://asr.yandex.net/asr_xml',
        params={
            'uuid': config.SPEECH_UUID,
            'key': config.YA_KEY,
            'topic': 'queries',
        },
        headers={
            'Content-Type': 'audio/x-wav',
            # 'Transfer-Encoding': 'chunked',
        },
        data=audio_buffer)

    logger.debug('XML response')
    logger.debug(response.content)

    recognition_results = objectify.fromstring(response.content)
    logger.debug(objectify.dump(recognition_results))

    if not recognition_results.get('success') == '1':
        return

    def dump_variant(variant):
        return {'text': variant.text, 'confidence': variant.get('confidence')}

    return [dump_variant(v) for v in recognition_results.variant]
Ejemplo n.º 11
0
    def to_dict(self, xml_data):
        obj = objectify.fromstring(xml_data)

        if 'name' in objectify.dump(obj):
            self.dict["name"] = str(obj.name)

        return self.dict
 def to_dict(self, xml_data):
     obj = objectify.fromstring(xml_data)
     
     if 'name' in objectify.dump(obj):
         self.dict["name"] = str(obj.name)
     
     return self.dict
Ejemplo n.º 13
0
    def parse(self):
        result = objectify.fromstring(self.read, parser=_ant_parser)
        logger.info("Read ant datasetId={0}".format(
            result.attrib['datasetId']))

        if self.controller is not None:
            self.controller.add_ant(result)
        logger.debug('Ant data structure:\n{0}'.format(objectify.dump(result)))
Ejemplo n.º 14
0
 def xml_data(self):
     """
     Returns a formatted string that represents the state of this resource.
     """
     if self._xml_data is not None:
         return objectify.dump(self._xml_data)
     else:
         return 'No XML data'
Ejemplo n.º 15
0
 def xml_data(self):
     """
     Returns a formatted string that represents the state of this resource.
     """
     if self._xml_data is not None:
         return objectify.dump(self._xml_data)
     else:
         return 'No XML data'
Ejemplo n.º 16
0
def QGXP_lxml_objectify(qgXML):
    """ Processes an XML response from QualysGuard and Returns an easy to
    access python object containing the information.
    
    """
    tree = objectify.fromstring(qgXML)
    logging.debug(objectify.dump(tree))

    return tree
Ejemplo n.º 17
0
def objectifyXML(filepath):
    # Read XML as string
    xml = open(filepath, 'r').read()
    print("XML: " + str(xml))
    # Parse XML data
    root = objectify.fromstring(xml)
    print("Parsed object: " + objectify.dump(root))

    # loop over elements and print their tags, attribs and sub-elements
    for e in root.iterchildren():
        print "%s(%s) => %s" % (e.tag, e.attrib, e.__dict__)
Ejemplo n.º 18
0
def objectifyXML(filepath):
    # Read XML as string
    xml = open(filepath, 'r').read()
    print("XML: " + str(xml))
    # Parse XML data
    root = objectify.fromstring(xml)
    print("Parsed object: " + objectify.dump(root))
    
    # loop over elements and print their tags, attribs and sub-elements
    for e in root.iterchildren():
        print "%s(%s) => %s" % (e.tag, e.attrib, e.__dict__)
Ejemplo n.º 19
0
    def parse(self):
        obs = objectify.fromstring(self.read, parser=_obs_parser)
        logger.info("Read obs configId={0}, seq={1}".format(
            obs.attrib['configId'], obs.attrib['seq']))
        logger.debug('Obs data structure:\n' + objectify.dump(obs))

        if self.use_configUrl:
            url = obs.attrib['configUrl']
            logger.info("Retrieving vci from {0}".format(url))
            try:
                with contextlib.closing(urlopen(url)) as uo:
                    vciread = uo.read()
                logger.debug('Retrieved vci {0}'.format(vciread))
                vci = objectify.fromstring(vciread, parser=_vci_parser)
                logger.debug('VCI data structure:\n' + objectify.dump(vci))
                if self.controller is not None:
                    self.controller.add_vci(vci)
            except Exception as e:
                logger.warn("Error retrieving VCI from {0}. {1}".format(
                    url, e))

        if self.controller is not None:
            self.controller.add_obs(obs)
Ejemplo n.º 20
0
 def check_files(self, filepath):
     baseurl = self.driver.execute_script("return new URL('/',window.location.href);")#https://www.tutormeet.com/
     print(baseurl)
     # materialUrl & rnd 可省略
     #GET http://www.tutormeet.com/materials/php/listFiles.php?filepath=session000944_2017092218000944&materialUrl=111260&rnd=818 HTTP/1.1
     r = requests.get(baseurl+'materials/php/listFiles.php?filepath=' + filepath)
     print(r.status_code)
     print(r.content)
     directory = objectify.fromstring(r.content)
     print(objectify.dump(directory))
     fileCount = len(directory["file"])
     print(fileCount)
     if fileCount > 0:
         pass
     else:
         self.fail("投影片不存在")
Ejemplo n.º 21
0
def process(obj, childname, grandchildname):
    per_page = 100
    page = 1
    retval = ''
    while page:
        print "fetching page %s of %s" % (page, childname)
        response = obj.list(per_page = per_page, page = page)
        if hasattr(response[childname], grandchildname):
            subresponses = getattr(response[childname], grandchildname)
            retval += objectify.dump(response)
            retval += '\n'
            print "exported %s records from %s" % (len(subresponses), childname)
            if len(subresponses) < per_page:
                page = False
            else:
                page += 1
        else:
            page = False
    return retval
Ejemplo n.º 22
0
    def parse(self, dataset_name):
        """Return list of MeasureObjects."""
        measure_objects = []
        for measure_tag in self.measure_tags:
            identificatie = self.parse_identificatie(measure_tag)
            if dataset_name != WATERBEHEERDER_DATASET.get(
                identificatie.waterschapid):
                continue
            measure_object = MeasureObject()
            measure_object.identificatie = identificatie
            measure_object.typeMaatregel = self.parse_typemaatregel(
                measure_tag)
            measure_object.omschrijving = self.parse_omschrijving(measure_tag)
            measure_object.waarde = self.parse_waarde(measure_tag)
            measure_object.maatregelKostenDatatype = self.parse_kostendatatype(
                measure_tag)
            measure_object.initieleKostendrager = self.parse_initielekostendrager(
                measure_tag)
            measure_object.geldenVoorWaterbeheerGebied = self.parse_geldenvoorwaterbeheergebieden(measure_tag)
            measure_object.importRaw = objectify.dump(measure_tag)

            measure_objects.append(measure_object)

        return measure_objects
Ejemplo n.º 23
0
 def printout(self):
     from lxml import objectify, etree
     objectify.deannotate(self.dragon)
     etree.cleanup_namespaces(self.dragon)
     print(objectify.dump(self.dragon))
Ejemplo n.º 24
0
def search():
    print "hello"
    search_text = request.args['q'] 
    region = request.args['region']

    listed = True
    try:
        api = API(locale='us')
        products = api.item_search('All', Keywords=search_text, paginate=False, ResponseGroup="ItemIds, ItemAttributes, Images, OfferSummary, Offers")
        
        niceProducts = []
        ASINList = []
  
        
        for product in products.Items.Item:
            try:
                niceProduct = Product()
                niceProduct.title = product.ItemAttributes.Title
                niceProduct.ASIN = product.ASIN.text
                ASINList.append(niceProduct.ASIN)
                
                niceProduct.imageUrl = product.MediumImage.URL               
                
                try:
                    niceProduct.newPrice = float(product.OfferSummary.LowestNewPrice.Amount)/100
                    niceProduct.newFormattedPrice = product.OfferSummary.LowestNewPrice.FormattedPrice
                    niceProduct.newPriceCurrency = product.OfferSummary.LowestNewPrice.CurrencyCode
                except:
                    pass
    
                try:
                    niceProduct.usedPrice = float(product.OfferSummary.LowestUsedPrice.Amount)/100
                    niceProduct.usedFormattedPrice = product.OfferSummary.LowestUsedPrice.FormattedPrice
                    niceProduct.usedPriceCurrency = product.OfferSummary.LowestUsedPrice.CurrencyCode
                except:
                    pass
                    
                niceProduct.type = product.ItemAttributes.ProductGroup
                niceProduct.region =  getRegionFromUrl(product.DetailPageURL.text).upper() #product.ItemAttributes.RegionCode
                niceProduct.locale =  getRegionFromUrl(product.DetailPageURL.text)
                niceProduct.model = product.ItemAttributes.Model
                niceProducts.append(niceProduct)
                if not listed:
                    print(objectify.dump(product))
                    listed = True
            except:
                pass
                #not a product
                
       # res = api.item_lookup(*ASINList, MerchantId='Amazon', ResponseGroup = 'Offers')
        
       # i = 0
       # listed = False
        
       # for amazonProduct in res.Items.Item:
          #  print 'new amazon offer for ASIN : ', amazonProduct.ASIN
          #  print '#########################################'
            #print objectify.dump(amazonProduct)
          #  try:
                #print 'not void!'
                #for offer in amazonProduct.Offers:
          #      print objectify.dump(amazonProduct)
          #      niceProducts[i].newPrice = float(amazonProduct.OfferSummary.LowestNewPrice.Amount)/100
          #      niceProducts[i].newFormattedPrice = amazonProduct.OfferSummary.LowestNewPrice.FormattedPrice
          #      niceProducts[i].newPriceCurrency = amazonProduct.OfferSummary.LowestNewPrice.CurrencyCode
          #      print 'price is : ', float(amazonProduct.OfferSummary.LowestNewPrice.Amount)/100
                
          #  except Exception as inst:
          #      print inst        
            #if not listed:
            #        print(objectify.dump(amazonProduct))
            #        listed = True
            #try:
            ##    print 'set price : ', i, ', ASIN : ', amazonProduct.ASIN
            ##    niceProducts[i].newPrice = float(amazonProduct.ItemAttributes.ListPrice.Amount)/100
            ##    niceProducts[i].newFormattedPrice = amazonProduct.ItemAttributes.ListPrice.FormattedPrice
            ##    niceProducts[i].newPriceCurrency = amazonProduct.ItemAttributes.ListPrice.CurrencyCode
            ##    print 'ok price for : ', i
            ##except:
            #    pass
          #  i+=1
               

    except errors.AWSError, e:
        print 'Amazon complained about yout request!'
        print e.code
        print e.msg
        return e.msg
Ejemplo n.º 25
0
 def __str__(self):
     return dump(self.node)
Ejemplo n.º 26
0
 def __str__(self):
     return dump(self.node)
Ejemplo n.º 27
0
 def printout(self):
     objectify.deannotate(self.dragon)
     etree.cleanup_namespaces(self.dragon)
     print(objectify.dump(self.dragon))
#!/usr/bin/env python3

import urllib.request
from lxml import etree, objectify


def _download_webpage(url):
    r = urllib.request.Request(url)
    r.add_header('User-Agent', 'Python-Webpage-Comparison/0.1')
    return urllib.request.urlopen(r)


def _get_xpath_content(html, xpath):
    parser = etree.HTMLParser()
    tree = etree.parse(html, parser)
    content = tree.xpath(xpath)
    return content[0]


def get_content(url, xpath):
    html = _download_webpage(url)
    content = _get_xpath_content(html, xpath)
    return content


if __name__ == "__main__":
    url = 'http://www.google.com'
    content = get_content(url, "//div[@id='guser']")
    print(repr(content))
    print(objectify.dump(content))
Ejemplo n.º 29
0
    print('====PullMessage Result:==count:  ' + str(cmess))
    for cur_message in pullmess.NotificationMessage:
        mess_tree = cur_message.Message._value_1
        md_ell = mess_tree.xpath(".//*[@Name='IsMotion']/@Value")
        if len(md_ell):
            md_el = md_ell[0]
            print('!!Motion:' + md_el)
            if md_el != 'false':
                #--  motion flag=TRUE
                for part in mess_tree:
                    print('TAG=' + part.tag)
                    print(part.attrib)
                    #       print(objectify.dump(part))
                    #       for subpart in part:
                    #          print(subpart.tag, subpart.attrib)
                    #     b = objectify.SubElement(mess_tree, "Source")
                    #     print(objectify.dump(b))
                    #     print(mess_tree)
                    print('----------------')
                    print(objectify.dump(mess_tree))
                    print(etree.tostring(mess_tree, method="xml"))
            else:
                #--  motion flag = FALSE
                print(objectify.dump(mess_tree))
            print(
                '----------------------------------------------------------------------------------------'
            )
# except BaseException as e:
#   print(e.__class__)
#   break
Ejemplo n.º 30
0
# Transform the tree of all event paths into the final XSD
res = transform(xml_doc)

# ----

# Initialize parser
schema_root = etree.XML(str(res))
schema = etree.XMLSchema(schema_root)
parser = objectify.makeparser(schema=schema)


##
## Try to validate the test-event files
##
try:
    d = objectify.fromstring(open("tests/valid.xml").read(), parser)
    print "OK: Schema file tests/valid.xml is valid! (As expected)"

    print objectify.dump(d)

except Exception as e:
    print "FAILED: Schema file tests/valid.xml is INvalid! (Unexpected!!)"
    print e

# try:
#    d = objectify.fromstring(open('tests/invalid.xml').read(), parser)
#    print "FAILED: Schema file tests/valid.xml is valid! (Unexpected!!)"
# except Exception as e:
#    print "OK: Schema file tests/valid.xml is INvalid! (As expected)"
#    print e
Ejemplo n.º 31
0
 def __str__(self):
     return objectify.dump(self.tree)
Ejemplo n.º 32
0
 def __str__(self):
     objectify.dump(self._xml)
Ejemplo n.º 33
0
 def __str__(self):
     return objectify.dump(self.tree)
Ejemplo n.º 34
0
            print
            weather = LocalWeather("london", num_of_days=3)
            print len(weather.data.weather)
            today = weather.data.weather[0]
            tomorrow = weather.data.weather[1]
            twodayslater = weather.data.weather[2]
            print u"Today: %s, Max \u2103: %d, Min \u2103: %d, %s" %\
                (today.date, today.tempMaxC, today.tempMinC, today.weatherDesc)

            print
            for w in weather.data.weather:
                print u"Date: %s, Max \u2103: %d, Min \u2103: %d, %s" %\
                    (w.date, w.tempMaxC, w.tempMinC, w.weatherDesc)

            print
            print objectify.dump(tomorrow)

            print
        #you need to change this to your own key.
        #you can get your own key from registering on WWO website
        if setKey("w9ve379xdu8etugm7e2ftxd6", "premium"):
            weather = LocalWeather("new york")
            print
            print weather.data.current_condition.temp_C
            print weather.data.current_condition.weatherDesc
            print weather.data.current_condition.weatherIconUrl

            setKeyType("free")
            weather = LocalWeather("san francisco")
            print
            print weather.data.current_condition.temp_C
Ejemplo n.º 35
0
            print
            weather = LocalWeather("london", num_of_days=3)
            print len(weather.data.weather)
            today = weather.data.weather[0]
            tomorrow = weather.data.weather[1]
            twodayslater = weather.data.weather[2]
            print u"Today: %s, Max \u2103: %d, Min \u2103: %d, %s" %\
                (today.date, today.tempMaxC, today.tempMinC, today.weatherDesc)

            print
            for w in weather.data.weather:
                print u"Date: %s, Max \u2103: %d, Min \u2103: %d, %s" %\
                    (w.date, w.tempMaxC, w.tempMinC, w.weatherDesc)

            print
            print objectify.dump(tomorrow)

            print
        #you need to change this to your own key.
        #you can get your own key from registering on WWO website
        if setKey("w9ve379xdu8etugm7e2ftxd6", "premium"):
            weather = LocalWeather("new york")
            print
            print weather.data.current_condition.temp_C
            print weather.data.current_condition.weatherDesc
            print weather.data.current_condition.weatherIconUrl

            setKeyType("free")
            weather = LocalWeather("san francisco")
            print
            print weather.data.current_condition.temp_C
Ejemplo n.º 36
0
from subprocess import Popen, PIPE, STDOUT
import StringIO

def to_markdown(html_in):
  p = Popen(["pandoc", "-f", "html", "-t", "markdown"], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
  stdout = p.communicate(input=html_in)[0]
  return stdout



posts = objectify.parse( "./posts.xml" ).getroot()
users = objectify.parse( "users.xml" ).getroot()
comments = objectify.parse( "./comments.xml" ).getroot()
votes = objectify.parse( "./votes.xml" ).getroot()

objectify.dump(users)

for u in users.iterchildren():
  objectify.dump(u)


def get_user(uid):
  xpath = "row[@Id='" + uid + "']"
  return users.find(xpath)

def get_comments(postId):
  return comments.findall("row[@PostId='" + postId + "']")

def print_comments(md,Id):
    print >>md, "### Comments ###"
    for comment in get_comments(Id):
Ejemplo n.º 37
0
def import_task(task_xml, xml_object, dict_zip_files_post=None):
    """
    :param request: request object for getting POST and GET
    :return: response

    expect xml-file in post-request
    tries to objectify the xml and import it in Praktomat
    """

    logger.debug('handle task version 1.0.1')
    # is_zip = False
    rxcoding = re.compile(r"encoding=\"(?P<enc>[\w.-]+)")
    # rxversion = re.compile(r"^(?P<major>(\d+))(\.){1}?(?P<minor>(\d+))(\.){1}?(\.|\d+)+$")
    defined_user = "******"
    message = ""

    xmlexercise = task_xml

    if dict_zip_files_post is None:
        dict_zip_files = None
    else:
        dict_zip_files = dict_zip_files_post

    response = HttpResponse()

    # here is the actual namespace for the version
    format_namespace = "urn:proforma:task:v1.0.1"

    # the right ns is also for the right version necessary
    ns = {
        "p": format_namespace,
        "praktomat": "urn:proforma:praktomat:v0.2",
        "unit": "urn:proforma:tests:unittest:v1",
        "jartest": 'urn:proforma:tests:jartest:v1',
    }

    #encoding = rxcoding.search(xmlexercise, re.IGNORECASE)
    #if (encoding != 'UFT-8' or encoding != 'utf-8') and encoding is not None:
    #    xmlexercise = xmlexercise.decode(encoding.group('enc')).encode('utf-8')
    # xml_object = objectify.fromstring(xmlexercise)

    xml_task = xml_object
    # TODO check against schema

    # check Namespace
    if format_namespace not in list(xml_object.nsmap.values()):
        raise Exception(
            "The Exercise could not be imported!\r\nOnly support for Namspace: "
            + format_namespace)

    # TODO datetime max?

    new_task = Task.objects.create(title="test",
                                   description=xml_task.description.text,
                                   submission_date=datetime.now(),
                                   publication_date=datetime.now())

    try:
        # check for submission-restriction
        if xml_task.find("p:submission-restrictions", namespaces=ns) is None:
            raise Exception(
                "The Exercise could not be imported!\r\nsubmission-restrictions-Part is missing"
            )
        else:
            if xml_task.xpath("p:submission-restrictions/*[@max-size]",
                              namespaces=ns):
                new_task.max_file_size = int(
                    xml_task.xpath("p:submission-restrictions/*[@max-size]",
                                   namespaces=ns)[0].attrib.get("max-size"))
            else:
                new_task.max_file_size = 1000

            if xml_task.xpath("p:meta-data/*[@mime-type-regexp]",
                              namespaces=ns):
                new_task.supported_file_types = xml_task.xpath(
                    "p:meta-data/*[@mime-type-regexp]", namespaces=ns)[0]
            else:
                new_task.supported_file_types = ".*"  # all

        # check for embedded or external files

        # Files create dict with internal file objects should also used for external files
        embedded_file_dict = dict()
        # external_file_dict = dict()
        create_file_dict = dict()

        for uploaded_file in xml_task.xpath("p:files/p:file", namespaces=ns):
            if uploaded_file.attrib.get("class") == "internal":
                if uploaded_file.attrib.get("type") == "embedded":
                    t = tempfile.NamedTemporaryFile(delete=True)
                    t.write(uploaded_file.text.encode("utf-8"))
                    t.flush()
                    my_temp = File(t)
                    my_temp.name = (uploaded_file.attrib.get("filename"))
                    embedded_file_dict[uploaded_file.attrib.get(
                        "id")] = my_temp
                else:
                    embedded_file_dict[uploaded_file.attrib.get("id")] = \
                        dict_zip_files[uploaded_file.attrib.get("filename")]

            # all files in this dict were created by CreateFileChecker
            if (uploaded_file.attrib.get("class") == "library") or \
               (uploaded_file.attrib.get("class") == "internal-library"):
                if uploaded_file.attrib.get("type") == "embedded":
                    t = tempfile.NamedTemporaryFile(delete=True)
                    t.write(uploaded_file.text.encode("utf-8"))
                    t.flush()
                    my_temp = File(t)
                    my_temp.name = (
                        uploaded_file.attrib.get("filename")
                    )  # check! basename? i lost the path o not?
                    create_file_dict[uploaded_file.attrib.get("id")] = my_temp
                else:
                    create_file_dict[uploaded_file.attrib.get(
                        "id")] = dict_zip_files[uploaded_file.attrib.get(
                            "filename")]
            # if uploaded_file.attrib.get("type") == "file" and is_zip:
            #     # 1. check filename with zip_dict -> ID zuweisen
            #     # elif uploaded_file.attrib.get("class") == "internal":
            #     # embedded_file_dict[uploaded_file.attrib.get("id")] = zip_file_object.
            #     for zip_filename in zip_dict:
            #         if uploaded_file.attrib.get("filename") == zip_filename:
            #             if (uploaded_file.attrib.get("class") == "library") or \
            #                     (uploaded_file.attrib.get("class") == "internal-library"):
            #                 create_file_dict[uploaded_file.attrib.get("id")] = zipFileName.key  # get value of key!
            #             elif uploaded_file.attrib.get("class") == "internal":
            #                 #  embedded_file_dict[uploaded_file.attrib.get("id")] = zip_file_object  #todo this will fail
            #                 pass
            #             else:
            #                 new_task.delete()
            #                 response.write("file class in task.xml is not known")
            #                 return response
            #         else:
            #             new_task.delete()
            #             response.write("content of zip is not referenced by task.xml")
            #             return response

        # check if sysuser is created
        try:
            sys_user = User.objects.get(username=defined_user)
        except Exception as e:
            raise Exception("System User (" + defined_user +
                            ") does not exist: " + str(e))

        # check UUID
        if xml_task.xpath("/p:task/@uuid", namespaces=ns):
            pass
        else:
            raise Exception("No uuid")
        # new model-solution import
        if xml_task.xpath("p:model-solutions/p:model-solution", namespaces=ns):

            # check files > file.id with model-solutions > model-solution > filerefs > fileref > refid
            for modelSolution in xml_task.xpath(
                    "p:model-solutions/p:model-solution", namespaces=ns):
                try:
                    solution = Solution(task=new_task, author=sys_user)
                except Exception as e:
                    raise Exception("Error while importing Solution: " +
                                    str(e))

                # TODO check more than one solution
                if modelSolution.xpath("p:filerefs", namespaces=ns):
                    for fileRef in modelSolution.filerefs.iterchildren():
                        if fileRef.attrib.get("refid") in embedded_file_dict:
                            solution.save()
                            solution_file = SolutionFile(solution=solution)
                            solution_file.file = embedded_file_dict.get(
                                fileRef.attrib.get("refid"))
                            solution_file.save()
                            new_task.model_solution = solution
                        else:
                            raise Exception(
                                "You reference a model-solution to the files but there is no refid!"
                            )
        else:
            raise Exception("No Model Solution attached")

        # task name
        if xml_task.xpath("p:meta-data/p:title", namespaces=ns):
            new_task.title = xml_task.xpath("p:meta-data/p:title",
                                            namespaces=ns)[0].text
        else:
            xml_task.title = "unknown exercise"

        val_order = 1
        inst = None
        # create library and internal-library with create FileChecker
        val_order = task.creatingFileCheckerNoDep(create_file_dict,
                                                  new_task,
                                                  ns,
                                                  val_order,
                                                  xmlTest=None)

        for xmlTest in xml_task.tests.iterchildren():

            if xmlTest.xpath("p:test-type", namespaces=ns)[0] == "anonymity":
                inst = AnonymityChecker.AnonymityChecker.objects.create(
                    task=new_task, order=val_order)
                inst = task.check_visibility(inst=inst,
                                             namespace=ns,
                                             xml_test=xmlTest)
                inst.save()

            elif xmlTest.xpath("p:test-type",
                               namespaces=ns)[0] == "c-compilation":
                inst = CBuilder.CBuilder.objects.create(
                    task=new_task,
                    order=val_order,
                    _flags="-Wall",
                    _output_flags="-o %s",
                    _file_pattern=r"^[a-zA-Z0-9_]*\.[cC]$")
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerFlags",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerFlags",
                        namespaces=ns)[0].text is not None):
                    inst._flags = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerFlags",
                        namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerOutputFlags",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerOutputFlags",
                        namespaces=ns)[0].text is not None):
                    inst._output_flags = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-CompilerOutputFlags",
                        namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerLibs",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerLibs",
                        namespaces=ns)[0].text):
                    inst._libs = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerLibs",
                        namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerFilePattern",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerFilePattern",
                        namespaces=ns)[0].text):
                    inst._file_pattern = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-CompilerFilePattern",
                        namespaces=ns)[0]
                inst = task.check_visibility(inst=inst,
                                             namespace=ns,
                                             xml_test=xmlTest)
                inst.save()

            elif xmlTest.xpath("p:test-type",
                               namespaces=ns)[0] == "java-compilation":
                inst = JavaBuilder.JavaBuilder.objects.create(
                    task=new_task,
                    order=val_order,
                    _flags="",
                    _output_flags="",
                    _file_pattern=r"^.*\.[jJ][aA][vV][aA]$",
                    _main_required=False)
                if xmlTest.attrib is not None:
                    attributes = xmlTest.attrib
                    if attributes.get("id"):
                        inst.proforma_id = attributes.get("id")
                # first check if path exist, second if the element is empty, third import the value
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerFlags",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerFlags",
                        namespaces=ns)[0].text is not None):
                    inst._flags = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerFlags",
                        namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerOutputFlags",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerOutputFlags",
                        namespaces=ns)[0].text is not None):
                    inst._output_flags = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-CompilerOutputFlags",
                        namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerLibs",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerLibs",
                        namespaces=ns)[0].text):
                    inst._libs = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerLibs",
                        namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerFilePattern",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-CompilerFilePattern",
                        namespaces=ns)[0].text):
                    inst._file_pattern = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-CompilerFilePattern",
                        namespaces=ns)[0]
                inst = task.check_visibility(inst=inst,
                                             namespace=ns,
                                             xml_test=xmlTest)
                inst.save()

            # elif xmlTest.xpath("p:test-type", namespaces=ns)[0] == "dejagnu-setup":
            #     for fileref in xmlTest.xpath("p:test-configuration/p:filerefs", namespaces=ns):
            #         if embedded_file_dict.get(fileref.fileref.attrib.get("refid")) is not None:
            #             inst = DejaGnu.DejaGnuSetup.objects.create(task=new_task, order=val_order)
            #             inst.test_defs = embedded_file_dict.get(fileref.fileref.attrib.get("refid"))
            #             inst = task.check_visibility(inst=inst, namespace=ns, xml_test=xmlTest)
            #             inst.save()
            #         # todo else
            #
            # elif xmlTest.xpath("p:test-type", namespaces=ns)[0] == "dejagnu-tester":
            #     for fileref in xmlTest.xpath("p:test-configuration/p:filerefs", namespaces=ns):
            #         if embedded_file_dict.get(fileref.fileref.attrib.get("refid")) is not None:
            #             inst = DejaGnu.DejaGnuTester.objects.create(task=new_task, order=val_order)
            #             inst.test_case = embedded_file_dict.get(fileref.fileref.attrib.get("refid"))
            #             if xmlTest.xpath("p:title", namespaces=ns)[0] is not None:
            #                 inst.name = xmlTest.xpath("p:title", namespaces=ns)[0]
            #             inst = task.check_visibility(inst=inst, namespace=ns, xml_test=xmlTest)
            #             inst.save()

            # elif xmlTest.xpath("p:test-type", namespaces=ns)[0] == "no-type-TextNotChecker":
            # fine = True
            # inst = TextNotChecker.TextNotChecker.objects.create(task=new_task, order=val_order)
            # if xmlTest.xpath("p:title", namespaces=ns) is not None:
            # inst.name = xmlTest.xpath("p:title", namespaces=ns)[0]
            # if (xmlTest.xpath("p:test-configuration/p:test-meta-data/praktomat:config-text",
            # namespaces=ns) and
            # xmlTest.xpath("p:test-configuration/p:test-meta-data/praktomat:config-text",
            # namespaces=ns)[0].text):
            # inst.text = xmlTest.xpath("p:test-configuration/p:test-meta-data/praktomat:config-text",
            # namespaces=ns)[0].text
            # else:
            # inst.delete()
            # fine = False
            # message = "TextNotChecker removed: no config-text"

            # if (fine and xmlTest.xpath("p:test-configuration/p:test-meta-data/"
            # "praktomat:config-max_occurrence",
            # namespaces=ns) and
            # xmlTest.xpath("p:test-configuration/p:test-meta-data/"
            # "praktomat:config-max_occurrence",
            # namespaces=ns)[0].text):
            # inst.max_occ = xmlTest.xpath("p:test-configuration/p:test-meta-data/"
            # "praktomat:config-max_occurrence",
            # namespaces=ns)[0].text
            # else:
            # inst.delete()
            # fine = False
            # message = "TextNotChecker removed: no max_occurence"

            # if fine:
            # inst = task.check_visibility(inst=inst, namespace=ns, xml_test=xmlTest)
            # inst.save()
            # else:
            # pass

            # elif xmlTest.xpath("p:test-type", namespaces=ns)[0] == "textchecker":
            # inst = TextChecker.TextChecker.objects.create(task=new_task, order=val_order)
            # if (xmlTest.xpath("p:test-configuration/p:test-meta-data/praktomat:config-text",
            # namespaces=ns) and
            # xmlTest.xpath("p:test-configuration/p:test-meta-data/p:praktomat:config-text",
            # namespaces=ns)[0].text):
            # inst.text = xmlTest.xpath("p:test-configuration/p:test-meta-data/praktomat:config-text",
            # namespaces=ns)[0].text
            # if xmlTest.xpath("p:title", namespaces=ns) is not None:
            # inst.name = xmlTest.xpath("p:title", namespaces=ns)[0]
            # else:
            # inst.delete()
            # message = "Textchecker removed: no config-text"

            # inst = task.check_visibility(inst=inst, namespace=ns, xml_test=xmlTest)
            # inst.save()

            # setlx with jartest
            elif xmlTest.xpath("p:test-type", namespaces=ns)[0] == "jartest" and \
                    xmlTest.xpath("p:test-configuration/jartest:jartest[@framework='setlX']", namespaces=ns):

                for fileref in xmlTest.xpath("p:test-configuration/p:filerefs",
                                             namespaces=ns):
                    if embedded_file_dict.get(
                            fileref.fileref.attrib.get("refid")) is not None:
                        inst = SetlXChecker.SetlXChecker.objects.create(
                            task=new_task, order=val_order)
                        inst.testFile = embedded_file_dict.get(
                            fileref.fileref.attrib.get("refid"))

                if xmlTest.xpath("p:title", namespaces=ns) is not None:
                    if inst is None:
                        message = "Error in JARTest"
                        break
                    else:
                        inst.name = xmlTest.xpath("p:title", namespaces=ns)[0]

                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-testDescription",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-testDescription",
                        namespaces=ns)[0].text):
                    inst.test_description = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-testDescription",
                        namespaces=ns)[0].text

                inst = task.check_visibility(inst=inst,
                                             namespace=ns,
                                             xml_test=xmlTest)
                inst.save()

            # checkstyle with jartest todo:version-check check for valid regex

            elif xmlTest.xpath("p:test-type", namespaces=ns)[0] == "jartest" and \
                    xmlTest.xpath("p:test-configuration/jartest:jartest[@framework='checkstyle']", namespaces=ns):

                for fileref in xmlTest.xpath("p:test-configuration/p:filerefs",
                                             namespaces=ns):
                    if embedded_file_dict.get(
                            fileref.fileref.attrib.get("refid")) is not None:
                        inst = CheckStyleChecker.CheckStyleChecker.objects.create(
                            task=new_task, order=val_order)
                        inst.configuration = embedded_file_dict.get(
                            fileref.fileref.attrib.get("refid"))
                    if xmlTest.xpath("p:title", namespaces=ns) is not None:
                        inst.name = xmlTest.xpath("p:title", namespaces=ns)[0]
                    if xmlTest.xpath(
                            "p:test-configuration/jartest:jartest/jartest:parameter",
                            namespaces=ns) is not None:
                        para_list = list()
                        for parameter in xmlTest.xpath(
                                "p:test-configuration/jartest:jartest/"
                                "jartest:parameter",
                                namespaces=ns):
                            para_list.append(str(parameter))
                        reg_text = '|'.join(para_list)
                        is_valid = task.reg_check(reg_text)
                        if is_valid:
                            inst.regText = reg_text
                        else:
                            message = "no vaild regex for checkstyle: " + str(
                                reg_text)
                    if xmlTest.xpath(
                            "p:test-configuration/p:test-meta-data/"
                            "praktomat:max-checkstyle-warnings",
                            namespaces=ns) is not None:
                        inst.allowedWarnings = xmlTest.xpath(
                            "p:test-configuration/p:test-meta-data/"
                            "praktomat:max-checkstyle-warnings",
                            namespaces=ns)[0]

                    inst = task.check_visibility(inst=inst,
                                                 namespace=ns,
                                                 xml_test=xmlTest)
                    inst.save()

                if xmlTest.xpath("p:title", namespaces=ns) is not None:
                    inst.name = xmlTest.xpath("p:title", namespaces=ns)[0]

                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-testDescription",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-testDescription",
                        namespaces=ns)[0].text):
                    inst.test_description = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-testDescription",
                        namespaces=ns)[0].text

                inst = task.check_visibility(inst=inst,
                                             namespace=ns,
                                             xml_test=xmlTest)
                inst.save()

            elif xmlTest.xpath("p:test-type", namespaces=ns)[0] == "unittest" and \
                    xmlTest.xpath("p:test-configuration/unit:unittest[@framework='JUnit']", namespaces=ns):
                inst = JUnitChecker.JUnitChecker.objects.create(
                    task=new_task, order=val_order)

                if xmlTest.attrib is not None:
                    attributes = xmlTest.attrib
                    if attributes.get("id"):
                        inst.proforma_id = attributes.get("id")

                if xmlTest.xpath("p:title", namespaces=ns) is not None:
                    inst.name = xmlTest.xpath("p:title", namespaces=ns)[0]

                if (xmlTest.xpath(
                        "p:test-configuration/unit:unittest/unit:main-class",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/unit:unittest/unit:main-class",
                        namespaces=ns)[0].text):
                    inst.class_name = xmlTest.xpath(
                        "p:test-configuration/unit:unittest/unit:main-class",
                        namespaces=ns)[0].text
                else:
                    inst.delete()
                    message = "unittest main-class not found. Check your namespace"
                    break

                if xmlTest.xpath(
                        "p:test-configuration/unit:unittest[@framework='JUnit']",
                        namespaces=ns):
                    if xmlTest.xpath(
                            "p:test-configuration/unit:unittest[@framework='JUnit']",
                            namespaces=ns)[0].attrib.get("version"):
                        version = re.split(
                            '\.',
                            xmlTest.xpath(
                                "p:test-configuration/"
                                "unit:unittest[@framework='JUnit']",
                                namespaces=ns)[0].attrib.get("version"))

                        if int(version[0]) == 3:
                            inst.junit_version = 'junit3'
                        elif int(version[0]) == 4:
                            if str(version[1]) == "12-gruendel":
                                inst.junit_version = 'junit4.12-gruendel'
                            elif str(version[1]) == "12":
                                inst.junit_version = 'junit4.12'
                            else:
                                inst.junit_version = 'junit4'
                        else:
                            inst.delete()
                            message = "JUnit-Version not known: " + str(
                                version)
                            break

                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-testDescription",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-testDescription",
                        namespaces=ns)[0].text):
                    inst.test_description = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-testDescription",
                        namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/"
                        "p:test-meta-data/praktomat:config-testname",
                        namespaces=ns) and xmlTest.xpath(
                            "p:test-configuration/"
                            "p:test-meta-data/praktomat:config-testname",
                            namespaces=ns)[0].text):
                    inst.name = xmlTest.xpath(
                        "p:test-configuration/"
                        "p:test-meta-data/praktomat:config-testname",
                        namespaces=ns)[0].text
                if xmlTest.xpath("p:test-configuration/p:filerefs",
                                 namespaces=ns):
                    val_order = task.creating_file_checker(
                        file_dict=embedded_file_dict,
                        new_task=new_task,
                        ns=ns,
                        val_order=val_order,
                        xml_test=xmlTest,
                        checker=inst)

                inst.order = val_order
                inst = task.check_visibility(inst=inst,
                                             namespace=ns,
                                             xml_test=xmlTest)
                inst.save()

            elif xmlTest.xpath("p:test-type",
                               namespaces=ns)[0] == "java-checkstyle":
                for fileref in xmlTest.xpath("p:test-configuration/p:filerefs",
                                             namespaces=ns):
                    if embedded_file_dict.get(
                            fileref.fileref.attrib.get("refid")) is not None:
                        inst = CheckStyleChecker.CheckStyleChecker.objects.create(
                            task=new_task, order=val_order)
                        inst.configuration = embedded_file_dict.get(
                            fileref.fileref.attrib.get("refid"))
                    if xmlTest.xpath("p:title", namespaces=ns) is not None:
                        inst.name = xmlTest.xpath("p:title", namespaces=ns)[0]
                    if xmlTest.attrib is not None:
                        attributes = xmlTest.attrib
                        if attributes.get("id"):
                            inst.proforma_id = attributes.get("id")
                    if xmlTest.xpath("p:test-configuration/praktomat:version",
                                     namespaces=ns):
                        checkstyle_version = re.split(
                            '\.',
                            xmlTest.xpath(
                                "p:test-configuration/"
                                "praktomat:version",
                                namespaces=ns)[0].text)
                        if int(checkstyle_version[0]) == 7 and int(
                                checkstyle_version[1]) == 6:
                            inst.check_version = 'check-7.6'
                        elif int(checkstyle_version[0]) == 6 and int(
                                checkstyle_version[1]) == 2:
                            inst.check_version = 'check-6.2'
                        elif int(checkstyle_version[0]) == 5 and int(
                                checkstyle_version[1]) == 4:
                            inst.check_version = 'check-5.4'
                        else:
                            inst.delete()
                            message = "Checkstyle-Version is not supported: " + str(
                                checkstyle_version)
                            break

                    if xmlTest.xpath(
                            "p:test-configuration/p:test-meta-data/"
                            "praktomat:max-checkstyle-warnings",
                            namespaces=ns):
                        inst.allowedWarnings = xmlTest.xpath(
                            "p:test-configuration/"
                            "p:test-meta-data/"
                            "praktomat:max-checkstyle-warnings",
                            namespaces=ns)[0]
                    if xmlTest.xpath(
                            "p:test-configuration/p:test-meta-data/"
                            "praktomat:max-checkstyle-errors",
                            namespaces=ns):
                        inst.allowedErrors = xmlTest.xpath(
                            "p:test-configuration/"
                            "p:test-meta-data/"
                            "praktomat:max-checkstyle-errors",
                            namespaces=ns)[0]
                    inst = task.check_visibility(inst=inst,
                                                 namespace=ns,
                                                 xml_test=xmlTest)
                    inst.save()

            elif xmlTest.xpath("p:test-type", namespaces=ns)[0] == "python":
                inst = PythonChecker.PythonChecker.objects.create(
                    task=new_task, order=val_order)
                if (xmlTest.xpath("p:title", namespaces=ns)
                        and xmlTest.xpath("p:title", namespaces=ns)[0].text):
                    inst.name = xmlTest.xpath("p:title", namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-remove-regex",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-remove-regex",
                        namespaces=ns)[0].text):
                    inst.remove = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-remove-regex",
                        namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-returnHtml",
                        namespaces=ns
                ) and xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/praktomat:config-returnHtml",
                        namespaces=ns)[0].text):
                    inst.public = task.str2bool(
                        xmlTest.xpath(
                            "p:test-configuration/"
                            "p:test-meta-data/"
                            "praktomat:config-returnHtml",
                            namespaces=ns)[0].text)
                if xmlTest.xpath("p:test-configuration/p:filerefs",
                                 namespaces=ns):
                    for fileref in xmlTest.xpath(
                            "p:test-configuration/p:filerefs", namespaces=ns):
                        if embedded_file_dict.get(
                                fileref.fileref.attrib.get(
                                    "refid")) is not None:
                            inst.doctest = embedded_file_dict.get(
                                fileref.fileref.attrib.get("refid"))
                            inst = task.check_visibility(inst=inst,
                                                         namespace=ns,
                                                         xml_test=xmlTest)
                            inst.save()
                        else:
                            inst.delete()
                            message = "No File for python-checker found"

            elif xmlTest.xpath("p:test-type",
                               namespaces=ns)[0] == "RemoteScriptChecker":
                inst = RemoteSQLChecker.RemoteScriptChecker.objects.create(
                    task=new_task, order=val_order)
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-studentFilename",
                        namespaces=ns) and xmlTest.xpath(
                            "p:test-configuration/p:test-meta-data/"
                            "praktomat:config-studentFilename",
                            namespaces=ns)[0].text):
                    inst.solution_file_name = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-studentFilename",
                        namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-studentSolutionFilename",
                        namespaces=ns) and xmlTest.xpath(
                            "p:test-configuration/p:test-meta-data/"
                            "praktomat:config-studentSolutionFilename",
                            namespaces=ns)[0].text):
                    inst.student_solution_file_name = xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-studentSolutionFilename",
                        namespaces=ns)[0].text
                if (xmlTest.xpath(
                        "p:test-configuration/p:test-meta-data/"
                        "praktomat:config-returnHtml",
                        namespaces=ns) and xmlTest.xpath(
                            "p:test-configuration/p:test-meta-data/"
                            "praktomat:config-returnHtml",
                            namespaces=ns)[0].text):
                    inst.returns_html = task.str2bool(
                        xmlTest.xpath(
                            "p:test-configuration/"
                            "p:test-meta-data/"
                            "praktomat:config-returnHtml",
                            namespaces=ns)[0].text)
                if xmlTest.xpath("p:test-configuration/p:filerefs",
                                 namespaces=ns):
                    val_order = task.creating_file_checker(embedded_file_dict,
                                                           new_task,
                                                           ns,
                                                           val_order,
                                                           xmlTest,
                                                           checker=inst)

                inst.order = val_order
                inst = task.check_visibility(inst=inst,
                                             namespace=ns,
                                             xml_test=xmlTest)
                inst.save()

            else:
                message = "Following Test could not imported\n" + objectify.dump(
                    xmlTest) + "\r\n"

            # todo handle this properly!
            if inst != None and xmlTest.attrib is not None:
                attributes = xmlTest.attrib
                if attributes.get("id"):
                    inst.proforma_id = attributes.get("id")
                    inst.save()

            val_order += 1
    except Exception:
        new_task.delete()
        raise

    new_task.save()
    return new_task