def __new__(cls, s=None): """ (s:either(string, None)) """ if s is None: return cls("") elif not isinstance(s, unistr): s = decodeh.decode(s) return unistr.__new__(cls, s)
def redecode_from_string(self, src): """ (src:str) -> ts_raw:str Re-decode raw template string from src """ if src is None: raise ValueError("Template from string may not have src=None") if self.file is not None: raise ValueError("Template is file-based") return decode(src, enc=self.input_encoding)
def quote(cls, x): """ (x:anything) -> cls When the x argument is an own_type instance, it is just returned immediately, without any changes. When it is None, an empty cls instance is returned. All other arguments are converted to unicode strings and then quoted to produce an instance of cls. """ if isinstance(x, cls): return x if x is None: return cls() if type(x) is unistr: s = x elif isinstance(x, string): s = decodeh.decode(x) else: s = unistr(x) return cls._quote(s)