Changeset 7710
- Timestamp:
- 08/11/10 11:42:54 (10 years ago)
- Location:
- nappy/trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
nappy/trunk/nappy/nappy_api.py
r7638 r7710 140 140 import nappy.utils.common_utils 141 141 import nappy.utils.compare_na 142 import nappy.utils.text_parser 142 143 143 144 # Bring some utils into the API -
nappy/trunk/nappy/utils/common_utils.py
r5369 r7710 16 16 # Imports from local package 17 17 import parse_config 18 import text_parser as text_parser 18 19 19 20 logging.basicConfig() … … 36 37 the File Format Index (FFI) and return it as an integer. 37 38 """ 38 topline = open(filename).readline() 39 return int(topline.split()[-1]) 39 fin = open(filename) 40 topline = fin.readline() 41 fin.close() 42 43 ffi = text_parser.readItemsFromLine(topline, 2, int)[-1] 44 return ffi 40 45 41 46 -
nappy/trunk/nappy/utils/text_parser.py
r3403 r7710 12 12 """ 13 13 14 # Standard library imports 14 15 import re 15 16 import string 16 17 18 # Local imports 19 from nappy.utils.right_strip import * 20 21 # Global variables 17 22 pattnNoQuotes = re.compile("^[\"'].*\1$") 23 18 24 19 25 def readItemFromLine(line, rttype=str): 20 26 """ 27 Reads an item of type ``rttype`` from ``line``. 28 """ 29 line = rightStripCurlyBraces(line) 30 rtitem = pattnNoQuotes.sub("", line.strip()) 21 31 22 """23 rtitem = pattnNoQuotes.sub("", line.strip())24 32 if rttype is not str: 25 33 rtitem = rttype(rtitem) … … 28 36 def readItemsFromLine(line, nitems=None, rttype=str): 29 37 """ 38 Reads ``nitems`` items of type ``rttype`` from ``line``. 39 """ 40 line = rightStripCurlyBraces(line) 41 rtitems = re.split(r"\s+", line.strip()) 30 42 31 """32 rtitems = re.split(r"\s+", line.strip())33 43 if nitems and len(rtitems) != nitems: 34 44 raise "Incorrect number of items (%s) found in line: \n'%s'" % (nitems, line) … … 39 49 def readItemsFromLines(lines, nitems, rttype=str): 40 50 """ 41 51 Reads ``nitems`` items of type ``rttype`` from ``lines`` 42 52 """ 53 lines = [rightStripCurlyBraces(line) for line in lines] 43 54 rtitems = [] 44 55 for line in lines: … … 59 70 rtitems = [] 60 71 lines = [] 72 61 73 if type(object) == type([2,3]): 62 74 … … 64 76 nextitem = object[0] 65 77 object = object[1:] 66 items = nextitem.strip().split()78 items = rightStripCurlyBraces(nextitem).strip().split() 67 79 lines.append(items) 68 80 (rtitems, extras) = (rtitems + items[:nitems], items[nitems:]) … … 70 82 else: 71 83 while len(rtitems) < nitems: 72 items = object.readline().strip().split()84 items = rightStripCurlyBraces(object.readline()).strip().split() 73 85 lines.append(items) 74 86 (rtitems, extras) = (rtitems + items[:nitems], items[nitems:]) -
nappy/trunk/setup.py
r7607 r7710 10 10 setup( 11 11 name='nappy', 12 version='0.9.9 ',12 version='0.9.9c', 13 13 14 14 description = 'NASA Ames Processing in Python', -
nappy/trunk/tests/test_na_file_1001.py
r5072 r7710 63 63 64 64 65 def test_na1001CurlyWithCurlyBraces(self): 66 "Tests an input file with curly braces." 67 cb_file = os.path.join(data_files, "1001_cb.na") 68 fin = nappy.openNAFile(cb_file) 69 fin.readData() 70 na_dict = fin.getNADict() 71 foutname = os.path.join(test_outputs, "test_1001_cb_rewritten.na") 72 fobj = nappy.openNAFile(foutname, mode="w", na_dict=na_dict) 73 fobj.write() 74 self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 75 65 76 if __name__ == "__main__": 66 77
Note: See TracChangeset
for help on using the changeset viewer.