def serialize(o, stream): if isinstance(o, float): stream.write_raw(pdf_float(o).encode('ascii')) elif isinstance(o, bool): # Must check bool before int as bools are subclasses of int stream.write_raw(b'true' if o else b'false') elif isinstance(o, numbers.Integral): stream.write_raw(unicode_type(o).encode('ascii')) elif hasattr(o, 'pdf_serialize'): o.pdf_serialize(stream) elif o is None: stream.write_raw(b'null') elif isinstance(o, datetime): val = o.strftime("D:%Y%m%d%H%M%%02d%z") % min(59, o.second) if datetime.tzinfo is not None: val = "(%s'%s')" % (val[:-2], val[-2:]) stream.write(val.encode('ascii')) else: raise ValueError('Unknown object: %r' % o)
def fmtnum(o): if isinstance(o, float): return pdf_float(o) return unicode_type(o)
def fmtnum(o): if isinstance(o, float): return pdf_float(o) return str(o)