I'm trying to create a juptyer notebook that facilities copying and updating a "dev" Portal webmap to my "prod" Portal (I'm working with two internal Portals, same layers published to each).
It's easy to copy a web map from one portal to the other, using the copy_item function from clone portal users groups and content | ArcGIS for Developers . However, I'm having problems updating the web map once I've copied it from dev to production.
As far as I can tell, all I'd need to do is change the urls (from my development ArcGIS server to my production ArcGIS server) in the json representation of the Portal item. It also seems like I should change the itemId for the layers as well, (I might just have to hardcode the production itemIds unless I want to search for the layers by name and retrieve the ids that way - I have yet to solve the best way to approach that problem).
Lastly, once I've modified the data dictionary / json representation from the web map, I just run the update method.
See the code below:
<SPAN class="comment token">#####from some of the API documentation examples</SPAN>
TEXT_BASED_ITEM_TYPES <SPAN class="operator token">=</SPAN> frozenset<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Web Map'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Feature Service'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Map Service'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Web Scene'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'Image Service'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Feature Collection'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'Feature Collection Template'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'Web Mapping Application'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Mobile Application'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'Symbol Set'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Color Set'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'Windows Viewer Configuration'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
ITEM_COPY_PROPERTIES <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'title'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'type'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'typeKeywords'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'description'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'tags'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'snippet'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'extent'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'spatialReference'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'name'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'accessInformation'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'licenseInfo'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'culture'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'url'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">copy_item</SPAN><SPAN class="punctuation token">(</SPAN>target<SPAN class="punctuation token">,</SPAN> owner<SPAN class="punctuation token">,</SPAN> folder<SPAN class="punctuation token">,</SPAN> item<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">with</SPAN> tempfile<SPAN class="punctuation token">.</SPAN>TemporaryDirectory<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> temp_dir<SPAN class="punctuation token">:</SPAN>
copy_item <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">for</SPAN> property_name <SPAN class="keyword token">in</SPAN> ITEM_COPY_PROPERTIES<SPAN class="punctuation token">:</SPAN>
copy_item<SPAN class="punctuation token">[</SPAN>property_name<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> item<SPAN class="punctuation token">[</SPAN>property_name<SPAN class="punctuation token">]</SPAN>
data_file <SPAN class="operator token">=</SPAN> None
<SPAN class="keyword token">if</SPAN> item<SPAN class="punctuation token">.</SPAN>type <SPAN class="keyword token">in</SPAN> TEXT_BASED_ITEM_TYPES<SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># If its a text-based item, then read the text and add it to the request.</SPAN>
<SPAN class="keyword token">if</SPAN> item<SPAN class="punctuation token">.</SPAN>size <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN>
text <SPAN class="operator token">=</SPAN> item<SPAN class="punctuation token">.</SPAN>get_data<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#textstr = text.decode('utf-8')</SPAN>
copy_item<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'text'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> text
<SPAN class="keyword token">elif</SPAN> item<SPAN class="punctuation token">.</SPAN>size <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># download data for all other types, not just item.type in FILE_BASED_ITEM_TYPES:</SPAN>
<SPAN class="comment token"># download data and add to the request as a file</SPAN>
data_file <SPAN class="operator token">=</SPAN> item<SPAN class="punctuation token">.</SPAN>download<SPAN class="punctuation token">(</SPAN>temp_dir<SPAN class="punctuation token">)</SPAN>
thumbnail_file <SPAN class="operator token">=</SPAN> item<SPAN class="punctuation token">.</SPAN>download_thumbnail<SPAN class="punctuation token">(</SPAN>temp_dir<SPAN class="punctuation token">)</SPAN>
metadata_file <SPAN class="operator token">=</SPAN> item<SPAN class="punctuation token">.</SPAN>download_metadata<SPAN class="punctuation token">(</SPAN>temp_dir<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Add the item to the target portal</SPAN>
copied_item <SPAN class="operator token">=</SPAN> target<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN>copy_item<SPAN class="punctuation token">,</SPAN> data_file<SPAN class="punctuation token">,</SPAN> thumbnail_file<SPAN class="punctuation token">,</SPAN>
metadata_file<SPAN class="punctuation token">,</SPAN> owner<SPAN class="punctuation token">,</SPAN> folder<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> copied_item
<SPAN class="comment token">#####################################</SPAN>
<SPAN class="comment token">##My Notebook</SPAN>
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> Item
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> User
<SPAN class="keyword token">import</SPAN> tempfile
<SPAN class="keyword token">from</SPAN> IPython<SPAN class="punctuation token">.</SPAN>display <SPAN class="keyword token">import</SPAN> display
source <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"dev portal"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"username"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"password"</SPAN><SPAN class="punctuation token">,</SPAN> verify_cert<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
target <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"prod portal"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"username"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"password"</SPAN><SPAN class="punctuation token">,</SPAN> verify_cert<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
myDevMap <SPAN class="operator token">=</SPAN> Item<SPAN class="punctuation token">(</SPAN>source<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"d8c2a39f366843e0a5e24c5299aeb57c"</SPAN><SPAN class="punctuation token">)</SPAN>
copy_item<SPAN class="punctuation token">(</SPAN>target<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"user"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"folder"</SPAN><SPAN class="punctuation token">,</SPAN>myDevMap<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">######Once I've copied once, I just hardcode the item ID</SPAN>
myProdMap <SPAN class="operator token">=</SPAN> Item<SPAN class="punctuation token">(</SPAN>target<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"cc6a02d3e9644cd08cc105ae30a06d87"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#here I'm retrieveing the json representation of the map</SPAN>
data <SPAN class="operator token">=</SPAN> myProdMap<SPAN class="punctuation token">.</SPAN>get_data<SPAN class="punctuation token">(</SPAN>try_json<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
replaceData <SPAN class="operator token">=</SPAN> data
<SPAN class="comment token">##this is where I replace the URLS "gis-dev" is the development url, and "gis" is the production</SPAN>
layers <SPAN class="operator token">=</SPAN> data<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'operationalLayers'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> index <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN>len<SPAN class="punctuation token">(</SPAN>layers<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="string token">'url'</SPAN> <SPAN class="keyword token">in</SPAN> layers<SPAN class="punctuation token">[</SPAN>index<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>keys<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
url <SPAN class="operator token">=</SPAN> layers<SPAN class="punctuation token">[</SPAN>index<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'url'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="string token">"gis-dev"</SPAN> <SPAN class="keyword token">in</SPAN> url<SPAN class="punctuation token">:</SPAN>
newurl <SPAN class="operator token">=</SPAN> url<SPAN class="punctuation token">.</SPAN>replace<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"gis-dev"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"gis"</SPAN><SPAN class="punctuation token">)</SPAN>
replaceData<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'operationalLayers'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN>index<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'url'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="operator token">=</SPAN>newurl
myProdMap<SPAN class="punctuation token">.</SPAN>update<SPAN class="punctuation token">(</SPAN>data <SPAN class="operator token">=</SPAN> replaceData<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>When I try to run the update method, I get a whole host of errors, and I can't make heads or tails of them. So, am I doing something wrong / is there something I'm missing? I see some http vs https errors in here, along with some key errors as well. Don't really know what's going on but would love some assistance on this one.
AttributeError Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token"><</SPAN>ipython<SPAN class="operator token">-</SPAN>input<SPAN class="number token">-27</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">5fe3a5afb862</SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">1</SPAN> EONHome_fromDev<SPAN class="punctuation token">.</SPAN>update<SPAN class="punctuation token">(</SPAN>data <SPAN class="operator token">=</SPAN> replaceData<SPAN class="punctuation token">)</SPAN>
C<SPAN class="punctuation token">:</SPAN>\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro<SPAN class="operator token">-</SPAN>py3\lib\site<SPAN class="operator token">-</SPAN>packages\arcgis\gis<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> update<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> item_properties<SPAN class="punctuation token">,</SPAN> data<SPAN class="punctuation token">,</SPAN> thumbnail<SPAN class="punctuation token">,</SPAN> metadata<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">2846</SPAN> item_properties<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'tags'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">","</SPAN><SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>item_properties<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'tags'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">2847</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">2848</SPAN> ret <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>_portal<SPAN class="punctuation token">.</SPAN>update_item<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">.</SPAN>itemid<SPAN class="punctuation token">,</SPAN> item_properties<SPAN class="punctuation token">,</SPAN> data<SPAN class="punctuation token">,</SPAN> thumbnail<SPAN class="punctuation token">,</SPAN> metadata<SPAN class="punctuation token">,</SPAN> self<SPAN class="punctuation token">.</SPAN>owner<SPAN class="punctuation token">,</SPAN> folder<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">2849</SPAN> <SPAN class="keyword token">if</SPAN> ret<SPAN class="punctuation token">:</SPAN>
<SPAN class="number token">2850</SPAN> self<SPAN class="punctuation token">.</SPAN>_hydrate<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
C<SPAN class="punctuation token">:</SPAN>\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro<SPAN class="operator token">-</SPAN>py3\lib\site<SPAN class="operator token">-</SPAN>packages\arcgis\_impl\portalpy<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> update_item<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> itemid<SPAN class="punctuation token">,</SPAN> item_properties<SPAN class="punctuation token">,</SPAN> data<SPAN class="punctuation token">,</SPAN> thumbnail<SPAN class="punctuation token">,</SPAN> metadata<SPAN class="punctuation token">,</SPAN> owner<SPAN class="punctuation token">,</SPAN> folder<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">2014</SPAN> files <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="number token">2015</SPAN> <SPAN class="keyword token">if</SPAN> data<SPAN class="punctuation token">:</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">2016</SPAN> <SPAN class="keyword token">if</SPAN> _is_http_url<SPAN class="punctuation token">(</SPAN>data<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="number token">2017</SPAN> data <SPAN class="operator token">=</SPAN> request<SPAN class="punctuation token">.</SPAN>urlretrieve<SPAN class="punctuation token">(</SPAN>data<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="number token">2018</SPAN> files<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'file'</SPAN><SPAN class="punctuation token">,</SPAN> data<SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>data<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
C<SPAN class="punctuation token">:</SPAN>\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro<SPAN class="operator token">-</SPAN>py3\lib\site<SPAN class="operator token">-</SPAN>packages\arcgis\_impl\connection<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> _is_http_url<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1084</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">_is_http_url</SPAN><SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="number token">1085</SPAN> <SPAN class="keyword token">if</SPAN> url<SPAN class="punctuation token">:</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">1086</SPAN> <SPAN class="keyword token">return</SPAN> urlparse<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>scheme <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'http'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'https'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="number token">1087</SPAN>
<SPAN class="number token">1088</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">_unpack</SPAN><SPAN class="punctuation token">(</SPAN>obj_or_seq<SPAN class="punctuation token">,</SPAN> key<SPAN class="operator token">=</SPAN>None<SPAN class="punctuation token">,</SPAN> flatten<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
C<SPAN class="punctuation token">:</SPAN>\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro<SPAN class="operator token">-</SPAN>py3\lib\urllib\parse<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> urlparse<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">,</SPAN> scheme<SPAN class="punctuation token">,</SPAN> allow_fragments<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">290</SPAN> Note that we don't <SPAN class="keyword token">break</SPAN> the components up <SPAN class="keyword token">in</SPAN> smaller bits
<SPAN class="number token">291</SPAN> <SPAN class="punctuation token">(</SPAN>e<SPAN class="punctuation token">.</SPAN>g<SPAN class="punctuation token">.</SPAN> netloc <SPAN class="keyword token">is</SPAN> a single string<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> we don't expand <SPAN class="operator token">%</SPAN> escapes<SPAN class="punctuation token">.</SPAN><SPAN class="string token">""</SPAN>"
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">292</SPAN> url<SPAN class="punctuation token">,</SPAN> scheme<SPAN class="punctuation token">,</SPAN> _coerce_result <SPAN class="operator token">=</SPAN> _coerce_args<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">,</SPAN> scheme<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">293</SPAN> splitresult <SPAN class="operator token">=</SPAN> urlsplit<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">,</SPAN> scheme<SPAN class="punctuation token">,</SPAN> allow_fragments<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">294</SPAN> scheme<SPAN class="punctuation token">,</SPAN> netloc<SPAN class="punctuation token">,</SPAN> url<SPAN class="punctuation token">,</SPAN> query<SPAN class="punctuation token">,</SPAN> fragment <SPAN class="operator token">=</SPAN> splitresult
C<SPAN class="punctuation token">:</SPAN>\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro<SPAN class="operator token">-</SPAN>py3\lib\urllib\parse<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> _coerce_args<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>args<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">110</SPAN> <SPAN class="keyword token">if</SPAN> str_input<SPAN class="punctuation token">:</SPAN>
<SPAN class="number token">111</SPAN> <SPAN class="keyword token">return</SPAN> args <SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>_noop<SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">112</SPAN> <SPAN class="keyword token">return</SPAN> _decode_args<SPAN class="punctuation token">(</SPAN>args<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>_encode_result<SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">113</SPAN>
<SPAN class="number token">114</SPAN> <SPAN class="comment token"># Result objects are more helpful than simple tuples</SPAN>
C<SPAN class="punctuation token">:</SPAN>\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro<SPAN class="operator token">-</SPAN>py3\lib\urllib\parse<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> _decode_args<SPAN class="punctuation token">(</SPAN>args<SPAN class="punctuation token">,</SPAN> encoding<SPAN class="punctuation token">,</SPAN> errors<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">94</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">_decode_args</SPAN><SPAN class="punctuation token">(</SPAN>args<SPAN class="punctuation token">,</SPAN> encoding<SPAN class="operator token">=</SPAN>_implicit_encoding<SPAN class="punctuation token">,</SPAN>
<SPAN class="number token">95</SPAN> errors<SPAN class="operator token">=</SPAN>_implicit_errors<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">96</SPAN> <SPAN class="keyword token">return</SPAN> tuple<SPAN class="punctuation token">(</SPAN>x<SPAN class="punctuation token">.</SPAN>decode<SPAN class="punctuation token">(</SPAN>encoding<SPAN class="punctuation token">,</SPAN> errors<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> x <SPAN class="keyword token">else</SPAN> <SPAN class="string token">''</SPAN> <SPAN class="keyword token">for</SPAN> x <SPAN class="keyword token">in</SPAN> args<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">97</SPAN>
<SPAN class="number token">98</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">_coerce_args</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>args<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
C<SPAN class="punctuation token">:</SPAN>\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro<SPAN class="operator token">-</SPAN>py3\lib\urllib\parse<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>genexpr<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">94</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">_decode_args</SPAN><SPAN class="punctuation token">(</SPAN>args<SPAN class="punctuation token">,</SPAN> encoding<SPAN class="operator token">=</SPAN>_implicit_encoding<SPAN class="punctuation token">,</SPAN>
<SPAN class="number token">95</SPAN> errors<SPAN class="operator token">=</SPAN>_implicit_errors<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">96</SPAN> <SPAN class="keyword token">return</SPAN> tuple<SPAN class="punctuation token">(</SPAN>x<SPAN class="punctuation token">.</SPAN>decode<SPAN class="punctuation token">(</SPAN>encoding<SPAN class="punctuation token">,</SPAN> errors<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> x <SPAN class="keyword token">else</SPAN> <SPAN class="string token">''</SPAN> <SPAN class="keyword token">for</SPAN> x <SPAN class="keyword token">in</SPAN> args<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">97</SPAN>
<SPAN class="number token">98</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">_coerce_args</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>args<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
AttributeError<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'dict'</SPAN> object has no attribute <SPAN class="string token">'decode'</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>