forked from sagemath/sage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
171 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
"""Cross-platform compatibility routines and wrappers.""" | ||
|
||
#***************************************************************************** | ||
# ***************************************************************************** | ||
# Copyright (C) 2017 William Stein <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 2 of the License, or | ||
# (at your option) any later version. | ||
# http://www.gnu.org/licenses/ | ||
#***************************************************************************** | ||
# ***************************************************************************** | ||
|
||
import os | ||
import subprocess | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
- Julian Rueth (2014-03-19): added ``decorator_keywords`` decorator | ||
""" | ||
#***************************************************************************** | ||
# ***************************************************************************** | ||
# Copyright (C) 2009 Tim Dumol | ||
# 2010,2011 Johan S. R. Nielsen | ||
# 2011 Simon King <[email protected]> | ||
|
@@ -24,7 +24,7 @@ | |
# the Free Software Foundation, either version 2 of the License, or | ||
# (at your option) any later version. | ||
# http://www.gnu.org/licenses/ | ||
#***************************************************************************** | ||
# ***************************************************************************** | ||
|
||
from functools import (partial, update_wrapper, WRAPPER_ASSIGNMENTS, | ||
WRAPPER_UPDATES) | ||
|
@@ -155,10 +155,10 @@ def sage_wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES): | |
81 | ||
""" | ||
#TRAC 9919: Workaround for bug in @update_wrapper when used with | ||
#non-function callables. | ||
# TRAC 9919: Workaround for bug in @update_wrapper when used with | ||
# non-function callables. | ||
assigned = set(assigned).intersection(set(dir(wrapped))) | ||
#end workaround | ||
# end workaround | ||
|
||
def f(wrapper, assigned=assigned, updated=updated): | ||
update_wrapper(wrapper, wrapped, assigned=assigned, updated=updated) | ||
|
@@ -168,9 +168,9 @@ def f(wrapper, assigned=assigned, updated=updated): | |
wrapper.__wrapped__ = wrapped | ||
wrapper._sage_src_ = lambda: sage_getsource(wrapped) | ||
wrapper._sage_src_lines_ = lambda: sage_getsourcelines(wrapped) | ||
#Getting the signature right in documentation by Sphinx (Issue 9976) | ||
#The attribute _sage_argspec_() is read by Sphinx if present and used | ||
#as the argspec of the function instead of using reflection. | ||
# Getting the signature right in documentation by Sphinx (Issue 9976) | ||
# The attribute _sage_argspec_() is read by Sphinx if present and used | ||
# as the argspec of the function instead of using reflection. | ||
wrapper._sage_argspec_ = lambda: sage_getargspec(wrapped) | ||
return wrapper | ||
return f | ||
|
@@ -424,7 +424,7 @@ def listForNone(l): | |
newArgs = [self.name + opt for opt in self.options.keys()] | ||
args = (argspec.args if argspec.args is not None else []) + newArgs | ||
defaults = (argspec.defaults if argspec.defaults is not None else ()) \ | ||
+ tuple(self.options.values()) | ||
+ tuple(self.options.values()) | ||
# Note: argspec.defaults is not always a tuple for some reason | ||
return FullArgSpec(args, argspec.varargs, argspec.varkw, defaults, | ||
kwonlyargs=[], kwonlydefaults=None, annotations={}) | ||
|
@@ -496,9 +496,9 @@ def wrapper(*args, **kwds): | |
options.update(kwds) | ||
return func(*args, **options) | ||
|
||
#Add the options specified by @options to the signature of the wrapped | ||
#function in the Sphinx-generated documentation (Issue 9976), using the | ||
#special attribute _sage_argspec_ (see e.g. sage.misc.sageinspect) | ||
# Add the options specified by @options to the signature of the wrapped | ||
# function in the Sphinx-generated documentation (Issue 9976), using the | ||
# special attribute _sage_argspec_ (see e.g. sage.misc.sageinspect) | ||
def argspec(): | ||
argspec = sage_getargspec(func) | ||
args = ((argspec.args if argspec.args is not None else []) + | ||
|
@@ -659,6 +659,7 @@ def wrapper(*args, **kwds): | |
|
||
return wrapper | ||
|
||
|
||
class specialize: | ||
r""" | ||
A decorator generator that returns a decorator that in turn | ||
|
@@ -697,6 +698,7 @@ def __init__(self, *args, **kwargs): | |
def __call__(self, f): | ||
return sage_wraps(f)(partial(f, *self.args, **self.kwargs)) | ||
|
||
|
||
def decorator_keywords(func): | ||
r""" | ||
A decorator for decorators with optional keyword arguments. | ||
|
@@ -731,7 +733,7 @@ def decorator_keywords(func): | |
@sage_wraps(func) | ||
def wrapped(f=None, **kwargs): | ||
if f is None: | ||
return sage_wraps(func)(lambda f:func(f, **kwargs)) | ||
return sage_wraps(func)(lambda f: func(f, **kwargs)) | ||
else: | ||
return func(f, **kwargs) | ||
return wrapped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,15 +144,15 @@ | |
""" | ||
|
||
#***************************************************************************** | ||
# ***************************************************************************** | ||
# Copyright (C) 2009 Carl Witty <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 2 of the License, or | ||
# (at your option) any later version. | ||
# http://www.gnu.org/licenses/ | ||
#***************************************************************************** | ||
# ***************************************************************************** | ||
|
||
|
||
import pickletools | ||
|
@@ -258,6 +258,7 @@ def explain_pickle(pickle=None, file=None, compress=True, **kwargs): | |
|
||
return explain_pickle_string(p, **kwargs) | ||
|
||
|
||
def explain_pickle_string(pickle, in_current_sage=False, | ||
default_assumptions=False, eval=False, preparse=True, | ||
pedantic=False): | ||
|
@@ -295,6 +296,8 @@ def explain_pickle_string(pickle, in_current_sage=False, | |
|
||
|
||
valid_name_re = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$') | ||
|
||
|
||
def name_is_valid(name): | ||
r""" | ||
Test whether a string is a valid Python identifier. (We use a | ||
|
@@ -318,6 +321,7 @@ def name_is_valid(name): | |
# This string is used as the representation of a mark. | ||
the_mark = 'mark' | ||
|
||
|
||
class PickleObject: | ||
r""" | ||
Pickles have a stack-based virtual machine. The :func:`explain_pickle` | ||
|
@@ -374,6 +378,7 @@ def _sage_input_(self, sib, coerced): | |
self.immutable = True | ||
return self.expression | ||
|
||
|
||
class PickleDict: | ||
r""" | ||
An object which can be used as the value of a :class:`PickleObject`. The items | ||
|
@@ -394,6 +399,7 @@ def __init__(self, items): | |
""" | ||
self.items = items | ||
|
||
|
||
class PickleInstance: | ||
r""" | ||
An object which can be used as the value of a :class:`PickleObject`. Unlike | ||
|
@@ -412,6 +418,7 @@ def __init__(self, klass): | |
""" | ||
self.klass = klass | ||
|
||
|
||
class PickleExplainer: | ||
r""" | ||
An interpreter for the pickle virtual machine, that executes | ||
|
@@ -831,9 +838,9 @@ def _APPENDS_helper(self, lst, slice): | |
lst.expression = self.sib(lst.value) | ||
elif isinstance(lst, PickleObject) or self.default_assumptions: | ||
if isinstance(lst.value, list) or \ | ||
(isinstance(lst.value, PickleInstance) and | ||
issubclass(lst.value.klass, list)) or \ | ||
self.default_assumptions: | ||
(isinstance(lst.value, PickleInstance) and | ||
issubclass(lst.value.klass, list)) or \ | ||
self.default_assumptions: | ||
if len(slice) > 1: | ||
self.sib.command(lst, self.sib.name('list').extend(lst, slice)) | ||
else: | ||
|
@@ -1105,10 +1112,10 @@ def BUILD(self): | |
slots = state[1].value | ||
state = state[0].value | ||
d = self.sib.getattr(obj, '__dict__') | ||
for k,v in state.items: | ||
for k, v in state.items: | ||
self.sib.command(obj, self.sib.assign(d[k], v)) | ||
if slots is not None: | ||
for k,v in slots.items: | ||
for k, v in slots.items: | ||
if isinstance(k, PickleObject) and isinstance(k.value, str): | ||
self.sib.command(obj, self.sib.assign(self.sib.getattr(obj, k.value), v)) | ||
else: | ||
|
@@ -2473,6 +2480,7 @@ def unpickle_instantiate(fn, args): | |
|
||
unpickle_persistent_loader = None | ||
|
||
|
||
def unpickle_persistent(s): | ||
r""" | ||
Takes an integer index and returns the persistent object with that | ||
|
@@ -2985,6 +2993,7 @@ def __setstate__(self, state): | |
self.x = state[1]['y'] | ||
self.y = state[0]['x'] | ||
|
||
|
||
class TestGlobalOldName: | ||
r""" | ||
A featureless new-style class. When you try to unpickle an instance | ||
|
@@ -3032,6 +3041,7 @@ def __repr__(self): | |
|
||
register_unpickle_override('sage.misc.explain_pickle', 'TestGlobalOldName', TestGlobalNewName, call_name=('sage.misc.explain_pickle', 'TestGlobalNewName')) | ||
|
||
|
||
class TestGlobalFunnyName: | ||
r""" | ||
A featureless new-style class which has a name that's not a legal | ||
|
@@ -3065,5 +3075,5 @@ def __repr__(self): | |
|
||
|
||
TestGlobalFunnyName.__name__ = "funny$name" | ||
#This crashed Sphinx. Instead, we manually execute this just before the test. | ||
#globals()['funny$name'] = TestGlobalFunnyName | ||
# This crashed Sphinx. Instead, we manually execute this just before the test. | ||
# globals()['funny$name'] = TestGlobalFunnyName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.