Args:
            path: `str`. The path to the document to upload. 
            document_type: `str`. DocumentType identified by the value of its name attribute. 
            is_protocol: `bool`. 
            description: `str`.
329190
def upload(cls, path, document_type, is_protocol, description=""):
        
        file_name = os.path.basename(path)
        mime_type = mimetypes.guess_type(file_name)[0]
        data = base64.b64encode(open(path, 'rb').read())
        temp_uri = str(data, "utf-8")
        #href = "data:{mime_type};base64,{temp_uri}".format(mime_type=mime_type, temp_uri=temp_uri) 
        payload = {}
        payload["content_type"] = mime_type 
        payload["data"] = temp_uri
        payload["description"] = description
        payload["document_type_id"] = DocumentType(document_type).id
        payload["name"] =  file_name
        payload["is_protocol"] = is_protocol
        cls.post(payload)
1149333
def document(_, path=''):
    
    container_path, object_path = path_parts(path)
    conn = get_connection()
    try:
        container = conn.get_container(container_path)
    except errors.NoContainerException:
        raise Http404("No container at: %s" % container_path)
    except errors.NotPermittedException:
        raise Http404("Access denied for container at: %s" % container_path)

    try:
        storage_obj = container.get_object(object_path)
    except errors.NoObjectException:
        raise Http404("No object at: %s" % object_path)

    # Get content-type and encoding.
    content_type = storage_obj.smart_content_type
    encoding = storage_obj.smart_content_encoding
    response = HttpResponse(content=storage_obj.read(),
                            content_type=content_type)
    if encoding not in (None, ''):
        response['Content-Encoding'] = encoding

    return response
1218193
def islink(self, path=None, header=None):
        
        if header is None:
            header = self._head(self.get_client_kwargs(path))

        for key in ('x-oss-object-type', 'type'):
            try:
                return header.pop(key) == 'Symlink'
            except KeyError:
                continue
        return False
1111624
def file(self, value):
        

        if value is not None:
            assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format("file", value)
        self.__file = value
276071
def path(self, value):
        

        if value is not None:
            assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
                "path", value)
            assert os.path.exists(value), "'{0}' attribute: '{1}' file doesn't exists!".format("path", value)
        self.__path = value
635327
def filebrowser(request, file_type):
    
    template = 'filebrowser.html'
    upload_form = FileUploadForm()
    uploaded_file = None
    upload_tab_active = False
    is_images_dialog = (file_type == 'img')
    is_documents_dialog = (file_type == 'doc')
    
    files = FileBrowserFile.objects.filter(file_type=file_type)
    
    if request.POST:
        upload_form = FileUploadForm(request.POST, request.FILES)
        upload_tab_active = True
        
        if upload_form.is_valid():
            uploaded_file = upload_form.save(commit=False)
            uploaded_file.file_type = file_type
            uploaded_file.save()
    
    data = {
        'upload_form': upload_form,
        'uploaded_file': uploaded_file,
        'upload_tab_active': upload_tab_active,
        'is_images_dialog': is_images_dialog,
        'is_documents_dialog': is_documents_dialog
    }
    per_page = getattr(settings, 'FILEBROWSER_PER_PAGE', 20)
    return render_paginate(request, template, files, per_page, data)
1170743
def _file_model_from_path(self, path, content=False, format=None):
        
        model = base_model(path)
        model["type"] = "file"
        if self.fs.isfile(path):
            model["last_modified"] = model["created"] = self.fs.lstat(path)["ST_MTIME"]
        else:
            model["last_modified"] = model["created"] = DUMMY_CREATED_DATE
        if content:
            try:
                content = self.fs.read(path)
            except NoSuchFile as e:
                self.no_such_entity(e.path)
            except GenericFSError as e:
                self.do_error(str(e), 500)
            model["format"] = format or "text"
            model["content"] = content
            model["mimetype"] = mimetypes.guess_type(path)[0] or "text/plain"
            if format == "base64":
                model["format"] = format or "base64"
                from base64 import b64decode
                model["content"] = b64decode(content)
        return model
1243050
def parse(cls, url_path):
        # type: (str) -> UrlPath
        
        if not url_path:
            return cls()

        nodes = []
        for node in url_path.rstrip('/').split('/'):
            # Identifies a PathNode
            if '{' in node or '}' in node:
                m = PATH_NODE_RE.match(node)
                if not m:
                    raise ValueError("Invalid path param: {}".format(node))

                # Parse out name and type
                name, param_type, param_arg = m.groups()
                try:
                    type_ = Type[param_type]
                except KeyError:
                    if param_type is not None:
                        raise ValueError("Unknown param type `{}` in: {}".format(param_type, node))
                    type_ = Type.Integer

                nodes.append(PathParam(name, type_, param_arg))
            else:
                nodes.append(node)

        return cls(*nodes)
1230238
def is_reparse_point(path):
	
	res = api.GetFileAttributes(path)
	return (
		res != api.INVALID_FILE_ATTRIBUTES
		and bool(res & api.FILE_ATTRIBUTE_REPARSE_POINT)
	)
919837
def set_with_filename(path)
      return if path.blank?
      
      self.filename = ::File.basename(path)
      self.content_type = ::MIME::Types.type_for(path).first.content_type
      self.data = ::Base64.encode64(::File.read(path))
    end
755817
def load(self, path):
        
        self.dct = wrapper.Dictionary()
        self.guide = wrapper.Guide()

        with open(path, 'rb') as f:
            self.dct.read(f)
            self.guide.read(f)

        return self
1351896
def upload(key, data_or_path, headers = {})
      if data_or_path.respond_to?(:read) && data_or_path.respond_to?(:size)
        upload_io(key, data_or_path, data_or_path.size, headers)
      elsif !File.file?(data_or_path.to_s)
        raise ArgumentError, "data_or_path must be an IO with data or filename string"
      else
        File.open(data_or_path.to_s, "rb") do |io|
          upload_io(key, io, io.stat.size, headers)
        end
      end
    end
643216
def load_path(self, path):
        
        logger.debug("load_path(path=%s)" % path)
        if os.path.isfile(path):
            configtype = self.guess_type(path)
            logger.debug("Detected config type: %s" % self._type_to_str(configtype))
            if configtype in self.TYPES:
                logger.debug("Opening config for reading")
                with open(path, 'r') as f:
                    data = f.read()
                datadict = self.TYPES[configtype]().reverse(data)
                return self.load_data(datadict)
            else:
                raise ValueError("Unsupported config type")
        else:
            logger.warn("load_path couldn't find the path: %s" % path)
484837
def fs_encode(path):
    

    path = _get_path(path)
    if path is None:
        raise TypeError("expected a valid path to encode")
    if isinstance(path, six.text_type):
        path = path.encode(_fs_encoding, _fs_encode_errors)
    return path
1042171
def islink(path):
    
    if platform.system() == "Windows":
        if sys.version_info[:2] < (3, 5):
            try:
                # pylint: disable=undefined-variable
                attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(path))  # noqa
                assert attrs != -1
                return bool(attrs & FILE_ATTRIBUTE_REPARSE_POINT)
            except (AttributeError, AssertionError):
                return False
        try:
            st = os.lstat(path)  # pylint: disable=invalid-name
        except (OSError, AttributeError):
            return False
        # pylint: disable=no-member
        return stat.S_ISLNK(st.st_mode) or st.st_file_attributes & stat.FILE_ATTRIBUTE_REPARSE_POINT
    return os.path.islink(path)
270926
def guess_mime_type(self, path):
		
		_, ext = posixpath.splitext(path)
		if ext in self.extensions_map:
			return self.extensions_map[ext]
		ext = ext.lower()
		return self.extensions_map[ext if ext in self.extensions_map else '']
1335561
def read(self, file_path=None):
        
        if not file_path:
            file_path = self.file_path

        # abort if the file path does not exist
        if not os.path.exists(file_path):
            self.oops("Sorry, but {} does not exist".format(file_path))
            return False

        # abort if the file path is not a file
        if not os.path.isfile(file_path):
            self.oops("Sorry, but {} is not a file".format(file_path))
            return False

        with open(file_path) as handler:
            return handler.read()