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

No commit comments for this range

Something went wrong with that request. Please try again.