You read the biopython code here? That's the best explanation of the quality scores I've seen.
There's also a nice text-graphic about 2/3rd's of the way down the wikipedia page
Finally, FastQC guesses the encoding of your quality scores, so you could look at the java code.
Here is a Perl script for guessing the quality scale
Does the FAST-X toolkit answer your needs ? http://hannonlab.cshl.edu/fastx_toolkit/commandline.html#fastq_quality_boxplot_usage
Isn't that solving the wrong problem? The guessing code in FastQC looks fragile, it simply looks at the smallest code used for qualities, so it depends on actually seeing low quality bases.
I believe you should get the correct encoding from extra knowledge (i.e. knowing which version of which program generated the file, say from some log file), and then convert to a well specified format (e.g. BAM) once. Please don't perpetuate the practive of guessing at the details underspecified formats.