• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(5712)  |  Call(4801)  |  Derive(0)  |  Import(911)
Encode a sequence of two-element tuples or dictionary into a URL query string.

If any values in the query arg are sequences and doseq is true, each
sequence element is converted to a separate parameter.

If the query arg is a sequence of two-element tuples, the order of the
parameters in the output will match the order of parameters in the
input.

        def urlencode(query, doseq=0):
    """Encode a sequence of two-element tuples or dictionary into a URL query string.

    If any values in the query arg are sequences and doseq is true, each
    sequence element is converted to a separate parameter.

    If the query arg is a sequence of two-element tuples, the order of the
    parameters in the output will match the order of parameters in the
    input.
    """

    if hasattr(query,"items"):
        # mapping objects
        query = query.items()
    else:
        # it's a bother at times that strings and string-like objects are
        # sequences...
        try:
            # non-sequence items should not work with len()
            # non-empty strings will fail this
            if len(query) and not isinstance(query[0], tuple):
                raise TypeError
            # zero-length sequences of all types will get here and succeed,
            # but that's a minor nit - since the original implementation
            # allowed empty dicts that type of behavior probably should be
            # preserved for consistency
        except TypeError:
            ty,va,tb = sys.exc_info()
            raise TypeError, "not a valid non-string sequence or mapping object", tb

    l = []
    if not doseq:
        # preserve old behavior
        for k, v in query:
            k = quote_plus(str(k))
            v = quote_plus(str(v))
            l.append(k + '=' + v)
    else:
        for k, v in query:
            k = quote_plus(str(k))
            if isinstance(v, str):
                v = quote_plus(v)
                l.append(k + '=' + v)
            elif _is_unicode(v):
                # is there a reasonable way to convert to ASCII?
                # encode generates a string, but "replace" or "ignore"
                # lose information and "strict" can raise UnicodeError
                v = quote_plus(v.encode("ASCII","replace"))
                l.append(k + '=' + v)
            else:
                try:
                    # is this a sufficient test for sequence-ness?
                    len(v)
                except TypeError:
                    # not a sequence
                    v = quote_plus(str(v))
                    l.append(k + '=' + v)
                else:
                    # loop over the sequence
                    for elt in v:
                        l.append(k + '=' + quote_plus(str(elt)))
    return '&'.join(l)
        


src/b/r/braintree_python_examples-HEAD/tr_checkout_app_engine/web/http.py   braintree_python_examples(Download)
            return utils.utf8(value)
 
    query = dict([(k, convert(v, doseq)) for k, v in query.items()])
    return urllib.urlencode(query, doseq=doseq)
 
def changequery(query=None, **kw):
    """

src/m/e/mendeley-oapi-example-HEAD/oauth2/__init__.py   mendeley-oapi-example(Download)
    def __str__(self):
        data = {'oauth_consumer_key': self.key,
            'oauth_consumer_secret': self.secret}
 
        return urllib.urlencode(data)
 
 
 
        if self.callback_confirmed is not None:
            data['oauth_callback_confirmed'] = self.callback_confirmed
        return urllib.urlencode(data)
 
    @staticmethod
    def from_string(s):
    def to_postdata(self):
        """Serialize as post data for a POST request."""
        # tell urlencode to deal with sequence values and map them correctly
        # to resulting querystring. for example self["k"] = ["v1", "v2"] will
        # result in 'k=v1&k=v2' and not k=%5B%27v1%27%2C+%27v2%27%5D
        encoded_str = urllib.urlencode(self, True)
        return encoded_str.replace('+', '%20')
        for k, v in self.items():
            query.setdefault(k, []).append(v)
        url = (base_url.scheme, base_url.netloc, base_url.path, base_url.params,
               urllib.urlencode(query, True), base_url.fragment)
        return urlparse.urlunparse(url)
 
    def get_parameter(self, parameter):
        query = urlparse.urlparse(self.url)[4]
        items.extend(self._split_url_string(query).items())
 
        encoded_str = urllib.urlencode(sorted(items))
        # Encode signature parameters per Oauth Core 1.0 protocol
        # spec draft 7, section 3.6
        # (http://tools.ietf.org/html/draft-hammer-oauth-07#section-3.6)

src/r/e/remoteobjects-1.1.1/examples/twitter.py   remoteobjects(Download)
import httplib
from optparse import OptionParser
import sys
from urllib import urlencode, quote_plus
from urlparse import urljoin, urlunsplit
 
from httplib2 import Http
    def get_user(cls, http=None, **kwargs):
        url = '/users/show'
        if 'id' in kwargs:
            url += '/%s.json' % quote_plus(kwargs['id'])
        else:
            url += '.json'
        query = urlencode(filter(lambda x: x in ('screen_name', 'user_id'), kwargs))
    def get_messages(cls, http=None, **kwargs):
        url = '/direct_messages.json'
        query = urlencode(filter(lambda x: x in ('since_id', 'page'), kwargs))
        url = urlunsplit((None, None, url, query, None))
        return cls.get(urljoin(Twitter.endpoint, url), http=http)
 
    @classmethod
    def get_sent_messages(cls, http=None, **kwargs):
        url = '/direct_messages/sent.json'
        query = urlencode(filter(lambda x: x in ('since_id', 'page'), kwargs))
    def get_related(cls, relation, http=None, **kwargs):
        url = '/statuses/%s' % relation
        if 'id' in kwargs:
            url += '/%s.json' % quote_plus(kwargs['id'])
        else:
            url += '.json'
        query = urlencode(filter(lambda x: x in ('screen_name', 'user_id', 'page'), kwargs))
    def friends(cls, http=None, **kwargs):
        query = urlencode(filter(lambda x: x in ('since_id', 'max_id', 'count', 'page'), kwargs))
        url = urlunsplit((None, None, '/statuses/friends_timeline.json', query, None))
        return cls.get(urljoin(Twitter.endpoint, url), http=http)
 
    @classmethod
    def user(cls, http=None, **kwargs):
        url = '/statuses/user_timeline'
        if 'id' in kwargs:
            url += '/%s.json' % quote_plus(kwargs['id'])
        else:
            url += '.json'
        query = urlencode(filter(lambda x: x in ('screen_name', 'user_id', 'since_id', 'max_id', 'page'), kwargs))
    def mentions(cls, http=None, **kwargs):
        query = urlencode(filter(lambda x: x in ('since_id', 'max_id', 'page'), kwargs))
        url = urlunsplit((None, None, '/statuses/mentions.json', query, None))
        return cls.get(urljoin(Twitter.endpoint, url), http=http)
 
 
class Twitter(Http):

src/r/d/Rdbhdb-HEAD/examples/get_no_series_terms.py   Rdbhdb(Download)
# Direct connection; Not through API; Prints rows of tables accounts and branches
 
from urllib import urlencode
from urllib2 import Request, urlopen
 
url = 'http://rdbhost.com/db/'+'s000015'
authcode = 'KF7IUQPlwfSth4sBvjdqqanHkojAZzEjMshrkfEV0O53yz6w6v'
req = Request(url)
flds0 = [('authcode',authcode)]
postdata = urlencode(flds0)
x1 = "DROP TABLE IF EXISTS rdbhdbTest"
try:
    flds1 = [ ('q', x1),('format','xml'),('authcode',authcode)]
    postdata = urlencode(flds1)
    req.add_data(postdata)
    pg=urlopen(req)
    text=pg.read()
    pass
finally:
    flds1 = [ ('q', x1),('format','xml'),('authcode',authcode)]
    postdata = urlencode(flds1)
    req.add_data(postdata)
    pg=urlopen(req)
    text=pg.read()

src/r/d/Rdbhdb-HEAD/examples/ex4.py   Rdbhdb(Download)
# Direct connection; Not through API; Creates table test and then deletes it.
 
from urllib import urlencode
from urllib2 import Request, urlopen
 
url = 'http://rdbhost.com/db/'+'s000015'
authcode = 'KF7IUQPlwfSth4sBvjdqqanHkojAZzEjMshrkfEV0O53yz6w6v'
req = Request(url)
flds0 = [('authcode',authcode)]
postdata = urlencode(flds0)
);'''
q2 = "DROP TABLE test;"
flds1 = [ ('q', q1),('format','xml'),('authcode',authcode)]
postdata = urlencode(flds1)
req.add_data(postdata)
pg=urlopen(req)
text=pg.read()
print text
flds2 = [ ('q', q2),('format','xml'),('authcode',authcode)]
postdata = urlencode(flds2)

src/r/d/Rdbhdb-HEAD/examples/ex10.py   Rdbhdb(Download)
# Direct connection; Not through API; Prints rows of tables accounts and branches
 
from urllib import urlencode
from urllib2 import Request, urlopen
 
url = 'http://rdbhost.com/db/'+'s000015'
authcode = 'KF7IUQPlwfSth4sBvjdqqanHkojAZzEjMshrkfEV0O53yz6w6v'
req = Request(url)
print req
flds0 = [('authcode',authcode)]
postdata = urlencode(flds0)
req.add_data(postdata)
print req
flds1 = [ ('q', 'SELECT * FROM accounts'),('format','xml'),('authcode',authcode)]
postdata = urlencode(flds1)
req.add_data(postdata)
pg=urlopen(req)
text=pg.read()
print text
flds2 = [ ('q', 'SELECT * FROM branches'),('format','xml'),('authcode',authcode)]
postdata = urlencode(flds2)

src/p/y/python-sdk-HEAD/examples/oauth/facebookoauth.py   python-sdk(Download)
            # basic profile info
            profile = json.load(urllib.urlopen(
                "https://graph.facebook.com/me?" +
                urllib.urlencode(dict(access_token=access_token))))
            user = User(key_name=str(profile["id"]), id=str(profile["id"]),
                        name=profile["name"], access_token=access_token,
                        profile_url=profile["link"])
        else:
            self.redirect(
                "https://graph.facebook.com/oauth/authorize?" +
                urllib.urlencode(args))
 
 
class LogoutHandler(BaseHandler):

src/b/a/badger-lib-HEAD/packages/gdata/samples/authsub/secure_authsub.py   badger-lib(Download)
        request_url=self.H9_AUTHSUB_HANDLER,
        include_scopes_in_next=include_scopes_in_next)
    if extra_params:
      auth_sub_url = '%s&%s' % (auth_sub_url, urllib.urlencode(extra_params))
    return auth_sub_url
 
  def SetPrivateKey(self, filename):
 
    # Query the Health Data API
    params = {'digest': 'true', 'strict': 'true'}
    uri = '%s?%s' % (H9_PROFILE_FEED_URL, urllib.urlencode(params))
    feed = client.GetFeed(uri)
 
    req.write('<h4>Listing medications</h4>')

src/r/d/Rdbhdb-HEAD/examples/get_no_table_rows.py   Rdbhdb(Download)
# Direct connection; Not through API; Prints rows of tables accounts and branches
 
from urllib import urlencode
from urllib2 import Request, urlopen
 
url = 'http://rdbhost.com/db/'+'s000015'
authcode = 'KF7IUQPlwfSth4sBvjdqqanHkojAZzEjMshrkfEV0O53yz6w6v'
req = Request(url)
flds0 = [('authcode',authcode)]
postdata = urlencode(flds0)
req.add_data(postdata)
q = "SELECT COUNT(*) FROM pg_type WHERE typtype = \'b\' "
flds1 = [ ('q', q),('format','xml'),('authcode',authcode)]
postdata = urlencode(flds1)
req.add_data(postdata)
pg=urlopen(req)
text=pg.read()

src/d/j/django-datagrid-1.1/example/datagrid/templatetags/datagrid.py   django-datagrid(Download)
def get_pdf_link(context):
    getvars = {}
    if 'request' in context:
        request = context['request']
        getvars = request.GET.copy()
        getvars['is_pdf'] = 1
        getvars = urllib.urlencode(getvars)
        return {'getvars':getvars}
    else:
        getvars['is_pdf'] = 1
        getvars = urllib.urlencode(getvars)
def get_csv_link(context):
    getvars = {}
    if 'request' in context:
        request = context['request']
        getvars = request.GET.copy()
        getvars['is_csv'] = 1
        getvars = urllib.urlencode(getvars)
    else:
        getvars['is_csv'] = 1
        getvars = urllib.urlencode(getvars)
        getvars = request.GET.copy()
        if 'page' in getvars:
            getvars['page']
    getvars = urllib.urlencode(getvars)
 
    return {
        'hits': context['hits'],

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next