Refactored the binplistlib.py module to get rid of some code style issues.

Sat, 05 Sep 2015 15:25:59 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 05 Sep 2015 15:25:59 +0200
changeset 4436
52ec6b6b3432
parent 4435
9f6555d3c3c0
child 4437
b9cc331a4576

Refactored the binplistlib.py module to get rid of some code style issues.

APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Utilities.binplistlib.html file | annotate | diff | comparison | revisions
Utilities/binplistlib.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric6.api	Sat Sep 05 15:13:13 2015 +0200
+++ b/APIs/Python3/eric6.api	Sat Sep 05 15:25:59 2015 +0200
@@ -8878,7 +8878,6 @@
 eric6.Utilities.binplistlib.PlistWriter.binaryInt?4(obj, bytes=None)
 eric6.Utilities.binplistlib.PlistWriter.binaryReal?4(obj)
 eric6.Utilities.binplistlib.PlistWriter.byteCounts?7
-eric6.Utilities.binplistlib.PlistWriter.check_key?4()
 eric6.Utilities.binplistlib.PlistWriter.computeOffsets?4(obj, asReference=False, isRoot=False)
 eric6.Utilities.binplistlib.PlistWriter.computedUniques?7
 eric6.Utilities.binplistlib.PlistWriter.file?7
@@ -8886,7 +8885,6 @@
 eric6.Utilities.binplistlib.PlistWriter.incrementByteCount?4(field, incr=1)
 eric6.Utilities.binplistlib.PlistWriter.intSize?4(obj)
 eric6.Utilities.binplistlib.PlistWriter.positionOfObjectReference?4(obj)
-eric6.Utilities.binplistlib.PlistWriter.proc_size?4()
 eric6.Utilities.binplistlib.PlistWriter.proc_variable_length?4(length)
 eric6.Utilities.binplistlib.PlistWriter.realSize?4(obj)
 eric6.Utilities.binplistlib.PlistWriter.referencePositions?7
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Sat Sep 05 15:13:13 2015 +0200
+++ b/Documentation/Help/source.qhp	Sat Sep 05 15:25:59 2015 +0200
@@ -8766,14 +8766,14 @@
       <keyword name="PlistReader.setCurrentOffsetToObjectNumber" id="PlistReader.setCurrentOffsetToObjectNumber" ref="eric6.Utilities.binplistlib.html#PlistReader.setCurrentOffsetToObjectNumber" />
       <keyword name="PlistWriter" id="PlistWriter" ref="eric6.Utilities.binplistlib.html#PlistWriter" />
       <keyword name="PlistWriter (Constructor)" id="PlistWriter (Constructor)" ref="eric6.Utilities.binplistlib.html#PlistWriter.__init__" />
+      <keyword name="PlistWriter.__checkKey" id="PlistWriter.__checkKey" ref="eric6.Utilities.binplistlib.html#PlistWriter.__checkKey" />
+      <keyword name="PlistWriter.__processSize" id="PlistWriter.__processSize" ref="eric6.Utilities.binplistlib.html#PlistWriter.__processSize" />
       <keyword name="PlistWriter.binaryInt" id="PlistWriter.binaryInt" ref="eric6.Utilities.binplistlib.html#PlistWriter.binaryInt" />
       <keyword name="PlistWriter.binaryReal" id="PlistWriter.binaryReal" ref="eric6.Utilities.binplistlib.html#PlistWriter.binaryReal" />
-      <keyword name="PlistWriter.check_key" id="PlistWriter.check_key" ref="eric6.Utilities.binplistlib.html#PlistWriter.check_key" />
       <keyword name="PlistWriter.computeOffsets" id="PlistWriter.computeOffsets" ref="eric6.Utilities.binplistlib.html#PlistWriter.computeOffsets" />
       <keyword name="PlistWriter.incrementByteCount" id="PlistWriter.incrementByteCount" ref="eric6.Utilities.binplistlib.html#PlistWriter.incrementByteCount" />
       <keyword name="PlistWriter.intSize" id="PlistWriter.intSize" ref="eric6.Utilities.binplistlib.html#PlistWriter.intSize" />
       <keyword name="PlistWriter.positionOfObjectReference" id="PlistWriter.positionOfObjectReference" ref="eric6.Utilities.binplistlib.html#PlistWriter.positionOfObjectReference" />
-      <keyword name="PlistWriter.proc_size" id="PlistWriter.proc_size" ref="eric6.Utilities.binplistlib.html#PlistWriter.proc_size" />
       <keyword name="PlistWriter.proc_variable_length" id="PlistWriter.proc_variable_length" ref="eric6.Utilities.binplistlib.html#PlistWriter.proc_variable_length" />
       <keyword name="PlistWriter.realSize" id="PlistWriter.realSize" ref="eric6.Utilities.binplistlib.html#PlistWriter.realSize" />
       <keyword name="PlistWriter.reset" id="PlistWriter.reset" ref="eric6.Utilities.binplistlib.html#PlistWriter.reset" />
--- a/Documentation/Source/eric6.Utilities.binplistlib.html	Sat Sep 05 15:13:13 2015 +0200
+++ b/Documentation/Source/eric6.Utilities.binplistlib.html	Sat Sep 05 15:25:59 2015 +0200
@@ -649,15 +649,18 @@
 <td><a href="#PlistWriter.__init__">PlistWriter</a></td>
 <td>Constructor</td>
 </tr><tr>
+<td><a href="#PlistWriter.__checkKey">__checkKey</a></td>
+<td>Private method to check the validity of a key.</td>
+</tr><tr>
+<td><a href="#PlistWriter.__processSize">__processSize</a></td>
+<td>Private method to process a size.</td>
+</tr><tr>
 <td><a href="#PlistWriter.binaryInt">binaryInt</a></td>
 <td>Public method to pack an integer object.</td>
 </tr><tr>
 <td><a href="#PlistWriter.binaryReal">binaryReal</a></td>
 <td>Public method to pack a real object.</td>
 </tr><tr>
-<td><a href="#PlistWriter.check_key">check_key</a></td>
-<td></td>
-</tr><tr>
 <td><a href="#PlistWriter.computeOffsets">computeOffsets</a></td>
 <td>Public method to compute offsets of an object.</td>
 </tr><tr>
@@ -670,9 +673,6 @@
 <td><a href="#PlistWriter.positionOfObjectReference">positionOfObjectReference</a></td>
 <td>Public method to get the position of an object.</td>
 </tr><tr>
-<td><a href="#PlistWriter.proc_size">proc_size</a></td>
-<td></td>
-</tr><tr>
 <td><a href="#PlistWriter.proc_variable_length">proc_variable_length</a></td>
 <td></td>
 </tr><tr>
@@ -712,6 +712,37 @@
 <dd>
 file to write the plist data to (file object)
 </dd>
+</dl><a NAME="PlistWriter.__checkKey" ID="PlistWriter.__checkKey"></a>
+<h4>PlistWriter.__checkKey</h4>
+<b>__checkKey</b>(<i>key</i>)
+<p>
+        Private method to check the validity of a key.
+</p><dl>
+<dt><i>key</i></dt>
+<dd>
+key to be checked
+</dd>
+</dl><dl>
+<dt>Raises <b>InvalidPlistException</b>:</dt>
+<dd>
+raised to indicate an invalid
+            plist file
+</dd>
+</dl><a NAME="PlistWriter.__processSize" ID="PlistWriter.__processSize"></a>
+<h4>PlistWriter.__processSize</h4>
+<b>__processSize</b>(<i>size</i>)
+<p>
+        Private method to process a size.
+</p><dl>
+<dt><i>size</i></dt>
+<dd>
+size value to be processed (int)
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+processed size (int)
+</dd>
 </dl><a NAME="PlistWriter.binaryInt" ID="PlistWriter.binaryInt"></a>
 <h4>PlistWriter.binaryInt</h4>
 <b>binaryInt</b>(<i>obj, bytes=None</i>)
@@ -751,10 +782,7 @@
 <dd>
 serialized object (bytes)
 </dd>
-</dl><a NAME="PlistWriter.check_key" ID="PlistWriter.check_key"></a>
-<h4>PlistWriter.check_key</h4>
-<b>check_key</b>(<i></i>)
-<a NAME="PlistWriter.computeOffsets" ID="PlistWriter.computeOffsets"></a>
+</dl><a NAME="PlistWriter.computeOffsets" ID="PlistWriter.computeOffsets"></a>
 <h4>PlistWriter.computeOffsets</h4>
 <b>computeOffsets</b>(<i>obj, asReference=False, isRoot=False</i>)
 <p>
@@ -829,10 +857,7 @@
 <dd>
 position of the object (integer)
 </dd>
-</dl><a NAME="PlistWriter.proc_size" ID="PlistWriter.proc_size"></a>
-<h4>PlistWriter.proc_size</h4>
-<b>proc_size</b>(<i></i>)
-<a NAME="PlistWriter.proc_variable_length" ID="PlistWriter.proc_variable_length"></a>
+</dl><a NAME="PlistWriter.proc_variable_length" ID="PlistWriter.proc_variable_length"></a>
 <h4>PlistWriter.proc_variable_length</h4>
 <b>proc_variable_length</b>(<i>length</i>)
 <a NAME="PlistWriter.realSize" ID="PlistWriter.realSize"></a>
--- a/Utilities/binplistlib.py	Sat Sep 05 15:13:13 2015 +0200
+++ b/Utilities/binplistlib.py	Sat Sep 05 15:25:59 2015 +0200
@@ -778,6 +778,34 @@
         self.byteCounts = self.byteCounts._replace(
             **{field: self.byteCounts.__getattribute__(field) + incr})
 
+    def __checkKey(self, key):
+        """
+        Private method to check the validity of a key.
+        
+        @param key key to be checked
+        @exception InvalidPlistException raised to indicate an invalid
+            plist file
+        """
+        if key is None:
+            raise InvalidPlistException(
+                'Dictionary keys cannot be null in plists.')
+        elif isinstance(key, Data):
+            raise InvalidPlistException(
+                'Data cannot be dictionary keys in plists.')
+        elif not isinstance(key, str):
+            raise InvalidPlistException('Keys must be strings.')
+    
+    def __processSize(self, size):
+        """
+        Private method to process a size.
+        
+        @param size size value to be processed (int)
+        @return processed size (int)
+        """
+        if size > 0b1110:
+            size += self.intSize(size)
+        return size
+    
     def computeOffsets(self, obj, asReference=False, isRoot=False):
         """
         Public method to compute offsets of an object.
@@ -787,22 +815,7 @@
         @param isRoot flag indicating a root object (boolean)
         @exception InvalidPlistException raised to indicate an invalid
             plist file
-        """                                             # __IGNORE_WARNING__
-        def check_key(key):
-            if key is None:
-                raise InvalidPlistException(
-                    'Dictionary keys cannot be null in plists.')
-            elif isinstance(key, Data):
-                raise InvalidPlistException(
-                    'Data cannot be dictionary keys in plists.')
-            elif not isinstance(key, str):
-                raise InvalidPlistException('Keys must be strings.')
-        
-        def proc_size(size):
-            if size > 0b1110:
-                size += self.intSize(size)
-            return size
-        
+        """
         # If this should be a reference, then we keep a record of it in the
         # uniques table.
         if asReference:
@@ -827,28 +840,28 @@
         elif isinstance(obj, datetime.datetime):
             self.incrementByteCount('dateBytes', incr=2)
         elif isinstance(obj, Data):
-            size = proc_size(len(obj))
+            size = self.__processSize(len(obj))
             self.incrementByteCount('dataBytes', incr=1 + size)
         elif isinstance(obj, str):
-            size = proc_size(len(obj))
+            size = self.__processSize(len(obj))
             self.incrementByteCount('stringBytes', incr=1 + size)
         elif isinstance(obj, HashableWrapper):
             obj = obj.value
             if isinstance(obj, set):
-                size = proc_size(len(obj))
+                size = self.__processSize(len(obj))
                 self.incrementByteCount('setBytes', incr=1 + size)
                 for value in obj:
                     self.computeOffsets(value, asReference=True)
             elif isinstance(obj, (list, tuple)):
-                size = proc_size(len(obj))
+                size = self.__processSize(len(obj))
                 self.incrementByteCount('arrayBytes', incr=1 + size)
                 for value in obj:
                     self.computeOffsets(value, asReference=True)
             elif isinstance(obj, dict):
-                size = proc_size(len(obj))
+                size = self.__processSize(len(obj))
                 self.incrementByteCount('dictBytes', incr=1 + size)
                 for key, value in obj.items():
-                    check_key(key)
+                    self.__checkKey(key)
                     self.computeOffsets(key, asReference=True)
                     self.computeOffsets(value, asReference=True)
         else:

eric ide

mercurial