dabo Commit
Revision 6052
Date: 2010-10-02 11:26:19 -0700 (Sat, 02 Oct 2010)
Author: Ed
Trac: http://trac.dabodev.com/changeset/6052

Changed:
U   trunk/dabo/biz/dBizobj.py
U   trunk/dabo/dEvents.py
U   trunk/dabo/dObject.py
U   trunk/dabo/dPref.py
U   trunk/dabo/lib/connParser.py
U   trunk/dabo/lib/datanav/Page.py
U   trunk/dabo/lib/dates.py
U   trunk/dabo/lib/eventMixin.py
U   trunk/dabo/lib/propertyHelperMixin.py

Log:
First phase of removing/refactoring the use of dict.has_key() method, replaced 
with either try/except or the 'in' test. More to come.


Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py   2010-10-02 18:09:01 UTC (rev 6051)
+++ trunk/dabo/biz/dBizobj.py   2010-10-02 18:26:19 UTC (rev 6052)
@@ -2122,7 +2122,7 @@
                the current parent key. If not, creates one.
                """
                self.__currentCursorKey = val
-               if not self.__cursors.has_key(val):
+               if val not in self.__cursors:
                        self.createCursor()
 
 

Modified: trunk/dabo/dEvents.py
===================================================================
--- trunk/dabo/dEvents.py       2010-10-02 18:09:01 UTC (rev 6051)
+++ trunk/dabo/dEvents.py       2010-10-02 18:26:19 UTC (rev 6052)
@@ -103,10 +103,11 @@
 
 
        def __getattr__(self, att):
-               if self.EventData.has_key(att):
+               try:
                        return self._eventData[att]
-               raise AttributeError("%s.%s object has no attribute %s." % (
-                       self.__class__.__module__, self.__class__.__name__, 
att))
+               except KeyError:
+                       raise AttributeError("%s.%s object has no attribute 
%s." % (
+                                       self.__class__.__module__, 
self.__class__.__name__, att))
 
 
        def _getContinue(self):

Modified: trunk/dabo/dObject.py
===================================================================
--- trunk/dabo/dObject.py       2010-10-02 18:09:01 UTC (rev 6051)
+++ trunk/dabo/dObject.py       2010-10-02 18:26:19 UTC (rev 6052)
@@ -226,7 +226,7 @@
                for c in cls.__mro__:
                        for item in dir(c):
                                if item[0] in string.lowercase:
-                                       if c.__dict__.has_key(item):
+                                       if item in c.__dict__:
                                                if type(c.__dict__[item]) in 
(types.MethodType, types.FunctionType):
                                                        if 
methodList.count(item) == 0:
                                                                
methodList.append(item)

Modified: trunk/dabo/dPref.py
===================================================================
--- trunk/dabo/dPref.py 2010-10-02 18:09:01 UTC (rev 6051)
+++ trunk/dabo/dPref.py 2010-10-02 18:26:19 UTC (rev 6052)
@@ -88,35 +88,36 @@
 
        def __getattr__(self, att):
                if att in regularAtts:
-                       if self.__dict__.has_key(att):
+                       try:
                                return self.__dict__[att]
-                       else:
+                       except KeyError:
                                return None
-               if self.__dict__.has_key(att):
+               try:
                        ret = self.__dict__[att]
-               elif self._cache.has_key(att):
-                       ret = self._cache[att]
-               else:
-                       # See if it's in the database
-                       key = self._getKey()
-                       if key:
-                               param = "%s.%s" % (key, att)
-                       else:
-                               param = att
-                       crs = self._cursor
+               except KeyError:
                        try:
-                               crs.execute("select ctype, cvalue from 
daboprefs where ckey = ? ", (param, ))
-                               rec = crs.getCurrentRecord()
-                       except StandardError, e:
-                               print "QUERY ERR", e
-                               rec = {}
-                       if rec:
-                               ret = self._decodeType(rec)
-                       else:
-                               ret = dPref(crs=self._cursor, cxn = self._cxn)
-                               ret._parent = self
-                               ret._key = att
-                       self._cache[att] = ret
+                               ret = self._cache[att]
+                       except KeyError:
+                               # See if it's in the database
+                               key = self._getKey()
+                               if key:
+                                       param = "%s.%s" % (key, att)
+                               else:
+                                       param = att
+                               crs = self._cursor
+                               try:
+                                       crs.execute("select ctype, cvalue from 
daboprefs where ckey = ? ", (param, ))
+                                       rec = crs.getCurrentRecord()
+                               except StandardError, e:
+                                       print "QUERY ERR", e
+                                       rec = {}
+                               if rec:
+                                       ret = self._decodeType(rec)
+                               else:
+                                       ret = dPref(crs=self._cursor, cxn = 
self._cxn)
+                                       ret._parent = self
+                                       ret._key = att
+                               self._cache[att] = ret
                return ret
 
 
@@ -270,12 +271,12 @@
                                crs.execute("delete from daboprefs where ckey 
like ? ", (key, ))
                        else:
                                crs.execute("delete from daboprefs where ckey = 
? ", (key, ))
-                       if self._cache.has_key(att):
-                               del self._cache[att]
                else:
                        self._deletionCache[key] = None
-                       if self._cache.has_key(att):
-                               del self._cache[att]
+               try:
+                       del self._cache[att]
+               except KeyError:
+                       pass
                self._cursor.commitTransaction()
 
 

Modified: trunk/dabo/lib/connParser.py
===================================================================
--- trunk/dabo/lib/connParser.py        2010-10-02 18:09:01 UTC (rev 6051)
+++ trunk/dabo/lib/connParser.py        2010-10-02 18:26:19 UTC (rev 6052)
@@ -40,7 +40,7 @@
 
        def characters(self, content):
                if self.element:
-                       if self.currDict.has_key(self.element):
+                       if self.element in self.currDict:
                                self.currDict[self.element] += content
 
 
@@ -118,7 +118,7 @@
        a 'connection' XML element.
        """
        try:
-               if not d.has_key("name"):
+               if "name" not in d:
                        if not d["user"]:
                                d["user"] = "anybody"
                        if not d["host"]:

Modified: trunk/dabo/lib/datanav/Page.py
===================================================================
--- trunk/dabo/lib/datanav/Page.py      2010-10-02 18:09:01 UTC (rev 6051)
+++ trunk/dabo/lib/datanav/Page.py      2010-10-02 18:26:19 UTC (rev 6052)
@@ -145,7 +145,7 @@
                mn = dabo.ui.dMenu()
                if self.sortFields:
                        mn.append(_("Show sort order"), 
OnHit=self.handleSortOrder)
-               if self.sortFields.has_key(self.sortDS):
+               if self.sortDS in self.sortFields:
                        mn.append(_("Remove sort on ") + self.sortCap,
                                        OnHit=self.handleSortRemove)
 
@@ -183,7 +183,7 @@
                                self.sortFields[key] = (newPos, 
self.sortFields[key][1], self.sortFields[key][2])
                                newPos += 1
                elif action != "show":
-                       if self.sortFields.has_key(self.sortDS):
+                       if self.sortDS in self.sortFields:
                                self.sortFields[self.sortDS] = 
(self.sortFields[self.sortDS][0],
                                                action, self.sortCap)
                        else:
@@ -244,7 +244,7 @@
                flds = self.selectFields.keys()
                whr = ""
                for fld in flds:
-                       if biz.VirtualFields.has_key(fld):
+                       if fld in biz.VirtualFields:
                                #virtual field, save for later use and ignore
                                self.__virtualFilters.append(fld)
                                continue
@@ -359,7 +359,7 @@
 
 
        def setLimit(self, biz):
-               if self.selectFields.has_key("limit"):
+               if "limit" in self.selectFields:
                        
biz.setLimitClause(self.selectFields["limit"]["ctrl"].Value)
 
 

Modified: trunk/dabo/lib/dates.py
===================================================================
--- trunk/dabo/lib/dates.py     2010-10-02 18:09:01 UTC (rev 6051)
+++ trunk/dabo/lib/dates.py     2010-10-02 18:26:19 UTC (rev 6052)
@@ -136,9 +136,9 @@
                m = regex.match(strVal)
                if m is not None:
                        groups = m.groupdict()
-                       if not groups.has_key("year"):
+                       if "year" not in groups.:
                                curYear = datetime.date.today().year
-                               if groups.has_key("shortyear"):
+                               if shortyear in groups:
                                        groups["year"] = int("%s%s" % 
(ustr(curYear)[:2],
                                                        groups["shortyear"]))
                                else:
@@ -191,12 +191,12 @@
                if m is not None:
                        groups = m.groupdict()
                        for skip_group in ["ms", "second", "minute", "hour"]:
-                               if not groups.has_key(skip_group) or 
len(groups[skip_group]) == 0:
+                               if (skip_group not in groups) or not 
groups[skip_group]:
                                        # group not in the expression: default 
to 0
                                        groups[skip_group] = 0
-                       if not groups.has_key("year"):
+                       if "year" not in groups:
                                curYear = datetime.date.today().year
-                               if groups.has_key("shortyear"):
+                               if shortyear in groups:
                                        groups["year"] = int("%s%s" % 
(ustr(curYear)[:2],
                                                        groups["shortyear"]))
                                else:

Modified: trunk/dabo/lib/eventMixin.py
===================================================================
--- trunk/dabo/lib/eventMixin.py        2010-10-02 18:09:01 UTC (rev 6051)
+++ trunk/dabo/lib/eventMixin.py        2010-10-02 18:26:19 UTC (rev 6052)
@@ -69,11 +69,11 @@
                        self.__raisedEvents.append(eventSig)
 
                eventData = None
-               if kwargs.has_key("eventData"):
+               if eventData in kwargs:
                        eventData = kwargs["eventData"]
                        del kwargs["eventData"]
                evtObject = self
-               if kwargs.has_key("eventObject"):
+               if eventObject in kwargs:
                        evtObject = kwargs["eventObject"]
                        del kwargs["eventObject"]
 

Modified: trunk/dabo/lib/propertyHelperMixin.py
===================================================================
--- trunk/dabo/lib/propertyHelperMixin.py       2010-10-02 18:09:01 UTC (rev 
6051)
+++ trunk/dabo/lib/propertyHelperMixin.py       2010-10-02 18:26:19 UTC (rev 
6052)
@@ -272,7 +272,7 @@
                                break
                        for item in dir(c):
                                if item[0] in string.uppercase:
-                                       if c.__dict__.has_key(item):
+                                       if item in c.__dict__:
                                                if type(c.__dict__[item]) == 
property:
                                                        if propList.count(item) 
== 0:
                                                                
propList.append(item)
@@ -324,7 +324,7 @@
                        d["type"] = type(propVal)
                        d["definedIn"] = None
                        for o in classRef.__mro__:
-                               if o.__dict__.has_key(name):
+                               if name in o.__dict__:
                                        d["definedIn"] = o
 
                        return d



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to