<commit_before>package com.elctech {

	import flash.events.EventDispatcher;
	import flash.events.ProgressEvent;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.events.HTTPStatusEvent;
	import flash.events.DataEvent;

	import flash.net.FileReference;
	import flash.net.URLVariables;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;

	import flash.system.Security;
	import flash.xml.XMLDocument;
	import flash.xml.XMLNode;

	/**
	 * This class encapsulates a POST request to S3.
	 * 
	 * After you create an S3PostRequest, invoke S3PostRequest::upload(fileReference:FileReference).
	 * 
	 */
	public class S3UploadRequest extends EventDispatcher {

		[Event(name="open", type="flash.events.Event.OPEN")]
		[Event(name="uploadCompleteData", type="flash.events.DataEvent.UPLOAD_COMPLETE_DATA")]
		[Event(name="ioError", type="flash.events.IOErrorEvent.IO_ERROR")]
		[Event(name="securityError", type="flash.events.SecurityErrorEvent.SECURITY_ERROR")]
		[Event(name="progress", type="flash.events.ProgressEvent.PROGRESS")]

		private var _accessKeyId:String;
		private var _bucket:String;
		private var _key:String;
		private var _options:S3UploadOptions;
		private var _suppressIoError:Boolean;
		private var _uploadStarted:Boolean;
		private var fileReference:FileReference;

		private const ENDPOINT:String = "s3.amazonaws.com";
		private const MIN_BUCKET_LENGTH:int = 3;
		private const MAX_BUCKET_LENGTH:int = 63;

		/**
		 * Creates and initializes a new S3PostRequest object.
		 * @param    accessKeyId The AWS access key id to authenticate the request
		 * @param    bucket The bucket to POST into
		 * @param    key The key to create
		 * @param    options Options for this request
		 */
		public function S3UploadRequest(options:S3UploadOptions) 
		{
			_accessKeyId = options.AWSAccessKeyId;
			_bucket      = options.bucket;
			_key         = options.key;
			_options     = options;
		}

		private function buildUrl():String 
		{

			var canUseVanityStyle:Boolean = canUseVanityStyle(_bucket);

			if(_options.Secure!="false" && canUseVanityStyle && _bucket.match(/\./)) {
				// We cannot use SSL for bucket names containing "."
				// The certificate won't match "my.bucket.s3.amazonaws.com"
				throw new SecurityError("Cannot use SSL with bucket name containing '.': " + _bucket);
			}

			var postUrl:String = "http" + ((_options.Secure == 'true') ? "s" : "") + "://";

			if(canUseVanityStyle) {
				postUrl += _bucket + "." + ENDPOINT;
			} else {
				postUrl += ENDPOINT + "/" + _bucket;
			}

			return postUrl;
		}

		private function canUseVanityStyle(bucket:String):Boolean 
		{
			if( bucket.length < MIN_BUCKET_LENGTH ||
					bucket.length > MAX_BUCKET_LENGTH ||
					bucket.match(/^\./) ||
					bucket.match(/\.$/) ) {
				return false;
			}

			// must be lower case
			if(bucket.toLowerCase() != bucket) {
				return false;
			}<commit_msg>removed obsolete guard against ssl<commit_after>package com.elctech {

	import flash.events.EventDispatcher;
	import flash.events.ProgressEvent;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.events.HTTPStatusEvent;
	import flash.events.DataEvent;

	import flash.net.FileReference;
	import flash.net.URLVariables;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;

	import flash.system.Security;
	import flash.xml.XMLDocument;
	import flash.xml.XMLNode;

	/**
	 * This class encapsulates a POST request to S3.
	 * 
	 * After you create an S3PostRequest, invoke S3PostRequest::upload(fileReference:FileReference).
	 * 
	 */
	public class S3UploadRequest extends EventDispatcher {

		[Event(name="open", type="flash.events.Event.OPEN")]
		[Event(name="uploadCompleteData", type="flash.events.DataEvent.UPLOAD_COMPLETE_DATA")]
		[Event(name="ioError", type="flash.events.IOErrorEvent.IO_ERROR")]
		[Event(name="securityError", type="flash.events.SecurityErrorEvent.SECURITY_ERROR")]
		[Event(name="progress", type="flash.events.ProgressEvent.PROGRESS")]

		private var _accessKeyId:String;
		private var _bucket:String;
		private var _key:String;
		private var _options:S3UploadOptions;
		private var _suppressIoError:Boolean;
		private var _uploadStarted:Boolean;
		private var fileReference:FileReference;

		private const ENDPOINT:String = "s3.amazonaws.com";
		private const MIN_BUCKET_LENGTH:int = 3;
		private const MAX_BUCKET_LENGTH:int = 63;

		/**
		 * Creates and initializes a new S3PostRequest object.
		 * @param    accessKeyId The AWS access key id to authenticate the request
		 * @param    bucket The bucket to POST into
		 * @param    key The key to create
		 * @param    options Options for this request
		 */
		public function S3UploadRequest(options:S3UploadOptions) 
		{
			_accessKeyId = options.AWSAccessKeyId;
			_bucket      = options.bucket;
			_key         = options.key;
			_options     = options;
		}

		private function buildUrl():String 
		{
			var canUseVanityStyle:Boolean = canUseVanityStyle(_bucket);
			var postUrl:String = "http" + ((_options.Secure == 'true') ? "s" : "") + "://";

			if(canUseVanityStyle) {
				postUrl += _bucket + "." + ENDPOINT;
			} else {
				postUrl += ENDPOINT + "/" + _bucket;
			}

			return postUrl;
		}

		private function canUseVanityStyle(bucket:String):Boolean 
		{
			if( bucket.length < MIN_BUCKET_LENGTH ||
					bucket.length > MAX_BUCKET_LENGTH ||
					bucket.match(/^\./) ||
					bucket.match(/\.$/) ) {
				return false;
			}

			// must be lower case
			if(bucket.toLowerCase() != bucket) {
				return false;
			}
{'fraction_non_alphanumeric': 0.11484444444444444, 'fraction_numerical': 0.0044444444444444444, 'mean_word_length': 3.917832167832168, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3509634', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1727, 'n_words': 397}