<commit_before>"""A base class notebook manager.

Authors:

* <NAME>
"""

#-----------------------------------------------------------------------------
#  Copyright (C) 2011  The IPython Development Team
#
#  Distributed under the terms of the BSD License.  The full license is in
#  the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------

import os
import uuid

from tornado import web
from urllib import quote, unquote

from IPython.config.configurable import LoggingConfigurable
from IPython.nbformat import current
from IPython.utils.traitlets import List, Dict, Unicode, TraitError

#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------

class NotebookManager(LoggingConfigurable):

    # Todo:
    # The notebook_dir attribute is used to mean a couple of different things:
    # 1. Where the notebooks are stored if FileNotebookManager is used.
    # 2. The cwd of the kernel for a project.
    # Right now we use this attribute in a number of different places and
    # we are going to have to disentangle all of this.
    notebook_dir = Unicode(os.getcwdu(), config=True, help="""
            The directory to use for notebooks.
            """)
            
    def named_notebook_path(self, notebook_path):
        
        names = notebook_path.split('/')
        if len(names) > 1:     
            name = names[-1]
            if name.endswith(".ipynb"):
                name = name
                path = notebook_path[0:-len(name)-1]+'/'
            else:
                name = None
                path = notebook_path+'/'
        else:
            name = names[0]
            if name.endswith(".ipynb"):
                name = name
                path = None
            else:
                name = None
                path = notebook_path+'/'
        return name, path
    
    def url_encode(self, path):<commit_msg>cleaning up named_notebook_path<commit_after>"""A base class notebook manager.

Authors:

* <NAME>
"""

#-----------------------------------------------------------------------------
#  Copyright (C) 2011  The IPython Development Team
#
#  Distributed under the terms of the BSD License.  The full license is in
#  the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------

import os
import uuid

from tornado import web
from urllib import quote, unquote

from IPython.config.configurable import LoggingConfigurable
from IPython.nbformat import current
from IPython.utils.traitlets import List, Dict, Unicode, TraitError

#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------

class NotebookManager(LoggingConfigurable):

    # Todo:
    # The notebook_dir attribute is used to mean a couple of different things:
    # 1. Where the notebooks are stored if FileNotebookManager is used.
    # 2. The cwd of the kernel for a project.
    # Right now we use this attribute in a number of different places and
    # we are going to have to disentangle all of this.
    notebook_dir = Unicode(os.getcwdu(), config=True, help="""
            The directory to use for notebooks.
            """)

    def named_notebook_path(self, notebook_path):
        """Given a notebook_path name, returns a (name, path) tuple, where
        name is a .ipynb file, and path is the directory for the file.

        Parameters
        ----------
        notebook_path : string
            A path that may be a .ipynb name or a directory

        Returns
        -------
        name : string or None
            the filename of the notebook, or None if not a .ipynb extesnsion
        path : string or None
            the path to the directory which contains the notebook
        """
        names = notebook_path.split('/')
        if len(names) > 1:
            name = names[-1]
            if name.endswith(".ipynb"):
                name = name
                path = notebook_path[:-1]+'/'
            else:
                name = None
                path = notebook_path+'/'
        else:
            name = names[0]
            if name.endswith(".ipynb"):
                name = name
                path = None
            else:
                name = None
                path = notebook_path+'/'
        return name, path
    
    def url_encode(self, path):
{'fraction_non_alphanumeric': 0.2537161474241499, 'fraction_numerical': 0.004276114844227245, 'mean_word_length': 1.175376439326838, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '242682', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1113, 'n_words': 416}