def post(self): name = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') error = {} # let's check if user already exists user = User.by_name(name) if user: error['name'] = "User already exists" # let's check if a name it's been introduced and its format name_ok = name and validate(name, '^[a-zA-Z0-9_-]{3,20}$') if not name_ok: error['name'] = "That's not a valid user name" # let's check there is a password and its format password_ok = password and validate(password, '^.{3,20}$') if not password_ok: error['password'] = "******" # let's check the verify password is the same as the password if verify != password: error['verify'] = "Your passwords didn't match" # not needed, but if there is an email let's check its format if email != '': if not validate(email, '^[\S]+@[\S]+.[\S]+$'): error['email'] = "That's not a valid email" # if everything went right, let's introduce our new friend if not error: pw_hash = make_pw_hash(name, password) user = User(name=name, password=pw_hash, email=email) user.put() # now we logged the user in self.login(user) self.redirect('/') # if something went wrong, let's render again showing the error self.render('sign-up.html', name=name, email=email, error=error)
def _parse_environment_file(self, data, params): parsed = {} tunnel_schema = { 'service': SchemaEntry(True, '', str, None), 'message': SchemaEntry(False, '', str, None) } env_schema = { 'copy': SchemaEntry(False, [], list, None), 'image': SchemaEntry(False, [], list, None), 'components': SchemaEntry(True, {}, dict, None), # TODO: enhance validation such that expose_tunnel can be validated here 'expose_tunnel': SchemaEntry(False, {}, None, None) } top_schema = { 'name': SchemaEntry(True, '', str, None), 'environment': SchemaEntry(False, {}, dict, env_schema), 'cluster': SchemaEntry(False, {}, dict, None) } is_valid, message, validated = helpers.validate(data, top_schema) if not is_valid: raise ParseError(message) if not defaults.taggable_name_re.match(validated['name']): raise ParseError('Invalid characters in name') # Validate expose_tunnel separately (because it can be either a dictionary or a list) if 'environment' in top_schema and 'expose_tunnel' in top_schema['environment']: expose_tunnel = top_schema['environment']['expose_tunnel'] if type(expose_tunnel) == dict: tunnel_valid, tunnel_msg, tunnel_validated = helpers.validate(expose_tunnel, tunnel_schema) elif type(expose_tunnel) == list: for e in expose_tunnel: tunnel_valid, tunnel_msg, tunnel_validated = helpers.validate(expose_tunnel, tunnel_schema) if not tunnel_valid: break else: raise ParseError('expose_tunnel must be either a list or dictionary') if not tunnel_valid: raise ParseError(tunnel_msg) if 'components' in validated.get('environment', {}): validated['environment']['components'] = self._parse_components_section(validated['environment']['components']) if 'cluster' in validated: validated['cluster'] = self._parse_cluster_section(validated['cluster'], params) return validated
def voice_pipeine(): """Starts voice processing pipleine """ global can_sst_start, can_validate _thread.start_new_thread(record, (4, )) speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config) print("Speach to text conversion started") result = speech_recognizer.recognize_once() if result.reason == speechsdk.ResultReason.RecognizedSpeech: print("Recognized: {}".format(result.text)) while (not can_validate): pass validated, emp_id = helpers.validate(result.text) if validated: requests.get(url=SERVER_URL + 'alternate/' + emp_id + '/' + 'BUILDING_IN/', timeout=5) elif result.reason == speechsdk.ResultReason.NoMatch: print("No speech could be recognized: {}".format( result.no_match_details)) elif result.reason == speechsdk.ResultReason.Canceled: cancellation_details = result.cancellation_details print("Speech Recognition canceled: {}".format( cancellation_details.reason)) if cancellation_details.reason == speechsdk.CancellationReason.Error: print("Error details: {}".format( cancellation_details.error_details)) can_sst_start = True
def main(): """encapsuate execution main""" from sys import argv message = input("Type a message:\n") prompt = "Rotate by:\n" shift = int(validate(prompt, *argv)) print(encrypt(message, shift))
def register(): """Register user""" if request.method == 'POST': if not request.form.get('username'): return apology("Please provide a unique username", 403) if not request.form.get('password'): return apology("Please Provide a password", 403) if not request.form.get('confirmation'): return apology("Please confirm password", 403) validate_error = validate(request.form.get("password")) if validate_error: return validate_error if request.form.get('password') != request.form.get('confirmation'): return apology("Password do not match", 403) user = db.execute( "INSERT INTO users (username, hash) VALUES(:username, :hash)", username=request.form.get('username'), hash=generate_password_hash(request.form.get('password'))) if user is None: return apology("Unsuccessful Registration", 403) flash("Lets Start TRADING !!!") session['user_id'] = user return redirect("/") else: return render_template('register.html')
def main(): """Vigenere main encapsulation""" from sys import argv message = input("Type a message: \n") prompt = "Encryption key:\n" crypt_key = validate(prompt, *argv) print(encrypt(message, crypt_key))
def register(r, w, params): d = get_json_or_error(r, w) if d is None: return if "username" not in d or "password" not in d: write_response(w, '{"error": "no username or password in body"}') return username = d["username"] password = d["password"] u = find_user(username) if u is not None: write_response(w, '{"error": "user already exists"}') return if not validate(username): write_response(w, '{"error": "invalid username or password"}') return create_user(username, password) write_response(w, '{"result": "ok"}')
def register(username, password): validator = helpers.validate(username, password) if not validator.is_valid(password): raise helpers.StrongPasswordException(messages.STRONG_PASSWORD) hashed_password, salt = helpers.hash_my_password(password) cursor.execute('''INSERT INTO clients (username, password, salt) VALUES (?, ?, ?)''', (username, hashed_password, salt)) db.commit()
def register(): """Register user""" # Forget any user_id session.clear() # User reached route via POST (as by submitting a form via POST) if request.method == "POST": # Ensure username was submitted if not request.form.get("username"): return apology("missing username", 400) # Ensure password was submitted elif not request.form.get("password"): return apology("missing password", 400) # ensure password is correctly confirm elif request.form.get("password") != request.form.get("confirmation"): return apology("password do not match confirmation", 400) username = request.form.get('username') password = request.form.get('password') validate_pass = validate(password) if validate_pass == 1: flash("Make sure your password is at least 8 letters") return render_template("register.html") elif validate_pass == 2: flash("Make sure your password has a number in it") return render_template("register.html") elif validate_pass == 3: flash("Make sure your password has a capital letter in it") return render_template("register.html") else: pass_hash = generate_password_hash(password) result = db.execute("INSERT INTO users (username, hash) VALUES (:username, :pass_hash)", username=username, pass_hash=pass_hash ) if not result: return apology("Username already taken", 400) # auto log in user session["user_id"] = result # Redirect user to home page return redirect("/") else: return render_template("register.html")
def register(): """Register user""" if request.method == "POST": # Get username (make sure not blank) if not request.form.get("username"): return apology("must provide username", 400) # Get password (make sure not blank) elif not request.form.get("password"): return apology("must provide password", 400) # Get password2 (make sure not blank) # elif not request.form.get("password2"): !!! DISABLED FOR CHECK50 # return apology("must provide confirmation password", 400) !!! DISABLED FOR CHECK50 # Make sure passwords match # elif request.form.get("password") != request.form.get("password2"): !!! DISABLED FOR CHECK50 # return apology("passwords must match", 400) !!! DISABLED FOR CHECK50 # Make sure password is valid elif validate(request.form.get("password")): return apology("invalid password", 400) # Get confirmation (make sure form checked) elif not request.form.get("confirmation"): return apology("accept terms and conditions", 400) # Create hash from password hash = generate_password_hash(request.form.get("password")) # Insert user in database new_user = db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)", username=request.form.get("username"), hash=hash) # Check if the user is unique, if not -> apology if not new_user: return apology("username taken", 400) # Automatically log in the new user session["user_id"] = new_user flash("Registered!") return redirect("/") else: return render_template("register.html")
def signup(): errors = {} if request.method == "POST": username = request.form['username'] password = request.form['password'] verify_pass = request.form['verify'] field_inputs = { 'username': username, 'password': password, 'verify_pass': verify_pass } validate(field_inputs, errors) if errors: return render_template("signup.html", errors=errors, field_inputs=field_inputs) new_user = User(username, password) db.session.add(new_user) db.session.commit() user = User.query.filter_by(username=username).first() session['username'] = user.username return redirect("/newpost") return render_template("signup.html", errors=errors)
def create_kozi(r, w, params): cookies = parse_cookies(r) if "session" not in cookies: write_response(w, '{"error": "auth is required"}') return mng = get_session_manager() username = mng.get_session(cookies["session"]) if username is None: write_response(w, '{"error": "auth is required"}') return u = find_user(username) if u is None: write_response(w, '{"error": "auth is required"}') return d = get_json_or_error(r, w) if d is None: return if "name" not in d or "fortune" not in d or "checksum" not in d: write_response(w, '{"error": "no name or fortune or checksum in body"}') return name = d["name"] if not validate(name): write_response(w, '{"error": "invalid name"}') return k = find_kozinak("%s_%s" % (username, name)) if k is not None: write_response(w, '{"error": "kozinak already exists"}') return fortune = d["fortune"] checksum = d["checksum"] pipe = d["pipe"] if "pipe" in d else None if create_kozinak_chk(name, fortune, checksum, username, pipe): write_response(w, '{"result": "ok"}') else: write_response(w, '{"error": "incorrect checksum"}')
def update(): if request.method == "GET": return render_template("enter.html") else: try: firstname = request.form.get("firstname") lastname = request.form.get("lastname") email = request.form.get("email") tel = request.form.get("tel") address = request.form.get("address") zip = request.form.get("zip") city = request.form.get("city") state = request.form.get("state") country = request.form.get("country") ccnum = request.form.get("ccnum") expdatemonth = request.form.get("expdatemonth") expdateyear = request.form.get("expdateyear") cvv = request.form.get("cvv") except: return apology("You didn't fill out part of the form!", 400) # Validate the credit card number (just because :)) x = validate(ccnum) if x is False: return apology("Invalid credit card number", 400) db.execute( "UPDATE information SET firstname = :firstname, lastname = :lastname, email = :email, telephone=:tel, address=:address, zip=:zip, city=:city, state=:state, ccnum=:ccnum, expdatemonth=:expdatemonth, expdateyear=:expdateyear, cvv=:cvv WHERE id=:id", id=session.get("user_id"), firstname=firstname, lastname=lastname, email=email, tel=tel, address=address, zip=zip, city=city, state=state, ccnum=ccnum, expdatemonth=expdatemonth, expdateyear=expdateyear, cvv=cvv) # Send email sendemail(email, "You have successfully updated your information!") return redirect("/userinfo")
def login(): ''' Display a login form and show validation errors as necessary. If they were trying to access a URL requiring login, remember this URL, so we can redirect to it after successful login. ''' next = request.args.get('n',u'') username = request.args.get('u',u'') error = helpers.getInt(request.args.get('r')) # determine whether or not to override focus to password f = helpers.validate(request.args.get('f'), ['username','password']) if not f: f = False if (username is u'') else 'password' return render_template('login.html', links=False, next=next, u=username, oFocus=f, err=error)
def signin(): if request.method == 'POST': validError = validate(request.form['username'], request.form['pwd'], database, "signin") if not validError: conn = create_connection(database) session['logged_in'] = True session['username'] = request.form['username'] session['id'] = get_user_id(conn, request.form['username']) session['is_admin'] = get_admin_status(conn, request.form['username']) return redirect('/') else: return render_template('signin.html', error=validError) elif request.method == 'GET': return render_template('signin.html')
def change_password(): """Change user password""" if request.method == "POST": # Check validity of all fields if not request.form.get("current_password"): return apology("provide current password", 400) elif not request.form.get("new_password"): return apology("provide new password", 400) elif not request.form.get("new_password2"): return apology("must provide confirmation password", 400) elif request.form.get("new_password") != request.form.get("new_password2"): return apology("passwords must match", 400) # Make sure new password is valid elif validate(request.form.get("new_password")): return apology("invalid password", 400) # Authenticate user userdata = db.execute("SELECT * FROM users WHERE id = :user_id", user_id=session["user_id"]) if len(userdata) != 1 or not check_password_hash(userdata[0]["hash"], request.form.get("current_password")): # Clear session and log out the user session.clear() return apology("password is incorrect", 400) # Change password hash = generate_password_hash(request.form.get("new_password")) # Update password db.execute("UPDATE users SET hash = :hash WHERE id = :user_id", user_id=session["user_id"], hash=hash) # Flash and return back to index page flash("Password Changed!") return redirect("/") else: return render_template("change_password.html")
def _read_profile(self, profile_file): """ Given user supplied file path, read in and validate profile file. Return dictionary contents """ full_path = os.path.abspath(os.path.expanduser(profile_file)) if not os.path.isfile(full_path): raise ProfileError('Cannot open file "{0}"'.format(profile_file)) stream = open(full_path, 'r') try: contents = yaml.load(stream) except yaml.YAMLError as e: raise ProfileError('Invalid YAML format {0}'.format(e)) main_schema = { 'cluster_name': SchemaEntry(True, None, str, None), 'controller_instance_type': SchemaEntry(False, '', str, None), 'shared_volume_size': SchemaEntry(False, 0, int, None), 'central_logging_level': SchemaEntry(False, 0, int, None), 'environment_file': SchemaEntry(False, '', str, None), 'shared_volume_id': SchemaEntry(False, '', str, None), 'parameters': SchemaEntry(True, {}, dict, None) } # Validate profile file is_valid, message, validated = helpers.validate(contents, main_schema) if not is_valid: raise ProfileError(message) if not defaults.taggable_name_re.match(validated['cluster_name']): raise ProfileError('Unsupported characters in cluster_name "{0}"'.format(validated['cluster_name'])) if len(validated['cluster_name']) > defaults.taggable_name_max_length: raise ProfileError('"cluster_name" cannot be more than {0} characters'.format(defaults.taggable_name_max_length)) if not 0 <= validated['central_logging_level'] <= 2: raise ProfileError('"central_logging_level" must be either 0, 1 or 2') if validated['shared_volume_size'] < 0: raise ProfileError('"shared_volume_size" cannot be negative') return validated
def enter(): try: firstname = request.form.get("firstname") lastname = request.form.get("lastname") email = request.form.get("email") tel = request.form.get("tel") address = request.form.get("address") zip = request.form.get("zip") city = request.form.get("city") state = request.form.get("state") ccnum = request.form.get("ccnum") expdatemonth = request.form.get("expdatemonth") expdateyear = request.form.get("expdateyear") cvv = request.form.get("cvv") except: return apology("You didn't fill out part of the form!", 400) # Validate the credit card number x = validate(ccnum) if x is False: return apology("Invalid credit card number", 400) db.execute( "INSERT INTO information VALUES(:id, :firstname, :lastname, :email, :tel, :address, :zip, :city, :state, :ccnum, :expdatemonth, :expdateyear, :cvv)", id=session.get("user_id"), firstname=firstname, lastname=lastname, email=email, tel=tel, address=address, zip=zip, city=city, state=state, ccnum=ccnum, expdatemonth=expdatemonth, expdateyear=expdateyear, cvv=cvv) # Send email sendemail(email, "You have registered for the ChadShirts bot!") return redirect("/")
def getuserfn(uname,owner=False): val=validate(uname) if(val['msg']): return {'result':val['msg']} conn = mysql.connect() cur = conn.cursor() cur.execute("select username,fname,lname,propicid,userid,gender from users where username=%s;",uname) details = cur.fetchone() userd = {'username': details[0], 'name': details[1] + " " + details[2],'gender':details[5],'userid':details[4]} picd={'id':details[3]} uid=str(details[4]) type = {'type': 'user', 'loggedin': val['loggedin'],'owner':val['owner'], 'name': details[0]} if val['owner']: cur.execute("select coverid,name,albumid from albums where userid=%s;",uid) else: cur.execute("select coverid,name,albumid from albums where userid=%s and privacy='public';", uid) albums = cur.fetchall() cur.close() conn.close() return {'result':'success','userdetails':userd,'profilepic':picd,'type':type,'albums':albums}
def validate(self): validator = helpers.validate(self.__username, self.__password) if not validator.is_valid(self.__password): raise exceptions.StrongPasswordException(messages.STRONG_PASSWORD) return True
def pre_train(dataloader, test_loader, dict_loader, dataloader_test, mask_labels, total_epochs=50, learning_rate=1e-4, use_gpu=True, seed=123): args = parser.parse_args() pprint(args) num_bits = args.num_bits model = CNN(model_name='alexnet', bit=num_bits, class_num=args.num_class) criterion = custom_loss(num_bits=num_bits) arch = 'cnn_' filename = arch + args.dataset + '_' + str(num_bits) + "bits" checkpoint_filename = os.path.join(args.checkpoint, filename + '.pt') if use_gpu: model = model.cuda() model = torch.nn.DataParallel(model, device_ids=range( torch.cuda.device_count())) criterion = criterion.cuda() torch.cuda.manual_seed(seed) running_loss = 0.0 start_epoch = 0 batch_time = AverageMeter() data_time = AverageMeter() end = time.time() best_prec = -99999 k = 10500 n_samples = 200000 alpha = 0.4 alpha_1 = 0.99 mask_labels = torch.from_numpy(mask_labels).long().cuda() Z_h1 = torch.zeros(n_samples, num_bits).float().cuda() # intermediate values z_h1 = torch.zeros(n_samples, num_bits).float().cuda() # temporal outputs h1 = torch.zeros(n_samples, num_bits).float().cuda() # current outputs Z_h2 = torch.zeros(args.anchor_num, num_bits).float().cuda() # intermediate values z_h2 = torch.zeros(args.anchor_num, num_bits).float().cuda() # temporal outputs h2 = torch.zeros(args.anchor_num, num_bits).float().cuda() # current outputs for epoch in range(start_epoch, total_epochs): model.train(True) rampup_value = rampup(epoch) rampdown_value = rampdown(epoch) learning_rate = rampup_value * rampdown_value * 0.00005 adam_beta1 = rampdown_value * 0.9 + (1.0 - rampdown_value) * 0.5 adam_beta2 = step_rampup(epoch) * 0.99 + (1 - step_rampup(epoch)) * 0.999 if epoch == 0: u_w = 0.0 else: u_w = rampup_value u_w_m = u_w * 5 u_w_m = torch.autograd.Variable(torch.FloatTensor([u_w_m]).cuda(), requires_grad=False) optimizer = Adam(model.parameters(), lr=learning_rate, betas=(adam_beta1, adam_beta2), eps=1e-8, amsgrad=True) anchors_data, anchor_Label = generate_anchor_vectors(dict_loader) for iteration, data in enumerate(dataloader, 0): anchor_index = np.arange(args.anchor_num) np.random.shuffle(anchor_index) anchor_index = anchor_index[:100] anchor_index = torch.from_numpy(anchor_index).long().cuda() anchor_inputs = anchors_data[anchor_index, :, :, :] anchor_labels = anchor_Label[anchor_index, :] inputs, labels, index = data['image'], data['labels'], data[ 'index'] labels = labels.float() mask_flag = Variable(mask_labels[index], requires_grad=False) idx = (mask_flag > 0) if index.shape[0] == args.batch_size: anchor_batch_S, anchor_batch_W = CalcSim( labels[idx, :].cuda(), anchor_labels.cuda()) if inputs.size(3) == 3: inputs = inputs.permute(0, 3, 1, 2) inputs = inputs.type(torch.FloatTensor) zcomp_h1 = z_h1[index.cuda(), :] zcomp_h2 = z_h2[anchor_index, :] labeled_batch_S, labeled_batch_W = CalcSim( labels[idx, :].cuda(), labels[idx, :].cuda()) if use_gpu: inputs = Variable(inputs.cuda(), requires_grad=False) anchor_batch_S = Variable(anchor_batch_S.cuda(), requires_grad=False) anchor_batch_W = Variable(anchor_batch_W.cuda(), requires_grad=False) labeled_batch_S = Variable(labeled_batch_S.cuda(), requires_grad=False) labeled_batch_W = Variable(labeled_batch_W.cuda(), requires_grad=False) # zero the parameter gradients optimizer.zero_grad() y_h1 = model(inputs) y_h2 = model(anchor_inputs) y = F.sigmoid(48 / num_bits * 0.4 * torch.matmul(y_h1, y_h2.permute(1, 0))) loss, l_batch_loss, m_loss = criterion( y, y_h1, y_h2, anchor_batch_S, anchor_batch_W, labeled_batch_S, labeled_batch_W, zcomp_h1, zcomp_h2, mask_flag, u_w_m, epoch, num_bits) h1[index, :] = y_h1.data.clone() h2[anchor_index, :] = y_h2.data.clone() # backward+optimize loss.backward() optimizer.step() running_loss += loss.item() Z_h2 = alpha_1 * Z_h2 + (1. - alpha_1) * h2 z_h2 = Z_h2 * (1. / (1. - alpha_1**(epoch + 1))) print( "Epoch[{}]({}/{}): Time:(data {:.3f}/ batch {:.3f}) Loss_H: {:.4f}/{:.4f}/{:.4f}" .format(epoch, iteration, len(dataloader), data_time.val, batch_time.val, loss.item(), l_batch_loss.item(), m_loss.item())) Z_h1 = alpha * Z_h1 + (1. - alpha) * h1 z_h1 = Z_h1 * (1. / (1. - alpha**(epoch + 1))) if epoch % 1 == 0: MAP = helpers.validate(model, dataloader_test, test_loader) print("Test image map is:{}".format(MAP)) is_best = MAP > best_prec best_prec = max(best_prec, MAP) save_checkpoint( { 'epoch': epoch + 1, 'state_dict': model.state_dict(), 'optimizer': optimizer.state_dict(), }, is_best, prefix=arch, num_bits=num_bits, filename=checkpoint_filename) return model
def test_valitate_password(self): password = "******" validator = helpers.validate("krasi", password) self.assertTrue(validator.is_valid(password))
def test_required_fields(app): """Test required fields.""" marcxml = load_fixture_file('videos_video.xml') with app.app_context(): blob = create_record(marcxml) record = model.do(blob) expected = { '$schema': { '$ref': ('https://cds.cern.ch/schemas/records/videos/video/' 'video-v1.0.0.json') }, '_access': { 'read': [ '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**' ], 'update': ['*****@*****.**', '*****@*****.**'] }, '_files': [{ 'filepath': 'MediaArchive/Video/Masters/Movies/CERN/2017/CERN-MOVIE-2017-023/Final_Output/CERN-MOVIE-2017-023-001.mov', 'key': 'CERN-MOVIE-2017-023-001.mov', 'tags': { 'media_type': 'video', 'content_type': 'mov', 'context_type': 'master', 'preview': True, }, }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-5872-kbps-1920x1080-audio-128-kbps-stereo.mp4', 'key': 'CERN-MOVIE-2017-023-001-5872-kbps-1920x1080-audio-128-kbps-stereo.mp4', 'tags_to_guess_preset': { 'preset': '1080p', 'video_bitrate': 5872 }, 'tags': { 'media_type': 'video', 'content_type': 'mp4', 'context_type': 'subformat', }, }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-2672-kbps-1280x720-audio-128-kbps-stereo.mp4', 'key': 'CERN-MOVIE-2017-023-001-2672-kbps-1280x720-audio-128-kbps-stereo.mp4', 'tags_to_guess_preset': { 'preset': '720p', 'video_bitrate': 2672 }, 'tags': { 'media_type': 'video', 'content_type': 'mp4', 'context_type': 'subformat', }, }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-1436-kbps-853x480-audio-64-kbps-stereo.mp4', 'key': 'CERN-MOVIE-2017-023-001-1436-kbps-853x480-audio-64-kbps-stereo.mp4', 'tags_to_guess_preset': { 'preset': '480p', 'video_bitrate': 1436 }, 'tags': { 'media_type': 'video', 'content_type': 'mp4', 'context_type': 'subformat', }, }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-836-kbps-640x360-audio-64-kbps-stereo.mp4', 'key': 'CERN-MOVIE-2017-023-001-836-kbps-640x360-audio-64-kbps-stereo.mp4', 'tags_to_guess_preset': { 'preset': '360p', 'video_bitrate': 836 }, 'tags': { 'media_type': 'video', 'content_type': 'mp4', 'context_type': 'subformat', }, }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-386-kbps-426x240-audio-64-kbps-stereo.mp4', 'key': 'CERN-MOVIE-2017-023-001-386-kbps-426x240-audio-64-kbps-stereo.mp4', 'tags_to_guess_preset': { 'preset': '240p', 'video_bitrate': 386 }, 'tags': { 'media_type': 'video', 'content_type': 'mp4', 'context_type': 'subformat', }, }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-5-percent.jpg', 'key': 'frame-1.jpg', 'tags': { 'content_type': 'jpg', 'context_type': 'frame', 'media_type': 'image' }, 'tags_to_transform': { 'timestamp': 5 } }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-5-percent.jpg', 'key': 'posterframe.jpg', 'tags': { 'media_type': 'image', 'height': '360', 'width': '640', 'content_type': 'jpg', 'context_type': 'poster', }, 'tags_to_transform': { 'timestamp': 5 }, }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-15-percent.jpg', 'key': 'frame-2.jpg', 'tags': { 'content_type': 'jpg', 'context_type': 'frame', 'media_type': 'image' }, 'tags_to_transform': { 'timestamp': 15 } }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-25-percent.jpg', 'key': 'frame-3.jpg', 'tags': { 'content_type': 'jpg', 'context_type': 'frame', 'media_type': 'image' }, 'tags_to_transform': { 'timestamp': 25 } }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-35-percent.jpg', 'key': 'frame-4.jpg', 'tags': { 'content_type': 'jpg', 'context_type': 'frame', 'media_type': 'image' }, 'tags_to_transform': { 'timestamp': 35 } }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-45-percent.jpg', 'key': 'frame-5.jpg', 'tags': { 'content_type': 'jpg', 'context_type': 'frame', 'media_type': 'image' }, 'tags_to_transform': { 'timestamp': 45 } }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-55-percent.jpg', 'key': 'frame-6.jpg', 'tags': { 'content_type': 'jpg', 'context_type': 'frame', 'media_type': 'image' }, 'tags_to_transform': { 'timestamp': 55 } }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-65-percent.jpg', 'key': 'frame-7.jpg', 'tags': { 'content_type': 'jpg', 'context_type': 'frame', 'media_type': 'image' }, 'tags_to_transform': { 'timestamp': 65 } }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-75-percent.jpg', 'key': 'frame-8.jpg', 'tags': { 'content_type': 'jpg', 'context_type': 'frame', 'media_type': 'image' }, 'tags_to_transform': { 'timestamp': 75 } }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-85-percent.jpg', 'key': 'frame-9.jpg', 'tags': { 'content_type': 'jpg', 'context_type': 'frame', 'media_type': 'image' }, 'tags_to_transform': { 'timestamp': 85 } }, { 'filepath': 'MediaArchive/Video/Public/Movies/CERN/2017/CERN-MOVIE-2017-023/CERN-MOVIE-2017-023-001/CERN-MOVIE-2017-023-001-posterframe-640x360-at-95-percent.jpg', 'key': 'frame-10.jpg', 'tags': { 'content_type': 'jpg', 'context_type': 'frame', 'media_type': 'image' }, 'tags_to_transform': { 'timestamp': 95 } }], '_project_id': 'https://cds.cern.ch/record/1', 'category': 'CERN', 'contributors': [{ 'name': 'CERN Video Productions', 'role': 'Producer' }, { 'name': 'CERN Video Productions', 'role': 'Director' }, { 'affiliations': (u'CERN', ), 'email': u'*****@*****.**', 'ids': [{ 'source': 'CERN', 'value': u'755568' }, { 'source': 'CDS', 'value': u'2090563' }], 'name': 'Madsen, Christoph Martin', 'role': 'Director' }, { 'affiliations': (u'CERN', ), 'email': u'*****@*****.**', 'ids': [{ 'source': 'CERN', 'value': u'380837' }, { 'source': 'CDS', 'value': u'2050975' }], 'name': 'Catapano, Paola', 'role': 'Director' }, { 'affiliations': (u'CERN', ), 'email': u'*****@*****.**', 'ids': [{ 'source': 'CERN', 'value': u'755568' }, { 'source': 'CDS', 'value': u'2090563' }], 'name': 'Madsen, Christoph Martin', 'role': 'Editor' }], 'copyright': { 'holder': 'CERN', 'year': '2017' }, 'date': '2017-07-04', 'description': ('Where were you on 4 July 2012, the day in which ' 'the Higgs boson discovery was announced?'), 'duration': '00:01:09', 'keywords': [{ 'name': 'higgs', 'source': 'CERN' }, { 'name': 'anniversary', 'source': 'CERN' }], 'language': u'en', 'recid': 2272973, 'report_number': ['CERN-MOVIE-2017-023-001'], 'title': { 'title': 'Happy 5th anniversary, Higgs boson!' }, 'type': 'MOVIE', 'external_system_identifiers': [{ 'schema': 'AVW', 'value': 'AVW.clip.3447' }], 'modified_by': '*****@*****.**', } assert record == expected # Add required fields calculated by post-process tasks. record['publication_date'] = '2017-07-04' record['doi'] = 'CERN/2272973' record['license'] = [{ 'license': 'CC BY 4.0', 'url': 'https://creativecommons.org/licenses/by/4.0/' }] validate(record)
def copy_kozi(r, w, params): cookies = parse_cookies(r) if "session" not in cookies: write_response(w, '{"error": "auth is required"}') return mng = get_session_manager() username = mng.get_session(cookies["session"]) if username is None: write_response(w, '{"error": "auth is required"}') return u = find_user(username) if u is None: write_response(w, '{"error": "auth is required"}') return d = get_json_or_error(r, w) if d is None: return if "url" not in d or "name" not in d: write_response(w, '{"error": "no name or url in body"}') return url = d["url"] name = d["name"] if not validate(name): write_response(w, '{"error": "invalid name"}') return if url.lower().startswith("gopher") or url.lower().startswith("file"): write_response(w, '{"error": "invalid url"}') return req = urlopen(url) data = req.read() try: j = json.loads(data) except: write_response(w, '{"error": "incorrect json %s"}' % data) return if "result" not in j: write_response(w, '{"error": "incorrect json %s"}' % data) return j = j["result"] if type(j) != type({}): write_response(w, '{"error": "incorrect json %s"}' % data) return if "name" not in j or "fortune" not in j or "owner" not in j or "pipe" not in j: write_response( w, '{"error": "no name or fortune or owner or pipe in body"}') return fortune = j["fortune"] pipe = j["pipe"] k = find_kozinak("%s_%s" % (username, name)) if k is not None: write_response(w, '{"error": "kozinak already exists"}') return create_kozinak(name, fortune, username, pipe) write_response(w, '{"result": "ok"}')