changeset 376:32b9137577b8

avoiding 'str doesn't support the buffer api' exception
author cat@eee
date Sun, 21 Feb 2010 15:25:22 -0500
parents 6cc12ad6e616
children 70ca35d96c49
files cmd2.py docs/pycon2010/pirate6.py docs/pycon2010/pycon2010.rst
diffstat 3 files changed, 34 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Sat Feb 20 09:26:33 2010 -0500
+++ b/cmd2.py	Sun Feb 21 15:25:22 2010 -0500
@@ -1438,7 +1438,10 @@
         self.trap.seek(0)
         result = self.trap.read()
         self.trap.truncate(0)
-        return result.strip('\x00')        
+        try:
+            return result.strip('\x00') #TODO: understand this
+        except TypeError:
+            return result
     def tearDown(self):
         sys.stdout = self.old_stdout
 
--- a/docs/pycon2010/pirate6.py	Sat Feb 20 09:26:33 2010 -0500
+++ b/docs/pycon2010/pirate6.py	Sun Feb 21 15:25:22 2010 -0500
@@ -1,4 +1,4 @@
-from cmd import Cmd
+from cmd2 import Cmd
 # prompts and defaults
 
 class Pirate(Cmd):
--- a/docs/pycon2010/pycon2010.rst	Sat Feb 20 09:26:33 2010 -0500
+++ b/docs/pycon2010/pycon2010.rst	Sun Feb 21 15:25:22 2010 -0500
@@ -327,6 +327,35 @@
 
    Now ``cmd2``-based; postgreSQL; MySQL
 
+File reporter
+=============
+
+.. class:: huge
+
+   Gather info: Python
+
+   Store: postgresql
+
+   Report: html
+
+fileutil.py
+===========
+
+::
+
+    import glob
+    import os.path
+
+    for fullfilename in glob.glob('/home/cat/proj/cmd2/*.py'):
+        (dirpath, fname) = os.path.split(fullfilename)
+        stats = os.stat(fullfilename)
+        binds['path'] = dirpath
+        binds['name'] = fname
+        binds['bytes'] = stats.st_size
+        cmd("""INSERT INTO cat.files (path, name, bytes)
+               VALUES (%(path)s, %(name)s, %(bytes)s)""")
+    quit()
+
 sqlpython features
 ==================
 
@@ -338,16 +367,6 @@
    * UNIX: ls, cat, grep
    * Special output
 
-File reporter
-=============
-
-.. class:: huge
-
-   Gather info: Python
-
-   Store: postgresql
-
-   Report: html
 
 Thank you
 =========