Merge lp:~jamesmikedupont/openobject-server/openobject-server into lp:openobject-server
- openobject-server
- Merge into trunk
Status: | Needs review |
---|---|
Proposed branch: | lp:~jamesmikedupont/openobject-server/openobject-server |
Merge into: | lp:openobject-server |
Diff against target: |
314 lines (+67/-67) 3 files modified
openerp-server (+20/-8) openerp/service/http_server.py (+45/-57) openerp/service/websrv_lib.py (+2/-2) |
To merge this branch: | bzr merge lp:~jamesmikedupont/openobject-server/openobject-server |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Xavier (Open ERP) (community) | Needs Fixing | ||
Review via email: mp+133440@code.launchpad.net |
Commit message
Description of the change
Running of pylint
https:/
- 4496. By James Michael DuPont
-
merge
- 4497. By James Michael DuPont
-
pylint
Xavier (Open ERP) (xmo-deactivatedaccount) wrote : | # |
James Michael DuPont (jamesmikedupont) wrote : | # |
ok fair enough, I will rework it when I have time.
On Tue, Nov 13, 2012 at 3:39 AM, Xavier (Open ERP) <email address hidden> wrote:
> Review: Needs Fixing
>
> I can't say I'm fond of the way many lines are broken to fit in 80chars. Not the fitting in 80chars thing (that's great), but the way it's done e.g.
>
> sys.stderr.
>
> to
>
> sys.stderr.
> " is a security risk, aborting.\n")
>
> I think would make more sense (and look better) as
>
> sys.stderr.write(
> "Running as user 'root' is a security risk, aborting.\n")
>
> and
>
> db, registry = openerp.
>
> to
>
> _db, registry = \
> openerp.
> update_
> or openerp.
> pooljobs=False)
>
> is downright weird, why not e.g.
>
> to_update = openerp.
> or openerp.
> _db, registry = openerp.
> dbname, update_
>
> this kind of wonky line-breaking seems fairly common and hampers readablility more than it helps.
> --
> https:/
> You are the owner of lp:~jamesmikedupont/openobject-server/openobject-server.
--
James Michael DuPont
Member of Free Libre Open Source Software Kosova http://
Saving wikipedia(tm) articles from deletion http://
Contributor FOSM, the CC-BY-SA map of the world http://
Mozilla Rep https:/
Free Software Foundation Europe Fellow http://
Antony Lesuisse (OpenERP) (al-openerp) wrote : | # |
please rebase on trunk
James Michael DuPont (jamesmikedupont) wrote : | # |
I have not had time to do this,
thanks
mike
On Tue, Dec 18, 2012 at 10:02 AM, Antony Lesuisse (OpenERP)
<email address hidden>wrote:
> please rebase on trunk
> --
>
> https:/
> You are the owner of
> lp:~jamesmikedupont/openobject-server/openobject-server.
>
--
James Michael DuPont
Member of Free Libre Open Source Software Kosova http://
Saving wikipedia(tm) articles from deletion http://
Contributor FOSM, the CC-BY-SA map of the world http://
Mozilla Rep https:/
Free Software Foundation Europe Fellow http://
Unmerged revisions
- 4497. By James Michael DuPont
-
pylint
- 4496. By James Michael DuPont
-
merge
- 4495. By James Michael DuPont
-
clean
Preview Diff
1 | === modified file 'openerp-server' |
2 | --- openerp-server 2012-10-29 17:33:21 +0000 |
3 | +++ openerp-server 2012-11-08 11:45:27 +0000 |
4 | @@ -19,7 +19,7 @@ |
5 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6 | # |
7 | ############################################################################## |
8 | - |
9 | +# pylint: disable=C0103 |
10 | """ |
11 | OpenERP - Server |
12 | OpenERP is an ERP+CRM program for small and medium businesses. |
13 | @@ -50,7 +50,8 @@ |
14 | if os.name == 'posix': |
15 | import pwd |
16 | if pwd.getpwuid(os.getuid())[0] == 'root' : |
17 | - sys.stderr.write("Running as user 'root' is a security risk, aborting.\n") |
18 | + sys.stderr.write("Running as user 'root'" |
19 | + "is a security risk, aborting.\n") |
20 | sys.exit(1) |
21 | |
22 | def check_postgres_user(): |
23 | @@ -60,7 +61,8 @@ |
24 | """ |
25 | config = openerp.tools.config |
26 | if config['db_user'] == 'postgres': |
27 | - sys.stderr.write("Using the database user 'postgres' is a security risk, aborting.") |
28 | + sys.stderr.write("Using the database user 'postgres'" |
29 | + "is a security risk, aborting.") |
30 | sys.exit(1) |
31 | |
32 | def report_configuration(): |
33 | @@ -91,7 +93,11 @@ |
34 | def preload_registry(dbname): |
35 | """ Preload a registry, and start the cron.""" |
36 | try: |
37 | - db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=openerp.tools.config['init'] or openerp.tools.config['update'], pooljobs=False) |
38 | + _db, registry = \ |
39 | + openerp.pooler.get_db_and_pool(dbname, \ |
40 | + update_module=openerp.tools.config['init'] \ |
41 | + or openerp.tools.config['update'], \ |
42 | + pooljobs=False) |
43 | |
44 | # jobs will start to be processed later, when openerp.cron.start_master_thread() is called by openerp.service.start_services() |
45 | registry.schedule_cron_jobs() |
46 | @@ -102,7 +108,7 @@ |
47 | """ Preload a registry, possibly run a test file, and start the cron.""" |
48 | try: |
49 | config = openerp.tools.config |
50 | - db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=config['init'] or config['update'], pooljobs=False) |
51 | + db, _registry = openerp.pooler.get_db_and_pool(dbname, update_module=config['init'] or config['update'], pooljobs=False) |
52 | cr = db.cursor() |
53 | _logger.info('loading test file %s', test_file) |
54 | openerp.tools.convert_yaml_import(cr, 'base', file(test_file), 'test', {}, 'test', True) |
55 | @@ -112,6 +118,7 @@ |
56 | _logger.exception('Failed to initialize database `%s` and run test file `%s`.', dbname, test_file) |
57 | |
58 | def export_translation(): |
59 | + """ export the translation file to the file specified by translate_out""" |
60 | config = openerp.tools.config |
61 | dbname = config['db_name'] |
62 | |
63 | @@ -133,6 +140,7 @@ |
64 | _logger.info('translation file written successfully') |
65 | |
66 | def import_translation(): |
67 | + """ Import the translations back in """ |
68 | config = openerp.tools.config |
69 | context = {'overwrite': config["overwrite_existing_translations"]} |
70 | dbname = config['db_name'] |
71 | @@ -147,7 +155,7 @@ |
72 | # below. This variable is monitored by ``quit_on_signals()``. |
73 | quit_signals_received = 0 |
74 | |
75 | -def signal_handler(sig, frame): |
76 | +def signal_handler(_sig, _frame): |
77 | """ Signal handler: exit ungracefully on the second handled signal. |
78 | |
79 | :param sig: the signal number |
80 | @@ -160,7 +168,7 @@ |
81 | sys.stderr.write("Forced shutdown.\n") |
82 | os._exit(0) |
83 | |
84 | -def dumpstacks(sig, frame): |
85 | +def dumpstacks(_sig, _frame): |
86 | """ Signal handler: dump a stack trace for each existing thread.""" |
87 | # code from http://stackoverflow.com/questions/132058/getting-stack-trace-from-a-running-python-application#answer-2569696 |
88 | # modified for python 2.5 compatibility |
89 | @@ -187,7 +195,9 @@ |
90 | map(lambda sig: signal.signal(sig, signal_handler), SIGNALS) |
91 | signal.signal(signal.SIGQUIT, dumpstacks) |
92 | elif os.name == 'nt': |
93 | +# pylint: disable=F0401 |
94 | import win32api |
95 | +# pylint: enable=F0401 |
96 | win32api.SetConsoleCtrlHandler(lambda sig: signal_handler(sig, None), 1) |
97 | |
98 | def quit_on_signals(): |
99 | @@ -213,12 +223,14 @@ |
100 | sys.exit(0) |
101 | |
102 | def configure_babel_localedata_path(): |
103 | - # Workaround: py2exe and babel. |
104 | + """ Workaround: py2exe and babel. """ |
105 | if hasattr(sys, 'frozen'): |
106 | import babel |
107 | babel.localedata._dirname = os.path.join(os.path.dirname(sys.executable), 'localedata') |
108 | |
109 | def main(): |
110 | + """ the main routine for OPENERP """ |
111 | + |
112 | os.environ["TZ"] = "UTC" |
113 | |
114 | check_root_user() |
115 | |
116 | === modified file 'openerp/service/http_server.py' |
117 | --- openerp/service/http_server.py 2012-09-11 15:07:24 +0000 |
118 | +++ openerp/service/http_server.py 2012-11-08 11:45:27 +0000 |
119 | @@ -34,7 +34,8 @@ |
120 | |
121 | The OpenERP server defines a single instance of a HTTP server, listening at |
122 | the standard 8069, 8071 ports (well, it is 2 servers, and ports are |
123 | - configurable, of course). This "single" server then uses a `MultiHTTPHandler` |
124 | + configurable, of course). |
125 | + This "single" server then uses a `MultiHTTPHandler` |
126 | to dispatch requests to the appropriate channel protocol, like the XML-RPC, |
127 | static HTTP, DAV or other. |
128 | """ |
129 | @@ -44,51 +45,28 @@ |
130 | import urllib |
131 | import os |
132 | import logging |
133 | +from openerp.service.security import security |
134 | +from openerp.service.websrv_lib import FixSendError, \ |
135 | + HttpOptions, HTTPHandler, reg_http_service, AuthProvider,\ |
136 | + AuthRejectedExc, AuthRequiredExc |
137 | |
138 | -from websrv_lib import * |
139 | import openerp.tools as tools |
140 | - |
141 | -try: |
142 | - import fcntl |
143 | -except ImportError: |
144 | - fcntl = None |
145 | - |
146 | -try: |
147 | - from ssl import SSLError |
148 | -except ImportError: |
149 | - class SSLError(Exception): pass |
150 | - |
151 | + |
152 | _logger = logging.getLogger(__name__) |
153 | |
154 | -# TODO delete this for 6.2, it is still needed for 6.1. |
155 | -class HttpLogHandler: |
156 | - """ helper class for uniform log handling |
157 | - Please define self._logger at each class that is derived from this |
158 | - """ |
159 | - _logger = None |
160 | - |
161 | - def log_message(self, format, *args): |
162 | - self._logger.debug(format % args) # todo: perhaps other level |
163 | - |
164 | - def log_error(self, format, *args): |
165 | - self._logger.error(format % args) |
166 | - |
167 | - def log_exception(self, format, *args): |
168 | - self._logger.exception(format, *args) |
169 | - |
170 | - def log_request(self, code='-', size='-'): |
171 | - self._logger.debug('"%s" %s %s', |
172 | - self.requestline, str(code), str(size)) |
173 | - |
174 | -class StaticHTTPHandler(HttpLogHandler, FixSendError, HttpOptions, HTTPHandler): |
175 | + |
176 | +class StaticHTTPHandler( FixSendError, HttpOptions, HTTPHandler): |
177 | + """ The static http handler""" |
178 | _logger = logging.getLogger(__name__) |
179 | |
180 | _HTTP_OPTIONS = { 'Allow': ['OPTIONS', 'GET', 'HEAD'] } |
181 | |
182 | - def __init__(self,request, client_address, server): |
183 | - HTTPHandler.__init__(self,request,client_address,server) |
184 | + def __init__(self, request, client_address, server): |
185 | + HTTPHandler.__init__(self, request, client_address, server) |
186 | document_root = tools.config.get('static_http_document_root', False) |
187 | - assert document_root, "Please specify static_http_document_root in configuration, or disable static-httpd!" |
188 | + assert document_root, \ |
189 | + "Please specify static_http_document_root in configuration, "\ |
190 | + "or disable static-httpd!" |
191 | self.__basepath = document_root |
192 | |
193 | def translate_path(self, path): |
194 | @@ -100,23 +78,27 @@ |
195 | |
196 | """ |
197 | # abandon query parameters |
198 | - path = path.split('?',1)[0] |
199 | - path = path.split('#',1)[0] |
200 | + path = path.split('?', 1)[0] |
201 | + path = path.split('#', 1)[0] |
202 | path = posixpath.normpath(urllib.unquote(path)) |
203 | words = path.split('/') |
204 | words = filter(None, words) |
205 | path = self.__basepath |
206 | for word in words: |
207 | - if word in (os.curdir, os.pardir): continue |
208 | + if word in (os.curdir, os.pardir): |
209 | + continue |
210 | path = os.path.join(path, word) |
211 | return path |
212 | |
213 | def init_static_http(): |
214 | + """setup the static file http handler.""" |
215 | if not tools.config.get('static_http_enable', False): |
216 | return |
217 | |
218 | document_root = tools.config.get('static_http_document_root', False) |
219 | - assert document_root, "Document root must be specified explicitly to enable static HTTP service (option --static-http-document-root)" |
220 | + assert document_root, \ |
221 | + "Document root must be specified explicitly to enable static HTTP service" \ |
222 | + " (option --static-http-document-root)" |
223 | |
224 | base_path = tools.config.get('static_http_url_prefix', '/') |
225 | |
226 | @@ -124,35 +106,39 @@ |
227 | |
228 | _logger.info("Registered HTTP dir %s for %s", document_root, base_path) |
229 | |
230 | -import security |
231 | + |
232 | |
233 | class OpenERPAuthProvider(AuthProvider): |
234 | """ Require basic authentication.""" |
235 | - def __init__(self,realm='OpenERP User'): |
236 | - self.realm = realm |
237 | + def __init__(self, realm='OpenERP User'): |
238 | + AuthProvider.__init__(self, realm) |
239 | self.auth_creds = {} |
240 | self.auth_tries = 0 |
241 | self.last_auth = None |
242 | |
243 | def authenticate(self, db, user, passwd, client_address): |
244 | try: |
245 | - uid = security.login(db,user,passwd) |
246 | + uid = security.login(db, user, passwd) |
247 | if uid is False: |
248 | return False |
249 | return (user, passwd, db, uid) |
250 | - except Exception,e: |
251 | - _logger.debug("Fail auth: %s" % e ) |
252 | - return False |
253 | - |
254 | - def checkRequest(self,handler,path, db=False): |
255 | - auth_str = handler.headers.get('Authorization',False) |
256 | + except AuthRejectedExc, e: |
257 | + _logger.debug("Fail auth: %s" % e ) |
258 | + return False |
259 | + except AuthRequiredExc, e: |
260 | + _logger.debug("Fail auth: %s" % e ) |
261 | + return False |
262 | + |
263 | + |
264 | + def checkRequest(self, handler, path, db=False): |
265 | + auth_str = handler.headers.get('Authorization', False) |
266 | try: |
267 | if not db: |
268 | db = handler.get_db_from_path(path) |
269 | - except Exception: |
270 | + except Exception: #FIXME! what exception is really thrown here? |
271 | if path.startswith('/'): |
272 | path = path[1:] |
273 | - psp= path.split('/') |
274 | + psp = path.split('/') |
275 | if len(psp)>1: |
276 | db = psp[0] |
277 | else: |
278 | @@ -162,10 +148,12 @@ |
279 | if self.auth_creds.get(db): |
280 | return True |
281 | if auth_str and auth_str.startswith('Basic '): |
282 | - auth_str=auth_str[len('Basic '):] |
283 | - (user,passwd) = base64.decodestring(auth_str).split(':') |
284 | - _logger.info("Found user=\"%s\", passwd=\"***\" for db=\"%s\"", user, db) |
285 | - acd = self.authenticate(db,user,passwd,handler.client_address) |
286 | + auth_str = auth_str[len('Basic '):] |
287 | + (user, passwd) = base64.decodestring(auth_str).split(':') |
288 | + _logger.info(\ |
289 | + "Found user=\"%s\", passwd=\"***\" for db=\"%s\"", \ |
290 | + user, db) |
291 | + acd = self.authenticate(db, user, passwd, handler.client_address) |
292 | if acd != False: |
293 | self.auth_creds[db] = acd |
294 | self.last_auth = db |
295 | |
296 | === modified file 'openerp/service/websrv_lib.py' |
297 | --- openerp/service/websrv_lib.py 2012-02-12 11:45:09 +0000 |
298 | +++ openerp/service/websrv_lib.py 2012-11-08 11:45:27 +0000 |
299 | @@ -52,13 +52,13 @@ |
300 | def __init__(self,realm): |
301 | self.realm = realm |
302 | |
303 | - def authenticate(self, user, passwd, client_address): |
304 | + def authenticate(self, db, user, passwd, client_address): |
305 | return False |
306 | |
307 | def log(self, msg): |
308 | print msg |
309 | |
310 | - def checkRequest(self,handler,path = '/'): |
311 | + def checkRequest(self, handler, path = '/', db=False): |
312 | """ Check if we are allowed to process that request |
313 | """ |
314 | pass |
I can't say I'm fond of the way many lines are broken to fit in 80chars. Not the fitting in 80chars thing (that's great), but the way it's done e.g.
sys. stderr. write(" Running as user 'root' is a security risk, aborting.\n")
to
sys. stderr. write(" Running as user 'root'"
" is a security risk, aborting.\n")
I think would make more sense (and look better) as
sys. stderr. write(
"Running as user 'root' is a security risk, aborting.\n")
and
db, registry = openerp. pooler. get_db_ and_pool( dbname, update_ module= openerp. tools.config[ 'init'] or openerp. tools.config[ 'update' ], pooljobs=False)
to
_db, registry = \
openerp. pooler. get_db_ and_pool( dbname, \
update_ module= openerp. tools.config[ 'init'] \
or openerp. tools.config[ 'update' ], \
pooljobs= False)
is downright weird, why not e.g.
to_update = openerp. tools.config[ 'init'] \ tools.config[ 'update' ] pooler. get_db_ and_pool( module= to_update, pooljobs=False)
or openerp.
_db, registry = openerp.
dbname, update_
this kind of wonky line-breaking seems fairly common and hampers readablility more than it helps.