~ubuntu-branches/ubuntu/vivid/haproxy/vivid

« back to all changes in this revision

Viewing changes to debian/dconv/parser/keyword.py

  • Committer: Package Import Robot
  • Author(s): Apollon Oikonomopoulos
  • Date: 2014-06-20 11:05:17 UTC
  • mfrom: (1.1.15) (15.1.12 experimental)
  • Revision ID: package-import@ubuntu.com-20140620110517-u6q5p9kyy2f3ozw9
Tags: 1.5.0-1
* New upstream stable series. Notable changes since the 1.4 series:
  + Native SSL support on both sides with SNI/NPN/ALPN and OCSP stapling.
  + IPv6 and UNIX sockets are supported everywhere
  + End-to-end HTTP keep-alive for better support of NTLM and improved
    efficiency in static farms
  + HTTP/1.1 response compression (deflate, gzip) to save bandwidth
  + PROXY protocol versions 1 and 2 on both sides
  + Data sampling on everything in request or response, including payload
  + ACLs can use any matching method with any input sample
  + Maps and dynamic ACLs updatable from the CLI
  + Stick-tables support counters to track activity on any input sample
  + Custom format for logs, unique-id, header rewriting, and redirects
  + Improved health checks (SSL, scripted TCP, check agent, ...)
  + Much more scalable configuration supports hundreds of thousands of
    backends and certificates without sweating

* Upload to unstable, merge all 1.5 work from experimental. Most important
  packaging changes since 1.4.25-1 include:
  + systemd support.
  + A more sane default config file.
  + Zero-downtime upgrades between 1.5 releases by gracefully reloading
    HAProxy during upgrades.
  + HTML documentation shipped in the haproxy-doc package.
  + kqueue support for kfreebsd.

* Packaging changes since 1.5~dev26-2:
  + Drop patches merged upstream:
    o Fix-reference-location-in-manpage.patch
    o 0001-BUILD-stats-workaround-stupid-and-bogus-Werror-forma.patch
  + d/watch: look for stable 1.5 releases
  + systemd: respect CONFIG and EXTRAOPTS when specified in
    /etc/default/haproxy.
  + initscript: test the configuration before start or reload.
  + initscript: remove the ENABLED flag and logic.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import re
 
2
import parser
 
3
from urllib import quote
 
4
 
 
5
class Parser(parser.Parser):
 
6
    def __init__(self, pctxt):
 
7
        parser.Parser.__init__(self, pctxt)
 
8
        self.keywordPattern = re.compile(r'^(%s%s)(%s)' % (
 
9
            '([a-z][a-z0-9\-_\.]*[a-z0-9\-_)])', # keyword
 
10
            '( [a-z0-9\-_]+)*',                  # subkeywords
 
11
            '(\((&lt;[a-z0-9]+&gt;)((\[?,|/)(&lt;[a-z0-9]+&gt;)(\]?))*\))?'   # arg (ex: (<backend>), (<frontend>/<backend>), (<offset1>,<length>[,<offset2>]) ...
 
12
        ))
 
13
 
 
14
    def parse(self, line):
 
15
        pctxt = self.pctxt
 
16
        keywords = pctxt.keywords
 
17
        keywordsCount = pctxt.keywordsCount
 
18
        chapters = pctxt.chapters
 
19
 
 
20
        res = ""
 
21
 
 
22
        if line != "" and not re.match(r'^ ', line):
 
23
            parsed = self.keywordPattern.match(line)
 
24
            if parsed != None:
 
25
 
 
26
                keyword = parsed.group(1)
 
27
                arg     = parsed.group(4)
 
28
                parameters = line[len(keyword) + len(arg):]
 
29
                if parameters != "" and not re.match("^ +(&lt;|\[|\{|/|\(deprecated\))", parameters):
 
30
                    keyword = False
 
31
                else:
 
32
                    splitKeyword = keyword.split(" ")
 
33
                parameters = arg + parameters
 
34
            else:
 
35
                keyword = False
 
36
 
 
37
            if keyword and (len(splitKeyword) <= 5):
 
38
                toplevel = pctxt.details["toplevel"]
 
39
                for j in xrange(0, len(splitKeyword)):
 
40
                    subKeyword = " ".join(splitKeyword[0:j + 1])
 
41
                    if subKeyword != "no":
 
42
                        if not subKeyword in keywords:
 
43
                            keywords[subKeyword] = set()
 
44
                        keywords[subKeyword].add(pctxt.details["chapter"])
 
45
                    res += '<a class="anchor" name="%s"></a>' % subKeyword
 
46
                    res += '<a class="anchor" name="%s-%s"></a>' % (toplevel, subKeyword)
 
47
                    res += '<a class="anchor" name="%s-%s"></a>' % (pctxt.details["chapter"], subKeyword)
 
48
                    res += '<a class="anchor" name="%s (%s)"></a>' % (subKeyword, chapters[toplevel]['title'])
 
49
                    res += '<a class="anchor" name="%s (%s)"></a>' % (subKeyword, chapters[pctxt.details["chapter"]]['title'])
 
50
 
 
51
                deprecated = parameters.find("(deprecated)")
 
52
                if deprecated != -1:
 
53
                    prefix = ""
 
54
                    suffix = ""
 
55
                    parameters = parameters.replace("(deprecated)", '<span class="label label-warning">(deprecated)</span>')
 
56
                else:
 
57
                    prefix = ""
 
58
                    suffix = ""
 
59
 
 
60
                nextline = pctxt.get_line(1)
 
61
 
 
62
                while nextline.startswith("   "):
 
63
                    # Found parameters on the next line
 
64
                    parameters += "\n" + nextline
 
65
                    pctxt.next()
 
66
                    if pctxt.has_more_lines(1):
 
67
                        nextline = pctxt.get_line(1)
 
68
                    else:
 
69
                        nextline = ""
 
70
 
 
71
 
 
72
                parameters = self.colorize(parameters)
 
73
                res += '<div class="keyword">%s<b><a class="anchor" name="%s"></a><a href="#%s">%s</a></b>%s%s</div>' % (prefix, keyword, quote("%s-%s" % (pctxt.details["chapter"], keyword)), keyword, parameters, suffix)
 
74
                pctxt.next()
 
75
                pctxt.stop = True
 
76
            elif line.startswith("/*"):
 
77
                # Skip comments in the documentation
 
78
                while not pctxt.get_line().endswith("*/"):
 
79
                    pctxt.next()
 
80
                pctxt.next()
 
81
            else:
 
82
                # This is probably not a keyword but a text, ignore it
 
83
                res += line
 
84
        else:
 
85
            res += line
 
86
 
 
87
        return res
 
88
 
 
89
    # Used to colorize keywords parameters
 
90
    # TODO : use CSS styling
 
91
    def colorize(self, text):
 
92
        colorized = ""
 
93
        tags = [
 
94
                [ "["   , "]"   , "#008" ],
 
95
                [ "{"   , "}"   , "#800" ],
 
96
                [ "&lt;", "&gt;", "#080" ],
 
97
        ]
 
98
        heap = []
 
99
        pos = 0
 
100
        while pos < len(text):
 
101
            substring = text[pos:]
 
102
            found = False
 
103
            for tag in tags:
 
104
                if substring.startswith(tag[0]):
 
105
                    # Opening tag
 
106
                    heap.append(tag)
 
107
                    colorized += '<span style="color: %s">%s' % (tag[2], substring[0:len(tag[0])])
 
108
                    pos += len(tag[0])
 
109
                    found = True
 
110
                    break
 
111
                elif substring.startswith(tag[1]):
 
112
                    # Closing tag
 
113
 
 
114
                    # pop opening tags until the corresponding one is found
 
115
                    openingTag = False
 
116
                    while heap and openingTag != tag:
 
117
                        openingTag = heap.pop()
 
118
                        if openingTag != tag:
 
119
                            colorized += '</span>'
 
120
                    # all intermediate tags are now closed, we can display the tag
 
121
                    colorized += substring[0:len(tag[1])]
 
122
                    # and the close it if it was previously opened
 
123
                    if openingTag == tag:
 
124
                        colorized += '</span>'
 
125
                    pos += len(tag[1])
 
126
                    found = True
 
127
                    break
 
128
            if not found:
 
129
                colorized += substring[0]
 
130
                pos += 1
 
131
        # close all unterminated tags
 
132
        while heap:
 
133
            tag = heap.pop()
 
134
            colorized += '</span>'
 
135
 
 
136
        return colorized
 
137
 
 
138