def to_int(cls, permission): perm = 0 v = to_str(permission) match = cls.re_from_str.search(v) if match: if match.group(1) != '-': perm |= STAT_ISDIR if match.group(2) != '-': perm |= STAT_RUSR if match.group(3) != '-': perm |= STAT_WUSR if match.group(4) != '-': perm |= STAT_XUSR if match.group(5) != '-': perm |= STAT_RGRP if match.group(6) != '-': perm |= STAT_WGRP if match.group(7) != '-': perm |= STAT_XGRP if match.group(8) != '-': perm |= STAT_ROTH if match.group(9) != '-': perm |= STAT_WOTH if match.group(10) != '-': perm |= STAT_XOTH return perm match = cls.re_dec.search(v) if match: perm = int(match.group(1)) return perm match = cls.re_oct.search(v) if match: perm = int(match.group(1), 8) return perm match = cls.re_hex.search(v) if match: perm = int(match.group(1), 16) return perm msg = "Invalid permission %r." % (permission) raise ValueError(msg)
def mtime(self, val): if isinstance(val, datetime): self._mtime = val elif isinstance(val, six.string_types) or isinstance(val, six.binary_type): v = to_str(val) pat_older = '%b %d %Y' pat_newer = '%Y %b %d %H:%M' cur_year = datetime.utcnow().year try: self._mtime = datetime.strptime(v, pat_older) except ValueError: try: vn = "%d %s" % (cur_year, v) self._mtime = datetime.strptime(vn, pat_newer) except ValueError: msg = "Invalid mtime of the FTP entry %r." % (val) raise ValueError(msg) else: msg = "Invalid mtime of the FTP entry %r." % (val) raise ValueError(msg)
def read_line(self, socket_has_data=False): """ Reads exact one line of data from socket and gives it back. This reading action is performed either from self.connection, if there is such one after accept(), or from self.sock. I assume, that there are some data on the socket, so this call is not blocking. If it isn't so, then the call to this method is blocking (if has_data was set to False). If there was more than one line read at once, the rest is saved self._input_buffer. @param socket_has_data: assumes, that there are some data on the socket, that can be read. If False, then read_line() checks, with select, whether there are some data on the socket @type socket_has_data: bool @return: the first line from self._input_buffer including the EOL character @rtype: str """ # Checking, whether to read from socket if not socket_has_data: if self.has_data(): socket_has_data = True # Read in all data, they are even on socket. if socket_has_data: if not self.connection: self.accept() while socket_has_data: self._read() if self.interrupted: socket_has_data = False else: socket_has_data = self.has_data() if self.interrupted: self.reset() if self.verbose > 3: log.debug(_("Performing input buffer ...")) if self._input_buffer: if self.verbose > 3: log.debug(_("Current input buffer: %r"), self._input_buffer) ibuffer = to_str(self._input_buffer, self.encoding) match = re_first_line.search(ibuffer) if match: line = match.group(1) + match.group(2) self._input_buffer = to_bytes( re_first_line.sub('', ibuffer), self.encoding) if self.verbose > 3: log.debug(_("Got a line: %r"), line) log.debug(_( "Current input buffer after read_line(): %r"), self._input_buffer) return line else: return '' return ''
def group(self, val): if isinstance(val, six.string_types) or isinstance(val, six.binary_type): self._group = to_str(val) else: msg = "Invalid FTP group name %r." % (val) raise ValueError(msg)
def user(self, val): if isinstance(val, six.string_types) or isinstance(val, six.binary_type): self._user = to_str(val) else: msg = "Invalid FTP user name %r." % (val) raise ValueError(msg)
def name(self, val): if isinstance(val, six.string_types) or isinstance(val, six.binary_type): self._name = to_str(val) else: msg = "Invalid FTP entry name %r." % (val) raise ValueError(msg)