Exemplo n.º 1
0
 def __init__(self):
  dir='E:\\Python\\apps\\simon816\\cURL\\'
  self.console=Console()
  self.console.console('curl >',"CURL")
  self.console.bodystyle['input']={'color':'#117711'}
  self.console.bodystyle['output']={'color':'#000088'}
  self.console.bind('exec_cmd',self.command)
  def p(a,r):
      #self.console.oldstd['out'].write(repr(a) + '\n')
      return r
  self.console.bind('get_text_css',lambda a=None:
   p(a,{'font-antialias':'on','font-size':'15'})
  )
  self.UserPassStore={}
  self.protocols={
   'http':[80,httplib.HTTPConnection],
   'https':[443,httplib.HTTPSConnection]
  }
  if not os.path.exists(dir):os.makedirs(dir)
  os.chdir(dir)
  self.argParser=ArgumentParser()
  # arguments in order and agree with the specification at
  # http://curl.haxx.se/docs/manpage.html
  self.add_arg('-0',0,['--http1.0'],'Use HTTP/1.0')
  self.add_arg('-A',2,['--user-agent'],'Sets user-agent')
  self.add_arg('-b',2,['--cookie'],'Send cookie')
  self.add_arg('-c',2,['--cookie-jar'],'Recieve cookie')
  self.add_arg('--connect-timeout',2,d='Set timeout')
  self.add_arg('-d',2,['--data','--data-ascii'],'POST Data')
  self.add_arg('-D',2,['--dump-header'],'Send output to a file')
  self.add_arg('-e',2,['--referer'],'Set referer header')
  self.add_arg('-F',2,['--form'],'POST a form, usally file upload')
  self.add_arg('-G',0,['--get'],'Set a GET parameter')
  self.add_arg('-H',2,['--header'],'Set a header')
  self.add_arg('-i',0,['--include'],'Return headers recieved')
  self.add_arg('-I',0,['--head'],'Use the HEAD verb')
  self.add_arg('-L',0,['--location'], 'Follow Location headers when a 3XX status code is returned')
  self.add_arg('-o',2,['--output'],'Where to dump output')
  self.add_arg('-O',0,['--remote-name'])
  self.add_arg('-s',0,['--silent'])
  self.add_arg('-u',1,['--user'],'Sets the user, using Basic auth')
  self.add_arg('--url',2,d='Specify URL to connect to')
  self.add_arg('-v',0,['--verbose'],'Makes curl talk a lot')
  self.add_arg('-X',2,['--request'],'Set HTTP verb')
  self.add_arg('-h',0,['--help'],'Displays help')
  self.maxredirs=10
  self.redirs = 0
  self.console.shell_run('http://google.com')
Exemplo n.º 2
0
if __name__ == '__main__':

    class Env(dict):
        def __init__(self):
            super(Env, self).__init__(globals())

        def __getitem__(self, a):
            print a
            return super(Env, self).__getitem__(a)

        def __setitem__(self, a, v):
            print a
            globals()[a] = v

    from simon816.console import Console
    m = Console()
    env = Env()
    m.console('> ')
    m.bodystyle['input'] = {'font-size': 20}
    m.bodystyle['printer'] = {'font-size': 20, 'color': '#0000FF'}
    m.bodystyle['output'] = {
        'font-size': 17,
        'color': '#Ff7f00',
        'font-weight': 'bold',
        'font-style': 'italic'
    }

    def e(c):
        if c.startswith('structure'):
            m.output(repr(globals()[c.split(' ')[1]]))
            return