Example #1
0
def ISO_from_name(cname, cslist, tag):
    res = utility.get_default_error()
    found = False
    cs = cslist[0]
    ss = cslist[1]
    sname = (utility.to_str(cname)).upper().strip()

    for c in cs:
        name = (utility.to_str(c['Name'])).upper().strip()
        if (sname == name):
            found = True
            res = c[tag]
            break
        else:
            found = False

    if (not found):
        for s in ss:
            names = ((utility.to_str(s['Country'])).upper().strip()).split(delimiter)
            for name in names:
                mname = str(name).upper().strip()
                if (sname == mname):
                    res = s[tag]
                    found = True
                    #print "MINOR CONCERN - ", sname, " was found in the country synonym list."
                    break
            if found == True:
                break

    if res == utility.get_default_error(): 
        print "MAJOR ERROR - ", sname, " was not found in the ISO country or synonym lists"

    return res 
def write_record(target, cr, count): 
	ckeys = cr.keys()
	for n in range(0, len(cr)): 
		kv = cr[ckeys[n]]
		if (type(kv) == list):
			target.write( utility.tabs(count) + utility.create_starting_xml_tag(ckeys[n]) + utility.get_newline() )
			if (ckeys[n] != "Goods") and (ckeys[n] != "Suggested_Actions"):
				for l in kv:
					write_record(target, l, count+1)
			if (ckeys[n] == "Goods"):
				for good in cr[ckeys[n]]:
					target.write( utility.tabs(count+1) + "<Good>" + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Good_Name"))
					target.write( good["Good_Name"])
					target.write( utility.create_closing_xml_tag("Good_Name") + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Child_Labor") )
					target.write( good["Child_Labor"] )
					target.write( utility.create_closing_xml_tag("Child_Labor") + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Forced_Labor") )
					target.write( good["Forced_Labor"]  )
					target.write( utility.create_closing_xml_tag("Forced_Labor") + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Forced_Child_Labor")  )
					target.write( good["Forced_Child_Labor"]  )
					target.write( utility.create_closing_xml_tag("Forced_Child_Labor") + utility.get_newline() )
					target.write( utility.tabs(count+1) + "</Good>" + utility.get_newline() )
			if (ckeys[n] == "Suggested_Actions"):
				sga = cr[ckeys[n]]
				for action in sga:
					stripped = unicode(utility.unicode_to_str(action['Area']), 'ascii', 'ignore')
					xmltag = sanitize(utility.unicode_to_str(stripped))
					target.write( utility.tabs(count+1) + utility.create_starting_xml_tag(xmltag) + utility.get_newline() )
					for act in action['Actions']:
						target.write(utility.tabs(count+2) + utility.create_starting_xml_tag("Action") + utility.get_newline() )
						aname = special_chars.xml_safe(utility.unicode_to_str(act['Name']), sp_chars)
						ayears = special_chars.xml_safe(utility.unicode_to_str(act['Years']), sp_chars)
						target.write(utility.tabs(count+3) + utility.create_starting_xml_tag("Name")  
						             + aname + utility.create_closing_xml_tag("Name")
						             + utility.get_newline() )
						target.write(utility.tabs(count+3) + utility.create_starting_xml_tag("Years")  
						             + ayears + utility.create_closing_xml_tag("Years")
						             + utility.get_newline() )
						target.write(utility.tabs(count+2) + utility.create_closing_xml_tag("Action") + utility.get_newline() )
					target.write( utility.tabs(count+1) + utility.create_closing_xml_tag(xmltag) + utility.get_newline() )
			target.write( utility.tabs(count) + utility.create_closing_xml_tag(ckeys[n]) + utility.get_newline() )
		else:
			keyname = utility.to_str(ckeys[n])
			start = utility.create_starting_xml_tag(keyname)
			val = special_chars.xml_safe(utility.to_str(cr[keyname]), sp_chars)
			end = utility.create_closing_xml_tag(keyname)
			target.write( utility.tabs(count) + start + val + end + utility.get_newline() )
	return
Example #3
0
def write_record(target, cr, count):
    ckeys = cr.keys()
    for n in range(0, len(cr)):
        kv = cr[ckeys[n]]
        if (type(kv) == list):
            target.write(
                utility.tabs(count) +
                utility.create_starting_xml_tag(ckeys[n]) +
                utility.get_newline())
            count += 1
            for l in kv:
                this_key_group = (ckeys[n])[:(len(ckeys[n]) - 1)]
                if len(kv) > 0:
                    this_key_group = this_key_group.replace("ie", "y")
                    #print this_key_group
                    target.write(
                        utility.tabs(count) +
                        utility.create_starting_xml_tag(this_key_group) +
                        utility.get_newline())
                write_record(target, l, count + 1)
                if len(kv) > 0:
                    target.write(
                        utility.tabs(count) +
                        utility.create_closing_xml_tag(this_key_group) +
                        utility.get_newline())
            target.write(
                utility.tabs(count - 1) +
                utility.create_closing_xml_tag(ckeys[n]) +
                utility.get_newline())
        else:
            keyname = utility.to_str(ckeys[n])
            start = utility.create_starting_xml_tag(keyname)
            val = special_chars.xml_safe(utility.to_str(cr[keyname]), sp_chars)
            end = utility.create_closing_xml_tag(keyname)
            target.write(
                utility.tabs(count) + start + val + end +
                utility.get_newline())
    return
Example #4
0
def write_record(target, cr, count): 
	ckeys = cr.keys()
	for n in range(0, len(cr)): 
		kv = cr[ckeys[n]]
		if (type(kv) == list):
			target.write( utility.tabs(count) + utility.create_starting_xml_tag(ckeys[n]) + utility.get_newline() )
			count += 1
			for l in kv:
				this_key_group = (ckeys[n])[:(len(ckeys[n])-1)]
				if len(kv) > 0:
					this_key_group = this_key_group.replace("ie", "y")
					#print this_key_group
					target.write( utility.tabs(count) + utility.create_starting_xml_tag(this_key_group) + utility.get_newline())
				write_record(target, l, count+1)
				if len(kv) > 0:
					target.write( utility.tabs(count) + utility.create_closing_xml_tag(this_key_group) + utility.get_newline())
			target.write( utility.tabs(count-1) + utility.create_closing_xml_tag(ckeys[n]) + utility.get_newline() )
		else:
			keyname = utility.to_str(ckeys[n])
			start = utility.create_starting_xml_tag(keyname)
			val = special_chars.xml_safe(utility.to_str(cr[keyname]), sp_chars)
			end = utility.create_closing_xml_tag(keyname)
			target.write( utility.tabs(count) + start + val + end + utility.get_newline() )
	return
def write_record(target, cr, count):
    ckeys = cr.keys()
    for n in range(0, len(cr)):
        kv = cr[ckeys[n]]
        if (type(kv) == list):
            target.write(
                utility.tabs(count) +
                utility.create_starting_xml_tag(ckeys[n]) +
                utility.get_newline())
            if (ckeys[n] != "Goods") and (ckeys[n] != "Suggested_Actions"):
                for l in kv:
                    write_record(target, l, count + 1)
            if (ckeys[n] == "Goods"):
                for good in cr[ckeys[n]]:
                    target.write(
                        utility.tabs(count + 1) + "<Good>" +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Good_Name"))
                    target.write(good["Good_Name"])
                    target.write(
                        utility.create_closing_xml_tag("Good_Name") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Child_Labor"))
                    target.write(good["Child_Labor"])
                    target.write(
                        utility.create_closing_xml_tag("Child_Labor") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Forced_Labor"))
                    target.write(good["Forced_Labor"])
                    target.write(
                        utility.create_closing_xml_tag("Forced_Labor") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Forced_Child_Labor"))
                    target.write(good["Forced_Child_Labor"])
                    target.write(
                        utility.create_closing_xml_tag("Forced_Child_Labor") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 1) + "</Good>" +
                        utility.get_newline())
            if (ckeys[n] == "Suggested_Actions"):
                sga = cr[ckeys[n]]
                for action in sga:
                    stripped = unicode(utility.unicode_to_str(action['Area']),
                                       'ascii', 'ignore')
                    xmltag = sanitize(utility.unicode_to_str(stripped))
                    target.write(
                        utility.tabs(count + 1) +
                        utility.create_starting_xml_tag(xmltag) +
                        utility.get_newline())
                    for act in action['Actions']:
                        target.write(
                            utility.tabs(count + 2) +
                            utility.create_starting_xml_tag("Action") +
                            utility.get_newline())
                        aname = special_chars.xml_safe(
                            utility.unicode_to_str(act['Name']), sp_chars)
                        ayears = special_chars.xml_safe(
                            utility.unicode_to_str(act['Years']), sp_chars)
                        target.write(
                            utility.tabs(count + 3) +
                            utility.create_starting_xml_tag("Name") + aname +
                            utility.create_closing_xml_tag("Name") +
                            utility.get_newline())
                        target.write(
                            utility.tabs(count + 3) +
                            utility.create_starting_xml_tag("Years") + ayears +
                            utility.create_closing_xml_tag("Years") +
                            utility.get_newline())
                        target.write(
                            utility.tabs(count + 2) +
                            utility.create_closing_xml_tag("Action") +
                            utility.get_newline())
                    target.write(
                        utility.tabs(count + 1) +
                        utility.create_closing_xml_tag(xmltag) +
                        utility.get_newline())
            target.write(
                utility.tabs(count) +
                utility.create_closing_xml_tag(ckeys[n]) +
                utility.get_newline())
        else:
            keyname = utility.to_str(ckeys[n])
            start = utility.create_starting_xml_tag(keyname)
            val = special_chars.xml_safe(utility.to_str(cr[keyname]), sp_chars)
            end = utility.create_closing_xml_tag(keyname)
            target.write(
                utility.tabs(count) + start + val + end +
                utility.get_newline())
    return