diff options
Diffstat (limited to 'Doc/includes')
| -rw-r--r-- | Doc/includes/email-alternative.py | 2 | ||||
| -rw-r--r-- | Doc/includes/email-dir.py | 2 | ||||
| -rw-r--r-- | Doc/includes/email-headers.py | 17 | ||||
| -rw-r--r-- | Doc/includes/email-mime.py | 2 | ||||
| -rw-r--r-- | Doc/includes/email-simple.py | 5 | ||||
| -rw-r--r-- | Doc/includes/email-unpack.py | 2 | ||||
| -rw-r--r-- | Doc/includes/minidom-example.py | 6 | ||||
| -rw-r--r-- | Doc/includes/sqlite3/load_extension.py | 26 | ||||
| -rw-r--r-- | Doc/includes/turtle-star.py | 10 |
9 files changed, 62 insertions, 10 deletions
diff --git a/Doc/includes/email-alternative.py b/Doc/includes/email-alternative.py index 82e3ffa..33c430a 100644 --- a/Doc/includes/email-alternative.py +++ b/Doc/includes/email-alternative.py @@ -1,4 +1,4 @@ -#! /usr/bin/python +#!/usr/bin/env python3 import smtplib diff --git a/Doc/includes/email-dir.py b/Doc/includes/email-dir.py index e67de61..b1b45b8 100644 --- a/Doc/includes/email-dir.py +++ b/Doc/includes/email-dir.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """Send the contents of a directory as a MIME message.""" diff --git a/Doc/includes/email-headers.py b/Doc/includes/email-headers.py new file mode 100644 index 0000000..a53317d --- /dev/null +++ b/Doc/includes/email-headers.py @@ -0,0 +1,17 @@ +# Import the email modules we'll need +from email.parser import Parser + +# If the e-mail headers are in a file, uncomment this line: +#headers = Parser().parse(open(messagefile, 'r')) + +# Or for parsing headers in a string, use: +headers = Parser().parsestr('From: <user@example.com>\n' + 'To: <someone_else@example.com>\n' + 'Subject: Test message\n' + '\n' + 'Body would go here\n') + +# Now the header items can be accessed as a dictionary: +print('To: %s' % headers['to']) +print('From: %s' % headers['from']) +print('Subject: %s' % headers['subject']) diff --git a/Doc/includes/email-mime.py b/Doc/includes/email-mime.py index f64df83..ec7e371 100644 --- a/Doc/includes/email-mime.py +++ b/Doc/includes/email-mime.py @@ -27,5 +27,5 @@ for file in pngfiles: # Send the email via our own SMTP server. s = smtplib.SMTP() -s.sendmail(me, family, msg.as_string()) +s.send_message(msg) s.quit() diff --git a/Doc/includes/email-simple.py b/Doc/includes/email-simple.py index 689511e..b069ab0 100644 --- a/Doc/includes/email-simple.py +++ b/Doc/includes/email-simple.py @@ -17,8 +17,7 @@ msg['Subject'] = 'The contents of %s' % textfile msg['From'] = me msg['To'] = you -# Send the message via our own SMTP server, but don't include the -# envelope header. +# Send the message via our own SMTP server. s = smtplib.SMTP() -s.sendmail(me, [you], msg.as_string()) +s.sendmail(msg) s.quit() diff --git a/Doc/includes/email-unpack.py b/Doc/includes/email-unpack.py index a8f712d..3653543 100644 --- a/Doc/includes/email-unpack.py +++ b/Doc/includes/email-unpack.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """Unpack a MIME message into a directory of files.""" diff --git a/Doc/includes/minidom-example.py b/Doc/includes/minidom-example.py index 88048c0..5ee7682 100644 --- a/Doc/includes/minidom-example.py +++ b/Doc/includes/minidom-example.py @@ -19,11 +19,11 @@ document = """\ dom = xml.dom.minidom.parseString(document) def getText(nodelist): - rc = "" + rc = [] for node in nodelist: if node.nodeType == node.TEXT_NODE: - rc = rc + node.data - return rc + rc.append(node.data) + return ''.join(rc) def handleSlideshow(slideshow): print("<html>") diff --git a/Doc/includes/sqlite3/load_extension.py b/Doc/includes/sqlite3/load_extension.py new file mode 100644 index 0000000..015aa0d --- /dev/null +++ b/Doc/includes/sqlite3/load_extension.py @@ -0,0 +1,26 @@ +import sqlite3 + +con = sqlite3.connect(":memory:") + +# enable extension loading +con.enable_load_extension(True) + +# Load the fulltext search extension +con.execute("select load_extension('./fts3.so')") + +# alternatively you can load the extension using an API call: +# con.load_extension("./fts3.so") + +# disable extension laoding again +con.enable_load_extension(False) + +# example from SQLite wiki +con.execute("create virtual table recipe using fts3(name, ingredients)") +con.executescript(""" + insert into recipe (name, ingredients) values ('broccoli stew', 'broccoli peppers cheese tomatoes'); + insert into recipe (name, ingredients) values ('pumpkin stew', 'pumpkin onions garlic celery'); + insert into recipe (name, ingredients) values ('broccoli pie', 'broccoli cheese onions flour'); + insert into recipe (name, ingredients) values ('pumpkin pie', 'pumpkin sugar flour butter'); + """) +for row in con.execute("select rowid, name, ingredients from recipe where name match 'pie'"): + print(row) diff --git a/Doc/includes/turtle-star.py b/Doc/includes/turtle-star.py new file mode 100644 index 0000000..1a5db76 --- /dev/null +++ b/Doc/includes/turtle-star.py @@ -0,0 +1,10 @@ +from turtle import * +color('red', 'yellow') +begin_fill() +while True: + forward(200) + left(170) + if abs(pos()) < 1: + break +end_fill() +done() |
