def execute_db(self, method, *args): sock = tiny_socket.mysocket() sock.connect(self.host, self.port) sock.mysend(('db', method) + args) res = sock.myreceive() sock.disconnect() return res
def run(self): import select self.running = True try: ts = tiny_socket.mysocket(self.sock) # 获取到socket except: self.sock.close() self.threads.remove(self) return False while self.running: try: msg = ts.myreceive() # 有请求 except: self.sock.close() self.threads.remove(self) return False try: result = self.dispatch(msg[0], msg[1], msg[2:]) # 解析, 并获取相应结果 # dispatch 在OpenERPDispatcher中实现 ts.mysend(result) # 发送结果, 阻塞方式 except OpenERPDispatcherException, e: new_e = Exception(tools.exception_to_unicode(e.exception)) # avoid problems of pickeling try: ts.mysend(new_e, exception=True, traceback=e.traceback) except: self.sock.close() self.threads.remove(self) return False self.sock.close() self.threads.remove(self) return True
def login(self, db, user, passwd): sock = tiny_socket.mysocket() try: sock.connect(self.host, self.port) sock.mysend(('common', 'login', db, user, passwd)) res = sock.myreceive() sock.disconnect() except Exception, e: return -1
def listdb(self): sock = tiny_socket.mysocket() try: sock.connect(self.host, self.port) sock.mysend(('db', 'list')) res = sock.myreceive() sock.disconnect() return res except Exception, e: return -1
def execute(self, obj, method, *args): sock = tiny_socket.mysocket() try: sock.connect(self.host, self.port) sock.mysend((obj, method, self.db, self.uid, self.passwd)+ args) res = sock.myreceive() sock.disconnect() return res except socket.error, (e1, e2): raise common.error(_('Connection refused !'), e1, e2)
def exec_no_except(self, url, resource, method, *args): m = re.match('^(http[s]?://|socket://)([\w.\-]+):(\d{1,5})$', url or '') if m.group(1) == 'http://' or m.group(1) == 'https://': sock = xmlrpclib.ServerProxy(url + '/xmlrpc/' + resource) return getattr(sock, method)(*args) else: sock = tiny_socket.mysocket() sock.connect(m.group(2), int(m.group(3))) sock.mysend((resource, method)+args) res = sock.myreceive() sock.disconnect() return res
def exec_no_except(self, url, resource, method, *args): m = re.match('^(http[s]?://|socket://)([\w.\-]+):(\d{1,5})$', url or '') if m.group(1) == 'http://' or m.group(1) == 'https://': sock = xmlrpclib.ServerProxy(url + '/xmlrpc/' + resource) return getattr(sock, method)(*args) else: sock = tiny_socket.mysocket() sock.connect(m.group(2), int(m.group(3))) sock.mysend((resource, method) + args) res = sock.myreceive() sock.disconnect() return res
def _execute(self, obj, method, args=(), noauth=False): sock = tiny_socket.mysocket() try: sock.connect(self.host, self.port) if not noauth: args = (self.db, self.uid, self.password) + args sock.mysend((obj, method) + args) res = sock.myreceive() sock.disconnect() return res except xmlrpclib.Fault, err: raise RPCException(err.faultCode, err.faultString)
def exec_no_except(self, url, resource, method, *args): m = re.match('^(http[s]?://|http[s]?\+msgpack://|socket://)([\w.-]+):(\d{1,5})$', url or '') if m.group(1) == 'http://' or m.group(1) == 'https://': sock = xmlrpclib.ServerProxy(url + '/xmlrpc/' + resource) return getattr(sock, method)(*args) elif m.group(1).endswith('+msgpack://'): endpoint = '%s/%s' % (url.replace('+msgpack', ''), resource) m = msgpack.packb([method] + list(args)) u = urllib2.urlopen(endpoint, m) s = u.read() u.close() res = msgpack.unpackb(s) return res else: sock = tiny_socket.mysocket() sock.connect(m.group(2), int(m.group(3))) sock.mysend((resource, method)+args) res = sock.myreceive() sock.disconnect() return res
def run(self): self.running = True try: ts = tiny_socket.mysocket(self.sock) except Exception: self.threads.remove(self) self.running = False return False while self.running: try: msg = ts.myreceive() result = self.dispatch(msg[0], msg[1], msg[2:]) ts.mysend(result) except socket.timeout: #terminate this channel because other endpoint is gone break except netsvc.OpenERPDispatcherException, e: try: new_e = Exception( e.compat_string()) # avoid problems of pickeling logging.getLogger('web-services').debug( "netrpc: rpc-dispatching exception", exc_info=True) ts.mysend(new_e, exception=True, traceback=e.traceback) except Exception: #terminate this channel if we can't properly send back the error logging.getLogger('web-services').exception( "netrpc: cannot deliver exception message to client") break except Exception, e: try: tb = getattr(e, 'traceback', sys.exc_info()) tb_s = "".join(traceback.format_exception(*tb)) logging.getLogger('web-services').debug( "netrpc: communication-level exception", exc_info=True) ts.mysend(e, exception=True, traceback=tb_s) except Exception, ex: #terminate this channel if we can't properly send back the error logging.getLogger('web-services').exception( "netrpc: cannot deliver exception message to client") break
def run(self): self.running = True try: ts = tiny_socket.mysocket(self.sock, self.is_gzip) except Exception: self.threads.remove(self) self.running = False return False while self.running: try: msg = ts.myreceive() result = self.dispatch(msg[0], msg[1], msg[2:]) ts.mysend(result) except socket.timeout: #terminate this channel because other endpoint is gone break except netsvc.OpenERPDispatcherException, e: try: new_e = Exception(tools.exception_to_unicode(e.exception)) # avoid problems of pickeling logging.getLogger('web-services').debug("netrpc: rpc-dispatching exception", exc_info=True) ts.mysend(new_e, exception=True, traceback=e.traceback) except Exception: #terminate this channel if we can't properly send back the error logging.getLogger('web-services').exception("netrpc: cannot deliver exception message to client") break except Exception, e: try: tb = getattr(e, 'traceback', sys.exc_info()) tb_s = "".join(traceback.format_exception(*tb)) logging.getLogger('web-services').debug("netrpc: communication-level exception", exc_info=True) ts.mysend(e, exception=True, traceback=tb_s) except Exception, ex: #terminate this channel if we can't properly send back the error logging.getLogger('web-services').exception("netrpc: cannot deliver exception message to client") break
def call(self, obj, method, args, auth_level='db'): try: s = tiny_socket.mysocket() s.connect( self.url ) except socket.error, err: raise RpcProtocolException( unicode(err) )
def __init__(self, url, db, uid, passwd, obj='/object'): gw_inter.__init__(self, url, db, uid, passwd, obj) self._sock = tiny_socket.mysocket() self._obj = obj[1:]
try: m = msgpack.packb(['login', db or '', uname or '', passwd or '']) u = urllib2.urlopen('%s/common' % _url, m) s = u.read() u.close() res = msgpack.unpackb(s) except socket.error,e: return -1 if not res: self._open=False self.uid=False return -2 else: _url = _protocol+url+':'+str(port) _sock = tiny_socket.mysocket() self._gw = tinySocket_gw try: _sock.connect(url, int(port)) _sock.mysend(('common', 'login', db or '', uname or '', passwd or '')) res = _sock.myreceive() _sock.disconnect() except socket.error,e: return -1 if not res: self._open=False self.uid=False return -2 self._url = _url self._open = True self.uid = res
_url = _protocol + url+':'+str(port)+'/xmlrpc' _sock = xmlrpclib.ServerProxy(_url+'/common') self._gw = xmlrpc_gw try: res = _sock.login(db or '', uname or '', passwd or '') except socket.error,e: return -1 except Exception, e: return 0 if not res: self._open=False self.uid=False return -2 else: _url = _protocol+url+':'+str(port) _sock = tiny_socket.mysocket() self._gw = tinySocket_gw try: _sock.connect(url, int(port)) _sock.mysend(('common', 'login', db or '', uname or '', passwd or '')) res = _sock.myreceive() _sock.disconnect() except socket.error,e: return -1 except Exception: return 0 if not res: self._open=False self.uid=False return -2 self._url = _url