How to use _listMethods method in pyatom

Best Python code snippet using pyatom_python

server.py

Source:server.py Github

copy

Full Screen

1"""RPC Server module."""2import sys3import socket4import pickle5from fnmatch import fnmatch6from repr import repr7# Default verbosity (0 = silent, 1 = print connections, 2 = print requests too)8VERBOSE = 19class Server:10 11 """RPC Server class. Derive a class to implement a particular service."""12 13 def __init__(self, address, verbose = VERBOSE):14 if type(address) == type(0):15 address = ('', address)16 self._address = address17 self._verbose = verbose18 self._socket = None19 self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)20 self._socket.bind(address)21 self._socket.listen(1)22 self._listening = 123 24 def _setverbose(self, verbose):25 self._verbose = verbose26 27 def __del__(self):28 self._close()29 30 def _close(self):31 self._listening = 032 if self._socket:33 self._socket.close()34 self._socket = None35 36 def _serverloop(self):37 while self._listening:38 self._serve()39 40 def _serve(self):41 if self._verbose: print "Wait for connection ..."42 conn, address = self._socket.accept()43 if self._verbose: print "Accepted connection from %s" % repr(address)44 if not self._verify(conn, address):45 print "*** Connection from %s refused" % repr(address)46 conn.close()47 return48 rf = conn.makefile('r')49 wf = conn.makefile('w')50 ok = 151 while ok:52 wf.flush()53 if self._verbose > 1: print "Wait for next request ..."54 ok = self._dorequest(rf, wf)55 56 _valid = ['192.16.201.*', '192.16.197.*', '132.151.1.*', '129.6.64.*']57 58 def _verify(self, conn, address):59 host, port = address60 for pat in self._valid:61 if fnmatch(host, pat): return 162 return 063 64 def _dorequest(self, rf, wf):65 rp = pickle.Unpickler(rf)66 try:67 request = rp.load()68 except EOFError:69 return 070 if self._verbose > 1: print "Got request: %s" % repr(request)71 try:72 methodname, args, id = request73 if '.' in methodname:74 reply = (None, self._special(methodname, args), id)75 elif methodname[0] == '_':76 raise NameError, "illegal method name %s" % repr(methodname)77 else:78 method = getattr(self, methodname)79 reply = (None, apply(method, args), id)80 except:81 reply = (sys.exc_type, sys.exc_value, id)82 if id < 0 and reply[:2] == (None, None):83 if self._verbose > 1: print "Suppress reply"84 return 185 if self._verbose > 1: print "Send reply: %s" % repr(reply)86 wp = pickle.Pickler(wf)87 wp.dump(reply)88 return 189 90 def _special(self, methodname, args):91 if methodname == '.methods':92 if not hasattr(self, '_methods'):93 self._methods = tuple(self._listmethods())94 return self._methods95 raise NameError, "unrecognized special method name %s" % repr(methodname)96 97 def _listmethods(self, cl=None):98 if not cl: cl = self.__class__99 names = cl.__dict__.keys()100 names = filter(lambda x: x[0] != '_', names)101 names.sort()102 for base in cl.__bases__:103 basenames = self._listmethods(base)104 basenames = filter(lambda x, names=names: x not in names, basenames)105 names[len(names):] = basenames106 return names107from security import Security108class SecureServer(Server, Security):109 def __init__(self, *args):110 apply(Server.__init__, (self,) + args)111 Security.__init__(self)112 def _verify(self, conn, address):113 import string114 challenge = self._generate_challenge()115 conn.send("%d\n" % challenge)116 response = ""117 while "\n" not in response and len(response) < 100:118 data = conn.recv(100)119 if not data:120 break121 response = response + data122 try:123 response = string.atol(string.strip(response))124 except string.atol_error:125 if self._verbose > 0:126 print "Invalid response syntax", `response`127 return 0128 if not self._compare_challenge_response(challenge, response):129 if self._verbose > 0:130 print "Invalid response value", `response`131 return 0132 if self._verbose > 1:133 print "Response matches challenge. Go ahead!"...

Full Screen

Full Screen

imageClass.py

Source:imageClass.py Github

copy

Full Screen

1from PIL import Image2class ImageFile(Image):3 def __init__(self):4 self.__main__5 self.Image()6 # if type(address) == type(0):7 def _special(self, methodname, args):8 if methodname == '.methods':9 if not hasattr(self, '_methods'):10 self._methods = tuple(self._listmethods())11 return self._methods12 raise NameError, "unrecognized special method name %s" % repr(methodname)13 def _listmethods(self, cl=None):14 if not cl: cl = self.__class__15 names = cl.__dict__.keys()16 names = filter(lambda x: x[0] != '_', names)17 names.sort()18 for base in cl.__bases__:19 basenames = self._listmethods(base)20 basenames = filter(lambda x, names=names: x not in names, basenames)21 names[len(names):] = basenames22 #return names23 def writeXmp(self, xmpkey, xmpvalue):24 import pyexiv225 metadata = pyexiv2.ImageMetadata(self)26 metadata[xmpkey] = xmpvalue27 def writeIptc(self, iptckey, iptcvalue):28 import pyexiv229 metadata = pyexiv2.ImageMetadata(self)30 metadata[iptckey] = iptcvalue31 def readIptc(self):32 import pyexiv233 metadata = pyexiv2.ImageMetadata(self)34 mdataprint = metadata.read()35 print metadata36 def metadata_get_exif(self):37 ret = {}38 from PIL import Image39 from PIL.ExifTags import TAGS40 i = Image.open(self)41 info = i._getexif()42 for tag, value in info.items():43 decoded = TAGS.get(tag, tag)44 ret[decoded] = value45 return ret46class download():47 import urllib, urllib2, requests48 def __init__(self, url):49 self.url = url50 pass51 def GET(self):52 # path = url53 #header('Content-type','images/jpeg')54 #header('Content-transfer-encoding','binary')55 #header('Content-Disposition', 'attachment;filename="fname.ext"')56 return open(self.url, 'rb').read()57if __name__ == "__main__":58 # app = web.application(urls, globals())...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful