Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/submit_email/web/submit_email.py

Issue 29756624: Noissue - Adapt best practices for trailing commas (sitescripts) (Closed)
Patch Set: Re-run script on Python 2, added flake8-commas extension Created April 19, 2018, 2:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/stats/test/logprocessor.py ('k') | sitescripts/templateFilters.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 template = config.get('submit_email', product + '_verification_email_tem plate') 42 template = config.get('submit_email', product + '_verification_email_tem plate')
43 except (KeyError, ConfigParser.NoOptionError): 43 except (KeyError, ConfigParser.NoOptionError):
44 return send_simple_response(start_response, 400, 'Unknown product') 44 return send_simple_response(start_response, 400, 'Unknown product')
45 45
46 email = data.get('email', '').strip() 46 email = data.get('email', '').strip()
47 try: 47 try:
48 email = encode_email_address(email) 48 email = encode_email_address(email)
49 except ValueError: 49 except ValueError:
50 return send_simple_response( 50 return send_simple_response(
51 start_response, 400, 51 start_response, 400,
52 'Please enter a valid email address.' 52 'Please enter a valid email address.',
53 ) 53 )
54 54
55 params = [('email', email), ('signature', sign(config, email)), ('product', product)] 55 params = [('email', email), ('signature', sign(config, email)), ('product', product)]
56 lang = data.get('lang') 56 lang = data.get('lang')
57 if lang: 57 if lang:
58 params.append(('lang', lang)) 58 params.append(('lang', lang))
59 59
60 sendMail( 60 sendMail(
61 template, 61 template,
62 { 62 {
63 'recipient': email, 63 'recipient': email,
64 'verification_url': '%s?%s' % ( 64 'verification_url': '%s?%s' % (
65 urljoin(wsgiref.util.application_uri(environ), VERIFICATION_PATH ), 65 urljoin(wsgiref.util.application_uri(environ), VERIFICATION_PATH ),
66 urlencode(params) 66 urlencode(params),
67 ) 67 ),
68 } 68 },
69 ) 69 )
70 70
71 return send_simple_response( 71 return send_simple_response(
72 start_response, 200, 72 start_response, 200,
73 'A confirmation email has been sent. Please check ' 73 'A confirmation email has been sent. Please check '
74 'your email and click the confirmation link.' 74 'your email and click the confirmation link.',
75 ) 75 )
76 76
77 77
78 @url_handler(VERIFICATION_PATH) 78 @url_handler(VERIFICATION_PATH)
79 def verify_email(environ, start_response): 79 def verify_email(environ, start_response):
80 config = get_config() 80 config = get_config()
81 params = dict(parse_qsl(environ.get('QUERY_STRING', ''))) 81 params = dict(parse_qsl(environ.get('QUERY_STRING', '')))
82 82
83 try: 83 try:
84 filename = config.get('submit_email', params['product'] + '_filename') 84 filename = config.get('submit_email', params['product'] + '_filename')
85 except (KeyError, ConfigParser.NoOptionError): 85 except (KeyError, ConfigParser.NoOptionError):
86 return send_simple_response(start_response, 400, 'Unknown product') 86 return send_simple_response(start_response, 400, 'Unknown product')
87 87
88 email = params.get('email', '') 88 email = params.get('email', '')
89 signature = params.get('signature', '') 89 signature = params.get('signature', '')
90 if sign(config, email) != signature: 90 if sign(config, email) != signature:
91 return send_simple_response( 91 return send_simple_response(
92 start_response, 403, 92 start_response, 403,
93 'Invalid signature in verification request.' 93 'Invalid signature in verification request.',
94 ) 94 )
95 95
96 with open(filename, 'ab', 0) as file: 96 with open(filename, 'ab', 0) as file:
97 fcntl.lockf(file, fcntl.LOCK_EX) 97 fcntl.lockf(file, fcntl.LOCK_EX)
98 try: 98 try:
99 print >>file, email 99 print >>file, email
100 finally: 100 finally:
101 fcntl.lockf(file, fcntl.LOCK_UN) 101 fcntl.lockf(file, fcntl.LOCK_UN)
102 102
103 location = config.get('submit_email', 'successful_verification_redirect_loca tion') 103 location = config.get('submit_email', 'successful_verification_redirect_loca tion')
104 location = location.format(lang=quote(params.get('lang') or 'en', '')) 104 location = location.format(lang=quote(params.get('lang') or 'en', ''))
105 start_response('303 See Other', [('Location', location)]) 105 start_response('303 See Other', [('Location', location)])
106 return [] 106 return []
OLDNEW
« no previous file with comments | « sitescripts/stats/test/logprocessor.py ('k') | sitescripts/templateFilters.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld