Commits

Anonymous committed 9fe02ac

MD5 sums checking as a separate function

Comments (0)

Files changed (1)

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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.