Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: jakubroztocil/httpie
base: 0.2.0
...
head fork: jakubroztocil/httpie
compare: 0.2.1
  • 11 commits
  • 9 files changed
  • 0 commit comments
  • 3 contributors
7 README.rst
View
@@ -188,7 +188,11 @@ Contributors
Changelog
---------
-* `New in development version <https://github.com/jkbr/httpie/compare/0.2.0...master>`_
+* `New in development version <https://github.com/jkbr/httpie/compare/0.2.1...master>`_
+* 0.2.1 (2012-06-13)
+ * Added compatibility with ``requests-0.12.1``.
+ * Dropped custom JSON and HTTP lexers in favor of the ones newly included in ``pygments-1.5``.
+ * `Complete changelog <https://github.com/jkbr/httpie/compare/0.2.0...0.2.1>`_
* 0.2.0 (2012-04-25)
* Added Python 3 support.
* Added the ability to print the HTTP request as well as the response (see ``--print`` and ``--verbose``).
@@ -198,5 +202,4 @@ Changelog
* Added support for field name escaping.
* Many bug fixes.
* `Complete changelog <https://github.com/jkbr/httpie/compare/0.1.6...0.2.0>`_
-
* `0.1.6 <https://github.com/jkbr/httpie/compare/0.1.4...0.1.6>`_ (2012-03-04)
2  httpie/__init__.py
View
@@ -3,5 +3,5 @@
"""
__author__ = 'Jakub Roztocil'
-__version__ = '0.2.0'
+__version__ = '0.2.1'
__licence__ = 'BSD'
4 httpie/__main__.py
View
@@ -1,8 +1,11 @@
#!/usr/bin/env python
import sys
import json
+
import requests
+
from requests.compat import str
+
from . import httpmessage
from . import cliparse
from . import cli
@@ -91,6 +94,7 @@ def _get_output(args, stdout_isatty, response):
with_headers=cliparse.OUT_REQ_HEADERS in args.output_options,
with_body=cliparse.OUT_REQ_BODY in args.output_options
))
+ output.append('\n')
if do_output_response:
output.append('\n')
8 httpie/cliparse.py
View
@@ -3,15 +3,19 @@
"""
import os
-import json
import re
+import json
+import argparse
+
from collections import namedtuple
+
try:
from collections import OrderedDict
except ImportError:
OrderedDict = dict
-import argparse
+
from requests.structures import CaseInsensitiveDict
+
from . import __version__
28 httpie/httpmessage.py
View
@@ -18,6 +18,13 @@ def from_request(request):
request_headers = dict(request.headers)
if 'Host' not in request_headers:
request_headers['Host'] = url.netloc
+
+ try:
+ body = request.data
+ except AttributeError:
+ # requests < 0.12.1
+ body = request._enc_data
+
return HTTPMessage(
line='{method} {path} HTTP/1.1'.format(
method=request.method,
@@ -25,7 +32,7 @@ def from_request(request):
headers='\n'.join(str('%s: %s') % (name, value)
for name, value
in request_headers.items()),
- body=request._enc_data,
+ body=body,
content_type=request_headers.get('Content-Type')
)
@@ -38,7 +45,7 @@ def from_response(response):
return HTTPMessage(
line='HTTP/{version} {status} {reason}'.format(
version='.'.join(str(original.version)),
- status=original.status, reason=original.reason,),
+ status=original.status, reason=original.reason),
headers=str(original.msg),
body=response.content.decode(encoding) if response.content else '',
content_type=response_headers.get('Content-Type'))
@@ -47,20 +54,21 @@ def from_response(response):
def format(message, prettifier=None,
with_headers=True, with_body=True):
"""Return a `unicode` representation of `message`. """
+ pretty = prettifier is not None
bits = []
+
if with_headers:
- if prettifier:
- bits.append(prettifier.headers(message.line))
- bits.append(prettifier.headers(message.headers))
- else:
- bits.append(message.line)
- bits.append(message.headers)
+ bits.append(message.line)
+ bits.append(message.headers)
+ if pretty:
+ bits = [prettifier.headers('\n'.join(bits))]
if with_body and message.body:
bits.append('\n')
+
if with_body and message.body:
- if prettifier and message.content_type:
+ if pretty and message.content_type:
bits.append(prettifier.body(message.body, message.content_type))
else:
bits.append(message.body)
- bits.append('\n')
+
return '\n'.join(bit.strip() for bit in bits)
51 httpie/pretty.py
View
@@ -1,14 +1,14 @@
import os
import json
+
import pygments
-from pygments import token
+
from pygments.util import ClassNotFound
-from pygments.lexers import get_lexer_for_mimetype
+from pygments.styles import get_style_by_name, STYLE_MAP
+from pygments.lexers import get_lexer_for_mimetype, HttpLexer
from pygments.formatters.terminal256 import Terminal256Formatter
from pygments.formatters.terminal import TerminalFormatter
-from pygments.lexer import RegexLexer, bygroups
-from pygments.styles import get_style_by_name, STYLE_MAP
-from .pygson import JSONLexer
+
from . import solarized
@@ -19,24 +19,6 @@
else TerminalFormatter)
-class HTTPLexer(RegexLexer):
- name = 'HTTP'
- aliases = ['http']
- filenames = ['*.http']
- tokens = {
- 'root': [
- (r'\s+', token.Text),
- # Request-Line
- (r'([A-Z]+\s+)(/.*?)(\s+HTTP/[\d.]+)', bygroups(
- token.Keyword, token.String, token.Keyword)),
- # Status-Line
- (r'(HTTP/[\d.]+\s+)(\d+)(\s+.+)', bygroups(
- token.Keyword, token.Number, token.String)),
- # Header
- (r'(.*?:)(.+)', bygroups(token.Name, token.Keyword))
- ]}
-
-
class PrettyHttp(object):
def __init__(self, style_name):
@@ -47,22 +29,21 @@ def __init__(self, style_name):
self.formatter = FORMATTER(style=style)
def headers(self, content):
- return pygments.highlight(content, HTTPLexer(), self.formatter)
+ return pygments.highlight(content, HttpLexer(), self.formatter)
def body(self, content, content_type):
- lexer = None
content_type = content_type.split(';')[0]
- if 'json' in content_type:
- lexer = JSONLexer()
+ try:
+ lexer = get_lexer_for_mimetype(content_type)
+ except ClassNotFound:
+ return content
+
+ if content_type == 'application/json':
try:
- # Indent the JSON data.
+ # Indent and sort the JSON data.
content = json.dumps(json.loads(content),
- sort_keys=True, indent=4)
- except Exception:
+ sort_keys=True, indent=4)
+ except:
pass
- if not lexer:
- try:
- lexer = get_lexer_for_mimetype(content_type)
- except ClassNotFound:
- return content
+
return pygments.highlight(content, lexer, self.formatter)
77 httpie/pygson.py
View
@@ -1,77 +0,0 @@
-"""
-JSON lexer by Norman Richards
-
-It's already been merged into Pygments but not released yet,
-so we are temporarily bundling it with HTTPie.
-
-It can be removed once Pygments > 1.4 has been released.
-
-See <https://github.com/jkbr/httpie/pull/25> for more details.
-
-"""
-import re
-from pygments import token
-from pygments.lexer import RegexLexer, include
-
-
-class JSONLexer(RegexLexer):
- name = 'JSON Lexer'
- aliases = ['json']
- filenames = ['*.json']
- mimetypes = []
-
-
- flags = re.DOTALL
- tokens = {
- 'whitespace': [
- (r'\s+', token.Text),
- ],
-
- # represents a simple terminal value
- 'simplevalue':[
- (r'(true|false|null)\b', token.Keyword.Constant),
- (r'-?[0-9]+', token.Number.Integer),
- (r'"(\\\\|\\"|[^"])*"', token.String.Double),
- ],
-
-
- # the right hand side of an object, after the attribute name
- 'objectattribute': [
- include('value'),
- (r':', token.Punctuation),
- # comma terminates the attribute but expects more
- (r',', token.Punctuation, '#pop'),
- # a closing bracket terminates the entire object, so pop twice
- (r'}', token.Punctuation, ('#pop', '#pop')),
- ],
-
- # a json object - { attr, attr, ... }
- 'objectvalue': [
- include('whitespace'),
- (r'"(\\\\|\\"|[^"])*"', token.Name.Tag, 'objectattribute'),
- (r'}', token.Punctuation, '#pop'),
- ],
-
- # json array - [ value, value, ... }
- 'arrayvalue': [
- include('whitespace'),
- include('value'),
- (r',', token.Punctuation),
- (r']', token.Punctuation, '#pop'),
- ],
-
- # a json value - either a simple value or a complex value (object or array)
- 'value': [
- include('whitespace'),
- include('simplevalue'),
- (r'{', token.Punctuation, 'objectvalue'),
- (r'\[', token.Punctuation, 'arrayvalue'),
- ],
-
-
- # the root of a json document would be a value
- 'root': [
- include('value'),
- ],
-
- }
3  httpie/solarized.py
View
@@ -27,7 +27,8 @@
"""
from pygments.style import Style
-from pygments.token import Token, Comment, Name, Keyword, Generic, Number, Operator, String
+from pygments.token import (Token, Comment, Name, Keyword, Generic, Number,
+ Operator, String)
BASE03 = '#002B36'
3  setup.py
View
@@ -9,7 +9,8 @@
sys.exit()
-requirements = ['requests>=0.10.1', 'Pygments>=1.4']
+# Debian has only requests==0.10.1 and httpie.deb depends on that.
+requirements = ['requests>=0.10.1', 'Pygments>=1.5']
if sys.version_info[:2] in ((2, 6), (3, 1)):
# argparse has been added in Python 3.2 / 2.7
requirements.append('argparse>=1.2.1')

No commit comments for this range

Something went wrong with that request. Please try again.