Browse Source

Run 2to3 automatic fixes over entire tree

tags/nilmdb-2.0.0
Jim Paris 1 year ago
parent
commit
0f5c1c0db6
40 changed files with 206 additions and 205 deletions
  1. +2
    -2
      extras/fix-oversize-files.py
  2. +1
    -1
      nilmdb/client/client.py
  3. +4
    -4
      nilmdb/client/httpclient.py
  4. +1
    -1
      nilmdb/client/numpyclient.py
  5. +2
    -2
      nilmdb/cmdline/cmdline.py
  6. +1
    -1
      nilmdb/cmdline/extract.py
  7. +6
    -6
      nilmdb/cmdline/metadata.py
  8. +1
    -1
      nilmdb/fsck/__init__.py
  9. +6
    -6
      nilmdb/fsck/fsck.py
  10. +6
    -6
      nilmdb/scripts/nilmdb_server.py
  11. +1
    -1
      nilmdb/server/__init__.py
  12. +8
    -8
      nilmdb/server/bulkdata.py
  13. +1
    -1
      nilmdb/server/nilmdb.py
  14. +3
    -3
      nilmdb/server/server.py
  15. +3
    -3
      nilmdb/server/serverutil.py
  16. +2
    -2
      nilmdb/utils/__init__.py
  17. +5
    -5
      nilmdb/utils/datetime_tz/__init__.py
  18. +69
    -69
      nilmdb/utils/datetime_tz/pytz_abbr.py
  19. +1
    -1
      nilmdb/utils/diskusage.py
  20. +1
    -1
      nilmdb/utils/iterator.py
  21. +1
    -1
      nilmdb/utils/lrucache.py
  22. +2
    -2
      nilmdb/utils/mustclose.py
  23. +1
    -1
      nilmdb/utils/printf.py
  24. +8
    -8
      nilmdb/utils/serializer.py
  25. +2
    -2
      nilmdb/utils/threadsafety.py
  26. +1
    -1
      nilmdb/utils/time.py
  27. +2
    -2
      nilmdb/utils/timer.py
  28. +3
    -3
      nilmdb/utils/timestamper.py
  29. +1
    -1
      nilmdb/utils/unicode.py
  30. +2
    -2
      tests/test_bulkdata.py
  31. +12
    -12
      tests/test_client.py
  32. +18
    -18
      tests/test_cmdline.py
  33. +5
    -5
      tests/test_interval.py
  34. +2
    -2
      tests/test_mustclose.py
  35. +5
    -4
      tests/test_nilmdb.py
  36. +1
    -1
      tests/test_printf.py
  37. +5
    -5
      tests/test_rbtree.py
  38. +2
    -2
      tests/test_serializer.py
  39. +8
    -8
      tests/test_timestamper.py
  40. +1
    -1
      tests/testutil/helpers.py

+ 2
- 2
extras/fix-oversize-files.py View File

@@ -2,7 +2,7 @@

import os
import sys
import cPickle as pickle
import pickle as pickle
import argparse
import fcntl
import re
@@ -44,7 +44,7 @@ with open(lock, "w") as f:
maxsize = fix[fixpath]
if size > maxsize:
diff = size - maxsize
print diff, "too big:", fn
print(diff, "too big:", fn)
if args.yes:
with open(fn, "a+") as dbfile:
dbfile.truncate(maxsize)

+ 1
- 1
nilmdb/client/client.py View File

@@ -159,7 +159,7 @@ class Client(object):
so it will be broken into reasonably-sized chunks and
start/end will be deduced if missing."""
with self.stream_insert_context(path, start, end) as ctx:
if isinstance(data, basestring):
if isinstance(data, str):
ctx.insert(data)
else:
for chunk in data:


+ 4
- 4
nilmdb/client/httpclient.py View File

@@ -4,7 +4,7 @@ import nilmdb.utils
from nilmdb.client.errors import ClientError, ServerError, Error

import simplejson as json
import urlparse
import urllib.parse
import requests

class HTTPClient(object):
@@ -13,9 +13,9 @@ class HTTPClient(object):
"""If baseurl is supplied, all other functions that take
a URL can be given a relative URL instead."""
# Verify / clean up URL
reparsed = urlparse.urlparse(baseurl).geturl()
reparsed = urllib.parse.urlparse(baseurl).geturl()
if '://' not in reparsed:
reparsed = urlparse.urlparse("http://" + baseurl).geturl()
reparsed = urllib.parse.urlparse("http://" + baseurl).geturl()
self.baseurl = reparsed.rstrip('/') + '/'

# Note whether we want SSL verification
@@ -60,7 +60,7 @@ class HTTPClient(object):
pass

def _do_req(self, method, url, query_data, body_data, stream, headers):
url = urlparse.urljoin(self.baseurl, url)
url = urllib.parse.urljoin(self.baseurl, url)
try:
# Create a new session, ensure we send "Connection: close",
# and explicitly close connection after the transfer.


+ 1
- 1
nilmdb/client/numpyclient.py View File

@@ -12,7 +12,7 @@ import contextlib
from nilmdb.utils.time import timestamp_to_string, string_to_timestamp

import numpy
import cStringIO
import io

def layout_to_dtype(layout):
ltype = layout.split('_')[0]


+ 2
- 2
nilmdb/cmdline/cmdline.py View File

@@ -83,8 +83,8 @@ class Complete(object): # pragma: no cover
# prefix comes in as UTF-8, but results need to be Unicode,
# weird. Still doesn't work in all cases, but that's bugs in
# argcomplete.
prefix = nilmdb.utils.unicode.decode(prefix)
for (k,v) in client.stream_get_metadata(path).iteritems():
prefix = nilmdb.utils.str.decode(prefix)
for (k,v) in client.stream_get_metadata(path).items():
kv = self.escape(k + '=' + v)
if kv.startswith(prefix):
results.append(kv)


+ 1
- 1
nilmdb/cmdline/extract.py View File

@@ -1,4 +1,4 @@
from __future__ import print_function
from nilmdb.utils.printf import *
import nilmdb.client
import sys


+ 6
- 6
nilmdb/cmdline/metadata.py View File

@@ -41,10 +41,10 @@ def cmd_metadata(self):
if self.args.set is not None or self.args.update is not None:
# Either set, or update
if self.args.set is not None:
keyvals = map(nilmdb.utils.unicode.decode, self.args.set)
keyvals = list(map(nilmdb.utils.str.decode, self.args.set))
handler = self.client.stream_set_metadata
else:
keyvals = map(nilmdb.utils.unicode.decode, self.args.update)
keyvals = list(map(nilmdb.utils.str.decode, self.args.update))
handler = self.client.stream_update_metadata

# Extract key=value pairs
@@ -64,7 +64,7 @@ def cmd_metadata(self):
# Delete (by setting values to empty strings)
keys = None
if self.args.delete:
keys = map(nilmdb.utils.unicode.decode, self.args.delete)
keys = list(map(nilmdb.utils.str.decode, self.args.delete))
try:
data = self.client.stream_get_metadata(self.args.path, keys)
for key in data:
@@ -76,7 +76,7 @@ def cmd_metadata(self):
# Get (or unspecified)
keys = None
if self.args.get:
keys = map(nilmdb.utils.unicode.decode, self.args.get)
keys = list(map(nilmdb.utils.str.decode, self.args.get))
try:
data = self.client.stream_get_metadata(self.args.path, keys)
except nilmdb.client.ClientError as e:
@@ -86,5 +86,5 @@ def cmd_metadata(self):
if value is None:
value = ""
printf("%s=%s\n",
nilmdb.utils.unicode.encode(key),
nilmdb.utils.unicode.encode(value))
nilmdb.utils.str.encode(key),
nilmdb.utils.str.encode(value))

+ 1
- 1
nilmdb/fsck/__init__.py View File

@@ -1,5 +1,5 @@
"""nilmdb.fsck"""

from __future__ import absolute_import

from nilmdb.fsck.fsck import Fsck

+ 6
- 6
nilmdb/fsck/fsck.py View File

@@ -21,7 +21,7 @@ import progressbar
import re
import time
import shutil
import cPickle as pickle
import pickle as pickle
import numpy

class FsckError(Exception):
@@ -179,7 +179,7 @@ class Fsck(object):
### Check streams and basic interval overlap

def check_streams(self):
ids = self.stream_path.keys()
ids = list(self.stream_path.keys())
log("checking %s streams\n", "{:,d}".format(len(ids)))
with Progress(len(ids)) as pbar:
for i, sid in enumerate(ids):
@@ -187,7 +187,7 @@ class Fsck(object):
path = self.stream_path[sid]

# unique path, valid layout
if self.stream_path.values().count(path) != 1:
if list(self.stream_path.values()).count(path) != 1:
raise FsckError("duplicated path %s", path)
layout = self.stream_layout[sid].split('_')[0]
if layout not in ('int8', 'int16', 'int32', 'int64',
@@ -269,7 +269,7 @@ class Fsck(object):
for subdir in subdirs:
# Find all files in that dir
subpath = os.path.join(bulk, subdir)
files = filter(regex.search, os.listdir(subpath))
files = list(filter(regex.search, os.listdir(subpath)))
if not files:
self.fix_empty_subdir(subpath)
raise RetryFsck
@@ -315,7 +315,7 @@ class Fsck(object):
### Check interval endpoints

def check_intervals(self):
total_ints = sum(len(x) for x in self.stream_interval.values())
total_ints = sum(len(x) for x in list(self.stream_interval.values()))
log("checking %s intervals\n", "{:,d}".format(total_ints))
done = 0
with Progress(total_ints) as pbar:
@@ -398,7 +398,7 @@ class Fsck(object):

def check_data(self):
total_rows = sum(sum((y[3] - y[2]) for y in x)
for x in self.stream_interval.values())
for x in list(self.stream_interval.values()))
log("checking %s rows of data\n", "{:,d}".format(total_rows))
done = 0
with Progress(total_rows) as pbar:


+ 6
- 6
nilmdb/scripts/nilmdb_server.py View File

@@ -51,18 +51,18 @@ def main():

# Print info
if not args.quiet:
print "Version: %s" % nilmdb.__version__
print "Database: %s" % (os.path.realpath(args.database))
print("Version: %s" % nilmdb.__version__)
print("Database: %s" % (os.path.realpath(args.database)))
if args.address == '0.0.0.0' or args.address == '::':
host = socket.getfqdn()
else:
host = args.address
print "Server URL: http://%s:%d/" % ( host, args.port)
print "----"
print("Server URL: http://%s:%d/" % ( host, args.port))
print("----")

# Run it
if args.yappi:
print "Running in yappi"
print("Running in yappi")
try:
import yappi
yappi.start()
@@ -78,7 +78,7 @@ def main():

# Clean up
if not args.quiet:
print "Closing database"
print("Closing database")
db.close()

if __name__ == "__main__":


+ 1
- 1
nilmdb/server/__init__.py View File

@@ -1,6 +1,6 @@
"""nilmdb.server"""

from __future__ import absolute_import

# Try to set up pyximport to automatically rebuild Cython modules. If
# this doesn't work, it's OK, as long as the modules were built externally.


+ 8
- 8
nilmdb/server/bulkdata.py View File

@@ -2,14 +2,14 @@

# Need absolute_import so that "import nilmdb" won't pull in
# nilmdb.py, but will pull the parent nilmdb module instead.
from __future__ import absolute_import
from __future__ import division
from nilmdb.utils.printf import *
from nilmdb.utils.time import timestamp_to_string as timestamp_to_string
import nilmdb.utils

import os
import cPickle as pickle
import pickle as pickle
import re
import sys
import tempfile
@@ -75,7 +75,7 @@ class BulkData(object):
# because we want to be able to represent all code points and the user
# will never be directly exposed to filenames. We can then do path
# manipulations on the UTF-8 directly.
if isinstance(path, unicode):
if isinstance(path, str):
return path.encode('utf-8')
return path

@@ -133,7 +133,7 @@ class BulkData(object):
os.rmdir(ospath)
except OSError:
pass
raise exc_info[1], None, exc_info[2]
raise exc_info[1].with_traceback(exc_info[2])

return elements

@@ -168,7 +168,7 @@ class BulkData(object):
os.rmdir(ospath)
except OSError:
pass
raise exc_info[1], None, exc_info[2]
raise exc_info[1].with_traceback(exc_info[2])

# Success
return
@@ -177,7 +177,7 @@ class BulkData(object):
"""Remove empty directories starting at the leaves of unicodepath"""
path = self._encode_filename(unicodepath)
elements = path.lstrip('/').split('/')
for i in reversed(range(len(elements))):
for i in reversed(list(range(len(elements)))):
ospath = os.path.join(self.root, *elements[0:i+1])
try:
os.rmdir(ospath)
@@ -348,7 +348,7 @@ class Table(object):
for subdir in subdirs:
# Now find the last file in that dir
path = os.path.join(self.root, subdir)
files = filter(regex.search, os.listdir(path))
files = list(filter(regex.search, os.listdir(path)))
if not files: # pragma: no cover (shouldn't occur)
# Empty dir: try the next one
continue


+ 1
- 1
nilmdb/server/nilmdb.py View File

@@ -9,7 +9,7 @@ Manages both the SQL database and the table storage backend.

# Need absolute_import so that "import nilmdb" won't pull in
# nilmdb.py, but will pull the parent nilmdb module instead.
from __future__ import absolute_import
import nilmdb.utils
from nilmdb.utils.printf import *
from nilmdb.utils.time import timestamp_to_string


+ 3
- 3
nilmdb/server/server.py View File

@@ -2,7 +2,7 @@

# Need absolute_import so that "import nilmdb" won't pull in
# nilmdb.py, but will pull the nilmdb module instead.
from __future__ import absolute_import
import nilmdb.server
from nilmdb.utils.printf import *
from nilmdb.server.errors import NilmDBError
@@ -168,7 +168,7 @@ class Stream(NilmApp):
except nilmdb.server.nilmdb.StreamError as e:
raise cherrypy.HTTPError("404 Not Found", e.message)
if key is None: # If no keys specified, return them all
key = data.keys()
key = list(data.keys())
elif not isinstance(key, list):
key = [ key ]
result = {}
@@ -187,7 +187,7 @@ class Stream(NilmApp):
except TypeError as e:
raise NilmDBError("can't parse 'data' parameter: " + e.message)
for key in data:
if not (isinstance(data[key], basestring) or
if not (isinstance(data[key], str) or
isinstance(data[key], float) or
isinstance(data[key], int)):
raise NilmDBError("metadata values must be a string or number")


+ 3
- 3
nilmdb/server/serverutil.py View File

@@ -56,7 +56,7 @@ def workaround_cp_bug_1200(func, *args, **kwargs): # pragma: no cover
# Re-raise it, but maintain the original traceback
exc_info = sys.exc_info()
new_exc = Exception(exc_info[0].__name__ + ": " + str(exc_info[1]))
raise new_exc, None, exc_info[2]
raise new_exc.with_traceback(exc_info[2])
finally:
del exc_info

@@ -76,7 +76,7 @@ def exception_to_httperror(*expected):
# Re-raise it, but maintain the original traceback
exc_info = sys.exc_info()
new_exc = cherrypy.HTTPError("400 Bad Request", str(exc_info[1]))
raise new_exc, None, exc_info[2]
raise new_exc.with_traceback(exc_info[2])
finally:
del exc_info
# We need to preserve the function's argspecs for CherryPy to
@@ -160,7 +160,7 @@ def json_error_page(status, message, traceback, version,
"application/json;charset=utf-8" )
# Undo the HTML escaping that cherrypy's get_error_page function applies
# (cherrypy issue 1135)
for k, v in errordata.iteritems():
for k, v in errordata.items():
v = v.replace("&lt;","<")
v = v.replace("&gt;",">")
v = v.replace("&amp;","&")


+ 2
- 2
nilmdb/utils/__init__.py View File

@@ -1,6 +1,6 @@
"""NilmDB utilities"""

from __future__ import absolute_import
from nilmdb.utils.timer import Timer
from nilmdb.utils.serializer import serializer_proxy
from nilmdb.utils.lrucache import lru_cache
@@ -14,4 +14,4 @@ import nilmdb.utils.iterator
import nilmdb.utils.interval
import nilmdb.utils.lock
import nilmdb.utils.sort
import nilmdb.utils.unicode
import nilmdb.utils.str

+ 5
- 5
nilmdb/utils/datetime_tz/__init__.py View File

@@ -44,13 +44,13 @@ import dateutil.parser
import dateutil.relativedelta
import dateutil.tz
import pytz
import pytz_abbr
from . import pytz_abbr


try:
# pylint: disable-msg=C6204
import functools
except ImportError, e:
except ImportError as e:

class functools(object):
"""Fake replacement for a full functools."""
@@ -172,12 +172,12 @@ def _detect_timezone_etc_timezone():
tz = file("/etc/timezone").read().strip()
try:
return pytz.timezone(tz)
except (IOError, pytz.UnknownTimeZoneError), ei:
except (IOError, pytz.UnknownTimeZoneError) as ei:
warnings.warn("Your /etc/timezone file references a timezone (%r) that"
" is not valid (%r)." % (tz, ei))

# Problem reading the /etc/timezone file
except IOError, eo:
except IOError as eo:
warnings.warn("Could not access your /etc/timezone file: %s" % eo)


@@ -273,7 +273,7 @@ class datetime_tz(datetime.datetime):

# See if we are given a tzinfo object...
tzinfo = None
if isinstance(args[-1], (datetime.tzinfo, basestring)):
if isinstance(args[-1], (datetime.tzinfo, str)):
tzinfo = _tzinfome(args.pop(-1))
elif kw.get("tzinfo", None) is not None:
tzinfo = _tzinfome(kw.pop("tzinfo"))


+ 69
- 69
nilmdb/utils/datetime_tz/pytz_abbr.py View File

@@ -91,7 +91,7 @@ def tzinfos_create(use_region):
pass
return result
else:
raise ValueError, "Unknown timezone found %s" % abbr
raise ValueError("Unknown timezone found %s" % abbr)
if offset == 0:
return pytz.utc
if offset:
@@ -107,68 +107,68 @@ tzinfos = tzinfos_create('all')

# Create the abbreviations.
# *WARNING*: Order matters!
tzabbr_register("A", u"Alpha Time Zone", u"Military", "Etc/GMT-1", False)
tzabbr_register("ACDT", u"Australian Central Daylight Time", u"Australia",
tzabbr_register("A", "Alpha Time Zone", "Military", "Etc/GMT-1", False)
tzabbr_register("ACDT", "Australian Central Daylight Time", "Australia",
"Australia/Adelaide", True)
tzabbr_register("ACST", u"Australian Central Standard Time", u"Australia",
tzabbr_register("ACST", "Australian Central Standard Time", "Australia",
"Australia/Adelaide", False)
tzabbr_register("ADT", u"Atlantic Daylight Time", u"North America",
tzabbr_register("ADT", "Atlantic Daylight Time", "North America",
"America/Halifax", True)
tzabbr_register("AEDT", u"Australian Eastern Daylight Time", u"Australia",
tzabbr_register("AEDT", "Australian Eastern Daylight Time", "Australia",
"Australia/Sydney", True)
tzabbr_register("AEST", u"Australian Eastern Standard Time", u"Australia",
tzabbr_register("AEST", "Australian Eastern Standard Time", "Australia",
"Australia/Sydney", False)
tzabbr_register("AKDT", u"Alaska Daylight Time", u"North America",
tzabbr_register("AKDT", "Alaska Daylight Time", "North America",
"US/Alaska", True)
tzabbr_register("AKST", u"Alaska Standard Time", u"North America",
tzabbr_register("AKST", "Alaska Standard Time", "North America",
"US/Alaska", False)
tzabbr_register("AST", u"Atlantic Standard Time", u"North America",
tzabbr_register("AST", "Atlantic Standard Time", "North America",
"America/Halifax", False)
tzabbr_register("AWDT", u"Australian Western Daylight Time", u"Australia",
tzabbr_register("AWDT", "Australian Western Daylight Time", "Australia",
"Australia/West", True)
tzabbr_register("AWST", u"Australian Western Standard Time", u"Australia",
tzabbr_register("AWST", "Australian Western Standard Time", "Australia",
"Australia/West", False)
tzabbr_register("B", u"Bravo Time Zone", u"Military", "Etc/GMT-2", False)
tzabbr_register("BST", u"British Summer Time", u"Europe", "Europe/London", True)
tzabbr_register("C", u"Charlie Time Zone", u"Military", "Etc/GMT-2", False)
tzabbr_register("CDT", u"Central Daylight Time", u"North America",
tzabbr_register("B", "Bravo Time Zone", "Military", "Etc/GMT-2", False)
tzabbr_register("BST", "British Summer Time", "Europe", "Europe/London", True)
tzabbr_register("C", "Charlie Time Zone", "Military", "Etc/GMT-2", False)
tzabbr_register("CDT", "Central Daylight Time", "North America",
"US/Central", True)
tzabbr_register("CEDT", u"Central European Daylight Time", u"Europe",
tzabbr_register("CEDT", "Central European Daylight Time", "Europe",
"Etc/GMT+2", True)
tzabbr_register("CEST", u"Central European Summer Time", u"Europe",
tzabbr_register("CEST", "Central European Summer Time", "Europe",
"Etc/GMT+2", True)
tzabbr_register("CET", u"Central European Time", u"Europe", "Etc/GMT+1", False)
tzabbr_register("CST", u"Central Standard Time", u"North America",
tzabbr_register("CET", "Central European Time", "Europe", "Etc/GMT+1", False)
tzabbr_register("CST", "Central Standard Time", "North America",
"US/Central", False)
tzabbr_register("CXT", u"Christmas Island Time", u"Australia",
tzabbr_register("CXT", "Christmas Island Time", "Australia",
"Indian/Christmas", False)
tzabbr_register("D", u"Delta Time Zone", u"Military", "Etc/GMT-2", False)
tzabbr_register("E", u"Echo Time Zone", u"Military", "Etc/GMT-2", False)
tzabbr_register("EDT", u"Eastern Daylight Time", u"North America",
tzabbr_register("D", "Delta Time Zone", "Military", "Etc/GMT-2", False)
tzabbr_register("E", "Echo Time Zone", "Military", "Etc/GMT-2", False)
tzabbr_register("EDT", "Eastern Daylight Time", "North America",
"US/Eastern", True)
tzabbr_register("EEDT", u"Eastern European Daylight Time", u"Europe",
tzabbr_register("EEDT", "Eastern European Daylight Time", "Europe",
"Etc/GMT+3", True)
tzabbr_register("EEST", u"Eastern European Summer Time", u"Europe",
tzabbr_register("EEST", "Eastern European Summer Time", "Europe",
"Etc/GMT+3", True)
tzabbr_register("EET", u"Eastern European Time", u"Europe", "Etc/GMT+2", False)
tzabbr_register("EST", u"Eastern Standard Time", u"North America",
tzabbr_register("EET", "Eastern European Time", "Europe", "Etc/GMT+2", False)
tzabbr_register("EST", "Eastern Standard Time", "North America",
"US/Eastern", False)
tzabbr_register("F", u"Foxtrot Time Zone", u"Military", "Etc/GMT-6", False)
tzabbr_register("G", u"Golf Time Zone", u"Military", "Etc/GMT-7", False)
tzabbr_register("GMT", u"Greenwich Mean Time", u"Europe", pytz.utc, False)
tzabbr_register("H", u"Hotel Time Zone", u"Military", "Etc/GMT-8", False)
tzabbr_register("F", "Foxtrot Time Zone", "Military", "Etc/GMT-6", False)
tzabbr_register("G", "Golf Time Zone", "Military", "Etc/GMT-7", False)
tzabbr_register("GMT", "Greenwich Mean Time", "Europe", pytz.utc, False)
tzabbr_register("H", "Hotel Time Zone", "Military", "Etc/GMT-8", False)
#tzabbr_register("HAA", u"Heure Avancée de l'Atlantique", u"North America", u"UTC - 3 hours")
#tzabbr_register("HAC", u"Heure Avancée du Centre", u"North America", u"UTC - 5 hours")
tzabbr_register("HADT", u"Hawaii-Aleutian Daylight Time", u"North America",
tzabbr_register("HADT", "Hawaii-Aleutian Daylight Time", "North America",
"Pacific/Honolulu", True)
#tzabbr_register("HAE", u"Heure Avancée de l'Est", u"North America", u"UTC - 4 hours")
#tzabbr_register("HAP", u"Heure Avancée du Pacifique", u"North America", u"UTC - 7 hours")
#tzabbr_register("HAR", u"Heure Avancée des Rocheuses", u"North America", u"UTC - 6 hours")
tzabbr_register("HAST", u"Hawaii-Aleutian Standard Time", u"North America",
tzabbr_register("HAST", "Hawaii-Aleutian Standard Time", "North America",
"Pacific/Honolulu", False)
#tzabbr_register("HAT", u"Heure Avancée de Terre-Neuve", u"North America", u"UTC - 2:30 hours")
#tzabbr_register("HAY", u"Heure Avancée du Yukon", u"North America", u"UTC - 8 hours")
tzabbr_register("HDT", u"Hawaii Daylight Time", u"North America",
tzabbr_register("HDT", "Hawaii Daylight Time", "North America",
"Pacific/Honolulu", True)
#tzabbr_register("HNA", u"Heure Normale de l'Atlantique", u"North America", u"UTC - 4 hours")
#tzabbr_register("HNC", u"Heure Normale du Centre", u"North America", u"UTC - 6 hours")
@@ -177,54 +177,54 @@ tzabbr_register("HDT", u"Hawaii Daylight Time", u"North America",
#tzabbr_register("HNR", u"Heure Normale des Rocheuses", u"North America", u"UTC - 7 hours")
#tzabbr_register("HNT", u"Heure Normale de Terre-Neuve", u"North America", u"UTC - 3:30 hours")
#tzabbr_register("HNY", u"Heure Normale du Yukon", u"North America", u"UTC - 9 hours")
tzabbr_register("HST", u"Hawaii Standard Time", u"North America",
tzabbr_register("HST", "Hawaii Standard Time", "North America",
"Pacific/Honolulu", False)
tzabbr_register("I", u"India Time Zone", u"Military", "Etc/GMT-9", False)
tzabbr_register("IST", u"Irish Summer Time", u"Europe", "Europe/Dublin", True)
tzabbr_register("K", u"Kilo Time Zone", u"Military", "Etc/GMT-10", False)
tzabbr_register("L", u"Lima Time Zone", u"Military", "Etc/GMT-11", False)
tzabbr_register("M", u"Mike Time Zone", u"Military", "Etc/GMT-12", False)
tzabbr_register("MDT", u"Mountain Daylight Time", u"North America",
tzabbr_register("I", "India Time Zone", "Military", "Etc/GMT-9", False)
tzabbr_register("IST", "Irish Summer Time", "Europe", "Europe/Dublin", True)
tzabbr_register("K", "Kilo Time Zone", "Military", "Etc/GMT-10", False)
tzabbr_register("L", "Lima Time Zone", "Military", "Etc/GMT-11", False)
tzabbr_register("M", "Mike Time Zone", "Military", "Etc/GMT-12", False)
tzabbr_register("MDT", "Mountain Daylight Time", "North America",
"US/Mountain", True)
#tzabbr_register("MESZ", u"Mitteleuroäische Sommerzeit", u"Europe", u"UTC + 2 hours")
#tzabbr_register("MEZ", u"Mitteleuropäische Zeit", u"Europe", u"UTC + 1 hour")
tzabbr_register("MSD", u"Moscow Daylight Time", u"Europe",
tzabbr_register("MSD", "Moscow Daylight Time", "Europe",
"Europe/Moscow", True)
tzabbr_register("MSK", u"Moscow Standard Time", u"Europe",
tzabbr_register("MSK", "Moscow Standard Time", "Europe",
"Europe/Moscow", False)
tzabbr_register("MST", u"Mountain Standard Time", u"North America",
tzabbr_register("MST", "Mountain Standard Time", "North America",
"US/Mountain", False)
tzabbr_register("N", u"November Time Zone", u"Military", "Etc/GMT+1", False)
tzabbr_register("NDT", u"Newfoundland Daylight Time", u"North America",
tzabbr_register("N", "November Time Zone", "Military", "Etc/GMT+1", False)
tzabbr_register("NDT", "Newfoundland Daylight Time", "North America",
"America/St_Johns", True)
tzabbr_register("NFT", u"Norfolk (Island) Time", u"Australia",
tzabbr_register("NFT", "Norfolk (Island) Time", "Australia",
"Pacific/Norfolk", False)
tzabbr_register("NST", u"Newfoundland Standard Time", u"North America",
tzabbr_register("NST", "Newfoundland Standard Time", "North America",
"America/St_Johns", False)
tzabbr_register("O", u"Oscar Time Zone", u"Military", "Etc/GMT+2", False)
tzabbr_register("P", u"Papa Time Zone", u"Military", "Etc/GMT+3", False)
tzabbr_register("PDT", u"Pacific Daylight Time", u"North America",
tzabbr_register("O", "Oscar Time Zone", "Military", "Etc/GMT+2", False)
tzabbr_register("P", "Papa Time Zone", "Military", "Etc/GMT+3", False)
tzabbr_register("PDT", "Pacific Daylight Time", "North America",
"US/Pacific", True)
tzabbr_register("PST", u"Pacific Standard Time", u"North America",
tzabbr_register("PST", "Pacific Standard Time", "North America",
"US/Pacific", False)
tzabbr_register("Q", u"Quebec Time Zone", u"Military", "Etc/GMT+4", False)
tzabbr_register("R", u"Romeo Time Zone", u"Military", "Etc/GMT+5", False)
tzabbr_register("S", u"Sierra Time Zone", u"Military", "Etc/GMT+6", False)
tzabbr_register("T", u"Tango Time Zone", u"Military", "Etc/GMT+7", False)
tzabbr_register("U", u"Uniform Time Zone", u"Military", "Etc/GMT+8", False)
tzabbr_register("UTC", u"Coordinated Universal Time", u"Europe",
tzabbr_register("Q", "Quebec Time Zone", "Military", "Etc/GMT+4", False)
tzabbr_register("R", "Romeo Time Zone", "Military", "Etc/GMT+5", False)
tzabbr_register("S", "Sierra Time Zone", "Military", "Etc/GMT+6", False)
tzabbr_register("T", "Tango Time Zone", "Military", "Etc/GMT+7", False)
tzabbr_register("U", "Uniform Time Zone", "Military", "Etc/GMT+8", False)
tzabbr_register("UTC", "Coordinated Universal Time", "Europe",
pytz.utc, False)
tzabbr_register("V", u"Victor Time Zone", u"Military", "Etc/GMT+9", False)
tzabbr_register("W", u"Whiskey Time Zone", u"Military", "Etc/GMT+10", False)
tzabbr_register("WDT", u"Western Daylight Time", u"Australia",
tzabbr_register("V", "Victor Time Zone", "Military", "Etc/GMT+9", False)
tzabbr_register("W", "Whiskey Time Zone", "Military", "Etc/GMT+10", False)
tzabbr_register("WDT", "Western Daylight Time", "Australia",
"Australia/West", True)
tzabbr_register("WEDT", u"Western European Daylight Time", u"Europe",
tzabbr_register("WEDT", "Western European Daylight Time", "Europe",
"Etc/GMT+1", True)
tzabbr_register("WEST", u"Western European Summer Time", u"Europe",
tzabbr_register("WEST", "Western European Summer Time", "Europe",
"Etc/GMT+1", True)
tzabbr_register("WET", u"Western European Time", u"Europe", pytz.utc, False)
tzabbr_register("WST", u"Western Standard Time", u"Australia",
tzabbr_register("WET", "Western European Time", "Europe", pytz.utc, False)
tzabbr_register("WST", "Western Standard Time", "Australia",
"Australia/West", False)
tzabbr_register("X", u"X-ray Time Zone", u"Military", "Etc/GMT+11", False)
tzabbr_register("Y", u"Yankee Time Zone", u"Military", "Etc/GMT+12", False)
tzabbr_register("Z", u"Zulu Time Zone", u"Military", pytz.utc, False)
tzabbr_register("X", "X-ray Time Zone", "Military", "Etc/GMT+11", False)
tzabbr_register("Y", "Yankee Time Zone", "Military", "Etc/GMT+12", False)
tzabbr_register("Z", "Zulu Time Zone", "Military", pytz.utc, False)

+ 1
- 1
nilmdb/utils/diskusage.py View File

@@ -4,7 +4,7 @@ from math import log

def human_size(num):
"""Human friendly file size"""
unit_list = zip(['bytes', 'kiB', 'MiB', 'GiB', 'TiB'], [0, 0, 1, 2, 2])
unit_list = list(zip(['bytes', 'kiB', 'MiB', 'GiB', 'TiB'], [0, 0, 1, 2, 2]))
if num > 1:
exponent = min(int(log(num, 1024)), len(unit_list) - 1)
quotient = float(num) / 1024**exponent


+ 1
- 1
nilmdb/utils/iterator.py View File

@@ -17,7 +17,7 @@ def imerge(*iterables):
h_append = h.append
for it in map(iter, iterables):
try:
next = it.next
next = it.__next__
h_append([next(), next])
except _Stop:
pass


+ 1
- 1
nilmdb/utils/lrucache.py View File

@@ -53,7 +53,7 @@ def lru_cache(size = 10, onremove = None, keys = slice(None)):
if key in cache:
evict(cache.pop(key))
else:
if len(cache) > 0 and len(args) != len(cache.iterkeys().next()):
if len(cache) > 0 and len(args) != len(next(iter(cache.keys()))):
raise KeyError("trying to remove from LRU cache, but "
"number of arguments doesn't match the "
"cache key length")


+ 2
- 2
nilmdb/utils/mustclose.py View File

@@ -14,7 +14,7 @@ def must_close(errorfile = sys.stderr, wrap_verify = False):

def wrap_class_method(wrapper):
try:
orig = getattr(cls, wrapper.__name__).im_func
orig = getattr(cls, wrapper.__name__).__func__
except Exception:
orig = lambda x: None
setattr(cls, wrapper.__name__, decorator.decorator(wrapper, orig))
@@ -58,7 +58,7 @@ def must_close(errorfile = sys.stderr, wrap_verify = False):
continue
# Set up wrapper
setattr(cls, name, decorator.decorator(verifier,
method.im_func))
method.__func__))

return cls
return class_decorator

+ 1
- 1
nilmdb/utils/printf.py View File

@@ -1,6 +1,6 @@
"""printf, fprintf, sprintf"""

from __future__ import print_function
def printf(_str, *args):
print(_str % args, end='')
def fprintf(_file, _str, *args):


+ 8
- 8
nilmdb/utils/serializer.py View File

@@ -1,4 +1,4 @@
import Queue
import queue
import threading
import sys
import decorator
@@ -57,25 +57,25 @@ def serializer_proxy(obj_or_type):
# go away (and kill the thread) until after get called.
self.objectproxy = objectproxy
def __call__(self, *args, **kwargs):
result_queue = Queue.Queue()
result_queue = queue.Queue()
self.call_queue.put((result_queue, self.func, args, kwargs))
( exc_info, result ) = result_queue.get()
if exc_info is None:
return result
else:
raise exc_info[0], exc_info[1], exc_info[2]
raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])

class SerializerObjectProxy(object):
def __init__(self, obj_or_type, *args, **kwargs):
self.__object = obj_or_type
try:
if type(obj_or_type) in (types.TypeType, types.ClassType):
if type(obj_or_type) in (type, type):
classname = obj_or_type.__name__
else:
classname = obj_or_type.__class__.__name__
except AttributeError: # pragma: no cover
classname = "???"
self.__call_queue = Queue.Queue()
self.__call_queue = queue.Queue()
self.__thread = SerializerThread(classname, self.__call_queue)
self.__thread.daemon = True
self.__thread.start()
@@ -98,9 +98,9 @@ def serializer_proxy(obj_or_type):
attr = getattr(self.__object, "__iter__")
self.__iter = SerializerCallProxy(self.__call_queue, attr, self)()
return self
def next(self):
def __next__(self):
return SerializerCallProxy(self.__call_queue,
self.__iter.next, self)()
self.__iter.__next__, self)()

def __getitem__(self, key):
return self.__getattr__("__getitem__")(key)
@@ -110,7 +110,7 @@ def serializer_proxy(obj_or_type):
to serializer_proxy. Otherwise, pass the call through."""
ret = SerializerCallProxy(self.__call_queue,
self.__object, self)(*args, **kwargs)
if type(self.__object) in (types.TypeType, types.ClassType):
if type(self.__object) in (type, type):
# Instantiation
self.__object = ret
return self


+ 2
- 2
nilmdb/utils/threadsafety.py View File

@@ -81,7 +81,7 @@ def verify_proxy(obj_or_type, exception = False, check_thread = True,
p.concur_callee = None
self.__obj = obj_or_type
try:
if type(obj_or_type) in (types.TypeType, types.ClassType):
if type(obj_or_type) in (type, type):
p.classname = self.__obj.__name__
else:
p.classname = self.__obj.__class__.__name__
@@ -100,7 +100,7 @@ def verify_proxy(obj_or_type, exception = False, check_thread = True,
"""Call this to instantiate the type, if a type was passed
to verify_proxy. Otherwise, pass the call through."""
ret = VerifyCallProxy(self.__obj, self.__ns)(*args, **kwargs)
if type(self.__obj) in (types.TypeType, types.ClassType):
if type(self.__obj) in (type, type):
# Instantiation
self.__obj = ret
return self


+ 1
- 1
nilmdb/utils/time.py View File

@@ -1,4 +1,4 @@
from __future__ import absolute_import

from nilmdb.utils import datetime_tz
import re


+ 2
- 2
nilmdb/utils/timer.py View File

@@ -5,8 +5,8 @@
# with nilmdb.utils.Timer("flush"):
# foo.flush()

from __future__ import print_function
from __future__ import absolute_import
import contextlib
import time



+ 3
- 3
nilmdb/utils/timestamper.py View File

@@ -9,7 +9,7 @@ class Timestamper(object):
"""file: filename, or another file-like object
ts_iter: iterator that returns a timestamp string for
each line of the file"""
if isinstance(infile, basestring):
if isinstance(infile, str):
self.file = open(infile, "r")
else:
self.file = infile
@@ -27,7 +27,7 @@ class Timestamper(object):
continue
break
try:
return self.ts_iter.next() + line
return next(self.ts_iter) + line
except StopIteration:
return ""

@@ -43,7 +43,7 @@ class Timestamper(object):
def __iter__(self):
return self

def next(self):
def __next__(self):
result = self.readline()
if not result:
raise StopIteration


+ 1
- 1
nilmdb/utils/unicode.py View File

@@ -3,7 +3,7 @@ import sys
if sys.version_info[0] >= 3: # pragma: no cover (future Python3 compat)
text_type = str
else:
text_type = unicode
text_type = str

def encode(u):
"""Try to encode something from Unicode to a string using the


+ 2
- 2
tests/test_bulkdata.py View File

@@ -41,7 +41,7 @@ class TestBulkData(object):
with assert_raises(ValueError):
data.create("foo/bar", "uint16_8")
data.create("/foo/bar", "uint16_8")
data.create(u"/foo/baz/quux", "float64_16")
data.create("/foo/baz/quux", "float64_16")
with assert_raises(ValueError):
data.create("/foo/bar/baz", "uint16_8")
with assert_raises(ValueError):
@@ -57,7 +57,7 @@ class TestBulkData(object):
def get_node_slice(key):
if isinstance(key, slice):
return [ node.get_data(x, x+1) for x in
xrange(*key.indices(node.nrows)) ]
range(*key.indices(node.nrows)) ]
return node.get_data(key, key+1)

# Test node


+ 12
- 12
tests/test_client.py View File

@@ -16,7 +16,7 @@ import distutils.version
import os
import sys
import threading
import cStringIO
import io
import simplejson as json
import unittest
import warnings
@@ -209,7 +209,7 @@ class TestClient(object):
"start must precede end", str(e.exception))

# Now try empty data (no server request made)
empty = cStringIO.StringIO("")
empty = io.StringIO("")
data = timestamper.TimestamperRate(empty, start, 120)
result = client.stream_insert("/newton/prep", data)
eq_(result, None)
@@ -359,18 +359,18 @@ class TestClient(object):
end = nilmdb.utils.time.parse_time("20120323T1000")
for function in [ client.stream_intervals, client.stream_extract ]:
with assert_raises(ClientError) as e:
function("/newton/prep", start, end).next()
next(function("/newton/prep", start, end))
in_("400 Bad Request", str(e.exception))
in_("start must precede end", str(e.exception))

# Trigger a curl error in generator
with assert_raises(ServerError) as e:
client.http.get_gen("http://nosuchurl.example.com./").next()
next(client.http.get_gen("http://nosuchurl.example.com./"))

# Check 404 for missing streams
for function in [ client.stream_intervals, client.stream_extract ]:
with assert_raises(ClientError) as e:
function("/no/such/stream").next()
next(function("/no/such/stream"))
in_("404 Not Found", str(e.exception))
in_("No such stream", str(e.exception))

@@ -391,7 +391,7 @@ class TestClient(object):

def headers():
h = ""
for (k, v) in http._last_response.headers.items():
for (k, v) in list(http._last_response.headers.items()):
h += k + ": " + v + "\n"
return h.lower()

@@ -454,8 +454,8 @@ class TestClient(object):
eq_(client.stream_list(), [])

# Create Unicode stream, match it
raw = [ u"/düsseldorf/raw", u"uint16_6" ]
prep = [ u"/düsseldorf/prep", u"uint16_6" ]
raw = [ "/düsseldorf/raw", "uint16_6" ]
prep = [ "/düsseldorf/prep", "uint16_6" ]
client.stream_create(*raw)
eq_(client.stream_list(), [raw])
eq_(client.stream_list(layout=raw[1]), [raw])
@@ -466,10 +466,10 @@ class TestClient(object):
# Set / get metadata with Unicode keys and values
eq_(client.stream_get_metadata(raw[0]), {})
eq_(client.stream_get_metadata(prep[0]), {})
meta1 = { u"alpha": u"α",
u"β": u"beta" }
meta2 = { u"alpha": u"α" }
meta3 = { u"β": u"beta" }
meta1 = { "alpha": "α",
"β": "beta" }
meta2 = { "alpha": "α" }
meta3 = { "β": "beta" }
client.stream_set_metadata(prep[0], meta1)
client.stream_update_metadata(prep[0], {})
client.stream_update_metadata(raw[0], meta2)


+ 18
- 18
tests/test_cmdline.py View File

@@ -13,7 +13,7 @@ import itertools
import os
import re
import sys
import StringIO
import io
import shlex
import warnings

@@ -56,7 +56,7 @@ def teardown_module():

# Add an encoding property to StringIO so Python will convert Unicode
# properly when writing or reading.
class UTF8StringIO(StringIO.StringIO):
class UTF8StringIO(io.StringIO):
encoding = 'utf-8'

class TestCmdline(object):
@@ -91,7 +91,7 @@ class TestCmdline(object):
sys.exit(0)
except SystemExit as e:
exitcode = e.code
captured = nilmdb.utils.unicode.decode(outfile.getvalue())
captured = nilmdb.utils.str.decode(outfile.getvalue())
self.captured = captured
self.exitcode = exitcode

@@ -131,16 +131,16 @@ class TestCmdline(object):
with open(file) as f:
contents = f.read()
if contents != self.captured:
print "--- reference file (first 1000 bytes):\n"
print contents[0:1000] + "\n"
print "--- captured data (first 1000 bytes):\n"
print self.captured[0:1000] + "\n"
zipped = itertools.izip_longest(contents, self.captured)
print("--- reference file (first 1000 bytes):\n")
print(contents[0:1000] + "\n")
print("--- captured data (first 1000 bytes):\n")
print(self.captured[0:1000] + "\n")
zipped = itertools.zip_longest(contents, self.captured)
for (n, (a, b)) in enumerate(zipped):
if a != b:
print "--- first difference is at offset", n
print "--- reference:", repr(a)
print "--- captured:", repr(b)
print("--- first difference is at offset", n)
print("--- reference:", repr(a))
print("--- captured:", repr(b))
break
raise AssertionError("captured data doesn't match " + file)

@@ -818,18 +818,18 @@ class TestCmdline(object):
self.ok("destroy /newton/prep /newton/raw")
self.ok("destroy /newton/zzz")

self.ok(u"create /düsseldorf/raw uint16_6")
self.ok("create /düsseldorf/raw uint16_6")
self.ok("list -l --detail")
self.contain(u"/düsseldorf/raw uint16_6")
self.contain("/düsseldorf/raw uint16_6")
self.contain("(no intervals)")

# Unicode metadata
self.ok(u"metadata /düsseldorf/raw --set α=beta 'γ=δ'")
self.ok(u"metadata /düsseldorf/raw --update 'α=β ε τ α'")
self.ok(u"metadata /düsseldorf/raw")
self.match(u"α=β ε τ α\nγ=δ\n")
self.ok("metadata /düsseldorf/raw --set α=beta 'γ=δ'")
self.ok("metadata /düsseldorf/raw --update 'α=β ε τ α'")
self.ok("metadata /düsseldorf/raw")
self.match("α=β ε τ α\nγ=δ\n")

self.ok(u"destroy /düsseldorf/raw")
self.ok("destroy /düsseldorf/raw")

def test_13_files(self):
# Test BulkData's ability to split into multiple files,


+ 5
- 5
tests/test_interval.py View File

@@ -379,13 +379,13 @@ class TestIntervalTree:
# make a set of 100 intervals
iset = IntervalSet()
j = 100
for i in random.sample(xrange(j),j):
for i in random.sample(range(j),j):
interval = Interval(i, i+1)
iset += interval
render(iset, "Random Insertion")

# remove about half of them
for i in random.sample(xrange(j),j):
for i in random.sample(range(j),j):
if random.randint(0,1):
iset -= Interval(i, i+1)

@@ -397,7 +397,7 @@ class TestIntervalTree:
# make a set of 100 intervals, inserted in order
iset = IntervalSet()
j = 100
for i in xrange(j):
for i in range(j):
interval = Interval(i, i+1)
iset += interval
render(iset, "In-order insertion")
@@ -410,14 +410,14 @@ class TestIntervalSpeed:
import random
import math

print
print()
yappi.start()
speeds = {}
limit = 22 # was 20
for j in [ 2**x for x in range(5,limit) ]:
start = time.time()
iset = IntervalSet()
for i in random.sample(xrange(j),j):
for i in random.sample(range(j),j):
interval = Interval(i, i+1)
iset += interval
speed = (time.time() - start) * 1000000.0


+ 2
- 2
tests/test_mustclose.py View File

@@ -8,12 +8,12 @@ from nose.tools import assert_raises
from testutil.helpers import *

import sys
import cStringIO
import io
import gc

import inspect

err = cStringIO.StringIO()
err = io.StringIO()

@nilmdb.utils.must_close(errorfile = err)
class Foo:


+ 5
- 4
tests/test_nilmdb.py View File

@@ -8,9 +8,10 @@ import itertools
import os
import sys
import threading
import urllib2
from urllib2 import urlopen, HTTPError
import cStringIO
import urllib.request, urllib.error, urllib.parse
from urllib.request import urlopen
from urllib.error import HTTPError
import io
import time
import requests

@@ -34,7 +35,7 @@ class Test00Nilmdb(object): # named 00 so it runs first
db.close()

# test timer, just to get coverage
capture = cStringIO.StringIO()
capture = io.StringIO()
old = sys.stdout
sys.stdout = capture
with nilmdb.utils.Timer("test"):


+ 1
- 1
tests/test_printf.py View File

@@ -3,7 +3,7 @@ from nilmdb.utils.printf import *

from nose.tools import *
from nose.tools import assert_raises
from cStringIO import StringIO
from io import StringIO
import sys

from testutil.helpers import *


+ 5
- 5
tests/test_rbtree.py View File

@@ -36,12 +36,12 @@ class TestRBTree:
# make a set of 100 intervals, inserted in order
rb = RBTree()
j = 100
for i in xrange(j):
for i in range(j):
rb.insert(RBNode(i, i+1))
render(rb, "in-order insert")

# remove about half of them
for i in random.sample(xrange(j),j):
for i in random.sample(range(j),j):
if random.randint(0,1):
rb.delete(rb.find(i, i+1))
render(rb, "in-order insert, random delete")
@@ -49,18 +49,18 @@ class TestRBTree:
# make a set of 100 intervals, inserted at random
rb = RBTree()
j = 100
for i in random.sample(xrange(j),j):
for i in random.sample(range(j),j):
rb.insert(RBNode(i, i+1))
render(rb, "random insert")

# remove about half of them
for i in random.sample(xrange(j),j):
for i in random.sample(range(j),j):
if random.randint(0,1):
rb.delete(rb.find(i, i+1))
render(rb, "random insert, random delete")

# in-order insert of 50 more
for i in xrange(50):
for i in range(50):
rb.insert(RBNode(i+500, i+501))
render(rb, "random insert, random delete, in-order insert")



+ 2
- 2
tests/test_serializer.py View File

@@ -50,7 +50,7 @@ class Base(object):
def func(foo):
foo.test()
threads = []
for i in xrange(20):
for i in range(20):
threads.append(threading.Thread(target = func, args = (self.foo,)))
for t in threads:
t.start()
@@ -76,7 +76,7 @@ class ListLike(object):
eq_(threading.current_thread().name, self.thread)
return key

def next(self):
def __next__(self):
eq_(threading.current_thread().name, self.thread)
if self.foo < 5:
self.foo += 1


+ 8
- 8
tests/test_timestamper.py View File

@@ -6,7 +6,7 @@ from nose.tools import *
from nose.tools import assert_raises
import os
import sys
import cStringIO
import io

from testutil.helpers import *

@@ -29,20 +29,20 @@ class TestTimestamper(object):
"1332561600000250 hello world" ]

# full
input = cStringIO.StringIO(join(lines_in))
input = io.StringIO(join(lines_in))
ts = timestamper.TimestamperRate(input, start, 8000)
foo = ts.readlines()
eq_(foo, join(lines_out))
in_("TimestamperRate(..., start=", str(ts))

# first 30 or so bytes means the first 2 lines
input = cStringIO.StringIO(join(lines_in))
input = io.StringIO(join(lines_in))
ts = timestamper.TimestamperRate(input, start, 8000)
foo = ts.readlines(30)
eq_(foo, join(lines_out[0:2]))

# stop iteration early
input = cStringIO.StringIO(join(lines_in))
input = io.StringIO(join(lines_in))
ts = timestamper.TimestamperRate(input, start, 8000,
1332561600000200)
foo = ""
@@ -51,21 +51,21 @@ class TestTimestamper(object):
eq_(foo, join(lines_out[0:2]))

# stop iteration early (readlines)
input = cStringIO.StringIO(join(lines_in))
input = io.StringIO(join(lines_in))
ts = timestamper.TimestamperRate(input, start, 8000,
1332561600000200)
foo = ts.readlines()
eq_(foo, join(lines_out[0:2]))

# stop iteration really early
input = cStringIO.StringIO(join(lines_in))
input = io.StringIO(join(lines_in))
ts = timestamper.TimestamperRate(input, start, 8000,
1332561600000000)
foo = ts.readlines()
eq_(foo, "")

# use iterator
input = cStringIO.StringIO(join(lines_in))
input = io.StringIO(join(lines_in))
ts = timestamper.TimestamperRate(input, start, 8000)
foo = ""
for line in ts:
@@ -73,7 +73,7 @@ class TestTimestamper(object):
eq_(foo, join(lines_out))

# check that TimestamperNow gives similar result
input = cStringIO.StringIO(join(lines_in))
input = io.StringIO(join(lines_in))
ts = timestamper.TimestamperNow(input)
foo = ts.readlines()
ne_(foo, join(lines_out))


+ 1
- 1
tests/testutil/helpers.py View File

@@ -3,7 +3,7 @@
import shutil, os

def myrepr(x):
if isinstance(x, basestring):
if isinstance(x, str):
return '"' + x + '"'
else:
return repr(x)


Loading…
Cancel
Save