Ejemplo n.º 1
0
    def __profile_name_to_location (self, profile, node):
        if not profile:
            return None

        uri = self.__ldap_query ("locationmap", {"p":profile, "h":socket.getfqdn()})
        if uri:
            return uri

        # do the necessary URI escaping of the profile name if needed
        orig_profile = profile
        try:
            tmp = parseURI(profile)
        except:
            profile = libxml2.URIEscapeStr(profile, "/:")

        # if there is a base on the node, then use 
        if node != None:
            try:
                base = node.getBase(None)
                if base != None and base != "" and \
                   base != os.path.join (config.PROFILESDIR, "users.xml"):
                    # URI composition from the base
                    ret = libxml2.buildURI(profile, base)
                    if ret[0] == '/':
                        ret = libxml2.URIUnescapeString(ret, len(ret), None)
                    dprint("Converted profile name '%s' to location '%s'\n",
                           orig_profile, ret)
                    return ret
            except:
                pass
        try:
            uri = libxml2.parseURI(profile);
            if uri.scheme() is None:
                # it is a file path
                if profile[0] != '/':
                    profile = os.path.join (config.PROFILESDIR, profile)
                if profile[-4:] != ".zip":
                    profile = profile + ".zip"
            else:
                # TODO need to make a local copy or use the local copy
                profile = profile
        except:
            # we really expect an URI there
            profile = None

        if profile[0] == '/':
            profile = libxml2.URIUnescapeString(profile, len(profile), None)
        dprint("Converted profile name '%s' to location '%s'\n",
               orig_profile, profile)
        return profile
Ejemplo n.º 2
0
def runTestCases(case):
    creator = case.prop('creator')
    if creator != None:
        print "=>", creator
    base = case.getBase(None)
    basedir = case.prop('basedir')
    if basedir != None:
        base = libxml2.buildURI(basedir, base)
    test = case.children
    while test != None:
        if test.name == 'testcase':
            runTest(test, base)
        if test.name == 'testcases':
            runTestCases(test)
        test = test.next
def runTestCases(case):
    creator = case.prop('creator')
    if creator != None:
	print "=>", creator
    base = case.getBase(None)
    basedir = case.prop('basedir')
    if basedir != None:
	base = libxml2.buildURI(basedir, base)
    test = case.children
    while test != None:
        if test.name == 'testcase':
	    runTest(test, base)
	if test.name == 'testcases':
	    runTestCases(test)
        test = test.next
Ejemplo n.º 4
0
def runTestCases(case):
    creator = case.prop("creator")
    if creator is not None:
        print "=>", creator
    base = case.getBase(None)
    basedir = case.prop("basedir")
    if basedir is not None:
        base = libxml2.buildURI(basedir, base)
    test = case.children
    while test is not None:
        if test.name == "testcase":
            runTest(test, base)
        if test.name == "testcases":
            runTestCases(test)
        test = test.next
Ejemplo n.º 5
0
def scanXMLDateArchive(t = None, force = 0, max_fetch = 0):
    if max_fetch <= 0:
        max_fetch = config.get_mail_max_fetch()

    url = getXMLDateArchive(t)
    prefix = getXMLDatePrefix(t)
    month = getXMLDateMonth(t)
    if verbose:
        print "loading %s" % (url)
    else:
        print "loading Web archive page"
    try:
        doc = libxml2.htmlParseFile(url, None);
    except:
        doc = None
    if doc == None:
        print "Failed to parse %s" % (url)
        return -1
    max_fetch -= 1
    ctxt = doc.xpathNewContext()
    anchors = ctxt.xpathEval("//a[@href]")
    links = 0
    newmsg = 0
    for anchor in anchors:
        href = anchor.prop("href")
        if href == None or href[0:3] != "msg":
            continue
        try:
            suffix=href[3:]
            if suffix[-5:] == ".html":
                suffix = suffix[:-5]
            links = links + 1

            url = libxml2.buildURI(href, url)
            title = anchor.content
            msgid = "%s-%s" % (month, suffix)
            loaded = scanXMLMsgArchive(url, msgid, title, force)
            newmsg = newmsg + loaded
            max_fetch -= loaded
            if max_fetch <= 0:
                return newmsg

        except:
            pass

    print "loading done"
    return newmsg
Ejemplo n.º 6
0
def scanXMLDateArchive(t = None, force = 0):
    global wordsDictArchive

    wordsDictArchive = {}

    url = getXMLDateArchive(t)
    print "loading %s" % (url)
    try:
	doc = libxml2.htmlParseFile(url, None);
    except:
        doc = None
    if doc == None:
        print "Failed to parse %s" % (url)
	return -1
    ctxt = doc.xpathNewContext()
    anchors = ctxt.xpathEval("//a[@href]")
    links = 0
    newmsg = 0
    for anchor in anchors:
	href = anchor.prop("href")
	if href == None or href[0:3] != "msg":
	    continue
        try:
	    links = links + 1

	    msg = libxml2.buildURI(href, url)
	    title = anchor.content
	    if title != None and title[0:4] == 'Re: ':
	        title = title[4:]
	    if title != None and title[0:6] == '[xml] ':
	        title = title[6:]
	    if title != None and title[0:7] == '[xslt] ':
	        title = title[7:]
	    newmsg = newmsg + scanXMLMsgArchive(msg, title, force)

	except:
	    pass

    return newmsg
Ejemplo n.º 7
0
def runTest(test):
    global test_nr
    global test_succeed
    global test_failed
    global error_msg
    global log

    uri = test.prop('URI')
    id = test.prop('ID')
    if uri == None:
        print("Test without ID:", uri)
        return -1
    if id == None:
        print("Test without URI:", id)
        return -1
    base = test.getBase(None)
    URI = libxml2.buildURI(uri, base)
    if os.access(URI, os.R_OK) == 0:
        print("Test %s missing: base %s uri %s" % (URI, base, uri))
        return -1
    type = test.prop('TYPE')
    if type == None:
        print("Test %s missing TYPE" % (id))
        return -1

    extra = None
    if type == "invalid":
        res = testInvalid(URI, id)
    elif type == "valid":
        res = testValid(URI, id)
    elif type == "not-wf":
        extra = test.prop('ENTITIES')
        # print URI
        #if extra == None:
        #    res = testNotWfEntDtd(URI, id)
        #elif extra == 'none':
        #    res = testNotWf(URI, id)
        #elif extra == 'general':
        #    res = testNotWfEnt(URI, id)
        #elif extra == 'both' or extra == 'parameter':
        res = testNotWfEntDtd(URI, id)

#else:
#    print "Unknow value %s for an ENTITIES test value" % (extra)
#    return -1
    elif type == "error":
        res = testError(URI, id)
    else:
        # TODO skipped for now
        return -1

    test_nr = test_nr + 1
    if res > 0:
        test_succeed = test_succeed + 1
    elif res == 0:
        test_failed = test_failed + 1
    elif res < 0:
        test_error = test_error + 1

    # Log the ontext
    if res != 1:
        log.write("   File: %s\n" % (URI))
        content = string.strip(test.content)
        while content[-1] == '\n':
            content = content[0:-1]
        if extra != None:
            log.write("   %s:%s:%s\n" % (type, extra, content))
        else:
            log.write("   %s:%s\n\n" % (type, content))
        if error_msg != '':
            log.write("   ----\n%s   ----\n" % (error_msg))
            error_msg = ''
        log.write("\n")

    return 0
Ejemplo n.º 8
0
def runTest(test):
    global test_nr
    global test_succeed
    global test_failed
    global error_msg
    global log

    uri = test.prop('URI')
    id = test.prop('ID')
    if uri is None:
        print "Test without ID:", uri
	return -1
    if id is None:
        print "Test without URI:", id
	return -1
    base = test.getBase(None)
    URI = libxml2.buildURI(uri, base)
    if os.access(URI, os.R_OK) == 0:
        print "Test %s missing: base %s uri %s" % (URI, base, uri)
	return -1
    type = test.prop('TYPE')
    if type is None:
        print "Test %s missing TYPE" % (id)
	return -1

    extra = None
    if type == "invalid":
        res = testInvalid(URI, id)
    elif type == "valid":
        res = testValid(URI, id)
    elif type == "not-wf":
        extra =  test.prop('ENTITIES')
	# print URI
	#if extra == None:
	#    res = testNotWfEntDtd(URI, id)
 	#elif extra == 'none':
	#    res = testNotWf(URI, id)
	#elif extra == 'general':
	#    res = testNotWfEnt(URI, id)
	#elif extra == 'both' or extra == 'parameter':
	res = testNotWfEntDtd(URI, id)
	#else:
	#    print "Unknow value %s for an ENTITIES test value" % (extra)
	#    return -1
    elif type == "error":
	res = testError(URI, id)
    else:
        # TODO skipped for now
	return -1

    test_nr = test_nr + 1
    if res > 0:
	test_succeed = test_succeed + 1
    elif res == 0:
	test_failed = test_failed + 1
    elif res < 0:
	test_error = test_error + 1

    # Log the ontext
    if res != 1:
	log.write("   File: %s\n" % (URI))
	content = string.strip(test.content)
	while content[-1] == '\n':
	    content = content[0:-1]
	if extra is not None:
	    log.write("   %s:%s:%s\n" % (type, extra, content))
	else:
	    log.write("   %s:%s\n\n" % (type, content))
	if error_msg != '':
	    log.write("   ----\n%s   ----\n" % (error_msg))
	    error_msg = ''
	log.write("\n")

    return 0