Skip to content
Newer
Older
100644 27 lines (25 sloc) 1.11 KB
5e71148 @Almad Add classes so bad selector engines are worky
Almad authored Apr 25, 2012
1 <section name="python" class="python">
b62198c @zdne 'In' (input) renamed 'to' Request
zdne authored Nov 27, 2012
2 <p class="ioDesc">Request</p>
3637277 @kuba-kubula PRE with CODE element with class language
kuba-kubula authored Nov 14, 2012
3 <pre class="incoming"><code class="language-python">from urllib2 import Request, urlopen
ee2752c @kuba-kubula Fixing rendering of cURL multiline body, new-lines in PHP and Python,…
kuba-kubula authored Jan 30, 2013
4 <% if @contentType is "application/json": %>
5 from json import dumps
6 <% else if @contentType is "application/x-www-form-urlencoded": %>
7 from urllib import urlencode
ec8401f @Almad Initial transfer of language templates
Almad authored Apr 1, 2012
8 <% end %>
ee2752c @kuba-kubula Fixing rendering of cURL multiline body, new-lines in PHP and Python,…
kuba-kubula authored Jan 30, 2013
9 <% if @contentType is "application/x-www-form-urlencoded" and @body: %>
10 values = urlencode(<%= @body %>)
11 <% else if @contentType is "application/json" and @body: %>
12 values = dumps(<%= @body %>)
13 <% else if @method isnt 'GET' and @body: %>
14 values = <%= @helpers.escape @body %>
15
16 <% end %>
17 <% if @helpers.isNotEmpty @headers: %>
18 headers = {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>}
19 <% end %>
20 request = Request("<%= @apiUrl %><%= @url %>"<% if @method isnt 'GET' and @body : %>, data=values<% end %><% if @helpers.isNotEmpty @headers: %>, headers=headers<% end %>)
21 <% if @method not in ['GET', 'POST'] : %>
22 request.get_method = lambda: '<%= @method %>'
23 <% end %>
24 response_body = urlopen(request).read()
3637277 @kuba-kubula PRE with CODE element with class language
kuba-kubula authored Nov 14, 2012
25 print response_body</code></pre>
ec8401f @Almad Initial transfer of language templates
Almad authored Apr 1, 2012
26 </section>
Something went wrong with that request. Please try again.