<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3APostUrl</id>
	<title>Scripts:PostUrl - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3APostUrl"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:PostUrl&amp;action=history"/>
	<updated>2026-08-06T01:10:49Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://bf2tech.uturista.pt/index.php?title=Scripts:PostUrl&amp;diff=126&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;&#039;&#039;&#039;posturl&#039;&#039;&#039; Usage of postdata(url, data):  &lt;code&gt;temp = postdata(&#039;[http://www.yourdomain.com/postdata.php%27 http://www.yourdomain.com/postdata.php&#039;], {&#039;field1&#039;: &#039;field1data...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:PostUrl&amp;diff=126&amp;oldid=prev"/>
		<updated>2018-06-22T15:35:40Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;#039;&amp;#039;&amp;#039;posturl&amp;#039;&amp;#039;&amp;#039; Usage of postdata(url, data):  &amp;lt;code&amp;gt;temp = postdata(&amp;#039;[http://www.yourdomain.com/postdata.php%27 http://www.yourdomain.com/postdata.php&amp;#039;], {&amp;#039;field1&amp;#039;: &amp;#039;field1data...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;posturl&amp;#039;&amp;#039;&amp;#039; Usage of postdata(url, data):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;temp = postdata(&amp;#039;[http://www.yourdomain.com/postdata.php%27 http://www.yourdomain.com/postdata.php&amp;#039;], {&amp;#039;field1&amp;#039;: &amp;#039;field1data&amp;#039;, &amp;#039;field2&amp;#039;: &amp;#039;field2data&amp;#039;})&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import string&lt;br /&gt;
import socket&lt;br /&gt;
import os&lt;br /&gt;
import time&lt;br /&gt;
import sys&lt;br /&gt;
import re&lt;br /&gt;
import urlparse&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    unicode&lt;br /&gt;
except NameError:&lt;br /&gt;
    def _is_unicode(x):&lt;br /&gt;
        return 0&lt;br /&gt;
else:&lt;br /&gt;
    def _is_unicode(x):&lt;br /&gt;
        return isinstance(x, unicode)&lt;br /&gt;
&lt;br /&gt;
def toBytes(url):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;toBytes(u&amp;quot;URL&amp;quot;) --&amp;gt; &amp;#039;URL&amp;#039;.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    # Most URL schemes require ASCII. If that changes, the conversion&lt;br /&gt;
    # can be relaxed&lt;br /&gt;
    if _is_unicode(url):&lt;br /&gt;
        try:&lt;br /&gt;
            url = url.encode(&amp;quot;ASCII&amp;quot;)&lt;br /&gt;
        except UnicodeError:&lt;br /&gt;
            raise UnicodeError(&amp;quot;URL &amp;quot; + repr(url) +&lt;br /&gt;
                               &amp;quot; contains non-ASCII characters&amp;quot;)&lt;br /&gt;
    return url&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def unquote(s):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;unquote(&amp;#039;abc%20def&amp;#039;) -&amp;gt; &amp;#039;abc def&amp;#039;.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    mychr = chr&lt;br /&gt;
    myatoi = int&lt;br /&gt;
    list = s.split(&amp;#039;%&amp;#039;)&lt;br /&gt;
    res = [list[0]]&lt;br /&gt;
    myappend = res.append&lt;br /&gt;
    del list[0]&lt;br /&gt;
    for item in list:&lt;br /&gt;
        if item[1:2]:&lt;br /&gt;
            try:&lt;br /&gt;
                myappend(mychr(myatoi(item[:2], 16))&lt;br /&gt;
                     + item[2:])&lt;br /&gt;
            except ValueError:&lt;br /&gt;
                myappend(&amp;#039;%&amp;#039; + item)&lt;br /&gt;
        else:&lt;br /&gt;
            myappend(&amp;#039;%&amp;#039; + item)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(res)&lt;br /&gt;
&lt;br /&gt;
def unquote_plus(s):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;unquote(&amp;#039;%7e/abc+def&amp;#039;) -&amp;gt; &amp;#039;~/abc def&amp;#039;&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if &amp;#039;+&amp;#039; in s:&lt;br /&gt;
        # replace &amp;#039;+&amp;#039; with &amp;#039; &amp;#039;&lt;br /&gt;
        s = &amp;#039; &amp;#039;.join(s.split(&amp;#039;+&amp;#039;))&lt;br /&gt;
    return unquote(s)&lt;br /&gt;
&lt;br /&gt;
always_safe = (&amp;#039;ABCDEFGHIJKLMNOPQRSTUVWXYZ&amp;#039;&lt;br /&gt;
               &amp;#039;abcdefghijklmnopqrstuvwxyz&amp;#039;&lt;br /&gt;
               &amp;#039;0123456789&amp;#039; &amp;#039;_.-&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
_fast_safe_test = always_safe + &amp;#039;/&amp;#039;&lt;br /&gt;
_fast_safe = None&lt;br /&gt;
&lt;br /&gt;
def _fast_quote(s):&lt;br /&gt;
    global _fast_safe&lt;br /&gt;
    if _fast_safe is None:&lt;br /&gt;
        _fast_safe = {}&lt;br /&gt;
        for c in _fast_safe_test:&lt;br /&gt;
            _fast_safe[c] = c&lt;br /&gt;
    res = list(s)&lt;br /&gt;
    for i in range(len(res)):&lt;br /&gt;
        c = res[i]&lt;br /&gt;
        if not c in _fast_safe:&lt;br /&gt;
            res[i] = &amp;#039;%%%02X&amp;#039; % ord(c)&lt;br /&gt;
    return &amp;#039;&amp;#039;.join(res)&lt;br /&gt;
&lt;br /&gt;
def quote(s, safe = &amp;#039;/&amp;#039;):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;quote(&amp;#039;abc def&amp;#039;) -&amp;gt; &amp;#039;abc%20def&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    Each part of a URL, e.g. the path info, the query, etc., has a&lt;br /&gt;
    different set of reserved characters that must be quoted.&lt;br /&gt;
&lt;br /&gt;
    RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists&lt;br /&gt;
    the following reserved characters.&lt;br /&gt;
&lt;br /&gt;
    reserved    = &amp;quot;;&amp;quot; | &amp;quot;/&amp;quot; | &amp;quot;?&amp;quot; | &amp;quot;:&amp;quot; | &amp;quot;@&amp;quot; | &amp;quot;&amp;amp;&amp;quot; | &amp;quot;=&amp;quot; | &amp;quot;+&amp;quot; |&lt;br /&gt;
                  &amp;quot;$&amp;quot; | &amp;quot;,&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    Each of these characters is reserved in some component of a URL,&lt;br /&gt;
    but not necessarily in all of them.&lt;br /&gt;
&lt;br /&gt;
    By default, the quote function is intended for quoting the path&lt;br /&gt;
    section of a URL.  Thus, it will not encode &amp;#039;/&amp;#039;.  This character&lt;br /&gt;
    is reserved, but in typical usage the quote function is being&lt;br /&gt;
    called on a path where the existing slash characters are used as&lt;br /&gt;
    reserved characters.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    safe = always_safe + safe&lt;br /&gt;
    if _fast_safe_test == safe:&lt;br /&gt;
        return _fast_quote(s)&lt;br /&gt;
    res = list(s)&lt;br /&gt;
    for i in range(len(res)):&lt;br /&gt;
        c = res[i]&lt;br /&gt;
        if c not in safe:&lt;br /&gt;
            res[i] = &amp;#039;%%%02X&amp;#039; % ord(c)&lt;br /&gt;
    return &amp;#039;&amp;#039;.join(res)&lt;br /&gt;
&lt;br /&gt;
def quote_plus(s, safe = &amp;#039;&amp;#039;):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Quote the query fragment of a URL; replacing &amp;#039; &amp;#039; with &amp;#039;+&amp;#039;&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if &amp;#039; &amp;#039; in s:&lt;br /&gt;
        l = s.split(&amp;#039; &amp;#039;)&lt;br /&gt;
        for i in range(len(l)):&lt;br /&gt;
            l[i] = quote(l[i], safe)&lt;br /&gt;
        return &amp;#039;+&amp;#039;.join(l)&lt;br /&gt;
    else:&lt;br /&gt;
        return quote(s, safe)&lt;br /&gt;
&lt;br /&gt;
def urlencode(query,doseq=0):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Encode a sequence of two-element tuples or dictionary into a URL query string.&lt;br /&gt;
&lt;br /&gt;
    If any values in the query arg are sequences and doseq is true, each&lt;br /&gt;
    sequence element is converted to a separate parameter.&lt;br /&gt;
&lt;br /&gt;
    If the query arg is a sequence of two-element tuples, the order of the&lt;br /&gt;
    parameters in the output will match the order of parameters in the&lt;br /&gt;
    input.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if hasattr(query,&amp;quot;items&amp;quot;):&lt;br /&gt;
        # mapping objects&lt;br /&gt;
        query = query.items()&lt;br /&gt;
    else:&lt;br /&gt;
        # it&amp;#039;s a bother at times that strings and string-like objects are&lt;br /&gt;
        # sequences...&lt;br /&gt;
        try:&lt;br /&gt;
            # non-sequence items should not work with len()&lt;br /&gt;
            # non-empty strings will fail this&lt;br /&gt;
            if len(query) and not isinstance(query[0], tuple):&lt;br /&gt;
                raise TypeError&lt;br /&gt;
            # zero-length sequences of all types will get here and succeed,&lt;br /&gt;
            # but that&amp;#039;s a minor nit - since the original implementation&lt;br /&gt;
            # allowed empty dicts that type of behavior probably should be&lt;br /&gt;
            # preserved for consistency&lt;br /&gt;
        except TypeError:&lt;br /&gt;
            ty,va,tb = sys.exc_info()&lt;br /&gt;
            raise TypeError, &amp;quot;not a valid non-string sequence or mapping object&amp;quot;, tb&lt;br /&gt;
&lt;br /&gt;
    l = []&lt;br /&gt;
    if not doseq:&lt;br /&gt;
        # preserve old behavior&lt;br /&gt;
        for k, v in query:&lt;br /&gt;
            k = quote_plus(str(k))&lt;br /&gt;
            v = quote_plus(str(v))&lt;br /&gt;
            l.append(k + &amp;#039;=&amp;#039; + v)&lt;br /&gt;
    else:&lt;br /&gt;
        for k, v in query:&lt;br /&gt;
            k = quote_plus(str(k))&lt;br /&gt;
            if isinstance(v, str):&lt;br /&gt;
                v = quote_plus(v)&lt;br /&gt;
                l.append(k + &amp;#039;=&amp;#039; + v)&lt;br /&gt;
            elif _is_unicode(v):&lt;br /&gt;
                # is there a reasonable way to convert to ASCII?&lt;br /&gt;
                # encode generates a string, but &amp;quot;replace&amp;quot; or &amp;quot;ignore&amp;quot;&lt;br /&gt;
                # lose information and &amp;quot;strict&amp;quot; can raise UnicodeError&lt;br /&gt;
                v = quote_plus(v.encode(&amp;quot;ASCII&amp;quot;,&amp;quot;replace&amp;quot;))&lt;br /&gt;
                l.append(k + &amp;#039;=&amp;#039; + v)&lt;br /&gt;
            else:&lt;br /&gt;
                try:&lt;br /&gt;
                    # is this a sufficient test for sequence-ness?&lt;br /&gt;
                    x = len(v)&lt;br /&gt;
                except TypeError:&lt;br /&gt;
                    # not a sequence&lt;br /&gt;
                    v = quote_plus(str(v))&lt;br /&gt;
                    l.append(k + &amp;#039;=&amp;#039; + v)&lt;br /&gt;
                else:&lt;br /&gt;
                    # loop over the sequence&lt;br /&gt;
                    for elt in v:&lt;br /&gt;
                        l.append(k + &amp;#039;=&amp;#039; + quote_plus(str(elt)))&lt;br /&gt;
    return &amp;#039;&amp;amp;&amp;#039;.join(l)&lt;br /&gt;
&lt;br /&gt;
def postdata(url, data):&lt;br /&gt;
    print &amp;#039;in postdata function&amp;#039;&lt;br /&gt;
        urldata = urlparse.urlparse(url)&lt;br /&gt;
        hostname = urldata[1]&lt;br /&gt;
        path = urldata[2]&lt;br /&gt;
    print hostname, path&lt;br /&gt;
        formdata = bf2.urllib.urlencode(data)&lt;br /&gt;
    print &amp;quot;formdata&amp;quot;, formdata&lt;br /&gt;
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)&lt;br /&gt;
        s.connect((hostname, 80))&lt;br /&gt;
        s.send(&amp;quot;POST %s HTTP/1.0\n&amp;quot; % path)&lt;br /&gt;
        s.send(&amp;quot;Host: %s\n&amp;quot; % hostname)&lt;br /&gt;
        s.send(&amp;quot;Connection: close\n&amp;quot;)&lt;br /&gt;
        s.send(&amp;quot;Content-type: application/x-www-form-urlencoded\n&amp;quot;)&lt;br /&gt;
        contentlength = &amp;quot;Content-length: %s\n\n&amp;quot; % len(formdata)&lt;br /&gt;
        s.send(contentlength)&lt;br /&gt;
        s.send(&amp;quot;%s&amp;quot; % formdata)&lt;br /&gt;
        splitter = re.compile(&amp;#039;\r\n&amp;#039;)&lt;br /&gt;
        while 1:&lt;br /&gt;
            buf = s.recv(1000)&lt;br /&gt;
            if not buf:&lt;br /&gt;
                break&lt;br /&gt;
            var = splitter.split(buf)&lt;br /&gt;
&lt;br /&gt;
        s.close()&lt;br /&gt;
        return &amp;#039;\r\n&amp;#039;.join(var)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>