comparison src/server/server.py @ 865:f024fc5744d0

server: fixes options parsing when url_redirections_dict or url_redirections_profile are not defined
author souliane <souliane@mailoo.org>
date Mon, 22 Feb 2016 12:06:35 +0100
parents e3e2effc9a4c
children 782ba105f5c7
comparison
equal deleted inserted replaced
864:d8c2203998df 865:f024fc5744d0
119 """ 119 """
120 super(LiberviaRootResource, self).__init__(*args, **kwargs) 120 super(LiberviaRootResource, self).__init__(*args, **kwargs)
121 121
122 ## redirections 122 ## redirections
123 self.redirections = {} 123 self.redirections = {}
124 if options['url_redirections_dict'] and not options['url_redirections_profile']: 124 if options.get('url_redirections_dict') is not None and not options['url_redirections_profile']:
125 raise ValueError(u"url_redirections_profile need to be filled if you want to use url_redirections_dict") 125 raise ValueError(u"url_redirections_profile need to be filled if you want to use url_redirections_dict")
126 126
127 for old, new in options['url_redirections_dict'].iteritems(): 127 for old, new in options.get('url_redirections_dict', {}).iteritems():
128 if not old.strip(): 128 if not old.strip():
129 # root URL special case 129 # root URL special case
130 old = '' 130 old = ''
131 elif not old.startswith('/'): 131 elif not old.startswith('/'):
132 raise ValueError(u"redirected url must start with '/', got {}".format(old)) 132 raise ValueError(u"redirected url must start with '/', got {}".format(old))
157 else: 157 else:
158 raise NotImplementedError(u"{scheme}: scheme is not managed for url_redirections_dict".format(scheme=new_url.scheme)) 158 raise NotImplementedError(u"{scheme}: scheme is not managed for url_redirections_dict".format(scheme=new_url.scheme))
159 self.redirections[old] = request_data 159 self.redirections[old] = request_data
160 if not old: 160 if not old:
161 log.info(u"Root URL redirected to {uri}".format(uri=request_data[1].decode('utf-8'))) 161 log.info(u"Root URL redirected to {uri}".format(uri=request_data[1].decode('utf-8')))
162 del options['url_redirections_dict'] 162 options.pop('url_redirections_dict', None)
163 del options['url_redirections_profile'] 163 options.pop('url_redirections_profile', None)
164 164
165 if not '' in self.redirections: 165 if not '' in self.redirections:
166 self.redirections[''] = self._getRequestData(C.LIBERVIA_MAIN_PAGE) 166 self.redirections[''] = self._getRequestData(C.LIBERVIA_MAIN_PAGE)
167 167
168 def _normalizeURL(self, url, lower=True): 168 def _normalizeURL(self, url, lower=True):