def __init__(self, arg=None): """Construct a dictionary. Args: arg: This constructor accepts the following args: 1) Another dictionary. 2) A list of key/value pairs. 3) A null or no argument (producing an empty dictionary) """ self.initialize() if isinstance(arg, dict): super(Dictionary, self).__init__(None, None) self._dictionary = arg else: self._dictionary = None if (isinstance(arg, computedobject.ComputedObject) and arg.func and arg.func.getSignature()['returns'] == 'Dictionary'): # If it's a call that's already returning a Dictionary, just cast. super(Dictionary, self).__init__(arg.func, arg.args, arg.varName) else: # Delegate everything else to the server-side constuctor. super(Dictionary, self).__init__(apifunction.ApiFunction('Dictionary'), {'input': arg})
def __init__(self, string): """Construct a string wrapper. This constuctor accepts the following args: 1) A bare string. 2) A ComputedObject returning a string. Args: string: The string to wrap. """ self.initialize() if isinstance(string, basestring): super(String, self).__init__(None, None) elif isinstance(string, computedobject.ComputedObject): if string.func and string.func.getSignature( )['returns'] == 'String': # If it's a call that's already returning a String, just cast. super(String, self).__init__(string.func, string.args, string.varName) else: super(String, self).__init__(apifunction.ApiFunction('String'), {'input': string}) else: raise ee_exception.EEException( 'Invalid argument specified for ee.String(): %s' % string) self._string = string
def __init__(self, date, opt_tz=None): """Construct a date. This sends all inputs (except another Date) through the Date function. This constuctor accepts the following args: 1) A bare date. 2) An ISO string 3) A integer number of milliseconds since the epoch. 4) A ComputedObject. Args: date: The date to wrap. opt_tz: An optional timezone, only useable with a string date. """ self.initialize() func = apifunction.ApiFunction('Date') args = None varName = None if isinstance(date, datetime.datetime): args = { 'value': math.floor(serializer.DatetimeToMicroseconds(date) / 1000) } elif types.isNumber(date): args = {'value': date} elif isinstance(date, basestring): args = {'value': date} if opt_tz: if isinstance(opt_tz, basestring): args['timeZone'] = opt_tz else: raise ee_exception.EEException( 'Invalid argument specified for ee.Date(..., opt_tz): %s' % date) elif isinstance(date, computedobject.ComputedObject): if date.func and date.func.getSignature()['returns'] == 'Date': # If it's a call that's already returning a Date, just cast. func = date.func args = date.args varName = date.varName else: args = {'value': date} else: raise ee_exception.EEException( 'Invalid argument specified for ee.Date(): %s' % date) super(Date, self).__init__(func, args, varName)