Ticket #11733: trac_11733_sagenb_misc_misc_sagenb.patch

File trac_11733_sagenb_misc_misc_sagenb.patch, 8.5 KB (added by saraedum, 10 years ago)
  • sagenb/misc/misc.py

    exporting patch:
    # HG changeset patch
    # User Julian Rüth <julian.rueth@gmail.com>
    Trac 11733: do not load sagenb.misc.misc on normal startup
    
    diff --git a/sagenb/misc/misc.py b/sagenb/misc/misc.py
    index 9611ed0..6559a47 100644
    a b def find_next_available_port(interface, start, max_tries=100, verbose=False): 
    104104
    105105    EXAMPLES::
    106106
    107         sage: import sagenb
    108         sage: sagenb.misc.misc.find_next_available_port('127.0.0.1', 9000, verbose=False)   # random output -- depends on network
     107        sage: from sagenb.misc.misc import find_next_available_port
     108        sage: find_next_available_port('127.0.0.1', 9000, verbose=False)   # random output -- depends on network
    109109        9002
    110110    """
    111111    alarm_count = 0 
    def DATA(): 
    164164    TESTS::
    165165
    166166        sage: import os.path
    167         sage: os.path.exists(sagenb.misc.misc.DATA())
     167        sage: from sagenb.misc.misc import DATA
     168        sage: os.path.exists(DATA())
    168169        True
    169170    """
    170171    # the import of pkg_resources takes a considerable amount of time (see #11730)
    elif os.environ.has_key('DOT_SAGE'): 
    179180else:
    180181    DOT_SAGENB = os.path.join(os.environ['HOME'], '.sagenb')
    181182
     183conf_path     = os.path.join(DOT_SAGENB, 'notebook')
     184
     185private_pem   = os.path.join(conf_path, 'private.pem')
     186public_pem    = os.path.join(conf_path, 'public.pem')
     187template_file = os.path.join(conf_path, 'cert.cfg')
     188
    182189try:
    183190    from sage.misc.misc import SAGE_URL
    184191except ImportError:
    def SAGENB_VERSION(): 
    329336
    330337    TESTS::
    331338
    332         sage: isinstance(sagenb.misc.misc.SAGENB_VERSION(),type(''))
     339        sage: from sagenb.misc.misc import SAGENB_VERSION
     340        sage: isinstance(SAGENB_VERSION(),type(''))
    333341        True
    334342    """
    335343    try:
    def SAGE_VERSION(): 
    346354
    347355    TESTS::
    348356
    349         sage: isinstance(sagenb.misc.misc.SAGE_VERSION(),type(''))
     357        sage: from sagenb.misc.misc import SAGE_VERSION
     358        sage: isinstance(SAGE_VERSION(),type(''))
    350359        True
    351360    """
    352361    # for consistency with SAGENB_VERSION this is a function and not a global variable
  • sagenb/notebook/interact.py

    diff --git a/sagenb/notebook/interact.py b/sagenb/notebook/interact.py
    index 3fd3845..a4d7a39 100644
    a b import types 
    154154
    155155# Sage libraries
    156156from jsmath import math_parse
    157 from sagenb.misc.misc import srange, sage_eval, Color, is_Matrix
    158157from sage.misc.cachefunc import cached_method
    159158
    160159# SAGE_CELL_ID is a module scope variable that is always set equal to
    class InteractControl(InteractElement): 
    806805            sage: sagenb.notebook.interact.InteractControl('x', 1)._adaptor('2/3', globals())
    807806            2/3       
    808807        """
     808        from sagenb.misc.misc import sage_eval
    809809        return sage_eval(value, globs)
    810810       
    811811    def interact(self, *args):
    class InputBox(InteractControl): 
    959959            sage: sagenb.notebook.interact.InputBox('theta', Color('red'), type=Color)._adaptor('#aaaaaa',globals())
    960960            RGB color (0.66..., 0.66..., 0.66...)
    961961        """
     962        from sagenb.misc.misc import Color
    962963        if self.__type is None:
     964            from sagenb.misc.misc import sage_eval
    963965            return sage_eval(value, globs)
    964966        elif self.__type is str:
    965967            return value
    class InputBox(InteractControl): 
    973975                    print "Invalid color '%s', using default Color()" % value
    974976                    return Color()
    975977        else:
     978            from sagenb.misc.misc import sage_eval
    976979            return self.__type(sage_eval(value,globs))
    977980
    978981    def value_js(self):
    class InputGrid(InteractControl): 
    11631166            sage: sagenb.notebook.interact.InputGrid('M', 1,3, default_value=[[1,2,3]], to_value=lambda x: vector(flatten(x)))._adaptor("[[4,5,6]]", globals())
    11641167            (4, 5, 6)
    11651168        """
    1166        
     1169        from sagenb.misc.misc import sage_eval
    11671170        return self.__to_value(sage_eval(value, globs))
    11681171
    11691172    def value_js(self):
    class input_box(control): 
    27582761            sage: input_box("2+2", 'Exp').render('x')
    27592762            An InputBox interactive control with x='2+2' and label 'Exp'       
    27602763        """
     2764        from sagenb.misc.misc import Color
    27612765        if self.__type is Color:
    27622766            return ColorInput(var, default_value=self.__default, label=self.label(), type=self.__type, **self.__kwargs)
    27632767        else:
    class color_selector(input_box): 
    28102814            ...
    28112815            ValueError: unknown color 'abcdef'
    28122816        """
     2817        from sagenb.misc.misc import Color
    28132818        input_box.__init__(self, default=Color(default), label=label,
    28142819                           type=Color, widget=widget, hide_box=hide_box)
    28152820        self.__widget = widget
    class slider_generic(control): 
    30783083            if num_steps <= 2:
    30793084                vals = [self.__vmin, self.__vmax]
    30803085            else:
     3086                from sagenb.misc.misc import srange
    30813087                vals = srange(self.__vmin, self.__vmax, self.__step_size, include_endpoint=True)
    30823088                if vals[-1] != self.__vmax:
    30833089                    try:
    def automatic_control(default): 
    36283634        if isinstance(default, tuple) and len(default) == 2 and isinstance(default[1], (tuple, list, types.GeneratorType)):
    36293635            default_value, default = default
    36303636           
     3637    from sagenb.misc.misc import Color, is_Matrix
    36313638    if isinstance(default, control):
    36323639        C = default
    36333640        if label:
  • sagenb/notebook/notebook.py

    diff --git a/sagenb/notebook/notebook.py b/sagenb/notebook/notebook.py
    index bfba26d..674b8e9 100644
    a b import socket 
    2828import time
    2929import bz2
    3030import cPickle
    31 from cgi import escape
    3231
    3332
    34 # Sage libraries
    35 from sagenb.misc.misc import (pad_zeros, cputime, tmp_dir, load, save,
    36                               ignore_nonexistent_files, unicode_str)
    37 
    3833# Sage Notebook
    3934import keyboards    # keyboard layouts
    4035import server_conf  # server configuration
    class Notebook(object): 
    619614            target = os.path.join(W.directory(),'data')
    620615            if os.path.exists(target):
    621616                shutil.rmtree(target, ignore_errors=True)
     617            from sagenb.misc.misc import ignore_nonexistent_files
    622618            shutil.copytree(data, target, ignore=ignore_nonexistent_files)
    623619        cells = src.cells_directory()
    624620        if os.path.exists(cells):
    class Notebook(object): 
    15971593            u'...pre class="plaintext"...cell_intext...textfield...'
    15981594        """
    15991595        plain_text = worksheet.plain_text(prompts=True, banner=False)
     1596        from cgi import escape
    16001597        plain_text = escape(plain_text).strip()
    16011598
    16021599        from template import template
  • sagenb/notebook/run_notebook.py

    diff --git a/sagenb/notebook/run_notebook.py b/sagenb/notebook/run_notebook.py
    index 8f469ed..16aad32 100644
    a b from exceptions import SystemExit 
    3030
    3131from twisted.python.runtime import platformType
    3232
    33 from sagenb.misc.misc import (DOT_SAGENB, find_next_available_port,
    34                               print_open_msg)
    3533import notebook
    3634
    37 conf_path     = os.path.join(DOT_SAGENB, 'notebook')
    38 
    39 private_pem   = os.path.join(conf_path, 'private.pem')
    40 public_pem    = os.path.join(conf_path, 'public.pem')
    41 template_file = os.path.join(conf_path, 'cert.cfg')
    42 
    43 
    4435def cmd_exists(cmd):
    4536    """
    4637    Return True if the given cmd exists.
    def get_old_settings(conf): 
    6960
    7061
    7162def notebook_setup(self=None):
     63    from sagenb.misc.misc import conf_path, private_pem, public_pem, template_file
    7264    if not os.path.exists(conf_path):
    7365        os.makedirs(conf_path)
    7466
    reactor.addSystemEventTrigger('before', 'shutdown', save_notebook) 
    414406        ## Start up twisted
    415407        cmd = 'twistd --pidfile="%s" -ny "%s"' % (pidfile, conf)
    416408        if not quiet:
     409            from sagenb.misc.misc import print_open_msg
    417410            print_open_msg('localhost' if not interface else interface,
    418411                           port, secure=secure)
    419412        if secure and not quiet:
    reactor.addSystemEventTrigger('before', 'shutdown', save_notebook) 
    440433            print "**crazy**!  You should run the notebook with the option secure=True."
    441434            print "*" * 70
    442435
     436    from sagenb.misc.misc import find_next_available_port
    443437    port = find_next_available_port(interface, port, port_tries)
    444438    if open_viewer:
    445439        "Open viewer automatically isn't fully implemented.  You have to manually open your web browser to the above URL."