Hi,

I find some problems when I run webpy on windows box, and the doctest
of web/utils.py failed:
1. directive %e of strftime is not available on windows.[1]
2. the file tempfile.NamedTemporaryFile returned cannot be opened
again.[2]


[1] http://docs.python.org/library/datetime.html#module-datetime
[2] http://docs.python.org/library/tempfile.html

I hope it's useful.
PS. my patch is based on official release 0.31


diff -urNd web.orig\http.py web\http.py
--- web.orig\http.py    Wed Dec 10 20:07:06 2008
+++ web\http.py Tue Dec 16 18:38:09 2008
@@ -130,7 +130,7 @@
     from utils import profile
     def profile_internal(e, o):
         out, result = profile(app)(e, o)
-        return out + ['<pre>' + net.websafe(result) + '</pre>']
+        return out + '<pre>' + net.websafe(result) + '</pre>'
     return profile_internal

 if __name__ == "__main__":
diff -urNd web.orig\utils.py web\utils.py
--- web.orig\utils.py   Wed Dec 10 20:07:06 2008
+++ web\utils.py        Tue Dec 16 18:43:03 2008
@@ -572,7 +572,7 @@
         if abs(deltadays) < 4:
             return agohence(deltadays, 'day')

-        out = then.strftime('%B %e') # e.g. 'June 13'
+        out = then.strftime('%B ') + '%2d' % then.day # e.g. 'June
13'
         if then.year != now.year or deltadays < 0:
             out += ', %s' % then.year
         return out
@@ -731,28 +731,35 @@
     def __init__(self, func):
         self.func = func
     def __call__(self, *args): ##, **kw):   kw unused
-        import hotshot, hotshot.stats, tempfile ##, time already
imported
-        temp = tempfile.NamedTemporaryFile()
-        prof = hotshot.Profile(temp.name)
+        import hotshot, hotshot.stats, tempfile, os ##, time already
imported
+        fd, name = tempfile.mkstemp()
+        os.close(fd)
+        try:
+            prof = hotshot.Profile(name)

-        stime = time.time()
-        result = prof.runcall(self.func, *args)
-        stime = time.time() - stime
-        prof.close()
+            stime = time.time()
+            result = prof.runcall(self.func, *args)
+            stime = time.time() - stime
+            prof.close()

-        import cStringIO
-        out = cStringIO.StringIO()
-        stats = hotshot.stats.load(temp.name)
-        stats.stream = out
-        stats.strip_dirs()
-        stats.sort_stats('time', 'calls')
-        stats.print_stats(40)
-        stats.print_callers()
+            import cStringIO
+            out = cStringIO.StringIO()
+            stats = hotshot.stats.load(name)
+            stats.stream = out
+            stats.strip_dirs()
+            stats.sort_stats('time', 'calls')
+            stats.print_stats(40)
+            stats.print_callers()

-        x =  '\n\ntook '+ str(stime) + ' seconds\n'
-        x += out.getvalue()
+            x =  '\n\ntook '+ str(stime) + ' seconds\n'
+            x += out.getvalue()

-        return result, x
+            return result, x
+        finally:
+            try:
+                os.unlink(name)
+            except:
+                pass

 profile = Profile

@@ -1006,6 +1013,7 @@
             p.stdin.close()
             p.wait()
         else:
+            import os
             i, o = os.popen2(["/usr/lib/sendmail", '-f',
from_address] + recipients)
             i.write(message)
             i.close()

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to