Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #This file is part of Tryton. The COPYRIGHT file at the top level of | 1 #This file is part of Tryton. The COPYRIGHT file at the top level of |
2 #this repository contains the full copyright notices and license terms. | 2 #this repository contains the full copyright notices and license terms. |
3 from trytond.protocols.sslsocket import SSLSocket | 3 from trytond.protocols.sslsocket import SSLSocket |
4 from trytond.protocols.dispatcher import dispatch | 4 from trytond.protocols.dispatcher import dispatch |
5 from trytond.config import CONFIG | 5 from trytond.config import CONFIG |
6 import SimpleXMLRPCServer | 6 import SimpleXMLRPCServer |
7 import SimpleHTTPServer | 7 import SimpleHTTPServer |
8 import SocketServer | 8 import SocketServer |
9 import json | 9 try: |
yangoon1
2010/01/06 13:20:32
entry in setup.py and INSTALL missing
ced
2010/01/06 13:43:26
json is part of the python standard module
h.goebel
2010/01/06 14:05:41
json is new in Python 2.6. See <http://docs.python
| |
10 import json | |
11 except ImportError: | |
12 import simplejson as json | |
10 from xmlrpclib import Fault | 13 from xmlrpclib import Fault |
11 import threading | 14 import threading |
12 import traceback | 15 import traceback |
13 import socket | 16 import socket |
14 import sys | 17 import sys |
15 import os | 18 import os |
16 import gzip | 19 import gzip |
17 import StringIO | 20 import StringIO |
18 try: | 21 try: |
19 import fcntl | 22 import fcntl |
20 except ImportError: | 23 except ImportError: |
21 fcntl = None | 24 fcntl = None |
22 import posixpath | 25 import posixpath |
23 import urllib | 26 import urllib |
24 import datetime | 27 import datetime |
28 from decimal import Decimal | |
25 | 29 |
26 def object_hook(dct): | 30 def object_hook(dct): |
27 if '__class__' in dct: | 31 if '__class__' in dct: |
28 if dct['__class__'] == 'datetime': | 32 if dct['__class__'] == 'datetime': |
29 return datetime.datetime(dct['year'], dct['month'], dct['day'], | 33 return datetime.datetime(dct['year'], dct['month'], dct['day'], |
30 dct['hour'], dct['minute'], dct['second']) | 34 dct['hour'], dct['minute'], dct['second']) |
31 elif dct['__class__'] == 'date': | 35 elif dct['__class__'] == 'date': |
32 return datetime.date(dct['year'], dct['month'], dct['day']) | 36 return datetime.date(dct['year'], dct['month'], dct['day']) |
33 return dct | 37 return dct |
34 | 38 |
35 class JSONEncoder(json.JSONEncoder): | 39 class JSONEncoder(json.JSONEncoder): |
36 | 40 |
37 def default(self, obj): | 41 def default(self, obj): |
38 if isinstance(obj, datetime.date): | 42 if isinstance(obj, datetime.date): |
39 if isinstance(obj, datetime.datetime): | 43 if isinstance(obj, datetime.datetime): |
40 return {'__class__': 'datetime', | 44 return {'__class__': 'datetime', |
41 'year': obj.year, | 45 'year': obj.year, |
42 'month': obj.month, | 46 'month': obj.month, |
43 'day': obj.day, | 47 'day': obj.day, |
44 'hour': obj.hour, | 48 'hour': obj.hour, |
45 'minute': obj.minute, | 49 'minute': obj.minute, |
46 'second': obj.second, | 50 'second': obj.second, |
47 } | 51 } |
48 return {'__class__': 'date', | 52 return {'__class__': 'date', |
49 'year': obj.year, | 53 'year': obj.year, |
50 'month': obj.month, | 54 'month': obj.month, |
51 'day': obj.day, | 55 'day': obj.day, |
52 } | 56 } |
57 elif isinstance(obj, Decimal): | |
58 return float(obj) | |
53 return json.JSONEncoder.default(self, obj) | 59 return json.JSONEncoder.default(self, obj) |
54 | 60 |
55 | 61 |
56 class SimpleJSONRPCDispatcher(SimpleXMLRPCServer.SimpleXMLRPCDispatcher): | 62 class SimpleJSONRPCDispatcher(SimpleXMLRPCServer.SimpleXMLRPCDispatcher): |
57 """Mix-in class that dispatches JSON-RPC requests. | 63 """Mix-in class that dispatches JSON-RPC requests. |
58 | 64 |
59 This class is used to register JSON-RPC method handlers | 65 This class is used to register JSON-RPC method handlers |
60 and then to dispatch them. There should never be any | 66 and then to dispatch them. There should never be any |
61 reason to instantiate this class directly. | 67 reason to instantiate this class directly. |
62 """ | 68 """ |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 SimpleHTTPServer.SimpleHTTPRequestHandler): | 132 SimpleHTTPServer.SimpleHTTPRequestHandler): |
127 """Simple JSON-RPC request handler class. | 133 """Simple JSON-RPC request handler class. |
128 | 134 |
129 Handles all HTTP POST requests and attempts to decode them as | 135 Handles all HTTP POST requests and attempts to decode them as |
130 JSON-RPC requests. | 136 JSON-RPC requests. |
131 """ | 137 """ |
132 rpc_paths = None | 138 rpc_paths = None |
133 encode_threshold = 1400 # common MTU | 139 encode_threshold = 1400 # common MTU |
134 | 140 |
135 # Copy from SimpleXMLRPCServer.py with gzip encoding added | 141 # Copy from SimpleXMLRPCServer.py with gzip encoding added |
136 def do_POST(self): | 142 def do_POST(self): |
h.goebel
2010/01/06 14:02:56
Isn't this a plain copy of from tryton's xmlrp.py?
ced
2010/01/06 14:15:02
Different header
| |
137 """Handles the HTTP POST request. | 143 """Handles the HTTP POST request. |
138 | 144 |
139 Attempts to interpret all HTTP POST requests as JSON-RPC calls, | 145 Attempts to interpret all HTTP POST requests as JSON-RPC calls, |
140 which are forwarded to the server's _dispatch method for handling. | 146 which are forwarded to the server's _dispatch method for handling. |
141 """ | 147 """ |
142 | 148 |
143 # Check that the path is legal | 149 # Check that the path is legal |
144 if not self.is_rpc_path_valid(): | 150 if not self.is_rpc_path_valid(): |
145 self.report_404() | 151 self.report_404() |
146 return | 152 return |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 self.server.socket.shutdown(socket.SHUT_RDWR) | 331 self.server.socket.shutdown(socket.SHUT_RDWR) |
326 else: | 332 else: |
327 self.server.socket.shutdown(2) | 333 self.server.socket.shutdown(2) |
328 self.server.socket.close() | 334 self.server.socket.close() |
329 | 335 |
330 def run(self): | 336 def run(self): |
331 self.running = True | 337 self.running = True |
332 while self.running: | 338 while self.running: |
333 self.server.handle_request() | 339 self.server.handle_request() |
334 return True | 340 return True |
LEFT | RIGHT |