def _import_top_module(self, parent, name):
    """Locate the top of the import tree (relative or absolute).

    parent defines the context in which the import should occur. See
    _determine_import_context() for details.

    Returns a tuple (module, tail). module is the loaded (top-level) module,
    or None if the module is not found. tail is the remaining portion of
    the dotted name.
    """
    i = strop.find(name, '.')
    if i == -1:
      head = name
      tail = ""
    else:
      head = name[:i]
      tail = name[i+1:]
    if parent:
      fqname = "%s.%s" % (parent.__name__, head)
    else:
      fqname = head
    module = self._import_one(parent, head, fqname)
    if module:
      # the module was relative, or no context existed (the module was
      # simply found on the path).
      return module, tail
    if parent:
      # we tried relative, now try an absolute import (from the path)
      module = self._import_one(None, head, head)
      if module:
        return module, tail

    # the module wasn't found
    return None, None
    def add(self, entry):
        """Add an ENTRY to the CArchive.

           ENTRY must have:
             entry[0] is name (under which it will be saved).
             entry[1] is fullpathname of the file.
             entry[2] is a flag for it's storage format (0==uncompressed,
             1==compressed, 2==Python source format)
             entry[3] is the entry's type code."""
        (nm, pathnm, flag, typcd) = entry[:4]
        if flag == 2:
            s = open(pathnm, 'r').read()
            s = s + '\n\0'
        else:
            s = open(pathnm, 'rb').read()
        ulen = len(s)
        if flag == 1:
            s = zlib.compress(s, self.LEVEL)
        dlen = len(s)
        where = self.lib.tell()
        if typcd == 'm':
            if strop.find(pathnm, '.__init__.py') > -1:
                typcd = 'M'
        self.toc.add(where, dlen, ulen, flag, typcd, nm)
        self.lib.write(s)
Example #3
0
  def _import_top_module(self, parent, name):
    """Locate the top of the import tree (relative or absolute).

    parent defines the context in which the import should occur. See
    _determine_import_context() for details.

    Returns a tuple (module, tail). module is the loaded (top-level) module,
    or None if the module is not found. tail is the remaining portion of
    the dotted name.
    """
    i = strop.find(name, '.')
    if i == -1:
      head = name
      tail = ""
    else:
      head = name[:i]
      tail = name[i+1:]
    if parent:
      fqname = "%s.%s" % (parent.__name__, head)
    else:
      fqname = head
    module = self._import_one(parent, head, fqname)
    if module:
      # the module was relative, or no context existed (the module was
      # simply found on the path).
      return module, tail
    if parent:
      # we tried relative, now try an absolute import (from the path)
      module = self._import_one(None, head, head)
      if module:
        return module, tail

    # the module wasn't found
    return None, None
Example #4
0
 def add(self, entry):
     """Add an ENTRY to the CArchive.
 
    ENTRY must have:
      entry[0] is name (under which it will be saved).
      entry[1] is fullpathname of the file.
      entry[2] is a flag for it's storage format (0==uncompressed,
      1==compressed, 2==Python source format)
      entry[3] is the entry's type code."""
     (nm, pathnm, flag, typcd) = entry[:4]
     if flag == 2:
         s = open(pathnm, 'r').read()
         s = s + '\n\0'
     else:
         s = open(pathnm, 'rb').read()
     ulen = len(s)
     if flag == 1:
         s = zlib.compress(s, self.LEVEL)
     dlen = len(s)
     where = self.lib.tell()
     if typcd == 'm':
         if strop.find(pathnm, '.__init__.py') > -1:
             typcd = 'M'
     self.toc.add(where, dlen, ulen, flag, typcd, nm)
     self.lib.write(s)
 def test_find(self):
     self.assertTrue(strop.find("abcdefghiabc", "abc") == 0)
     self.assertTrue(strop.find("abcdefghiabc", "abc", 1) == 9)
     self.assertTrue(strop.find("abcdefghiabc", "def", 4) == -1)
Example #6
0
import warnings
 def test_find(self):
     self.assertTrue(strop.find("abcdefghiabc", "abc") == 0)
     self.assertTrue(strop.find("abcdefghiabc", "abc", 1) == 9)
     self.assertTrue(strop.find("abcdefghiabc", "def", 4) == -1)
Example #8
0
import warnings