[Blends-commit] [SCM] website branch, master, updated. cf9b551122eab6eed0fce1bd11db23d255e3b970

Akshita Jha akshita-guest at users.alioth.debian.org
Mon Jul 27 17:51:07 UTC 2015


The following commit has been merged in the master branch:
commit 0e789f21f303a84c7bbbc9b24ba9672103da302c
Author: Akshita Jha <akshita-guest at users.alioth.debian.org>
Date:   Mon Jul 27 23:18:58 2015 +0530

    Modify blendsmarkdown.py : Make blendsmarkdown.py pep8 complaint

diff --git a/webtools_py3/blendsmarkdown.py b/webtools_py3/blendsmarkdown.py
index 4baddb0..8c3a973 100644
--- a/webtools_py3/blendsmarkdown.py
+++ b/webtools_py3/blendsmarkdown.py
@@ -1,58 +1,65 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 # Copyright 2008: Andreas Tille <tille at debian.org>
 # License: GPL
 
 # To enable better formatting of long descriptions we use Markdown
 # and some preprocessing of the RFC822 formatted descriptions
 
-import re
 
-from sys import stderr, exit
+from __future__ import print_function
+
+import re
+from sys import stderr
 from markdown import markdown            # Markdown
 from docutils.core import publish_parts  # alternatively reST
 from genshi import Markup
 
-from blendsunicode import to_unicode
-
 detect_list_start_re = re.compile("^\s+[-*+]\s+")
 detect_code_start_re = re.compile("^\s")
-detect_code_end_re   = re.compile("^[^\s]")
-detect_url_re        = re.compile("[fh]t?tp://")
+detect_code_end_re = re.compile("^[^\s]")
+detect_url_re = re.compile("[fh]t?tp://")
+
 
 def PrepareMarkdownInput(lines):
-    ret    = ''
+    ret = ''
     inlist = 0
     incode = 0
     for line in lines:
         # strip leading space from description as well as useless trailing
         line = re.sub('^ ', '', line.rstrip())
 
-        # a '^\.$' marks in descriptions a new paragraph, markdown uses an empty line here
+        # a '^\.$' marks in descriptions a new paragraph,
+        # markdown uses an empty line here
         line = re.sub('^\.$', '', line)
 
-        # In long descriptions 'o' and '.' are quite frequently used as bullet in lists which
-        # is not recognised by markdown.  So just turn '[.o]' into '*' to let markdown do
+        # In long descriptions 'o' and '.' are quite frequently used
+        # as bullet in lists which is not recognised by markdown.
+        # So just turn '[.o]' into '*' to let markdown do
         # its work successfully.
         line = re.sub('^(\s*)[.o]\s+', '\\1* ', line)
 
-        # To enable Markdown debugging and verbose output in remarks a 'o'/'.' is inserted
-        # as '\o'/'\.' in remarks - the original is restored here:
+        # To enable Markdown debugging and verbose output in remarks
+        # a 'o'/'.' is inserted as '\o'/'\.' in remarks
+        # - the original is restored here:
         line = re.sub('^(\s*)\\\\([.o]\s+)', '\\1\\2', line)
 
         if detect_code_start_re.search(line):
-            if incode == 0: # If a list or verbatim mode starts MarkDown needs an empty line
+            # If a list or verbatim mode starts MarkDown needs an empty line
+            if incode == 0:
                 ret += "\n"
                 incode = 1
                 if detect_list_start_re.search(line):
                     inlist = 1
         if incode == 1 and inlist == 0:
-            ret += "\t" # Add a leading tab if in verbatim but not in list mode
-        # If there is an empty line or a not indented line the list or verbatim text ends
-        # It is important to check for empty lines because some descriptions would insert
-        # more lines than needed in verbose mode (see for instance glam2)
-        if ( detect_code_end_re.search(line) or line == '' ) and incode == 1:
-            inlist = 0 # list ends if indentation stops
-            incode = 0 # verbatim mode ends if indentation stops
+            # Add a leading tab if in verbatim but not in list mode
+            ret += "\t"
+        # If there is an empty line or a not indented line the list
+        # or verbatim text ends. It is important to check for empty lines
+        # because some descriptions would insert more lines than needed
+        # in verbose mode (see for instance glam2)
+        if (detect_code_end_re.search(line) or line == '') and incode == 1:
+            inlist = 0  # list ends if indentation stops
+            incode = 0  # verbatim mode ends if indentation stops
         # Mask # at first character in line which would lead to
         #   MARKDOWN-CRITICAL: "We've got a problem header!"
         # otherwise
@@ -61,53 +68,60 @@ def PrepareMarkdownInput(lines):
         if detect_url_re.search(line):
             # some descriptions put URLs in '<>' which is unneeded and might
             # confuse the parsing of '&' in URLs which is needed sometimes
-            line = re.sub('<*([fh]t?tp://[-./\w?=~;&%]+)>*', '[\\1](\\1)', line)
+            line = re.sub('<*([fh]t?tp://[-./\w?=~;&%]+)>*',
+                          '[\\1](\\1)', line)
         ret += line + "\n"
     return ret
 
+
 def render_longdesc(lines):
-    MarkDownInput  = PrepareMarkdownInput(lines)
+    MarkDownInput = PrepareMarkdownInput(lines)
 
     global rendering_lib
     if rendering_lib == 'rest':
         try:
             LongDesc = publish_parts(MarkDownInput, writer_name='html')['body']
         except:
-            print("Unable to render the following prepared text:\n" + MarkDownInput, file=stderr)
+            print("Unable to render the following prepared text: \n %s"
+                  % (MarkDownInput), file=stderr)
             LongDesc = "Problems in rendering description using reST"
-    else: # by default use Markdown
+    else:  # by default use Markdown
         LongDesc = markdown(MarkDownInput)
     return LongDesc
 
+
 def SplitDescription(description):
     # Split first line of Description value as short description
-    
+
     lines = description.splitlines()
 
-    ShortDesc = lines[0].replace("&", "&").replace("<", "<").replace(">", ">")
-    LongDesc  = render_longdesc(lines[1:])
+    ShortDesc = lines[0].replace("&", "&")\
+        .replace("<", "<").replace(">", ">")
+    LongDesc = render_longdesc(lines[1:])
 
     return (ShortDesc, LongDesc)
 
+
 def MarkupString(string, pkg, elem, lang='en'):
     # Genshi does not touch strings that are marked with "Markup()"
-    # This function does the actual Markup call for any string with error checking
+    # This function does the actual Markup call
+    # for any string with error checking
 
-    if string == None:
+    if string is None:
         return None
     try:
         string = Markup(string)
     except UnicodeDecodeError as errtxt:
-        print("----> %s UnicodeDecodeError in %s (lang='%s'): '%s'; ErrTxt: %s" % \
-                                    (elem, pkg, lang, 'debug-string', errtxt), file=stderr)
+        print("----> %s UnicodeDecodeError in %s (lang='%s'): '%s'; ErrTxt: %s"
+              % (elem, pkg, lang, 'debug-string', errtxt), file=stderr)
         try:
             string = Markup(str(string, 'utf-8'))
         except TypeError as errtxt:
-            print("====> %s TypeError in %s (lang='%s'): '%s'; ErrTxt: %s" % \
-                                    (elem, pkg, lang, 'debug-string', errtxt), file=stderr)
+            print("====> %s TypeError in %s (lang='%s'): '%s'; ErrTxt: %s"
+                  % (elem, pkg, lang, 'debug-string', errtxt), file=stderr)
     except TypeError as errtxt:
-        print("----> %s TypeError in %s (lang='%s'): '%s'; ErrTxt: %s" % \
-                                    (elem, pkg, lang, 'debug-string', errtxt), file=stderr)
+        print("----> %s TypeError in %s (lang='%s'): '%s'; ErrTxt: %s"
+              % (elem, pkg, lang, 'debug-string', errtxt), file=stderr)
     return string
 
-rendering_lib  = ''
+rendering_lib = ''

-- 
Static and dynamic websites for Debian Pure Blends



More information about the Blends-commit mailing list