summaryrefslogtreecommitdiffstats
path: root/Objects/classobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-04-05 14:24:32 (GMT)
committerGuido van Rossum <guido@python.org>1992-04-05 14:24:32 (GMT)
commit8dd79cf788d23bb2abdd5a6fd8557431e80cfe43 (patch)
tree20cf339b599e59b0aa1a7280c0406bd538b2d384 /Objects/classobject.c
parent5113f5fd346c32c98ac46d374e0b5c3dced289a6 (diff)
downloadcpython-8dd79cf788d23bb2abdd5a6fd8557431e80cfe43.zip
cpython-8dd79cf788d23bb2abdd5a6fd8557431e80cfe43.tar.gz
cpython-8dd79cf788d23bb2abdd5a6fd8557431e80cfe43.tar.bz2
Don't allow assignment to attributes named __*__
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r--Objects/classobject.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index a4270e0..ed0e6f4 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
+Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
All Rights Reserved
@@ -106,7 +106,7 @@ class_getattr(op, name)
int i;
for (i = 0; i < n; i++) {
v = class_getattr((classobject *)
- gettupleitem(op->cl_bases, i), name);
+ gettupleitem(op->cl_bases, i), name);
if (v != NULL)
return v;
err_clear();
@@ -122,6 +122,13 @@ class_setattr(op, name, v)
char *name;
object *v;
{
+ if (name[0] == '_' && name[1] == '_') {
+ int n = strlen(name);
+ if (name[n-1] == '_' && name[n-2] == '_') {
+ err_setstr(TypeError, "read-only special attribute");
+ return -1;
+ }
+ }
if (v == NULL)
return dictremove(op->cl_methods, name);
else
@@ -226,6 +233,13 @@ instance_setattr(inst, name, v)
char *name;
object *v;
{
+ if (name[0] == '_' && name[1] == '_') {
+ int n = strlen(name);
+ if (name[n-1] == '_' && name[n-2] == '_') {
+ err_setstr(TypeError, "read-only special attribute");
+ return -1;
+ }
+ }
if (v == NULL)
return dictremove(inst->in_attr, name);
else