def __str__(self): """Convert to a string. double check that unicode is handled somehow here""" self._cpo_store = cpo.pofile(encoding=self._encoding, noheader=True) self._build_cpo_from_self() output = str(self._cpo_store) del self._cpo_store return output
def __str__(self): """Convert to a string. double check that unicode is handled somehow here""" self._cpo_store = cpo.pofile(encoding=self._encoding) self._build_cpo_from_self() output = str(self._cpo_store) del self._cpo_store return output
def __str__(self): """Convert to a string. double check that unicode is handled somehow here""" self._cpo_store = cpo.pofile(encoding=self._encoding, noheader=True) try: self._build_cpo_from_self() except UnicodeEncodeError, e: self._encoding = "utf-8" self.updateheader(add=True, Content_Type="text/plain; charset=UTF-8") self._build_cpo_from_self()
def serialize(self, out): """Write content to file""" self._cpo_store = cpo.pofile(encoding=self.encoding, noheader=True) try: self._build_cpo_from_self() except UnicodeEncodeError as e: self.encoding = "utf-8" self.updateheader(add=True, Content_Type="text/plain; charset=UTF-8") self._build_cpo_from_self() self._cpo_store.serialize(out) del self._cpo_store
def serialize(self, out): """Write content to file""" self._cpo_store = cpo.pofile(encoding=self.encoding, noheader=True) try: self._build_cpo_from_self() except UnicodeEncodeError as e: self.encoding = "utf-8" self.updateheader(add=True, Content_Type="text/plain; charset=UTF-8") self._build_cpo_from_self() self._cpo_store.serialize(out) del self._cpo_store
def _build_cpo_from_self(self): """Builds the internal cpo store from the data in self. A user must ensure that self._cpo_store does not exist, and should delete it after using it.""" self._cpo_store = cpo.pofile(noheader=True) for unit in self.units: if not unit.isblank(): self._cpo_store.addunit(cpo.pofile.UnitClass.buildfromunit(unit, self._encoding)) if not self._cpo_store.header(): #only add a temporary header self._cpo_store.makeheader(charset=self._encoding, encoding="8bit")
def serialize(self): """Convert to bytes. double check that unicode is handled somehow here""" self._cpo_store = cpo.pofile(encoding=self._encoding, noheader=True) try: self._build_cpo_from_self() except UnicodeEncodeError as e: self._encoding = "utf-8" self.updateheader(add=True, Content_Type="text/plain; charset=UTF-8") self._build_cpo_from_self() output = self._cpo_store.serialize() del self._cpo_store return output
def parse(self, input): """Parses the given file or file source string.""" try: if hasattr(input, "name"): self.filename = input.name elif not getattr(self, "filename", ""): self.filename = "" self.units = [] self._cpo_store = cpo.pofile(input, noheader=True) self._build_self_from_cpo() del self._cpo_store except Exception as e: raise base.ParseError(e)
def serialize(self): """Convert to bytes. double check that unicode is handled somehow here""" self._cpo_store = cpo.pofile(encoding=self.encoding, noheader=True) try: self._build_cpo_from_self() except UnicodeEncodeError as e: self.encoding = "utf-8" self.updateheader(add=True, Content_Type="text/plain; charset=UTF-8") self._build_cpo_from_self() output = self._cpo_store.serialize() del self._cpo_store return output
def parse(self, input): """Parses the given file or file source string.""" try: if hasattr(input, 'name'): self.filename = input.name elif not getattr(self, 'filename', ''): self.filename = '' self.units = [] self._cpo_store = cpo.pofile(input, noheader=True) self._build_self_from_cpo() del self._cpo_store except Exception as e: raise base.ParseError(e)
def parse(self, input, duplicatestyle="merge"): """Parses the given file or file source string.""" try: if hasattr(input, 'name'): self.filename = input.name elif not getattr(self, 'filename', ''): self.filename = '' self.units = [] self._cpo_store = cpo.pofile(input, noheader=True) self._build_self_from_cpo() del self._cpo_store except Exception as e: raise base.ParseError(e) # duplicates are now removed by default unless duplicatestyle=allow if duplicatestyle != "allow": self.removeduplicates(duplicatestyle=duplicatestyle)
def parse(self, input, duplicatestyle="merge"): """Parses the given file or file source string.""" try: if hasattr(input, 'name'): self.filename = input.name elif not getattr(self, 'filename', ''): self.filename = '' self.units = [] self._cpo_store = cpo.pofile(input, noheader=True) self._build_self_from_cpo() del self._cpo_store except Exception as e: raise base.ParseError(e) # duplicates are now removed by default unless duplicatestyle=allow if duplicatestyle != "allow": self.removeduplicates(duplicatestyle=duplicatestyle)
def parse(self, input): """Parses the given file or file source string.""" try: if hasattr(input, 'name'): self.filename = input.name elif not getattr(self, 'filename', ''): self.filename = '' tmp_header_added = False # if isinstance(input, str) and '"Content-Type: text/plain; charset=' not in input[:200]: # input = basic_header + input # tmp_header_added = True self._cpo_store = cpo.pofile(input) self._build_self_from_cpo() del self._cpo_store if tmp_header_added: self.units = self.units[1:] except Exception, e: raise base.ParseError(e)
def parse(self, input): """Parses the given file or file source string.""" try: if hasattr(input, 'name'): self.filename = input.name elif not getattr(self, 'filename', ''): self.filename = '' tmp_header_added = False # if isinstance(input, str) and '"Content-Type: text/plain; charset=' not in input[:200]: # input = basic_header + input # tmp_header_added = True self.units = [] self._cpo_store = cpo.pofile(input, noheader=True) self._build_self_from_cpo() del self._cpo_store if tmp_header_added: self.units = self.units[1:] except Exception, e: raise base.ParseError(e)