Commit 9d1b10d6 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Fix utf8 header

move it to the top of the file
parent 8906dd2e
# -*- coding: utf-8 -*-
# Copyright 2012 GRNET S.A. All rights reserved. # Copyright 2012 GRNET S.A. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or # Redistribution and use in source and binary forms, with or
...@@ -31,7 +32,6 @@ ...@@ -31,7 +32,6 @@
# interpreted as representing official policies, either expressed # interpreted as representing official policies, either expressed
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
# -*- coding: utf-8 -*-
from random import random, choice, randint from random import random, choice, randint
from math import log from math import log
from inspect import isclass from inspect import isclass
...@@ -50,7 +50,7 @@ def shorts(s): ...@@ -50,7 +50,7 @@ def shorts(s):
return s return s
return s[:61] + '...' return s[:61] + '...'
class CanonifyException(Exception): class CanonifyException(Exception):
pass pass
...@@ -133,7 +133,7 @@ class Canonical(object): ...@@ -133,7 +133,7 @@ class Canonical(object):
def _parse(self, item): def _parse(self, item):
raise NotImplementedError raise NotImplementedError
def create(self): def create(self):
return None return None
...@@ -170,7 +170,7 @@ class Canonical(object): ...@@ -170,7 +170,7 @@ class Canonical(object):
(k, v.tostring( depth=depth, (k, v.tostring( depth=depth,
showopts=showopts, showopts=showopts,
multiline=multiline))) multiline=multiline)))
for k, v in self.kw.items()] for k, v in self.kw.items()]
if showopts: if showopts:
args += [("%s=%s" % (k, str(v))) for k, v in self.opts.items()] args += [("%s=%s" % (k, str(v))) for k, v in self.opts.items()]
...@@ -315,7 +315,7 @@ class Text(Canonical): ...@@ -315,7 +315,7 @@ class Text(Canonical):
if minlen is not None and itemlen < minlen: if minlen is not None and itemlen < minlen:
m = "%s: len('%s') < minlen=%d" % (self, shorts(item), minlen) m = "%s: len('%s') < minlen=%d" % (self, shorts(item), minlen)
raise CanonifyException(m) raise CanonifyException(m)
matcher = self.matcher matcher = self.matcher
if matcher is not None: if matcher is not None:
match = matcher.match(item) match = matcher.match(item)
...@@ -414,7 +414,7 @@ class Bytes(Canonical): ...@@ -414,7 +414,7 @@ class Bytes(Canonical):
if minlen is not None and itemlen < minlen: if minlen is not None and itemlen < minlen:
m = "%s: len('%s') < minlen=%d" % (self, shorts(item), minlen) m = "%s: len('%s') < minlen=%d" % (self, shorts(item), minlen)
raise CanonifyException(m) raise CanonifyException(m)
matcher = self.matcher matcher = self.matcher
if matcher is not None: if matcher is not None:
match = matcher.match(item) match = matcher.match(item)
...@@ -526,7 +526,7 @@ class ListOf(Canonical): ...@@ -526,7 +526,7 @@ class ListOf(Canonical):
raise CanonifyException(m) raise CanonifyException(m)
return canonified return canonified
def random_listof(self, kw): def random_listof(self, kw):
z = randint(1, 4) z = randint(1, 4)
get_random = self.canonical.random get_random = self.canonical.random
...@@ -563,7 +563,7 @@ class Args(Canonical): ...@@ -563,7 +563,7 @@ class Args(Canonical):
parsed[key] = self.kw[key].parse(v) parsed[key] = self.kw[key].parse(v)
return parsed return parsed
def _check(self, item): def _check(self, item):
try: try:
item = OrderedDict(item) item = OrderedDict(item)
...@@ -572,13 +572,13 @@ class Args(Canonical): ...@@ -572,13 +572,13 @@ class Args(Canonical):
raise CanonifyException(m) raise CanonifyException(m)
canonified = OrderedDict() canonified = OrderedDict()
try: try:
for n, c in self.kw.items(): for n, c in self.kw.items():
t = item[n] if n in item else None t = item[n] if n in item else None
canonified[n] = c(t) canonified[n] = c(t)
except KeyError: except KeyError:
m = ("%s: Argument '%s' not found in '%s'" m = ("%s: Argument '%s' not found in '%s'"
% (self, shorts(n), shorts(item))) % (self, shorts(n), shorts(item)))
raise CanonifyException(m) raise CanonifyException(m)
...@@ -632,7 +632,7 @@ class Tuple(Canonical): ...@@ -632,7 +632,7 @@ class Tuple(Canonical):
g = (canonical.parse(element) g = (canonical.parse(element)
for canonical, (k, element) in zip(self.args, item)) for canonical, (k, element) in zip(self.args, item))
return tuple(g) return tuple(g)
def __add__(self, other): def __add__(self, other):
oargs = other.args if isinstance(other, Tuple) else (other,) oargs = other.args if isinstance(other, Tuple) else (other,)
args = self.args + oargs args = self.args + oargs
...@@ -661,7 +661,7 @@ class Dict(Canonical): ...@@ -661,7 +661,7 @@ class Dict(Canonical):
if n not in item: if n not in item:
m = "%s: key '%s' not found" % (self, shorts(n)) m = "%s: key '%s' not found" % (self, shorts(n))
raise CanonifyException(m) raise CanonifyException(m)
canonified[n] = c(item[n]) canonified[n] = c(item[n])
strict = self.opts.get('strict', True) strict = self.opts.get('strict', True)
if strict and len(item) != len(canonical): if strict and len(item) != len(canonical):
...@@ -701,7 +701,7 @@ class Dict(Canonical): ...@@ -701,7 +701,7 @@ class Dict(Canonical):
raise CanonifyException(m) raise CanonifyException(m)
return canonified return canonified
def random_dict(self, kw): def random_dict(self, kw):
item = {} item = {}
for n, c in self.canonical.items(): for n, c in self.canonical.items():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment