Example #1
0
    def get_country_entry(self,
                          country_names=None,
                          country_codes=None,
                          currency_names=None,
                          currency_codes=None,
                          single_result=False):
        """
        Parameters:
            country_names: country name to query(full match only). This can be list to do the batch task.
            country_codes: country code (ISO 3166) to query(full match only). This can be list to do the batch task.
            currency_names: currency name to query(full match only). This can be list to do the batch task.
            currency_codes: currency code (ISO 4217) to query(full match only). This can be list to do the batch task.

        Returns:
            List of country_entry. Return empty list if no result.
        """
        country_names = ext.to_list(country_names)
        country_codes = ext.to_list(country_codes)
        currency_names = ext.to_list(currency_names)
        currency_codes = ext.to_list(currency_codes)

        ret = self._get_lines(country_names, country_codes, currency_names,
                              currency_codes, single_result)

        return [country_entry(line) for line in ret]
Example #2
0
    def find_match(regex_list, text, is_case_sensitive=True):
        """
        Parameters:
            regex_list: Check if the provided text match the provided pattern. This should be list, and the element of the list can be a tuple. If the element of the list is a list, regex check will iterate through it.
            text: text to check.

        Returns:
            Has result: RegexFindResult
            No result: None
        """
        for num, regex in enumerate(regex_list):
            if not isinstance(regex, (list, tuple)):
                regex = ext.to_list(regex)

            for re_pattern in regex:
                if re_pattern is not None:
                    pattern = ur"^" + re_pattern + ur"$"
                    if not is_case_sensitive:
                        pattern = ur"(?iu)" + pattern

                    match_result = re.match(pattern, text)

                    if match_result is not None:
                        return RegexFindResult(num, match_result, pattern)

        return None
Example #3
0
 def __init__(self,
              headers,
              function_code,
              remotable,
              lowest_permission_req=permission.USER):
     self._function_code = function_code
     self._headers = [function_code + u'\n'] + ext.to_list(headers)
     self._remotable = remotable
     self._lowest_permission_required = lowest_permission_req
Example #4
0
    def valid_int_arr(obj, allow_null):
        base = param_validator.base_null(obj, allow_null)
        if base is not None:
            return base

        sp = ext.to_list(obj.split(param_validator.ARRAY_SEPARATOR))
        new_int = ext.to_int(sp)

        if new_int is not None:
            return param_validation_result(sp, True)
        else:
            return param_validation_result(error.sys_command.must_int(obj),
                                           False)
Example #5
0
    def conv_unicode_arr(obj, allow_null):
        base = param_validator.base_null(obj, allow_null)
        if base is not None:
            return base

        try:
            return param_validation_result([
                param_validator.conv_unicode(o, allow_null).result for o in
                ext.to_list(obj.split(param_validator.ARRAY_SEPARATOR))
            ], True)
        except Exception as ex:
            return param_validation_result(
                u'{} - {}'.format(type(ex), ex.message), False)
Example #6
0
    def display_data(self, categories, separator=u'\n'):
        """
        Parameters:
            categories: categories to display. This can be list to display multiple categories.
            separator: separator to separate different data. In unicode would be better.

        Returns:
            String in unicode.
        """
        categories = ext.to_list(categories)

        return u'{}\n{}'.format(
            u'{} ({})'.format(self.get_data(pli_category.CountryName), self.get_data(pli_category.CountryCode)), 
            separator.join([u'{}: {:.2f}'.format(unicode(category), self.get_data(category)) for category in categories]))
Example #7
0
    def del_post(self, author_uid, seq_id):
        """Return success or not in boolean. Seq_id can be either iterable or not."""

        seq_ids = ext.to_list(seq_id)

        cmd = super(rss_manager, self).delete_many({
            rss_data.SEQUENCE_ID: {
                '$in': seq_ids
            },
            rss_data.AUTHOR_UID:
            author_uid
        }).deleted_count

        return cmd == len(seq_ids) and len(seq_ids) > 0
Example #8
0
    def get_data(self, country_names=None, single_result=False):
        """
        Parameters:
            country_names: country name to query(full match only). This can be list to do the batch task.

        Returns:
            List of data_entry. Return empty list if no result.
        """
        country_names = ext.to_list(country_names)

        ret = self._get_lines(country_names, single_result)

        return [
            data_entry(line_arr, ppp_manager.START_YEAR) for line_arr in ret
        ]
Example #9
0
    def search_post(self, execute_in_gid, keywords):
        """
        Return posts found in list(rss_data), else empty list. keyword can be either iterable or not.
        Posts will belongs to execute_in_gid or public post.
        """
        keywords = ext.to_list(keywords)
        find_cursor = super(rss_manager, self).find({
            '$or': [{
                rss_data.RENDER_TEXT: {
                    '$regex': keyword
                }
            } for keyword in keywords],
            '$or': [{
                rss_data.AFFILIATED_GROUP: execute_in_gid,
                rss_data.AFFILIATED_GROUP: db.PUBLIC_GROUP_ID
            }]
        })

        return [rss_data(data) for data in find_cursor]