diff --git a/about.html b/about.html index 4f62e4d..ba679de 100644 --- a/about.html +++ b/about.html @@ -7,6 +7,8 @@ h1:before{content:""} + +
 

You are here: Home Dive Into Python 3 diff --git a/advanced-classes.html b/advanced-classes.html index 9de1b28..5cf84e4 100644 --- a/advanced-classes.html +++ b/advanced-classes.html @@ -8,6 +8,8 @@ body{counter-reset:h1 11} + +

  

You are here: Home Dive Into Python 3 diff --git a/advanced-iterators.html b/advanced-iterators.html index 1cd1e07..e13249d 100644 --- a/advanced-iterators.html +++ b/advanced-iterators.html @@ -8,6 +8,8 @@ body{counter-reset:h1 7} + +

  

You are here: Home Dive Into Python 3 diff --git a/case-study-porting-chardet-to-python-3.html b/case-study-porting-chardet-to-python-3.html index 8725e9d..598aa9d 100644 --- a/case-study-porting-chardet-to-python-3.html +++ b/case-study-porting-chardet-to-python-3.html @@ -11,6 +11,8 @@ ins{background:#9f9} del{background:#f87} + +

  

You are here: Home Dive Into Python 3 diff --git a/files.html b/files.html index 57567e1..24178d7 100644 --- a/files.html +++ b/files.html @@ -7,6 +7,8 @@ body{counter-reset:h1 12} + +

  

You are here: Home Dive Into Python 3 diff --git a/generators.html b/generators.html index b1275d1..86405cc 100644 --- a/generators.html +++ b/generators.html @@ -8,6 +8,8 @@ body{counter-reset:h1 5} + +

  

You are here: Home Dive Into Python 3 diff --git a/index.html b/index.html index b5eee76..a41f9e9 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,8 @@ h1:before{content:""} #b:before{content:"B. \00a0 \00a0"} + +

 
diff --git a/iterators-and-generators.html b/iterators-and-generators.html index 8c1b710..c1cf2fa 100644 --- a/iterators-and-generators.html +++ b/iterators-and-generators.html @@ -9,6 +9,8 @@ body{counter-reset:h1 -1} h1:before{counter-increment:h1;content:""} + +
  

You are here: Home Dive Into Python 3 diff --git a/iterators.html b/iterators.html index 196e3c0..e06b10e 100644 --- a/iterators.html +++ b/iterators.html @@ -8,6 +8,8 @@ body{counter-reset:h1 6} + +

  

You are here: Home Dive Into Python 3 diff --git a/native-datatypes.html b/native-datatypes.html index acaac7a..b3e6c47 100644 --- a/native-datatypes.html +++ b/native-datatypes.html @@ -8,6 +8,8 @@ body{counter-reset:h1 2} + +

  

You are here: Home Dive Into Python 3 @@ -18,7 +20,7 @@ body{counter-reset:h1 2}

 

Diving In

-

Cast aside your first Python program for just a minute, and let’s talk about datatypes. In Python, every variable has a datatype, but you don’t need to declare it explicitly. Based on each variable’s original assignment, Python figures out what type it is and keeps tracks of that internally. +

Cast aside your first Python program for just a minute, and let’s talk about datatypes. In Python, every variable has a datatype, but you don’t need to declare it explicitly. Based on each variable’s original assignment, Python figures out what type it is and keeps tracks of that internally.

Python has many native datatypes. Here are the important ones:

  1. Booleans are either True or False. diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html index a2cb1b7..68525ec 100644 --- a/porting-code-to-python-3-with-2to3.html +++ b/porting-code-to-python-3-with-2to3.html @@ -18,6 +18,8 @@ th,td,td pre{margin:0} td pre{padding:0;border:0} + +
      

    You are here: Home Dive Into Python 3 diff --git a/print.css b/print.css new file mode 100644 index 0000000..5586518 --- /dev/null +++ b/print.css @@ -0,0 +1,150 @@ +/* + +"Dive Into Python 3" print stylesheet + +Copyright (c) 2009, Mark Pilgrim, All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +/* print-specific (and some Prince-specific) rules */ + +@page { + size: US-Letter; + margin: 30pt; + padding: 0; + @bottom-center { + font: 12pt/1.75 Helvetica, 'Gill Sans', 'Gill Sans MT', Corbel, 'Nimbus Sans L', sans-serif; + content: counter(page); + } +} +pre { + page-break-inside: avoid; +} +h1 { + page-break-before: always; + prince-bookmark-level: 1; +} +h2 { + prince-bookmark-level: 2; +} +h3 { + prince-bookmark-level: 3; +} + +/* typography */ + +body, .w a { + font: 12pt/1.75 Helvetica, 'Gill Sans', 'Gill Sans MT', Corbel, 'Nimbus Sans L', sans-serif; + word-spacing: 0; +} +pre, kbd, samp, code, var, .b { + font-size: 10pt; + line-height: 2.1; +} +span { + font-size: 12pt; +} +.baa { + font-size: 13pt; +} +.q span { + font-size: 13pt; +} +.note span { + color: #000; +} +.f:first-letter { + color: #888; + font: normal 48pt/0.68 serif; +} +p { + margin: 1.75em 0; + font-size: 12pt; +} +ul, ol { + margin: 1.75em 20pt; + font-size: 12pt; +} + +/* basics */ + +html { + background: #fff; + color: #000; + margin: 0; + padding: 0; +} +body { + margin: 0; + padding: 0; +} + +/* links */ + +a { + text-decoration: none; + border-bottom: 1px dotted; +} +a:link, .w a { + color: #000; +} +a:visited { + color: #000; +} + +/* code blocks */ + +pre { + border: 0; +} +.c { + font-size: 10pt; + line-height: 2.1; +} +} +mark { + background: gainsboro; +} + +/* headers and pullquotes */ + +h1, h1 code { + font-size: 24pt; +} +h2, h2 code { + font-size: 18pt; +} +h3, h3 code { + font-size: 13pt; +} +aside { + font-size: 24pt; + background: #667; + color: white; +} + +/* overrides */ + +.w, .d { + display: none !important; +} diff --git a/publish b/publish index 39bcacc..495d9ee 100755 --- a/publish +++ b/publish @@ -1,5 +1,7 @@ #!/bin/sh +echo "started build" + # make build directory and copy original files there for preflighting rm -rf build mkdir build @@ -7,6 +9,8 @@ cp robots.txt *.js *.css build/ rm -f examples/*.pyc cp -R examples build/ +echo "minimizing HTML" + # minimize HTML (XXX this script is quite fragile and relies on knowledge of how I write HTML) for f in *.html; do python htmlminimizer.py "$f" build/"$f" @@ -24,19 +28,26 @@ sed -i -e "s|//google\.|google.|g" build/dip3.js sed -i -e "s|//}.; /\* google\..*|});|g" build/dip3.js # minimize JS and CSS +echo "minimizing JS" revision=`hg log|grep changeset|cut -d":" -f3|head -1` java -jar yuicompressor-2.4.2.jar build/dip3.js > build/$revision.js +echo "minimizing CSS" java -jar yuicompressor-2.4.2.jar build/dip3.css > build/$revision.css java -jar yuicompressor-2.4.2.jar build/mobile.css > build/m-$revision.css +java -jar yuicompressor-2.4.2.jar build/print.css > build/p-$revision.css sed -i -e "s|;}|}|g" build/$revision.css sed -i -e "s|;}|}|g" build/m-$revision.css +sed -i -e "s|;}|}|g" build/p-$revision.css # put CSS inline +echo "inlining CSS" css=`cat build/$revision.css` -mobilecss=`cat build/m-$revision.css` -#sed -i -e "s|||g" -e "s|||g" -e "s||g" -e "s| + +

      

    You are here: Home Dive Into Python 3 diff --git a/regular-expressions.html b/regular-expressions.html index c7f9f1b..1f5de1c 100644 --- a/regular-expressions.html +++ b/regular-expressions.html @@ -8,6 +8,8 @@ body{counter-reset:h1 4} + +

      

    You are here: Home Dive Into Python 3 diff --git a/special-method-names.html b/special-method-names.html index 5297c81..7f5da85 100644 --- a/special-method-names.html +++ b/special-method-names.html @@ -19,6 +19,8 @@ td pre{padding:0;border:0} td a:link, td a:visited{border:0} + +

      

    You are here: Home Dive Into Python 3 diff --git a/strings.html b/strings.html index 2176244..8720d8c 100644 --- a/strings.html +++ b/strings.html @@ -8,6 +8,8 @@ body{counter-reset:h1 3} + +

      

    You are here: Home Dive Into Python 3 diff --git a/table-of-contents.html b/table-of-contents.html index 0eddd80..03a8f52 100644 --- a/table-of-contents.html +++ b/table-of-contents.html @@ -11,6 +11,8 @@ ul{list-style:none;margin:0;padding:0} ul li ol{margin:0;padding:0 0 0 2.5em} + +

     

    You are here: Home Dive Into Python 3 diff --git a/unit-testing.html b/unit-testing.html index 0629580..7428c35 100644 --- a/unit-testing.html +++ b/unit-testing.html @@ -8,6 +8,8 @@ body{counter-reset:h1 8} + +

      

    You are here: Home Dive Into Python 3 diff --git a/util/flatten.py b/util/flatten.py index b849900..89e636e 100644 --- a/util/flatten.py +++ b/util/flatten.py @@ -3,42 +3,61 @@ # TODO: # - fix internal xrefs (look for href=.html) # - fix duplicate IDs -# - print stylesheet +import re + +# get list of chapters chapters = [] for line in open('index.html'): if not line.count('', 1)[0]) +# construct regexes used to fix internal xrefs +chapter_href = re.compile("".format("|".join(chapters))) +chapter_fragment_href = re.compile("".format("|".join(chapters))) +same_chapter_fragment_href = re.compile("]") + +# munge and combine chapter-specific styles out = open('build/single.html', 'w', encoding="utf-8") out.write(open('util/single-header.html', encoding="utf-8").read()) out.write("'): include = False if include and not line.count('counter-reset'): - line = "#{0} {1}".format(id, line) - line = line.replace(",", ", #{0} ".format(id)) + line = "#{0} {1}".format(chapter_id, line) + line = line.replace(",", ", #{0} ".format(chapter_id)) out.write(line) if line.count('\n") out.write(open('util/single-header2.html', encoding="utf-8").read()) +# munge and combine chapters for filename in chapters: include = False - id = "chapter-" + filename.split(".", 1)[0] - out.write("

    \n".format(id)) + id_prefix = filename.split(".", 1)[0] + chapter_id = "chapter-" + id_prefix + out.write("\n") diff --git a/util/single-header.html b/util/single-header.html index 1464658..e5daf68 100644 --- a/util/single-header.html +++ b/util/single-header.html @@ -3,6 +3,9 @@ Dive into Python 3 + + + + +
      

    You are here: Home Dive Into Python 3 diff --git a/xml.html b/xml.html index ba8bad9..818515c 100644 --- a/xml.html +++ b/xml.html @@ -9,6 +9,8 @@ body{counter-reset:h1 13} mark{display:inline} + +

      

    You are here: Home Dive Into Python 3 diff --git a/your-first-python-program.html b/your-first-python-program.html index 1e9cc34..b01c505 100644 --- a/your-first-python-program.html +++ b/your-first-python-program.html @@ -11,6 +11,8 @@ td,th{border:1px solid #bbb;padding:0 1.75em} th{text-align:left} + +

      

    You are here: Home Dive Into Python 3