| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,44 @@ | |||
| 1 | + # encoding: utf-8 | ||
| 2 | + | ||
| 3 | + # The MIT License | ||
| 4 | + # | ||
| 5 | + # Copyright (c) 2012 the bpython authors. | ||
| 6 | + # | ||
| 7 | + # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 8 | + # of this software and associated documentation files (the "Software"), to deal | ||
| 9 | + # in the Software without restriction, including without limitation the rights | ||
| 10 | + # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 11 | + # copies of the Software, and to permit persons to whom the Software is | ||
| 12 | + # furnished to do so, subject to the following conditions: | ||
| 13 | + # | ||
| 14 | + # The above copyright notice and this permission notice shall be included in | ||
| 15 | + # all copies or substantial portions of the Software. | ||
| 16 | + # | ||
| 17 | + # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 18 | + # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 19 | + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 20 | + # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 21 | + # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 22 | + # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 23 | + # THE SOFTWARE. | ||
| 24 | + # | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + """ | ||
| 28 | + Helper module for Python 3 compatibility. | ||
| 29 | + | ||
| 30 | + Defines the following attributes: | ||
| 31 | + | ||
| 32 | + - PythonLexer: Pygment's Python lexer matching the hosting runtime's | ||
| 33 | + Python version. | ||
| 34 | + - py3: True if the hosting Python runtime is of Python version 3 or later | ||
| 35 | + """ | ||
| 36 | + | ||
| 37 | + import sys | ||
| 38 | + | ||
| 39 | + py3 = (sys.version_info[0] == 3) | ||
| 40 | + | ||
| 41 | + if py3: | ||
| 42 | + from pygments.lexers import Python3Lexer as PythonLexer | ||
| 43 | + else: | ||
| 44 | + from pygments.lexers import PythonLexer | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,11 +81,11 @@ | |||
| 81 | 81 | from bpython.translations import _ | |
| 82 | 82 | ||
| 83 | 83 | from bpython import repl | |
| 84 | + from bpython._py3compat import py3 | ||
| 84 | 85 | from bpython.pager import page | |
| 85 | 86 | from bpython import autocomplete | |
| 86 | 87 | import bpython.args | |
| 87 | 88 | ||
| 88 | - py3 = sys.version_info[0] == 3 | ||
| 89 | 89 | if not py3: | |
| 90 | 90 | import inspect | |
| 91 | 91 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,16 +37,14 @@ | |||
| 37 | 37 | import gobject | |
| 38 | 38 | import gtk | |
| 39 | 39 | import pango | |
| 40 | - from pygments.lexers import PythonLexer | ||
| 41 | 40 | ||
| 42 | 41 | from bpython import importcompletion, repl, translations | |
| 42 | + from bpython._py3compat import PythonLexer, py3 | ||
| 43 | 43 | from bpython.formatter import theme_map | |
| 44 | 44 | from bpython.translations import _ | |
| 45 | 45 | import bpython.args | |
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | - py3 = sys.version_info[0] == 3 | ||
| 49 | - | ||
| 50 | 48 | _COLORS = dict(b='blue', c='cyan', g='green', m='magenta', r='red', | |
| 51 | 49 | w='white', y='yellow', k='black', d='black') | |
| 52 | 50 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,7 @@ def catch_warnings(): | |||
| 41 | 41 | finally: | |
| 42 | 42 | warnings.filters = filters | |
| 43 | 43 | ||
| 44 | - py3 = sys.version_info[:2] >= (3, 0) | ||
| 44 | + from bpython._py3compat import py3 | ||
| 45 | 45 | ||
| 46 | 46 | # The cached list of all known modules | |
| 47 | 47 | modules = set() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,10 +29,12 @@ | |||
| 29 | 29 | import re | |
| 30 | 30 | import sys | |
| 31 | 31 | import types | |
| 32 | + from itertools import dropwhile | ||
| 32 | 33 | ||
| 33 | - from pygments.lexers import PythonLexer | ||
| 34 | 34 | from pygments.token import Token | |
| 35 | 35 | ||
| 36 | + from bpython._py3compat import PythonLexer, py3 | ||
| 37 | + | ||
| 36 | 38 | try: | |
| 37 | 39 | collections.Callable | |
| 38 | 40 | has_collections_callable = True | |
@@ -44,8 +46,6 @@ | |||
| 44 | 46 | except AttributeError: | |
| 45 | 47 | has_instance_type = False | |
| 46 | 48 | ||
| 47 | - py3 = sys.version_info[0] == 3 | ||
| 48 | - | ||
| 49 | 49 | if not py3: | |
| 50 | 50 | _name = re.compile(r'[a-zA-Z_]\w*$') | |
| 51 | 51 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,15 +42,10 @@ | |||
| 42 | 42 | from urlparse import urlparse | |
| 43 | 43 | from xmlrpclib import ServerProxy, Error as XMLRPCError | |
| 44 | 44 | ||
| 45 | - py3 = sys.version_info[0] == 3 | ||
| 46 | - | ||
| 47 | 45 | from pygments.token import Token | |
| 48 | - if py3: | ||
| 49 | - from pygments.lexers import Python3Lexer as PythonLexer | ||
| 50 | - else: | ||
| 51 | - from pygments.lexers import PythonLexer | ||
| 52 | 46 | ||
| 53 | 47 | from bpython import importcompletion, inspection | |
| 48 | + from bpython._py3compat import PythonLexer, py3 | ||
| 54 | 49 | from bpython.formatter import Parenthesis | |
| 55 | 50 | from bpython.translations import _ | |
| 56 | 51 | from bpython.autocomplete import Autocomplete | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,7 @@ | |||
| 46 | 46 | from pygments.token import Token | |
| 47 | 47 | ||
| 48 | 48 | from bpython import args as bpargs, repl, translations | |
| 49 | + from bpython._py3compat import py3 | ||
| 49 | 50 | from bpython.formatter import theme_map | |
| 50 | 51 | from bpython.importcompletion import find_coroutine | |
| 51 | 52 | from bpython.translations import _ | |
@@ -54,7 +55,6 @@ | |||
| 54 | 55 | ||
| 55 | 56 | import urwid | |
| 56 | 57 | ||
| 57 | - py3 = sys.version_info[0] == 3 | ||
| 58 | 58 | if not py3: | |
| 59 | 59 | import inspect | |
| 60 | 60 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments