#!/usr/bin/python # This script is intended to be used by Apache's RewriteMap directive to # properly convert URLs with Greek characters. Specifically, Greek characters # in Unicode (such as those sent by Internet Explorer in its default setup) are # converted to iso-8859-7; all other characters are left as they are. # NOTE: This script must not hang or unexpectedly terminate, or the web server # will hang or malfunction. import sys def to_unicode(str, enc): "Changes str from enc to unicode; returns empty string on error" try: str = unicode(str, enc) return str except: return "" while 1: line = sys.stdin.readline() if not line: break nline = to_unicode(line, 'utf-8') if nline == "": nline = to_unicode(line, 'iso-8859-7') if nline == "": nline = line try: nline = nline.encode('iso-8859-7') sys.stdout.write(nline) except: sys.stdout.write(line) sys.stdout.flush()