Ejemplo n.º 1
0
 def parse(self, data):
     """ parse a solr schema to collect information for building
         search and indexing queries later on """
     if isinstance(data, basestring):
         data = StringIO(data)
     self['requiredFields'] = required = []
     types = {}
     for action, elem in iterparse(data):
         name = elem.get('name')
         if elem.tag == 'fieldType':
             types[name] = elem.attrib
         elif elem.tag == 'field':
             field = SolrField(types[elem.get('type')])
             field.update(elem.attrib)
             field['class_'] = field['class']    # `.class` will not work
             for key, value in field.items():    # convert to `bool`s
                 if value in ('true', 'false'):
                     field[key] = value == 'true'
             self[name] = field
             if field.get('required', False):
                 required.append(name)
         elif elem.tag in ('uniqueKey', 'defaultSearchField'):
             self[elem.tag] = elem.text
         elif elem.tag == 'solrQueryParser':
             self[elem.tag] = AttrStr(elem.text, **elem.attrib)
Ejemplo n.º 2
0
 def parse(self, data):
     """ parse a solr schema to collect information for building
         search and indexing queries later on """
     if isinstance(data, basestring):
         data = StringIO(data)
     self['requiredFields'] = required = []
     types = {}
     for action, elem in iterparse(data):
         name = elem.get('name')
         if elem.tag == 'fieldType':
             types[name] = elem.attrib
         elif elem.tag == 'field':
             field = SolrField(types[elem.get('type')])
             field.update(elem.attrib)
             field['class_'] = field['class']  # `.class` will not work
             for key, value in field.items():  # convert to `bool`s
                 if value in ('true', 'false'):
                     field[key] = value == 'true'
             self[name] = field
             if field.get('required', False):
                 required.append(name)
         elif elem.tag in ('uniqueKey', 'defaultSearchField'):
             self[elem.tag] = elem.text
         elif elem.tag == 'solrQueryParser':
             self[elem.tag] = AttrStr(elem.text, **elem.attrib)
Ejemplo n.º 3
0
 def parse(self, data):
     """ parse a solr response contained in a string or file-like object """
     if isinstance(data, basestring):
         data = StringIO(data)
     stack = [self]      # the response object is the outmost container
     elements = iterparse(data, events=('start', 'end'))
     for action, elem in elements:
         tag = elem.tag
         if action == 'start':
             if tag in nested:
                 data = nested[tag]()
                 for key, value in elem.attrib.items():
                     if not key == 'name':   # set extra attributes
                         setattr(data, key, value)
                 stack.append(data)
         elif action == 'end':
             if tag in nested:
                 data = stack.pop()
                 setter(stack[-1], elem.get('name'), data)
             elif tag in self.unmarshallers:
                 data = self.unmarshallers[tag](elem.text)
                 setter(stack[-1], elem.get('name'), data)
     return self
Ejemplo n.º 4
0
 def parse(self, data):
     """ parse a solr response contained in a string or file-like object """
     if isinstance(data, basestring):
         data = StringIO(data)
     stack = [self]  # the response object is the outmost container
     elements = iterparse(data, events=('start', 'end'))
     for action, elem in elements:
         tag = elem.tag
         if action == 'start':
             if tag in nested:
                 data = nested[tag]()
                 for key, value in elem.attrib.items():
                     if not key == 'name':  # set extra attributes
                         setattr(data, key, value)
                 stack.append(data)
         elif action == 'end':
             if tag in nested:
                 data = stack.pop()
                 setter(stack[-1], elem.get('name'), data)
             elif tag in self.unmarshallers:
                 data = self.unmarshallers[tag](elem.text)
                 setter(stack[-1], elem.get('name'), data)
     return self