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


Python utils.sstr函数代码示例

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


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

示例1: _check_magic_file

def _check_magic_file(path_s):
   ''' ComicVine implementation of the identically named method in the db.py '''
   series_ref = None
   file_s = None
   try:
      # 1. get the directory to search for a cvinfo file in, or None
      dir_s = path_s if path_s and Directory.Exists(path_s) else \
         Path.GetDirectoryName(path_s) if path_s else None
      dir_s = dir_s if dir_s and Directory.Exists(dir_s) else None
      
      if dir_s:
         # 2. search in that directory for a properly named cvinfo file
         #    note that Windows filenames are not case sensitive.
         for f in [dir_s + "\\" + x for x in ["cvinfo.txt", "cvinfo"]]:
            if File.Exists(f):
               file_s = f 
            
         # 3. if we found a file, read it's contents in, and parse the 
         #    comicvine series id out of it, if possible.
         if file_s:
            with StreamReader(file_s, Encoding.UTF8, False) as sr:
               line = sr.ReadToEnd()
               line = line.strip() if line else line
               series_ref = __url_to_seriesref(line)
   except:
      log.debug_exc("bad cvinfo file: " + sstr(file_s))
      
   if file_s and not series_ref:
      log.debug("ignoring bad cvinfo file: ", sstr(file_s))

   return series_ref # may be None!
开发者ID:cbanack,项目名称:comic-vine-scraper,代码行数:31,代码来源:cvdb.py

示例2: __volume_to_seriesref

def __volume_to_seriesref(volume):
   ''' Converts a cvdb "volume" dom element into a SeriesRef. '''
   publisher = '' if len(volume.publisher.__dict__) <= 1 else \
      volume.publisher.name
   return SeriesRef( int(volume.id), sstr(volume.name), 
      sstr(volume.start_year).rstrip("- "), # see bug 334 
      sstr(publisher), sstr(volume.count_of_issues), __parse_image_url(volume))
开发者ID:cbanack,项目名称:comic-vine-scraper,代码行数:7,代码来源:cvdb.py

示例3: _query_issue_id_dom

def _query_issue_id_dom(API_KEY, seriesid_s, issue_num_s):
    """
   Performs a query that will obtain a dom containing the issue ID for the 
   given issue number in the given series id.  
   
   This method doesn't return null, but it may throw Exceptions.
   """

    # {0} is the series ID, an integer, and {1} is issue number, a string
    QUERY = (
        "http://comicvine.com/api/issues/?api_key="
        + API_KEY
        + __CLIENTID
        + "&format=xml&field_list=name,issue_number,id,image"
        + "&filter=volume:{0},issue_number:{1}"
    )

    # cv does not play well with leading zeros in issue nums. see issue #403.
    issue_num_s = sstr(issue_num_s).strip()
    if len(issue_num_s) > 0:  # fix issue 411
        issue_num_s = issue_num_s.lstrip("0").strip()
        issue_num_s = issue_num_s if len(issue_num_s) > 0 else "0"

    if not seriesid_s or not issue_num_s:
        raise ValueError("bad parameters")
    return __get_dom(QUERY.format(sstr(seriesid_s), HttpUtility.UrlPathEncode(sstr(issue_num_s))))
开发者ID:IPyandy,项目名称:comic-vine-scraper,代码行数:26,代码来源:cvconnection.py

示例4: __set_colorists_sl

 def __set_colorists_sl(self, colorists_sl):
    ''' called when you assign a value to 'self.colorists_sl' '''
    try:
       self.__colorists_sl =  [ re.sub(r',|;', '', sstr(x)) 
          for x in colorists_sl if x and len(sstr(x).strip())>0 ]
    except:
       self.__colorists_sl = []
开发者ID:cbanack,项目名称:comic-vine-scraper,代码行数:7,代码来源:dbmodels.py

示例5: __set_crossovers_sl

 def __set_crossovers_sl(self, crossovers_sl):
    ''' called when you assign a value to 'self.crossovers_sl' '''
    try:
       self.__crossovers_sl = \
          [sstr(x) for x in crossovers_sl if x and len(sstr(x).strip())>0]
    except:
       self.__crossovers_sl = []
开发者ID:cbanack,项目名称:comic-vine-scraper,代码行数:7,代码来源:dbmodels.py

示例6: __set_letterers_sl

 def __set_letterers_sl(self, letterers_sl):
    ''' called when you assign a value to 'self.letterers_sl' '''
    try:
       self.__letterers_sl = [ re.sub(r',|;', '', sstr(x)) 
          for x in letterers_sl if x and len(sstr(x).strip())>0 ]
    except:
       self.__letterers_sl = []
开发者ID:cbanack,项目名称:comic-vine-scraper,代码行数:7,代码来源:dbmodels.py

示例7: __set_image_urls_sl

 def __set_image_urls_sl(self, image_urls_sl):
    ''' called when you assign a value to 'self.image_urls_sl' '''
    try:
       self.__image_urls_sl =\
          [ sstr(x) for x in image_urls_sl if x and len(sstr(x).strip())>0 ]
    except:
       self.__image_urls_sl = []
开发者ID:cbanack,项目名称:comic-vine-scraper,代码行数:7,代码来源:dbmodels.py

示例8: _create_key_tag_s

def _create_key_tag_s(issue_key):
    """ ComicVine implementation of the identically named method in the db.py """
    try:
        return "CVDB" + utils.sstr(int(issue_key))
    except:
        log.debug_exc("Couldn't create key tag out of: " + sstr(issue_key))
        return None
开发者ID:NordomWhistleklik,项目名称:comic-vine-scraper,代码行数:7,代码来源:cvdb.py

示例9: _query_issue_refs

def _query_issue_refs(series_ref, callback_function=lambda x: False):
    """ ComicVine implementation of the identically named method in the db.py """

    # a comicvine series key can be interpreted as an integer
    series_id_n = int(series_ref.series_key)
    cancelled_b = [False]
    issue_refs = set()

    # 1. do the initial query, record how many results in total we're getting
    dom = cvconnection._query_issue_ids_dom(__api_key, sstr(series_id_n), 1)
    num_results_n = int(dom.number_of_total_results) if dom else 0

    if num_results_n > 0:

        # 2. convert the results of the initial query to IssueRefs and then add
        #    them to the returned set. notice that the dom could contain single
        #    issue OR a list of issues in its 'issue' variable.
        if not isinstance(dom.results.issue, list):
            issue_refs.add(__issue_to_issueref(dom.results.issue))
        else:
            for issue in dom.results.issue:
                issue_refs.add(__issue_to_issueref(issue))

            # 3. if there were more than 100 results, we'll have to do some more
            #    queries now to get the rest of them
            RESULTS_PAGE_SIZE = 100
            iteration = RESULTS_PAGE_SIZE
            if iteration < num_results_n:

                # 3a. do a callback for the first results (initial query)...
                cancelled_b[0] = callback_function(float(iteration) / num_results_n)

                while iteration < num_results_n and not cancelled_b[0]:
                    # 4. query for the next batch of results, in a new dom
                    dom = cvconnection._query_issue_ids_dom(
                        __api_key, sstr(series_id_n), iteration // RESULTS_PAGE_SIZE + 1
                    )
                    iteration += RESULTS_PAGE_SIZE

                    # 4a. do a callback for the most recent batch of results
                    cancelled_b[0] = callback_function(float(iteration) / num_results_n)

                    if int(dom.number_of_page_results) < 1:
                        log.debug("WARNING: got empty results page")
                    else:
                        # 5. convert the current batch of results into IssueRefs,
                        #    and then add them to the returned list.  Again, the dom
                        #    could contain a single issue, OR a list.
                        if not isinstance(dom.results.issue, list):
                            issue_refs.add(__issue_to_issueref(dom.results.issue))
                        else:
                            for issue in dom.results.issue:
                                issue_refs.add(__issue_to_issueref(issue))

    # 6. Done.  issue_refs now contained whatever IssueRefs we could find
    return set() if cancelled_b[0] else issue_refs
开发者ID:NordomWhistleklik,项目名称:comic-vine-scraper,代码行数:56,代码来源:cvdb.py

示例10: delegate

 def delegate():
    if self.__persist_size_key_s or self.__persist_loc_key_s:
       prefs = load_map(Resources.GEOMETRY_FILE)
       if self.__persist_loc_key_s:
          prefs[self.__persist_loc_key_s] =\
             sstr(self.Location.X) + "," + sstr(self.Location.Y)
       if self.__persist_size_key_s:
          prefs[self.__persist_size_key_s] =\
             sstr(self.Width) + "," + sstr(self.Height)
       persist_map(prefs, Resources.GEOMETRY_FILE)
开发者ID:Blackbird88,项目名称:comic-vine-scraper,代码行数:10,代码来源:persistentform.py

示例11: __init__

 def __init__(self, database_name_s, url_s, underlying, error_code_s="0"):
    ''' 
    database_name_s -> the name of the database that raised this error
    url_s -> the url that caused the problem
    underlying => the underlying io exception object or error string
    error_code => the underlying database error code, or 0 if there isn't one
    '''
    
    super(Exception,self).__init__(sstr(database_name_s) +
       " database could not be reached\n"\
       "url: " + re.sub(r"api_key=[^&]*", r"api_key=...", url_s) + 
       "\nCAUSE: " + sstr(underlying).replace('\r','') ) # .NET exception
    self.__database_name_s = sstr(database_name_s)
    self.__error_code_s = sstr(error_code_s).strip()
开发者ID:Blackbird88,项目名称:comic-vine-scraper,代码行数:14,代码来源:dberrors.py

示例12: __issue_scrape_extra_details

def __issue_scrape_extra_details(issue, page):
   ''' Parse additional details from the issues ComicVine webpage. '''
   if page:
      
      # first pass:  find all the alternate cover image urls
      regex = re.compile( \
         r'(?mis)\<\s*div[^\>]*img imgboxart issue-cover[^\>]+\>(.*?)div\s*>')
      for div_s in re.findall( regex, page )[1:]:
         inner_search_results = re.search(\
            r'(?i)\<\s*img\s+.*src\s*=\s*"([^"]*)', div_s)
         if inner_search_results:
            image_url_s = inner_search_results.group(1)
            if image_url_s:
               issue.image_urls_sl.append(image_url_s)
               

      # second pass:  find the community rating (stars) for this comic
      regex = re.compile(\
         r'(?mis)\<span class="average-score"\>(\d+\.?\d*) stars?\</span\>')
      results = re.search( regex, page )
      if results:
         try:
            rating = float(results.group(1))
            if rating > 0:
               issue.rating_n = rating
         except:
            log.debug_exc("Error parsing rating for " + sstr(issue) + ": ")
开发者ID:cbanack,项目名称:comic-vine-scraper,代码行数:27,代码来源:cvdb.py

示例13: show_form

    def show_form(self):
        """
      Displays this form, blocking until the user closes it.  When it is closed,
      it will return an IssueFormResult describing how it was closed, and any
      IssueRef that may have been chosen when it was closed.
      """

        dialogAnswer = self.ShowDialog(self.Owner)  # blocks

        if dialogAnswer == DialogResult.OK:
            issue = self.__issue_refs[self.__chosen_index]
            result = IssueFormResult("OK", issue)
            alt_choice = self.__coverpanel.get_alt_issue_cover_choice()
            if alt_choice:
                issue_ref, image_ref = alt_choice
                # the user chose a non-default cover image for this issue.
                # we'll store that choice in the global "session data map",
                # in case any other part of the program wants to use it.
                alt_cover_key = sstr(issue_ref.issue_key) + "-altcover"
                self.__config.session_data_map[alt_cover_key] = image_ref
        elif dialogAnswer == DialogResult.Cancel:
            result = IssueFormResult("CANCEL")
        elif dialogAnswer == DialogResult.Ignore:
            if self.ModifierKeys == Keys.Control:
                result = IssueFormResult("PERMSKIP")
            else:
                result = IssueFormResult("SKIP")
        elif dialogAnswer == DialogResult.Retry:
            result = IssueFormResult("BACK")
        else:
            raise Exception()
        return result
开发者ID:IPyandy,项目名称:comic-vine-scraper,代码行数:32,代码来源:issueform.py

示例14: __build_label

    def __build_label(self, series_ref):
        """ builds and returns the main text label for this form """

        # 1. compute the best possible full name for the given SeriesRef
        name_s = series_ref.series_name_s
        publisher_s = series_ref.publisher_s
        vol_year_n = series_ref.volume_year_n
        vol_year_s = sstr(vol_year_n) if vol_year_n > 0 else ""
        fullname_s = ""
        if name_s:
            if publisher_s:
                if vol_year_s:
                    fullname_s = "'" + name_s + "' (" + publisher_s + ", " + vol_year_s + ")"
                else:
                    fullname_s = "'" + name_s + "' (" + publisher_s + ")"
            else:
                fullname_s = "'" + name_s + "'"

        label = Label()
        label.UseMnemonic = False
        sep = "  " if len(fullname_s) > 40 else "\n"
        label.Text = i18n.get("IssueFormChooseText").format(fullname_s, sep)

        if self.__config.show_covers_b:
            label.Location = Point(218, 20)
            label.Size = Size(480, 40)
        else:
            label.Location = Point(10, 20)
            label.Size = Size(680, 40)

        return label
开发者ID:IPyandy,项目名称:comic-vine-scraper,代码行数:31,代码来源:issueform.py

示例15: _check_magic_file

def _check_magic_file(path_s):
   ''' ComicVine implementation of the identically named method in the db.py '''
   series_key_s = None
   file_s = None
   try:
      # 1. get the directory to search for a cvinfo file in, or None
      dir_s = path_s if path_s and Directory.Exists(path_s) else \
         Path.GetDirectoryName(path_s) if path_s else None
      dir_s = dir_s if dir_s and Directory.Exists(dir_s) else None
      
      if dir_s:
         # 2. search in that directory for a properly named cvinfo file
         #    note that Windows filenames are not case sensitive.
         for f in [dir_s + "\\" + x for x in ["cvinfo.txt", "cvinfo"]]:
            if File.Exists(f):
               file_s = f 
            
         # 3. if we found a file, read it's contents in, and parse the 
         #    comicvine series id out of it, if possible.
         if file_s:
            with StreamReader(file_s, Encoding.UTF8, False) as sr:
               line = sr.ReadToEnd()
               line = line.strip() if line else line
               match = re.match(r"^.*?\b(49|4050)-(\d{2,})\b.*$", line)
               line = match.group(2) if match else line
               if utils.is_number(line):
                  series_key_s = utils.sstr(int(line))
   except:
      log.debug_exc("bad cvinfo file: " + sstr(file_s))
      
   # 4. did we find a series key?  if so, query comicvine to build a proper
   #    SeriesRef object for that series key.
   series_ref = None
   if series_key_s:
      try:
         dom = cvconnection._query_series_details_dom(
            __api_key, utils.sstr(series_key_s))
         num_results_n = int(dom.number_of_total_results)
         series_ref =\
            __volume_to_seriesref(dom.results) if num_results_n==1 else None
      except:
         log.debug_exc("error getting SeriesRef for: " + sstr(series_key_s))
         
   if file_s and not series_ref:
      log.debug("ignoring bad cvinfo file: ", sstr(file_s))
   return series_ref # may be None!
开发者ID:Blackbird88,项目名称:comic-vine-scraper,代码行数:46,代码来源:cvdb.py


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