Skip to content

Commit 99412fd

Browse files
committed
added popd
svn path=/trunk/matplotlib/; revision=715
1 parent bebb3a9 commit 99412fd

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
New entries should be added at the top
22

3+
2004-11-25 Added Printf to mplutils for printf style format string
4+
formatting in C++ (should help write better exceptions)
5+
36
2004-11-24 IMAGE_FORMAT: remove from agg and gtkagg backends as its no longer
47
used - SC
58

lib/matplotlib/cbook.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,14 @@ def allpairs(x):
411411
assert( not allequal(('a', 'b')))
412412

413413

414+
def popd(d, *args):
415+
if len(args)==1:
416+
key = args[0]
417+
val = d[key]
418+
del d[key]
419+
elif len(args)==2:
420+
key, default = args
421+
val = d.get(key, default)
422+
try: del d[key]
423+
except KeyError: pass
424+
return val

src/_backend_agg.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -950,12 +950,8 @@ RendererAgg::write_png(const Py::Tuple& args)
950950
if (o.isString()) {
951951
std::string fileName = Py::String(o);
952952
const char *file_name = fileName.c_str();
953-
if ((fp = fopen(file_name, "wb")) == NULL) {
954-
std::ostringstream os;
955-
os << "Could not open file " << file_name;
953+
if ((fp = fopen(file_name, "wb")) == NULL)
956954
throw Py::RuntimeError( Printf("Could not open file %s", file_name).str() );
957-
}
958-
//fp = fopen(file_name, "wb");
959955
}
960956
else {
961957
if ((fp = PyFile_AsFile(o.ptr())) == NULL)

src/_image.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,26 +539,26 @@ Image::write_png(const Py::Tuple& args)
539539

540540
fp = fopen(file_name, "wb");
541541
if (fp == NULL)
542-
throw Py::RuntimeError("could not open file");
542+
throw Py::RuntimeError(Printf("Could not open file %s", file_name).str());
543543

544544

545545
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
546546
if (png_ptr == NULL) {
547547
fclose(fp);
548-
throw Py::RuntimeError("could not create write struct");
548+
throw Py::RuntimeError("Could not create write struct");
549549
}
550550

551551
info_ptr = png_create_info_struct(png_ptr);
552552
if (info_ptr == NULL) {
553553
fclose(fp);
554554
png_destroy_write_struct(&png_ptr, &info_ptr);
555-
throw Py::RuntimeError("could not create info struct");
555+
throw Py::RuntimeError("Could not create info struct");
556556
}
557557

558558
if (setjmp(png_ptr->jmpbuf)) {
559559
fclose(fp);
560560
png_destroy_write_struct(&png_ptr, &info_ptr);
561-
throw Py::RuntimeError("error building image");
561+
throw Py::RuntimeError("Error building image");
562562
}
563563

564564
png_init_io(png_ptr, fp);
@@ -726,7 +726,7 @@ _image_module::readpng(const Py::Tuple& args) {
726726

727727
FILE *fp = fopen(fname.c_str(), "rb");
728728
if (!fp)
729-
throw Py::RuntimeError("_image_module::readpng could not open PNG file for reading");
729+
throw Py::RuntimeError(Printf("_image_module::readpng could not open PNG file %s for reading", fname.c_str()).str());
730730

731731
fread(header, 1, 8, fp);
732732
if (png_sig_cmp(header, 0, 8))
@@ -879,7 +879,7 @@ _image_module::fromarray(const Py::Tuple& args) {
879879

880880
if (A->dimensions[2] != 3 && A->dimensions[2] != 4 ) {
881881
Py_XDECREF(A);
882-
throw Py::ValueError("3rd dimension must be length 3 (RGB) or 4 (RGBA)");
882+
throw Py::ValueError(Printf("3rd dimension must be length 3 (RGB) or 4 (RGBA); found %d", A->dimensions[2]).str());
883883

884884
}
885885

src/ft2font.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,13 @@ FT2Font::load_char(const Py::Tuple & args) {
488488
int error = FT_Load_Char( face, (unsigned long)charcode, FT_LOAD_DEFAULT);
489489

490490
if (error)
491-
throw Py::RuntimeError("Could not load charcode");
491+
throw Py::RuntimeError(Printf("Could not load charcode %d", charcode).str());
492492

493493
FT_Glyph thisGlyph;
494494
error = FT_Get_Glyph( face->glyph, &thisGlyph );
495495

496496
if (error)
497-
throw Py::RuntimeError("Could not get glyph for char");
497+
throw Py::RuntimeError(Printf("Could not get glyph for char %d", charcode).str());
498498

499499
size_t num = glyphs.size(); //the index into the glyphs list
500500
glyphs.push_back(thisGlyph);
@@ -615,7 +615,7 @@ FT2Font::draw_rect(const Py::Tuple & args) {
615615
if ( x0<0 || y0<0 || x1<0 || y1<0 ||
616616
x0>iwidth || x1>iwidth ||
617617
y0>iheight || y1>iheight )
618-
throw Py::ValueError("rect coords outside image bounds");
618+
throw Py::ValueError("Rect coords outside image bounds");
619619

620620
for (long i=x0; i<x1; ++i) {
621621
image.buffer[i + y0*iwidth] = 255;
@@ -774,7 +774,7 @@ FT2Font::get_glyph_name(const Py::Tuple & args) {
774774

775775
char buffer[128];
776776
if (FT_Get_Glyph_Name(face, (FT_UInt) Py::Int(args[0]), buffer, 128))
777-
Py::RuntimeError("Could not get glyph names.");
777+
throw Py::RuntimeError("Could not get glyph names.");
778778
return Py::String(buffer);
779779
}
780780

0 commit comments

Comments
 (0)