summaryrefslogtreecommitdiff
path: root/doc/sample_html/cogapp_whiteutils.html
blob: e5f84356b3a5dfe04103d154c7245abba3572430 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!doctype html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Coverage for cogapp\whiteutils</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<script src='jquery-1.3.2.min.js'></script>
<script>
function toggle_lines(btn, cls) {
    var btn = $(btn);
    if (btn.hasClass("hide")) {
        $("#source ."+cls).removeClass("hide");
        btn.removeClass("hide");
    }
    else {
        $("#source ."+cls).addClass("hide");
        btn.addClass("hide");
    }
}
</script>
</head>
<body>
<div id='header'>
    <div class='content'>
        <h1>Coverage for <b>cogapp\whiteutils</b> :
            <span class='pc_cov'>92%</span>
        </h1>
        <h2 class='stats'>
            37 statements
            <span class='run hide' onclick='toggle_lines(this, "run")'>34 run</span>
            <span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
            <span class='mis' onclick='toggle_lines(this, "mis")'>3 missing</span>
        </h2>
    </div>
</div>

<div id='source'>
<table cellspacing='0' cellpadding='0'>
<tr>
<td class='linenos' valign='top'>
<p class='pln'>1</p>
<p class='pln'>2</p>
<p class='pln'>3</p>
<p class='pln'>4</p>
<p class='pln'>5</p>
<p class='pln'>6</p>
<p class='stm run hide'>7</p>
<p class='pln'>8</p>
<p class='stm run hide'>9</p>
<p class='pln'>10</p>
<p class='pln'>11</p>
<p class='pln'>12</p>
<p class='pln'>13</p>
<p class='stm run hide'>14</p>
<p class='pln'>15</p>
<p class='stm run hide'>16</p>
<p class='pln'>17</p>
<p class='pln'>18</p>
<p class='pln'>19</p>
<p class='stm run hide'>20</p>
<p class='pln'>21</p>
<p class='pln'>22</p>
<p class='pln'>23</p>
<p class='stm run hide'>24</p>
<p class='stm run hide'>25</p>
<p class='stm run hide'>26</p>
<p class='stm mis'>27</p>
<p class='stm mis'>28</p>
<p class='stm run hide'>29</p>
<p class='pln'>30</p>
<p class='stm run hide'>31</p>
<p class='pln'>32</p>
<p class='pln'>33</p>
<p class='pln'>34</p>
<p class='pln'>35</p>
<p class='stm run hide'>36</p>
<p class='stm run hide'>37</p>
<p class='stm run hide'>38</p>
<p class='stm run hide'>39</p>
<p class='stm run hide'>40</p>
<p class='stm run hide'>41</p>
<p class='stm run hide'>42</p>
<p class='stm run hide'>43</p>
<p class='stm run hide'>44</p>
<p class='stm run hide'>45</p>
<p class='stm run hide'>46</p>
<p class='pln'>47</p>
<p class='stm run hide'>48</p>
<p class='pln'>49</p>
<p class='pln'>50</p>
<p class='stm run hide'>51</p>
<p class='stm mis'>52</p>
<p class='stm run hide'>53</p>
<p class='stm run hide'>54</p>
<p class='stm run hide'>55</p>
<p class='stm run hide'>56</p>
<p class='stm run hide'>57</p>
<p class='stm run hide'>58</p>
<p class='stm run hide'>59</p>
<p class='stm run hide'>60</p>
<p class='stm run hide'>61</p>
<p class='stm run hide'>62</p>
<p class='stm run hide'>63</p>
    
</td>
<td class='text' valign='top'>
<p class='pln'>&quot;&quot;&quot; Indentation utilities for Cog.</p>
<p class='pln'>&nbsp; &nbsp; http://nedbatchelder.com/code/cog</p>
<p class='pln'>&nbsp;</p>
<p class='pln'>&nbsp; &nbsp; Copyright 2004-2009, Ned Batchelder.</p>
<p class='pln'>&quot;&quot;&quot;</p>
<p class='pln'>&nbsp;</p>
<p class='stm run hide'>import re</p>
<p class='pln'>&nbsp;</p>
<p class='stm run hide'>def whitePrefix(strings):</p>
<p class='pln'>&nbsp; &nbsp; &quot;&quot;&quot; Determine the whitespace prefix common to all non-blank lines</p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; in the argument list.</p>
<p class='pln'>&nbsp; &nbsp; &quot;&quot;&quot;</p>
<p class='pln'>&nbsp; &nbsp; # Remove all blank lines from the list</p>
<p class='stm run hide'>&nbsp; &nbsp; strings = [s for s in strings if s.strip() != &#39;&#39;]</p>
<p class='pln'>&nbsp;</p>
<p class='stm run hide'>&nbsp; &nbsp; if not strings: return &#39;&#39;</p>
<p class='pln'>&nbsp;</p>
<p class='pln'>&nbsp; &nbsp; # Find initial whitespace chunk in the first line.</p>
<p class='pln'>&nbsp; &nbsp; # This is the best prefix we can hope for.</p>
<p class='stm run hide'>&nbsp; &nbsp; prefix = re.match(r&#39;\s*&#39;, strings[0]).group(0)</p>
<p class='pln'>&nbsp;</p>
<p class='pln'>&nbsp; &nbsp; # Loop over the other strings, keeping only as much of</p>
<p class='pln'>&nbsp; &nbsp; # the prefix as matches each string.</p>
<p class='stm run hide'>&nbsp; &nbsp; for s in strings:</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; for i in range(len(prefix)):</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if prefix[i] != s[i]:</p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prefix = prefix[:i]</p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break</p>
<p class='stm run hide'>&nbsp; &nbsp; return prefix</p>
<p class='pln'>&nbsp;</p>
<p class='stm run hide'>def reindentBlock(lines, newIndent=&#39;&#39;):</p>
<p class='pln'>&nbsp; &nbsp; &quot;&quot;&quot; Take a block of text as a string or list of lines.</p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; Remove any common whitespace indentation.</p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; Re-indent using newIndent, and return it as a single string.</p>
<p class='pln'>&nbsp; &nbsp; &quot;&quot;&quot;</p>
<p class='stm run hide'>&nbsp; &nbsp; if isinstance(lines, basestring):</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; lines = lines.split(&#39;\n&#39;)</p>
<p class='stm run hide'>&nbsp; &nbsp; oldIndent = whitePrefix(lines)</p>
<p class='stm run hide'>&nbsp; &nbsp; outLines = []</p>
<p class='stm run hide'>&nbsp; &nbsp; for l in lines:</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; if oldIndent:</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; l = l.replace(oldIndent, &#39;&#39;, 1)</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; if l and newIndent:</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; l = newIndent + l</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; outLines.append(l)</p>
<p class='stm run hide'>&nbsp; &nbsp; return &#39;\n&#39;.join(outLines)</p>
<p class='pln'>&nbsp;</p>
<p class='stm run hide'>def commonPrefix(strings):</p>
<p class='pln'>&nbsp; &nbsp; &quot;&quot;&quot; Find the longest string that is a prefix of all the strings.</p>
<p class='pln'>&nbsp; &nbsp; &quot;&quot;&quot;</p>
<p class='stm run hide'>&nbsp; &nbsp; if not strings:</p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; return &#39;&#39;</p>
<p class='stm run hide'>&nbsp; &nbsp; prefix = strings[0]</p>
<p class='stm run hide'>&nbsp; &nbsp; for s in strings:</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; if len(s) &lt; len(prefix):</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prefix = prefix[:len(s)]</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; if not prefix:</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &#39;&#39;</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; for i in range(len(prefix)):</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if prefix[i] != s[i]:</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prefix = prefix[:i]</p>
<p class='stm run hide'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break</p>
<p class='stm run hide'>&nbsp; &nbsp; return prefix</p>
    
</td>
</tr>
</table>
</div>

</body>
</html>