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


Python utils.string_types方法代码示例

本文整理汇总了Python中future.utils.string_types方法的典型用法代码示例。如果您正苦于以下问题:Python utils.string_types方法的具体用法?Python utils.string_types怎么用?Python utils.string_types使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在future.utils的用法示例。


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

示例1: __init__

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def __init__(self, methods=None, ifnset=None, ifset=None):
        if isinstance(methods, string_types):
            methods = (methods,)
        if isinstance(ifnset, string_types):
            ifnset = (ifnset,)
        if isinstance(ifset, string_types):
            ifset = (ifset,)

        #: Method verbs, uppercase
        self.methods = frozenset([m.upper() for m in methods]) if methods else None

        #: Conditional matching: route params that should not be set
        self.ifnset = frozenset(ifnset) if ifnset else None

        # : Conditional matching: route params that should be set
        self.ifset  = frozenset(ifset ) if ifset  else None 
开发者ID:kolypto,项目名称:py-flask-jsontools,代码行数:18,代码来源:views.py

示例2: test_stopwords

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def test_stopwords(self):
        stopword = [u'AV', u'女優']
        logger.debug (u'Stopwords Filtering Test. Stopwords is {}'.format(u','.join(stopword)))
        test_sentence = u"紗倉 まな(さくら まな、1993年3月23日 - )は、日本のAV女優。"
        juman_wrapper = JumanWrapper()
        token_objects = juman_wrapper.tokenize(sentence=test_sentence,
                                               return_list=False,
                                               is_feature=True
                                               )
        filtered_result = juman_wrapper.filter(
            parsed_sentence=token_objects,
            stopwords=stopword
        )

        check_flag = True
        for stem_posTuple in filtered_result.convert_list_object():
            assert isinstance(stem_posTuple, tuple)
            word_stem = stem_posTuple[0]
            word_posTuple = stem_posTuple[1]
            assert isinstance(word_stem, string_types)
            assert isinstance(word_posTuple, tuple)

            logger.debug(u'word_stem:{} word_pos:{}'.format(word_stem, ' '.join(word_posTuple)))
            if word_stem in stopword: check_flag = False
        assert check_flag 
开发者ID:Kensuke-Mitsuzawa,项目名称:JapaneseTokenizers,代码行数:27,代码来源:test_juman_wrapper_python2.py

示例3: split_text

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def split_text(text_to_split):
        """Split text

        Splits the debug text into its different parts: 'Time', 'LogLevel + Module Name', 'Debug message'

        :param text_to_split: Text to split
        :return: List containing the content of text_to_split split up
        """
        assert isinstance(text_to_split, string_types)
        try:
            time, rest = text_to_split.split(': ', 1)
            source, message = rest.split(':', 1)
        except ValueError:
            time = source = ""
            message = text_to_split
        return time.strip(), source.strip(), message.strip() 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:18,代码来源:logging_console.py

示例4: key_edited

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def key_edited(self, path, new_key_str):
        """ Edits the key of a semantic data entry

        :param path: The path inside the tree store to the target entry
        :param str new_key_str: The new value of the target cell
        :return:
        """
        tree_store_path = self.create_tree_store_path_from_key_string(path) if isinstance(path, string_types) else path
        if self.tree_store[tree_store_path][self.KEY_STORAGE_ID] == new_key_str:
            return

        dict_path = self.tree_store[tree_store_path][self.ID_STORAGE_ID]
        old_value = self.model.state.get_semantic_data(dict_path)
        self.model.state.remove_semantic_data(dict_path)

        if new_key_str == "":
            target_dict = self.model.state.semantic_data
            for element in dict_path[0:-1]:
                target_dict = target_dict[element]
            new_key_str = generate_semantic_data_key(list(target_dict.keys()))

        new_dict_path = self.model.state.add_semantic_data(dict_path[0:-1], old_value, key=new_key_str)
        self._changed_id_to = {':'.join(dict_path): new_dict_path}  # use hashable key (workaround for tree view ctrl)
        self.reload_tree_store_data() 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:26,代码来源:semantic_data_editor.py

示例5: _on_shortcut_changed

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def _on_shortcut_changed(self, renderer, path, new_shortcuts):
        """Callback handling a change of a shortcut

        :param Gtk.CellRenderer renderer: Cell renderer showing the shortcut
        :param path: Path of shortcuts within the list store
        :param str new_shortcuts: New shortcuts
        """
        action = self.shortcut_list_store[int(path)][self.KEY_STORAGE_ID]
        old_shortcuts = self.gui_config_model.get_current_config_value("SHORTCUTS", use_preliminary=True)[action]

        from ast import literal_eval
        try:
            new_shortcuts = literal_eval(new_shortcuts)
            if not isinstance(new_shortcuts, list) and \
               not all([isinstance(shortcut, string_types) for shortcut in new_shortcuts]):
                raise ValueError()
        except (ValueError, SyntaxError):
            logger.warning("Shortcuts must be a list of strings")
            new_shortcuts = old_shortcuts

        shortcuts = self.gui_config_model.get_current_config_value("SHORTCUTS", use_preliminary=True,  default={})
        shortcuts[action] = new_shortcuts
        self.gui_config_model.set_preliminary_config_value("SHORTCUTS", shortcuts)
        self._select_row_by_column_value(self.view['shortcut_tree_view'], self.shortcut_list_store,
                                         self.KEY_STORAGE_ID, action) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:27,代码来源:preferences_window.py

示例6: limit_value_string_length

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def limit_value_string_length(value):
    """This method limits the string representation of the value to MAX_VALUE_LABEL_TEXT_LENGTH + 3 characters.

    :param value: Value to limit string representation
    :return: String holding the value with a maximum length of MAX_VALUE_LABEL_TEXT_LENGTH + 3
    """
    if isinstance(value, string_types) and len(value) > constants.MAX_VALUE_LABEL_TEXT_LENGTH:
        value = value[:constants.MAX_VALUE_LABEL_TEXT_LENGTH] + "..."
        final_string = " " + value + " "
    elif isinstance(value, (dict, list)) and len(str(value)) > constants.MAX_VALUE_LABEL_TEXT_LENGTH:
        value_text = str(value)[:constants.MAX_VALUE_LABEL_TEXT_LENGTH] + "..."
        final_string = " " + value_text + " "
    else:
        final_string = " " + str(value) + " "

    return final_string 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:18,代码来源:gap_draw_helper.py

示例7: limit_text_max_length

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def limit_text_max_length(text, max_length, separator='_'):
    """
    Limits the length of a string. The returned string will be the first `max_length/2` characters of the input string
    plus a separator plus the last `max_length/2` characters of the input string.
    
    :param text: the text to be limited
    :param max_length: the maximum length of the output string
    :param separator: the separator between the first "max_length"/2 characters of the input string and
                      the last "max_length/2" characters of the input string
    :return: the shortened input string
    """
    if max_length is not None:
        if isinstance(text, string_types) and len(text) > max_length:
            max_length = int(max_length)
            half_length = float(max_length - 1) / 2
            return text[:int(math.ceil(half_length))] + separator + text[-int(math.floor(half_length)):]
    return text 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:19,代码来源:storage.py

示例8: modify_origin

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def modify_origin(self, from_state, from_outcome):
        """Set both from_state and from_outcome at the same time to modify transition origin

        :param str from_state: State id of the origin state
        :param int from_outcome: Outcome id of the origin port
        :raises exceptions.ValueError: If parameters have wrong types or the new transition is not valid
        """
        if not (from_state is None and from_outcome is None):
            if not isinstance(from_state, string_types):
                raise ValueError("Invalid transition origin port: from_state must be a string")
            if not isinstance(from_outcome, int):
                raise ValueError("Invalid transition origin port: from_outcome must be of type int")

        old_from_state = self.from_state
        old_from_outcome = self.from_outcome
        self._from_state = from_state
        self._from_outcome = from_outcome

        valid, message = self._check_validity()
        if not valid:
            self._from_state = old_from_state
            self._from_outcome = old_from_outcome
            raise ValueError("The transition origin could not be changed: {0}".format(message)) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:25,代码来源:transition.py

示例9: modify_target

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def modify_target(self, to_state, to_outcome=None):
        """Set both to_state and to_outcome at the same time to modify transition target

        :param str to_state: State id of the target state
        :param int to_outcome: Outcome id of the target port
        :raises exceptions.ValueError: If parameters have wrong types or the new transition is not valid
        """
        if not (to_state is None and (to_outcome is not int and to_outcome is not None)):
            if not isinstance(to_state, string_types):
                raise ValueError("Invalid transition target port: to_state must be a string")
            if not isinstance(to_outcome, int) and to_outcome is not None:
                raise ValueError("Invalid transition target port: to_outcome must be of type int or None (if to_state "
                                 "is of type str)")

        old_to_state = self.to_state
        old_to_outcome = self.to_outcome
        self._to_state = to_state
        self._to_outcome = to_outcome

        valid, message = self._check_validity()
        if not valid:
            self._to_state = old_to_state
            self._to_outcome = old_to_outcome
            raise ValueError("The transition target could not be changed: {0}".format(message)) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:26,代码来源:transition.py

示例10: modify_origin

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def modify_origin(self, from_state, from_key):
        """Set both from_state and from_key at the same time to modify data flow origin

        :param str from_state: State id of the origin state
        :param int from_key: Data port id of the origin port
        :raises exceptions.ValueError: If parameters have wrong types or the new data flow is not valid
        """
        if not isinstance(from_state, string_types):
            raise ValueError("Invalid data flow origin port: from_state must be a string")
        if not isinstance(from_key, int):
            raise ValueError("Invalid data flow origin port: from_key must be of type int")

        old_from_state = self.from_state
        old_from_key = self.from_key
        self._from_state = from_state
        self._from_key = from_key

        valid, message = self._check_validity()
        if not valid:
            self._from_state = old_from_state
            self._from_key = old_from_key
            raise ValueError("The data flow origin could not be changed: {0}".format(message)) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:24,代码来源:data_flow.py

示例11: modify_target

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def modify_target(self, to_state, to_key):
        """Set both to_state and to_key at the same time to modify data flow target

        :param str to_state: State id of the target state
        :param int to_key: Data port id of the target port
        :raises exceptions.ValueError: If parameters have wrong types or the new data flow is not valid
        """
        if not isinstance(to_state, string_types):
            raise ValueError("Invalid data flow target port: from_state must be a string")
        if not isinstance(to_key, int):
            raise ValueError("Invalid data flow target port: from_outcome must be of type int")

        old_to_state = self.to_state
        old_to_key = self.to_key
        self._to_state = to_state
        self._to_key = to_key

        valid, message = self._check_validity()
        if not valid:
            self._to_state = old_to_state
            self._to_key = old_to_key
            raise ValueError("The data flow target could not be changed: {0}".format(message)) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:24,代码来源:data_flow.py

示例12: __init__

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def __init__(self,
                 pattern,
                 callback,
                 pass_groups=False,
                 pass_groupdict=False,
                 pass_update_queue=False,
                 pass_job_queue=False):
        super(StringRegexHandler, self).__init__(
            callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue)

        if isinstance(pattern, string_types):
            pattern = re.compile(pattern)

        self.pattern = pattern
        self.pass_groups = pass_groups
        self.pass_groupdict = pass_groupdict 
开发者ID:cbrgm,项目名称:telegram-robot-rss,代码行数:18,代码来源:stringregexhandler.py

示例13: __init__

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def __init__(self,
                 callback,
                 pass_update_queue=False,
                 pass_job_queue=False,
                 pattern=None,
                 pass_groups=False,
                 pass_groupdict=False,
                 pass_user_data=False,
                 pass_chat_data=False):
        super(CallbackQueryHandler, self).__init__(
            callback,
            pass_update_queue=pass_update_queue,
            pass_job_queue=pass_job_queue,
            pass_user_data=pass_user_data,
            pass_chat_data=pass_chat_data)

        if isinstance(pattern, string_types):
            pattern = re.compile(pattern)

        self.pattern = pattern
        self.pass_groups = pass_groups
        self.pass_groupdict = pass_groupdict 
开发者ID:cbrgm,项目名称:telegram-robot-rss,代码行数:24,代码来源:callbackqueryhandler.py

示例14: _process_stat_dict

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def _process_stat_dict(stat_value, fields, tags, prefix=""):
    """
    Add (field_name, field_value) tuples to the fields list for any
    non-string or non-"id" items in the stat_value dict so that they can be
    used for the "fields" parameter of the InfluxDB point.
    Any string or keys with "id" on the end of their name get turned into tags.
    """
    for key, value in stat_value.items():
        value_type = type(value)
        field_name = prefix + key
        if isinstance(value, string_types) or (key[-2:] == "id" and value_type == int):
            tags[field_name] = value
        elif value_type == list:
            list_prefix = field_name + SUB_KEY_SEPARATOR
            _process_stat_list(value, fields, tags, list_prefix)
        elif value_type == dict:
            dict_prefix = field_name + SUB_KEY_SEPARATOR
            _process_stat_dict(value, fields, tags, dict_prefix)
        else:
            _add_field(fields, field_name, value, value_type) 
开发者ID:Isilon,项目名称:isilon_data_insights_connector,代码行数:22,代码来源:influxdb_plugin.py

示例15: get_tfrecord_paths

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import string_types [as 别名]
def get_tfrecord_paths(globs):
    if isinstance(globs, string_types):
        globs = [globs]

    assert len(globs) == len(set(globs)), 'Specified globs are not unique: {}'.format(globs)

    paths = []
    for glob_ in globs:
        paths.extend(glob(glob_))

    assert len(paths) > 0, 'No tfrecords found for glob(s) {}'.format(globs)
    assert len(paths) == len(set(paths)), 'Globs resulted in non-unique set of paths.\nGlobs: {}\nPaths: {}'.format(
        globs, paths)
    sorted_unique_paths = sorted(set(paths))
    return sorted_unique_paths 
开发者ID:merantix,项目名称:imitation-learning,代码行数:17,代码来源:inputs.py


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