當前位置: 首頁>>代碼示例>>Python>>正文


Python py3compat.string_types方法代碼示例

本文整理匯總了Python中ipython_genutils.py3compat.string_types方法的典型用法代碼示例。如果您正苦於以下問題:Python py3compat.string_types方法的具體用法?Python py3compat.string_types怎麽用?Python py3compat.string_types使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ipython_genutils.py3compat的用法示例。


在下文中一共展示了py3compat.string_types方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: register

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def register(name=''):
    "For backwards compatibility, we support @register(name) syntax."
    def reg(widget):
        """A decorator registering a widget class in the widget registry."""
        w = widget.class_traits()
        Widget.widget_types.register(w['_model_module'].default_value,
                                    w['_model_module_version'].default_value,
                                    w['_model_name'].default_value,
                                    w['_view_module'].default_value,
                                    w['_view_module_version'].default_value,
                                    w['_view_name'].default_value,
                                    widget)
        return widget
    if isinstance(name, string_types):
        import warnings
        warnings.warn("Widget registration using a string name has been deprecated. Widget registration now uses a plain `@register` decorator.", DeprecationWarning)
        return reg
    else:
        return reg(name) 
開發者ID:luckystarufo,項目名稱:pySINDy,代碼行數:21,代碼來源:widget.py

示例2: array_to_binary_or_json

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def array_to_binary_or_json(ar, obj=None):
    if ar is None:
        return None
    element = ar
    dimension = 0
    try:
        while True:
            element = element[0]
            dimension += 1
    except:
        pass
    try:
        element = element.item()  # for instance get back the value from array(1)
    except:
        pass
    if isinstance(element, string_types):
        return array_to_json(ar)
    if dimension == 0:  # scalars are passed as is (json)
        return element
    return [array_to_binary(ar)] 
開發者ID:maartenbreddels,項目名稱:ipyvolume,代碼行數:22,代碼來源:serialize.py

示例3: _import_mapping

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def _import_mapping(mapping, original=None):
    """Import any string-keys in a type mapping."""
    #log = get_logger()
    #log.debug("Importing canning map")
    for key, value in list(mapping.items()):
        if isinstance(key, string_types):
            try:
                cls = import_item(key)
            except Exception:
                if original and key not in original:
                    # only message on user-added classes
                    # log.error("canning class not importable: %r", key, exc_info=True)
                    print("ERROR: canning class not importable: %r", key, exc_info=True)
                mapping.pop(key)
            else:
                mapping[cls] = mapping.pop(key) 
開發者ID:Parsl,項目名稱:parsl,代碼行數:18,代碼來源:canning.py

示例4: can

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def can(obj):
    """Prepare an object for pickling."""
    import_needed = False

    for cls, canner in iteritems(can_map):
        if isinstance(cls, string_types):
            import_needed = True
            break
        elif istype(obj, cls):
            return canner(obj)

    if import_needed:
        # perform can_map imports, then try again
        # this will usually only happen once
        _import_mapping(can_map, _original_can_map)
        return can(obj)

    return obj 
開發者ID:Parsl,項目名稱:parsl,代碼行數:20,代碼來源:canning.py

示例5: uncan

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def uncan(obj, g=None):
    """Invert canning."""
    import_needed = False
    for cls, uncanner in iteritems(uncan_map):
        if isinstance(cls, string_types):
            import_needed = True
            break
        elif isinstance(obj, cls):
            return uncanner(obj, g)

    if import_needed:
        # perform uncan_map imports, then try again
        # this will usually only happen once
        _import_mapping(uncan_map, _original_uncan_map)
        return uncan(obj, g)

    return obj 
開發者ID:Parsl,項目名稱:parsl,代碼行數:19,代碼來源:canning.py

示例6: html2text

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def html2text(element):
    """extract inner text from html
    
    Analog of jQuery's $(element).text()
    """
    if isinstance(element, py3compat.string_types):
        try:
            element = ElementTree.fromstring(element)
        except Exception:
            # failed to parse, just return it unmodified
            return element
    
    text = element.text or ""
    for child in element:
        text += html2text(child)
    text += (element.tail or "")
    return text 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:19,代碼來源:strings.py

示例7: get_color

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def get_color(self, color, intensity=0):
        """ Returns a QColor for a given color code or rgb list, or None if one
            cannot be constructed.
        """

        if isinstance(color, int):
            # Adjust for intensity, if possible.
            if color < 8 and intensity > 0:
                color += 8
            constructor = self.color_map.get(color, None)
        elif isinstance(color, (tuple, list)):
            constructor = color
        else:
            return None

        if isinstance(constructor, string_types):
            # If this is an X11 color name, we just hope there is a close SVG
            # color name. We could use QColor's static method
            # 'setAllowX11ColorNames()', but this is global and only available
            # on X11. It seems cleaner to aim for uniformity of behavior.
            return QtGui.QColor(constructor)

        elif isinstance(constructor, (tuple, list)):
            return QtGui.QColor(*constructor)

        return None 
開發者ID:luckystarufo,項目名稱:pySINDy,代碼行數:28,代碼來源:ansi_code_processor.py

示例8: set_style

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def set_style(self, style):
        """ Sets the style to the specified Pygments style.
        """
        if isinstance(style, string_types):
            style = get_style_by_name(style)
        self._style = style
        self._clear_caches() 
開發者ID:luckystarufo,項目名稱:pySINDy,代碼行數:9,代碼來源:pygments_highlighter.py

示例9: widget_from_single_value

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def widget_from_single_value(o):
        """Make widgets from single values, which can be used as parameter defaults."""
        if isinstance(o, string_types):
            return Text(value=unicode_type(o))
        elif isinstance(o, bool):
            return Checkbox(value=o)
        elif isinstance(o, Integral):
            min, max, value = _get_min_max_value(None, None, o)
            return IntSlider(value=o, min=min, max=max)
        elif isinstance(o, Real):
            min, max, value = _get_min_max_value(None, None, o)
            return FloatSlider(value=o, min=min, max=max)
        else:
            return None 
開發者ID:luckystarufo,項目名稱:pySINDy,代碼行數:16,代碼來源:interaction.py

示例10: _json_to_widget

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def _json_to_widget(x, obj):
    if isinstance(x, dict):
        return {k: _json_to_widget(v, obj) for k, v in x.items()}
    elif isinstance(x, (list, tuple)):
        return [_json_to_widget(v, obj) for v in x]
    elif isinstance(x, string_types) and x.startswith('IPY_MODEL_') and x[10:] in Widget.widgets:
        return Widget.widgets[x[10:]]
    else:
        return x 
開發者ID:luckystarufo,項目名稱:pySINDy,代碼行數:11,代碼來源:widget.py

示例11: array_sequence_to_binary_or_json

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def array_sequence_to_binary_or_json(ar, obj=None):
    if ar is None:
        return None
    element = ar
    dimension = 0
    try:
        while True:
            element = element[0]
            dimension += 1
    except:
        pass
    try:
        element = element.item()  # for instance get back the value from array(1)
    except:
        pass
    if isinstance(element, string_types):
        return array_to_json(ar)
    if dimension == 0:  # scalars are passed as is (json), empty lists as well
        if isinstance(element, np.ndarray):  # must be an empty list
            return []
        else:
            return element
    if isinstance(ar, (list, tuple, np.ndarray)):  # ok, at least 1d
        if isinstance(ar[0], (list, tuple, np.ndarray)):  # ok, 2d
            return [array_to_binary(ar[k]) for k in range(len(ar))]
        else:
            return [array_to_binary(ar)]
    else:
        raise ValueError("Expected a sequence, got %r", ar) 
開發者ID:maartenbreddels,項目名稱:ipyvolume,代碼行數:31,代碼來源:serialize.py

示例12: color_to_binary_or_json

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def color_to_binary_or_json(ar, obj=None):
    if ar is None:
        return None
    element = ar
    dimension = 0
    try:
        while True:
            element = element[0]
            dimension += 1
    except:
        pass
    try:
        element = element.item()  # for instance get back the str from array('foo')
    except:
        pass
    if isinstance(element, string_types):
        return array_to_json(ar)
    if dimension == 0:  # scalars are passed as is (json)
        return ar
    if ar.ndim > 1 and ar.shape[-1] == 3:
        # we add an alpha channel
        ones = np.ones(ar.shape[:-1])
        ar = np.stack([ar[..., 0], ar[..., 1], ar[..., 2], ones], axis=-1)
    elif ar.ndim > 1 and ar.shape[-1] != 4:
        raise ValueError('array should be of shape (...,3) or (...,4), not %r' % (ar.shape,))

    if dimension == 3:
        return [array_to_binary(ar[k]) for k in range(len(ar))]
    else:
        return [array_to_binary(ar)] 
開發者ID:maartenbreddels,項目名稱:ipyvolume,代碼行數:32,代碼來源:serialize.py

示例13: register_target

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def register_target(self, target_name, f):
        """Register a callable f for a given target name

        f will be called with two arguments when a comm_open message is
        received with `target`:

        - the Comm instance
        - the `comm_open` message itself.

        f can be a Python callable or an import string for one.
        """
        if isinstance(f, string_types):
            f = import_item(f)

        self.targets[target_name] = f 
開發者ID:jupyter,項目名稱:qtconsole,代碼行數:17,代碼來源:comms.py

示例14: __init__

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def __init__(self, name):
        if not isinstance(name, string_types):
            raise TypeError("illegal name: %r" % name)
        self.name = name
        self.buffers = [] 
開發者ID:Parsl,項目名稱:parsl,代碼行數:7,代碼來源:canning.py

示例15: register_preprocessor

# 需要導入模塊: from ipython_genutils import py3compat [as 別名]
# 或者: from ipython_genutils.py3compat import string_types [as 別名]
def register_preprocessor(self, preprocessor, enabled=False):
        """
        Register a preprocessor.
        Preprocessors are classes that act upon the notebook before it is
        passed into the Jinja templating engine.  preprocessors are also
        capable of passing additional information to the Jinja
        templating engine.

        Parameters
        ----------
        preprocessor : :class:`~nbconvert.preprocessors.Preprocessor`
            A dotted module name, a type, or an instance
        enabled : bool
            Mark the preprocessor as enabled

        """
        if preprocessor is None:
            raise TypeError('preprocessor must not be None')
        isclass = isinstance(preprocessor, type)
        constructed = not isclass

        # Handle preprocessor's registration based on it's type
        if constructed and isinstance(preprocessor, py3compat.string_types):
            # Preprocessor is a string, import the namespace and recursively call
            # this register_preprocessor method
            preprocessor_cls = import_item(preprocessor)
            return self.register_preprocessor(preprocessor_cls, enabled)

        if constructed and hasattr(preprocessor, '__call__'):
            # Preprocessor is a function, no need to construct it.
            # Register and return the preprocessor.
            if enabled:
                preprocessor.enabled = True
            self._preprocessors.append(preprocessor)
            return preprocessor

        elif isclass and issubclass(preprocessor, HasTraits):
            # Preprocessor is configurable.  Make sure to pass in new default for
            # the enabled flag if one was specified.
            self.register_preprocessor(preprocessor(parent=self), enabled)

        elif isclass:
            # Preprocessor is not configurable, construct it
            self.register_preprocessor(preprocessor(), enabled)

        else:
            # Preprocessor is an instance of something without a __call__
            # attribute.
            raise TypeError('preprocessor must be callable or an importable constructor, got %r' % preprocessor) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:51,代碼來源:exporter.py


注:本文中的ipython_genutils.py3compat.string_types方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。