def _XMLDumpPrimitive (self, key, value, indent, attrs_ptr, was_array_typecode=None) :
      if attrs_ptr is None :
          attrs = self.EMPTYAttrs_
      else :
          attrs = attrs_ptr

      if (self._IsComposite(value)) :
          raise Exception("Trying to dump a composite type as a primitive")
  
      if value is None :
          self._XMLDumpStartTag(key, attrs, indent, True, True)
          return

      self._XMLDumpStartTag(key, attrs, indent, True)

      # Force all strings into quotes, messy but will always work
      # with XML_LOAD_EVAL_CONTENT on the way back if you have to convert
      if (self.options_ & XML_DUMP_STRINGS_AS_STRINGS) :
          if (type(value) == str) : # make sure pick up quotes 
              self.os_.write(self._XMLContentFilter(repr(value), was_array_typecode))
          else :
              self.os_.write(self._XMLContentFilter(value, was_array_typecode)) # Let str pick 

      # Most of the time, we can keep all strings as-is (and avoid
      # those nasty '&apos;' quotes in XML around them): those
      # strings that will become something "real values" when Evalled 
      # need to have quotes so they will come back as strings
      # when using XML_LOAD_EVAL_CONTENT.  For example: '123' is a string
      # but when evaled, will become a number;  We dump this as 
      # "&apos;123&apos;" to preserve the numberness.
      elif (self.options_ & XML_DUMP_STRINGS_BEST_GUESS) :
          if (type(value)==str) :
              s = str(value)    # no quotes on string
              if (len(s)==0 or # always dump empty strings with &apos!
                  ((len(s)>0) and 
                   (s[0].isdigit() or s[0]=='(' or s[0]=='-' or s[0]=='+'))) :
                  # If it starts with a number or a sign or '(' (for (1+2j), 
                  # probably a number and we WANT to stringize
                  self.os_.write(self._XMLContentFilter(repr(value), was_array_typecode)) # puts quotes on str
              else :
                  self.os_.write(self._XMLContentFilter(value, was_array_typecode)) # no quotes!
          else :
              self.os_.write(self._XMLContentFilter(value, was_array_typecode)) # Let str pick 
  

      # Default, just plop content: still be careful of <empty></empty>:
      # Should that be a {}, None, [], or ""?  With this option, makes it
      # empty string (you don't need this option if you are using
      # XML_DUMP_STRINGS_BEST_GUESS or XML_DUMP_STRINGS_AS_STRINGS
      else :
          if (self.options_ & XML_DUMP_PREFER_EMPTY_STRINGS) :
              if type(value)==str and len(value)==0 :
                  value =  "''"  # Makes <empty></empty> into empty string

          self.os_.write(self._XMLContentFilter(value, was_array_typecode))
  
      self._XMLDumpEndTag(key, indent, True)


  # Centralize error handling
dataset/ETHPy150Open redhat-imaging/imagefactory/imgfac/picklingtools/xmldumper.py/XMLDumper._XMLDumpPrimitive/original