def _get_content(self, *args, **kwargs): """Use open_compressed and return content using a with-statement.""" # open_archive default is True, so if it's False it's not the default # so use the non-default of open_compressed (which is True) if kwargs.get('use_extension') is False: kwargs['use_extension'] = True with tools.open_compressed(*args, **kwargs) as f: content = f.read() self.assertOneDeprecation(self.INSTEAD) return content
def _get_content(self, *args, **kwargs): """Use open_compressed and return content using a with-statement.""" # open_archive default is True, but open_compressed default is False. # The test cases assumes a default of True and we need to make # open_compressed acknowledge that. if 'use_extension' not in kwargs: kwargs['use_extension'] = True with tools.open_compressed(*args, **kwargs) as f: content = f.read().replace(b'\r\n', b'\n') self.assertOneDeprecation(self.INSTEAD) return content
def parse(self): """Generator using cElementTree iterparse function.""" with open_compressed(self.filename) as source: # iterparse's event must be a str but they are unicode with # unicode_literals in Python 2 context = iterparse(source, events=(str("start"), str("end"), str("start-ns"))) self.root = None for event, elem in context: if event == "start-ns" and elem[0] == "": self.uri = elem[1] continue if event == "start" and self.root is None: self.root = elem continue for rev in self._parse(event, elem): yield rev
def parse(self): """Generator using cElementTree iterparse function.""" with open_compressed(self.filename) as source: # iterparse's event must be a str but they are unicode with # unicode_literals in Python 2 context = iterparse(source, events=(str('start'), str('end'), str('start-ns'))) self.root = None for event, elem in context: if event == "start-ns" and elem[0] == "": self.uri = elem[1] continue if event == "start" and self.root is None: self.root = elem continue for rev in self._parse(event, elem): yield rev
def _get_content(*args): """Use open_compressed and return content using a with-statement.""" with tools.open_compressed(*args) as f: return f.read()