source: TI04-geosplat/trunk/pygsc/common.py @ 798

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI04-geosplat/trunk/pygsc/common.py@798
Revision 798, 2.4 KB checked in by astephen, 14 years ago (diff)

Latest working version with install method.
Can accept more than one file but doesn't combine variables yet.

Line 
1#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
2#   This software may be distributed under the terms of the
3#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
4
5"""
6common.py
7=========
8
9Holds common functions and classes used in this package.
10
11"""
12
13# Import python modules
14import os
15
16# Import package modules
17from clientConfig import *
18
19# Set up commmon variables. These are CAPITALISED to
20# improve visibility in other modules.
21HTTP_HEADER="Content-Type: text/html\n\n"
22
23STAGES=["FileURIPage", "VariableSelectionPage", "GraphicalOutputTypePage", "PlotConfigPage", "ResultsPage"]
24
25# Set up common functions
26
27def deUnicodeObject(obj):
28    """
29    Returns the object identical except unicode strings are all
30    converted to normal strings.
31    """
32    tupleFound=None
33    if type(obj)==type((1,2)):
34        tupleFound=1
35        obj=list(obj)
36
37    if type(obj)==type([]):
38        rtobj=[]
39        for i in obj:
40            if type(i) in (type([]), type((1,2))):
41                rtobj.append(deUnicodeObject(i))
42            elif type(i)==type(u""):
43                rtobj.append(str(i))
44            else:
45                rtobj.append(i)
46        if tupleFound==1: rtobj=tuple(rtobj)
47
48    elif type(obj)==type(u""):
49        rtobj=str(obj)
50    else:
51        rtobj=obj
52    return rtobj
53
54
55def keyPatternMatch(dct, pattern):
56    """
57    Returns 1 if one or more keys in the dictionary 'dct' match the
58    pattern provided using string.find(). Returns 0 otherwise.
59    """
60    for key in dct.keys():
61        if key.find(pattern)>-1:
62            return 1
63    return 0
64
65def makeSpacesBetweenCaps(inString):
66   """
67   Returns a replacement for instring where capital letters have been pre-pended
68   with one blank space.
69   """
70   caps="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
71   outString=inString[0].upper()
72   for x in inString[1:]:
73       if x in caps:
74           outString=outString+" "+x
75       else:
76            outString=outString+x
77   return outString   
78
79# Set up common classes
80class RedirectStdout:
81    """
82    RedirectStdout class - used to direct standard output away from
83    the screen in CGI scripts.
84    """
85
86    def write(self, item):
87        """
88        write method - allows dummy standard out to work.
89        """
90        pass
91
92    def flush(self):
93        """
94        Method to do nothing, again!
95        """
96        pass
97
Note: See TracBrowser for help on using the repository browser.