def strLen(self, nstr): """""" if isinstance(nstr, int): nstr = str(nstr) bnstr = ByteArray() bnstr.writeUTFBytes(nstr) return len(bnstr)
def strLen(self,nstr): """""" if isinstance(nstr,int): nstr = str(nstr) bnstr = ByteArray() bnstr.writeUTFBytes(nstr); return len(bnstr);
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"
class PackBase: def __init__(self, msg): """ """ self.msg = msg self.__createByteArray(msg) def __createByteArray(self, msg): """ """ self.buf = ByteArray() self.buf.writeShort(0) self.buf.writeShort(msg) def strLen(self, nstr): """""" if isinstance(nstr, int): nstr = str(nstr) bnstr = ByteArray() bnstr.writeUTFBytes(nstr) return len(bnstr) def pack(self): """ """ self.buf.seek(0) self.buf.endian = ByteArray.ENDIAN_LITTLE self.buf.writeShort(len(self.buf)) return self.buf.getvalue()
class PackBase: def __init__(self,msg): """ """ self.msg = msg; self.__createByteArray(msg); def __createByteArray(self,msg): """ """ self.buf = ByteArray(); self.buf.writeShort(0); self.buf.writeShort(msg); def strLen(self,nstr): """""" if isinstance(nstr,int): nstr = str(nstr) bnstr = ByteArray() bnstr.writeUTFBytes(nstr); return len(bnstr); def pack(self): """ """ self.buf.seek(0); self.buf.endian = ByteArray.ENDIAN_LITTLE; self.buf.writeShort(len(self.buf)); return self.buf.getvalue();
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.assertEquals(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 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 test_encode_bytearray(self): from pyamf.amf3 import ByteArray stream = ByteArray() stream.write("12345678") msg = remoting.Envelope(pyamf.AMF0, pyamf.ClientTypes.Flash6) msg["/1"] = remoting.Response([stream]) self.assertEquals( 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 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 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 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 get_font_img(request, font): print font font_id = int(font.id) if font_id not in fonts.keys(): return FailResponse(u'非法的字体请求') font_file = fonts[font_id]["font"] font_file = os.path.join(FONT_ROOT, font_file) #font_file = font_file.encode('utf-8') if not os.path.isfile(font_file): return FailResponse(u'字体文件不存在') if len(font.content) == 0: font.content = fonts[font_id]["label"] from utils.txt2img import txt2img img = txt2img(font, font_file) #img.save("c:\\font.png") buf = StringIO() img.save(buf, 'png') snapshot = ByteArray() snapshot.write(buf.getvalue()) return snapshot
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)
class TweetModel(object): username = '' status = '' icon = ByteArray()
def __createByteArray(self, msg): """ """ self.buf = ByteArray() self.buf.writeShort(0) self.buf.writeShort(msg)
def __createByteArray(self,msg): """ """ self.buf = ByteArray(); self.buf.writeShort(0); self.buf.writeShort(msg);
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'])
def read(self, data): ba = ByteArray(data) return ba.readObject()
(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'])