summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-12-10 14:00:03 (GMT)
committerGuido van Rossum <guido@python.org>1991-12-10 14:00:03 (GMT)
commit87e7ea72a6ef9232be9db06038943044c747971b (patch)
tree0482b0b111b4779a18f680db9a1c5bd10ca0005f /Objects
parent97ff5308fe3e490aac51316cf5575c6119227cc8 (diff)
downloadcpython-87e7ea72a6ef9232be9db06038943044c747971b.zip
cpython-87e7ea72a6ef9232be9db06038943044c747971b.tar.gz
cpython-87e7ea72a6ef9232be9db06038943044c747971b.tar.bz2
Use new exceptions.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/fileobject.c24
-rw-r--r--Objects/listobject.c4
-rw-r--r--Objects/longobject.c14
-rw-r--r--Objects/moduleobject.c4
4 files changed, 18 insertions, 28 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index b25615933..1f1dcae 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -95,7 +95,7 @@ newfileobject(name, mode)
#endif
f->f_fp = fopen(name, mode);
if (f->f_fp == NULL) {
- err_errno(RuntimeError);
+ err_errno(IOError);
DECREF(f);
return NULL;
}
@@ -166,7 +166,7 @@ file_close(f, args)
if (sts == EOF) {
if (errno == 0)
errno = EIO;
- return err_errno(RuntimeError);
+ return err_errno(IOError);
}
if (sts != 0)
return newintobject((long)sts);
@@ -198,7 +198,7 @@ file_seek(f, args)
if (fseek(f->f_fp, offset, (int)whence) != 0) {
if (errno == 0)
errno = EIO;
- return err_errno(RuntimeError);
+ return err_errno(IOError);
}
INCREF(None);
return None;
@@ -219,7 +219,7 @@ file_tell(f, args)
if (offset == -1L) {
if (errno == 0)
errno = EIO;
- return err_errno(RuntimeError);
+ return err_errno(IOError);
}
return newintobject(offset);
}
@@ -237,7 +237,7 @@ file_flush(f, args)
if (fflush(f->f_fp) != 0) {
if (errno == 0)
errno = EIO;
- return err_errno(RuntimeError);
+ return err_errno(IOError);
}
INCREF(None);
return None;
@@ -441,7 +441,6 @@ file_write(f, args)
object *args;
{
int n, n2;
- char *s;
if (f->f_fp == NULL) {
err_badarg();
return NULL;
@@ -452,20 +451,11 @@ file_write(f, args)
}
f->f_softspace = 0;
errno = 0;
- n = getstringsize(args);
- s = getstringvalue(args);
- if (n > BUFSIZ) {
- fflush(f->f_fp);
- n2 = write(fileno(f->f_fp), s, n);
- fflush(f->f_fp);
- }
- else {
- n2 = fwrite(s, 1, n, f->f_fp);
- }
+ n2 = fwrite(getstringvalue(args), 1, n = getstringsize(args), f->f_fp);
if (n2 != n) {
if (errno == 0)
errno = EIO;
- err_errno(RuntimeError);
+ err_errno(IOError);
return NULL;
}
INCREF(None);
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 18bdbca..2e2b9a2 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -543,7 +543,7 @@ listindex(self, args)
if (cmpobject(self->ob_item[i], args) == 0)
return newintobject(i);
}
- err_setstr(RuntimeError, "list.index(x): x not in list");
+ err_setstr(ValueError, "list.index(x): x not in list");
return NULL;
}
@@ -586,7 +586,7 @@ listremove(self, args)
}
}
- err_setstr(RuntimeError, "list.remove(x): x not in list");
+ err_setstr(ValueError, "list.remove(x): x not in list");
return NULL;
}
diff --git a/Objects/longobject.c b/Objects/longobject.c
index fb5d241..37f2f35 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -168,7 +168,7 @@ getlongvalue(vv)
prev = x;
x = (x << SHIFT) + v->ob_digit[i];
if ((x >> SHIFT) != prev) {
- err_setstr(RuntimeError,
+ err_setstr(ValueError,
"long int too long to convert");
return -1;
}
@@ -422,7 +422,7 @@ long_divrem(a, b, prem)
if (size_b == 0) {
if (prem != NULL)
*prem = NULL;
- err_setstr(RuntimeError, "long division by zero");
+ err_setstr(ZeroDivisionError, "long division or remainder");
return NULL;
}
if (size_a < size_b ||
@@ -938,7 +938,7 @@ long_pow(a, w)
if (size_b == ~0)
size_b = 0;
else if (size_b < 0) {
- err_setstr(RuntimeError, "long integer to the negative power");
+ err_setstr(ValueError, "long integer to the negative power");
return NULL;
}
@@ -1054,11 +1054,11 @@ long_rshift(a, b)
if (shiftby == -1L && err_occurred())
return NULL;
if (shiftby < 0) {
- err_setstr(RuntimeError, "negative shift count");
+ err_setstr(ValueError, "negative shift count");
return NULL;
}
if (shiftby > MASK) {
- err_setstr(RuntimeError, "outrageous shift count");
+ err_setstr(ValueError, "outrageous shift count");
return NULL;
}
wordshift = shiftby / SHIFT;
@@ -1105,11 +1105,11 @@ long_lshift(a, b)
if (shiftby == -1L && err_occurred())
return NULL;
if (shiftby < 0) {
- err_setstr(RuntimeError, "negative shift count");
+ err_setstr(ValueError, "negative shift count");
return NULL;
}
if (shiftby > MASK) {
- err_setstr(RuntimeError, "outrageous shift count");
+ err_setstr(ValueError, "outrageous shift count");
return NULL;
}
if (shiftby % SHIFT == 0) {
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index ffc8e74..1104986 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -118,7 +118,7 @@ module_getattr(m, name)
}
res = dictlookup(m->md_dict, name);
if (res == NULL)
- err_setstr(NameError, name);
+ err_setstr(AttributeError, name);
else
INCREF(res);
return res;
@@ -131,7 +131,7 @@ module_setattr(m, name, v)
object *v;
{
if (strcmp(name, "__dict__") == 0 || strcmp(name, "__name__") == 0) {
- err_setstr(NameError, "can't assign to reserved member name");
+ err_setstr(TypeError, "can't assign to reserved member name");
return -1;
}
if (v == NULL)