Ejemplo n.º 1
0
    def get_member_names(self):
        """Return list of direct collection member names (utf-8 encoded).

        See DAVCollection.get_member_names()
        """
        # On Windows NT/2k/XP and Unix, if path is a Unicode object, the result
        # will be a list of Unicode objects.
        # Undecodable filenames will still be returned as string objects
        # If we don't request unicode, for example Vista may return a '?'
        # instead of a special character. The name would then be unusable to
        # build a distinct URL that references this resource.

        nameList = []
        # self._file_path is unicode, so os.listdir returns unicode as well
        assert compat.is_unicode(self._file_path)
        for name in os.listdir(self._file_path):
            if not compat.is_unicode(name):
                name = name.decode(sys.getfilesystemencoding())
            assert compat.is_unicode(name)
            # Skip non files (links and mount points)
            fp = os.path.join(self._file_path, name)
            if not os.path.isdir(fp) and not os.path.isfile(fp):
                _logger.debug("Skipping non-file {!r}".format(fp))
                continue
            # name = name.encode("utf8")
            name = compat.to_native(name)
            nameList.append(name)
        return nameList
Ejemplo n.º 2
0
    def get_member_names(self):
        """Return list of direct collection member names (utf-8 encoded).

        See DAVCollection.get_member_names()
        """
        # On Windows NT/2k/XP and Unix, if path is a Unicode object, the result
        # will be a list of Unicode objects.
        # Undecodable filenames will still be returned as string objects
        # If we don't request unicode, for example Vista may return a '?'
        # instead of a special character. The name would then be unusable to
        # build a distinct URL that references this resource.

        nameList = []
        # self._file_path is unicode, so os.listdir returns unicode as well
        assert compat.is_unicode(self._file_path)
        for name in os.listdir(self._file_path):
            if not compat.is_unicode(name):
                name = name.decode(sys.getfilesystemencoding())
            assert compat.is_unicode(name)
            # Skip non files (links and mount points)
            fp = os.path.join(self._file_path, name)
            if not os.path.isdir(fp) and not os.path.isfile(fp):
                _logger.debug("Skipping non-file {!r}".format(fp))
                continue
            # name = name.encode("utf8")
            name = compat.to_native(name)
            nameList.append(name)
        return nameList
Ejemplo n.º 3
0
    def wsgiWriteData(self, data):
        if not self.wsgiSentHeaders:
            status, headers = self.wsgiHeaders
            # Need to send header prior to data
            statusCode = status[:status.find(" ")]
            statusMsg = status[status.find(" ") + 1:]
            _logger.debug("wsgiWriteData: send headers '{!r}', {!r}".format(
                status, headers))
            self.send_response(int(statusCode), statusMsg)
            for header, value in headers:
                self.send_header(header, value)
            self.end_headers()
            self.wsgiSentHeaders = 1
        # Send the data
        # assert type(data) is str # If not, Content-Length is propably wrong!
        _logger.debug("wsgiWriteData: write {} bytes: '{!r}'...".format(
            len(data), compat.to_native(data[:50])))
        if compat.is_unicode(
                data):  # If not, Content-Length is propably wrong!
            _logger.info(
                "ext_wsgiutils_server: Got unicode data: {!r}".format(data))
            # data = compat.wsgi_to_bytes(data)
            data = compat.to_bytes(data)

        try:
            self.wfile.write(data)
        except socket.error as e:
            # Suppress stack trace when client aborts connection disgracefully:
            # 10053: Software caused connection abort
            # 10054: Connection reset by peer
            if e.args[0] in (10053, 10054):
                _logger.info("*** Caught socket.error: ", e, file=sys.stderr)
            else:
                raise
Ejemplo n.º 4
0
 def get_member_names(self):
     nameList = []
     # self._file_path is unicode, so os.listdir returns unicode as well
     assert compat.is_unicode(self._file_path)
     for name in self.db.list_files_and_dirs(self._file_path):
         if not compat.is_unicode(name):
             name = name.decode(sys.getfilesystemencoding())
         assert compat.is_unicode(name)
         # Skip non files (links and mount points)
         fp = name
         if not self.db.is_dir(fp) and not self.db.is_file(fp):
             _logger.debug("Skipping non-file {!r}".format(fp))
             continue
         # name = name.encode("utf8")
         name = compat.to_native(name)
         nameList.append(name)
     return nameList
Ejemplo n.º 5
0
 def _isUser(self, username, domain, server):
     resume = "init"
     while resume:
         if resume == "init":
             resume = 0
         try:
             users, _total, resume = win32net.NetUserEnum(
                 server, 0, win32netcon.FILTER_NORMAL_ACCOUNT, 0)
             # Make sure, we compare unicode
             un = username.decode("utf8").lower()
             for userinfo in users:
                 uiname = userinfo.get("name")
                 assert uiname
                 assert compat.is_unicode(uiname)
                 if un == userinfo["name"].lower():
                     return True
         except win32net.error as e:
             _logger.exception("NetUserEnum: %s" % e)
             return False
     _logger.info("User '%s' not found on server '%s'" % (username, server))
     return False
Ejemplo n.º 6
0
 def _is_user(self, user_name, domain, server):
     # TODO: implement some kind of caching here?
     resume = "init"
     while resume:
         if resume == "init":
             resume = 0
         try:
             users, _total, resume = win32net.NetUserEnum(
                 server, 0, win32netcon.FILTER_NORMAL_ACCOUNT, 0
             )
             # Make sure, we compare unicode
             un = compat.to_unicode(user_name).lower()
             for userinfo in users:
                 uiname = userinfo.get("name")
                 assert uiname
                 assert compat.is_unicode(uiname)
                 if un == userinfo["name"].lower():
                     return True
         except win32net.error as e:
             _logger.exception("NetUserEnum: {}".format(e))
             return False
     _logger.info("User {!r} not found on server {!r}".format(user_name, server))
     return False