Ejemplo n.º 1
0
    def write_image(**kwargs):
        from paste import loop
        loop.check()

        stream = kwargs["image"].stream.read()
        is_image = imghdr.what(None, stream)

        if not is_image:
            raise Exception("Not a valid image")

        b64encoded = base64.b64encode(stream)
        uid = PasteController._gen_uid()

        data = {
            "date": time.mktime(datetime.now().timetuple()),
            "ip_addr": kwargs["ip_addr"],
            "contents": b64encoded,
            "uid": uid
        }

        blob = json.dumps(data, indent=4, separators=(',', ': '))
        exposure = "priv"

        f = open('%s/img/%s/%s' % (path_base, exposure, uid), 'w')
        f.write(blob)
        f.close()

        return uid
Ejemplo n.º 2
0
    def write_text(**kwargs):
        from paste import loop
        loop.check()

        keys = 'ip_addr', 'syntax', 'expiration', 'private', 'contents'
        data = collections.OrderedDict()
        data['date'] = time.mktime(datetime.now().timetuple())

        for expected in keys:
            if not expected in kwargs:
                raise Exception('%s not found in arguments' % expected)

            data[expected] = kwargs[expected]

        uid = PasteController._gen_uid()
        exposure = 'pub' if not data['private'] else 'priv'

        blob = json.dumps(data, indent=4, separators=(',', ': '))

        f = open('%s/paste/%s/%s' % (path_base, exposure, uid), 'w')
        f.write(blob)
        f.close()

        if data['expiration']:
            loop.data[uid] = {
                'date': data['expiration'],
                'uid': uid
            }

        return uid
Ejemplo n.º 3
0
    def recent_public():
        from paste import loop
        loop.check()

        data = []

        uids = os.popen('ls -ht %s/paste/pub/ | head -n 7' % path_base).read()
        uids = [z for z in uids.split('\n') if z]

        for uid in uids:
            paste = PasteController.read_text(uid)
            data.append(paste)

        return data