Example #1
0
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
Example #2
0
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()
Example #3
0
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()
Example #4
0
 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
Example #5
0
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)
Example #6
0
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)
Example #7
0
def _unzip(compressed):
    buff = StringIO(compressed)
    archive = zipfile.ZipFile(buff, mode="r")
    return archive.read(archive.namelist()[0])
Example #8
0
 def __init__(self, length=None):
     self.acc = StringIO()