Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_getting_standard_product_from_upc(self):
upc = '1234567890'
profile = factories.AmazonProfileFactory(product__upc=upc)
spi = profile.get_standard_product_id()
self.assertEquals(
etree.tostring(spi),
PRODUCT_TYPE_XML.format('UPC', upc)
)
attr = ""
innerHTML = ""
for key, value in cell.iteritems():
val = unicode(str(value), "utf-8")
if key != "text":
attr += " %s='%s'" % (key, val)
else:
innerHTML = val
r.append(html.fromstring("%s" % (attr, innerHTML)))
tbody.append(r)
table.append(tbody)
return etree.tostring(table, pretty_print=True)
entry.set(attr, str(data[idx]))
if entry.tag == 'POSIXUser':
try:
entry.set("group", grp.getgrgid(data[3])[0])
except KeyError:
logger.warning("User %s is a member of nonexistent group %s" %
(entry.get("name"), data[3]))
entry.set("group", str(data[3]))
for group in users.user_supplementary_groups(entry):
memberof = lxml.etree.SubElement(entry, "MemberOf",
group=group[0])
entry.tag = "Bound" + entry.tag
baseline.append(entry)
print(lxml.etree.tostring(baseline, pretty_print=True))
def format_value(self, value):
formatted = etree.tostring(value, encoding='unicode', method='html')
if self.strip_xhtml_ns:
formatted = formatted.replace(u' xmlns="http://www.w3.org/1999/xhtml"', '')
return formatted
read_network=False,
write_network=False)
xsl_style = env.subst('$DOCBOOK_XSL')
xsl_tree = etree.parse(xsl_style)
transform = etree.XSLT(xsl_tree, access_control=xslt_ac)
doc = etree.parse(str(source[0]))
# Support for additional parameters
parampass = {}
if parampass:
result = transform(doc, **parampass)
else:
result = transform(doc)
try:
of = open(str(target[0]), "wb")
of.write(of.write(etree.tostring(result, pretty_print=True)))
of.close()
except:
pass
return None
else:
hsterms_swat_model_parameters.text = \
self.model_parameter.get_swat_model_parameters()
if self.model_input:
modelInputFields = ['warmupPeriodType', 'warmupPeriodValue', 'rainfallTimeStepType',
'rainfallTimeStepValue', 'routingTimeStepType',
'routingTimeStepValue', 'simulationTimeStepType',
'simulationTimeStepValue', 'watershedArea', 'numberOfSubbasins',
'numberOfHRUs', 'demResolution', 'demSourceName', 'demSourceURL',
'landUseDataSourceName', 'landUseDataSourceURL',
'soilDataSourceName', 'soilDataSourceURL'
]
self.add_metadata_element_to_xml(container, self.model_input, modelInputFields)
return etree.tostring(RDF_ROOT, pretty_print=pretty_print)
def _html4_parse(data):
data = html.fromstring(data)
data.attrib.pop('xmlns', None)
for elem in data.iter(tag=etree.Comment):
if elem.text:
elem.text = elem.text.strip('-')
data = etree.tostring(data, encoding='unicode')
# Setting huge_tree=True causes crashes in windows with large files
parser = etree.XMLParser(no_network=True)
try:
data = etree.fromstring(data, parser=parser)
except etree.XMLSyntaxError:
data = etree.fromstring(data, parser=RECOVER_PARSER)
return data
def add_eni_info(instances):
eni_url = "http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html"
tree = etree.parse(urllib2.urlopen(eni_url), etree.HTMLParser())
table = tree.xpath('//div[@class="table-contents"]//table')[0]
rows = table.xpath('.//tr[./td]')
by_type = {i.instance_type: i for i in instances}
for r in rows:
instance_type = etree.tostring(r[0], method='text').strip().decode()
max_enis = locale.atoi(etree.tostring(r[1], method='text').decode())
ip_per_eni = locale.atoi(etree.tostring(r[2], method='text').decode())
if instance_type not in by_type:
print("Unknown instance type: {}".format(instance_type))
continue
by_type[instance_type].vpc = {
'max_enis': max_enis,
'ips_per_eni': ip_per_eni}
# Recommended
# TODO author is REQUIRED if the whole feed lacks one!
#atom_el.author("TODO"),
#atom_el.content("TODO"),
atom_el.link(rel="alternate", href=url),
#atom_el.summary("TODO"),
# Optional
#atom_el.category("..."),
#atom_el.contributor("..."),
#atom_el.published("..."),
#atom_el.source("..."),
#atom_el.rights("..."),
))
xml = etree.tostring(
root,
pretty_print=True,
encoding="UTF-8",
xml_declaration=True)
return Response(xml, content_type="text/xml", charset="UTF-8")