Commits

Anonymous committed 9fe02ac

MD5 sums checking as a separate function

  • Participants
  • Parent commits 590e1de

Comments (0)

Files changed (1)

File sphinx/web/middleware/appserver.py

     def doHTMLFile(self, req, resp):
         """Rendering the HTML files happens here: things like themes,
         OpenID info and so on."""
+        def check_rst_sum(repo_file):
+            """Count the MD5 sum for 'repo_file' and compare it with
+            MD5 sum from the database. Return True if the MD5 sum has
+            changed and False otherwise (return False also when the
+            'repo_file' file does not exist."""
+            if path.exists(repo_file):
+                try:
+                    w = open(repo_file)
+                    rst_contents = w.read()
+                    w.close()
+                except Exception, err:
+                    SphinxError(err)
+
+                rst_sum = md5(rst_contents).hexdigest()
+
+                if self.reposums.sum_changed(repo_file, rst_sum):
+                    return True
+            return False
+
         resp.content_type = 'text/html'
-        resp.charset = 'utf8'
-        
+        resp.charset = 'utf8' 
         file_path = self.constructPath(req)
 
         repo_file = path.join(self.webconfig.repodir,file_path[:-5] + '.rst')
-        if path.exists(repo_file):
-            try:
-                w = open(repo_file)
-                rst_contents = w.read()
-                w.close()
-            except Exception, err:
-                SphinxError(err)
-
-            rst_sum = md5(rst_contents).hexdigest()
-
-            if self.reposums.sum_changed(repo_file, rst_sum):
-               self.htmlbuilder.render_page(file_path[:-5])
+        if check_rst_sum(repo_file):
+            self.htmlbuilder.render_page(file_path[:-5])
 
         file_path = path.join(self.www_dir, file_path)
-
         try:
             if file_path.endswith('.html'):
                 file_contents = open(file_path).read()