Skip to content

Commit 246a5ee

Browse files
Add Python license for two functions
1 parent 4c0ea6b commit 246a5ee

File tree

2 files changed

+94
-4
lines changed

2 files changed

+94
-4
lines changed

LICENSE

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,55 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222

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.

bpython/simpleeval.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
# 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+
#
225
"""simple evaluation of side-effect free code
326
427
In order to provide fancy completion, some code can be executed safely.
@@ -26,6 +49,16 @@ def safe_eval(expr, namespace):
2649
raise EvaluationError
2750

2851

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
2962
def simple_eval(node_or_string, namespace=None):
3063
"""
3164
Safely evaluate an expression node or a string containing a Python
@@ -40,7 +73,6 @@ def simple_eval(node_or_string, namespace=None):
4073
4174
The optional namespace dict-like ought not to cause side effects on lookup
4275
"""
43-
# Based heavily on stdlib ast.literal_eval
4476
if namespace is None:
4577
namespace = {}
4678
if isinstance(node_or_string, string_types):
@@ -118,11 +150,18 @@ def safe_getitem(obj, index):
118150
raise ValueError('unsafe to lookup on object of type %s' % (type(obj), ))
119151

120152

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
121160
def find_attribute_with_name(node, name):
122-
"""Based on ast.NodeVisitor"""
161+
"""Search depth-first for getitem indexing with name"""
123162
if isinstance(node, ast.Attribute) and node.attr == name:
124163
return node
125-
for field, value in ast.iter_fields(node):
164+
for _, value in ast.iter_fields(node):
126165
if isinstance(value, list):
127166
for item in value:
128167
if isinstance(item, ast.AST):
@@ -134,7 +173,6 @@ def find_attribute_with_name(node, name):
134173
if r:
135174
return r
136175

137-
138176
def evaluate_current_expression(cursor_offset, line, namespace=None):
139177
"""
140178
Return evaluated expression to the right of the dot of current attribute.

0 commit comments

Comments
 (0)