--- a/common/migration.py Wed Sep 09 15:58:02 2009 +0200
+++ b/common/migration.py Wed Sep 09 18:00:18 2009 +0200
@@ -338,7 +338,7 @@
configfile = self.config.main_config_file()
if self._option_changes:
read_old_config(self.config, self._option_changes, configfile)
- _, newconfig = tempfile.mkstemp()
+ fd, newconfig = tempfile.mkstemp()
for optdescr in self._option_changes:
if optdescr[0] == 'added':
optdict = self.config.get_option_def(optdescr[1])
@@ -346,6 +346,7 @@
self.config.input_option(optdescr[1], optdict)
self.config.generate_config(open(newconfig, 'w'))
show_diffs(configfile, newconfig)
+ os.close(fd)
if exists(newconfig):
os.unlink(newconfig)
--- a/common/test/unittest_mail.py Wed Sep 09 15:58:02 2009 +0200
+++ b/common/test/unittest_mail.py Wed Sep 09 18:00:18 2009 +0200
@@ -8,7 +8,7 @@
"""
import os
-import pwd
+import sys
from logilab.common.testlib import unittest_main
from logilab.common.umessage import message_from_string
@@ -22,7 +22,11 @@
(man 3 getlogin)
Another solution would be to use $LOGNAME, $USER or $USERNAME
"""
- return pwd.getpwuid(os.getuid())[0]
+ if sys.platform != 'win32':
+ import pwd
+ return pwd.getpwuid(os.getuid())[0]
+ else:
+ return os.environ.get('USERNAME')
class EmailTC(EnvBasedTC):
--- a/devtools/__init__.py Wed Sep 09 15:58:02 2009 +0200
+++ b/devtools/__init__.py Wed Sep 09 18:00:18 2009 +0200
@@ -130,7 +130,7 @@
self.set_option('sender-addr', 'cubicweb-test@logilab.fr')
try:
send_to = '%s@logilab.fr' % os.getlogin()
- except OSError:
+ except (OSError, AttributeError):
send_to = '%s@logilab.fr' % (os.environ.get('USER')
or os.environ.get('USERNAME')
or os.environ.get('LOGNAME'))
--- a/devtools/htmlparser.py Wed Sep 09 15:58:02 2009 +0200
+++ b/devtools/htmlparser.py Wed Sep 09 18:00:18 2009 +0200
@@ -36,7 +36,11 @@
class DTDValidator(Validator):
def __init__(self):
Validator.__init__(self)
- self.parser = etree.XMLParser(dtd_validation=True)
+ # XXX understand what's happening under windows
+ validate = True
+ if sys.platform == 'win32':
+ validate = False
+ self.parser = etree.XMLParser(dtd_validation=validate)
def preprocess_data(self, data):
"""used to fix potential blockquote mess generated by docutils"""
--- a/ext/xhtml2fo.py Wed Sep 09 15:58:02 2009 +0200
+++ b/ext/xhtml2fo.py Wed Sep 09 18:00:18 2009 +0200
@@ -1,6 +1,3 @@
-from cubicweb.utils import can_do_pdf_conversion
-assert can_do_pdf_conversion()
-
from xml.etree.ElementTree import QName, fromstring
from pysixt.standard.xhtml_xslfo.transformer import XHTML2FOTransformer
from pysixt.utils.xslfo.standard import cm
--- a/md5crypt.py Wed Sep 09 15:58:02 2009 +0200
+++ b/md5crypt.py Wed Sep 09 18:00:18 2009 +0200
@@ -1,10 +1,8 @@
#########################################################
"""
-
+XXX clarify this header
:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
# md5crypt.py
#
@@ -58,8 +56,9 @@
v = v >> 6
return ret
-
def crypt(pw, salt, magic=None):
+ if isinstance(pw, unicode):
+ pw = pw.encode('utf-8')
if magic is None:
magic = MAGIC
# Take care of the magic string if present
--- a/server/serverctl.py Wed Sep 09 15:58:02 2009 +0200
+++ b/server/serverctl.py Wed Sep 09 18:00:18 2009 +0200
@@ -677,7 +677,8 @@
import tempfile
srcappid = pop_arg(args, 1, msg='No source instance specified !')
destappid = pop_arg(args, msg='No destination instance specified !')
- output = tempfile.mkstemp()[1]
+ fd, output = tempfile.mkstemp()
+ os.close(fd)
if ':' in srcappid:
host, srcappid = srcappid.split(':')
_remote_dump(host, srcappid, output, self.config.sudo)
--- a/server/test/unittest_extlite.py Wed Sep 09 15:58:02 2009 +0200
+++ b/server/test/unittest_extlite.py Wed Sep 09 18:00:18 2009 +0200
@@ -24,35 +24,34 @@
self._cleanup()
def test(self):
- lock = threading.Lock()
-
+ lock1 = threading.Lock()
+ lock2 = threading.Lock()
+
def run_thread():
cnx2 = get_connection('sqlite', database=self.sqlite_file)
- lock.acquire()
+ lock1.acquire()
cu = cnx2.cursor()
cu.execute('SELECT name FROM toto')
self.failIf(cu.fetchall())
cnx2.commit()
- lock.release()
- time.sleep(0.1)
- lock.acquire()
+ lock1.release()
+ lock2.acquire()
cu.execute('SELECT name FROM toto')
self.failUnless(cu.fetchall())
- lock.release()
+ lock2.release()
cnx1 = get_connection('sqlite', database=self.sqlite_file)
- lock.acquire()
+ lock1.acquire()
+ lock2.acquire()
thread = threading.Thread(target=run_thread)
thread.start()
cu = cnx1.cursor()
cu.execute('SELECT name FROM toto')
- lock.release()
- time.sleep(0.1)
+ lock1.release()
cnx1.commit()
- lock.acquire()
cu.execute("INSERT INTO toto(name) VALUES ('toto')")
cnx1.commit()
- lock.release()
+ lock2.release()
if __name__ == '__main__':
unittest_main()
--- a/test/unittest_utils.py Wed Sep 09 15:58:02 2009 +0200
+++ b/test/unittest_utils.py Wed Sep 09 18:00:18 2009 +0200
@@ -17,12 +17,12 @@
self.assertNotEquals(make_uid('xyz'), make_uid('xyz'))
def test_2(self):
- d = {}
+ d = set()
while len(d)<10000:
uid = make_uid('xyz')
- if d.has_key(uid):
+ if uid in d:
self.fail(len(d))
- d[uid] = 1
+ d.add(uid)
class UStringIOTC(TestCase):
--- a/utils.py Wed Sep 09 15:58:02 2009 +0200
+++ b/utils.py Wed Sep 09 18:00:18 2009 +0200
@@ -11,6 +11,7 @@
import locale
from md5 import md5
+import sys
from datetime import datetime, timedelta, date
from time import time, mktime
from random import randint, seed
@@ -103,11 +104,17 @@
encoding = locale.getpreferredencoding(do_setlocale=False) or 'UTF-8'
return unicode(date.strftime(str(fmt)), encoding)
-def make_uid(key):
- """forge a unique identifier"""
- msg = str(key) + "%.10f" % time() + str(randint(0, 1000000))
- return md5(msg).hexdigest()
+if sys.version_info[:2] < (2, 5):
+ def make_uid(key):
+ """forge a unique identifier
+ not that unique on win32"""
+ msg = str(key) + "%.10f" % time() + str(randint(0, 1000000))
+ return md5(msg).hexdigest()
+else:
+ from uuid import uuid4
+ def make_uid(key):
+ return key + str(uuid4())
def dump_class(cls, clsname):
"""create copy of a class by creating an empty class inheriting
--- a/web/views/__init__.py Wed Sep 09 15:58:02 2009 +0200
+++ b/web/views/__init__.py Wed Sep 09 18:00:18 2009 +0200
@@ -111,13 +111,8 @@
def cell_call(self, row=0, col=0):
self.row, self.col = row, col # in case one needs it
- _, tmpfile = tempfile.mkstemp('.png')
- try:
- self._generate(tmpfile)
- self.w(open(tmpfile, 'rb').read())
- finally:
- try:
- os.unlink(tmpfile)
- except Exception, ex:
- if sys.platform != 'win32':
- self.warning("can't delete %s : %s" % (tmpfile, ex))
+ fd, tmpfile = tempfile.mkstemp('.png')
+ os.close(fd)
+ self._generate(tmpfile)
+ self.w(open(tmpfile, 'rb').read())
+ os.unlink(tmpfile)