def load(self, url): try: img = urllib2.urlopen(url).read() bytes = ByteArray() bytes.write(img) return bytes except: return "Image request Error"
def loadThumb(self, url, size): try: buffer = urllib2.urlopen(url).read() img = images.resize(buffer, size, size) bytes = ByteArray() bytes.write(img) return bytes except: return "Image request Error"
def exportToExcel(): if not request.vars.code or not request.vars.sheet or not request.vars.view: return "Missing parameters!" if request.vars.code == "amf": sheet = base64.b64decode(request.vars.sheet) view = base64.b64decode(request.vars.view) sheet = Decoder(ByteArray(sheet)).readElement() view = Decoder(ByteArray(view)).readElement() else: sheet = eval(base64.urlsafe_b64decode(request.vars.sheet)) view = eval(base64.urlsafe_b64decode(request.vars.view)) login = view["login"] validator = getLogin(login["database"], login["username"], login["password"]) if validator["valid"] == False: return validator["message"] response.headers['Content-Type'] = "application/vnd.ms-excel" response.headers[ 'Content-Disposition'] = 'attachment;filename="NervaturaExport.xls"' return dbout.exportToExcel(sheet, view)
def test_encode_bytearray(self): from pyamf.amf3 import ByteArray stream = ByteArray() stream.write('12345678') msg = remoting.Envelope(pyamf.AMF0) msg['/1'] = remoting.Response([stream]) self.assertEqual(remoting.encode(msg).getvalue(), '\x00\x00\x00\x00\x00\x01\x00\x0b/1/onResult\x00\x04null' '\x00\x00\x00\x00\n\x00\x00\x00\x01\x11\x0c\x1112345678')
def fiximage(data): """Take an uploaded image, call I'm feeling lucky and put it back out to the user. """ logging.info("Transforming image...") logging.info("In data size: %d" % (len(data), )) image_in = Image(str(data)) image_in.im_feeling_lucky() image_out = ByteArray() image_out.write(image_in.execute_transforms()) logging.info("Out data size: %d" % (len(image_out), )) return image_out
def getfile(request, path, bytearray=None): """ Returns a ByteArray of the file at the requested path and the md5 hash. """ fp = open(os.path.join(settings.GATEWAY_ROOT, path), 'rb') content = fp.read() fp.close() ba = ByteArray() ba.write(content) m = hashlib.md5() m.update(content) md5 = m.hexdigest() return [path, ba, md5]
def load(self, sid): access_token = memcache.get(sid) models = [] if access_token: try: auth = tweepy.OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET) auth.set_access_token(access_token.key, access_token.secret) api = tweepy.API(auth_handler=auth) for tweet in tweepy.Cursor(api.home_timeline).items(100): model = TweetModel() model.username = tweet.user.screen_name model.status = tweet.text model.icon = ByteArray() model.icon.write( urllib2.urlopen(tweet.user.profile_image_url).read()) models.append(model) return models except: return 'Error' else: return 'not Authed'
def __init__(self, buf): """ """ self.buf = ByteArray(buf)
def __createByteArray(self, msg): """ """ self.buf = ByteArray() self.buf.writeShort(0) self.buf.writeShort(msg)
def read(self, data): ba = ByteArray(data) return ba.readObject()
class TweetModel(object): username = '' status = '' icon = ByteArray()
help="host address [default: %default]") (options, args) = parser.parse_args() # define gateway url = 'http://%s:%d' % (options.host, int(options.port)) server = RemotingService(url) service = server.getService('getSnapshots')() # get list of snapshots base_path = service[0] types = service[1] snapshots = service[2] print "Found %d snapshot(s):" % (len(snapshots)) for snapshot in snapshots: print "\t%s%s" % (base_path, snapshot['name']) # save snapshot path = 'django-logo.jpg' image = os.path.join(images_root, path) file = open(image, 'r').read() snapshot = ByteArray() snapshot.write(file) save_snapshot = server.getService('ByteArray.saveSnapshot') saved = save_snapshot(snapshot, 'jpg') print "Saved snapshot:\n\t%s:\t%s" % (saved['name'], saved['url'])