def text2QRCode(value): from qrcode import QRCode qr = QRCode() qr.add_data(value) qr_code = StringIO() qr.print_ascii(out=qr_code) ascii = qr_code.getvalue() return ascii
class UnicodeBuilder: __slots__ = ["acc"] def __init__(self, length=None): self.acc = StringIO() def append(self, data): self.acc.write(data) def build(self): return self.acc.getvalue()
def DataFrame2string(df, columns=None): output = StringIO.StringIO() try: df.to_csv(output, sep="\t", header=True, cols=columns, engine='python') return output.getvalue() finally: output.close()
def __init__(query_path, instream): if is_text(instream): instream = StringIO(instream) self.instream = instream self.wordchars = ('abcdfeghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_' 'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ' 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ') self.numchars = '0123456789' self.whitespace = ' \t\r\n' self.charstack = [] self.tokenstack = [] self.eof = False
def ini2value(ini_content): """ INI FILE CONTENT TO Data """ buff = StringIO(ini_content) config = ConfigParser() config._read(buff, "dummy") output = {} for section in config.sections(): output[section] = s = {} for k, v in config.items(section): s[k] = v return wrap(output)
def get_json(url, **kwargs): """ ASSUME RESPONSE IN IN JSON """ response = get(url, **kwargs) try: c = response.all_content path = URL(url).path if path.endswith(".zip"): buff = StringIO(c) archive = zipfile.ZipFile(buff, mode='r') c = archive.read(archive.namelist()[0]) elif path.endswith(".gz"): c = zip2bytes(c) return json2value(c.decode('utf8')) except Exception as e: if mo_math.round(response.status_code, decimal=-2) in [400, 500]: Log.error(u"Bad GET response: {{code}}", code=response.status_code) else: Log.error(u"Good GET requests, but bad JSON", cause=e)
def _unzip(compressed): buff = StringIO(compressed) archive = zipfile.ZipFile(buff, mode="r") return archive.read(archive.namelist()[0])
def __init__(self, length=None): self.acc = StringIO()