<commit_before># Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE

import io
import mimetypes
import os
import re
import shutil
import zipfile
from typing import List, Optional, Union
from urllib.parse import quote, unquote

from PIL import Image, ImageFile, ImageOps
from requests.exceptions import HTTPError, SSLError

import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import call_hook_method, cint, get_files_path, get_hook_method
from frappe.utils.file_manager import is_safe_path
from frappe.utils.image import optimize_image, strip_exif_data

from .exceptions import AttachmentLimitReached, FolderNotEmpty, MaxFileSizeReachedError
from .utils import *

exclude_from_linked_with = True
ImageFile.LOAD_TRUNCATED_IMAGES = True
URL_PREFIXES = ("http://", "https://")


class File(Document):
	no_feed_on_delete = True

	def __init__(self, *args, **kwargs):
		super().__init__(*args, **kwargs)
		# if content is set, file_url will be generated
		# decode comes in the picture if content passed has to be decoded before writing to disk

		self.content = self.get("content") or b""
		self.decode = self.get("decode", False)

	@property
	def is_remote_file(self):
		return not self.content or (self.file_url or "").startswith(URL_PREFIXES)

	def autoname(self):
		"""Set name for folder"""
		if self.is_folder:
			if self.folder:
				self.name = self.get_name_based_on_parent_folder()
			else:
				# home
				self.name = self.file_name
		else:
			self.name = frappe.generate_hash(length=10)

	def before_insert(self):
		self.set_folder_name()
		self.set_file_name()
		self.validate_attachment_limit()

		if not self.is_folder and not self.is_remote_file:
			self.save_file(content=self.get_content())
			self.flags.new_file = True
			frappe.local.rollback_observers.append(self)

	def after_insert(self):
		if not self.is_folder:<commit_msg>fix: File.is_remote_file logic<commit_after># Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE

import io
import mimetypes
import os
import re
import shutil
import zipfile
from typing import List, Optional, Union
from urllib.parse import quote, unquote

from PIL import Image, ImageFile, ImageOps
from requests.exceptions import HTTPError, SSLError

import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import call_hook_method, cint, get_files_path, get_hook_method
from frappe.utils.file_manager import is_safe_path
from frappe.utils.image import optimize_image, strip_exif_data

from .exceptions import AttachmentLimitReached, FolderNotEmpty, MaxFileSizeReachedError
from .utils import *

exclude_from_linked_with = True
ImageFile.LOAD_TRUNCATED_IMAGES = True
URL_PREFIXES = ("http://", "https://")


class File(Document):
	no_feed_on_delete = True

	def __init__(self, *args, **kwargs):
		super().__init__(*args, **kwargs)
		# if content is set, file_url will be generated
		# decode comes in the picture if content passed has to be decoded before writing to disk

		self.content = self.get("content") or b""
		self.decode = self.get("decode", False)

	@property
	def is_remote_file(self):
		if self.file_url:
			return self.file_url.startswith(URL_PREFIXES)
		return not self.content

	def autoname(self):
		"""Set name for folder"""
		if self.is_folder:
			if self.folder:
				self.name = self.get_name_based_on_parent_folder()
			else:
				# home
				self.name = self.file_name
		else:
			self.name = frappe.generate_hash(length=10)

	def before_insert(self):
		self.set_folder_name()
		self.set_file_name()
		self.validate_attachment_limit()

		if not self.is_folder and not self.is_remote_file:
			self.save_file(content=self.get_content())
			self.flags.new_file = True
			frappe.local.rollback_observers.append(self)

	def after_insert(self):
		if not self.is_folder:
{'fraction_non_alphanumeric': 0.08829568788501027, 'fraction_numerical': 0.003080082135523614, 'mean_word_length': 4.976993865030675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7198829', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1279, 'n_words': 359}