Re: Possible to create a read-only complex object?
On 7/11/2010 12:51 PM, pyt...@bdurham.com wrote: I have a complex object with attributes that contain lists, sets, dictionaries, and other objects. The lists and dictionaries may themselves contain complex objects. I would like to provide a read-only version of this type of object for other developers to query for reporting. Is there a way to prevent other developers from changing the attributes of my complex and nested object? In researching this question, I have identified __setattr__ and __delattr__ as possible ways to prevent changes to simple attributes, but I don't believe these magic methods will prevent others from fiddling with attributes containing lists and dictionaries or the contents of these lists and dictionaries. Python was not really not developed for multi-developer projects whose members are willing to stomp on each others objects. Another idea I had was to create a wrapper object to proxy all access to the original object. Is there a generic reciepe for this type of wrapper? -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible to create a read-only complex object?
On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: On 7/11/2010 12:51 PM, pyt...@bdurham.com wrote: I have a complex object with attributes that contain lists, sets, dictionaries, and other objects. The lists and dictionaries may themselves contain complex objects. I would like to provide a read-only version of this type of object for other developers to query for reporting. Is there a way to prevent other developers from changing the attributes of my complex and nested object? In researching this question, I have identified __setattr__ and __delattr__ as possible ways to prevent changes to simple attributes, but I don't believe these magic methods will prevent others from fiddling with attributes containing lists and dictionaries or the contents of these lists and dictionaries. Python was not really not developed for multi-developer projects whose members are willing to stomp on each others objects. I like the idea of competition-driven development, where the code that survives best in the face of hostile developers gets used. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible to create a read-only complex object?
On Mon, Jul 12, 2010 at 12:45 AM, Steven D'Aprano steve-remove-t...@cybersource.com.au wrote: On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: On 7/11/2010 12:51 PM, pyt...@bdurham.com wrote: I have a complex object with attributes that contain lists, sets, dictionaries, and other objects. The lists and dictionaries may themselves contain complex objects. I would like to provide a read-only version of this type of object for other developers to query for reporting. Is there a way to prevent other developers from changing the attributes of my complex and nested object? In researching this question, I have identified __setattr__ and __delattr__ as possible ways to prevent changes to simple attributes, but I don't believe these magic methods will prevent others from fiddling with attributes containing lists and dictionaries or the contents of these lists and dictionaries. Python was not really not developed for multi-developer projects whose members are willing to stomp on each others objects. I like the idea of competition-driven development, where the code that survives best in the face of hostile developers gets used. http://en.wikipedia.org/wiki/Defensive_programming Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible to create a read-only complex object?
On Mon, 12 Jul 2010 01:11:53 -0700, Chris Rebert wrote: On Mon, Jul 12, 2010 at 12:45 AM, Steven D'Aprano steve-remove-t...@cybersource.com.au wrote: On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: On 7/11/2010 12:51 PM, pyt...@bdurham.com wrote: I have a complex object with attributes that contain lists, sets, dictionaries, and other objects. The lists and dictionaries may themselves contain complex objects. I would like to provide a read-only version of this type of object for other developers to query for reporting. Is there a way to prevent other developers from changing the attributes of my complex and nested object? In researching this question, I have identified __setattr__ and __delattr__ as possible ways to prevent changes to simple attributes, but I don't believe these magic methods will prevent others from fiddling with attributes containing lists and dictionaries or the contents of these lists and dictionaries. Python was not really not developed for multi-developer projects whose members are willing to stomp on each others objects. I like the idea of competition-driven development, where the code that survives best in the face of hostile developers gets used. http://en.wikipedia.org/wiki/Defensive_programming Meh, defensive programming is designed to deal with bugs and hostile outsiders. I mean writing your functions and classes to deal with actively hostile coding *partners* who are trying to destroy your class so their class will survive to fight another day... There's probably a Dilbert cartoon about it. I'm not serious of course, if the members of your project are trying to screw your code, you're in trouble. I just like the idea of competition- driven development being the next buzzword, for when agile, test-driven, or pair-programming development is no longer enough. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible to create a read-only complex object?
On Mon, Jul 12, 2010 at 3:45 AM, Steven D'Aprano steve-remove-t...@cybersource.com.au wrote: On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: On 7/11/2010 12:51 PM, pyt...@bdurham.com wrote: I have a complex object with attributes that contain lists, sets, dictionaries, and other objects. The lists and dictionaries may themselves contain complex objects. I would like to provide a read-only version of this type of object for other developers to query for reporting. Is there a way to prevent other developers from changing the attributes of my complex and nested object? In researching this question, I have identified __setattr__ and __delattr__ as possible ways to prevent changes to simple attributes, but I don't believe these magic methods will prevent others from fiddling with attributes containing lists and dictionaries or the contents of these lists and dictionaries. Python was not really not developed for multi-developer projects whose members are willing to stomp on each others objects. I like the idea of competition-driven development, where the code that survives best in the face of hostile developers gets used. You jest, but I've actually done this. The goal was to test security awareness among developers- we formed two tiger teams, one to develop code and one to exploit it, and had one member of the developer group as a saboteur. His goal was to put in the largest possible vulnerability without getting caught, while the others wanted to produce the most secure code they could that met spec. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Possible to create a read-only complex object?
I have a complex object with attributes that contain lists, sets, dictionaries, and other objects. The lists and dictionaries may themselves contain complex objects. I would like to provide a read-only version of this type of object for other developers to query for reporting. Is there a way to prevent other developers from changing the attributes of my complex and nested object? In researching this question, I have identified __setattr__ and __delattr__ as possible ways to prevent changes to simple attributes, but I don't believe these magic methods will prevent others from fiddling with attributes containing lists and dictionaries or the contents of these lists and dictionaries. Another idea I had was to create a wrapper object to proxy all access to the original object. Is there a generic reciepe for this type of wrapper? Thank you, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible to create a read-only complex object?
On Sun, Jul 11, 2010 at 9:51 AM, pyt...@bdurham.com wrote: I have a complex object with attributes that contain lists, sets, dictionaries, and other objects. The lists and dictionaries may themselves contain complex objects. I would like to provide a read-only version of this type of object for other developers to query for reporting. Is there a way to prevent other developers from changing the attributes of my complex and nested object? Have you considered just making a deep copy of your object instead? That way, others could inspect the copy and mess with it all they want, without affecting the original. http://docs.python.org/library/copy.html#copy.deepcopy Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list