我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用codecs.ascii_encode()。
def encode(self, input, final=False): return codecs.ascii_encode(input, self.errors)[0]
def email(self, email): # XXX: becoming a pattern? if isinstance(email, UnicodeType): self._email = email.encode(ascii_encode) elif isinstance(email, BytesType): _ = email.decode("ascii") # noqa self._email = email else: raise TypeError("bytes, str, unicode email required")
def setTextFrame(self, fid, txt): fid = b(fid, ascii_encode) if not fid.startswith(b"T") or fid.startswith(b"TX"): raise ValueError("Invalid frame-id for text frame") if not txt and self.frame_set[fid]: del self.frame_set[fid] elif txt: self.frame_set.setTextFrame(fid, txt)
def getTextFrame(self, fid): fid = b(fid, ascii_encode) if not fid.startswith(b"T") or fid.startswith(b"TX"): raise ValueError("Invalid frame-id for text frame") f = self.frame_set[fid] return f[0].text if f else None
def frameiter(self, fids=None): """A iterator for tag frames. If ``fids`` is passed it must be a list of frame IDs to filter and return.""" fids = fids or [] fids = [(b(f, ascii_encode) if isinstance(f, UnicodeType) else f) for f in fids] for f in self.frame_set.getAllFrames(): if not fids or f.id in fids: yield f