Trees | Indices | Help |
---|
|
1 # 2 # Copyright (c) 2008--2018 Red Hat, Inc. 3 # 4 # This software is licensed to you under the GNU General Public License, 5 # version 2 (GPLv2). There is NO WARRANTY for this software, express or 6 # implied, including the implied warranties of MERCHANTABILITY or FITNESS 7 # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 8 # along with this software; if not, see 9 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 10 # 11 # Red Hat trademarks are not licensed under GPLv2. No permission is 12 # granted to use or replicate Red Hat trademarks that are incorporated 13 # in this software or its documentation. 14 # 15 16 import os 17 import pwd 18 import sys 19 24 25 26 # If Object1 and Object2 have any common attributes, set the attribute in Object1 27 # to the value of the attribute in Object2. Does not make functions or variables starting with '_' equivalent.29 30 # Go through every attribute in object1 31 for attr in object1.__dict__.keys(): 32 33 # Make sure that the attribute name doesn't begin with "_" 34 if not attr or attr[0] == "_": 35 continue 36 37 # Make sure that object2 has the attribute as well. and that it's not equal to ''. 38 if attr not in object2.__dict__ or object2.__dict__[attr] == '': 39 continue 40 41 # Make sure the attributes are the same type OR that the attribute in object1 is None. 42 if isinstance(object1.__dict__[attr], (type(object2.__dict__[attr]), type(None))): 43 if object1.__dict__[attr] != object2.__dict__[attr]: 44 object1.__dict__[attr] = object2.__dict__[attr] 45 else: 46 continue 47 else: 48 continue 49 50 return (object1, object2)51 52 53 # Pylint is too stupid to understand subclasses of tuples apparently. 54 # This is just to make it shut up.56 ret = [] 57 if hasattr(urlparse_object, 'scheme'): 58 ret.append(urlparse_object.scheme) 59 ret.append(urlparse_object.netloc) 60 ret.append(urlparse_object.path) 61 ret.append(urlparse_object.params) 62 ret.append(urlparse_object.query) 63 ret.append(urlparse_object.fragment) 64 else: 65 ret = [urlparse_object[i] for i in range(0, 6)] 66 67 if sys.version_info[0] == 3: 68 for i in range(0, 6): 69 if not isinstance(ret[i], str): 70 ret[i] = ret[i].decode('ascii') 71 return tuple(ret)72 73 if __name__ == "__main__": 74 # This is just for testing purposes. 75 # pylint: disable=R0903 80 85 86 obj1 = class1() 87 obj2 = class2() 88 89 obj1, obj2 = make_common_attr_equal(obj1, obj2) 90 91 print(obj1.a) 92 print(obj2.a) 93
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Wed Mar 4 07:37:47 2020 | http://epydoc.sourceforge.net |