Skip to content

Commit 147a26e

Browse files
committed
Mro
1 parent d395391 commit 147a26e

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

index.html

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,15 @@ <h2 id="combinatorics"><a href="#combinatorics" name="combinatorics">#</a>Combin
460460
</code></pre>
461461
<h2 id="datetime"><a href="#datetime" name="datetime">#</a>Datetime</h2>
462462
<ul>
463-
<li><strong>Module 'datetime' provides 'date' <code class="python hljs">&lt;D&gt;</code>, 'time' <code class="python hljs">&lt;T&gt;</code>, 'datetime' <code class="python hljs">&lt;DT&gt;</code> and 'timedelta' <code class="python hljs">&lt;TD&gt;</code> classes. All are immutable and hashable.</strong></li>
464-
<li><strong>Time and datetime can be 'aware' <code class="python hljs">&lt;a&gt;</code>, meaning they have defined timezone, or 'naive' <code class="python hljs">&lt;n&gt;</code>, meaning they don't.</strong></li>
463+
<li><strong>Module 'datetime' provides 'date' <code class="apache hljs"><span class="hljs-section">&lt;D&gt;</span></code>, 'time' <code class="apache hljs"><span class="hljs-section">&lt;T&gt;</span></code>, 'datetime' <code class="apache hljs"><span class="hljs-section">&lt;DT&gt;</span></code> and 'timedelta' <code class="apache hljs"><span class="hljs-section">&lt;TD&gt;</span></code> classes. All are immutable and hashable.</strong></li>
464+
<li><strong>Time and datetime can be 'aware' <code class="apache hljs"><span class="hljs-section">&lt;a&gt;</span></code>, meaning they have defined timezone, or 'naive' <code class="apache hljs"><span class="hljs-section">&lt;n&gt;</span></code>, meaning they don't.</strong></li>
465465
<li><strong>If object is naive it is presumed to be in system's timezone.</strong></li>
466466
</ul>
467467
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> date, time, datetime, timedelta
468468
<span class="hljs-keyword">from</span> dateutil.tz <span class="hljs-keyword">import</span> UTC, tzlocal, gettz
469469
</code></pre>
470470
<h3 id="constructors">Constructors</h3>
471-
<pre><code class="python language-python hljs">&lt;D&gt; = date(year, month, day)
471+
<pre><code class="python language-python apache hljs">&lt;D&gt; = date(year, month, day)
472472
&lt;T&gt; = time(hour=<span class="hljs-number">0</span>, minute=<span class="hljs-number">0</span>, second=<span class="hljs-number">0</span>, microsecond=<span class="hljs-number">0</span>, tzinfo=<span class="hljs-keyword">None</span>, fold=<span class="hljs-number">0</span>)
473473
&lt;DT&gt; = datetime(year, month, day, hour=<span class="hljs-number">0</span>, minute=<span class="hljs-number">0</span>, second=<span class="hljs-number">0</span>, ...)
474474
&lt;TD&gt; = timedelta(days=<span class="hljs-number">0</span>, seconds=<span class="hljs-number">0</span>, microseconds=<span class="hljs-number">0</span>, milliseconds=<span class="hljs-number">0</span>,
@@ -488,11 +488,11 @@ <h3 id="timezone">Timezone</h3>
488488
&lt;tz&gt; = tzlocal() <span class="hljs-comment"># Local timezone.</span>
489489
&lt;tz&gt; = gettz(<span class="hljs-string">'&lt;Cont.&gt;/&lt;City&gt;'</span>) <span class="hljs-comment"># Timezone from 'Continent/City_Name' str.</span>
490490
</code></pre>
491-
<pre><code class="python language-python hljs">&lt;DTa&gt; = &lt;DT&gt;.astimezone(&lt;tz&gt;) <span class="hljs-comment"># Datetime, converted to passed timezone.</span>
491+
<pre><code class="python language-python apache hljs">&lt;DTa&gt; = &lt;DT&gt;.astimezone(&lt;tz&gt;) <span class="hljs-comment"># Datetime, converted to passed timezone.</span>
492492
&lt;Ta/DTa&gt; = &lt;T/DT&gt;.replace(tzinfo=&lt;tz&gt;) <span class="hljs-comment"># Unconverted object with new timezone.</span>
493493
</code></pre>
494494
<h3 id="encode">Encode</h3>
495-
<pre><code class="python language-python hljs">&lt;D/T/DT&gt; = D/T/DT.fromisoformat(<span class="hljs-string">'&lt;iso&gt;'</span>) <span class="hljs-comment"># Object from ISO string.</span>
495+
<pre><code class="python language-python apache hljs">&lt;D/T/DT&gt; = D/T/DT.fromisoformat(<span class="hljs-string">'&lt;iso&gt;'</span>) <span class="hljs-comment"># Object from ISO string.</span>
496496
&lt;DT&gt; = DT.strptime(&lt;str&gt;, <span class="hljs-string">'&lt;format&gt;'</span>) <span class="hljs-comment"># Datetime from str, according to format.</span>
497497
&lt;D/DTn&gt; = D/DT.fromordinal(&lt;int&gt;) <span class="hljs-comment"># D/DTn from days since Christ.</span>
498498
&lt;DTa&gt; = DT.fromtimestamp(&lt;real&gt;, &lt;tz&gt;) <span class="hljs-comment"># DTa from seconds since Epoch in tz time.</span>
@@ -502,7 +502,7 @@ <h3 id="encode">Encode</h3>
502502
<li><strong>On Unix systems Epoch is <code class="python hljs"><span class="hljs-string">'1970-01-01 00:00 UTC'</span></code>, <code class="python hljs"><span class="hljs-string">'1970-01-01 01:00 CET'</span></code>, …</strong></li>
503503
</ul>
504504
<h3 id="decode">Decode</h3>
505-
<pre><code class="python language-python hljs">&lt;str&gt; = &lt;D/T/DT&gt;.isoformat() <span class="hljs-comment"># ISO string representation.</span>
505+
<pre><code class="python language-python apache hljs">&lt;str&gt; = &lt;D/T/DT&gt;.isoformat() <span class="hljs-comment"># ISO string representation.</span>
506506
&lt;str&gt; = &lt;D/T/DT&gt;.strftime(<span class="hljs-string">'&lt;format&gt;'</span>) <span class="hljs-comment"># Custom string representation.</span>
507507
&lt;int&gt; = &lt;D/DT&gt;.toordinal() <span class="hljs-comment"># Days since Christ, ignoring time and tz.</span>
508508
&lt;float&gt; = &lt;DT&gt;.timestamp() <span class="hljs-comment"># Seconds since Epoch in local time or tz.</span>
@@ -749,9 +749,10 @@ <h3 id="multipleinheritance">Multiple Inheritance</h3>
749749
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">C</span><span class="hljs-params">(A, B)</span>:</span> <span class="hljs-keyword">pass</span>
750750
</code></pre>
751751
<p><strong>MRO determines the order in which parent classes are traversed when searching for a method:</strong></p>
752+
752753
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>C.mro()
753-
[&lt;<span class="hljs-class"><span class="hljs-keyword">class</span> '<span class="hljs-title">C</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">A</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">B</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">object</span>'&gt;]
754-
</span></code></pre>
754+
[&lt;<span class="hljs-class"><span class="hljs-title">class</span> '<span class="hljs-title">C</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">A</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">B</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">object</span>'&gt;]</span></code>
755+
</pre>
755756
<h3 id="copy">Copy</h3>
756757
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> copy <span class="hljs-keyword">import</span> copy, deepcopy
757758
&lt;object&gt; = copy(&lt;object&gt;)

parse.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const TOC =
3030
'}\n' +
3131
'</code></pre>\n';
3232

33+
const MRO =
34+
'<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>C.mro()\n[&lt;<span class="hljs-class"><span class="hljs-title">class</span> \'<span class="hljs-title">C</span>\'&gt;, &lt;<span class="hljs-title">class</span> \'<span class="hljs-title">A</span>\'&gt;, &lt;<span class="hljs-title">class</span> \'<span class="hljs-title">B</span>\'&gt;, &lt;<span class="hljs-title">class</span> \'<span class="hljs-title">object</span>\'&gt;]</span></code>\n</pre>\n'
3335

3436
function main() {
3537
const html = getMd();
@@ -60,10 +62,7 @@ function modifyPage() {
6062
addToc();
6163
insertLinks();
6264
unindentBanner();
63-
$('code').not('.python').not('.text').not('.bash').addClass('python');
64-
$('code').each(function(index) {
65-
hljs.highlightBlock(this);
66-
});
65+
highlightCode();
6766
}
6867

6968
function removeOrigToc() {
@@ -73,6 +72,11 @@ function removeOrigToc() {
7372
contentsList.remove();
7473
}
7574

75+
function addToc() {
76+
const nodes = $.parseHTML(TOC);
77+
$('#main').before(nodes);
78+
}
79+
7680
function insertLinks() {
7781
$('h2').each(function() {
7882
const aId = $(this).attr('id');
@@ -89,10 +93,24 @@ function unindentBanner() {
8993
downloadPraragrapth.addClass('banner');
9094
}
9195

92-
function addToc() {
93-
const headerMain = $('#main');
94-
const nodes = $.parseHTML(TOC);
95-
headerMain.before(nodes);
96+
function highlightCode() {
97+
setApache('<D>')
98+
setApache('<T>')
99+
setApache('<DT>')
100+
setApache('<TD>')
101+
setApache('<a>')
102+
setApache('<n>')
103+
$('code').not('.python').not('.text').not('.bash').not('.apache').addClass('python');
104+
$('code').each(function(index) {
105+
hljs.highlightBlock(this);
106+
});
107+
$('#copy').prev().remove()
108+
const nodes = $.parseHTML(MRO);
109+
$('#copy').before(nodes);
110+
}
111+
112+
function setApache(codeContents) {
113+
$(`code:contains(${codeContents})`).addClass('apache');
96114
}
97115

98116
function readFile(filename) {

0 commit comments

Comments
 (0)