Permalink
Browse files

fix shell script

  • Loading branch information...
1 parent a21be97 commit 903b85781dc6bb31d99c73a0d665409476c76b6d @benoitc benoitc committed Feb 27, 2010
View
@@ -1,4 +1,4 @@
-2008,2010 (c) Benoît Chesneau <benoitc@e-engura.org>
+2008-2010 (c) Benoît Chesneau <benoitc@e-engura.org>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
View
@@ -8,6 +8,7 @@ PAPER =
BUILDDIR = _build
GHPIMPORT = ${PWD}/ghp-import
SPHINXTOGITHUB = ${PWD}/sphinxtogithub.py
+EPYDOC = epydoc
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
@@ -35,6 +36,7 @@ clean:
html: clean
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ $(EPYDOC) -o html/api ../restkit
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
@@ -32,6 +32,7 @@ <h1 class="logo"><a href="{{ pathto(master_doc) }}">restkit</a></h1>
{%- block relbar1 %}{% endblock %}
+
{% block footer %}
</div>
<div id="footer">
View
@@ -6,7 +6,10 @@
import sys, os
import restkit
-extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage']
+sys.path.append(os.getcwd())
+
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage',
+ 'extapi']
templates_path = ['_templates']
@@ -1,11 +0,0 @@
-Authentication
-==============
-
-Restkit support for now `basic authentication`_ and `OAuth`_. But any
-other authentication schema can easily be added using http filters.
-
-
-
-
-.. _basic authentification: http://www.ietf.org/rfc/rfc2617.txt
-.. _OAuth: http://oauth.net/
@@ -1,13 +0,0 @@
-Basic authentication
-++++++++++++++++++++
-
-To use `basic authentication` in a `Resource object` you can do::
-
- from restkit import Resource, BasicAuth
-
- auth = BasicAuth("username", "password")
- r = Resource("http://friendpaste.com", filters=[auth])
-
-Or simply use an authentication url::
-
- r = Resource("http://username:password@friendpaste.com")
View
@@ -1,4 +1,9 @@
-.. _documentation
+.. _doc:
Documentation
-=============
+=============
+
+.. toctree::
+ :maxdepth: 2
+
+ authentication
View
@@ -1,7 +1,7 @@
.. _oauth:
OAuth
-+++++
+=====
Restkit OAuth is based on `simplegeo python-oauth2 module <http://github.com/simplegeo/python-oauth2>`_ So you don't need other installation to use OAuth (you can also simply use restkit.oauth2 module in your applications).
@@ -16,7 +16,7 @@ With a list of tupple, the filter will try to match the path with the rule. It a
Example the rule `/some/resource/*` will match `/some/resource/other` and `/some/resource/other2`, while the rule `/some/resource` will only match the path `/some/resource`.
Simple client example:
-~~~~~~~~~~~~~~~~~~~~~~
+----------------------
::
View
@@ -23,10 +23,13 @@ Features
- HTTP Filters, you can hook requests in responses with your own callback
- Compatible with Python 2.x (>= 2.5)
-Contents:
-
.. toctree::
- :maxdepth: 2
+ :maxdepth: 1
+
+ installation
+ doc/index
+ api/index
+ news
Indices and tables
==================
View
@@ -1 +1,4 @@
-.. _news:
+.. _news:
+
+News
+====
View
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-from optparse import OptionParser
+import optparse as op
import os
import sys
import shutil
View
No changes.
View
@@ -1,153 +0,0 @@
-# -*- coding: utf-8 -
-#
-# This file is part of restkit released under the MIT license.
-# See the NOTICE for more information.
-
-import os
-import sys
-from optparse import OptionParser
-import urlparse
-import urllib
-
-from urlparse import parse_qs as parse_qs
-
-import restkit
-from restkit import httpc
-
-class Url(object):
- def __init__(self, string):
- parts = urlparse.urlsplit(urllib.unquote(string))
- if parts[0] != 'http' and parts[0] != 'https':
- raise ValueError('Invalid url: %s.' % string)
-
- if "@" in parts[1]:
- host = parts[1].split('@').pop()
- else:
- host = parts[1]
-
- self.hostname = host
- if parts[0] == 'http':
- self.port = 80
- else:
- self.port = 443
-
- if ":" in host:
- try:
- self.hostname, self.port = host.split(':')
- except:
- raise ValueError('Invalid url: %s.' % string)
-
- self.port = int(self.port)
-
- self.uri = "%s://%s" % (parts[0], host)
-
- if parts[2]:
- self.path = parts[2]
- else:
- self.path = ''
-
- if parts[3]:
- self.query = parse_qs(parts[3])
- else:
- self.query = {}
-
- self.username = parts.username
- self.password = parts.password
-
-
-def make_query(string, method='GET', fname=None,
- list_headers=None, output=None, proxy=None):
- try:
- uri = Url(string)
- except ValueError, e:
- print >>sys.stderr, e
- return
-
- if uri.username:
- res = restkit.Resource(uri.uri)
- res.add_authorization(httpc.BasicAuth((uri.username, uri.password)))
- else:
- res = restkit.Resource(uri.uri)
-
- list_headers = list_headers or []
- headers = {}
- if list_headers:
- for header in list_headers:
- if ":" in header:
- k, v = header.split(':')
- headers[k] = v
-
- payload = None
- if fname:
- if fname == '-':
- payload = sys.stdin.read()
- headers['Content-Length'] = len(payload)
- else:
- fname = os.path.normpath(os.path.join(os.getcwd(),fname))
- headers['Content-Length'] = os.path.getsize(fname)
- payload = open(fname, 'r')
-
- result = res.request(method, path=uri.path, payload=payload, headers=headers, **uri.query)
-
- output = output or ''
- if not output or output == '-':
- return result.body
- else:
- try:
- f = open(output, 'wb')
- for block in result.body_file:
- f.write(block)
- f.close()
- except:
- print >>sys.stderr, "Can't save result in %s" % output
- return
-
-
-def main():
- parser = OptionParser(usage='%prog [options] url [METHOD] [filename]', version="%prog " + restkit.__version__)
- parser.add_option('-H', '--header', action='append', dest='headers',
- help='http string header in the form of Key:Value. '+
- 'For example: "Accept: application/json" ')
- parser.add_option('-i', '--input', action='store', dest='input', metavar='FILE',
- help='the name of the file to read from')
- parser.add_option('-o', '--output', action='store', dest='output',
- help='the name of the file to write to')
-
- parser.add_option('--proxy', action='store', dest='proxy',
- help='Full uri of proxy, ex:\n'+
- 'http://username:password@proxy:port/')
-
- options, args = parser.parse_args()
-
- if len(args) < 1:
- return parser.error('incorrect number of arguments')
- if options.input:
- fname=options.input
- else:
- fname=None
-
- if len(args) == 3:
- return make_query(args[0], method=args[1], fname=args[2],
- list_headers=options.headers, output=options.output,
- proxy=options.proxy)
-
- elif len(args) == 2:
- if args[1] == "-":
- return make_query(args[0], method='POST', fname=args[1],
- list_headers=options.headers, output=options.output,
- proxy=options.proxy)
- return make_query(args[0], method=args[1], fname=fname,
- list_headers=options.headers, output=options.output,
- proxy=options.proxy)
- else:
- if options.input:
- method = 'POST'
- else:
- method='GET'
- return make_query(args[0], method=method, fname=fname,
- list_headers=options.headers, output=options.output,
- proxy=options.proxy)
-
-
-if __name__ == '__main__':
- main()
View
@@ -0,0 +1,90 @@
+# -*- coding: utf-8 -
+#
+# This file is part of restkit released under the MIT license.
+# See the NOTICE for more information.
+
+import os
+import optparse as op
+import sys
+
+from restkit import __version__, request
+
+__usage__ = "'%prog [options] url [METHOD] [filename]'"
+
+def options():
+ """ build command lines options """
+ return [
+ op.make_option('-H', '--header', action='append', dest='headers',
+ help='http string header in the form of Key:Value. '+
+ 'For example: "Accept: application/json" '),
+ op.make_option('-i', '--input', action='store', dest='input',
+ metavar='FILE', help='the name of the file to read from'),
+ op.make_option('-o', '--output', action='store', dest='output',
+ help='the name of the file to write to'),
+ op.make_option('--follow-redirect', action='store_false',
+ dest='follow_redirect', default=True)
+ ]
+
+def main():
+ """ function to manage restkit command line """
+ parser = op.OptionParser(usage=__usage__, option_list=options(),
+ version="%prog " + __version__)
+
+ opts, args = parser.parse_args()
+ args_len = len(args)
+
+ if args_len < 1:
+ return parser.error('incorrect number of arguments')
+
+ body = None
+ headers = []
+ if opts.input:
+ if opts.input == '-':
+ body = sys.stdin.read()
+ headers.append(("Content-Length", str(len(body))))
+ else:
+ fname = os.path.normpath(os.path.join(os.getcwd(),opts.input))
+ body = open(fname, 'r')
+
+ if opts.headers:
+ for header in opts.headers:
+ try:
+ k, v = header.split(':')
+ headers.append((k, v))
+ except ValueError:
+ pass
+
+ try:
+ if args_len == 3:
+ resp = request(args[0], method=args[1], body=body,
+ headers=headers, follow_redirect=opts.follow_redirect)
+ elif len(args) == 2:
+ if args[1] == "-":
+ body = sys.stdin.read()
+ headers.append(("Content-Length", str(len(body))))
+
+ resp = request(args[0], method=args[1], body=body,
+ headers=headers, follow_redirect=opts.follow_redirect)
+ else:
+ if opts.input:
+ method = 'POST'
+ else:
+ method='GET'
+ resp = request(args[0], method=method, body=body,
+ headers=headers, follow_redirect=opts.follow_redirect)
+
+ if opts.output:
+ f = open(opts.output, 'wb')
+ for block in resp.body_file:
+ f.write(block)
+ f.close()
+ else:
+ print resp.body
+
+ except Exception, e:
+ sys.stderr.write("An error happened: %s" % str(e))
+ sys.stderr.flush()
+ sys.exit(1)
+
+ sys.exit(0)
+
View
@@ -43,7 +43,7 @@
packages = find_packages(exclude=['tests']),
entry_points = {
'console_scripts': [
- 'restcli = restkit.bin.rest_cli:main',
+ 'restcli = restkit.console:main',
]
},

0 comments on commit 903b857

Please sign in to comment.