Пример #1
0
 def _generate(self, n, l):
     if l == 0:
         yield (n, )
     else:
         for a in pyk.xrange(n - l, 0, -1):
             for ps in self[(n - a, l - 1)]:
                 if a >= ps[0]:
                     yield (a, ) + ps
Пример #2
0
 def _generate (self, n, l) :
     if l == 0 :
         yield (n, )
     else :
         for a in pyk.xrange (n - l, 0 , -1) :
             for ps in self [(n - a, l - 1)] :
                 if a >= ps [0] :
                     yield (a, ) + ps
Пример #3
0
 def _fix(self, start=0):
     for pos in pyk.xrange(start, len(self)):
         value = self[pos]
         self.index_dict[value] = pos
Пример #4
0
 def rotate_prev (self, n) :
     """Move `self.mark` backward (i.e., following `prev`) `n` times."""
     for i in pyk.xrange (n) :
         self.mark = self.mark.prev
Пример #5
0
 def rotate_next (self, n) :
     """Move `self.mark` forward (i.e., following `next`) `n` times."""
     for i in pyk.xrange (n) :
         self.mark = self.mark.next
def gen_records(xls_name):
    book = xlrd.open_workbook(xls_name, encoding_override="iso-8859-1")
    sheet = book.sheet_by_index(0)
    for i in pyk.xrange(0, sheet.nrows):
        for ndc in _convert_row(sheet.row(i)):
            yield ndc
Пример #7
0
 def _fix (self, start = 0) :
     for pos in pyk.xrange (start, len (self)) :
         value = self [pos]
         self.index_dict [value] = pos
Пример #8
0
 def _years(self, year):
     for y in pyk.xrange(year + 1, self.top.copyright_start - 1, -1):
         yp = self.Year(name=str(y), page_args=self.page_args, parent=self, year=y)
         if yp.count or yp.referral_query.count():
             yield yp
Пример #9
0
 def _parse (self, fp):
     """Slighly modified version of gettext.GNUTranslations._parse."""
     unpack   = struct.unpack
     filename = getattr (fp, "name", "")
     # Parse the .mo file header, which consists of 5 little endian 32
     # bit words.
     self._catalog = catalog = {}
     self.plural   = lambda n: int (n != 1) # germanic plural by default
     buf           = fp.read ()
     buflen        = len     (buf)
     # Are we big endian or little endian?
     magic = unpack ("<I", buf [:4]) [0]
     if magic == self.LE_MAGIC :
         version, msgcount, masteridx, transidx = unpack ("<4I", buf [4:20])
         ii = "<II"
     elif magic == self.BE_MAGIC:
         version, msgcount, masteridx, transidx = unpack (">4I", buf [4:20])
         ii = ">II"
     else:
         raise IOError (0, "Bad magic number", filename)
     # Now put all messages from the .mo file buffer into the catalog
     # dictionary.
     for i in pyk.xrange (0, msgcount) :
         mlen, moff = unpack (ii, buf [masteridx : masteridx + 8])
         tlen, toff = unpack (ii, buf [transidx  : transidx  + 8])
         mend       = moff + mlen
         tend       = toff + tlen
         if mend < buflen and tend < buflen:
             msg  = buf [moff:mend]
             tmsg = buf [toff:tend]
         else:
             raise IOError (0, "File is corrupt", filename)
         # See if we're looking at GNU .mo conventions for metadata
         if not mlen :
             # Catalog description
             lastk = k = None
             for b_item in tmsg.split ('\n'.encode("ascii")) :
                 item = b_item.decode().strip()
                 if not item:
                     continue
                 if ":" in item :
                     k, v           = item.split (":", 1)
                     k              = k.strip ().lower ()
                     v              = v.strip ()
                     self._info [k] = v
                     lastk          = k
                 elif lastk :
                     self._info [lastk] += "\n" + item
                 if k == "content-type" :
                     self._charset = v.split ("charset=") [1]
                 elif k == "plural-forms" :
                     v           = v.split     (";")
                     plural      = v [1].split ("plural=") [1]
                     self.plural = c2py        (plural)
         # Note: we unconditionally convert both msgids and msgstrs to
         # Unicode using the character encoding specified in the charset
         # parameter of the Content-Type header.  The gettext documentation
         # strongly encourages msgids to be us-ascii, but some appliations
         # require alternative encodings (e.g. Zope's ZCML and ZPT).  For
         # traditional gettext applications, the msgid conversion will
         # cause no problems since us-ascii should always be a subset of
         # the charset encoding.  We may want to fall back to 8-bit msgids
         # if the Unicode conversion fails.
         charset = self._charset or 'ascii'
         sep     = b"\x00"
         if sep in msg :
             # Plural forms
             msgid1, msgid2 = msg.split  (sep)
             tmsg           = tmsg.split (sep)
             msgid1 = pyk.text_type (msgid1, charset)
             msgid2 = pyk.text_type (msgid2, charset)
             tmsg   = [pyk.text_type (x, charset) for x in tmsg]
             for i, msg in enumerate (tmsg) :
                 catalog [(msgid1, i)] = msg
             ### In addtion to the two keys to the catalog as well to be
             ### able to have access to the singular and the last plural
             ### translation as well
             catalog [msgid1] = tmsg [ 0]
             catalog [msgid2] = tmsg [-1]
         else:
             msg  = pyk.text_type (msg,  charset)
             tmsg = pyk.text_type (tmsg, charset)
             catalog [msg] = tmsg
         # advance to next entry in the seek tables
         masteridx += 8
         transidx  += 8
def gen_records (xls_name) :
    book    = xlrd.open_workbook  (xls_name, encoding_override = "iso-8859-1")
    sheet   = book.sheet_by_index (0)
    for i in pyk.xrange (0, sheet.nrows) :
        for ndc in _convert_row (sheet.row (i)) :
            yield ndc
Пример #11
0
 def rotate_prev(self, n):
     """Move `self.mark` backward (i.e., following `prev`) `n` times."""
     for i in pyk.xrange(n):
         self.mark = self.mark.prev
Пример #12
0
 def rotate_next(self, n):
     """Move `self.mark` forward (i.e., following `next`) `n` times."""
     for i in pyk.xrange(n):
         self.mark = self.mark.next