Generate cartocss for class properties

def _get_cartocss(self, basemap, has_time=False):
        """Generate cartocss for class properties"""
        if isinstance(self.size, (int, float)):
            size_style = self.size
        elif isinstance(self.size, dict):
            self.size['range'] = (
                [1, 5] if self.size['range'] == [5, 25]
                else self.size['range']
            )
            size_style = ('ramp([{column}],'
                          ' range({min_range},{max_range}),'
                          ' {bin_method}({bins}))').format(
                              column=self.size['column'],
                              min_range=self.size['range'][0],
                              max_range=self.size['range'][1],
                              bin_method=self.size['bin_method'],
                              bins=self.size['bins'])

        if self.scheme:
            color_style = get_scheme_cartocss(
                'value' if has_time else self.color,
                self.scheme)
        else:
            color_style = self.color

        line_color = '#000' if basemap.source == 'dark' else '#FFF'
        if self.time:
            css = cssify({
                # Torque Point CSS
                "#layer": {
                    'marker-width': size_style,
                    'marker-fill': color_style,
                    'marker-fill-opacity': self.opacity,
                    'marker-allow-overlap': 'true',
                    'marker-line-width': 0,
                    'marker-line-color': line_color,
                    'marker-line-opacity': 1,
                    'comp-op': 'source-over',
                }
            })
            if self.color in self.style_cols:
                css += cssify({
                    '#layer[{} = null]'.format(self.color): {
                        'marker-fill': '#666'}
                    })
            for trail_num in range(1, self.time['trails'] + 1):
                # Trails decay as 1/2^n, and grow 30% at each step
                trail_temp = cssify({
                    '#layer[frame-offset={}]'.format(trail_num): {
                        'marker-width': size_style * (1.0 + trail_num * 0.3),
                        'marker-opacity': 0.9 / 2.0**trail_num,
                    }
                })
                css += trail_temp
            return css
        else:
            if self.geom_type == 'point':
                css = cssify({
                    # Point CSS
                    "#layer": {
                        'marker-width': size_style,
                        'marker-fill': color_style,
                        'marker-fill-opacity': self.opacity,
                        'marker-allow-overlap': 'true',
                        'marker-line-width': '0.5',
                        'marker-line-color': line_color,
                        'marker-line-opacity': '1',
                    }})
                if self.color in self.style_cols:
                    css += cssify({
                        '#layer[{} = null]'.format(self.color): {
                            'marker-fill': '#ccc'}
                        })
                return css
            if self.geom_type == 'line':
                css = cssify({
                    "#layer": {
                        'line-width': size_style,
                        'line-color': color_style,
                        'line-opacity': self.opacity
                    }})
                if self.color in self.style_cols:
                    css += cssify({
                        '#layer[{} = null]'.format(self.color): {
                            'line-color': '#ccc'}
                        })
                return css
            if self.geom_type == 'polygon':
                css = cssify({
                    "#layer": {
                        'polygon-fill': color_style,
                        'polygon-opacity': self.opacity,
                        'polygon-gamma': '0.5',
                        'line-color': '#FFF',
                        'line-width': '0.5',
                        'line-opacity': '0.25',
                        'line-comp-op': 'hard-light',
                    }})
                if self.color in self.style_cols:
                    css += cssify({
                        '#layer[{} = null]'.format(self.color): {
                            'polygon-fill': '#ccc'}
                        })
                return css
            else:
                raise ValueError('Unsupported geometry type: {}'.format(
                    self.geom_type))