parameters: (stream)
return_statement: return ch.output
docstring: Loads an SVG image from a stream (can be a string or a file object).
docstring_summary: Loads an SVG image from a stream (can be a string or a file object).
docstring_tokens: Loads an SVG image from a stream ( can be a string or a file object ) .
function: def load_stream(stream):
      """Loads an SVG image from a stream (can be a string or a file object)."""
  
      from xml.sax import handler, make_parser
      from xml.sax.handler import feature_namespaces, feature_external_ges, feature_external_pes
  
      class ContentHandler(handler.ContentHandler):
          def __init__(self):
              self.stack = []
              self.output = None
              self.all_whitespace = re.compile(r"^\s*$")
  
          def startElement(self, name, attr):
              s = SVG(name)
              s.attr = dict(attr.items())
              if len(self.stack) > 0:
                  last = self.stack[-1]
                  last.sub.append(s)
              self.stack.append(s)
  
          def characters(self, ch):
              if not isinstance(ch, basestring) or self.all_whitespace.match(ch) is None:
                  if len(self.stack) > 0:
                      last = self.stack[-1]
                      if len(last.sub) > 0 and isinstance(last.sub[-1], basestring):
                          last.sub[-1] = last.sub[-1] + "\n" + ch
                      else:
                          last.sub.append(ch)
  
          def endElement(self, name):
              if len(self.stack) > 0:
                  last = self.stack[-1]
                  if (isinstance(last, SVG) and last.t == "style" and
                      "type" in last.attr and last.attr["type"] == "text/css" and
                      len(last.sub) == 1 and isinstance(last.sub[0], basestring)):
                      last.sub[0] = "<![CDATA[\n" + last.sub[0] + "]]>"
  
              self.output = self.stack.pop()
  
      ch = ContentHandler()
      parser = make_parser()
      parser.setContentHandler(ch)
      parser.setFeature(feature_namespaces, 0)
      parser.setFeature(feature_external_ges, 0)
      parser.parse(stream)
      return ch.output
function_tokens: def load_stream ( stream ) : from xml . sax import handler , make_parser from xml . sax . handler import feature_namespaces , feature_external_ges , feature_external_pes class ContentHandler ( handler . ContentHandler ) : def __init__ ( self ) : self . stack = [ ] self . output = None self . all_whitespace = re . compile ( r"^\s*$" ) def startElement ( self , name , attr ) : s = SVG ( name ) s . attr = dict ( attr . items ( ) ) if len ( self . stack ) > 0 : last = self . stack [ - 1 ] last . sub . append ( s ) self . stack . append ( s ) def characters ( self , ch ) : if not isinstance ( ch , basestring ) or self . all_whitespace . match ( ch ) is None : if len ( self . stack ) > 0 : last = self . stack [ - 1 ] if len ( last . sub ) > 0 and isinstance ( last . sub [ - 1 ] , basestring ) : last . sub [ - 1 ] = last . sub [ - 1 ] + "\n" + ch else : last . sub . append ( ch ) def endElement ( self , name ) : if len ( self . stack ) > 0 : last = self . stack [ - 1 ] if ( isinstance ( last , SVG ) and last . t == "style" and "type" in last . attr and last . attr [ "type" ] == "text/css" and len ( last . sub ) == 1 and isinstance ( last . sub [ 0 ] , basestring ) ) : last . sub [ 0 ] = "<![CDATA[\n" + last . sub [ 0 ] + "]]>" self . output = self . stack . pop ( ) ch = ContentHandler ( ) parser = make_parser ( ) parser . setContentHandler ( ch ) parser . setFeature ( feature_namespaces , 0 ) parser . setFeature ( feature_external_ges , 0 ) parser . parse ( stream ) return ch . output