web/webconfig.py
branchstable
changeset 9326 9d145b4c4e53
parent 9317 0f2b80078aeb
child 9340 b1e933b0e850
equal deleted inserted replaced
9325:a4fc09836329 9326:9d145b4c4e53
   294         """
   294         """
   295         return str(uuid4())
   295         return str(uuid4())
   296 
   296 
   297     def sign_text(self, text):
   297     def sign_text(self, text):
   298         """sign some text for later checking"""
   298         """sign some text for later checking"""
       
   299         # hmac.new expect bytes
       
   300         if isinstance(text, unicode):
       
   301             text = text.encode('utf-8')
   299         # replace \r\n so we do not depend on whether a browser "reencode"
   302         # replace \r\n so we do not depend on whether a browser "reencode"
   300         # original message using \r\n or not
   303         # original message using \r\n or not
   301         return hmac.new(self._instance_salt,
   304         return hmac.new(self._instance_salt,
   302                         text.strip().replace('\r\n', '\n')).hexdigest()
   305                         text.strip().replace('\r\n', '\n')).hexdigest()
   303 
   306 
   304     def check_text_sign(self, text, signature):
   307     def check_text_sign(self, text, signature):
   305         """check the text signature is equal to the given signature"""
   308         """check the text signature is equal to the given signature"""
   306         return self.sign_text(text) == signature
   309         return self.sign_text(text) == signature
   307 
       
   308 
   310 
   309     def locate_resource(self, rid):
   311     def locate_resource(self, rid):
   310         """return the (directory, filename) where the given resource
   312         """return the (directory, filename) where the given resource
   311         may be found
   313         may be found
   312         """
   314         """