Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'things.': 0.05; 'elegant': 0.07; 'executed': 0.07; 'params': 0.07; 'ugly': 0.07; 'works.': 0.07; 'wrapper': 0.07; 'function:': 0.09; 'iterate': 0.09; 'received:mail-vb0-f46.google.com': 0.09; 'subject:2.7': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'library': 0.15; 'essentials': 0.16; 'eval': 0.16; 'hell.': 0.16; 'sequential': 0.16; 'subject:requests': 0.16; 'received:209.85.212.46': 0.18; '(or': 0.18; 'define': 0.20; 'written': 0.20; 'bit': 0.21; 'lets': 0.22; 'runs': 0.22; 'cc:2**0': 0.23; 'matching': 0.23; 'task': 0.23; 'cc:no real name:2**0': 0.24; 'command': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'wondering': 0.26; 'appreciated': 0.27; 'message- id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'skip:( 20': 0.28; 'credentials': 0.29; 'probably': 0.29; "i'm": 0.29; 'maybe': 0.29; 'worked': 0.30; 'code': 0.31; 'print': 0.32; 'certain': 0.33; 'problem': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'whatever': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'subject:with': 0.36; 'subject: (': 0.36; 'moment': 0.37; 'ones': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'positive': 0.38; 'some': 0.38; 'header:Received:5': 0.40; 'help': 0.40; 'your': 0.60; 'most': 0.61; 'places': 0.61; 'more': 0.63; 'services': 0.64; ':).': 0.84; 'calls,': 0.84; 'services?': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=CMP0qfa1jDhYBNF48FY21YzsZesxsoP1Dn4p1DMJxNE=; b=x0Z15qXTgbjelRcRsLDufsxaEui7wtnsbzTh1HjPTctTLuUxXus19y8+pFg+K+wyP9 CHnMeW9w0odI+GxuiRFRivxarjpHbeR3c2IlOFTLm3ld8qR0xodSuIB3H1902FNTr+fE 2hBsDr4R5UOJuCsDI4V1hIzsbzJP91Ba26xw7has36eLWLwaSJ7BkBtHs8H2VS+LAsJl lJvY+BYqejva9YzDC6nm0gN4OQEneGQn3kK3Dk7xj06eQAdkrINXRfPACb36STYHEVBn roXQiu5PI7sTX2hBPRJXBDBPFpXfaHflCbknzO2kGmIALQSLIfIoor6ZL92NX5VYp4T3 305g== MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 14 Sep 2012 06:56:30 -0400 Subject: Re: Batching HTTP requests with httplib (Python 2.7) From: Dwight Hutto To: Chicken McNuggets Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 69 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347620198 news.xs4all.nl 6896 [2001:888:2000:d::a6]:60507 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29152 >> | The problem with most web services is that they require a list of >> | sequential commands to be executed in a certain order to complete a >> | given task (or at least the one I am using does) so having to manually >> | call each command is a bit of a pain. How would you go about the design >> | of a library to interact with these services? >> | >> | Any help is greatly appreciated :). >> >> Maybe I'm missing something. What's hard about: >> >> - wrapping the web services calls in a simple wrapper which >> composes the call, runs it, and returns the result parts >> This lets you hide all the waffle about the base URL, >> credentials etc in the wrapper and only supply the essentials >> at call time. >> >> - writing your workflow thing then as a simple function: >> >> def doit(...): >> web_service_call1(...) >> web_service_call2(...) >> web_service_call3(...) >> >> with whatever internal control is required? >> >> This has worked for me for simple things. >> >> What am I missing about the larger context? >> > > That is what I have at the moment but it is ugly as hell. I was wondering if > there was a somewhat more elegant solution that I was missing. > -- Well if the code works it works. There probably is a better way than what I came up with: def web_service_call0(y): print "Service call = %i)" % y def web_service_call1(y): print "Service call = %i)" % y def web_service_call2(y): print "Service call = %i)" % y def web_service_call3(y): print "Service call = %i)" % y def web_service_call4(y): print "Service call = %i)" % y service_num_list = [num for num in range(0,5)] for service_num in service_num_list: eval("web_service_call%i(%i)" % (service_num,service_num)) I just define the service calls, and iterate through them with an eval that places in the service call num, but you would have to have a matching list of the params that would go with each one. I'm almost positive there will be some more well written ones on the way. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com