예제 #1
0
파일: __init__.py 프로젝트: Ismatov/gsl-en
 def pull(self):
     """Returns an iterator over the items in this template."""
     # create stream and apply filters
     self.initialize()
     stream = ElementStream(_coalesce(self.content(),
         self._get_assume_encoding()))
     return stream
 def pull(self):
     """Returns an iterator over the items in this template."""
     # create stream and apply filters
     self.initialize()
     stream = ElementStream(
         _coalesce(self.content(), self._get_assume_encoding()))
     return stream
def apply_matches(stream, template, templates, apply_func):
    for ev, item in stream:
        if ev == START:
            matched = False
            for i in range(0, len(templates)):
                match, call = templates[i]
                if match(item):
                    item = stream.expand()
                    newstream = _coalesce(call(template, item, apply_func),
                                          template._get_assume_encoding())
                    if len(templates) < 2:
                        for ev, item in newstream:
                            yield ev, item
                    else:
                        for ev, item in apply_matches(
                                ElementStream(newstream), template,
                                templates[:i] + templates[i + 1:], apply_func):
                            yield ev, item
                    matched = True
                    break
            if matched:
                continue
        yield ev, item
예제 #4
0
파일: filter.py 프로젝트: thraxil/gtreed
def apply_matches(stream, template, templates, apply_func):
    for ev, item in stream:
        if ev == START:
            matched = False
            for i in range(0, len(templates)):
                match, call = templates[i]
                if match(item):
                    item = stream.expand()
                    newstream = _coalesce(call(template, item, apply_func),
                        template._get_assume_encoding())
                    if len(templates) < 2:
                        for ev, item in newstream:
                            yield ev, item
                    else:
                        for ev, item in apply_matches(
                                ElementStream(newstream), template,
                                templates[:i] + templates[i+1:], apply_func):
                            yield ev, item
                    matched = True
                    break
            if matched:
                continue
        yield ev, item
예제 #5
0
 def apply_filters(self, stream, format=None):
     stream = _coalesce(stream, self.src_encoding)
     if format:
         stream = self.format_stream(stream, format)
     return stream
예제 #6
0
 def apply_filters(self, stream, format=None):
     stream = _coalesce(stream, self.src_encoding)
     if format:
         stream = self.format_stream(stream, format)
     return stream