当前位置: 首页>>代码示例>>Python>>正文


Python misc.unicode_str函数代码示例

本文整理汇总了Python中sagenb.misc.misc.unicode_str函数的典型用法代码示例。如果您正苦于以下问题:Python unicode_str函数的具体用法?Python unicode_str怎么用?Python unicode_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了unicode_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: worksheet_new_cell_after

def worksheet_new_cell_after(worksheet):
    """Add a new cell after a given cell."""
    id = get_cell_id()
    input = unicode_str(request.values.get('input', ''))
    cell = worksheet.new_cell_after(id, input=input)
    worksheet.increase_state_number()
    
    from sagenb.notebook.twist import encode_list
    return encode_list([cell.id(), cell.html(div_wrap=False), id])
开发者ID:jasongrout,项目名称:sagenb-flask,代码行数:9,代码来源:worksheet.py

示例2: worksheet_new_text_cell_after

def worksheet_new_text_cell_after(worksheet):
    """Add a new text cell after a given cell."""    
    id = get_cell_id()
    input = unicode_str(request.values.get('input', ''))
    cell = worksheet.new_text_cell_after(id, input=input)
    worksheet.increase_state_number()
    
    from sagenb.notebook.twist import encode_list
    # XXX: Does editing correspond to TinyMCE?  If so, we should try
    # to centralize that code.
    return encode_list([cell.id(), cell.html(editing=True), id])
开发者ID:jasongrout,项目名称:sagenb-flask,代码行数:11,代码来源:worksheet.py

示例3: worksheet_new_cell_after

def worksheet_new_cell_after(worksheet):
    """Add a new cell after a given cell."""
    r = {}
    r['id'] = id = get_cell_id()
    input = unicode_str(request.values.get('input', ''))
    cell = worksheet.new_cell_after(id, input=input)
    worksheet.increase_state_number()

    r['new_id'] = cell.id()
    r['new_html'] = cell.html(div_wrap=True)

    return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:12,代码来源:worksheet.py

示例4: worksheet_new_cell_before

    def worksheet_new_cell_before(self, worksheet):
        """Add a new cell before a given cell."""
        r = {}
        r['id'] =  id = self.get_cell_id()
        input = unicode_str(self.request_values.get('input', ''))
        cell = worksheet.new_cell_before(id, input=input)
        worksheet.increase_state_number()

        r['new_id'] = cell.id()
        #r['new_html'] = cell.html(div_wrap=False)

        return encode_response(r)
开发者ID:rljacobson,项目名称:Guru-NB,代码行数:12,代码来源:WorksheetController.py

示例5: worksheet_new_cell_before

def worksheet_new_cell_before(worksheet):
    """Add a new cell before a given cell."""
    r = {}
    r["id"] = id = get_cell_id()
    input = unicode_str(request.values.get("input", ""))
    cell = worksheet.new_cell_before(id, input=input)
    worksheet.increase_state_number()

    r["new_id"] = cell.id()
    # r['new_html'] = cell.html(div_wrap=False)

    return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:12,代码来源:worksheet.py

示例6: worksheet_new_cell_before

def worksheet_new_cell_before(worksheet):
    """Add a new cell before a given cell."""
    r = {}
    r['id'] =  id = get_cell_id()
    input = unicode_str(request.values.get('input', ''))
    cell = worksheet.new_cell_before(id, input=input)
    worksheet.increase_state_number()
    
    r['new_id'] = cell.id()
    r['new_html'] = cell.html(div_wrap=False)

    from sagenb.notebook.misc import encode_response
    return encode_response(r)
开发者ID:philbrks,项目名称:sagenb,代码行数:13,代码来源:worksheet.py

示例7: worksheet_list

def worksheet_list():
    """
    Returns a worksheet listing.

    INPUT:

    -  ``args`` - ctx.args where ctx is the dict passed
       into a resource's render method

    -  ``pub`` - boolean, True if this is a listing of
       public worksheets

    -  ``username`` - the user whose worksheets we are
       listing

    OUTPUT:

    a string
    """
    
    from sagenb.notebook.notebook import sort_worksheet_list
    from sagenb.misc.misc import unicode_str, SAGE_VERSION
    from sagenb.notebook.misc import encode_response
    
    r = {}

    pub = 'pub' in request.args    
    readonly = g.notebook.readonly_user(g.username)
    typ = request.args['type'] if 'type' in request.args else 'active'
    search = unicode_str(request.args['search']) if 'search' in request.args else None
    sort = request.args['sort'] if 'sort' in request.args else 'last_edited'
    reverse = (request.args['reverse'] == 'True') if 'reverse' in request.args else False
    try:
        if not pub:
            r['worksheets'] = [x.basic() for x in g.notebook.worksheet_list_for_user(g.username, typ=typ, sort=sort, search=search, reverse=reverse)]
        else:
            r['worksheets'] = [x.basic() for x in g.notebook.worksheet_list_for_public(g.username, sort=sort, search=search, reverse=reverse)]

    except ValueError as E:
        # for example, the sort key was not valid
        print "Error displaying worksheet listing: ", E
        return current_app.message(_("Error displaying worksheet listing."))

    #if pub and (not g.username or g.username == tuple([])):
    #    r['username'] = 'pub'

    r['accounts'] = g.notebook.user_manager().get_accounts()
    r['sage_version'] = SAGE_VERSION
    # r['pub'] = pub
    
    return encode_response(r)
开发者ID:rljacobson,项目名称:Guru-NB,代码行数:51,代码来源:worksheet_listing.py

示例8: worksheet_new_text_cell_after

def worksheet_new_text_cell_after(worksheet):
    """Add a new text cell after a given cell."""
    r = {}
    r['id'] = id = get_cell_id()
    input = unicode_str(request.values.get('input', ''))
    cell = worksheet.new_text_cell_after(id, input=input)
    worksheet.increase_state_number()

    r['new_id'] = cell.id()
    r['new_html'] = cell.html(editing=True)

    # XXX: Does editing correspond to TinyMCE?  If so, we should try
    # to centralize that code.
    return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:14,代码来源:worksheet.py

示例9: render_worksheet_list

def render_worksheet_list(args, pub, username):
    """
    Returns a rendered worksheet listing.

    INPUT:

    -  ``args`` - ctx.args where ctx is the dict passed
       into a resource's render method

    -  ``pub`` - boolean, True if this is a listing of
       public worksheets

    -  ``username`` - the user whose worksheets we are
       listing

    OUTPUT:

    a string
    """

    from sagenb.notebook.notebook import sort_worksheet_list
    from sagenb.misc.misc import unicode_str, SAGE_VERSION

    typ = args['typ'] if 'typ' in args else 'active'
    search = unicode_str(args['search']) if 'search' in args else None
    sort = args['sort'] if 'sort' in args else 'last_edited'
    reverse = (args['reverse'] == 'True') if 'reverse' in args else False
    readonly = g.notebook.readonly_user(g.username)
    try:
        if not pub:
            worksheets = g.notebook.worksheet_list_for_user(username, typ=typ, sort=sort,
                                                              search=search, reverse=reverse)
        else:
            worksheets = g.notebook.worksheet_list_for_public(username, sort=sort,
                                                                search=search, reverse=reverse)
    except ValueError as E:
        # for example, the sort key was not valid
        print "Error displaying worksheet listing: ", E
        return current_app.message(_("Error displaying worksheet listing."))

    worksheet_filenames = [x.filename() for x in worksheets]

    if pub and (not username or username == tuple([])):
        username = 'pub'

    accounts = g.notebook.user_manager().get_accounts()
    sage_version = SAGE_VERSION
    return render_template('html/worksheet_listing.html', **locals())
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:48,代码来源:worksheet_listing.py

示例10: worksheet_eval

def worksheet_eval(worksheet):
    """
    Evaluate a worksheet cell.

    If the request is not authorized (the requester did not enter the
    correct password for the given worksheet), then the request to
    evaluate or introspect the cell is ignored.

    If the cell contains either 1 or 2 question marks at the end (not
    on a comment line), then this is interpreted as a request for
    either introspection to the documentation of the function, or the
    documentation of the function and the source code of the function
    respectively.
    """    
    from sagenb.notebook.twist import encode_list
    from base import notebook_updates
    
    id = get_cell_id()
    input_text = unicode_str(request.values.get('input', '')).replace('\r\n', '\n') #DOS

    worksheet.increase_state_number()

    cell = worksheet.get_cell_with_id(id)
    cell.set_input_text(input_text)

    if request.values.get('save_only', '0') == '1':
        notebook_updates()
        return ''
    elif request.values.get('text_only', '0') == '1':
        notebook_updates()
        return encode_list([str(id), cell.html()])
    else:
        new_cell = int(request.values.get('newcell', 0)) #wheter to insert a new cell or not

    cell.evaluate(username=g.username)

    if cell.is_last():
        new_cell = worksheet.append_new_cell()
        s = encode_list([new_cell.id(), 'append_new_cell', new_cell.html(div_wrap=False)])
    elif new_cell:
        new_cell = worksheet.new_cell_after(id)
        s = encode_list([new_cell.id(), 'insert_cell', new_cell.html(div_wrap=False), str(id)])
    else:
        s = encode_list([cell.next_id(), 'no_new_cell', str(id)])

    notebook_updates()
    return s
开发者ID:jasongrout,项目名称:sagenb-flask,代码行数:47,代码来源:worksheet.py

示例11: displayhook_hack

def displayhook_hack(string):
    """
    Modified version of string so that ``exec``'ing it results in
    displayhook possibly being called.
    
    STRING:

        - ``string`` - a string

    OUTPUT:

        - string formated so that when exec'd last line is printed if
          it is an expression

    EXAMPLES::
    
        sage: from sagenb.misc.format import displayhook_hack
        sage: displayhook_hack('\n12\n')
        "\nexec compile(u'12' + '\\n', '', 'single')"
        sage: displayhook_hack('\ndef my_fun(foo):\n    print(foo)\n')
        '\ndef my_fun(foo):\n        print(foo)'
        sage: print(displayhook_hack('\nclass A:\n    def __init__(self, foo):\n        self.foo\nb = A(8)\nb'))
        <BLANKLINE>
        class A:
            def __init__(self, foo):
                self.foo
        b = A(8)
        exec compile(u'b' + '\n', '', 'single')
    """
    # This function is all so the last line (or single lines) will
    # implicitly print as they should, unless they are an assignment.
    # If anybody knows a better way to do this, please tell me!
    string = string.splitlines()
    i = len(string)-1
    if i >= 0:
        while len(string[i]) > 0 and string[i][0] in ' \t':
            i -= 1
        final_lines = unicode_str('\n'.join(string[i:]))
        if not final_lines.startswith('def '):
            try:
                compile(final_lines + '\n', '', 'single')
                string[i] = "exec compile(%r + '\\n', '', 'single')" % final_lines
                string = string[:i+1]
            except SyntaxError:
                pass
    return '\n'.join(string)
开发者ID:TIMMYD3,项目名称:sagenb,代码行数:46,代码来源:format.py

示例12: __init__

    def __init__(self, *args, **kwds):
        self.startup_token = kwds.pop('startup_token', None)
        Flask.__init__(self, *args, **kwds)
        self.session_interface = OldSecureCookieSessionInterface()

        self.config['SESSION_COOKIE_HTTPONLY'] = False

        self.root_path = SAGENB_ROOT

        self.add_static_path('/css', os.path.join(DATA, "sage", "css"))
        self.add_static_path('/images', os.path.join(DATA, "sage", "images"))
        self.add_static_path('/javascript', DATA)
        self.add_static_path('/static', DATA)
        self.add_static_path('/java', DATA)
        self.add_static_path('/java/jmol', os.path.join(os.environ["SAGE_SHARE"],"jmol"))
        self.add_static_path('/jsmol', os.path.join(os.environ["SAGE_SHARE"],"jsmol"))
        self.add_static_path('/jsmol/js', os.path.join(os.environ["SAGE_SHARE"],"jsmol","js"))
        self.add_static_path('/j2s', os.path.join(os.environ["SAGE_SHARE"],"jsmol","j2s"))
        self.add_static_path('/jsmol/j2s', os.path.join(os.environ["SAGE_SHARE"],"jsmol","j2s"))
        self.add_static_path('/j2s/core', os.path.join(os.environ["SAGE_SHARE"],"jsmol","j2s","core"))
        self.add_static_path('/threejs', os.path.join(os.environ["SAGE_SHARE"],"threejs"))
        import mimetypes
        mimetypes.add_type('text/plain','.jmol')


        #######
        # Doc #
        #######
        #These "should" be in doc.py
        DOC = os.path.join(SAGE_DOC, 'html', 'en')
        self.add_static_path('/pdf', os.path.join(SAGE_DOC, 'pdf'))
        self.add_static_path('/doc/static', DOC)

        # Template globals
        self.add_template_global(url_for)
        # Template filters
        self.add_template_filter(css_escape)
        self.add_template_filter(number_of_rows)
        self.add_template_filter(clean_name)
        self.add_template_filter(prettify_time_ago)
        self.add_template_filter(max)
        self.add_template_filter(lambda x: repr(unicode_str(x))[1:],
                                 name='repr_str')
        self.add_template_filter(dumps, 'tojson')
开发者ID:sagemath,项目名称:sagenb,代码行数:44,代码来源:base.py

示例13: process_doc_html

    def process_doc_html(self, doc_in):
        r"""
        Returns processed HTML input as HTML output.  This is the only
        method that needs to be called externally.

        INPUT:

        - ``doc_in`` - a string containing properly formed HTML

        OUTPUT:

        - a string; the processed HTML

        EXAMPLES::

            sage: rst = ""
            sage: rst += "Title\n"
            sage: rst += "-----\n"
            sage: rst += "n"
            sage: rst += "Some text\n"
            sage: from docutils.core import publish_string
            sage: html = publish_string(rst, writer_name='html')
            sage: from sagenb.notebook.docHTMLProcessor import docutilsHTMLProcessor
            sage: p = docutilsHTMLProcessor()
            sage: txt = p.process_doc_html(html)
            sage: len(txt)
            51
            sage: txt
            u'<h1 class="title">Title</h1>\n\n<p>nSome text</p>\n\n\n\n'

        """        
        # self.feed() is a SGMLParser method and starts everything
        # off; Most of the functions here are extensions to
        # SGMLParser, and may never actually be visibly called here.

        # This module works with unicode literals. In case that input data is
        # ascii, exceptions may occur. So, input data must be converted to
        # unicode if it were not.
        doc_in = unicode_str(doc_in)  
        self.feed(doc_in) #SGMLParser call
        self.close()     #SGMLParser call
        self.hand_off_temp_pieces('to_doc_pieces')
        return self.all_pieces.replace('\\(', '').replace('\\)', '').replace('\\[', '').replace('\\]', '')
开发者ID:TIMMYD3,项目名称:sagenb,代码行数:43,代码来源:docHTMLProcessor.py

示例14: clean_name

    EXAMPLES::

        sage: from sagenb.notebook.template import clean_name
        sage: print clean_name('[email protected]+string')
        this_is_bad_string
    """
    return ''.join([x if x.isalnum() else '_' for x in name])

env.filters['css_escape'] = css_escape
env.filters['number_of_rows'] = number_of_rows
env.filters['clean_name'] = clean_name
env.filters['prettify_time_ago'] = prettify_time_ago
env.filters['math_parse'] = math_parse
env.filters['max'] = max
env.filters['repr_str'] = lambda x: repr(unicode_str(x))[1:]

def template(filename, **user_context):
    """
    Returns HTML, CSS, etc., for a template file rendered in the given
    context.

    INPUT:

    - ``filename`` - a string; the filename of the template relative
      to ``sagenb/data/templates``

    - ``user_context`` - a dictionary; the context in which to evaluate
      the file's template variables

    OUTPUT:
开发者ID:regmi,项目名称:femhub-lab,代码行数:30,代码来源:template.py

示例15: worksheet_eval

def worksheet_eval(worksheet):
    """
    Evaluate a worksheet cell.

    If the request is not authorized (the requester did not enter the
    correct password for the given worksheet), then the request to
    evaluate or introspect the cell is ignored.

    If the cell contains either 1 or 2 question marks at the end (not
    on a comment line), then this is interpreted as a request for
    either introspection to the documentation of the function, or the
    documentation of the function and the source code of the function
    respectively.
    """
    from base import notebook_updates

    r = {}

    r['id'] = id = get_cell_id()
    cell = worksheet.get_cell_with_id(id)
    public = worksheet.tags().get('_pub_', [False])[0] #this is set in pub_worksheet

    if public and not cell.is_interactive_cell():
        r['command'] = 'error'
        r['message'] = 'Cannot evaluate non-interactive public cell with ID %r.' % id
        return encode_response(r)

    worksheet.increase_state_number()

    if public:
        # Make public input cells read-only.
        input_text = cell.input_text()
    else:
        input_text = unicode_str(request.values.get('input', '')).replace('\r\n', '\n') #DOS

    # Handle an updated / recomputed interact.  TODO: JSON encode
    # the update data.
    if 'interact' in request.values:
        r['interact'] = 1
        input_text = INTERACT_UPDATE_PREFIX
        variable = request.values.get('variable', '')
        if variable!='':
            adapt_number = int(request.values.get('adapt_number', -1))
            value = request.values.get('value', '')
            input_text += "\n_interact_.update('%s', '%s', %s, _interact_.standard_b64decode('%s'), globals())" % (id, variable, adapt_number, value)

        if int(request.values.get('recompute', 0)):
            input_text += "\n_interact_.recompute('%s')" % id

    cell.set_input_text(input_text)

    if int(request.values.get('save_only', '0')):
        notebook_updates()
        return encode_response(r)
    elif int(request.values.get('text_only', '0')):
        notebook_updates()
        r['cell_html'] = cell.html()
        return encode_response(r)

    cell.evaluate(username=g.username)

    new_cell = int(request.values.get('newcell', 0)) #whether to insert a new cell or not
    if new_cell:
        new_cell = worksheet.new_cell_after(id)
        r['command'] = 'insert_cell'
        r['new_cell_id'] = new_cell.id()
        r['new_cell_html'] = new_cell.html(div_wrap=False)
    else:
        r['next_id'] = cell.next_compute_id()

    notebook_updates()

    return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:73,代码来源:worksheet.py


注:本文中的sagenb.misc.misc.unicode_str函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。