gen_misc.py python3 changes

- ConfigParser
- StringIO
- Modify use of "long" which is not supported in python3

Change-Id: Ifa6ade055f87154e8efa492b27c0c8ad98357215
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/gen_misc.py b/lib/gen_misc.py
index 0979cb9..d43aa20 100755
--- a/lib/gen_misc.py
+++ b/lib/gen_misc.py
@@ -8,11 +8,15 @@
 import sys
 import errno
 import os
-import ConfigParser
+import collections
+try:
+    import ConfigParser
+except ImportError:
+    import configparser
 try:
     import StringIO
 except ImportError:
-    from io import StringIO
+    import io
 import re
 import socket
 import tempfile
@@ -28,6 +32,7 @@
 robot_env = gp.robot_env
 if robot_env:
     from robot.libraries.BuiltIn import BuiltIn
+    from robot.utils import DotDict
 
 
 def add_trailing_slash(dir_path):
@@ -204,7 +209,11 @@
     # get ConfigParser.MissingSectionHeaderError).  Properties files don't
     # need those so I'll write a dummy section header.
 
-    string_file = StringIO.StringIO()
+    try:
+        string_file = StringIO.StringIO()
+    except NameError:
+        string_file = io.StringIO()
+
     # Write the dummy section header to the string file.
     string_file.write('[dummysection]\n')
     # Write the entire contents of the properties file to the string file.
@@ -213,13 +222,19 @@
     string_file.seek(0, os.SEEK_SET)
 
     # Create the ConfigParser object.
-    config_parser = ConfigParser.ConfigParser()
+    try:
+        config_parser = ConfigParser.ConfigParser()
+    except NameError:
+        config_parser = configparser.ConfigParser()
     # Make the property names case-sensitive.
     config_parser.optionxform = str
     # Read the properties from the string file.
     config_parser.readfp(string_file)
     # Return the properties as a dictionary.
-    return dict(config_parser.items('dummysection'))
+    if robot_env:
+        return DotDict(config_parser.items('dummysection'))
+    else:
+        return collections.OrderedDict(config_parser.items('dummysection'))
 
 
 def file_to_list(file_path,
@@ -368,7 +383,7 @@
 
 
 def to_signed(number,
-              bit_width=gp.bit_length(long(sys.maxsize)) + 1):
+              bit_width=None):
     r"""
     Convert number to a signed number and return the result.
 
@@ -403,6 +418,12 @@
                                     multiple of 32.
     """
 
+    if bit_width is None:
+        try:
+            bit_width = gp.bit_length(long(sys.maxsize)) + 1
+        except NameError:
+            bit_width = gp.bit_length(int(sys.maxsize)) + 1
+
     if number < 0:
         return number
     neg_bit_mask = 2**(bit_width - 1)