Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2013
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. # Regex to find unicode characters that are not valid in XML
  2. # http://en.wikipedia.org/wiki/Valid_characters_in_XML
  3. invalid_xml_chars = re.compile(u'[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F]')
  4.  
  5. # Create the temp file to hold the XML
  6. xml = StringIO()
  7.  
  8. s = unicode(xml_tpl.format(data_obj))
  9. xml.write(re.sub(invalid_xml_chars, u"", s).encode('utf-8', 'xmlcharrefreplace'))
  10. xml.seek(0)
  11.  
  12. ftp = FTP(credential..)
  13. # Set connection mode to active
  14. ftp.set_pasv(False)
  15. ftp.storbinary("STOR file.xml", xml)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement