Browse Source

Small fixes

pull/46/head
Jure Šorn 5 years ago
parent
commit
5a48992cb0
4 changed files with 95 additions and 68 deletions
  1. 50
      README.md
  2. 64
      index.html
  3. 34
      parse.js
  4. 15
      web/script_2.js

50
README.md

@ -401,40 +401,40 @@ Format
### General Options
```python
{<el>:<10} # '<el> '
{<el>:^10} # ' <el> '
{<el>:>10} # ' <el>'
{<el>:<10} # '<el> '
{<el>:^10} # ' <el> '
{<el>:>10} # ' <el>'
```
```python
{<el>:.<10} # '<el>......'
{<el>:<0} # '<el>'
{<el>:.<10} # '<el>......'
{<el>:<0} # '<el>'
```
### Strings
**`'!r'` calls object's repr() method, instead of str(), to get a string.**
```python
{'abcde'!r:<10} # "'abcde' "
{'abcde':.3} # 'abc'
{'abcde':10.3} # 'abc '
{'abcde'!r:<10} # "'abcde' "
{'abcde':.3} # 'abc'
{'abcde':10.3} # 'abc '
```
### Numbers
```python
{ 123456:10,} # ' 123,456'
{ 123456:10_} # ' 123_456'
{ 123456:+10} # ' +123456'
{-123456:=10} # '- 123456'
{ 123456: } # ' 123456'
{-123456: } # '-123456'
{ 123456:10,} # ' 123,456'
{ 123456:10_} # ' 123_456'
{ 123456:+10} # ' +123456'
{-123456:=10} # '- 123456'
{ 123456: } # ' 123456'
{-123456: } # '-123456'
```
### Floats
```python
{1.23456:10.3} # ' 1.23'
{1.23456:10.3f} # ' 1.235'
{1.23456:10.3e} # ' 1.235e+00'
{1.23456:10.3%} # ' 123.456%'
{1.23456:10.3} # ' 1.23'
{1.23456:10.3f} # ' 1.235'
{1.23456:10.3e} # ' 1.235e+00'
{1.23456:10.3%} # ' 123.456%'
```
#### Comparison of float presentation types:
@ -469,9 +469,9 @@ Format
### Ints
```python
{90:c} # 'Z'
{90:X} # '5A'
{90:b} # '1011010'
{90:c} # 'Z'
{90:X} # '5A'
{90:b} # '1011010'
```
@ -1499,7 +1499,7 @@ Open
<file> = open('<path>', mode='r', encoding=None, newline=None)
```
* **`'encoding=None'` means default encoding is used, which is platform dependent. Best practice is to use `'encoding="utf-8"'` whenever possible.**
* **`'newline=None'` means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to the system's default line separator.**
* **`'newline=None'` means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.**
* **`'newline=""'` means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.**
### Modes
@ -1800,13 +1800,13 @@ SQLite
**Server-less database engine that stores each database into separate file.**
### Connect
**Opens a connection to the database file. Creates a new file if path doesn't exist.**
```python
import sqlite3
db = sqlite3.connect('<path>') # Also ':memory:'.
...
db.close()
```
* **New database will be created if path doesn't exist.**
### Read
**Returned values can be of type str, int, float, bytes or None.**
@ -1963,12 +1963,12 @@ Memory View
<mview> = memoryview(<bytes/bytearray/array>)
<num> = <mview>[<index>] # Returns an int or a float.
<mview> = <mview>[<slice>] # Mview with rearranged elements.
<mview> = <mview>.cast('<typecode>') # Casts a memoryview to a new format.
<mview> = <mview>.cast('<typecode>') # Casts memoryview to the new format.
<mview>.release() # Releases the object's memory buffer.
```
```python
<bin_file>.write(<mview>) # Writes mview to a binary file.
<bin_file>.write(<mview>) # Appends mview to the binary file.
<bytes> = bytes(<mview>) # Creates a new bytes object.
<bytes> = <bytes>.join(<coll_of_mviews>) # Joins mviews using bytes object as sep.
<list> = list(<mview>) # Returns list of ints or floats.

64
index.html

@ -496,32 +496,32 @@ to_exclusive = &lt;range&gt;.stop
<span class="hljs-string">'187'</span>
</code></pre></div>
<div><h3 id="generaloptions">General Options</h3><pre><code class="python language-python hljs">{&lt;el&gt;:&lt;<span class="hljs-number">10</span>} <span class="hljs-comment"># '&lt;el&gt; '</span>
{&lt;el&gt;:^<span class="hljs-number">10</span>} <span class="hljs-comment"># ' &lt;el&gt; '</span>
{&lt;el&gt;:&gt;<span class="hljs-number">10</span>} <span class="hljs-comment"># ' &lt;el&gt;'</span>
<div><h3 id="generaloptions">General Options</h3><pre><code class="python language-python hljs">{&lt;el&gt;:&lt;<span class="hljs-number">10</span>} <span class="hljs-comment"># '&lt;el&gt; '</span>
{&lt;el&gt;:^<span class="hljs-number">10</span>} <span class="hljs-comment"># ' &lt;el&gt; '</span>
{&lt;el&gt;:&gt;<span class="hljs-number">10</span>} <span class="hljs-comment"># ' &lt;el&gt;'</span>
</code></pre></div>
<pre><code class="python language-python hljs">{&lt;el&gt;:.&lt;<span class="hljs-number">10</span>} <span class="hljs-comment"># '&lt;el&gt;......'</span>
{&lt;el&gt;:&lt;<span class="hljs-number">0</span>} <span class="hljs-comment"># '&lt;el&gt;'</span>
<pre><code class="python language-python hljs">{&lt;el&gt;:.&lt;<span class="hljs-number">10</span>} <span class="hljs-comment"># '&lt;el&gt;......'</span>
{&lt;el&gt;:&lt;<span class="hljs-number">0</span>} <span class="hljs-comment"># '&lt;el&gt;'</span>
</code></pre>
<div><h3 id="strings">Strings</h3><p><strong><code class="python hljs"><span class="hljs-string">'!r'</span></code> calls object's repr() method, instead of str(), to get a string.</strong></p><pre><code class="python language-python hljs">{<span class="hljs-string">'abcde'</span>!r:&lt;<span class="hljs-number">10</span>} <span class="hljs-comment"># "'abcde' "</span>
{<span class="hljs-string">'abcde'</span>:<span class="hljs-number">.3</span>} <span class="hljs-comment"># 'abc'</span>
{<span class="hljs-string">'abcde'</span>:<span class="hljs-number">10.3</span>} <span class="hljs-comment"># 'abc '</span>
<div><h3 id="strings">Strings</h3><p><strong><code class="python hljs"><span class="hljs-string">'!r'</span></code> calls object's repr() method, instead of str(), to get a string.</strong></p><pre><code class="python language-python hljs">{<span class="hljs-string">'abcde'</span>!r:&lt;<span class="hljs-number">10</span>} <span class="hljs-comment"># "'abcde' "</span>
{<span class="hljs-string">'abcde'</span>:<span class="hljs-number">.3</span>} <span class="hljs-comment"># 'abc'</span>
{<span class="hljs-string">'abcde'</span>:<span class="hljs-number">10.3</span>} <span class="hljs-comment"># 'abc '</span>
</code></pre></div>
<div><h3 id="numbers-1">Numbers</h3><pre><code class="python language-python hljs">{ <span class="hljs-number">123456</span>:<span class="hljs-number">10</span>,} <span class="hljs-comment"># ' 123,456'</span>
{ <span class="hljs-number">123456</span>:<span class="hljs-number">10</span>_} <span class="hljs-comment"># ' 123_456'</span>
{ <span class="hljs-number">123456</span>:+<span class="hljs-number">10</span>} <span class="hljs-comment"># ' +123456'</span>
{<span class="hljs-number">-123456</span>:=<span class="hljs-number">10</span>} <span class="hljs-comment"># '- 123456'</span>
{ <span class="hljs-number">123456</span>: } <span class="hljs-comment"># ' 123456'</span>
{<span class="hljs-number">-123456</span>: } <span class="hljs-comment"># '-123456'</span>
<div><h3 id="numbers-1">Numbers</h3><pre><code class="python language-python hljs">{ <span class="hljs-number">123456</span>:<span class="hljs-number">10</span>,} <span class="hljs-comment"># ' 123,456'</span>
{ <span class="hljs-number">123456</span>:<span class="hljs-number">10</span>_} <span class="hljs-comment"># ' 123_456'</span>
{ <span class="hljs-number">123456</span>:+<span class="hljs-number">10</span>} <span class="hljs-comment"># ' +123456'</span>
{<span class="hljs-number">-123456</span>:=<span class="hljs-number">10</span>} <span class="hljs-comment"># '- 123456'</span>
{ <span class="hljs-number">123456</span>: } <span class="hljs-comment"># ' 123456'</span>
{<span class="hljs-number">-123456</span>: } <span class="hljs-comment"># '-123456'</span>
</code></pre></div>
<div><h3 id="floats">Floats</h3><pre><code class="python language-python hljs">{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>} <span class="hljs-comment"># ' 1.23'</span>
{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>f} <span class="hljs-comment"># ' 1.235'</span>
{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>e} <span class="hljs-comment"># ' 1.235e+00'</span>
{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>%} <span class="hljs-comment"># ' 123.456%'</span>
<div><h3 id="floats">Floats</h3><pre><code class="python language-python hljs">{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>} <span class="hljs-comment"># ' 1.23'</span>
{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>f} <span class="hljs-comment"># ' 1.235'</span>
{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>e} <span class="hljs-comment"># ' 1.235e+00'</span>
{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>%} <span class="hljs-comment"># ' 123.456%'</span>
</code></pre></div>
<div><h4 id="comparisonoffloatpresentationtypes">Comparison of float presentation types:</h4><pre><code class="text language-text">+----------------+----------------+---------------+----------------+-----------------+
@ -551,9 +551,9 @@ to_exclusive = &lt;range&gt;.stop
| 567.89 | '5.7e+02' | '567.89' | '5.68e+02' | '56789.00%' |
+----------------+----------------+---------------+----------------+-----------------+
</code></pre>
<div><h3 id="ints">Ints</h3><pre><code class="python language-python hljs">{<span class="hljs-number">90</span>:c} <span class="hljs-comment"># 'Z'</span>
{<span class="hljs-number">90</span>:X} <span class="hljs-comment"># '5A'</span>
{<span class="hljs-number">90</span>:b} <span class="hljs-comment"># '1011010'</span>
<div><h3 id="ints">Ints</h3><pre><code class="python language-python hljs">{<span class="hljs-number">90</span>:c} <span class="hljs-comment"># 'Z'</span>
{<span class="hljs-number">90</span>:X} <span class="hljs-comment"># '5A'</span>
{<span class="hljs-number">90</span>:b} <span class="hljs-comment"># '1011010'</span>
</code></pre></div>
<div><h2 id="numbers"><a href="#numbers" name="numbers">#</a>Numbers</h2><div><h3 id="types">Types</h3><pre><code class="python language-python hljs">&lt;int&gt; = int(&lt;float/str/bool&gt;) <span class="hljs-comment"># Or: math.floor(&lt;float&gt;)</span>
@ -1337,7 +1337,7 @@ LogicOp = Enum(<span class="hljs-string">'LogicOp'</span>, {<span class="hljs-st
<span class="hljs-keyword">pass</span>
</code></pre></div>
<div><h2 id="print"><a href="#print" name="print">#</a>Print</h2><pre><code class="python language-python hljs">print(&lt;el_1&gt;, ..., sep=<span class="hljs-string">' '</span>, end=<span class="hljs-string">'\n'</span>, file=sys.stdout, flush=<span class="hljs-keyword">False</span>)
<div class="pagebreak"></div><div><h2 id="print"><a href="#print" name="print">#</a>Print</h2><pre><code class="python language-python hljs">print(&lt;el_1&gt;, ..., sep=<span class="hljs-string">' '</span>, end=<span class="hljs-string">'\n'</span>, file=sys.stdout, flush=<span class="hljs-keyword">False</span>)
</code></pre></div>
<ul>
@ -1387,7 +1387,7 @@ value = args.&lt;name&gt;
<ul>
<li><strong><code class="python hljs"><span class="hljs-string">'encoding=None'</span></code> means default encoding is used, which is platform dependent. Best practice is to use <code class="python hljs"><span class="hljs-string">'encoding="utf-8"'</span></code> whenever possible.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'newline=None'</span></code> means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to the system's default line separator.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'newline=None'</span></code> means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'newline=""'</span></code> means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.</strong></li>
</ul>
<div><h3 id="modes">Modes</h3><ul>
@ -1605,7 +1605,7 @@ shutil.copytree(from, to) <span class="hljs-comment"># Copies the enti
writer.writerows(rows)
</code></pre></div>
<div><h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2><p><strong>Server-less database engine that stores each database into separate file.</strong></p><div><h3 id="connect">Connect</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3
<div><h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2><p><strong>Server-less database engine that stores each database into separate file.</strong></p><div><h3 id="connect">Connect</h3><p><strong>Opens a connection to the database file. Creates a new file if path doesn't exist.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3
db = sqlite3.connect(<span class="hljs-string">'&lt;path&gt;'</span>) <span class="hljs-comment"># Also ':memory:'.</span>
...
db.close()
@ -1613,9 +1613,7 @@ db.close()
<ul>
<li><strong>New database will be created if path doesn't exist.</strong></li>
</ul>
<div><h3 id="read-1">Read</h3><p><strong>Returned values can be of type str, int, float, bytes or None.</strong></p><pre><code class="python language-python hljs">&lt;cursor&gt; = db.execute(<span class="hljs-string">'&lt;query&gt;'</span>) <span class="hljs-comment"># Can raise sqlite3.OperationalError.</span>
&lt;tuple&gt; = &lt;cursor&gt;.fetchone() <span class="hljs-comment"># Returns next row. Also next(&lt;cursor&gt;).</span>
&lt;list&gt; = &lt;cursor&gt;.fetchall() <span class="hljs-comment"># Returns remaining rows.</span>
@ -1702,21 +1700,21 @@ db = connector.connect(host=&lt;str&gt;, user=&lt;str&gt;, password=&lt;str&gt;,
(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)
</code></pre></div>
<div><h3 id="format-2">Format</h3><div><h4 id="forstandardsizesstartformatstringwith">For standard sizes start format string with:</h4><ul>
<div><h3 id="format-2">Format</h3></div><div><h4 id="forstandardsizesstartformatstringwith">For standard sizes start format string with:</h4><ul>
<li><strong><code class="python hljs"><span class="hljs-string">'='</span></code> - native byte order</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'&lt;'</span></code> - little-endian</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'&gt;'</span></code> - big-endian</strong></li>
</ul><div><h4 id="integertypesusecapitalletterforunsignedtypestandardsizesareinbrackets">Integer types. Use capital letter for unsigned type. Standard sizes are in brackets:</h4><ul>
</ul></div><div><h4 id="integertypesusecapitalletterforunsignedtypestandardsizesareinbrackets">Integer types. Use capital letter for unsigned type. Standard sizes are in brackets:</h4><ul>
<li><strong><code class="python hljs"><span class="hljs-string">'x'</span></code> - pad byte</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'b'</span></code> - char (1)</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'h'</span></code> - short (2)</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'i'</span></code> - int (4)</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'l'</span></code> - long (4)</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'q'</span></code> - long long (8)</strong></li>
</ul><div><h4 id="floatingpointtypes">Floating point types:</h4><ul>
</ul></div><div><h4 id="floatingpointtypes">Floating point types:</h4><ul>
<li><strong><code class="python hljs"><span class="hljs-string">'f'</span></code> - float (4)</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'d'</span></code> - double (8)</strong></li>
</ul></div></div></div></div>
</ul></div>
@ -1737,12 +1735,12 @@ db = connector.connect(host=&lt;str&gt;, user=&lt;str&gt;, password=&lt;str&gt;,
</ul><pre><code class="python language-python hljs">&lt;mview&gt; = memoryview(&lt;bytes/bytearray/array&gt;)
&lt;num&gt; = &lt;mview&gt;[&lt;index&gt;] <span class="hljs-comment"># Returns an int or a float.</span>
&lt;mview&gt; = &lt;mview&gt;[&lt;slice&gt;] <span class="hljs-comment"># Mview with rearranged elements.</span>
&lt;mview&gt; = &lt;mview&gt;.cast(<span class="hljs-string">'&lt;typecode&gt;'</span>) <span class="hljs-comment"># Casts a memoryview to a new format.</span>
&lt;mview&gt; = &lt;mview&gt;.cast(<span class="hljs-string">'&lt;typecode&gt;'</span>) <span class="hljs-comment"># Casts memoryview to the new format.</span>
&lt;mview&gt;.release() <span class="hljs-comment"># Releases the object's memory buffer.</span>
</code></pre></div>
<pre><code class="python language-python hljs">&lt;bin_file&gt;.write(&lt;mview&gt;) <span class="hljs-comment"># Writes mview to a binary file.</span>
<pre><code class="python language-python hljs">&lt;bin_file&gt;.write(&lt;mview&gt;) <span class="hljs-comment"># Appends mview to the binary file.</span>
&lt;bytes&gt; = bytes(&lt;mview&gt;) <span class="hljs-comment"># Creates a new bytes object.</span>
&lt;bytes&gt; = &lt;bytes&gt;.join(&lt;coll_of_mviews&gt;) <span class="hljs-comment"># Joins mviews using bytes object as sep.</span>
&lt;list&gt; = list(&lt;mview&gt;) <span class="hljs-comment"># Returns list of ints or floats.</span>

34
parse.js

@ -309,8 +309,9 @@ function highlightCode() {
fixClasses();
fixHighlights();
preventPageBreaks();
fixPageBreaks();
// insertPageBreak();
fixPageBreaksFile();
fixPageBreaksStruct();
insertPageBreaks();
}
function setApaches(elements) {
@ -346,16 +347,31 @@ function preventPageBreaks() {
});
}
function fixPageBreaks() {
const fileDiv = $('#file').parent()
function fixPageBreaksFile() {
const modesDiv = $('#file').parent().parent().parent()
modesDiv.after(fileDiv)
const exceptDiv = $('#exceptions-1').parent()
modesDiv.after(exceptDiv)
move(modesDiv, 'file')
move(modesDiv, 'exceptions-1')
}
function insertPageBreak() {
$('<div class="pagebreak"></div>').insertBefore($('#libraries').parent())
function fixPageBreaksStruct() {
const formatDiv = $('#floatingpointtypes').parent().parent().parent().parent()
move(formatDiv, 'floatingpointtypes')
move(formatDiv, 'integertypesusecapitalletterforunsignedtypestandardsizesareinbrackets')
move(formatDiv, 'forstandardsizesstartformatstringwith')
}
function move(anchor_el, el_id) {
const el = $('#'+el_id).parent()
anchor_el.after(el)
}
function insertPageBreaks() {
// insertPageBreakBefore('#libraries')
insertPageBreakBefore('#print')
}
function insertPageBreakBefore(an_id) {
$('<div class="pagebreak"></div>').insertBefore($(an_id).parent())
}
function readFile(filename) {

15
web/script_2.js

@ -118,6 +118,19 @@ const DIAGRAM_7_B =
'┃ count() │ │ │ │ ✓ ┃\n' +
'┗━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n';
const DIAGRAM_7_C =
'┏━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━┓\n' +
'┃ │ Iterable │ Collection │ Sequence │ abc.Sequence ┃\n' +
'┠────────────┼────────────┼────────────┼────────────┼──────────────┨\n' +
'┃ iter() │ ! │ ! │ ✓ │ ✓ ┃\n' +
'┃ contains() │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
'┃ len() │ │ ! │ ! │ ! ┃\n' +
'┃ getitem() │ │ │ ! │ ! ┃\n' +
'┃ reversed() │ │ │ ✓ │ ✓ ┃\n' +
'┃ index() │ │ │ │ ✓ ┃\n' +
'┃ count() │ │ │ │ ✓ ┃\n' +
'┗━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n';
const DIAGRAM_8_A =
'BaseException\n' +
' +-- SystemExit';
@ -203,7 +216,7 @@ if (isFontAvailable('Menlo')) {
$(`code:contains(${DIAGRAM_4_A})`).html(DIAGRAM_4_B);
$(`code:contains(${DIAGRAM_5_A})`).html(DIAGRAM_5_B);
$(`code:contains(${DIAGRAM_6_A})`).html(DIAGRAM_6_B);
$(`code:contains(${DIAGRAM_7_A})`).html(DIAGRAM_7_B);
$(`code:contains(${DIAGRAM_7_A})`).html(DIAGRAM_7_C);
$(`code:contains(${DIAGRAM_8_A})`).html(DIAGRAM_8_B);
$(`code:contains(${DIAGRAM_9_A})`).html(DIAGRAM_9_B);
$(`code:contains(${DIAGRAM_10_A})`).html(DIAGRAM_10_B);

Loading…
Cancel
Save