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 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 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
(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'])
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'])