source: TI03-DataExtractor/trunk/pydxc/common.py @ 794

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/trunk/pydxc/common.py@794
Revision 794, 2.3 KB checked in by astephen, 13 years ago (diff)

Unstable but latest version with multi-variable support and split hooks
for CDML and CSML.

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 the Data Extractor software.
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=["DatasetGroupPage", "DatasetPage", "VariablesPage", "DomainPage", "ResultsPage"]
24
25TIME_KEYS=["Year", "Month", "Day", "Hour", "Minute", "Second"]
26
27HORIZ_KEYS=["northernExtent", "easternExtent", "southernExtent", "westernExtent"]
28
29# Set up common functions
30
31def createTimeKeyList():
32    """
33    Returns all the separate date and time component arguments required as a list.
34    """
35    allTimeKeys=[]
36    for ts in ["start", "end"]:
37        for i in range(1, MAX_NUM_DATASETS+1):
38            for key in TIME_KEYS:
39                allTimeKeys.append("%s%s_%s" % (ts, key, i))
40    return allTimeKeys
41   
42
43def deUnicodeObject(obj):
44    """
45    Returns the object identical except unicode strings are all
46    converted to normal strings.
47    """
48    tupleFound=None
49    if type(obj)==type((1,2)):
50        tupleFound=1
51        obj=list(obj)
52
53    if type(obj)==type([]):
54        rtobj=[]
55        for i in obj:
56            if type(i) in (type([]), type((1,2))):
57                rtobj.append(deUnicodeObject(i))
58            elif type(i)==type(u""):
59                rtobj.append(str(i))
60            else:
61                rtobj.append(i)
62        if tupleFound==1: rtobj=tuple(rtobj)
63
64    elif type(obj)==type(u""):
65        rtobj=str(obj)
66    else:
67        rtobj=obj
68    return rtobj
69
70
71# Set up common classes
72class RedirectStdout:
73    """
74    RedirectStdout class - used to direct standard output away from
75    the screen in CGI scripts.
76    """
77
78    def write(self, item):
79        """
80        write method - allows dummy standard out to work.
81        """
82        pass
83
84    def flush(self):
85        """
86        Method to do nothing, again!
87        """
88        pass
89
Note: See TracBrowser for help on using the repository browser.