Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67a
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Internet > HTTP (WWW)

    Doze 0.3

    Download button

    No screenshots available
    Downloads: 90  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Eric Moritz | More programs
    BSD License / FREE
    August 27th, 2012, 18:45 GMT
    ROOT / Internet / HTTP (WWW)

     Read user reviews (0)  Refer to a friend  Subscribe

    Doze description

    Easy URL creation

    Doze is a URL building module inspired by slumber.

    This project attempts to take what is awesome about slumber while enabling more flexibility.

    Usage

    We will demonstrate how to fetch data from the twitter API:

    import requests
    from doze import url

    twitter = url("http://api.twitter.com/1/")
    user_lookup = twitter.users("lookup.json")

    # generates "http://api.twitter.com/1/lookup.json?screen_name=ericmoritz"
    response = requests.get(str(user_lookup(screen_name="ericmoritz")))

    if response.status_code == 200:
     data = response.json
    else:
     data = None


    While this code is a bit more verbose it give us much more flexibility and control over the fetching and serialization of the data.

    For instance if we wanted to add a object_hook to the json.loads:

    if response.status_code == 200:
     data = json.loads(response.content,
     object_hook=custom_object_hook)
    else:
     data = None


    You can also reuse user_lookup to compose multiple requests:

    import requests
    from doze import url

    twitter = url("http://api.twitter.com/1/")
    user_lookup = twitter.users("lookup.json")

    # Fetch the user_lookup data for each screen name
    users = []
    for screen_name in ["ericmoritz", "montylounge"]:
     url = str(user_lookup(screen_name=screen_name))
     response = requests.get(url)
     if response.status_code == 200:
     users.append(json.loads(response.content))


    If you find the dotted notation awkward you can pass the path items as arguments and the url params as kwargs:

    from doze import url

    endpoint = url("http://example.com/v1")

    # dotted way
    def sections(section_id):
     # http://example.com/v1/sections/{section_id}?page=2
     url = str(endpoint.sections(section_id, page=2))
     return requests.get(url).json

    # "functional way"
    def sections(section_id):
     # http://example.com/v1/sections/{section_id}?page=2
     url = str(endpoint("sections", section_id, page=2))
     return requests.get(url).json



    Product's homepage

    Requirements:

    · Python

      


    TAGS:

    URL creation | URL construction | URL building | URL | construction | creation

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM