Fix copyright (recent file changes)
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 26 Feb 2014 15:10:58 +0000 (17:10 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 26 Feb 2014 15:10:58 +0000 (17:10 +0200)
kamaki/cli/commands/__init__.py
kamaki/cli/commands/pithos.py
kamaki/cli/config/__init__.py
kamaki/cli/utils/__init__.py

index ed22039..d0b6a65 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2011-2013 GRNET S.A. All rights reserved.
+# Copyright 2011-2014 GRNET S.A. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or
 # without modification, are permitted provided that the following
index 7b41b4f..6bc3224 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2011-2013 GRNET S.A. All rights reserved.
+# Copyright 2011-2014 GRNET S.A. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or
 # without modification, are permitted provided that the following
index a03c7a3..f13f754 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2011-2013 GRNET S.A. All rights reserved.
+# Copyright 2011-2014 GRNET S.A. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or
 # without modification, are permitted provided that the following
index 56269f4..7909302 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2011-2013 GRNET S.A. All rights reserved.
+# Copyright 2011-2014 GRNET S.A. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or
 # without modification, are permitted provided that the following
@@ -35,11 +35,15 @@ from sys import stdout, stdin
 from re import compile as regex_compile
 from os import walk, path
 from json import dumps
+from kamaki.cli.logger import get_logger
+from locale import getpreferredencoding
 
 from kamaki.cli.errors import raiseCLIError
 
 
 INDENT_TAB = 4
+log = get_logger(__name__)
+pref_enc = getpreferredencoding()
 
 
 suggest = dict(ansicolors=dict(
@@ -56,6 +60,45 @@ except ImportError:
     suggest['ansicolors']['active'] = True
 
 
+def _encode_nicely(somestr, encoding, replacement='?'):
+    """Encode somestr as 'encoding', but don't raise errors (replace with ?)
+        This method is slow. Us it only for grace.
+        :param encoding: (str) encode every character in this encoding
+        :param replacement: (char) replace each char raising encode-decode errs
+    """
+    newstr, err_counter = '', 0
+    for c in somestr:
+        try:
+            newc = c.encode(encoding)
+            newstr = '%s%s' % (newstr, newc)
+        except UnicodeError:
+            newstr = '%s%s' % (newstr, replacement)
+            err_counter += 1
+    if err_counter:
+        log.debug('\t%s character%s failed to be encoded as %s' % (
+            err_counter, 's' if err_counter > 1 else '', encoding))
+    return newstr
+
+
+def DontRaiseUnicodeError(foo):
+    def wrap(self, *args, **kwargs):
+        try:
+            s = kwargs.pop('s')
+        except KeyError:
+            try:
+                s = args[0]
+            except IndexError:
+                return foo(self, *args, **kwargs)
+            args = args[1:]
+        try:
+            s = s.encode(pref_enc)
+        except UnicodeError as ue:
+            log.debug('Encoding(%s): %s' % (pref_enc, ue))
+            s = _encode_nicely(s, pref_enc, replacement='?')
+        return foo(self, s, *args, **kwargs)
+    return wrap
+
+
 def suggest_missing(miss=None, exclude=[]):
     global suggest
     sgs = dict(suggest)
@@ -424,7 +467,7 @@ def filter_dicts_by_dict(
     :param exact_match: (bool) if false, check if the filter value is part of
         the actual value
 
-    :param case_sensitive: (bool) revers to values only (not keys)
+    :param case_sensitive: (bool) refers to values only (not keys)
 
     :returns: (list) only the dicts that match all filters
     """