@@ -1205,8 +1205,21 @@ def __process_text_options(layer, layer_parameter):
12051205
12061206
12071207def process_layer (layer , layer_parameter ):
1208- if isinstance (layer , string_types ) and layer .startswith ("fetch:" ):
1209- layer = {"url" : layer [len ('fetch:' ):]}
1208+ if isinstance (layer , string_types ):
1209+ resource_type = None
1210+ if layer .startswith ("fetch:" ):
1211+ url = layer [len ('fetch:' ):]
1212+ elif layer .find (":fetch:" , 0 , 12 ) != - 1 :
1213+ resource_type , _ , url = layer .split (":" , 2 )
1214+ else :
1215+ # nothing to process, a raw string, keep as is.
1216+ return layer
1217+
1218+ # handle remote fetch URL
1219+ layer = {"url" : url , "type" : "fetch" }
1220+ if resource_type :
1221+ layer ["resource_type" ] = resource_type
1222+
12101223 if not isinstance (layer , dict ):
12111224 return layer
12121225
@@ -1215,19 +1228,19 @@ def process_layer(layer, layer_parameter):
12151228 type = layer .get ("type" )
12161229 public_id = layer .get ("public_id" )
12171230 format = layer .get ("format" )
1218- fetch = layer .get ("url" )
1231+ fetch_url = layer .get ("url" )
12191232 components = list ()
12201233
12211234 if text is not None and resource_type is None :
12221235 resource_type = "text"
12231236
1224- if fetch and resource_type is None :
1225- resource_type = "fetch"
1237+ if fetch_url and type is None :
1238+ type = "fetch"
12261239
12271240 if public_id is not None and format is not None :
12281241 public_id = public_id + "." + format
12291242
1230- if public_id is None and resource_type != "text" and resource_type != "fetch" :
1243+ if public_id is None and resource_type != "text" and type != "fetch" :
12311244 raise ValueError ("Must supply public_id for for non-text " + layer_parameter )
12321245
12331246 if resource_type is not None and resource_type != "image" :
@@ -1251,8 +1264,6 @@ def process_layer(layer, layer_parameter):
12511264
12521265 if text is not None :
12531266 var_pattern = VAR_NAME_RE
1254- match = re .findall (var_pattern , text )
1255-
12561267 parts = filter (lambda p : p is not None , re .split (var_pattern , text ))
12571268 encoded_text = []
12581269 for part in parts :
@@ -1262,11 +1273,9 @@ def process_layer(layer, layer_parameter):
12621273 encoded_text .append (smart_escape (smart_escape (part , r"([,/])" )))
12631274
12641275 text = '' .join (encoded_text )
1265- # text = text.replace("%2C", "%252C")
1266- # text = text.replace("/", "%252F")
12671276 components .append (text )
1268- elif resource_type == "fetch" :
1269- b64 = base64_encode_url (fetch )
1277+ elif type == "fetch" :
1278+ b64 = base64_encode_url (fetch_url )
12701279 components .append (b64 )
12711280 else :
12721281 public_id = public_id .replace ("/" , ':' )
0 commit comments