| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4c0ea6b commit 246a5ee
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,3 +20,55 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
| 20 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
| 21 | 21 | THE SOFTWARE. | |
| 22 | 22 | ||
| 23 | + | ||
| 24 | + Two functions in bpython/simpleeval.py are licensed under the | ||
| 25 | + Python Software Foundation License version 2: simple_eval and find_attribute_with_name | ||
| 26 | + | ||
| 27 | + PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 | ||
| 28 | + -------------------------------------------- | ||
| 29 | + | ||
| 30 | + 1. This LICENSE AGREEMENT is between the Python Software Foundation | ||
| 31 | + ("PSF"), and the Individual or Organization ("Licensee") accessing and | ||
| 32 | + otherwise using this software ("Python") in source or binary form and | ||
| 33 | + its associated documentation. | ||
| 34 | + | ||
| 35 | + 2. Subject to the terms and conditions of this License Agreement, PSF | ||
| 36 | + hereby grants Licensee a nonexclusive, royalty-free, world-wide | ||
| 37 | + license to reproduce, analyze, test, perform and/or display publicly, | ||
| 38 | + prepare derivative works, distribute, and otherwise use Python | ||
| 39 | + alone or in any derivative version, provided, however, that PSF's | ||
| 40 | + License Agreement and PSF's notice of copyright, i.e., "Copyright (c) | ||
| 41 | + 2001, 2002, 2003, 2004 Python Software Foundation; All Rights Reserved" | ||
| 42 | + are retained in Python alone or in any derivative version prepared | ||
| 43 | + by Licensee. | ||
| 44 | + | ||
| 45 | + 3. In the event Licensee prepares a derivative work that is based on | ||
| 46 | + or incorporates Python or any part thereof, and wants to make | ||
| 47 | + the derivative work available to others as provided herein, then | ||
| 48 | + Licensee hereby agrees to include in any such work a brief summary of | ||
| 49 | + the changes made to Python. | ||
| 50 | + | ||
| 51 | + 4. PSF is making Python available to Licensee on an "AS IS" | ||
| 52 | + basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR | ||
| 53 | + IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND | ||
| 54 | + DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS | ||
| 55 | + FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT | ||
| 56 | + INFRINGE ANY THIRD PARTY RIGHTS. | ||
| 57 | + | ||
| 58 | + 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON | ||
| 59 | + FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS | ||
| 60 | + A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, | ||
| 61 | + OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. | ||
| 62 | + | ||
| 63 | + 6. This License Agreement will automatically terminate upon a material | ||
| 64 | + breach of its terms and conditions. | ||
| 65 | + | ||
| 66 | + 7. Nothing in this License Agreement shall be deemed to create any | ||
| 67 | + relationship of agency, partnership, or joint venture between PSF and | ||
| 68 | + Licensee. This License Agreement does not grant permission to use PSF | ||
| 69 | + trademarks or trade name in a trademark sense to endorse or promote | ||
| 70 | + products or services of Licensee, or any third party. | ||
| 71 | + | ||
| 72 | + 8. By copying, installing or otherwise using Python, Licensee | ||
| 73 | + agrees to be bound by the terms and conditions of this License | ||
| 74 | + Agreement. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,27 @@ | |||
| 1 | 1 | # encoding: utf-8 | |
| 2 | + | ||
| 3 | + # The MIT License | ||
| 4 | + # | ||
| 5 | + # Copyright (c) 2015 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 | + # | ||
| 2 | 25 | """simple evaluation of side-effect free code | |
| 3 | 26 | ||
| 4 | 27 | In order to provide fancy completion, some code can be executed safely. | |
@@ -26,6 +49,16 @@ def safe_eval(expr, namespace): | |||
| 26 | 49 | raise EvaluationError | |
| 27 | 50 | ||
| 28 | 51 | ||
| 52 | + # This function is under the Python License, Version 2 | ||
| 53 | + # This license requires modifications to the code be reported. | ||
| 54 | + # Based on ast.literal_eval in Python 2 and Python 3 | ||
| 55 | + # Modifications: | ||
| 56 | + # * Python 2 and Python 3 versions of the function are combined | ||
| 57 | + # * checks that objects used as operands of + and - are numbers | ||
| 58 | + # instead of checking they are constructed with number literals | ||
| 59 | + # * new docstring describing different functionality | ||
| 60 | + # * looks up names from namespace | ||
| 61 | + # * indexing syntax is allowed | ||
| 29 | 62 | def simple_eval(node_or_string, namespace=None): | |
| 30 | 63 | """ | |
| 31 | 64 | Safely evaluate an expression node or a string containing a Python | |
@@ -40,7 +73,6 @@ def simple_eval(node_or_string, namespace=None): | |||
| 40 | 73 | ||
| 41 | 74 | The optional namespace dict-like ought not to cause side effects on lookup | |
| 42 | 75 | """ | |
| 43 | - # Based heavily on stdlib ast.literal_eval | ||
| 44 | 76 | if namespace is None: | |
| 45 | 77 | namespace = {} | |
| 46 | 78 | if isinstance(node_or_string, string_types): | |
@@ -118,11 +150,18 @@ def safe_getitem(obj, index): | |||
| 118 | 150 | raise ValueError('unsafe to lookup on object of type %s' % (type(obj), )) | |
| 119 | 151 | ||
| 120 | 152 | ||
| 153 | + # This function is under the Python License, Version 2 | ||
| 154 | + # This license requires modifications to the code be reported. | ||
| 155 | + # Based on ast.NodeVisitor.generic_visit | ||
| 156 | + # Modifications: | ||
| 157 | + # * Now a standalone function instead of method | ||
| 158 | + # * now hardcoded to look for Attribute node with given attr name | ||
| 159 | + # * returns values back up the recursive call stack to stop once target found | ||
| 121 | 160 | def find_attribute_with_name(node, name): | |
| 122 | - """Based on ast.NodeVisitor""" | ||
| 161 | + """Search depth-first for getitem indexing with name""" | ||
| 123 | 162 | if isinstance(node, ast.Attribute) and node.attr == name: | |
| 124 | 163 | return node | |
| 125 | - for field, value in ast.iter_fields(node): | ||
| 164 | + for _, value in ast.iter_fields(node): | ||
| 126 | 165 | if isinstance(value, list): | |
| 127 | 166 | for item in value: | |
| 128 | 167 | if isinstance(item, ast.AST): | |
@@ -134,7 +173,6 @@ def find_attribute_with_name(node, name): | |||
| 134 | 173 | if r: | |
| 135 | 174 | return r | |
| 136 | 175 | ||
| 137 | - | ||
| 138 | 176 | def evaluate_current_expression(cursor_offset, line, namespace=None): | |
| 139 | 177 | """ | |
| 140 | 178 | Return evaluated expression to the right of the dot of current attribute. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments