Commits

Jan Brohl committed baa923f

regex in util sodass sie nicht mehr so viel müll miterkennen

Comments (0)

Files changed (1)

src/simplerest/util.py

 import datetime
 import codecs
 from UserDict import DictMixin
-datere = re.compile(u"([0-9]{1,4})-([01]?[0-9])-([0-3]?[0-9])$")
-timere = re.compile(u"([0-2]?[0-9]):([0-6]?[0-9]):([0-6]?[0-9])$")
-datetimere = re.compile(u"([0-9]{1,4})-([01]?[0-9])-([0-3]?[0-9]).([0-2]?[0-9]):([0-6]?[0-9]):([0-6]?[0-9])$")
-intre = re.compile(u"[+-]?0|(?:[1-9][0-9]*)$")
-floatre = re.compile(u"((?:[+-]?0|(?:[1-9][0-9]*))?)[.,]([0-9]+)(?:[Ee]|(?:[*]10[^])([+-]?0|(?:[1-9][0-9]*)))?$")  #TODO: mehr formate
+datere = re.compile(u"(?:([0-9]{1,4})-([01]?[0-9])-([0-3]?[0-9]))$")
+timere = re.compile(u"(?:([0-2]?[0-9]):([0-6]?[0-9]):([0-6]?[0-9]))$")
+datetimere = re.compile(u"(?:([0-9]{1,4})-([01]?[0-9])-([0-3]?[0-9]).([0-2]?[0-9]):([0-6]?[0-9]):([0-6]?[0-9]))$")
+intre = re.compile(u"(?:[+-]?0|(?:[1-9][0-9]*))$")
+floatre = re.compile(u"(?:((?:[+-]?0|(?:[1-9][0-9]*))?)[.,]([0-9]+)(?:[Ee]|(?:[*]10[^])([+-]?0|(?:[1-9][0-9]*)))?)$")  #TODO: mehr formate
 numstartre = re.compile(u"[+-]?[.]?[0-9]")
 type_charsetre = re.compile('(?P<maintype>\\S+?)/(?P<subtype>\\S+?)(?:;\\s*charset=(?P<charset>\\S+))')
 
     """
     Convert String value if possible in a safe way
     """
-    if isinstance(s, basestring) and numstartre.match(s) is not None:
+    if isinstance(s, basestring) and numstartre.match(s):
         try:
             m = datetimere.match(s)
             if m is not None:
             m = intre.match(s)
             if m is not None:
                 cls = int
-                return int(m.group())
+                return int(m.group(), 10)
             m = floatre.match(s)
             if m is not None:
                 cls = float
     for k, v in obj.items():
         if v is not None:
             if isinstance(v, basestring):
+                if k == "internal_id":
+                    print k, v
                 v = convert(v)
             elif isinstance(v, dict):
                 v = default_hook(v)