Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 18 lines (17 sloc) 1.163 kB
5e71148 @Almad Add classes so bad selector engines are worky
Almad authored
1 <section name="python" class="python">
ec8401f @Almad Initial transfer of language templates
Almad authored
2 <p class="ioDesc">In</p>
3 <pre class="incoming brush:python">
4 from urllib2 import Request, urlopen
5 <% if @contentType is "application/json": %>from json import dumps
6 <% else if @contentType is "application/x-www-form-urlencoded": %>from urllib import urlencode
7 <% end %>
0a9af09 @Almad Process unjoined @body
Almad authored
8 <% if @contentType is "application/x-www-form-urlencoded": %>values = urlencode(<%= @body.join('') %>)
9 <% else if @contentType is "application/json": %>values = dumps(<%= @body.join('') %>)
10 <% else if @method isnt 'GET': %>values = <%= @helpers.escape @body.join('') %>
7378dd9 @zzen Fixed escaping of template headers
zzen authored
11 <% end %><% if @helpers.isNotEmpty @headers: %>headers = {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>}
3f721ee @zzen Better empty headers detection
zzen authored
12 <% end %>request = Request("<%= @apiUrl %><%= @url %>"<% if @method in ['POST', 'PUT'] : %>, data=values<% end %><% if @helpers.isNotEmpty @headers: %>, headers=headers<% end %>)
ec8401f @Almad Initial transfer of language templates
Almad authored
13 <% if @method not in ['GET', 'POST'] : %>request.get_method = lambda: '<%= @method %>'
14 <% end %>response_body = urlopen(request).read()
3f721ee @zzen Better empty headers detection
zzen authored
15 print response_body
ec8401f @Almad Initial transfer of language templates
Almad authored
16 </pre>
17 </section>
Something went wrong with that request. Please try again.