Convert metadata unicode strings to ascii ( previous code doesn't seem to do anything, am I missing something? ). Add no_value metadata attribute to columns and column_types metadata. Fix for column_maker and filter tools.

This commit is contained in:
Greg Von Kuster
2008-09-24 11:14:44 -04:00
parent 9d3fd1eede
commit 7aace9ccaa
4 changed files with 8 additions and 13 deletions
+3 -4
View File
@@ -60,10 +60,10 @@ class MetadataParameter( object ):
if isinstance( value, ListType ):
for i, elem in enumerate( value ):
if type ( elem ) == unicode:
value[i] = str( elem )
value[i] = elem.decode( 'ascii' )
elif isinstance ( value, basestring ):
if type( value ) == unicode:
value = str( value )
value = value.decode( 'ascii' )
self.value = value
self.context = context
self.display = True
@@ -76,7 +76,7 @@ class MetadataParameter( object ):
@classmethod
def marshal( cls, value ):
'''
This method should/can be overridden to convert the incomming
This method should/can be overridden to convert the incoming
value to whatever type it is supposed to be.
'''
return value
@@ -273,7 +273,6 @@ class ColumnParameter( RangeParameter ):
class ColumnTypesParameter( MetadataParameter ):
def __init__( self, spec, value, context ):
MetadataParameter.__init__( self, spec, value, context )
def __str__(self):
return ",".join( map( str, self.value ) )
+2 -2
View File
@@ -19,8 +19,8 @@ class Tabular( data.Text ):
"""Tab delimited data"""
"""Add metadata elements"""
MetadataElement( name="columns", default=0, desc="Number of columns", readonly=True, visible=False )
MetadataElement( name="column_types", default=[], desc="Column types", param=metadata.ColumnTypesParameter, readonly=True, visible=False )
MetadataElement( name="columns", default=0, desc="Number of columns", readonly=True, visible=False, no_value=0 )
MetadataElement( name="column_types", default=[], desc="Column types", param=metadata.ColumnTypesParameter, readonly=True, visible=False, no_value=[] )
def init_meta( self, dataset, copy_from=None ):
data.Text.init_meta( self, dataset, copy_from=copy_from )
+2 -4
View File
@@ -19,12 +19,10 @@ expr = sys.argv[3]
round = sys.argv[4]
try:
in_columns = int( sys.argv[5] )
# in_column_types is passed as a string that looks something like:
# "[u'str', u'int', u'int', u'str', u'int', u'str']"
in_column_types = sys.argv[6].strip( '[' ).strip( ']' ).replace( 'u', '' ).replace( "'", '' ).split( ',' )
in_column_types = sys.argv[6].split( ',' )
except:
stop_err( "Data does not appear to be tabular. This tool can only be used with tab-delimited data." )
# Unescape if input has been escaped
mapped_str = {
'__lt__': '<',
+1 -3
View File
@@ -26,9 +26,7 @@ out_fname = sys.argv[2]
cond_text = sys.argv[3]
try:
in_columns = int( sys.argv[4] )
# in_column_types is passed as a string that looks something like:
# "[u'str', u'int', u'int', u'str', u'int', u'str']"
in_column_types = sys.argv[5].strip( '[' ).strip( ']' ).replace( 'u', '' ).replace( "'", '' ).split( ',' )
in_column_types = sys.argv[5].split( ',' )
except:
stop_err( "Data does not appear to be tabular. This tool can only be used with tab-delimited data." )