repo_name
stringlengths
6
100
path
stringlengths
4
294
copies
stringclasses
981 values
size
stringlengths
4
6
content
stringlengths
606
896k
license
stringclasses
15 values
input_ids
listlengths
1.02k
1.02k
labels
listlengths
1.02k
1.02k
attention_mask
listlengths
1.02k
1.02k
AthinaB/synnefo
snf-astakos-app/astakos/im/migrations/0030_auto__del_field_astakosuser_provider__del_field_astakosuser_third_part.py
10
27531
# encoding: utf-8 import datetime from south.db import db from south.v2 import SchemaMigration from django.db import models class Migration(SchemaMigration): def forwards(self, orm): # Deleting field 'AstakosUser.provider' db.delete_column('im_astakosuser', 'provider') # Deleting field 'AstakosUser.third_party_identifier' db.delete_column('im_astakosuser', 'third_party_identifier') # Adding field 'AstakosUser.deactivated_reason' db.add_column('im_astakosuser', 'deactivated_reason', self.gf('django.db.models.fields.TextField')(default=None, null=True), keep_default=False) # Adding field 'AstakosUser.deactivated_at' db.add_column('im_astakosuser', 'deactivated_at', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), keep_default=False) # Adding field 'AstakosUser.verification_code' db.add_column('im_astakosuser', 'verification_code', self.gf('django.db.models.fields.CharField')(max_length=255, unique=True, null=True), keep_default=False) # Adding field 'AstakosUser.verified_at' db.add_column('im_astakosuser', 'verified_at', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), keep_default=False) # Adding field 'AstakosUser.is_rejected' db.add_column('im_astakosuser', 'is_rejected', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False) # Adding field 'AstakosUser.rejected_reason' db.add_column('im_astakosuser', 'rejected_reason', self.gf('django.db.models.fields.TextField')(null=True, blank=True), keep_default=False) # Adding field 'AstakosUser.moderated' db.add_column('im_astakosuser', 'moderated', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False) # Adding field 'AstakosUser.moderated_at' db.add_column('im_astakosuser', 'moderated_at', self.gf('django.db.models.fields.DateTimeField')(default=None, null=True, blank=True), keep_default=False) # Adding field 'AstakosUser.moderated_data' db.add_column('im_astakosuser', 'moderated_data', self.gf('django.db.models.fields.TextField')(default=None, null=True, blank=True), keep_default=False) # Adding field 'AstakosUser.accepted_policy' db.add_column('im_astakosuser', 'accepted_policy', self.gf('django.db.models.fields.CharField')(default=None, max_length=255, null=True, blank=True), keep_default=False) # Adding field 'AstakosUser.accepted_email' db.add_column('im_astakosuser', 'accepted_email', self.gf('django.db.models.fields.EmailField')(default=None, max_length=75, null=True, blank=True), keep_default=False) def backwards(self, orm): # Adding field 'AstakosUser.provider' db.add_column('im_astakosuser', 'provider', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True), keep_default=False) # Adding field 'AstakosUser.third_party_identifier' db.add_column('im_astakosuser', 'third_party_identifier', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True), keep_default=False) # Deleting field 'AstakosUser.deactivated_reason' db.delete_column('im_astakosuser', 'deactivated_reason') # Deleting field 'AstakosUser.deactivated_at' db.delete_column('im_astakosuser', 'deactivated_at') # Deleting field 'AstakosUser.verification_code' db.delete_column('im_astakosuser', 'verification_code') # Deleting field 'AstakosUser.verified_at' db.delete_column('im_astakosuser', 'verified_at') # Deleting field 'AstakosUser.is_rejected' db.delete_column('im_astakosuser', 'is_rejected') # Deleting field 'AstakosUser.rejected_reason' db.delete_column('im_astakosuser', 'rejected_reason') # Deleting field 'AstakosUser.moderated' db.delete_column('im_astakosuser', 'moderated') # Deleting field 'AstakosUser.moderated_at' db.delete_column('im_astakosuser', 'moderated_at') # Deleting field 'AstakosUser.moderated_data' db.delete_column('im_astakosuser', 'moderated_data') # Deleting field 'AstakosUser.accepted_policy' db.delete_column('im_astakosuser', 'accepted_policy') # Deleting field 'AstakosUser.accepted_email' db.delete_column('im_astakosuser', 'accepted_email') models = { 'auth.group': { 'Meta': {'object_name': 'Group'}, 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) }, 'auth.permission': { 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, 'auth.user': { 'Meta': {'object_name': 'User'}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) }, 'contenttypes.contenttype': { 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) }, 'im.additionalmail': { 'Meta': {'object_name': 'AdditionalMail'}, 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"}) }, 'im.approvalterms': { 'Meta': {'object_name': 'ApprovalTerms'}, 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'location': ('django.db.models.fields.CharField', [], {'max_length': '255'}) }, 'im.astakosuser': { 'Meta': {'object_name': 'AstakosUser', '_ormbases': ['auth.User']}, 'accepted_email': ('django.db.models.fields.EmailField', [], {'default': 'None', 'max_length': '75', 'null': 'True', 'blank': 'True'}), 'accepted_policy': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255', 'null': 'True', 'blank': 'True'}), 'activation_sent': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), 'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}), 'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'date_signed_terms': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), 'deactivated_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), 'deactivated_reason': ('django.db.models.fields.TextField', [], {'default': 'None', 'null': 'True'}), 'disturbed_quota': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), 'email_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'has_credits': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'has_signed_terms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'invitations': ('django.db.models.fields.IntegerField', [], {'default': '0'}), 'is_rejected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'is_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'level': ('django.db.models.fields.IntegerField', [], {'default': '4'}), 'moderated': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'moderated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}), 'moderated_data': ('django.db.models.fields.TextField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}), 'policy': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.AstakosUserQuota']", 'symmetrical': 'False'}), 'rejected_reason': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), 'updated': ('django.db.models.fields.DateTimeField', [], {}), 'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'}), 'uuid': ('django.db.models.fields.CharField', [], {'max_length': '255', 'unique': 'True', 'null': 'True'}), 'verification_code': ('django.db.models.fields.CharField', [], {'max_length': '255', 'unique': 'True', 'null': 'True'}), 'verified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) }, 'im.astakosuserauthprovider': { 'Meta': {'ordering': "('module', 'created')", 'unique_together': "(('identifier', 'module', 'user'),)", 'object_name': 'AstakosUserAuthProvider'}, 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'affiliation': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255', 'null': 'True', 'blank': 'True'}), 'auth_backend': ('django.db.models.fields.CharField', [], {'default': "'astakos'", 'max_length': '255'}), 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'info_data': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True', 'blank': 'True'}), 'module': ('django.db.models.fields.CharField', [], {'default': "'local'", 'max_length': '255'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'auth_providers'", 'to': "orm['im.AstakosUser']"}) }, 'im.astakosuserquota': { 'Meta': {'unique_together': "(('resource', 'user'),)", 'object_name': 'AstakosUserQuota'}, 'capacity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"}) }, 'im.authproviderpolicyprofile': { 'Meta': {'ordering': "['priority']", 'object_name': 'AuthProviderPolicyProfile'}, 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'authpolicy_profiles'", 'symmetrical': 'False', 'to': "orm['auth.Group']"}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'is_exclusive': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), 'policy_add': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}), 'policy_automoderate': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}), 'policy_create': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}), 'policy_limit': ('django.db.models.fields.IntegerField', [], {'default': 'None', 'null': 'True'}), 'policy_login': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}), 'policy_remove': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}), 'policy_required': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}), 'policy_switch': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}), 'priority': ('django.db.models.fields.IntegerField', [], {'default': '1'}), 'provider': ('django.db.models.fields.CharField', [], {'max_length': '255'}), 'users': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'authpolicy_profiles'", 'symmetrical': 'False', 'to': "orm['im.AstakosUser']"}) }, 'im.chain': { 'Meta': {'object_name': 'Chain'}, 'chain': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) }, 'im.emailchange': { 'Meta': {'object_name': 'EmailChange'}, 'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40', 'db_index': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'new_email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}), 'requested_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'emailchanges'", 'unique': 'True', 'to': "orm['im.AstakosUser']"}) }, 'im.invitation': { 'Meta': {'object_name': 'Invitation'}, 'code': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}), 'consumed': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'inviter': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'invitations_sent'", 'null': 'True', 'to': "orm['im.AstakosUser']"}), 'is_consumed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'realname': ('django.db.models.fields.CharField', [], {'max_length': '255'}), 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}) }, 'im.pendingthirdpartyuser': { 'Meta': {'unique_together': "(('provider', 'third_party_identifier'),)", 'object_name': 'PendingThirdPartyUser'}, 'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'info': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True', 'blank': 'True'}), 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}), 'provider': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), 'third_party_identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'token': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) }, 'im.project': { 'Meta': {'object_name': 'Project'}, 'application': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'project'", 'unique': 'True', 'to': "orm['im.ProjectApplication']"}), 'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'deactivation_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'deactivation_reason': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}), 'id': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'chained_project'", 'unique': 'True', 'primary_key': 'True', 'db_column': "'id'", 'to': "orm['im.Chain']"}), 'last_approval_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'members': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.AstakosUser']", 'through': "orm['im.ProjectMembership']", 'symmetrical': 'False'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '80', 'unique': 'True', 'null': 'True', 'db_index': 'True'}), 'state': ('django.db.models.fields.IntegerField', [], {'default': '1', 'db_index': 'True'}) }, 'im.projectapplication': { 'Meta': {'unique_together': "(('chain', 'id'),)", 'object_name': 'ProjectApplication'}, 'applicant': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'projects_applied'", 'to': "orm['im.AstakosUser']"}), 'chain': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'chained_apps'", 'db_column': "'chain'", 'to': "orm['im.Chain']"}), 'comments': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), 'end_date': ('django.db.models.fields.DateTimeField', [], {}), 'homepage': ('django.db.models.fields.URLField', [], {'max_length': '255', 'null': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'issue_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'limit_on_members_number': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}), 'member_join_policy': ('django.db.models.fields.IntegerField', [], {}), 'member_leave_policy': ('django.db.models.fields.IntegerField', [], {}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '80'}), 'owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'projects_owned'", 'to': "orm['im.AstakosUser']"}), 'precursor_application': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.ProjectApplication']", 'null': 'True', 'blank': 'True'}), 'resource_grants': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.ProjectResourceGrant']", 'blank': 'True'}), 'response': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), 'response_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), 'start_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), 'state': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}) }, 'im.projectmembership': { 'Meta': {'unique_together': "(('person', 'project'),)", 'object_name': 'ProjectMembership'}, 'acceptance_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'db_index': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'leave_request_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"}), 'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Project']"}), 'request_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'state': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}) }, 'im.projectmembershiphistory': { 'Meta': {'object_name': 'ProjectMembershipHistory'}, 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'person': ('django.db.models.fields.BigIntegerField', [], {}), 'project': ('django.db.models.fields.BigIntegerField', [], {}), 'reason': ('django.db.models.fields.IntegerField', [], {}), 'serial': ('django.db.models.fields.BigIntegerField', [], {}) }, 'im.projectresourcegrant': { 'Meta': {'unique_together': "(('resource', 'project_application'),)", 'object_name': 'ProjectResourceGrant'}, 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'member_capacity': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}), 'project_application': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.ProjectApplication']", 'null': 'True'}), 'project_capacity': ('snf_django.lib.db.fields.IntDecimalField', [], {'null': 'True', 'max_digits': '38', 'decimal_places': '0'}), 'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"}) }, 'im.resource': { 'Meta': {'object_name': 'Resource'}, 'allow_in_projects': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'desc': ('django.db.models.fields.TextField', [], {'null': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), 'service': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Service']"}), 'unit': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}), 'uplimit': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}) }, 'im.serial': { 'Meta': {'object_name': 'Serial'}, 'serial': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) }, 'im.service': { 'Meta': {'object_name': 'Service'}, 'api_url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}), 'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}), 'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}), 'url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}) }, 'im.sessioncatalog': { 'Meta': {'object_name': 'SessionCatalog'}, 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sessions'", 'null': 'True', 'to': "orm['im.AstakosUser']"}) }, 'im.usersetting': { 'Meta': {'unique_together': "(('user', 'setting'),)", 'object_name': 'UserSetting'}, 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'setting': ('django.db.models.fields.CharField', [], {'max_length': '255'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"}), 'value': ('django.db.models.fields.IntegerField', [], {}) } } complete_apps = ['im']
gpl-3.0
[ 3, 2644, 26, 2774, 13, 24, 199, 646, 2197, 199, 504, 12919, 14, 697, 492, 1592, 199, 504, 12919, 14, 86, 18, 492, 24765, 199, 504, 1639, 14, 697, 492, 1709, 199, 199, 533, 12090, 8, 24822, 304, 339, 347, 17465, 8, 277, 12, 9813, 304, 2728, 327, 15920, 901, 283, 33, 270, 1151, 736, 1899, 14, 3780, 7, 267, 1592, 14, 1807, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 3780, 358, 398, 327, 15920, 901, 283, 33, 270, 1151, 736, 1899, 14, 11470, 63, 7522, 63, 5364, 7, 267, 1592, 14, 1807, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 11470, 63, 7522, 63, 5364, 358, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 271, 18218, 63, 5764, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 271, 18218, 63, 5764, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 6254, 7533, 885, 29, 403, 12, 2973, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 271, 18218, 63, 292, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 271, 18218, 63, 292, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 7533, 2307, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 16257, 63, 600, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 16257, 63, 600, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 7533, 988, 63, 1267, 29, 2299, 12, 3747, 29, 549, 12, 2973, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 12949, 63, 292, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 12949, 63, 292, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 7533, 2307, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 374, 63, 24054, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 374, 63, 24054, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 7533, 885, 29, 797, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 24054, 63, 5764, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 24054, 63, 5764, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 6254, 7533, 2307, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 632, 12601, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 632, 12601, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 7533, 885, 29, 797, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 632, 12601, 63, 292, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 632, 12601, 63, 292, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 7533, 885, 29, 403, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 632, 12601, 63, 576, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 632, 12601, 63, 576, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 6254, 7533, 885, 29, 403, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 16121, 63, 3185, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 16121, 63, 3185, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 7533, 885, 29, 403, 12, 1390, 63, 1267, 29, 2299, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 16121, 63, 2123, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 16121, 63, 2123, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 16577, 7533, 885, 29, 403, 12, 1390, 63, 1267, 29, 2194, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 2378, 347, 8552, 8, 277, 12, 9813, 304, 2728, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 3780, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 3780, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 7533, 988, 63, 1267, 29, 2299, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 11470, 63, 7522, 63, 5364, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 11470, 63, 7522, 63, 5364, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 7533, 988, 63, 1267, 29, 2299, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 15920, 901, 283, 33, 270, 1151, 736, 1899, 14, 271, 18218, 63, 5764, 7, 267, 1592, 14, 1807, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 271, 18218, 63, 5764, 358, 398, 327, 15920, 901, 283, 33, 270, 1151, 736, 1899, 14, 271, 18218, 63, 292, 7 ]
[ 2644, 26, 2774, 13, 24, 199, 646, 2197, 199, 504, 12919, 14, 697, 492, 1592, 199, 504, 12919, 14, 86, 18, 492, 24765, 199, 504, 1639, 14, 697, 492, 1709, 199, 199, 533, 12090, 8, 24822, 304, 339, 347, 17465, 8, 277, 12, 9813, 304, 2728, 327, 15920, 901, 283, 33, 270, 1151, 736, 1899, 14, 3780, 7, 267, 1592, 14, 1807, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 3780, 358, 398, 327, 15920, 901, 283, 33, 270, 1151, 736, 1899, 14, 11470, 63, 7522, 63, 5364, 7, 267, 1592, 14, 1807, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 11470, 63, 7522, 63, 5364, 358, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 271, 18218, 63, 5764, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 271, 18218, 63, 5764, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 6254, 7533, 885, 29, 403, 12, 2973, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 271, 18218, 63, 292, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 271, 18218, 63, 292, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 7533, 2307, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 16257, 63, 600, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 16257, 63, 600, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 7533, 988, 63, 1267, 29, 2299, 12, 3747, 29, 549, 12, 2973, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 12949, 63, 292, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 12949, 63, 292, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 7533, 2307, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 374, 63, 24054, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 374, 63, 24054, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 7533, 885, 29, 797, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 24054, 63, 5764, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 24054, 63, 5764, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 6254, 7533, 2307, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 632, 12601, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 632, 12601, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 7533, 885, 29, 797, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 632, 12601, 63, 292, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 632, 12601, 63, 292, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 7533, 885, 29, 403, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 632, 12601, 63, 576, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 632, 12601, 63, 576, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 6254, 7533, 885, 29, 403, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 16121, 63, 3185, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 16121, 63, 3185, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 7533, 885, 29, 403, 12, 1390, 63, 1267, 29, 2299, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 16121, 63, 2123, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 16121, 63, 2123, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 16577, 7533, 885, 29, 403, 12, 1390, 63, 1267, 29, 2194, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 2378, 347, 8552, 8, 277, 12, 9813, 304, 2728, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 3780, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 3780, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 7533, 988, 63, 1267, 29, 2299, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 12934, 901, 283, 33, 270, 1151, 736, 1899, 14, 11470, 63, 7522, 63, 5364, 7, 267, 1592, 14, 525, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 11470, 63, 7522, 63, 5364, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 7533, 988, 63, 1267, 29, 2299, 12, 2973, 29, 549, 12, 4596, 29, 549, 395, 4215, 63, 885, 29, 797, 9, 398, 327, 15920, 901, 283, 33, 270, 1151, 736, 1899, 14, 271, 18218, 63, 5764, 7, 267, 1592, 14, 1807, 63, 2301, 360, 1017, 63, 1810, 1151, 736, 751, 297, 283, 271, 18218, 63, 5764, 358, 398, 327, 15920, 901, 283, 33, 270, 1151, 736, 1899, 14, 271, 18218, 63, 292, 7, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
themagpimag/magpi-api
flaskstuff/werkzeug/testsuite/__init__.py
76
4086
# -*- coding: utf-8 -*- """ werkzeug.testsuite ~~~~~~~~~~~~~~~~~~ Contains all test Werkzeug tests. :copyright: (c) 2011 by Armin Ronacher. :license: BSD, see LICENSE for more details. """ from __future__ import with_statement import unittest from werkzeug.utils import import_string, find_modules def iter_suites(package): """Yields all testsuites.""" for module in find_modules(package, include_packages=True): mod = import_string(module) if hasattr(mod, 'suite'): yield mod.suite() def find_all_tests(suite): """Yields all the tests and their names from a given suite.""" suites = [suite] while suites: s = suites.pop() try: suites.extend(s) except TypeError: yield s, '%s.%s.%s' % ( s.__class__.__module__, s.__class__.__name__, s._testMethodName ) class WerkzeugTestCase(unittest.TestCase): """Baseclass for all the tests that Werkzeug uses. Use these methods for testing instead of the camelcased ones in the baseclass for consistency. """ def setup(self): pass def teardown(self): pass def setUp(self): self.setup() def tearDown(self): unittest.TestCase.tearDown(self) self.teardown() def assert_equal(self, x, y): return self.assertEqual(x, y) def assert_not_equal(self, x, y): return self.assertNotEqual(x, y) def assert_raises(self, exc_type, callable=None, *args, **kwargs): catcher = _ExceptionCatcher(self, exc_type) if callable is None: return catcher with catcher: callable(*args, **kwargs) class _ExceptionCatcher(object): def __init__(self, test_case, exc_type): self.test_case = test_case self.exc_type = exc_type def __enter__(self): return self def __exit__(self, exc_type, exc_value, tb): exception_name = self.exc_type.__name__ if exc_type is None: self.test_case.fail('Expected exception of type %r' % exception_name) elif not issubclass(exc_type, self.exc_type): raise exc_type, exc_value, tb return True class BetterLoader(unittest.TestLoader): """A nicer loader that solves two problems. First of all we are setting up tests from different sources and we're doing this programmatically which breaks the default loading logic so this is required anyways. Secondly this loader has a nicer interpolation for test names than the default one so you can just do ``run-tests.py ViewTestCase`` and it will work. """ def getRootSuite(self): return suite() def loadTestsFromName(self, name, module=None): root = self.getRootSuite() if name == 'suite': return root all_tests = [] for testcase, testname in find_all_tests(root): if testname == name or \ testname.endswith('.' + name) or \ ('.' + name + '.') in testname or \ testname.startswith(name + '.'): all_tests.append(testcase) if not all_tests: raise LookupError('could not find test case for "%s"' % name) if len(all_tests) == 1: return all_tests[0] rv = unittest.TestSuite() for test in all_tests: rv.addTest(test) return rv def suite(): """A testsuite that has all the Flask tests. You can use this function to integrate the Flask tests into your own testsuite in case you want to test that monkeypatches to Flask do not break it. """ suite = unittest.TestSuite() for other_suite in iter_suites(__name__): suite.addTest(other_suite) return suite def main(): """Runs the testsuite as command line application.""" try: unittest.main(testLoader=BetterLoader(), defaultTest='suite') except Exception, e: print 'Error: %s' % e
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 10380, 14, 14239, 272, 18294, 1714, 339, 22493, 1006, 511, 22798, 2295, 14, 339, 520, 7307, 26, 334, 67, 9, 7760, 701, 1952, 827, 32472, 19728, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 1655, 2436, 14, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 543, 63, 6242, 199, 199, 646, 2882, 199, 504, 10380, 14, 1208, 492, 492, 63, 875, 12, 2342, 63, 3112, 421, 199, 318, 2740, 63, 27034, 8, 2491, 304, 272, 408, 22889, 83, 1006, 2295, 11650, 1041, 272, 367, 859, 315, 2342, 63, 3112, 8, 2491, 12, 2387, 63, 5154, 29, 549, 304, 267, 3413, 275, 492, 63, 875, 8, 578, 9, 267, 340, 2688, 8, 1494, 12, 283, 5768, 735, 288, 1995, 3413, 14, 5768, 342, 421, 199, 318, 2342, 63, 452, 63, 2219, 8, 5768, 304, 272, 408, 22889, 83, 1006, 314, 2295, 436, 3932, 1561, 687, 282, 1627, 5241, 1041, 272, 24203, 275, 359, 5768, 61, 272, 1830, 24203, 26, 267, 308, 275, 24203, 14, 1935, 342, 267, 862, 26, 288, 24203, 14, 2880, 8, 83, 9, 267, 871, 3146, 26, 288, 1995, 308, 12, 1543, 83, 4111, 83, 4111, 83, 7, 450, 334, 355, 308, 855, 533, 4914, 578, 3108, 355, 308, 855, 533, 4914, 354, 3108, 355, 308, 423, 25008, 985, 288, 776, 421, 199, 533, 22798, 1746, 8, 2796, 14, 1746, 304, 272, 408, 1563, 533, 367, 1006, 314, 2295, 626, 22798, 4440, 14, 221, 3645, 3520, 272, 3102, 367, 5343, 3140, 402, 314, 31129, 32738, 7869, 315, 314, 272, 1300, 533, 367, 17754, 14, 272, 408, 339, 347, 3272, 8, 277, 304, 267, 986, 339, 347, 17558, 8, 277, 304, 267, 986, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 2758, 342, 339, 347, 6766, 8, 277, 304, 267, 2882, 14, 1746, 14, 12336, 8, 277, 9, 267, 291, 14, 15236, 342, 339, 347, 702, 63, 1452, 8, 277, 12, 671, 12, 612, 304, 267, 372, 291, 14, 629, 8, 88, 12, 612, 9, 339, 347, 702, 63, 1397, 63, 1452, 8, 277, 12, 671, 12, 612, 304, 267, 372, 291, 14, 7418, 8, 88, 12, 612, 9, 339, 347, 702, 63, 3536, 8, 277, 12, 3178, 63, 466, 12, 4550, 29, 403, 12, 627, 589, 12, 1011, 958, 304, 267, 8579, 281, 275, 485, 1726, 26096, 281, 8, 277, 12, 3178, 63, 466, 9, 267, 340, 4550, 365, 488, 26, 288, 372, 8579, 281, 267, 543, 8579, 281, 26, 288, 4550, 2031, 589, 12, 1011, 958, 9, 421, 199, 533, 485, 1726, 26096, 281, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 511, 63, 2546, 12, 3178, 63, 466, 304, 267, 291, 14, 396, 63, 2546, 275, 511, 63, 2546, 267, 291, 14, 2804, 63, 466, 275, 3178, 63, 466, 339, 347, 636, 4200, 721, 277, 304, 267, 372, 291, 339, 347, 636, 2224, 721, 277, 12, 3178, 63, 466, 12, 3178, 63, 585, 12, 7070, 304, 267, 1919, 63, 354, 275, 291, 14, 2804, 63, 466, 855, 354, 363, 267, 340, 3178, 63, 466, 365, 488, 26, 288, 291, 14, 396, 63, 2546, 14, 1633, 360, 6964, 1919, 402, 730, 450, 82, 7, 450, 1816, 1919, 63, 354, 9, 267, 916, 440, 11602, 8, 2804, 63, 466, 12, 291, 14, 2804, 63, 466, 304, 288, 746, 3178, 63, 466, 12, 3178, 63, 585, 12, 7070, 267, 372, 715, 421, 199, 533, 31535, 351, 5455, 8, 2796, 14, 15824, 304, 272, 408, 33, 30023, 5077, 626, 8597, 2310, 2877, 8826, 14, 221, 7758, 402, 1006, 781, 787, 4260, 272, 1536, 2295, 687, 3365, 5274, 436, 781, 3984, 9689, 642, 2240, 17174, 272, 1314, 18277, 314, 849, 8697, 9661, 880, 642, 365, 1415, 1263, 2885, 14, 272, 16707, 590, 642, 5077, 965, 282, 30023, 14046, 367, 511, 1561, 2419, 314, 272, 849, 1373, 880, 1265, 883, 2951, 886, 1124, 1065, 13, 2219, 14, 647, 10935, 1746, 1040, 436, 652, 272, 911, 1736, 14, 272, 408, 339, 347, 664, 6405, 6207, 8, 277, 304, 267, 372, 5241, 342, 339, 347, 2248, 11519, 985, 8, 277, 12, 536, 12, 859, 29, 403, 304, 267, 1738, 275, 291, 14, 362, 6405, 6207, 342, 267, 340, 536, 508, 283, 5768, 356, 288, 372, 1738, 398, 1006, 63, 2219, 275, 942, 267, 367, 16228, 12, 511, 354, 315, 2342, 63, 452, 63, 2219, 8, 1231, 304, 288, 340, 511, 354, 508, 536, 503, 971, 2049, 511, 354, 14, 4130, 360, 3530, 435, 536, 9, 503, 971, 2049, 661, 3530, 435, 536, 435, 20093, 315, 511, 354, 503, 971, 2049, 511, 354, 14, 2460, 8, 354, 435, 1987, 735, 355, 1006, 63, 2219, 14, 740, 8, 10847, 9, 398, 340, 440, 1006, 63, 2219, 26, 288, 746, 19021, 360, 15153, 440, 2342, 511, 1930, 367, 2071, 83, 4507, 450, 536, 9, 398, 340, 822, 8, 452, 63, 2219, 9, 508, 413, 26, 288, 372, 1006, 63, 2219, 59, 16, 61, 267, 4336, 275, 2882, 14, 10591, 342, 267, 367, 511, 315, 1006, 63, 2219, 26, 288, 4336, 14, 15714, 8, 396, 9, 267, 372, 4336, 421, 199, 318, 5241, 837, 272, 408, 33, 2295, 2577, 626, 965, 1006, 314, 16704, 2295, 14, 221, 2047, 883, 675, 642, 272, 805, 370, 21494, 314, 16704, 2295, 1901, 2195, 5705, 2295, 2577, 272, 315, 1930, 1265, 2934, 370, 511, 626, 14198, 11350, 370, 16704, 886, 440, 272, 2059, 652, 14, 272, 408, 272, 5241, 275, 2882, 14, 10591, 342, 272, 367, 1163, 63, 5768, 315, 2740, 63, 27034, 3460, 354, 18580, 267, 5241, 14, 15714, 8, 1848, 63, 5768, 9, 272, 372, 5241, 421, 199, 318, 2446, 837, 272, 408, 16291, 314, 2295, 2577, 465, 1414, 1004, 4223, 1041, 272, 862, 26, 267, 2882, 14, 973, 8, 396, 5455, 29, 24472, 351, 5455, 1062, 849, 774, 534, 5768, 358, 272, 871, 2186, 12, 325, 26, 267, 870, 283, 547, 26, 450, 83, 7, 450, 325, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 10380, 14, 14239, 272, 18294, 1714, 339, 22493, 1006, 511, 22798, 2295, 14, 339, 520, 7307, 26, 334, 67, 9, 7760, 701, 1952, 827, 32472, 19728, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 1655, 2436, 14, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 543, 63, 6242, 199, 199, 646, 2882, 199, 504, 10380, 14, 1208, 492, 492, 63, 875, 12, 2342, 63, 3112, 421, 199, 318, 2740, 63, 27034, 8, 2491, 304, 272, 408, 22889, 83, 1006, 2295, 11650, 1041, 272, 367, 859, 315, 2342, 63, 3112, 8, 2491, 12, 2387, 63, 5154, 29, 549, 304, 267, 3413, 275, 492, 63, 875, 8, 578, 9, 267, 340, 2688, 8, 1494, 12, 283, 5768, 735, 288, 1995, 3413, 14, 5768, 342, 421, 199, 318, 2342, 63, 452, 63, 2219, 8, 5768, 304, 272, 408, 22889, 83, 1006, 314, 2295, 436, 3932, 1561, 687, 282, 1627, 5241, 1041, 272, 24203, 275, 359, 5768, 61, 272, 1830, 24203, 26, 267, 308, 275, 24203, 14, 1935, 342, 267, 862, 26, 288, 24203, 14, 2880, 8, 83, 9, 267, 871, 3146, 26, 288, 1995, 308, 12, 1543, 83, 4111, 83, 4111, 83, 7, 450, 334, 355, 308, 855, 533, 4914, 578, 3108, 355, 308, 855, 533, 4914, 354, 3108, 355, 308, 423, 25008, 985, 288, 776, 421, 199, 533, 22798, 1746, 8, 2796, 14, 1746, 304, 272, 408, 1563, 533, 367, 1006, 314, 2295, 626, 22798, 4440, 14, 221, 3645, 3520, 272, 3102, 367, 5343, 3140, 402, 314, 31129, 32738, 7869, 315, 314, 272, 1300, 533, 367, 17754, 14, 272, 408, 339, 347, 3272, 8, 277, 304, 267, 986, 339, 347, 17558, 8, 277, 304, 267, 986, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 2758, 342, 339, 347, 6766, 8, 277, 304, 267, 2882, 14, 1746, 14, 12336, 8, 277, 9, 267, 291, 14, 15236, 342, 339, 347, 702, 63, 1452, 8, 277, 12, 671, 12, 612, 304, 267, 372, 291, 14, 629, 8, 88, 12, 612, 9, 339, 347, 702, 63, 1397, 63, 1452, 8, 277, 12, 671, 12, 612, 304, 267, 372, 291, 14, 7418, 8, 88, 12, 612, 9, 339, 347, 702, 63, 3536, 8, 277, 12, 3178, 63, 466, 12, 4550, 29, 403, 12, 627, 589, 12, 1011, 958, 304, 267, 8579, 281, 275, 485, 1726, 26096, 281, 8, 277, 12, 3178, 63, 466, 9, 267, 340, 4550, 365, 488, 26, 288, 372, 8579, 281, 267, 543, 8579, 281, 26, 288, 4550, 2031, 589, 12, 1011, 958, 9, 421, 199, 533, 485, 1726, 26096, 281, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 511, 63, 2546, 12, 3178, 63, 466, 304, 267, 291, 14, 396, 63, 2546, 275, 511, 63, 2546, 267, 291, 14, 2804, 63, 466, 275, 3178, 63, 466, 339, 347, 636, 4200, 721, 277, 304, 267, 372, 291, 339, 347, 636, 2224, 721, 277, 12, 3178, 63, 466, 12, 3178, 63, 585, 12, 7070, 304, 267, 1919, 63, 354, 275, 291, 14, 2804, 63, 466, 855, 354, 363, 267, 340, 3178, 63, 466, 365, 488, 26, 288, 291, 14, 396, 63, 2546, 14, 1633, 360, 6964, 1919, 402, 730, 450, 82, 7, 450, 1816, 1919, 63, 354, 9, 267, 916, 440, 11602, 8, 2804, 63, 466, 12, 291, 14, 2804, 63, 466, 304, 288, 746, 3178, 63, 466, 12, 3178, 63, 585, 12, 7070, 267, 372, 715, 421, 199, 533, 31535, 351, 5455, 8, 2796, 14, 15824, 304, 272, 408, 33, 30023, 5077, 626, 8597, 2310, 2877, 8826, 14, 221, 7758, 402, 1006, 781, 787, 4260, 272, 1536, 2295, 687, 3365, 5274, 436, 781, 3984, 9689, 642, 2240, 17174, 272, 1314, 18277, 314, 849, 8697, 9661, 880, 642, 365, 1415, 1263, 2885, 14, 272, 16707, 590, 642, 5077, 965, 282, 30023, 14046, 367, 511, 1561, 2419, 314, 272, 849, 1373, 880, 1265, 883, 2951, 886, 1124, 1065, 13, 2219, 14, 647, 10935, 1746, 1040, 436, 652, 272, 911, 1736, 14, 272, 408, 339, 347, 664, 6405, 6207, 8, 277, 304, 267, 372, 5241, 342, 339, 347, 2248, 11519, 985, 8, 277, 12, 536, 12, 859, 29, 403, 304, 267, 1738, 275, 291, 14, 362, 6405, 6207, 342, 267, 340, 536, 508, 283, 5768, 356, 288, 372, 1738, 398, 1006, 63, 2219, 275, 942, 267, 367, 16228, 12, 511, 354, 315, 2342, 63, 452, 63, 2219, 8, 1231, 304, 288, 340, 511, 354, 508, 536, 503, 971, 2049, 511, 354, 14, 4130, 360, 3530, 435, 536, 9, 503, 971, 2049, 661, 3530, 435, 536, 435, 20093, 315, 511, 354, 503, 971, 2049, 511, 354, 14, 2460, 8, 354, 435, 1987, 735, 355, 1006, 63, 2219, 14, 740, 8, 10847, 9, 398, 340, 440, 1006, 63, 2219, 26, 288, 746, 19021, 360, 15153, 440, 2342, 511, 1930, 367, 2071, 83, 4507, 450, 536, 9, 398, 340, 822, 8, 452, 63, 2219, 9, 508, 413, 26, 288, 372, 1006, 63, 2219, 59, 16, 61, 267, 4336, 275, 2882, 14, 10591, 342, 267, 367, 511, 315, 1006, 63, 2219, 26, 288, 4336, 14, 15714, 8, 396, 9, 267, 372, 4336, 421, 199, 318, 5241, 837, 272, 408, 33, 2295, 2577, 626, 965, 1006, 314, 16704, 2295, 14, 221, 2047, 883, 675, 642, 272, 805, 370, 21494, 314, 16704, 2295, 1901, 2195, 5705, 2295, 2577, 272, 315, 1930, 1265, 2934, 370, 511, 626, 14198, 11350, 370, 16704, 886, 440, 272, 2059, 652, 14, 272, 408, 272, 5241, 275, 2882, 14, 10591, 342, 272, 367, 1163, 63, 5768, 315, 2740, 63, 27034, 3460, 354, 18580, 267, 5241, 14, 15714, 8, 1848, 63, 5768, 9, 272, 372, 5241, 421, 199, 318, 2446, 837, 272, 408, 16291, 314, 2295, 2577, 465, 1414, 1004, 4223, 1041, 272, 862, 26, 267, 2882, 14, 973, 8, 396, 5455, 29, 24472, 351, 5455, 1062, 849, 774, 534, 5768, 358, 272, 871, 2186, 12, 325, 26, 267, 870, 283, 547, 26, 450, 83, 7, 450, 325, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
jeasoft/odoo
addons/base_report_designer/plugin/openerp_report_designer/bin/script/ConvertFieldsToBraces.py
384
2324
######################################################################### # # Copyright (c) 2003-2004 Danny Brewer d29583@groovegarden.com # Copyright (C) 2004-2010 OpenERP SA (<http://openerp.com>). # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # See: http://www.gnu.org/licenses/lgpl.html # ############################################################################# import uno import unohelper import string import re from com.sun.star.task import XJobExecutor if __name__<>"package": from lib.gui import * from LoginTest import * database="test" uid = 3 class ConvertFieldsToBraces( unohelper.Base, XJobExecutor ): def __init__(self, ctx): self.ctx = ctx self.module = "openerp_report" self.version = "0.1" LoginTest() if not loginstatus and __name__=="package": exit(1) self.aReportSyntex=[] self.getFields() def getFields(self): desktop=getDesktop() doc = desktop.getCurrentComponent() oParEnum = doc.getTextFields().createEnumeration() while oParEnum.hasMoreElements(): oPar = oParEnum.nextElement() if oPar.supportsService("com.sun.star.text.TextField.DropDown"): oPar.getAnchor().Text.insertString(oPar.getAnchor(),oPar.Items[1],False) oPar.dispose() if __name__<>"package": ConvertFieldsToBraces(None) else: g_ImplementationHelper.addImplementation( ConvertFieldsToBraces, "org.openoffice.openerp.report.convertFB", ("com.sun.star.task.Job",),) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
agpl-3.0
[ 3949, 3, 199, 3, 199, 3, 221, 1898, 334, 67, 9, 13004, 13, 15431, 577, 1189, 89, 699, 264, 2135, 366, 1398, 16793, 32, 23260, 79, 432, 23909, 848, 14, 957, 199, 3, 221, 1898, 334, 35, 9, 8353, 13, 6542, 7653, 13950, 8642, 1014, 921, 11267, 14, 957, 10121, 199, 3, 199, 3, 221, 961, 3555, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 221, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 221, 844, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 199, 3, 221, 1015, 499, 14, 17, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 221, 961, 3555, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 221, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 221, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 221, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 221, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 221, 844, 3180, 543, 642, 3555, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 221, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 221, 11315, 13, 10067, 221, 8217, 199, 3, 199, 3, 221, 1666, 26, 221, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 9783, 1168, 14, 1360, 199, 3, 199, 31635, 199, 199, 646, 625, 79, 199, 646, 625, 79, 3676, 199, 646, 1059, 199, 646, 295, 199, 504, 2414, 14, 11846, 14, 7848, 14, 1765, 492, 1323, 6694, 16752, 199, 692, 636, 354, 363, 28, 4335, 2491, 582, 272, 687, 1973, 14, 5885, 492, 627, 272, 687, 16430, 774, 492, 627, 272, 3050, 628, 396, 2, 272, 1747, 275, 650, 199, 199, 533, 7905, 7304, 1378, 17171, 823, 8, 625, 79, 3676, 14, 1563, 12, 1323, 6694, 16752, 3461, 272, 347, 636, 826, 721, 277, 12, 4027, 304, 267, 291, 14, 3799, 258, 275, 4027, 267, 291, 14, 578, 221, 275, 298, 11267, 63, 3070, 2, 267, 291, 14, 1023, 275, 298, 16, 14, 17, 2, 267, 16430, 774, 342, 267, 340, 440, 4676, 1205, 436, 636, 354, 363, 11800, 2491, 582, 288, 4458, 8, 17, 9, 267, 291, 14, 65, 7457, 17746, 3858, 9811, 267, 291, 14, 362, 7304, 342, 339, 347, 664, 7304, 8, 277, 304, 267, 19763, 29, 362, 20436, 342, 267, 1382, 275, 19763, 14, 16662, 7004, 342, 398, 312, 1262, 5081, 275, 1382, 14, 362, 6254, 83, 1252, 981, 13425, 342, 267, 1830, 312, 1262, 5081, 14, 1989, 11053, 6255, 837, 288, 312, 1262, 275, 312, 1262, 5081, 14, 2184, 2162, 342, 288, 340, 312, 1262, 14, 9823, 3167, 480, 957, 14, 11846, 14, 7848, 14, 505, 14, 6254, 14, 11070, 3514, 2349, 355, 312, 1262, 14, 362, 23517, 1252, 1872, 14, 3176, 1558, 8, 79, 1262, 14, 362, 23517, 1062, 79, 1262, 14, 7412, 59, 17, 467, 797, 9, 355, 312, 1262, 14, 29842, 342, 199, 199, 692, 636, 354, 363, 28, 4335, 2491, 582, 272, 7905, 7304, 1378, 17171, 823, 8, 403, 9, 199, 2836, 26, 272, 486, 63, 7921, 4433, 14, 525, 7921, 8, 7905, 7304, 1378, 17171, 823, 12, 298, 1308, 14, 1490, 18812, 14, 11267, 14, 3070, 14, 3916, 8223, 401, 1689, 957, 14, 11846, 14, 7848, 14, 1765, 14, 6694, 401, 16945, 421, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 3, 199, 3, 199, 3, 221, 1898, 334, 67, 9, 13004, 13, 15431, 577, 1189, 89, 699, 264, 2135, 366, 1398, 16793, 32, 23260, 79, 432, 23909, 848, 14, 957, 199, 3, 221, 1898, 334, 35, 9, 8353, 13, 6542, 7653, 13950, 8642, 1014, 921, 11267, 14, 957, 10121, 199, 3, 199, 3, 221, 961, 3555, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 221, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 221, 844, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 199, 3, 221, 1015, 499, 14, 17, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 221, 961, 3555, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 221, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 221, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 221, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 221, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 221, 844, 3180, 543, 642, 3555, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 221, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 221, 11315, 13, 10067, 221, 8217, 199, 3, 199, 3, 221, 1666, 26, 221, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 9783, 1168, 14, 1360, 199, 3, 199, 31635, 199, 199, 646, 625, 79, 199, 646, 625, 79, 3676, 199, 646, 1059, 199, 646, 295, 199, 504, 2414, 14, 11846, 14, 7848, 14, 1765, 492, 1323, 6694, 16752, 199, 692, 636, 354, 363, 28, 4335, 2491, 582, 272, 687, 1973, 14, 5885, 492, 627, 272, 687, 16430, 774, 492, 627, 272, 3050, 628, 396, 2, 272, 1747, 275, 650, 199, 199, 533, 7905, 7304, 1378, 17171, 823, 8, 625, 79, 3676, 14, 1563, 12, 1323, 6694, 16752, 3461, 272, 347, 636, 826, 721, 277, 12, 4027, 304, 267, 291, 14, 3799, 258, 275, 4027, 267, 291, 14, 578, 221, 275, 298, 11267, 63, 3070, 2, 267, 291, 14, 1023, 275, 298, 16, 14, 17, 2, 267, 16430, 774, 342, 267, 340, 440, 4676, 1205, 436, 636, 354, 363, 11800, 2491, 582, 288, 4458, 8, 17, 9, 267, 291, 14, 65, 7457, 17746, 3858, 9811, 267, 291, 14, 362, 7304, 342, 339, 347, 664, 7304, 8, 277, 304, 267, 19763, 29, 362, 20436, 342, 267, 1382, 275, 19763, 14, 16662, 7004, 342, 398, 312, 1262, 5081, 275, 1382, 14, 362, 6254, 83, 1252, 981, 13425, 342, 267, 1830, 312, 1262, 5081, 14, 1989, 11053, 6255, 837, 288, 312, 1262, 275, 312, 1262, 5081, 14, 2184, 2162, 342, 288, 340, 312, 1262, 14, 9823, 3167, 480, 957, 14, 11846, 14, 7848, 14, 505, 14, 6254, 14, 11070, 3514, 2349, 355, 312, 1262, 14, 362, 23517, 1252, 1872, 14, 3176, 1558, 8, 79, 1262, 14, 362, 23517, 1062, 79, 1262, 14, 7412, 59, 17, 467, 797, 9, 355, 312, 1262, 14, 29842, 342, 199, 199, 692, 636, 354, 363, 28, 4335, 2491, 582, 272, 7905, 7304, 1378, 17171, 823, 8, 403, 9, 199, 2836, 26, 272, 486, 63, 7921, 4433, 14, 525, 7921, 8, 7905, 7304, 1378, 17171, 823, 12, 298, 1308, 14, 1490, 18812, 14, 11267, 14, 3070, 14, 3916, 8223, 401, 1689, 957, 14, 11846, 14, 7848, 14, 1765, 14, 6694, 401, 16945, 421, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
JuezUN/INGInious
inginious/frontend/plugins/analytics/__init__.py
1
1875
import os from inginious.frontend.plugins.utils import create_static_resource_page from .api.stacked_bar_plot_api import StackedBarPlotAPI from .pages.analytics import AnalyticsPage from .api.analytics import AnalyticsAPI from .api.calendar_plot_api import CalendarPlotAPI from .api.time_series_plot_api import TimeSeriesPlotAPI from .api.box_plot_api import BoxPlotAPI from .api.radar_plot_api import RadarPlotAPI from .utils import set_use_minified from .services_collection_manager import ServicesCollectionManagerSingleton from .analytics_collection_manager import AnalyticsCollectionManagerSingleton _static_folder_path = os.path.join(os.path.dirname(__file__), "static") def init(plugin_manager, course_factory, client, plugin_config): plugin_manager.add_page(r'/analytics/static/(.*)', create_static_resource_page(_static_folder_path)) plugin_manager.add_page('/analytics/', AnalyticsPage) plugin_manager.add_page('/api/analytics/', AnalyticsAPI) plugin_manager.add_page('/api/calendar_plot_analytics/', CalendarPlotAPI) plugin_manager.add_page('/api/time_series_plot_analytics/', TimeSeriesPlotAPI) plugin_manager.add_page('/api/box_plot_analytics/', BoxPlotAPI) plugin_manager.add_page('/api/radar_plot_analytics/', RadarPlotAPI) plugin_manager.add_page('/api/stacked_bar_plot_analytics/', StackedBarPlotAPI) set_use_minified(plugin_config.get("use_minified", True)) def analytics_hook(): if plugin_manager.get_user_manager().user_is_superadmin(): return _(""""<li><a href='/analytics/' class='navbar-link'> <i class='fa fa-bar-chart fa-fw'></i> Analytics</a></li>""") plugin_manager.add_hook("superadmin_options", lambda: analytics_hook()) ServicesCollectionManagerSingleton(plugin_manager.get_database()) AnalyticsCollectionManagerSingleton(plugin_manager.get_database())
agpl-3.0
[ 646, 747, 199, 199, 504, 315, 903, 17326, 14, 18062, 14, 5265, 14, 1208, 492, 1218, 63, 1986, 63, 1927, 63, 1606, 199, 504, 1275, 1246, 14, 27266, 63, 1700, 63, 2798, 63, 1246, 492, 13894, 379, 5281, 10711, 3735, 199, 504, 1275, 5856, 14, 20211, 492, 14279, 7769, 3276, 199, 504, 1275, 1246, 14, 20211, 492, 14279, 7769, 3735, 199, 504, 1275, 1246, 14, 8183, 63, 2798, 63, 1246, 492, 27779, 10711, 3735, 199, 504, 1275, 1246, 14, 521, 63, 5602, 63, 2798, 63, 1246, 492, 4703, 9641, 10711, 3735, 199, 504, 1275, 1246, 14, 1977, 63, 2798, 63, 1246, 492, 20783, 10711, 3735, 199, 504, 1275, 1246, 14, 345, 4460, 63, 2798, 63, 1246, 492, 820, 350, 285, 10711, 3735, 199, 504, 1275, 1208, 492, 663, 63, 1180, 63, 827, 4541, 199, 504, 1275, 5950, 63, 3627, 63, 2609, 492, 21813, 7768, 2988, 28456, 199, 504, 1275, 20211, 63, 3627, 63, 2609, 492, 14279, 7769, 7768, 2988, 28456, 199, 199, 63, 1986, 63, 3741, 63, 515, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 298, 1986, 531, 421, 199, 318, 4205, 8, 2718, 63, 2609, 12, 2518, 63, 3702, 12, 1890, 12, 3589, 63, 888, 304, 272, 3589, 63, 2609, 14, 525, 63, 1606, 8, 82, 9807, 20211, 15, 1986, 7985, 2795, 3196, 1218, 63, 1986, 63, 1927, 63, 1606, 1547, 1986, 63, 3741, 63, 515, 430, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 20211, 3678, 14279, 7769, 3276, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 20211, 3678, 14279, 7769, 3735, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 8183, 63, 2798, 63, 20211, 3678, 27779, 10711, 3735, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 521, 63, 5602, 63, 2798, 63, 20211, 3678, 4703, 9641, 10711, 3735, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 1977, 63, 2798, 63, 20211, 3678, 20783, 10711, 3735, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 345, 4460, 63, 2798, 63, 20211, 3678, 820, 350, 285, 10711, 3735, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 27266, 63, 1700, 63, 2798, 63, 20211, 3678, 13894, 379, 5281, 10711, 3735, 9, 339, 663, 63, 1180, 63, 827, 4541, 8, 2718, 63, 888, 14, 362, 480, 1180, 63, 827, 4541, 401, 715, 430, 339, 347, 30159, 63, 3664, 837, 267, 340, 3589, 63, 2609, 14, 362, 63, 751, 63, 2609, 1252, 751, 63, 374, 63, 4792, 2113, 837, 288, 372, 485, 11986, 341, 28, 317, 2535, 65, 4369, 8805, 20211, 4805, 1021, 534, 10927, 1700, 13, 1073, 8423, 288, 665, 73, 1021, 534, 667, 1433, 13, 1700, 13, 9019, 1433, 13, 8835, 7, 2957, 73, 30, 14279, 7769, 1108, 65, 2957, 317, 15366, 339, 3589, 63, 2609, 14, 525, 63, 3664, 480, 4792, 2113, 63, 1419, 401, 2400, 26, 30159, 63, 3664, 1012, 339, 21813, 7768, 2988, 28456, 8, 2718, 63, 2609, 14, 362, 63, 4659, 1012, 272, 14279, 7769, 7768, 2988, 28456, 8, 2718, 63, 2609, 14, 362, 63, 4659, 1012, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 747, 199, 199, 504, 315, 903, 17326, 14, 18062, 14, 5265, 14, 1208, 492, 1218, 63, 1986, 63, 1927, 63, 1606, 199, 504, 1275, 1246, 14, 27266, 63, 1700, 63, 2798, 63, 1246, 492, 13894, 379, 5281, 10711, 3735, 199, 504, 1275, 5856, 14, 20211, 492, 14279, 7769, 3276, 199, 504, 1275, 1246, 14, 20211, 492, 14279, 7769, 3735, 199, 504, 1275, 1246, 14, 8183, 63, 2798, 63, 1246, 492, 27779, 10711, 3735, 199, 504, 1275, 1246, 14, 521, 63, 5602, 63, 2798, 63, 1246, 492, 4703, 9641, 10711, 3735, 199, 504, 1275, 1246, 14, 1977, 63, 2798, 63, 1246, 492, 20783, 10711, 3735, 199, 504, 1275, 1246, 14, 345, 4460, 63, 2798, 63, 1246, 492, 820, 350, 285, 10711, 3735, 199, 504, 1275, 1208, 492, 663, 63, 1180, 63, 827, 4541, 199, 504, 1275, 5950, 63, 3627, 63, 2609, 492, 21813, 7768, 2988, 28456, 199, 504, 1275, 20211, 63, 3627, 63, 2609, 492, 14279, 7769, 7768, 2988, 28456, 199, 199, 63, 1986, 63, 3741, 63, 515, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 298, 1986, 531, 421, 199, 318, 4205, 8, 2718, 63, 2609, 12, 2518, 63, 3702, 12, 1890, 12, 3589, 63, 888, 304, 272, 3589, 63, 2609, 14, 525, 63, 1606, 8, 82, 9807, 20211, 15, 1986, 7985, 2795, 3196, 1218, 63, 1986, 63, 1927, 63, 1606, 1547, 1986, 63, 3741, 63, 515, 430, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 20211, 3678, 14279, 7769, 3276, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 20211, 3678, 14279, 7769, 3735, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 8183, 63, 2798, 63, 20211, 3678, 27779, 10711, 3735, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 521, 63, 5602, 63, 2798, 63, 20211, 3678, 4703, 9641, 10711, 3735, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 1977, 63, 2798, 63, 20211, 3678, 20783, 10711, 3735, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 345, 4460, 63, 2798, 63, 20211, 3678, 820, 350, 285, 10711, 3735, 9, 272, 3589, 63, 2609, 14, 525, 63, 1606, 2336, 1246, 15, 27266, 63, 1700, 63, 2798, 63, 20211, 3678, 13894, 379, 5281, 10711, 3735, 9, 339, 663, 63, 1180, 63, 827, 4541, 8, 2718, 63, 888, 14, 362, 480, 1180, 63, 827, 4541, 401, 715, 430, 339, 347, 30159, 63, 3664, 837, 267, 340, 3589, 63, 2609, 14, 362, 63, 751, 63, 2609, 1252, 751, 63, 374, 63, 4792, 2113, 837, 288, 372, 485, 11986, 341, 28, 317, 2535, 65, 4369, 8805, 20211, 4805, 1021, 534, 10927, 1700, 13, 1073, 8423, 288, 665, 73, 1021, 534, 667, 1433, 13, 1700, 13, 9019, 1433, 13, 8835, 7, 2957, 73, 30, 14279, 7769, 1108, 65, 2957, 317, 15366, 339, 3589, 63, 2609, 14, 525, 63, 3664, 480, 4792, 2113, 63, 1419, 401, 2400, 26, 30159, 63, 3664, 1012, 339, 21813, 7768, 2988, 28456, 8, 2718, 63, 2609, 14, 362, 63, 4659, 1012, 272, 14279, 7769, 7768, 2988, 28456, 8, 2718, 63, 2609, 14, 362, 63, 4659, 1012, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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0, 0, 0, 0, 0, 0, 0, 0 ]
sabi0/intellij-community
python/lib/Lib/trace.py
90
29112
#!/usr/bin/env python # portions copyright 2001, Autonomous Zones Industries, Inc., all rights... # err... reserved and offered to the public under the terms of the # Python 2.2 license. # Author: Zooko O'Whielacronx # http://zooko.com/ # mailto:zooko@zooko.com # # Copyright 2000, Mojam Media, Inc., all rights reserved. # Author: Skip Montanaro # # Copyright 1999, Bioreason, Inc., all rights reserved. # Author: Andrew Dalke # # Copyright 1995-1997, Automatrix, Inc., all rights reserved. # Author: Skip Montanaro # # Copyright 1991-1995, Stichting Mathematisch Centrum, all rights reserved. # # # Permission to use, copy, modify, and distribute this Python software and # its associated documentation for any purpose without fee is hereby # granted, provided that the above copyright notice appears in all copies, # and that both that copyright notice and this permission notice appear in # supporting documentation, and that the name of neither Automatrix, # Bioreason or Mojam Media be used in advertising or publicity pertaining to # distribution of the software without specific, written prior permission. # """program/module to trace Python program or function execution Sample use, command line: trace.py -c -f counts --ignore-dir '$prefix' spam.py eggs trace.py -t --ignore-dir '$prefix' spam.py eggs trace.py --trackcalls spam.py eggs Sample use, programmatically import sys # create a Trace object, telling it what to ignore, and whether to # do tracing or line-counting or both. tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,], trace=0, count=1) # run the new command using the given tracer tracer.run('main()') # make a report, placing output in /tmp r = tracer.results() r.write_results(show_missing=True, coverdir="/tmp") """ import linecache import os import re import sys import threading import token import tokenize import types import gc try: import cPickle pickle = cPickle except ImportError: import pickle def usage(outfile): outfile.write("""Usage: %s [OPTIONS] <file> [ARGS] Meta-options: --help Display this help then exit. --version Output version information then exit. Otherwise, exactly one of the following three options must be given: -t, --trace Print each line to sys.stdout before it is executed. -c, --count Count the number of times each line is executed and write the counts to <module>.cover for each module executed, in the module's directory. See also `--coverdir', `--file', `--no-report' below. -l, --listfuncs Keep track of which functions are executed at least once and write the results to sys.stdout after the program exits. -T, --trackcalls Keep track of caller/called pairs and write the results to sys.stdout after the program exits. -r, --report Generate a report from a counts file; do not execute any code. `--file' must specify the results file to read, which must have been created in a previous run with `--count --file=FILE'. Modifiers: -f, --file=<file> File to accumulate counts over several runs. -R, --no-report Do not generate the coverage report files. Useful if you want to accumulate over several runs. -C, --coverdir=<dir> Directory where the report files. The coverage report for <package>.<module> is written to file <dir>/<package>/<module>.cover. -m, --missing Annotate executable lines that were not executed with '>>>>>> '. -s, --summary Write a brief summary on stdout for each file. (Can only be used with --count or --report.) Filters, may be repeated multiple times: --ignore-module=<mod> Ignore the given module and its submodules (if it is a package). --ignore-dir=<dir> Ignore files in the given directory (multiple directories can be joined by os.pathsep). """ % sys.argv[0]) PRAGMA_NOCOVER = "#pragma NO COVER" # Simple rx to find lines with no code. rx_blank = re.compile(r'^\s*(#.*)?$') class Ignore: def __init__(self, modules = None, dirs = None): self._mods = modules or [] self._dirs = dirs or [] self._dirs = map(os.path.normpath, self._dirs) self._ignore = { '<string>': 1 } def names(self, filename, modulename): if self._ignore.has_key(modulename): return self._ignore[modulename] # haven't seen this one before, so see if the module name is # on the ignore list. Need to take some care since ignoring # "cmp" musn't mean ignoring "cmpcache" but ignoring # "Spam" must also mean ignoring "Spam.Eggs". for mod in self._mods: if mod == modulename: # Identical names, so ignore self._ignore[modulename] = 1 return 1 # check if the module is a proper submodule of something on # the ignore list n = len(mod) # (will not overflow since if the first n characters are the # same and the name has not already occurred, then the size # of "name" is greater than that of "mod") if mod == modulename[:n] and modulename[n] == '.': self._ignore[modulename] = 1 return 1 # Now check that __file__ isn't in one of the directories if filename is None: # must be a built-in, so we must ignore self._ignore[modulename] = 1 return 1 # Ignore a file when it contains one of the ignorable paths for d in self._dirs: # The '+ os.sep' is to ensure that d is a parent directory, # as compared to cases like: # d = "/usr/local" # filename = "/usr/local.py" # or # d = "/usr/local.py" # filename = "/usr/local.py" if filename.startswith(d + os.sep): self._ignore[modulename] = 1 return 1 # Tried the different ways, so we don't ignore this module self._ignore[modulename] = 0 return 0 def modname(path): """Return a plausible module name for the patch.""" base = os.path.basename(path) filename, ext = os.path.splitext(base) return filename def fullmodname(path): """Return a plausible module name for the path.""" # If the file 'path' is part of a package, then the filename isn't # enough to uniquely identify it. Try to do the right thing by # looking in sys.path for the longest matching prefix. We'll # assume that the rest is the package name. comparepath = os.path.normcase(path) longest = "" for dir in sys.path: dir = os.path.normcase(dir) if comparepath.startswith(dir) and comparepath[len(dir)] == os.sep: if len(dir) > len(longest): longest = dir if longest: base = path[len(longest) + 1:] else: base = path base = base.replace(os.sep, ".") if os.altsep: base = base.replace(os.altsep, ".") filename, ext = os.path.splitext(base) return filename class CoverageResults: def __init__(self, counts=None, calledfuncs=None, infile=None, callers=None, outfile=None): self.counts = counts if self.counts is None: self.counts = {} self.counter = self.counts.copy() # map (filename, lineno) to count self.calledfuncs = calledfuncs if self.calledfuncs is None: self.calledfuncs = {} self.calledfuncs = self.calledfuncs.copy() self.callers = callers if self.callers is None: self.callers = {} self.callers = self.callers.copy() self.infile = infile self.outfile = outfile if self.infile: # Try to merge existing counts file. try: counts, calledfuncs, callers = \ pickle.load(open(self.infile, 'rb')) self.update(self.__class__(counts, calledfuncs, callers)) except (IOError, EOFError, ValueError), err: print >> sys.stderr, ("Skipping counts file %r: %s" % (self.infile, err)) def update(self, other): """Merge in the data from another CoverageResults""" counts = self.counts calledfuncs = self.calledfuncs callers = self.callers other_counts = other.counts other_calledfuncs = other.calledfuncs other_callers = other.callers for key in other_counts.keys(): counts[key] = counts.get(key, 0) + other_counts[key] for key in other_calledfuncs.keys(): calledfuncs[key] = 1 for key in other_callers.keys(): callers[key] = 1 def write_results(self, show_missing=True, summary=False, coverdir=None): """ @param coverdir """ if self.calledfuncs: print print "functions called:" calls = self.calledfuncs.keys() calls.sort() for filename, modulename, funcname in calls: print ("filename: %s, modulename: %s, funcname: %s" % (filename, modulename, funcname)) if self.callers: print print "calling relationships:" calls = self.callers.keys() calls.sort() lastfile = lastcfile = "" for ((pfile, pmod, pfunc), (cfile, cmod, cfunc)) in calls: if pfile != lastfile: print print "***", pfile, "***" lastfile = pfile lastcfile = "" if cfile != pfile and lastcfile != cfile: print " -->", cfile lastcfile = cfile print " %s.%s -> %s.%s" % (pmod, pfunc, cmod, cfunc) # turn the counts data ("(filename, lineno) = count") into something # accessible on a per-file basis per_file = {} for filename, lineno in self.counts.keys(): lines_hit = per_file[filename] = per_file.get(filename, {}) lines_hit[lineno] = self.counts[(filename, lineno)] # accumulate summary info, if needed sums = {} for filename, count in per_file.iteritems(): # skip some "files" we don't care about... if filename == "<string>": continue if filename.startswith("<doctest "): continue if filename.endswith((".pyc", ".pyo")): filename = filename[:-1] if coverdir is None: dir = os.path.dirname(os.path.abspath(filename)) modulename = modname(filename) else: dir = coverdir if not os.path.exists(dir): os.makedirs(dir) modulename = fullmodname(filename) # If desired, get a list of the line numbers which represent # executable content (returned as a dict for better lookup speed) if show_missing: lnotab = find_executable_linenos(filename) else: lnotab = {} source = linecache.getlines(filename) coverpath = os.path.join(dir, modulename + ".cover") n_hits, n_lines = self.write_results_file(coverpath, source, lnotab, count) if summary and n_lines: percent = int(100 * n_hits / n_lines) sums[modulename] = n_lines, percent, modulename, filename if summary and sums: mods = sums.keys() mods.sort() print "lines cov% module (path)" for m in mods: n_lines, percent, modulename, filename = sums[m] print "%5d %3d%% %s (%s)" % sums[m] if self.outfile: # try and store counts and module info into self.outfile try: pickle.dump((self.counts, self.calledfuncs, self.callers), open(self.outfile, 'wb'), 1) except IOError, err: print >> sys.stderr, "Can't save counts files because %s" % err def write_results_file(self, path, lines, lnotab, lines_hit): """Return a coverage results file in path.""" try: outfile = open(path, "w") except IOError, err: print >> sys.stderr, ("trace: Could not open %r for writing: %s" "- skipping" % (path, err)) return 0, 0 n_lines = 0 n_hits = 0 for i, line in enumerate(lines): lineno = i + 1 # do the blank/comment match to try to mark more lines # (help the reader find stuff that hasn't been covered) if lineno in lines_hit: outfile.write("%5d: " % lines_hit[lineno]) n_hits += 1 n_lines += 1 elif rx_blank.match(line): outfile.write(" ") else: # lines preceded by no marks weren't hit # Highlight them if so indicated, unless the line contains # #pragma: NO COVER if lineno in lnotab and not PRAGMA_NOCOVER in lines[i]: outfile.write(">>>>>> ") n_lines += 1 else: outfile.write(" ") outfile.write(lines[i].expandtabs(8)) outfile.close() return n_hits, n_lines def find_lines_from_code(code, strs): """Return dict where keys are lines in the line number table.""" linenos = {} line_increments = [ord(c) for c in code.co_lnotab[1::2]] table_length = len(line_increments) docstring = False lineno = code.co_firstlineno for li in line_increments: lineno += li if lineno not in strs: linenos[lineno] = 1 return linenos def find_lines(code, strs): """Return lineno dict for all code objects reachable from code.""" # get all of the lineno information from the code of this scope level linenos = find_lines_from_code(code, strs) # and check the constants for references to other code objects for c in code.co_consts: if isinstance(c, types.CodeType): # find another code object, so recurse into it linenos.update(find_lines(c, strs)) return linenos def find_strings(filename): """Return a dict of possible docstring positions. The dict maps line numbers to strings. There is an entry for line that contains only a string or a part of a triple-quoted string. """ d = {} # If the first token is a string, then it's the module docstring. # Add this special case so that the test in the loop passes. prev_ttype = token.INDENT f = open(filename) for ttype, tstr, start, end, line in tokenize.generate_tokens(f.readline): if ttype == token.STRING: if prev_ttype == token.INDENT: sline, scol = start eline, ecol = end for i in range(sline, eline + 1): d[i] = 1 prev_ttype = ttype f.close() return d def find_executable_linenos(filename): """Return dict where keys are line numbers in the line number table.""" try: prog = open(filename, "rU").read() except IOError, err: print >> sys.stderr, ("Not printing coverage data for %r: %s" % (filename, err)) return {} code = compile(prog, filename, "exec") strs = find_strings(filename) return find_lines(code, strs) class Trace: def __init__(self, count=1, trace=1, countfuncs=0, countcallers=0, ignoremods=(), ignoredirs=(), infile=None, outfile=None): """ @param count true iff it should count number of times each line is executed @param trace true iff it should print out each line that is being counted @param countfuncs true iff it should just output a list of (filename, modulename, funcname,) for functions that were called at least once; This overrides `count' and `trace' @param ignoremods a list of the names of modules to ignore @param ignoredirs a list of the names of directories to ignore all of the (recursive) contents of @param infile file from which to read stored counts to be added into the results @param outfile file in which to write the results """ self.infile = infile self.outfile = outfile self.ignore = Ignore(ignoremods, ignoredirs) self.counts = {} # keys are (filename, linenumber) self.blabbed = {} # for debugging self.pathtobasename = {} # for memoizing os.path.basename self.donothing = 0 self.trace = trace self._calledfuncs = {} self._callers = {} self._caller_cache = {} if countcallers: self.globaltrace = self.globaltrace_trackcallers elif countfuncs: self.globaltrace = self.globaltrace_countfuncs elif trace and count: self.globaltrace = self.globaltrace_lt self.localtrace = self.localtrace_trace_and_count elif trace: self.globaltrace = self.globaltrace_lt self.localtrace = self.localtrace_trace elif count: self.globaltrace = self.globaltrace_lt self.localtrace = self.localtrace_count else: # Ahem -- do nothing? Okay. self.donothing = 1 def run(self, cmd): import __main__ dict = __main__.__dict__ if not self.donothing: sys.settrace(self.globaltrace) threading.settrace(self.globaltrace) try: exec cmd in dict, dict finally: if not self.donothing: sys.settrace(None) threading.settrace(None) def runctx(self, cmd, globals=None, locals=None): if globals is None: globals = {} if locals is None: locals = {} if not self.donothing: sys.settrace(self.globaltrace) threading.settrace(self.globaltrace) try: exec cmd in globals, locals finally: if not self.donothing: sys.settrace(None) threading.settrace(None) def runfunc(self, func, *args, **kw): result = None if not self.donothing: sys.settrace(self.globaltrace) try: result = func(*args, **kw) finally: if not self.donothing: sys.settrace(None) return result def file_module_function_of(self, frame): code = frame.f_code filename = code.co_filename if filename: modulename = modname(filename) else: modulename = None funcname = code.co_name clsname = None if code in self._caller_cache: if self._caller_cache[code] is not None: clsname = self._caller_cache[code] else: self._caller_cache[code] = None ## use of gc.get_referrers() was suggested by Michael Hudson # all functions which refer to this code object funcs = [f for f in gc.get_referrers(code) if hasattr(f, "func_doc")] # require len(func) == 1 to avoid ambiguity caused by calls to # new.function(): "In the face of ambiguity, refuse the # temptation to guess." if len(funcs) == 1: dicts = [d for d in gc.get_referrers(funcs[0]) if isinstance(d, dict)] if len(dicts) == 1: classes = [c for c in gc.get_referrers(dicts[0]) if hasattr(c, "__bases__")] if len(classes) == 1: # ditto for new.classobj() clsname = str(classes[0]) # cache the result - assumption is that new.* is # not called later to disturb this relationship # _caller_cache could be flushed if functions in # the new module get called. self._caller_cache[code] = clsname if clsname is not None: # final hack - module name shows up in str(cls), but we've already # computed module name, so remove it clsname = clsname.split(".")[1:] clsname = ".".join(clsname) funcname = "%s.%s" % (clsname, funcname) return filename, modulename, funcname def globaltrace_trackcallers(self, frame, why, arg): """Handler for call events. Adds information about who called who to the self._callers dict. """ if why == 'call': # XXX Should do a better job of identifying methods this_func = self.file_module_function_of(frame) parent_func = self.file_module_function_of(frame.f_back) self._callers[(parent_func, this_func)] = 1 def globaltrace_countfuncs(self, frame, why, arg): """Handler for call events. Adds (filename, modulename, funcname) to the self._calledfuncs dict. """ if why == 'call': this_func = self.file_module_function_of(frame) self._calledfuncs[this_func] = 1 def globaltrace_lt(self, frame, why, arg): """Handler for call events. If the code block being entered is to be ignored, returns `None', else returns self.localtrace. """ if why == 'call': code = frame.f_code filename = frame.f_globals.get('__file__', None) if filename: # XXX modname() doesn't work right for packages, so # the ignore support won't work right for packages modulename = modname(filename) if modulename is not None: ignore_it = self.ignore.names(filename, modulename) if not ignore_it: if self.trace: print (" --- modulename: %s, funcname: %s" % (modulename, code.co_name)) return self.localtrace else: return None def localtrace_trace_and_count(self, frame, why, arg): if why == "line": # record the file name and line number of every trace filename = frame.f_code.co_filename lineno = frame.f_lineno key = filename, lineno self.counts[key] = self.counts.get(key, 0) + 1 bname = os.path.basename(filename) print "%s(%d): %s" % (bname, lineno, linecache.getline(filename, lineno)), return self.localtrace def localtrace_trace(self, frame, why, arg): if why == "line": # record the file name and line number of every trace filename = frame.f_code.co_filename lineno = frame.f_lineno bname = os.path.basename(filename) print "%s(%d): %s" % (bname, lineno, linecache.getline(filename, lineno)), return self.localtrace def localtrace_count(self, frame, why, arg): if why == "line": filename = frame.f_code.co_filename lineno = frame.f_lineno key = filename, lineno self.counts[key] = self.counts.get(key, 0) + 1 return self.localtrace def results(self): return CoverageResults(self.counts, infile=self.infile, outfile=self.outfile, calledfuncs=self._calledfuncs, callers=self._callers) def _err_exit(msg): sys.stderr.write("%s: %s\n" % (sys.argv[0], msg)) sys.exit(1) def main(argv=None): import getopt if argv is None: argv = sys.argv try: opts, prog_argv = getopt.getopt(argv[1:], "tcrRf:d:msC:lT", ["help", "version", "trace", "count", "report", "no-report", "summary", "file=", "missing", "ignore-module=", "ignore-dir=", "coverdir=", "listfuncs", "trackcalls"]) except getopt.error, msg: sys.stderr.write("%s: %s\n" % (sys.argv[0], msg)) sys.stderr.write("Try `%s --help' for more information\n" % sys.argv[0]) sys.exit(1) trace = 0 count = 0 report = 0 no_report = 0 counts_file = None missing = 0 ignore_modules = [] ignore_dirs = [] coverdir = None summary = 0 listfuncs = False countcallers = False for opt, val in opts: if opt == "--help": usage(sys.stdout) sys.exit(0) if opt == "--version": sys.stdout.write("trace 2.0\n") sys.exit(0) if opt == "-T" or opt == "--trackcalls": countcallers = True continue if opt == "-l" or opt == "--listfuncs": listfuncs = True continue if opt == "-t" or opt == "--trace": trace = 1 continue if opt == "-c" or opt == "--count": count = 1 continue if opt == "-r" or opt == "--report": report = 1 continue if opt == "-R" or opt == "--no-report": no_report = 1 continue if opt == "-f" or opt == "--file": counts_file = val continue if opt == "-m" or opt == "--missing": missing = 1 continue if opt == "-C" or opt == "--coverdir": coverdir = val continue if opt == "-s" or opt == "--summary": summary = 1 continue if opt == "--ignore-module": ignore_modules.append(val) continue if opt == "--ignore-dir": for s in val.split(os.pathsep): s = os.path.expandvars(s) # should I also call expanduser? (after all, could use $HOME) s = s.replace("$prefix", os.path.join(sys.prefix, "lib", "python" + sys.version[:3])) s = s.replace("$exec_prefix", os.path.join(sys.exec_prefix, "lib", "python" + sys.version[:3])) s = os.path.normpath(s) ignore_dirs.append(s) continue assert 0, "Should never get here" if listfuncs and (count or trace): _err_exit("cannot specify both --listfuncs and (--trace or --count)") if not (count or trace or report or listfuncs or countcallers): _err_exit("must specify one of --trace, --count, --report, " "--listfuncs, or --trackcalls") if report and no_report: _err_exit("cannot specify both --report and --no-report") if report and not counts_file: _err_exit("--report requires a --file") if no_report and len(prog_argv) == 0: _err_exit("missing name of file to run") # everything is ready if report: results = CoverageResults(infile=counts_file, outfile=counts_file) results.write_results(missing, summary=summary, coverdir=coverdir) else: sys.argv = prog_argv progname = prog_argv[0] sys.path[0] = os.path.split(progname)[0] t = Trace(count, trace, countfuncs=listfuncs, countcallers=countcallers, ignoremods=ignore_modules, ignoredirs=ignore_dirs, infile=counts_file, outfile=counts_file) try: t.run('execfile(%r)' % (progname,)) except IOError, err: _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err)) except SystemExit: pass results = t.results() if not no_report: results.write_results(missing, summary=summary, coverdir=coverdir) if __name__=='__main__': main()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 12468, 4248, 12521, 12, 27722, 30671, 7376, 3107, 4548, 473, 977, 85, 816, 397, 12, 3277, 2020, 1006, 4481, 1396, 199, 3, 2329, 1396, 221, 4644, 436, 402, 22941, 370, 314, 4575, 1334, 314, 2895, 402, 314, 199, 3, 2018, 499, 14, 18, 4190, 14, 199, 3, 6529, 26, 3107, 6992, 79, 593, 7, 55, 5812, 352, 645, 2641, 88, 199, 3, 1455, 921, 90, 6992, 79, 14, 957, 15, 199, 3, 6016, 475, 26, 90, 6992, 79, 32, 90, 6992, 79, 14, 957, 199, 3, 199, 3, 1898, 12293, 12, 3930, 16997, 12300, 12, 3277, 2020, 1006, 4481, 4644, 14, 199, 3, 6529, 26, 8232, 603, 1888, 290, 285, 79, 199, 3, 199, 3, 1898, 21300, 12, 31012, 720, 2660, 12, 3277, 2020, 1006, 4481, 4644, 14, 199, 3, 6529, 26, 6061, 5257, 577, 279, 415, 199, 3, 199, 3, 1898, 9013, 21, 13, 7155, 23, 12, 9195, 3642, 12, 3277, 2020, 1006, 4481, 4644, 14, 199, 3, 6529, 26, 8232, 603, 1888, 290, 285, 79, 199, 3, 199, 3, 1898, 9013, 17, 13, 7155, 21, 12, 428, 280, 335, 1337, 16593, 24508, 280, 15820, 445, 18626, 453, 12, 1006, 4481, 4644, 14, 199, 3, 199, 3, 199, 3, 8779, 370, 675, 12, 1331, 12, 2811, 12, 436, 11207, 642, 2018, 2032, 436, 199, 3, 2399, 4568, 3794, 367, 1263, 12016, 1928, 14751, 365, 11882, 199, 3, 10009, 12, 2741, 626, 314, 3432, 4248, 4245, 11337, 315, 1006, 6866, 12, 199, 3, 436, 626, 3865, 626, 4248, 4245, 436, 642, 4983, 4245, 7468, 315, 199, 3, 21038, 3794, 12, 436, 626, 314, 536, 402, 15564, 9195, 3642, 12, 199, 3, 31012, 720, 2660, 503, 3930, 16997, 12300, 506, 1202, 315, 19613, 1044, 503, 7974, 20976, 1126, 24522, 370, 199, 3, 4084, 402, 314, 2032, 1928, 2488, 12, 5313, 6791, 4983, 14, 199, 3, 199, 624, 6815, 15, 578, 370, 3307, 2018, 2240, 503, 805, 6451, 199, 199, 8176, 675, 12, 1414, 1004, 26, 523, 3307, 14, 647, 446, 67, 446, 70, 8242, 1553, 4247, 13, 694, 4505, 1861, 7, 14909, 14, 647, 22151, 523, 3307, 14, 647, 446, 84, 1553, 4247, 13, 694, 4505, 1861, 7, 14909, 14, 647, 22151, 523, 3307, 14, 647, 1553, 3885, 5352, 14909, 14, 647, 22151, 199, 199, 8176, 675, 12, 2240, 17174, 523, 492, 984, 819, 327, 1218, 282, 11680, 909, 12, 1565, 10564, 652, 4052, 370, 3686, 12, 436, 3775, 370, 523, 327, 886, 23465, 503, 1004, 13, 835, 316, 503, 3865, 14, 523, 29140, 275, 3307, 14, 3921, 8, 4247, 3220, 1524, 1274, 14, 1861, 12, 984, 14, 1628, 63, 1861, 12, 467, 3307, 29, 16, 12, 490, 2338, 29, 17, 9, 523, 327, 1255, 314, 892, 1414, 1808, 314, 1627, 29140, 523, 29140, 14, 1065, 360, 973, 19004, 523, 327, 1852, 282, 3622, 12, 299, 13121, 1072, 315, 1182, 2791, 523, 519, 275, 29140, 14, 2604, 342, 523, 519, 14, 952, 63, 2604, 8, 2384, 63, 4752, 29, 549, 12, 8486, 694, 9555, 2791, 531, 199, 624, 199, 199, 646, 26026, 199, 646, 747, 199, 646, 295, 199, 646, 984, 199, 646, 5796, 199, 646, 1526, 199, 646, 13343, 199, 646, 2943, 199, 646, 9486, 199, 199, 893, 26, 272, 492, 17572, 272, 5927, 275, 17572, 199, 2590, 3545, 26, 272, 492, 5927, 199, 199, 318, 4503, 8, 4984, 304, 272, 4386, 14, 952, 4852, 7692, 26, 450, 83, 359, 8808, 61, 665, 493, 30, 359, 13990, 61, 199, 199, 3396, 13, 1419, 26, 199, 306, 3437, 4483, 12175, 642, 1720, 2066, 4458, 14, 199, 306, 1023, 3777, 7242, 1015, 2556, 2066, 4458, 14, 199, 199, 8632, 2605, 12, 8840, 1373, 402, 314, 2569, 7795, 1511, 1471, 506, 1627, 26, 199, 13, 84, 12, 1553, 3446, 3698, 9101, 1924, 1004, 370, 984, 14, 2703, 2544, 652, 365, 7934, 14, 199, 13, 67, 12, 1553, 835, 3698, 14826, 314, 1329, 402, 5431, 1924, 1004, 365, 7934, 1993, 436, 2218, 314, 8242, 370, 665, 578, 10827, 5899, 367, 1924, 1993, 859, 7934, 12, 315, 314, 859, 1159, 2082, 14, 1993, 1666, 2597, 658, 306, 5899, 694, 297, 658, 306, 493, 297, 658, 306, 889, 13, 3070, 7, 5084, 14, 199, 13, 76, 12, 1553, 513, 9204, 755, 14797, 4426, 402, 1314, 3423, 787, 7934, 737, 5210, 1993, 5403, 436, 2218, 314, 2058, 370, 984, 14, 2703, 2410, 314, 1993, 2240, 20100, 14, 199, 13, 52, 12, 1553, 3885, 5352, 420, 14797, 4426, 402, 8025, 15, 3527, 6342, 436, 2218, 314, 1993, 2058, 370, 984, 14, 2703, 2410, 314, 2240, 20100, 14, 199, 13, 82, 12, 1553, 3070, 3515, 7958, 282, 3622, 687, 282, 8242, 570, 27, 886, 440, 5341, 1993, 1263, 1233, 14, 221, 658, 306, 493, 7, 1471, 4165, 314, 2058, 570, 370, 1993, 1586, 12, 1314, 1471, 1172, 2757, 2737, 315, 282, 4136, 1255, 1993, 543, 658, 306, 835, 1553, 493, 29, 3817, 1370, 199, 199, 7469, 6069, 26, 199, 13, 70, 12, 1553, 493, 18987, 493, 30, 258, 3814, 370, 30535, 8242, 1806, 9978, 7858, 14, 199, 13, 50, 12, 1553, 889, 13, 3070, 755, 4226, 440, 3550, 314, 11745, 3622, 1584, 14, 1993, 18491, 340, 1265, 2934, 370, 30535, 1806, 9978, 7858, 14, 199, 13, 35, 12, 1553, 5899, 694, 18987, 694, 30, 221, 15191, 2382, 314, 3622, 1584, 14, 221, 710, 11745, 1993, 3622, 367, 665, 2491, 10827, 28, 578, 30, 365, 5313, 370, 570, 1993, 665, 694, 23220, 2491, 23220, 578, 10827, 5899, 14, 199, 13, 77, 12, 1553, 4752, 260, 1626, 1397, 323, 7286, 2385, 626, 4898, 440, 7934, 1993, 543, 283, 28375, 1140, 1987, 199, 13, 83, 12, 1553, 4705, 260, 6990, 282, 29226, 6212, 641, 3839, 367, 1924, 570, 14, 1993, 334, 6049, 1454, 506, 1202, 543, 1553, 835, 503, 1553, 3070, 4959, 199, 199, 18053, 12, 1443, 506, 10877, 3663, 5431, 26, 199, 306, 4247, 13, 578, 18987, 1494, 30, 14092, 314, 1627, 859, 436, 2399, 29449, 1993, 334, 692, 652, 365, 282, 2559, 680, 199, 306, 4247, 13, 694, 18987, 694, 30, 259, 14092, 1584, 315, 314, 1627, 2082, 334, 6048, 1993, 6602, 883, 506, 16538, 701, 747, 14, 17843, 680, 199, 624, 450, 984 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 12468, 4248, 12521, 12, 27722, 30671, 7376, 3107, 4548, 473, 977, 85, 816, 397, 12, 3277, 2020, 1006, 4481, 1396, 199, 3, 2329, 1396, 221, 4644, 436, 402, 22941, 370, 314, 4575, 1334, 314, 2895, 402, 314, 199, 3, 2018, 499, 14, 18, 4190, 14, 199, 3, 6529, 26, 3107, 6992, 79, 593, 7, 55, 5812, 352, 645, 2641, 88, 199, 3, 1455, 921, 90, 6992, 79, 14, 957, 15, 199, 3, 6016, 475, 26, 90, 6992, 79, 32, 90, 6992, 79, 14, 957, 199, 3, 199, 3, 1898, 12293, 12, 3930, 16997, 12300, 12, 3277, 2020, 1006, 4481, 4644, 14, 199, 3, 6529, 26, 8232, 603, 1888, 290, 285, 79, 199, 3, 199, 3, 1898, 21300, 12, 31012, 720, 2660, 12, 3277, 2020, 1006, 4481, 4644, 14, 199, 3, 6529, 26, 6061, 5257, 577, 279, 415, 199, 3, 199, 3, 1898, 9013, 21, 13, 7155, 23, 12, 9195, 3642, 12, 3277, 2020, 1006, 4481, 4644, 14, 199, 3, 6529, 26, 8232, 603, 1888, 290, 285, 79, 199, 3, 199, 3, 1898, 9013, 17, 13, 7155, 21, 12, 428, 280, 335, 1337, 16593, 24508, 280, 15820, 445, 18626, 453, 12, 1006, 4481, 4644, 14, 199, 3, 199, 3, 199, 3, 8779, 370, 675, 12, 1331, 12, 2811, 12, 436, 11207, 642, 2018, 2032, 436, 199, 3, 2399, 4568, 3794, 367, 1263, 12016, 1928, 14751, 365, 11882, 199, 3, 10009, 12, 2741, 626, 314, 3432, 4248, 4245, 11337, 315, 1006, 6866, 12, 199, 3, 436, 626, 3865, 626, 4248, 4245, 436, 642, 4983, 4245, 7468, 315, 199, 3, 21038, 3794, 12, 436, 626, 314, 536, 402, 15564, 9195, 3642, 12, 199, 3, 31012, 720, 2660, 503, 3930, 16997, 12300, 506, 1202, 315, 19613, 1044, 503, 7974, 20976, 1126, 24522, 370, 199, 3, 4084, 402, 314, 2032, 1928, 2488, 12, 5313, 6791, 4983, 14, 199, 3, 199, 624, 6815, 15, 578, 370, 3307, 2018, 2240, 503, 805, 6451, 199, 199, 8176, 675, 12, 1414, 1004, 26, 523, 3307, 14, 647, 446, 67, 446, 70, 8242, 1553, 4247, 13, 694, 4505, 1861, 7, 14909, 14, 647, 22151, 523, 3307, 14, 647, 446, 84, 1553, 4247, 13, 694, 4505, 1861, 7, 14909, 14, 647, 22151, 523, 3307, 14, 647, 1553, 3885, 5352, 14909, 14, 647, 22151, 199, 199, 8176, 675, 12, 2240, 17174, 523, 492, 984, 819, 327, 1218, 282, 11680, 909, 12, 1565, 10564, 652, 4052, 370, 3686, 12, 436, 3775, 370, 523, 327, 886, 23465, 503, 1004, 13, 835, 316, 503, 3865, 14, 523, 29140, 275, 3307, 14, 3921, 8, 4247, 3220, 1524, 1274, 14, 1861, 12, 984, 14, 1628, 63, 1861, 12, 467, 3307, 29, 16, 12, 490, 2338, 29, 17, 9, 523, 327, 1255, 314, 892, 1414, 1808, 314, 1627, 29140, 523, 29140, 14, 1065, 360, 973, 19004, 523, 327, 1852, 282, 3622, 12, 299, 13121, 1072, 315, 1182, 2791, 523, 519, 275, 29140, 14, 2604, 342, 523, 519, 14, 952, 63, 2604, 8, 2384, 63, 4752, 29, 549, 12, 8486, 694, 9555, 2791, 531, 199, 624, 199, 199, 646, 26026, 199, 646, 747, 199, 646, 295, 199, 646, 984, 199, 646, 5796, 199, 646, 1526, 199, 646, 13343, 199, 646, 2943, 199, 646, 9486, 199, 199, 893, 26, 272, 492, 17572, 272, 5927, 275, 17572, 199, 2590, 3545, 26, 272, 492, 5927, 199, 199, 318, 4503, 8, 4984, 304, 272, 4386, 14, 952, 4852, 7692, 26, 450, 83, 359, 8808, 61, 665, 493, 30, 359, 13990, 61, 199, 199, 3396, 13, 1419, 26, 199, 306, 3437, 4483, 12175, 642, 1720, 2066, 4458, 14, 199, 306, 1023, 3777, 7242, 1015, 2556, 2066, 4458, 14, 199, 199, 8632, 2605, 12, 8840, 1373, 402, 314, 2569, 7795, 1511, 1471, 506, 1627, 26, 199, 13, 84, 12, 1553, 3446, 3698, 9101, 1924, 1004, 370, 984, 14, 2703, 2544, 652, 365, 7934, 14, 199, 13, 67, 12, 1553, 835, 3698, 14826, 314, 1329, 402, 5431, 1924, 1004, 365, 7934, 1993, 436, 2218, 314, 8242, 370, 665, 578, 10827, 5899, 367, 1924, 1993, 859, 7934, 12, 315, 314, 859, 1159, 2082, 14, 1993, 1666, 2597, 658, 306, 5899, 694, 297, 658, 306, 493, 297, 658, 306, 889, 13, 3070, 7, 5084, 14, 199, 13, 76, 12, 1553, 513, 9204, 755, 14797, 4426, 402, 1314, 3423, 787, 7934, 737, 5210, 1993, 5403, 436, 2218, 314, 2058, 370, 984, 14, 2703, 2410, 314, 1993, 2240, 20100, 14, 199, 13, 52, 12, 1553, 3885, 5352, 420, 14797, 4426, 402, 8025, 15, 3527, 6342, 436, 2218, 314, 1993, 2058, 370, 984, 14, 2703, 2410, 314, 2240, 20100, 14, 199, 13, 82, 12, 1553, 3070, 3515, 7958, 282, 3622, 687, 282, 8242, 570, 27, 886, 440, 5341, 1993, 1263, 1233, 14, 221, 658, 306, 493, 7, 1471, 4165, 314, 2058, 570, 370, 1993, 1586, 12, 1314, 1471, 1172, 2757, 2737, 315, 282, 4136, 1255, 1993, 543, 658, 306, 835, 1553, 493, 29, 3817, 1370, 199, 199, 7469, 6069, 26, 199, 13, 70, 12, 1553, 493, 18987, 493, 30, 258, 3814, 370, 30535, 8242, 1806, 9978, 7858, 14, 199, 13, 50, 12, 1553, 889, 13, 3070, 755, 4226, 440, 3550, 314, 11745, 3622, 1584, 14, 1993, 18491, 340, 1265, 2934, 370, 30535, 1806, 9978, 7858, 14, 199, 13, 35, 12, 1553, 5899, 694, 18987, 694, 30, 221, 15191, 2382, 314, 3622, 1584, 14, 221, 710, 11745, 1993, 3622, 367, 665, 2491, 10827, 28, 578, 30, 365, 5313, 370, 570, 1993, 665, 694, 23220, 2491, 23220, 578, 10827, 5899, 14, 199, 13, 77, 12, 1553, 4752, 260, 1626, 1397, 323, 7286, 2385, 626, 4898, 440, 7934, 1993, 543, 283, 28375, 1140, 1987, 199, 13, 83, 12, 1553, 4705, 260, 6990, 282, 29226, 6212, 641, 3839, 367, 1924, 570, 14, 1993, 334, 6049, 1454, 506, 1202, 543, 1553, 835, 503, 1553, 3070, 4959, 199, 199, 18053, 12, 1443, 506, 10877, 3663, 5431, 26, 199, 306, 4247, 13, 578, 18987, 1494, 30, 14092, 314, 1627, 859, 436, 2399, 29449, 1993, 334, 692, 652, 365, 282, 2559, 680, 199, 306, 4247, 13, 694, 18987, 694, 30, 259, 14092, 1584, 315, 314, 1627, 2082, 334, 6048, 1993, 6602, 883, 506, 16538, 701, 747, 14, 17843, 680, 199, 624, 450, 984, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
msarahan/bokeh
scripts/test_matrix.py
34
7005
from __future__ import print_function import argparse import os import shutil import subprocess import textwrap def get_parser(): """Create the parser that will be used to add arguments to the script. """ parser = argparse.ArgumentParser(description=textwrap.dedent(""" Creates conda environments for a given version of bokeh, installed using pip and conda and including python 2.7 and python 3.4. The --version ('-v') option takes an earlier version of bokeh, for use in creating environments where bokeh will be updated. Ex: ' python test_matrix.py -v 0.7.0' """), formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('-v', '--version', action='store', default=False, help='Version of bokeh', required=True) # parser.add_argument('') return parser def cleaner(env_path): """Checks that an environment path exists and, if so, deletes it. """ if os.path.exists(env_path): shutil.rmtree(env_path) def conda_creator(env_name, pkgs): """Create a conda environment of a given name containing a given string of pkgs. """ subprocess.call("conda create --yes -n %s %s" % (env_name, pkgs), shell=True) def bokeh_installer(env_name, install_string): """Activate an environment and run its install string to either install or update bokeh using conda or pip. """ if os.name == 'nt': command_string = 'activate %s & %s' % (env_name, install_string) else: command_string = 'source activate %s; %s' % (env_name, install_string) result = subprocess.call(command_string, shell=True, executable="/bin/bash") return result == 0 if __name__ == '__main__': parser = get_parser() ops = parser.parse_args() ver = ops.version envs = { "py27_conda_clean" : { "init" : "python=2.7 pytest mock", "install" : '; '.join([ # install latest version from dev channel "conda install --yes -c bokeh/channel/dev bokeh", # install dependencies needed for testing "conda install --yes -c jrderuiter pytest-cov", "conda install --yes -c auto websocket-client", "conda install --yes -c bokeh nose mock blaze abstract-rendering beautiful-soup ipython scipy websocket multiuserblazeserver pillow", ]) }, "py27_conda_update" : { "init" : "python=2.7 nose mock bokeh=%s" % ver, "install" : '; '.join([ "conda update --yes -c bokeh/channel/dev bokeh", # install dependencies needed for testing "conda install --yes -c auto websocket-client", "conda install --yes -c bokeh nose mock blaze abstract-rendering beautiful-soup ipython scipy websocket multiuserblazeserver pillow", ]) }, "py27_pip_clean" : { "init" : "python=2.7 pytest mock pip", "install" : '; '.join([ # Latest version of pip not included in anaconda 2.3.0 "pip install --pre -i https://pypi.anaconda.org/bokeh/channel/dev/simple bokeh --extra-index-url https://pypi.python.org/simple/", # install dependencies needed for testing "conda install --yes -c jrderuiter pytest-cov", "conda install --yes -c auto websocket-client", "conda install --yes -c bokeh nose mock blaze abstract-rendering beautiful-soup ipython scipy websocket-client multiuserblazeserver", ]) }, "py27_pip_update" : { "init" : "python=2.7 pip nose mock bokeh=%s" % ver, "install" : '; '.join([ # Latest version of pip not included in anaconda 2.3.0 "pip install --upgrade --pre -i https://pypi.anaconda.org/bokeh/channel/dev/simple bokeh --extra-index-url https://pypi.python.org/simple/", # install dependencies needed for testing "conda install --yes -c auto websocket-client", "conda install --yes -c bokeh nose mock blaze abstract-rendering beautiful-soup ipython scipy multiuserblazeserver", ]) }, "py34_pip_clean" : { "init" : "python=3.4 pytest mock pip", "install" : '; '.join([ # Latest version of pip not included in anaconda 2.3.0 "pip install --pre -i https://pypi.anaconda.org/bokeh/channel/dev/simple bokeh --extra-index-url https://pypi.python.org/simple/", # install dependencies needed for testing "conda install --yes -c jrderuiter pytest-cov", "conda install --yes -c bokeh nose mock blaze abstract-rendering beautiful-soup ipython scipy multiuserblazeserver", ]) }, "py34_pip_update" : { "init" : "python=3.4 pip nose mock bokeh=%s" % ver, "install" : '; '.join([ # Latest version of pip not included in anaconda 2.3.0 "pip install --upgrade --pre -i https://pypi.anaconda.org/bokeh/channel/dev/simple bokeh --extra-index-url https://pypi.python.org/simple/", # install dependencies needed for testing "conda install --yes -c bokeh nose mock blaze abstract-rendering beautiful-soup ipython scipy multiuserblazeserver", ]) }, } # Use this method rather than os.path.expanduser('~/anaconda') to provide # miniconda support root = subprocess.check_output(['conda', 'info', '--root']).rstrip() # Python3 will return a byte string on the above line, so it must be # decoded to utf-8 before we can pass it to os.path.join root = root.decode() for environment in envs: successful_install = True fails = [] cleaner(os.path.join(root, "envs", environment)) print() print("CREATING NEW ENV", environment) conda_creator(environment, envs[environment]["init"]) install = bokeh_installer(environment, envs[environment]["install"]) if not install: fails.append(environment) successful_install = False print() print("*********************") if successful_install: print("All environments have been installed! See below for their names.\n") for environment in envs: print(environment) print("\nNOTE: All of these environments will be deleted and replaced if you rerun test_matrix.py") else: print("The following environments have failed to install:\n") for install_fail in fails: print(install_fail) print("*********************")
bsd-3-clause
[ 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 7534, 199, 646, 747, 199, 646, 5145, 199, 646, 3873, 199, 646, 13390, 421, 199, 318, 664, 63, 2087, 837, 272, 408, 2499, 314, 1798, 626, 911, 506, 1202, 370, 1050, 2368, 370, 314, 2884, 14, 272, 408, 339, 1798, 275, 7534, 14, 10730, 8, 1802, 29, 505, 3823, 14, 14674, 4852, 490, 10560, 406, 983, 22196, 367, 282, 1627, 490, 1015, 402, 25214, 12, 4903, 1808, 7305, 436, 490, 406, 983, 436, 5893, 2366, 499, 14, 23, 436, 2366, 650, 14, 20, 14, 4951, 710, 1553, 1023, 12291, 86, 358, 945, 6181, 376, 14119, 1015, 402, 490, 25214, 12, 367, 675, 315, 6425, 22196, 2382, 25214, 911, 506, 490, 4588, 14, 421, 490, 1316, 26, 283, 2366, 511, 63, 3642, 14, 647, 446, 86, 378, 14, 23, 14, 16, 7, 490, 408, 395, 9698, 63, 533, 29, 18978, 14, 7963, 1872, 22779, 9, 339, 1798, 14, 525, 63, 2094, 3654, 86, 297, 2850, 1023, 297, 1595, 534, 1617, 297, 849, 29, 797, 12, 717, 1720, 534, 3353, 402, 25214, 297, 1415, 29, 549, 9, 272, 327, 1798, 14, 525, 63, 2094, 8355, 339, 372, 1798, 421, 199, 318, 3633, 281, 8, 1813, 63, 515, 304, 272, 408, 11834, 626, 376, 3734, 931, 3495, 436, 12, 340, 880, 12, 21812, 652, 14, 272, 408, 339, 340, 747, 14, 515, 14, 2444, 8, 1813, 63, 515, 304, 267, 5145, 14, 9242, 8, 1813, 63, 515, 9, 421, 199, 318, 406, 983, 63, 9986, 8, 1813, 63, 354, 12, 24162, 304, 272, 408, 2499, 282, 406, 983, 3734, 402, 282, 1627, 536, 3035, 282, 1627, 1059, 402, 24162, 14, 272, 408, 339, 3873, 14, 1250, 480, 23463, 1218, 1553, 5066, 446, 78, 450, 83, 450, 83, 2, 450, 334, 1813, 63, 354, 12, 24162, 395, 5218, 29, 549, 9, 421, 199, 318, 25214, 63, 17047, 8, 1813, 63, 354, 12, 3907, 63, 875, 304, 272, 408, 30120, 376, 3734, 436, 1255, 2399, 3907, 1059, 370, 1902, 3907, 503, 1678, 25214, 1808, 272, 406, 983, 503, 7305, 14, 272, 408, 339, 340, 747, 14, 354, 508, 283, 343, 356, 267, 1414, 63, 875, 275, 283, 8222, 450, 83, 1253, 450, 83, 7, 450, 334, 1813, 63, 354, 12, 3907, 63, 875, 9, 272, 587, 26, 267, 1414, 63, 875, 275, 283, 1365, 15422, 450, 83, 27, 450, 83, 7, 450, 334, 1813, 63, 354, 12, 3907, 63, 875, 9, 339, 754, 275, 3873, 14, 1250, 8, 1531, 63, 875, 12, 5218, 29, 549, 12, 7286, 9555, 1393, 15, 16408, 531, 339, 372, 754, 508, 378, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 339, 1798, 275, 664, 63, 2087, 342, 272, 4156, 275, 1798, 14, 1122, 63, 589, 342, 339, 809, 275, 4156, 14, 1023, 339, 2589, 83, 275, 469, 267, 298, 647, 1465, 63, 23463, 63, 3118, 2, 259, 520, 469, 288, 298, 826, 2, 259, 520, 298, 1548, 29, 18, 14, 23, 4613, 1683, 401, 288, 298, 3174, 2, 520, 14289, 1987, 904, 779, 490, 327, 3907, 8839, 1015, 687, 4866, 3623, 490, 298, 23463, 3907, 1553, 5066, 446, 67, 25214, 15, 2775, 15, 2374, 25214, 401, 490, 327, 3907, 5124, 4346, 367, 5343, 490, 298, 23463, 3907, 1553, 5066, 221, 446, 67, 1335, 82, 424, 85, 1661, 4613, 13, 8695, 401, 490, 298, 23463, 3907, 1553, 5066, 221, 446, 67, 2599, 24897, 13, 1258, 401, 490, 298, 23463, 3907, 1553, 5066, 221, 446, 67, 25214, 11354, 1683, 330, 416, 806, 9006, 13, 28228, 506, 25146, 13, 9317, 284, 1548, 7026, 24897, 3510, 751, 21244, 806, 1000, 299, 382, 674, 401, 355, 4794, 288, 1660, 267, 298, 647, 1465, 63, 23463, 63, 873, 2, 257, 520, 469, 288, 298, 826, 2, 259, 520, 298, 1548, 29, 18, 14, 23, 11354, 1683, 25214, 2458, 83, 2, 450, 809, 12, 288, 298, 3174, 2, 520, 14289, 1987, 904, 779, 490, 298, 23463, 1678, 1553, 5066, 446, 67, 25214, 15, 2775, 15, 2374, 25214, 401, 490, 327, 3907, 5124, 4346, 367, 5343, 490, 298, 23463, 3907, 1553, 5066, 446, 67, 2599, 24897, 13, 1258, 401, 490, 298, 23463, 3907, 1553, 5066, 446, 67, 25214, 11354, 1683, 330, 416, 806, 9006, 13, 28228, 506, 25146, 13, 9317, 284, 1548, 7026, 24897, 3510, 751, 21244, 806, 1000, 299, 382, 674, 401, 355, 4794, 288, 1660, 267, 298, 647, 1465, 63, 9983, 63, 3118, 2, 420, 520, 469, 288, 298, 826, 2, 259, 520, 298, 1548, 29, 18, 14, 23, 4613, 1683, 7305, 401, 288, 298, 3174, 2, 520, 14289, 1987, 904, 779, 355, 327, 491, 27126, 1015, 402, 7305, 440, 5120, 315, 376, 16928, 983, 499, 14, 19, 14, 16, 355, 298, 9983, 3907, 1553, 657, 446, 73, 4178, 921, 17343, 14, 28299, 14, 1308, 15, 656, 16610, 15, 2775, 15, 2374, 15, 4129, 25214, 1553, 2911, 13, 1080, 13, 633, 4178, 921, 17343, 14, 1548, 14, 1308, 15, 4129, 10665, 355, 327, 3907, 5124, 4346, 367, 5343, 355, 298, 23463, 3907, 1553, 5066, 221, 446, 67, 1335, 82, 424, 85, 1661, 4613, 13, 8695, 401, 355, 298, 23463, 3907, 1553, 5066, 446, 67, 2599, 24897, 13, 1258, 401, 355, 298, 23463, 3907, 1553, 5066, 446, 67, 25214, 11354, 1683, 330, 416, 806, 9006, 13, 28228, 506, 25146, 13, 9317, 284, 1548, 7026, 24897, 13, 1258, 3510, 751, 21244, 806, 1000, 401, 355, 4794, 288, 1660, 267, 298, 647, 1465, 63, 9983, 63, 873, 2, 258, 520, 469, 288, 298, 826, 2, 259, 520, 298, 1548, 29, 18, 14, 23, 7305, 11354, 1683, 25214, 2458, 83, 2, 450, 809, 12, 288, 298, 3174, 2, 520, 221, 14289, 1987, 904, 779, 355, 327, 491, 27126, 1015, 402, 7305, 440, 5120, 315, 376, 16928, 983, 499, 14, 19, 14, 16, 355, 298, 9983, 3907, 1553, 9375, 1553, 657, 446, 73, 4178, 921, 17343, 14, 28299, 14, 1308, 15, 656, 16610, 15, 2775, 15, 2374, 15, 4129, 25214, 1553, 2911, 13, 1080, 13, 633, 4178, 921, 17343, 14, 1548, 14, 1308, 15, 4129, 10665, 355, 327, 3907, 5124, 4346, 367, 5343, 355, 298, 23463, 3907, 1553, 5066, 446, 67, 2599, 24897, 13, 1258, 401, 355, 298, 23463, 3907, 1553, 5066 ]
[ 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 7534, 199, 646, 747, 199, 646, 5145, 199, 646, 3873, 199, 646, 13390, 421, 199, 318, 664, 63, 2087, 837, 272, 408, 2499, 314, 1798, 626, 911, 506, 1202, 370, 1050, 2368, 370, 314, 2884, 14, 272, 408, 339, 1798, 275, 7534, 14, 10730, 8, 1802, 29, 505, 3823, 14, 14674, 4852, 490, 10560, 406, 983, 22196, 367, 282, 1627, 490, 1015, 402, 25214, 12, 4903, 1808, 7305, 436, 490, 406, 983, 436, 5893, 2366, 499, 14, 23, 436, 2366, 650, 14, 20, 14, 4951, 710, 1553, 1023, 12291, 86, 358, 945, 6181, 376, 14119, 1015, 402, 490, 25214, 12, 367, 675, 315, 6425, 22196, 2382, 25214, 911, 506, 490, 4588, 14, 421, 490, 1316, 26, 283, 2366, 511, 63, 3642, 14, 647, 446, 86, 378, 14, 23, 14, 16, 7, 490, 408, 395, 9698, 63, 533, 29, 18978, 14, 7963, 1872, 22779, 9, 339, 1798, 14, 525, 63, 2094, 3654, 86, 297, 2850, 1023, 297, 1595, 534, 1617, 297, 849, 29, 797, 12, 717, 1720, 534, 3353, 402, 25214, 297, 1415, 29, 549, 9, 272, 327, 1798, 14, 525, 63, 2094, 8355, 339, 372, 1798, 421, 199, 318, 3633, 281, 8, 1813, 63, 515, 304, 272, 408, 11834, 626, 376, 3734, 931, 3495, 436, 12, 340, 880, 12, 21812, 652, 14, 272, 408, 339, 340, 747, 14, 515, 14, 2444, 8, 1813, 63, 515, 304, 267, 5145, 14, 9242, 8, 1813, 63, 515, 9, 421, 199, 318, 406, 983, 63, 9986, 8, 1813, 63, 354, 12, 24162, 304, 272, 408, 2499, 282, 406, 983, 3734, 402, 282, 1627, 536, 3035, 282, 1627, 1059, 402, 24162, 14, 272, 408, 339, 3873, 14, 1250, 480, 23463, 1218, 1553, 5066, 446, 78, 450, 83, 450, 83, 2, 450, 334, 1813, 63, 354, 12, 24162, 395, 5218, 29, 549, 9, 421, 199, 318, 25214, 63, 17047, 8, 1813, 63, 354, 12, 3907, 63, 875, 304, 272, 408, 30120, 376, 3734, 436, 1255, 2399, 3907, 1059, 370, 1902, 3907, 503, 1678, 25214, 1808, 272, 406, 983, 503, 7305, 14, 272, 408, 339, 340, 747, 14, 354, 508, 283, 343, 356, 267, 1414, 63, 875, 275, 283, 8222, 450, 83, 1253, 450, 83, 7, 450, 334, 1813, 63, 354, 12, 3907, 63, 875, 9, 272, 587, 26, 267, 1414, 63, 875, 275, 283, 1365, 15422, 450, 83, 27, 450, 83, 7, 450, 334, 1813, 63, 354, 12, 3907, 63, 875, 9, 339, 754, 275, 3873, 14, 1250, 8, 1531, 63, 875, 12, 5218, 29, 549, 12, 7286, 9555, 1393, 15, 16408, 531, 339, 372, 754, 508, 378, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 339, 1798, 275, 664, 63, 2087, 342, 272, 4156, 275, 1798, 14, 1122, 63, 589, 342, 339, 809, 275, 4156, 14, 1023, 339, 2589, 83, 275, 469, 267, 298, 647, 1465, 63, 23463, 63, 3118, 2, 259, 520, 469, 288, 298, 826, 2, 259, 520, 298, 1548, 29, 18, 14, 23, 4613, 1683, 401, 288, 298, 3174, 2, 520, 14289, 1987, 904, 779, 490, 327, 3907, 8839, 1015, 687, 4866, 3623, 490, 298, 23463, 3907, 1553, 5066, 446, 67, 25214, 15, 2775, 15, 2374, 25214, 401, 490, 327, 3907, 5124, 4346, 367, 5343, 490, 298, 23463, 3907, 1553, 5066, 221, 446, 67, 1335, 82, 424, 85, 1661, 4613, 13, 8695, 401, 490, 298, 23463, 3907, 1553, 5066, 221, 446, 67, 2599, 24897, 13, 1258, 401, 490, 298, 23463, 3907, 1553, 5066, 221, 446, 67, 25214, 11354, 1683, 330, 416, 806, 9006, 13, 28228, 506, 25146, 13, 9317, 284, 1548, 7026, 24897, 3510, 751, 21244, 806, 1000, 299, 382, 674, 401, 355, 4794, 288, 1660, 267, 298, 647, 1465, 63, 23463, 63, 873, 2, 257, 520, 469, 288, 298, 826, 2, 259, 520, 298, 1548, 29, 18, 14, 23, 11354, 1683, 25214, 2458, 83, 2, 450, 809, 12, 288, 298, 3174, 2, 520, 14289, 1987, 904, 779, 490, 298, 23463, 1678, 1553, 5066, 446, 67, 25214, 15, 2775, 15, 2374, 25214, 401, 490, 327, 3907, 5124, 4346, 367, 5343, 490, 298, 23463, 3907, 1553, 5066, 446, 67, 2599, 24897, 13, 1258, 401, 490, 298, 23463, 3907, 1553, 5066, 446, 67, 25214, 11354, 1683, 330, 416, 806, 9006, 13, 28228, 506, 25146, 13, 9317, 284, 1548, 7026, 24897, 3510, 751, 21244, 806, 1000, 299, 382, 674, 401, 355, 4794, 288, 1660, 267, 298, 647, 1465, 63, 9983, 63, 3118, 2, 420, 520, 469, 288, 298, 826, 2, 259, 520, 298, 1548, 29, 18, 14, 23, 4613, 1683, 7305, 401, 288, 298, 3174, 2, 520, 14289, 1987, 904, 779, 355, 327, 491, 27126, 1015, 402, 7305, 440, 5120, 315, 376, 16928, 983, 499, 14, 19, 14, 16, 355, 298, 9983, 3907, 1553, 657, 446, 73, 4178, 921, 17343, 14, 28299, 14, 1308, 15, 656, 16610, 15, 2775, 15, 2374, 15, 4129, 25214, 1553, 2911, 13, 1080, 13, 633, 4178, 921, 17343, 14, 1548, 14, 1308, 15, 4129, 10665, 355, 327, 3907, 5124, 4346, 367, 5343, 355, 298, 23463, 3907, 1553, 5066, 221, 446, 67, 1335, 82, 424, 85, 1661, 4613, 13, 8695, 401, 355, 298, 23463, 3907, 1553, 5066, 446, 67, 2599, 24897, 13, 1258, 401, 355, 298, 23463, 3907, 1553, 5066, 446, 67, 25214, 11354, 1683, 330, 416, 806, 9006, 13, 28228, 506, 25146, 13, 9317, 284, 1548, 7026, 24897, 13, 1258, 3510, 751, 21244, 806, 1000, 401, 355, 4794, 288, 1660, 267, 298, 647, 1465, 63, 9983, 63, 873, 2, 258, 520, 469, 288, 298, 826, 2, 259, 520, 298, 1548, 29, 18, 14, 23, 7305, 11354, 1683, 25214, 2458, 83, 2, 450, 809, 12, 288, 298, 3174, 2, 520, 221, 14289, 1987, 904, 779, 355, 327, 491, 27126, 1015, 402, 7305, 440, 5120, 315, 376, 16928, 983, 499, 14, 19, 14, 16, 355, 298, 9983, 3907, 1553, 9375, 1553, 657, 446, 73, 4178, 921, 17343, 14, 28299, 14, 1308, 15, 656, 16610, 15, 2775, 15, 2374, 15, 4129, 25214, 1553, 2911, 13, 1080, 13, 633, 4178, 921, 17343, 14, 1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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
jroltgen/aqua-gesture-framework
samples/SampleGesture/scons-local-1.3.0/SCons/Tool/MSCommon/netframework.py
5
2844
# # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # __revision__ = "src/engine/SCons/Tool/MSCommon/netframework.py 4720 2010/03/24 03:14:11 jars" __doc__ = """ """ import os import re import string from common import read_reg, debug # Original value recorded by dcournapeau _FRAMEWORKDIR_HKEY_ROOT = r'Software\Microsoft\.NETFramework\InstallRoot' # On SGK's system _FRAMEWORKDIR_HKEY_ROOT = r'Software\Microsoft\Microsoft SDKs\.NETFramework\v2.0\InstallationFolder' def find_framework_root(): # XXX: find it from environment (FrameworkDir) try: froot = read_reg(_FRAMEWORKDIR_HKEY_ROOT) debug("Found framework install root in registry: %s" % froot) except WindowsError, e: debug("Could not read reg key %s" % _FRAMEWORKDIR_HKEY_ROOT) return None if not os.path.exists(froot): debug("%s not found on fs" % froot) return None return froot def query_versions(): froot = find_framework_root() if froot: contents = os.listdir(froot) l = re.compile('v[0-9]+.*') versions = filter(lambda e, l=l: l.match(e), contents) def versrt(a,b): # since version numbers aren't really floats... aa = a[1:] bb = b[1:] aal = string.split(aa, '.') bbl = string.split(bb, '.') # sequence comparison in python is lexicographical # which is exactly what we want. # Note we sort backwards so the highest version is first. return cmp(bbl,aal) versions.sort(versrt) else: versions = [] return versions # Local Variables: # tab-width:4 # indent-tabs-mode:nil # End: # vim: set expandtab tabstop=4 shiftwidth=4:
gpl-3.0
[ 3, 199, 3, 1898, 334, 67, 9, 12521, 12, 14790, 12, 13004, 12, 8353, 12, 11811, 12, 8315, 12, 10219, 12, 9079, 12, 8937, 12, 7129, 710, 8218, 2752, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 199, 3, 282, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 199, 3, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 199, 3, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 199, 3, 11207, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 436, 370, 199, 3, 11291, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 5420, 370, 199, 3, 314, 2569, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 199, 3, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 199, 3, 3826, 12, 7168, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 199, 3, 2990, 1634, 3169, 12, 3092, 2381, 437, 3115, 3104, 2401, 199, 3, 13229, 14, 1621, 4825, 6461, 7000, 2334, 10610, 1549, 5877, 8164, 6262, 199, 3, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 7061, 1621, 1261, 9612, 199, 3, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 5738, 1634, 1549, 1621, 11287, 199, 3, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 2334, 4141, 14, 199, 3, 199, 199, 363, 5792, 363, 275, 298, 2164, 15, 3908, 15, 18521, 15, 5157, 15, 3053, 7844, 15, 846, 4857, 14, 647, 10954, 1165, 7129, 15, 1644, 15, 1194, 30569, 26, 1079, 26, 845, 1335, 4291, 2, 199, 199, 363, 1301, 363, 275, 408, 199, 624, 199, 199, 646, 747, 199, 646, 295, 199, 646, 1059, 199, 199, 504, 2863, 492, 1586, 63, 1135, 12, 3105, 199, 199, 3, 12769, 574, 18894, 701, 366, 331, 349, 924, 3844, 199, 63, 12683, 8406, 3022, 63, 23802, 63, 5441, 275, 519, 7, 10337, 60, 12940, 4537, 7278, 16442, 60, 8154, 6405, 7, 199, 3, 4068, 18868, 43, 1159, 2656, 199, 63, 12683, 8406, 3022, 63, 23802, 63, 5441, 275, 519, 7, 10337, 60, 12940, 60, 12940, 15610, 83, 4537, 7278, 16442, 60, 86, 18, 14, 16, 60, 31456, 7850, 7, 199, 199, 318, 2342, 63, 4857, 63, 1231, 837, 272, 327, 5787, 26, 2342, 652, 687, 3734, 334, 16442, 3567, 9, 272, 862, 26, 267, 289, 1231, 275, 1586, 63, 1135, 1547, 12683, 8406, 3022, 63, 23802, 63, 5441, 9, 267, 3105, 480, 3601, 10059, 3907, 1738, 315, 7086, 26, 450, 83, 2, 450, 289, 1231, 9, 272, 871, 23950, 12, 325, 26, 267, 3105, 480, 6531, 440, 1586, 1295, 790, 450, 83, 2, 450, 485, 12683, 8406, 3022, 63, 23802, 63, 5441, 9, 267, 372, 488, 339, 340, 440, 747, 14, 515, 14, 2444, 8, 70, 1231, 304, 267, 3105, 3647, 83, 440, 1911, 641, 7449, 2, 450, 289, 1231, 9, 267, 372, 488, 339, 372, 289, 1231, 199, 199, 318, 1827, 63, 6234, 837, 272, 289, 1231, 275, 2342, 63, 4857, 63, 1231, 342, 272, 340, 289, 1231, 26, 267, 4072, 275, 747, 14, 7374, 8, 70, 1231, 9, 398, 634, 275, 295, 14, 2014, 360, 86, 59, 16, 13, 25, 2807, 24915, 267, 5459, 275, 2457, 8, 2734, 325, 12, 634, 29, 76, 26, 634, 14, 1431, 8, 69, 395, 4072, 9, 398, 347, 809, 24336, 8, 65, 12, 66, 304, 288, 327, 3967, 1015, 5579, 10621, 1133, 7710, 15657, 1396, 288, 18319, 275, 282, 59, 17, 2938, 288, 14027, 275, 330, 59, 17, 2938, 288, 282, 279, 275, 1059, 14, 1294, 8, 2158, 12, 20093, 288, 330, 3345, 275, 1059, 14, 1294, 8, 2501, 12, 20093, 288, 327, 3414, 9132, 315, 2366, 365, 1026, 30077, 2180, 2652, 288, 327, 1314, 365, 8840, 4052, 781, 2934, 14, 288, 327, 3390, 781, 4069, 8552, 880, 314, 15356, 1015, 365, 1642, 14, 288, 372, 10467, 8, 2501, 76, 12, 65, 279, 9, 398, 5459, 14, 3191, 8, 14895, 2591, 9, 272, 587, 26, 267, 5459, 275, 942, 339, 372, 5459, 199, 199, 3, 10111, 17198, 26, 199, 3, 5174, 13, 2063, 26, 20, 199, 3, 4363, 13, 8741, 13, 632, 26, 20613, 199, 3, 9599, 26, 199, 3, 6695, 26, 663, 26414, 20849, 29, 20, 20105, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 3, 1898, 334, 67, 9, 12521, 12, 14790, 12, 13004, 12, 8353, 12, 11811, 12, 8315, 12, 10219, 12, 9079, 12, 8937, 12, 7129, 710, 8218, 2752, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 199, 3, 282, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 199, 3, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 199, 3, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 199, 3, 11207, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 436, 370, 199, 3, 11291, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 5420, 370, 199, 3, 314, 2569, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 199, 3, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 199, 3, 3826, 12, 7168, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 199, 3, 2990, 1634, 3169, 12, 3092, 2381, 437, 3115, 3104, 2401, 199, 3, 13229, 14, 1621, 4825, 6461, 7000, 2334, 10610, 1549, 5877, 8164, 6262, 199, 3, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 7061, 1621, 1261, 9612, 199, 3, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 5738, 1634, 1549, 1621, 11287, 199, 3, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 2334, 4141, 14, 199, 3, 199, 199, 363, 5792, 363, 275, 298, 2164, 15, 3908, 15, 18521, 15, 5157, 15, 3053, 7844, 15, 846, 4857, 14, 647, 10954, 1165, 7129, 15, 1644, 15, 1194, 30569, 26, 1079, 26, 845, 1335, 4291, 2, 199, 199, 363, 1301, 363, 275, 408, 199, 624, 199, 199, 646, 747, 199, 646, 295, 199, 646, 1059, 199, 199, 504, 2863, 492, 1586, 63, 1135, 12, 3105, 199, 199, 3, 12769, 574, 18894, 701, 366, 331, 349, 924, 3844, 199, 63, 12683, 8406, 3022, 63, 23802, 63, 5441, 275, 519, 7, 10337, 60, 12940, 4537, 7278, 16442, 60, 8154, 6405, 7, 199, 3, 4068, 18868, 43, 1159, 2656, 199, 63, 12683, 8406, 3022, 63, 23802, 63, 5441, 275, 519, 7, 10337, 60, 12940, 60, 12940, 15610, 83, 4537, 7278, 16442, 60, 86, 18, 14, 16, 60, 31456, 7850, 7, 199, 199, 318, 2342, 63, 4857, 63, 1231, 837, 272, 327, 5787, 26, 2342, 652, 687, 3734, 334, 16442, 3567, 9, 272, 862, 26, 267, 289, 1231, 275, 1586, 63, 1135, 1547, 12683, 8406, 3022, 63, 23802, 63, 5441, 9, 267, 3105, 480, 3601, 10059, 3907, 1738, 315, 7086, 26, 450, 83, 2, 450, 289, 1231, 9, 272, 871, 23950, 12, 325, 26, 267, 3105, 480, 6531, 440, 1586, 1295, 790, 450, 83, 2, 450, 485, 12683, 8406, 3022, 63, 23802, 63, 5441, 9, 267, 372, 488, 339, 340, 440, 747, 14, 515, 14, 2444, 8, 70, 1231, 304, 267, 3105, 3647, 83, 440, 1911, 641, 7449, 2, 450, 289, 1231, 9, 267, 372, 488, 339, 372, 289, 1231, 199, 199, 318, 1827, 63, 6234, 837, 272, 289, 1231, 275, 2342, 63, 4857, 63, 1231, 342, 272, 340, 289, 1231, 26, 267, 4072, 275, 747, 14, 7374, 8, 70, 1231, 9, 398, 634, 275, 295, 14, 2014, 360, 86, 59, 16, 13, 25, 2807, 24915, 267, 5459, 275, 2457, 8, 2734, 325, 12, 634, 29, 76, 26, 634, 14, 1431, 8, 69, 395, 4072, 9, 398, 347, 809, 24336, 8, 65, 12, 66, 304, 288, 327, 3967, 1015, 5579, 10621, 1133, 7710, 15657, 1396, 288, 18319, 275, 282, 59, 17, 2938, 288, 14027, 275, 330, 59, 17, 2938, 288, 282, 279, 275, 1059, 14, 1294, 8, 2158, 12, 20093, 288, 330, 3345, 275, 1059, 14, 1294, 8, 2501, 12, 20093, 288, 327, 3414, 9132, 315, 2366, 365, 1026, 30077, 2180, 2652, 288, 327, 1314, 365, 8840, 4052, 781, 2934, 14, 288, 327, 3390, 781, 4069, 8552, 880, 314, 15356, 1015, 365, 1642, 14, 288, 372, 10467, 8, 2501, 76, 12, 65, 279, 9, 398, 5459, 14, 3191, 8, 14895, 2591, 9, 272, 587, 26, 267, 5459, 275, 942, 339, 372, 5459, 199, 199, 3, 10111, 17198, 26, 199, 3, 5174, 13, 2063, 26, 20, 199, 3, 4363, 13, 8741, 13, 632, 26, 20613, 199, 3, 9599, 26, 199, 3, 6695, 26, 663, 26414, 20849, 29, 20, 20105, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
atdaemon/pip
pip/_vendor/packaging/specifiers.py
1107
28025
# This file is dual licensed under the terms of the Apache License, Version # 2.0, and the BSD License. See the LICENSE file in the root of this repository # for complete details. from __future__ import absolute_import, division, print_function import abc import functools import itertools import re from ._compat import string_types, with_metaclass from .version import Version, LegacyVersion, parse class InvalidSpecifier(ValueError): """ An invalid specifier was found, users should refer to PEP 440. """ class BaseSpecifier(with_metaclass(abc.ABCMeta, object)): @abc.abstractmethod def __str__(self): """ Returns the str representation of this Specifier like object. This should be representative of the Specifier itself. """ @abc.abstractmethod def __hash__(self): """ Returns a hash value for this Specifier like object. """ @abc.abstractmethod def __eq__(self, other): """ Returns a boolean representing whether or not the two Specifier like objects are equal. """ @abc.abstractmethod def __ne__(self, other): """ Returns a boolean representing whether or not the two Specifier like objects are not equal. """ @abc.abstractproperty def prereleases(self): """ Returns whether or not pre-releases as a whole are allowed by this specifier. """ @prereleases.setter def prereleases(self, value): """ Sets whether or not pre-releases as a whole are allowed by this specifier. """ @abc.abstractmethod def contains(self, item, prereleases=None): """ Determines if the given item is contained within this specifier. """ @abc.abstractmethod def filter(self, iterable, prereleases=None): """ Takes an iterable of items and filters them so that only items which are contained within this specifier are allowed in it. """ class _IndividualSpecifier(BaseSpecifier): _operators = {} def __init__(self, spec="", prereleases=None): match = self._regex.search(spec) if not match: raise InvalidSpecifier("Invalid specifier: '{0}'".format(spec)) self._spec = ( match.group("operator").strip(), match.group("version").strip(), ) # Store whether or not this Specifier should accept prereleases self._prereleases = prereleases def __repr__(self): pre = ( ", prereleases={0!r}".format(self.prereleases) if self._prereleases is not None else "" ) return "<{0}({1!r}{2})>".format( self.__class__.__name__, str(self), pre, ) def __str__(self): return "{0}{1}".format(*self._spec) def __hash__(self): return hash(self._spec) def __eq__(self, other): if isinstance(other, string_types): try: other = self.__class__(other) except InvalidSpecifier: return NotImplemented elif not isinstance(other, self.__class__): return NotImplemented return self._spec == other._spec def __ne__(self, other): if isinstance(other, string_types): try: other = self.__class__(other) except InvalidSpecifier: return NotImplemented elif not isinstance(other, self.__class__): return NotImplemented return self._spec != other._spec def _get_operator(self, op): return getattr(self, "_compare_{0}".format(self._operators[op])) def _coerce_version(self, version): if not isinstance(version, (LegacyVersion, Version)): version = parse(version) return version @property def operator(self): return self._spec[0] @property def version(self): return self._spec[1] @property def prereleases(self): return self._prereleases @prereleases.setter def prereleases(self, value): self._prereleases = value def __contains__(self, item): return self.contains(item) def contains(self, item, prereleases=None): # Determine if prereleases are to be allowed or not. if prereleases is None: prereleases = self.prereleases # Normalize item to a Version or LegacyVersion, this allows us to have # a shortcut for ``"2.0" in Specifier(">=2") item = self._coerce_version(item) # Determine if we should be supporting prereleases in this specifier # or not, if we do not support prereleases than we can short circuit # logic if this version is a prereleases. if item.is_prerelease and not prereleases: return False # Actually do the comparison to determine if this item is contained # within this Specifier or not. return self._get_operator(self.operator)(item, self.version) def filter(self, iterable, prereleases=None): yielded = False found_prereleases = [] kw = {"prereleases": prereleases if prereleases is not None else True} # Attempt to iterate over all the values in the iterable and if any of # them match, yield them. for version in iterable: parsed_version = self._coerce_version(version) if self.contains(parsed_version, **kw): # If our version is a prerelease, and we were not set to allow # prereleases, then we'll store it for later incase nothing # else matches this specifier. if (parsed_version.is_prerelease and not (prereleases or self.prereleases)): found_prereleases.append(version) # Either this is not a prerelease, or we should have been # accepting prereleases from the begining. else: yielded = True yield version # Now that we've iterated over everything, determine if we've yielded # any values, and if we have not and we have any prereleases stored up # then we will go ahead and yield the prereleases. if not yielded and found_prereleases: for version in found_prereleases: yield version class LegacySpecifier(_IndividualSpecifier): _regex_str = ( r""" (?P<operator>(==|!=|<=|>=|<|>)) \s* (?P<version> [^,;\s)]* # Since this is a "legacy" specifier, and the version # string can be just about anything, we match everything # except for whitespace, a semi-colon for marker support, # a closing paren since versions can be enclosed in # them, and a comma since it's a version separator. ) """ ) _regex = re.compile( r"^\s*" + _regex_str + r"\s*$", re.VERBOSE | re.IGNORECASE) _operators = { "==": "equal", "!=": "not_equal", "<=": "less_than_equal", ">=": "greater_than_equal", "<": "less_than", ">": "greater_than", } def _coerce_version(self, version): if not isinstance(version, LegacyVersion): version = LegacyVersion(str(version)) return version def _compare_equal(self, prospective, spec): return prospective == self._coerce_version(spec) def _compare_not_equal(self, prospective, spec): return prospective != self._coerce_version(spec) def _compare_less_than_equal(self, prospective, spec): return prospective <= self._coerce_version(spec) def _compare_greater_than_equal(self, prospective, spec): return prospective >= self._coerce_version(spec) def _compare_less_than(self, prospective, spec): return prospective < self._coerce_version(spec) def _compare_greater_than(self, prospective, spec): return prospective > self._coerce_version(spec) def _require_version_compare(fn): @functools.wraps(fn) def wrapped(self, prospective, spec): if not isinstance(prospective, Version): return False return fn(self, prospective, spec) return wrapped class Specifier(_IndividualSpecifier): _regex_str = ( r""" (?P<operator>(~=|==|!=|<=|>=|<|>|===)) (?P<version> (?: # The identity operators allow for an escape hatch that will # do an exact string match of the version you wish to install. # This will not be parsed by PEP 440 and we cannot determine # any semantic meaning from it. This operator is discouraged # but included entirely as an escape hatch. (?<====) # Only match for the identity operator \s* [^\s]* # We just match everything, except for whitespace # since we are only testing for strict identity. ) | (?: # The (non)equality operators allow for wild card and local # versions to be specified so we have to define these two # operators separately to enable that. (?<===|!=) # Only match for equals and not equals \s* v? (?:[0-9]+!)? # epoch [0-9]+(?:\.[0-9]+)* # release (?: # pre release [-_\.]? (a|b|c|rc|alpha|beta|pre|preview) [-_\.]? [0-9]* )? (?: # post release (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*) )? # You cannot use a wild card and a dev or local version # together so group them with a | and make them optional. (?: (?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release (?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)? # local | \.\* # Wild card syntax of .* )? ) | (?: # The compatible operator requires at least two digits in the # release segment. (?<=~=) # Only match for the compatible operator \s* v? (?:[0-9]+!)? # epoch [0-9]+(?:\.[0-9]+)+ # release (We have a + instead of a *) (?: # pre release [-_\.]? (a|b|c|rc|alpha|beta|pre|preview) [-_\.]? [0-9]* )? (?: # post release (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*) )? (?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release ) | (?: # All other operators only allow a sub set of what the # (non)equality operators do. Specifically they do not allow # local versions to be specified nor do they allow the prefix # matching wild cards. (?<!==|!=|~=) # We have special cases for these # operators so we want to make sure they # don't match here. \s* v? (?:[0-9]+!)? # epoch [0-9]+(?:\.[0-9]+)* # release (?: # pre release [-_\.]? (a|b|c|rc|alpha|beta|pre|preview) [-_\.]? [0-9]* )? (?: # post release (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*) )? (?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release ) ) """ ) _regex = re.compile( r"^\s*" + _regex_str + r"\s*$", re.VERBOSE | re.IGNORECASE) _operators = { "~=": "compatible", "==": "equal", "!=": "not_equal", "<=": "less_than_equal", ">=": "greater_than_equal", "<": "less_than", ">": "greater_than", "===": "arbitrary", } @_require_version_compare def _compare_compatible(self, prospective, spec): # Compatible releases have an equivalent combination of >= and ==. That # is that ~=2.2 is equivalent to >=2.2,==2.*. This allows us to # implement this in terms of the other specifiers instead of # implementing it ourselves. The only thing we need to do is construct # the other specifiers. # We want everything but the last item in the version, but we want to # ignore post and dev releases and we want to treat the pre-release as # it's own separate segment. prefix = ".".join( list( itertools.takewhile( lambda x: (not x.startswith("post") and not x.startswith("dev")), _version_split(spec), ) )[:-1] ) # Add the prefix notation to the end of our string prefix += ".*" return (self._get_operator(">=")(prospective, spec) and self._get_operator("==")(prospective, prefix)) @_require_version_compare def _compare_equal(self, prospective, spec): # We need special logic to handle prefix matching if spec.endswith(".*"): # In the case of prefix matching we want to ignore local segment. prospective = Version(prospective.public) # Split the spec out by dots, and pretend that there is an implicit # dot in between a release segment and a pre-release segment. spec = _version_split(spec[:-2]) # Remove the trailing .* # Split the prospective version out by dots, and pretend that there # is an implicit dot in between a release segment and a pre-release # segment. prospective = _version_split(str(prospective)) # Shorten the prospective version to be the same length as the spec # so that we can determine if the specifier is a prefix of the # prospective version or not. prospective = prospective[:len(spec)] # Pad out our two sides with zeros so that they both equal the same # length. spec, prospective = _pad_version(spec, prospective) else: # Convert our spec string into a Version spec = Version(spec) # If the specifier does not have a local segment, then we want to # act as if the prospective version also does not have a local # segment. if not spec.local: prospective = Version(prospective.public) return prospective == spec @_require_version_compare def _compare_not_equal(self, prospective, spec): return not self._compare_equal(prospective, spec) @_require_version_compare def _compare_less_than_equal(self, prospective, spec): return prospective <= Version(spec) @_require_version_compare def _compare_greater_than_equal(self, prospective, spec): return prospective >= Version(spec) @_require_version_compare def _compare_less_than(self, prospective, spec): # Convert our spec to a Version instance, since we'll want to work with # it as a version. spec = Version(spec) # Check to see if the prospective version is less than the spec # version. If it's not we can short circuit and just return False now # instead of doing extra unneeded work. if not prospective < spec: return False # This special case is here so that, unless the specifier itself # includes is a pre-release version, that we do not accept pre-release # versions for the version mentioned in the specifier (e.g. <3.1 should # not match 3.1.dev0, but should match 3.0.dev0). if not spec.is_prerelease and prospective.is_prerelease: if Version(prospective.base_version) == Version(spec.base_version): return False # If we've gotten to here, it means that prospective version is both # less than the spec version *and* it's not a pre-release of the same # version in the spec. return True @_require_version_compare def _compare_greater_than(self, prospective, spec): # Convert our spec to a Version instance, since we'll want to work with # it as a version. spec = Version(spec) # Check to see if the prospective version is greater than the spec # version. If it's not we can short circuit and just return False now # instead of doing extra unneeded work. if not prospective > spec: return False # This special case is here so that, unless the specifier itself # includes is a post-release version, that we do not accept # post-release versions for the version mentioned in the specifier # (e.g. >3.1 should not match 3.0.post0, but should match 3.2.post0). if not spec.is_postrelease and prospective.is_postrelease: if Version(prospective.base_version) == Version(spec.base_version): return False # Ensure that we do not allow a local version of the version mentioned # in the specifier, which is techincally greater than, to match. if prospective.local is not None: if Version(prospective.base_version) == Version(spec.base_version): return False # If we've gotten to here, it means that prospective version is both # greater than the spec version *and* it's not a pre-release of the # same version in the spec. return True def _compare_arbitrary(self, prospective, spec): return str(prospective).lower() == str(spec).lower() @property def prereleases(self): # If there is an explicit prereleases set for this, then we'll just # blindly use that. if self._prereleases is not None: return self._prereleases # Look at all of our specifiers and determine if they are inclusive # operators, and if they are if they are including an explicit # prerelease. operator, version = self._spec if operator in ["==", ">=", "<=", "~=", "==="]: # The == specifier can include a trailing .*, if it does we # want to remove before parsing. if operator == "==" and version.endswith(".*"): version = version[:-2] # Parse the version, and if it is a pre-release than this # specifier allows pre-releases. if parse(version).is_prerelease: return True return False @prereleases.setter def prereleases(self, value): self._prereleases = value _prefix_regex = re.compile(r"^([0-9]+)((?:a|b|c|rc)[0-9]+)$") def _version_split(version): result = [] for item in version.split("."): match = _prefix_regex.search(item) if match: result.extend(match.groups()) else: result.append(item) return result def _pad_version(left, right): left_split, right_split = [], [] # Get the release segment of our versions left_split.append(list(itertools.takewhile(lambda x: x.isdigit(), left))) right_split.append(list(itertools.takewhile(lambda x: x.isdigit(), right))) # Get the rest of our versions left_split.append(left[len(left_split[0]):]) right_split.append(right[len(right_split[0]):]) # Insert our padding left_split.insert( 1, ["0"] * max(0, len(right_split[0]) - len(left_split[0])), ) right_split.insert( 1, ["0"] * max(0, len(left_split[0]) - len(right_split[0])), ) return ( list(itertools.chain(*left_split)), list(itertools.chain(*right_split)), ) class SpecifierSet(BaseSpecifier): def __init__(self, specifiers="", prereleases=None): # Split on , to break each indidivual specifier into it's own item, and # strip each item to remove leading/trailing whitespace. specifiers = [s.strip() for s in specifiers.split(",") if s.strip()] # Parsed each individual specifier, attempting first to make it a # Specifier and falling back to a LegacySpecifier. parsed = set() for specifier in specifiers: try: parsed.add(Specifier(specifier)) except InvalidSpecifier: parsed.add(LegacySpecifier(specifier)) # Turn our parsed specifiers into a frozen set and save them for later. self._specs = frozenset(parsed) # Store our prereleases value so we can use it later to determine if # we accept prereleases or not. self._prereleases = prereleases def __repr__(self): pre = ( ", prereleases={0!r}".format(self.prereleases) if self._prereleases is not None else "" ) return "<SpecifierSet({0!r}{1})>".format(str(self), pre) def __str__(self): return ",".join(sorted(str(s) for s in self._specs)) def __hash__(self): return hash(self._specs) def __and__(self, other): if isinstance(other, string_types): other = SpecifierSet(other) elif not isinstance(other, SpecifierSet): return NotImplemented specifier = SpecifierSet() specifier._specs = frozenset(self._specs | other._specs) if self._prereleases is None and other._prereleases is not None: specifier._prereleases = other._prereleases elif self._prereleases is not None and other._prereleases is None: specifier._prereleases = self._prereleases elif self._prereleases == other._prereleases: specifier._prereleases = self._prereleases else: raise ValueError( "Cannot combine SpecifierSets with True and False prerelease " "overrides." ) return specifier def __eq__(self, other): if isinstance(other, string_types): other = SpecifierSet(other) elif isinstance(other, _IndividualSpecifier): other = SpecifierSet(str(other)) elif not isinstance(other, SpecifierSet): return NotImplemented return self._specs == other._specs def __ne__(self, other): if isinstance(other, string_types): other = SpecifierSet(other) elif isinstance(other, _IndividualSpecifier): other = SpecifierSet(str(other)) elif not isinstance(other, SpecifierSet): return NotImplemented return self._specs != other._specs def __len__(self): return len(self._specs) def __iter__(self): return iter(self._specs) @property def prereleases(self): # If we have been given an explicit prerelease modifier, then we'll # pass that through here. if self._prereleases is not None: return self._prereleases # If we don't have any specifiers, and we don't have a forced value, # then we'll just return None since we don't know if this should have # pre-releases or not. if not self._specs: return None # Otherwise we'll see if any of the given specifiers accept # prereleases, if any of them do we'll return True, otherwise False. return any(s.prereleases for s in self._specs) @prereleases.setter def prereleases(self, value): self._prereleases = value def __contains__(self, item): return self.contains(item) def contains(self, item, prereleases=None): # Ensure that our item is a Version or LegacyVersion instance. if not isinstance(item, (LegacyVersion, Version)): item = parse(item) # Determine if we're forcing a prerelease or not, if we're not forcing # one for this particular filter call, then we'll use whatever the # SpecifierSet thinks for whether or not we should support prereleases. if prereleases is None: prereleases = self.prereleases # We can determine if we're going to allow pre-releases by looking to # see if any of the underlying items supports them. If none of them do # and this item is a pre-release then we do not allow it and we can # short circuit that here. # Note: This means that 1.0.dev1 would not be contained in something # like >=1.0.devabc however it would be in >=1.0.debabc,>0.0.dev0 if not prereleases and item.is_prerelease: return False # We simply dispatch to the underlying specs here to make sure that the # given version is contained within all of them. # Note: This use of all() here means that an empty set of specifiers # will always return True, this is an explicit design decision. return all( s.contains(item, prereleases=prereleases) for s in self._specs ) def filter(self, iterable, prereleases=None): # Determine if we're forcing a prerelease or not, if we're not forcing # one for this particular filter call, then we'll use whatever the # SpecifierSet thinks for whether or not we should support prereleases. if prereleases is None: prereleases = self.prereleases # If we have any specifiers, then we want to wrap our iterable in the # filter method for each one, this will act as a logical AND amongst # each specifier. if self._specs: for spec in self._specs: iterable = spec.filter(iterable, prereleases=bool(prereleases)) return iterable # If we do not have any specifiers, then we need to have a rough filter # which will filter out any pre-releases, unless there are no final # releases, and which will filter out LegacyVersion in general. else: filtered = [] found_prereleases = [] for item in iterable: # Ensure that we some kind of Version class for this item. if not isinstance(item, (LegacyVersion, Version)): parsed_version = parse(item) else: parsed_version = item # Filter out any item which is parsed as a LegacyVersion if isinstance(parsed_version, LegacyVersion): continue # Store any item which is a pre-release for later unless we've # already found a final version or we are accepting prereleases if parsed_version.is_prerelease and not prereleases: if not filtered: found_prereleases.append(item) else: filtered.append(item) # If we've found no items except for pre-releases, then we'll go # ahead and use the pre-releases if not filtered and found_prereleases and prereleases is None: return found_prereleases return filtered
mit
[ 3, 961, 570, 365, 21164, 18233, 1334, 314, 2895, 402, 314, 3668, 844, 12, 3394, 199, 3, 499, 14, 16, 12, 436, 314, 6289, 844, 14, 1666, 314, 5113, 570, 315, 314, 1738, 402, 642, 7611, 199, 3, 367, 4890, 2436, 14, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 199, 646, 13022, 199, 646, 9143, 199, 646, 7975, 199, 646, 295, 199, 199, 504, 13653, 5819, 492, 1059, 63, 1313, 12, 543, 63, 6577, 199, 504, 1275, 1023, 492, 3394, 12, 26251, 3353, 12, 2198, 421, 199, 533, 6378, 6154, 3895, 8, 3393, 304, 272, 408, 272, 1626, 3866, 16628, 1990, 1911, 12, 4390, 1077, 10618, 370, 13663, 841, 2167, 14, 272, 408, 421, 199, 533, 3523, 6154, 3895, 8, 1045, 63, 6577, 8, 3175, 14, 22254, 12, 909, 2298, 339, 768, 3175, 14, 10315, 272, 347, 636, 495, 721, 277, 304, 267, 408, 267, 1803, 314, 620, 6025, 402, 642, 5367, 3895, 2839, 909, 14, 961, 267, 1077, 506, 2954, 1905, 402, 314, 5367, 3895, 6337, 14, 267, 408, 339, 768, 3175, 14, 10315, 272, 347, 636, 2227, 721, 277, 304, 267, 408, 267, 1803, 282, 2631, 574, 367, 642, 5367, 3895, 2839, 909, 14, 267, 408, 339, 768, 3175, 14, 10315, 272, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 408, 267, 1803, 282, 5046, 6144, 3775, 503, 440, 314, 2877, 5367, 3895, 2839, 267, 2251, 787, 4472, 14, 267, 408, 339, 768, 3175, 14, 10315, 272, 347, 636, 685, 721, 277, 12, 1163, 304, 267, 408, 267, 1803, 282, 5046, 6144, 3775, 503, 440, 314, 2877, 5367, 3895, 2839, 267, 2251, 787, 440, 4472, 14, 267, 408, 339, 768, 3175, 14, 6198, 1829, 272, 347, 24045, 8, 277, 304, 267, 408, 267, 1803, 3775, 503, 440, 876, 13, 11840, 465, 282, 8852, 787, 4370, 701, 642, 267, 16628, 14, 267, 408, 339, 768, 25648, 14, 8345, 272, 347, 24045, 8, 277, 12, 574, 304, 267, 408, 267, 10729, 3775, 503, 440, 876, 13, 11840, 465, 282, 8852, 787, 4370, 701, 642, 267, 16628, 14, 267, 408, 339, 768, 3175, 14, 10315, 272, 347, 3509, 8, 277, 12, 1242, 12, 24045, 29, 403, 304, 267, 408, 267, 22391, 340, 314, 1627, 1242, 365, 10470, 4453, 642, 16628, 14, 267, 408, 339, 768, 3175, 14, 10315, 272, 347, 2457, 8, 277, 12, 6076, 12, 24045, 29, 403, 304, 267, 408, 267, 17415, 376, 6076, 402, 2974, 436, 4766, 3062, 880, 626, 1454, 2974, 1314, 267, 787, 10470, 4453, 642, 16628, 787, 4370, 315, 652, 14, 267, 408, 421, 199, 533, 485, 28604, 6154, 3895, 8, 1563, 6154, 3895, 304, 339, 485, 12688, 275, 1052, 339, 347, 636, 826, 721, 277, 12, 3158, 8772, 24045, 29, 403, 304, 267, 1336, 275, 291, 423, 3821, 14, 1733, 8, 1650, 9, 267, 340, 440, 1336, 26, 288, 746, 6378, 6154, 3895, 480, 3364, 16628, 26, 5041, 16, 30366, 908, 8, 1650, 430, 398, 291, 423, 1650, 275, 334, 288, 1336, 14, 923, 480, 3856, 3471, 1913, 1062, 288, 1336, 14, 923, 480, 1023, 3471, 1913, 1062, 267, 776, 398, 327, 13874, 3775, 503, 440, 642, 5367, 3895, 1077, 4729, 24045, 267, 291, 423, 25648, 275, 24045, 339, 347, 636, 2722, 721, 277, 304, 267, 876, 275, 334, 288, 3872, 24045, 3126, 16, 1, 82, 5469, 908, 8, 277, 14, 25648, 9, 288, 340, 291, 423, 25648, 365, 440, 488, 288, 587, 3087, 267, 776, 398, 372, 3886, 91, 16, 93, 2561, 17, 1, 82, 8847, 18, 1552, 23167, 908, 8, 288, 291, 855, 533, 4914, 354, 3108, 288, 620, 8, 277, 395, 288, 876, 12, 267, 776, 339, 347, 636, 495, 721, 277, 304, 267, 372, 5310, 16, 8847, 17, 5469, 908, 2031, 277, 423, 1650, 9, 339, 347, 636, 2227, 721, 277, 304, 267, 372, 2631, 8, 277, 423, 1650, 9, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 340, 1228, 8, 1848, 12, 1059, 63, 1313, 304, 288, 862, 26, 355, 1163, 275, 291, 855, 533, 721, 1848, 9, 288, 871, 6378, 6154, 3895, 26, 355, 372, 3784, 267, 916, 440, 1228, 8, 1848, 12, 291, 855, 533, 18580, 288, 372, 3784, 398, 372, 291, 423, 1650, 508, 1163, 423, 1650, 339, 347, 636, 685, 721, 277, 12, 1163, 304, 267, 340, 1228, 8, 1848, 12, 1059, 63, 1313, 304, 288, 862, 26, 355, 1163, 275, 291, 855, 533, 721, 1848, 9, 288, 871, 6378, 6154, 3895, 26, 355, 372, 3784, 267, 916, 440, 1228, 8, 1848, 12, 291, 855, 533, 18580, 288, 372, 3784, 398, 372, 291, 423, 1650, 1137, 1163, 423, 1650, 339, 347, 485, 362, 63, 3856, 8, 277, 12, 1687, 304, 267, 372, 2519, 8, 277, 12, 2668, 5785, 7348, 16, 5469, 908, 8, 277, 423, 12688, 59, 411, 2459, 339, 347, 485, 14141, 63, 1023, 8, 277, 12, 1015, 304, 267, 340, 440, 1228, 8, 1023, 12, 334, 22628, 3353, 12, 3394, 2298, 288, 1015, 275, 2198, 8, 1023, 9, 267, 372, 1015, 339, 768, 1829, 272, 347, 4182, 8, 277, 304, 267, 372, 291, 423, 1650, 59, 16, 61, 339, 768, 1829, 272, 347, 1015, 8, 277, 304, 267, 372, 291, 423, 1650, 59, 17, 61, 339, 768, 1829, 272, 347, 24045, 8, 277, 304, 267, 372, 291, 423, 25648, 339, 768, 25648, 14, 8345, 272, 347, 24045, 8, 277, 12, 574, 304, 267, 291, 423, 25648, 275, 574, 339, 347, 636, 6134, 721, 277, 12, 1242, 304, 267, 372, 291, 14, 6134, 8, 1053, 9, 339, 347, 3509, 8, 277, 12, 1242, 12, 24045, 29, 403, 304, 267, 327, 14703, 340, 24045, 787, 370, 506, 4370, 503, 440, 14, 267, 340, 24045, 365, 488, 26, 288, 24045, 275, 291, 14, 25648, 398, 327, 21017, 1242, 370, 282, 3394, 503, 26251, 3353, 12, 642, 6127, 2739, 370, 1172, 267, 327, 282, 17522, 367, 25916, 18, 14, 16, 2, 315, 5367, 3895, 480, 8119, 18, 531, 267, 1242, 275, 291, 423, 14141, 63, 1023, 8, 1053, 9, 398, 327, 14703, 340, 781, 1077, 506, 21038, 24045, 315, 642, 16628, 267, 327, 503, 440, 12, 340, 781, 886, 440, 2291, 24045, 2419, 781, 883, 3974, 20304, 267, 327 ]
[ 961, 570, 365, 21164, 18233, 1334, 314, 2895, 402, 314, 3668, 844, 12, 3394, 199, 3, 499, 14, 16, 12, 436, 314, 6289, 844, 14, 1666, 314, 5113, 570, 315, 314, 1738, 402, 642, 7611, 199, 3, 367, 4890, 2436, 14, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 199, 646, 13022, 199, 646, 9143, 199, 646, 7975, 199, 646, 295, 199, 199, 504, 13653, 5819, 492, 1059, 63, 1313, 12, 543, 63, 6577, 199, 504, 1275, 1023, 492, 3394, 12, 26251, 3353, 12, 2198, 421, 199, 533, 6378, 6154, 3895, 8, 3393, 304, 272, 408, 272, 1626, 3866, 16628, 1990, 1911, 12, 4390, 1077, 10618, 370, 13663, 841, 2167, 14, 272, 408, 421, 199, 533, 3523, 6154, 3895, 8, 1045, 63, 6577, 8, 3175, 14, 22254, 12, 909, 2298, 339, 768, 3175, 14, 10315, 272, 347, 636, 495, 721, 277, 304, 267, 408, 267, 1803, 314, 620, 6025, 402, 642, 5367, 3895, 2839, 909, 14, 961, 267, 1077, 506, 2954, 1905, 402, 314, 5367, 3895, 6337, 14, 267, 408, 339, 768, 3175, 14, 10315, 272, 347, 636, 2227, 721, 277, 304, 267, 408, 267, 1803, 282, 2631, 574, 367, 642, 5367, 3895, 2839, 909, 14, 267, 408, 339, 768, 3175, 14, 10315, 272, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 408, 267, 1803, 282, 5046, 6144, 3775, 503, 440, 314, 2877, 5367, 3895, 2839, 267, 2251, 787, 4472, 14, 267, 408, 339, 768, 3175, 14, 10315, 272, 347, 636, 685, 721, 277, 12, 1163, 304, 267, 408, 267, 1803, 282, 5046, 6144, 3775, 503, 440, 314, 2877, 5367, 3895, 2839, 267, 2251, 787, 440, 4472, 14, 267, 408, 339, 768, 3175, 14, 6198, 1829, 272, 347, 24045, 8, 277, 304, 267, 408, 267, 1803, 3775, 503, 440, 876, 13, 11840, 465, 282, 8852, 787, 4370, 701, 642, 267, 16628, 14, 267, 408, 339, 768, 25648, 14, 8345, 272, 347, 24045, 8, 277, 12, 574, 304, 267, 408, 267, 10729, 3775, 503, 440, 876, 13, 11840, 465, 282, 8852, 787, 4370, 701, 642, 267, 16628, 14, 267, 408, 339, 768, 3175, 14, 10315, 272, 347, 3509, 8, 277, 12, 1242, 12, 24045, 29, 403, 304, 267, 408, 267, 22391, 340, 314, 1627, 1242, 365, 10470, 4453, 642, 16628, 14, 267, 408, 339, 768, 3175, 14, 10315, 272, 347, 2457, 8, 277, 12, 6076, 12, 24045, 29, 403, 304, 267, 408, 267, 17415, 376, 6076, 402, 2974, 436, 4766, 3062, 880, 626, 1454, 2974, 1314, 267, 787, 10470, 4453, 642, 16628, 787, 4370, 315, 652, 14, 267, 408, 421, 199, 533, 485, 28604, 6154, 3895, 8, 1563, 6154, 3895, 304, 339, 485, 12688, 275, 1052, 339, 347, 636, 826, 721, 277, 12, 3158, 8772, 24045, 29, 403, 304, 267, 1336, 275, 291, 423, 3821, 14, 1733, 8, 1650, 9, 267, 340, 440, 1336, 26, 288, 746, 6378, 6154, 3895, 480, 3364, 16628, 26, 5041, 16, 30366, 908, 8, 1650, 430, 398, 291, 423, 1650, 275, 334, 288, 1336, 14, 923, 480, 3856, 3471, 1913, 1062, 288, 1336, 14, 923, 480, 1023, 3471, 1913, 1062, 267, 776, 398, 327, 13874, 3775, 503, 440, 642, 5367, 3895, 1077, 4729, 24045, 267, 291, 423, 25648, 275, 24045, 339, 347, 636, 2722, 721, 277, 304, 267, 876, 275, 334, 288, 3872, 24045, 3126, 16, 1, 82, 5469, 908, 8, 277, 14, 25648, 9, 288, 340, 291, 423, 25648, 365, 440, 488, 288, 587, 3087, 267, 776, 398, 372, 3886, 91, 16, 93, 2561, 17, 1, 82, 8847, 18, 1552, 23167, 908, 8, 288, 291, 855, 533, 4914, 354, 3108, 288, 620, 8, 277, 395, 288, 876, 12, 267, 776, 339, 347, 636, 495, 721, 277, 304, 267, 372, 5310, 16, 8847, 17, 5469, 908, 2031, 277, 423, 1650, 9, 339, 347, 636, 2227, 721, 277, 304, 267, 372, 2631, 8, 277, 423, 1650, 9, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 340, 1228, 8, 1848, 12, 1059, 63, 1313, 304, 288, 862, 26, 355, 1163, 275, 291, 855, 533, 721, 1848, 9, 288, 871, 6378, 6154, 3895, 26, 355, 372, 3784, 267, 916, 440, 1228, 8, 1848, 12, 291, 855, 533, 18580, 288, 372, 3784, 398, 372, 291, 423, 1650, 508, 1163, 423, 1650, 339, 347, 636, 685, 721, 277, 12, 1163, 304, 267, 340, 1228, 8, 1848, 12, 1059, 63, 1313, 304, 288, 862, 26, 355, 1163, 275, 291, 855, 533, 721, 1848, 9, 288, 871, 6378, 6154, 3895, 26, 355, 372, 3784, 267, 916, 440, 1228, 8, 1848, 12, 291, 855, 533, 18580, 288, 372, 3784, 398, 372, 291, 423, 1650, 1137, 1163, 423, 1650, 339, 347, 485, 362, 63, 3856, 8, 277, 12, 1687, 304, 267, 372, 2519, 8, 277, 12, 2668, 5785, 7348, 16, 5469, 908, 8, 277, 423, 12688, 59, 411, 2459, 339, 347, 485, 14141, 63, 1023, 8, 277, 12, 1015, 304, 267, 340, 440, 1228, 8, 1023, 12, 334, 22628, 3353, 12, 3394, 2298, 288, 1015, 275, 2198, 8, 1023, 9, 267, 372, 1015, 339, 768, 1829, 272, 347, 4182, 8, 277, 304, 267, 372, 291, 423, 1650, 59, 16, 61, 339, 768, 1829, 272, 347, 1015, 8, 277, 304, 267, 372, 291, 423, 1650, 59, 17, 61, 339, 768, 1829, 272, 347, 24045, 8, 277, 304, 267, 372, 291, 423, 25648, 339, 768, 25648, 14, 8345, 272, 347, 24045, 8, 277, 12, 574, 304, 267, 291, 423, 25648, 275, 574, 339, 347, 636, 6134, 721, 277, 12, 1242, 304, 267, 372, 291, 14, 6134, 8, 1053, 9, 339, 347, 3509, 8, 277, 12, 1242, 12, 24045, 29, 403, 304, 267, 327, 14703, 340, 24045, 787, 370, 506, 4370, 503, 440, 14, 267, 340, 24045, 365, 488, 26, 288, 24045, 275, 291, 14, 25648, 398, 327, 21017, 1242, 370, 282, 3394, 503, 26251, 3353, 12, 642, 6127, 2739, 370, 1172, 267, 327, 282, 17522, 367, 25916, 18, 14, 16, 2, 315, 5367, 3895, 480, 8119, 18, 531, 267, 1242, 275, 291, 423, 14141, 63, 1023, 8, 1053, 9, 398, 327, 14703, 340, 781, 1077, 506, 21038, 24045, 315, 642, 16628, 267, 327, 503, 440, 12, 340, 781, 886, 440, 2291, 24045, 2419, 781, 883, 3974, 20304, 267, 327, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
40023154/2015cd_midterm
static/Brython3.1.1-20150328-091302/Lib/xml/dom/minidom.py
727
66854
"""Simple implementation of the Level 1 DOM. Namespaces and other minor Level 2 features are also supported. parse("foo.xml") parseString("<foo><bar/></foo>") Todo: ===== * convenience methods for getting elements and text. * more testing * bring some of the writer and linearizer code into conformance with this interface * SAX 2 namespaces """ import io import xml.dom from xml.dom import EMPTY_NAMESPACE, EMPTY_PREFIX, XMLNS_NAMESPACE, domreg from xml.dom.minicompat import * from xml.dom.xmlbuilder import DOMImplementationLS, DocumentLS # This is used by the ID-cache invalidation checks; the list isn't # actually complete, since the nodes being checked will never be the # DOCUMENT_NODE or DOCUMENT_FRAGMENT_NODE. (The node being checked is # the node being added or removed, not the node being modified.) # _nodeTypes_with_children = (xml.dom.Node.ELEMENT_NODE, xml.dom.Node.ENTITY_REFERENCE_NODE) class Node(xml.dom.Node): namespaceURI = None # this is non-null only for elements and attributes parentNode = None ownerDocument = None nextSibling = None previousSibling = None prefix = EMPTY_PREFIX # non-null only for NS elements and attributes def __bool__(self): return True def toxml(self, encoding=None): return self.toprettyxml("", "", encoding) def toprettyxml(self, indent="\t", newl="\n", encoding=None): if encoding is None: writer = io.StringIO() else: writer = io.TextIOWrapper(io.BytesIO(), encoding=encoding, errors="xmlcharrefreplace", newline='\n') if self.nodeType == Node.DOCUMENT_NODE: # Can pass encoding only to document, to put it into XML header self.writexml(writer, "", indent, newl, encoding) else: self.writexml(writer, "", indent, newl) if encoding is None: return writer.getvalue() else: return writer.detach().getvalue() def hasChildNodes(self): return bool(self.childNodes) def _get_childNodes(self): return self.childNodes def _get_firstChild(self): if self.childNodes: return self.childNodes[0] def _get_lastChild(self): if self.childNodes: return self.childNodes[-1] def insertBefore(self, newChild, refChild): if newChild.nodeType == self.DOCUMENT_FRAGMENT_NODE: for c in tuple(newChild.childNodes): self.insertBefore(c, refChild) ### The DOM does not clearly specify what to return in this case return newChild if newChild.nodeType not in self._child_node_types: raise xml.dom.HierarchyRequestErr( "%s cannot be child of %s" % (repr(newChild), repr(self))) if newChild.parentNode is not None: newChild.parentNode.removeChild(newChild) if refChild is None: self.appendChild(newChild) else: try: index = self.childNodes.index(refChild) except ValueError: raise xml.dom.NotFoundErr() if newChild.nodeType in _nodeTypes_with_children: _clear_id_cache(self) self.childNodes.insert(index, newChild) newChild.nextSibling = refChild refChild.previousSibling = newChild if index: node = self.childNodes[index-1] node.nextSibling = newChild newChild.previousSibling = node else: newChild.previousSibling = None newChild.parentNode = self return newChild def appendChild(self, node): if node.nodeType == self.DOCUMENT_FRAGMENT_NODE: for c in tuple(node.childNodes): self.appendChild(c) ### The DOM does not clearly specify what to return in this case return node if node.nodeType not in self._child_node_types: raise xml.dom.HierarchyRequestErr( "%s cannot be child of %s" % (repr(node), repr(self))) elif node.nodeType in _nodeTypes_with_children: _clear_id_cache(self) if node.parentNode is not None: node.parentNode.removeChild(node) _append_child(self, node) node.nextSibling = None return node def replaceChild(self, newChild, oldChild): if newChild.nodeType == self.DOCUMENT_FRAGMENT_NODE: refChild = oldChild.nextSibling self.removeChild(oldChild) return self.insertBefore(newChild, refChild) if newChild.nodeType not in self._child_node_types: raise xml.dom.HierarchyRequestErr( "%s cannot be child of %s" % (repr(newChild), repr(self))) if newChild is oldChild: return if newChild.parentNode is not None: newChild.parentNode.removeChild(newChild) try: index = self.childNodes.index(oldChild) except ValueError: raise xml.dom.NotFoundErr() self.childNodes[index] = newChild newChild.parentNode = self oldChild.parentNode = None if (newChild.nodeType in _nodeTypes_with_children or oldChild.nodeType in _nodeTypes_with_children): _clear_id_cache(self) newChild.nextSibling = oldChild.nextSibling newChild.previousSibling = oldChild.previousSibling oldChild.nextSibling = None oldChild.previousSibling = None if newChild.previousSibling: newChild.previousSibling.nextSibling = newChild if newChild.nextSibling: newChild.nextSibling.previousSibling = newChild return oldChild def removeChild(self, oldChild): try: self.childNodes.remove(oldChild) except ValueError: raise xml.dom.NotFoundErr() if oldChild.nextSibling is not None: oldChild.nextSibling.previousSibling = oldChild.previousSibling if oldChild.previousSibling is not None: oldChild.previousSibling.nextSibling = oldChild.nextSibling oldChild.nextSibling = oldChild.previousSibling = None if oldChild.nodeType in _nodeTypes_with_children: _clear_id_cache(self) oldChild.parentNode = None return oldChild def normalize(self): L = [] for child in self.childNodes: if child.nodeType == Node.TEXT_NODE: if not child.data: # empty text node; discard if L: L[-1].nextSibling = child.nextSibling if child.nextSibling: child.nextSibling.previousSibling = child.previousSibling child.unlink() elif L and L[-1].nodeType == child.nodeType: # collapse text node node = L[-1] node.data = node.data + child.data node.nextSibling = child.nextSibling if child.nextSibling: child.nextSibling.previousSibling = node child.unlink() else: L.append(child) else: L.append(child) if child.nodeType == Node.ELEMENT_NODE: child.normalize() self.childNodes[:] = L def cloneNode(self, deep): return _clone_node(self, deep, self.ownerDocument or self) def isSupported(self, feature, version): return self.ownerDocument.implementation.hasFeature(feature, version) def _get_localName(self): # Overridden in Element and Attr where localName can be Non-Null return None # Node interfaces from Level 3 (WD 9 April 2002) def isSameNode(self, other): return self is other def getInterface(self, feature): if self.isSupported(feature, None): return self else: return None # The "user data" functions use a dictionary that is only present # if some user data has been set, so be careful not to assume it # exists. def getUserData(self, key): try: return self._user_data[key][0] except (AttributeError, KeyError): return None def setUserData(self, key, data, handler): old = None try: d = self._user_data except AttributeError: d = {} self._user_data = d if key in d: old = d[key][0] if data is None: # ignore handlers passed for None handler = None if old is not None: del d[key] else: d[key] = (data, handler) return old def _call_user_data_handler(self, operation, src, dst): if hasattr(self, "_user_data"): for key, (data, handler) in list(self._user_data.items()): if handler is not None: handler.handle(operation, key, data, src, dst) # minidom-specific API: def unlink(self): self.parentNode = self.ownerDocument = None if self.childNodes: for child in self.childNodes: child.unlink() self.childNodes = NodeList() self.previousSibling = None self.nextSibling = None # A Node is its own context manager, to ensure that an unlink() call occurs. # This is similar to how a file object works. def __enter__(self): return self def __exit__(self, et, ev, tb): self.unlink() defproperty(Node, "firstChild", doc="First child node, or None.") defproperty(Node, "lastChild", doc="Last child node, or None.") defproperty(Node, "localName", doc="Namespace-local name of this node.") def _append_child(self, node): # fast path with less checks; usable by DOM builders if careful childNodes = self.childNodes if childNodes: last = childNodes[-1] node.previousSibling = last last.nextSibling = node childNodes.append(node) node.parentNode = self def _in_document(node): # return True iff node is part of a document tree while node is not None: if node.nodeType == Node.DOCUMENT_NODE: return True node = node.parentNode return False def _write_data(writer, data): "Writes datachars to writer." if data: data = data.replace("&", "&amp;").replace("<", "&lt;"). \ replace("\"", "&quot;").replace(">", "&gt;") writer.write(data) def _get_elements_by_tagName_helper(parent, name, rc): for node in parent.childNodes: if node.nodeType == Node.ELEMENT_NODE and \ (name == "*" or node.tagName == name): rc.append(node) _get_elements_by_tagName_helper(node, name, rc) return rc def _get_elements_by_tagName_ns_helper(parent, nsURI, localName, rc): for node in parent.childNodes: if node.nodeType == Node.ELEMENT_NODE: if ((localName == "*" or node.localName == localName) and (nsURI == "*" or node.namespaceURI == nsURI)): rc.append(node) _get_elements_by_tagName_ns_helper(node, nsURI, localName, rc) return rc class DocumentFragment(Node): nodeType = Node.DOCUMENT_FRAGMENT_NODE nodeName = "#document-fragment" nodeValue = None attributes = None parentNode = None _child_node_types = (Node.ELEMENT_NODE, Node.TEXT_NODE, Node.CDATA_SECTION_NODE, Node.ENTITY_REFERENCE_NODE, Node.PROCESSING_INSTRUCTION_NODE, Node.COMMENT_NODE, Node.NOTATION_NODE) def __init__(self): self.childNodes = NodeList() class Attr(Node): __slots__=('_name', '_value', 'namespaceURI', '_prefix', 'childNodes', '_localName', 'ownerDocument', 'ownerElement') nodeType = Node.ATTRIBUTE_NODE attributes = None specified = False _is_id = False _child_node_types = (Node.TEXT_NODE, Node.ENTITY_REFERENCE_NODE) def __init__(self, qName, namespaceURI=EMPTY_NAMESPACE, localName=None, prefix=None): self.ownerElement = None self._name = qName self.namespaceURI = namespaceURI self._prefix = prefix self.childNodes = NodeList() # Add the single child node that represents the value of the attr self.childNodes.append(Text()) # nodeValue and value are set elsewhere def _get_localName(self): try: return self._localName except AttributeError: return self.nodeName.split(":", 1)[-1] def _get_name(self): return self.name def _get_specified(self): return self.specified def _get_name(self): return self._name def _set_name(self, value): self._name = value if self.ownerElement is not None: _clear_id_cache(self.ownerElement) nodeName = name = property(_get_name, _set_name) def _get_value(self): return self._value def _set_value(self, value): self._value = value self.childNodes[0].data = value if self.ownerElement is not None: _clear_id_cache(self.ownerElement) self.childNodes[0].data = value nodeValue = value = property(_get_value, _set_value) def _get_prefix(self): return self._prefix def _set_prefix(self, prefix): nsuri = self.namespaceURI if prefix == "xmlns": if nsuri and nsuri != XMLNS_NAMESPACE: raise xml.dom.NamespaceErr( "illegal use of 'xmlns' prefix for the wrong namespace") self._prefix = prefix if prefix is None: newName = self.localName else: newName = "%s:%s" % (prefix, self.localName) if self.ownerElement: _clear_id_cache(self.ownerElement) self.name = newName prefix = property(_get_prefix, _set_prefix) def unlink(self): # This implementation does not call the base implementation # since most of that is not needed, and the expense of the # method call is not warranted. We duplicate the removal of # children, but that's all we needed from the base class. elem = self.ownerElement if elem is not None: del elem._attrs[self.nodeName] del elem._attrsNS[(self.namespaceURI, self.localName)] if self._is_id: self._is_id = False elem._magic_id_nodes -= 1 self.ownerDocument._magic_id_count -= 1 for child in self.childNodes: child.unlink() del self.childNodes[:] def _get_isId(self): if self._is_id: return True doc = self.ownerDocument elem = self.ownerElement if doc is None or elem is None: return False info = doc._get_elem_info(elem) if info is None: return False if self.namespaceURI: return info.isIdNS(self.namespaceURI, self.localName) else: return info.isId(self.nodeName) def _get_schemaType(self): doc = self.ownerDocument elem = self.ownerElement if doc is None or elem is None: return _no_type info = doc._get_elem_info(elem) if info is None: return _no_type if self.namespaceURI: return info.getAttributeTypeNS(self.namespaceURI, self.localName) else: return info.getAttributeType(self.nodeName) defproperty(Attr, "isId", doc="True if this attribute is an ID.") defproperty(Attr, "localName", doc="Namespace-local name of this attribute.") defproperty(Attr, "schemaType", doc="Schema type for this attribute.") class NamedNodeMap(object): """The attribute list is a transient interface to the underlying dictionaries. Mutations here will change the underlying element's dictionary. Ordering is imposed artificially and does not reflect the order of attributes as found in an input document. """ __slots__ = ('_attrs', '_attrsNS', '_ownerElement') def __init__(self, attrs, attrsNS, ownerElement): self._attrs = attrs self._attrsNS = attrsNS self._ownerElement = ownerElement def _get_length(self): return len(self._attrs) def item(self, index): try: return self[list(self._attrs.keys())[index]] except IndexError: return None def items(self): L = [] for node in self._attrs.values(): L.append((node.nodeName, node.value)) return L def itemsNS(self): L = [] for node in self._attrs.values(): L.append(((node.namespaceURI, node.localName), node.value)) return L def __contains__(self, key): if isinstance(key, str): return key in self._attrs else: return key in self._attrsNS def keys(self): return self._attrs.keys() def keysNS(self): return self._attrsNS.keys() def values(self): return self._attrs.values() def get(self, name, value=None): return self._attrs.get(name, value) __len__ = _get_length def _cmp(self, other): if self._attrs is getattr(other, "_attrs", None): return 0 else: return (id(self) > id(other)) - (id(self) < id(other)) def __eq__(self, other): return self._cmp(other) == 0 def __ge__(self, other): return self._cmp(other) >= 0 def __gt__(self, other): return self._cmp(other) > 0 def __le__(self, other): return self._cmp(other) <= 0 def __lt__(self, other): return self._cmp(other) < 0 def __ne__(self, other): return self._cmp(other) != 0 def __getitem__(self, attname_or_tuple): if isinstance(attname_or_tuple, tuple): return self._attrsNS[attname_or_tuple] else: return self._attrs[attname_or_tuple] # same as set def __setitem__(self, attname, value): if isinstance(value, str): try: node = self._attrs[attname] except KeyError: node = Attr(attname) node.ownerDocument = self._ownerElement.ownerDocument self.setNamedItem(node) node.value = value else: if not isinstance(value, Attr): raise TypeError("value must be a string or Attr object") node = value self.setNamedItem(node) def getNamedItem(self, name): try: return self._attrs[name] except KeyError: return None def getNamedItemNS(self, namespaceURI, localName): try: return self._attrsNS[(namespaceURI, localName)] except KeyError: return None def removeNamedItem(self, name): n = self.getNamedItem(name) if n is not None: _clear_id_cache(self._ownerElement) del self._attrs[n.nodeName] del self._attrsNS[(n.namespaceURI, n.localName)] if hasattr(n, 'ownerElement'): n.ownerElement = None return n else: raise xml.dom.NotFoundErr() def removeNamedItemNS(self, namespaceURI, localName): n = self.getNamedItemNS(namespaceURI, localName) if n is not None: _clear_id_cache(self._ownerElement) del self._attrsNS[(n.namespaceURI, n.localName)] del self._attrs[n.nodeName] if hasattr(n, 'ownerElement'): n.ownerElement = None return n else: raise xml.dom.NotFoundErr() def setNamedItem(self, node): if not isinstance(node, Attr): raise xml.dom.HierarchyRequestErr( "%s cannot be child of %s" % (repr(node), repr(self))) old = self._attrs.get(node.name) if old: old.unlink() self._attrs[node.name] = node self._attrsNS[(node.namespaceURI, node.localName)] = node node.ownerElement = self._ownerElement _clear_id_cache(node.ownerElement) return old def setNamedItemNS(self, node): return self.setNamedItem(node) def __delitem__(self, attname_or_tuple): node = self[attname_or_tuple] _clear_id_cache(node.ownerElement) node.unlink() def __getstate__(self): return self._attrs, self._attrsNS, self._ownerElement def __setstate__(self, state): self._attrs, self._attrsNS, self._ownerElement = state defproperty(NamedNodeMap, "length", doc="Number of nodes in the NamedNodeMap.") AttributeList = NamedNodeMap class TypeInfo(object): __slots__ = 'namespace', 'name' def __init__(self, namespace, name): self.namespace = namespace self.name = name def __repr__(self): if self.namespace: return "<TypeInfo %r (from %r)>" % (self.name, self.namespace) else: return "<TypeInfo %r>" % self.name def _get_name(self): return self.name def _get_namespace(self): return self.namespace _no_type = TypeInfo(None, None) class Element(Node): __slots__=('ownerDocument', 'parentNode', 'tagName', 'nodeName', 'prefix', 'namespaceURI', '_localName', 'childNodes', '_attrs', '_attrsNS', 'nextSibling', 'previousSibling') nodeType = Node.ELEMENT_NODE nodeValue = None schemaType = _no_type _magic_id_nodes = 0 _child_node_types = (Node.ELEMENT_NODE, Node.PROCESSING_INSTRUCTION_NODE, Node.COMMENT_NODE, Node.TEXT_NODE, Node.CDATA_SECTION_NODE, Node.ENTITY_REFERENCE_NODE) def __init__(self, tagName, namespaceURI=EMPTY_NAMESPACE, prefix=None, localName=None): self.parentNode = None self.tagName = self.nodeName = tagName self.prefix = prefix self.namespaceURI = namespaceURI self.childNodes = NodeList() self.nextSibling = self.previousSibling = None # Attribute dictionaries are lazily created # attributes are double-indexed: # tagName -> Attribute # URI,localName -> Attribute # in the future: consider lazy generation # of attribute objects this is too tricky # for now because of headaches with # namespaces. self._attrs = None self._attrsNS = None def _ensure_attributes(self): if self._attrs is None: self._attrs = {} self._attrsNS = {} def _get_localName(self): try: return self._localName except AttributeError: return self.tagName.split(":", 1)[-1] def _get_tagName(self): return self.tagName def unlink(self): if self._attrs is not None: for attr in list(self._attrs.values()): attr.unlink() self._attrs = None self._attrsNS = None Node.unlink(self) def getAttribute(self, attname): if self._attrs is None: return "" try: return self._attrs[attname].value except KeyError: return "" def getAttributeNS(self, namespaceURI, localName): if self._attrsNS is None: return "" try: return self._attrsNS[(namespaceURI, localName)].value except KeyError: return "" def setAttribute(self, attname, value): attr = self.getAttributeNode(attname) if attr is None: attr = Attr(attname) attr.value = value # also sets nodeValue attr.ownerDocument = self.ownerDocument self.setAttributeNode(attr) elif value != attr.value: attr.value = value if attr.isId: _clear_id_cache(self) def setAttributeNS(self, namespaceURI, qualifiedName, value): prefix, localname = _nssplit(qualifiedName) attr = self.getAttributeNodeNS(namespaceURI, localname) if attr is None: attr = Attr(qualifiedName, namespaceURI, localname, prefix) attr.value = value attr.ownerDocument = self.ownerDocument self.setAttributeNode(attr) else: if value != attr.value: attr.value = value if attr.isId: _clear_id_cache(self) if attr.prefix != prefix: attr.prefix = prefix attr.nodeName = qualifiedName def getAttributeNode(self, attrname): if self._attrs is None: return None return self._attrs.get(attrname) def getAttributeNodeNS(self, namespaceURI, localName): if self._attrsNS is None: return None return self._attrsNS.get((namespaceURI, localName)) def setAttributeNode(self, attr): if attr.ownerElement not in (None, self): raise xml.dom.InuseAttributeErr("attribute node already owned") self._ensure_attributes() old1 = self._attrs.get(attr.name, None) if old1 is not None: self.removeAttributeNode(old1) old2 = self._attrsNS.get((attr.namespaceURI, attr.localName), None) if old2 is not None and old2 is not old1: self.removeAttributeNode(old2) _set_attribute_node(self, attr) if old1 is not attr: # It might have already been part of this node, in which case # it doesn't represent a change, and should not be returned. return old1 if old2 is not attr: return old2 setAttributeNodeNS = setAttributeNode def removeAttribute(self, name): if self._attrsNS is None: raise xml.dom.NotFoundErr() try: attr = self._attrs[name] except KeyError: raise xml.dom.NotFoundErr() self.removeAttributeNode(attr) def removeAttributeNS(self, namespaceURI, localName): if self._attrsNS is None: raise xml.dom.NotFoundErr() try: attr = self._attrsNS[(namespaceURI, localName)] except KeyError: raise xml.dom.NotFoundErr() self.removeAttributeNode(attr) def removeAttributeNode(self, node): if node is None: raise xml.dom.NotFoundErr() try: self._attrs[node.name] except KeyError: raise xml.dom.NotFoundErr() _clear_id_cache(self) node.unlink() # Restore this since the node is still useful and otherwise # unlinked node.ownerDocument = self.ownerDocument removeAttributeNodeNS = removeAttributeNode def hasAttribute(self, name): if self._attrs is None: return False return name in self._attrs def hasAttributeNS(self, namespaceURI, localName): if self._attrsNS is None: return False return (namespaceURI, localName) in self._attrsNS def getElementsByTagName(self, name): return _get_elements_by_tagName_helper(self, name, NodeList()) def getElementsByTagNameNS(self, namespaceURI, localName): return _get_elements_by_tagName_ns_helper( self, namespaceURI, localName, NodeList()) def __repr__(self): return "<DOM Element: %s at %#x>" % (self.tagName, id(self)) def writexml(self, writer, indent="", addindent="", newl=""): # indent = current indentation # addindent = indentation to add to higher levels # newl = newline string writer.write(indent+"<" + self.tagName) attrs = self._get_attributes() a_names = sorted(attrs.keys()) for a_name in a_names: writer.write(" %s=\"" % a_name) _write_data(writer, attrs[a_name].value) writer.write("\"") if self.childNodes: writer.write(">") if (len(self.childNodes) == 1 and self.childNodes[0].nodeType == Node.TEXT_NODE): self.childNodes[0].writexml(writer, '', '', '') else: writer.write(newl) for node in self.childNodes: node.writexml(writer, indent+addindent, addindent, newl) writer.write(indent) writer.write("</%s>%s" % (self.tagName, newl)) else: writer.write("/>%s"%(newl)) def _get_attributes(self): self._ensure_attributes() return NamedNodeMap(self._attrs, self._attrsNS, self) def hasAttributes(self): if self._attrs: return True else: return False # DOM Level 3 attributes, based on the 22 Oct 2002 draft def setIdAttribute(self, name): idAttr = self.getAttributeNode(name) self.setIdAttributeNode(idAttr) def setIdAttributeNS(self, namespaceURI, localName): idAttr = self.getAttributeNodeNS(namespaceURI, localName) self.setIdAttributeNode(idAttr) def setIdAttributeNode(self, idAttr): if idAttr is None or not self.isSameNode(idAttr.ownerElement): raise xml.dom.NotFoundErr() if _get_containing_entref(self) is not None: raise xml.dom.NoModificationAllowedErr() if not idAttr._is_id: idAttr._is_id = True self._magic_id_nodes += 1 self.ownerDocument._magic_id_count += 1 _clear_id_cache(self) defproperty(Element, "attributes", doc="NamedNodeMap of attributes on the element.") defproperty(Element, "localName", doc="Namespace-local name of this element.") def _set_attribute_node(element, attr): _clear_id_cache(element) element._ensure_attributes() element._attrs[attr.name] = attr element._attrsNS[(attr.namespaceURI, attr.localName)] = attr # This creates a circular reference, but Element.unlink() # breaks the cycle since the references to the attribute # dictionaries are tossed. attr.ownerElement = element class Childless: """Mixin that makes childless-ness easy to implement and avoids the complexity of the Node methods that deal with children. """ __slots__ = () attributes = None childNodes = EmptyNodeList() firstChild = None lastChild = None def _get_firstChild(self): return None def _get_lastChild(self): return None def appendChild(self, node): raise xml.dom.HierarchyRequestErr( self.nodeName + " nodes cannot have children") def hasChildNodes(self): return False def insertBefore(self, newChild, refChild): raise xml.dom.HierarchyRequestErr( self.nodeName + " nodes do not have children") def removeChild(self, oldChild): raise xml.dom.NotFoundErr( self.nodeName + " nodes do not have children") def normalize(self): # For childless nodes, normalize() has nothing to do. pass def replaceChild(self, newChild, oldChild): raise xml.dom.HierarchyRequestErr( self.nodeName + " nodes do not have children") class ProcessingInstruction(Childless, Node): nodeType = Node.PROCESSING_INSTRUCTION_NODE __slots__ = ('target', 'data') def __init__(self, target, data): self.target = target self.data = data # nodeValue is an alias for data def _get_nodeValue(self): return self.data def _set_nodeValue(self, value): self.data = data nodeValue = property(_get_nodeValue, _set_nodeValue) # nodeName is an alias for target def _get_nodeName(self): return self.target def _set_nodeName(self, value): self.target = value nodeName = property(_get_nodeName, _set_nodeName) def writexml(self, writer, indent="", addindent="", newl=""): writer.write("%s<?%s %s?>%s" % (indent,self.target, self.data, newl)) class CharacterData(Childless, Node): __slots__=('_data', 'ownerDocument','parentNode', 'previousSibling', 'nextSibling') def __init__(self): self.ownerDocument = self.parentNode = None self.previousSibling = self.nextSibling = None self._data = '' Node.__init__(self) def _get_length(self): return len(self.data) __len__ = _get_length def _get_data(self): return self._data def _set_data(self, data): self._data = data data = nodeValue = property(_get_data, _set_data) def __repr__(self): data = self.data if len(data) > 10: dotdotdot = "..." else: dotdotdot = "" return '<DOM %s node "%r%s">' % ( self.__class__.__name__, data[0:10], dotdotdot) def substringData(self, offset, count): if offset < 0: raise xml.dom.IndexSizeErr("offset cannot be negative") if offset >= len(self.data): raise xml.dom.IndexSizeErr("offset cannot be beyond end of data") if count < 0: raise xml.dom.IndexSizeErr("count cannot be negative") return self.data[offset:offset+count] def appendData(self, arg): self.data = self.data + arg def insertData(self, offset, arg): if offset < 0: raise xml.dom.IndexSizeErr("offset cannot be negative") if offset >= len(self.data): raise xml.dom.IndexSizeErr("offset cannot be beyond end of data") if arg: self.data = "%s%s%s" % ( self.data[:offset], arg, self.data[offset:]) def deleteData(self, offset, count): if offset < 0: raise xml.dom.IndexSizeErr("offset cannot be negative") if offset >= len(self.data): raise xml.dom.IndexSizeErr("offset cannot be beyond end of data") if count < 0: raise xml.dom.IndexSizeErr("count cannot be negative") if count: self.data = self.data[:offset] + self.data[offset+count:] def replaceData(self, offset, count, arg): if offset < 0: raise xml.dom.IndexSizeErr("offset cannot be negative") if offset >= len(self.data): raise xml.dom.IndexSizeErr("offset cannot be beyond end of data") if count < 0: raise xml.dom.IndexSizeErr("count cannot be negative") if count: self.data = "%s%s%s" % ( self.data[:offset], arg, self.data[offset+count:]) defproperty(CharacterData, "length", doc="Length of the string data.") class Text(CharacterData): __slots__ = () nodeType = Node.TEXT_NODE nodeName = "#text" attributes = None def splitText(self, offset): if offset < 0 or offset > len(self.data): raise xml.dom.IndexSizeErr("illegal offset value") newText = self.__class__() newText.data = self.data[offset:] newText.ownerDocument = self.ownerDocument next = self.nextSibling if self.parentNode and self in self.parentNode.childNodes: if next is None: self.parentNode.appendChild(newText) else: self.parentNode.insertBefore(newText, next) self.data = self.data[:offset] return newText def writexml(self, writer, indent="", addindent="", newl=""): _write_data(writer, "%s%s%s" % (indent, self.data, newl)) # DOM Level 3 (WD 9 April 2002) def _get_wholeText(self): L = [self.data] n = self.previousSibling while n is not None: if n.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE): L.insert(0, n.data) n = n.previousSibling else: break n = self.nextSibling while n is not None: if n.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE): L.append(n.data) n = n.nextSibling else: break return ''.join(L) def replaceWholeText(self, content): # XXX This needs to be seriously changed if minidom ever # supports EntityReference nodes. parent = self.parentNode n = self.previousSibling while n is not None: if n.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE): next = n.previousSibling parent.removeChild(n) n = next else: break n = self.nextSibling if not content: parent.removeChild(self) while n is not None: if n.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE): next = n.nextSibling parent.removeChild(n) n = next else: break if content: self.data = content return self else: return None def _get_isWhitespaceInElementContent(self): if self.data.strip(): return False elem = _get_containing_element(self) if elem is None: return False info = self.ownerDocument._get_elem_info(elem) if info is None: return False else: return info.isElementContent() defproperty(Text, "isWhitespaceInElementContent", doc="True iff this text node contains only whitespace" " and is in element content.") defproperty(Text, "wholeText", doc="The text of all logically-adjacent text nodes.") def _get_containing_element(node): c = node.parentNode while c is not None: if c.nodeType == Node.ELEMENT_NODE: return c c = c.parentNode return None def _get_containing_entref(node): c = node.parentNode while c is not None: if c.nodeType == Node.ENTITY_REFERENCE_NODE: return c c = c.parentNode return None class Comment(CharacterData): nodeType = Node.COMMENT_NODE nodeName = "#comment" def __init__(self, data): CharacterData.__init__(self) self._data = data def writexml(self, writer, indent="", addindent="", newl=""): if "--" in self.data: raise ValueError("'--' is not allowed in a comment node") writer.write("%s<!--%s-->%s" % (indent, self.data, newl)) class CDATASection(Text): __slots__ = () nodeType = Node.CDATA_SECTION_NODE nodeName = "#cdata-section" def writexml(self, writer, indent="", addindent="", newl=""): if self.data.find("]]>") >= 0: raise ValueError("']]>' not allowed in a CDATA section") writer.write("<![CDATA[%s]]>" % self.data) class ReadOnlySequentialNamedNodeMap(object): __slots__ = '_seq', def __init__(self, seq=()): # seq should be a list or tuple self._seq = seq def __len__(self): return len(self._seq) def _get_length(self): return len(self._seq) def getNamedItem(self, name): for n in self._seq: if n.nodeName == name: return n def getNamedItemNS(self, namespaceURI, localName): for n in self._seq: if n.namespaceURI == namespaceURI and n.localName == localName: return n def __getitem__(self, name_or_tuple): if isinstance(name_or_tuple, tuple): node = self.getNamedItemNS(*name_or_tuple) else: node = self.getNamedItem(name_or_tuple) if node is None: raise KeyError(name_or_tuple) return node def item(self, index): if index < 0: return None try: return self._seq[index] except IndexError: return None def removeNamedItem(self, name): raise xml.dom.NoModificationAllowedErr( "NamedNodeMap instance is read-only") def removeNamedItemNS(self, namespaceURI, localName): raise xml.dom.NoModificationAllowedErr( "NamedNodeMap instance is read-only") def setNamedItem(self, node): raise xml.dom.NoModificationAllowedErr( "NamedNodeMap instance is read-only") def setNamedItemNS(self, node): raise xml.dom.NoModificationAllowedErr( "NamedNodeMap instance is read-only") def __getstate__(self): return [self._seq] def __setstate__(self, state): self._seq = state[0] defproperty(ReadOnlySequentialNamedNodeMap, "length", doc="Number of entries in the NamedNodeMap.") class Identified: """Mix-in class that supports the publicId and systemId attributes.""" __slots__ = 'publicId', 'systemId' def _identified_mixin_init(self, publicId, systemId): self.publicId = publicId self.systemId = systemId def _get_publicId(self): return self.publicId def _get_systemId(self): return self.systemId class DocumentType(Identified, Childless, Node): nodeType = Node.DOCUMENT_TYPE_NODE nodeValue = None name = None publicId = None systemId = None internalSubset = None def __init__(self, qualifiedName): self.entities = ReadOnlySequentialNamedNodeMap() self.notations = ReadOnlySequentialNamedNodeMap() if qualifiedName: prefix, localname = _nssplit(qualifiedName) self.name = localname self.nodeName = self.name def _get_internalSubset(self): return self.internalSubset def cloneNode(self, deep): if self.ownerDocument is None: # it's ok clone = DocumentType(None) clone.name = self.name clone.nodeName = self.name operation = xml.dom.UserDataHandler.NODE_CLONED if deep: clone.entities._seq = [] clone.notations._seq = [] for n in self.notations._seq: notation = Notation(n.nodeName, n.publicId, n.systemId) clone.notations._seq.append(notation) n._call_user_data_handler(operation, n, notation) for e in self.entities._seq: entity = Entity(e.nodeName, e.publicId, e.systemId, e.notationName) entity.actualEncoding = e.actualEncoding entity.encoding = e.encoding entity.version = e.version clone.entities._seq.append(entity) e._call_user_data_handler(operation, n, entity) self._call_user_data_handler(operation, self, clone) return clone else: return None def writexml(self, writer, indent="", addindent="", newl=""): writer.write("<!DOCTYPE ") writer.write(self.name) if self.publicId: writer.write("%s PUBLIC '%s'%s '%s'" % (newl, self.publicId, newl, self.systemId)) elif self.systemId: writer.write("%s SYSTEM '%s'" % (newl, self.systemId)) if self.internalSubset is not None: writer.write(" [") writer.write(self.internalSubset) writer.write("]") writer.write(">"+newl) class Entity(Identified, Node): attributes = None nodeType = Node.ENTITY_NODE nodeValue = None actualEncoding = None encoding = None version = None def __init__(self, name, publicId, systemId, notation): self.nodeName = name self.notationName = notation self.childNodes = NodeList() self._identified_mixin_init(publicId, systemId) def _get_actualEncoding(self): return self.actualEncoding def _get_encoding(self): return self.encoding def _get_version(self): return self.version def appendChild(self, newChild): raise xml.dom.HierarchyRequestErr( "cannot append children to an entity node") def insertBefore(self, newChild, refChild): raise xml.dom.HierarchyRequestErr( "cannot insert children below an entity node") def removeChild(self, oldChild): raise xml.dom.HierarchyRequestErr( "cannot remove children from an entity node") def replaceChild(self, newChild, oldChild): raise xml.dom.HierarchyRequestErr( "cannot replace children of an entity node") class Notation(Identified, Childless, Node): nodeType = Node.NOTATION_NODE nodeValue = None def __init__(self, name, publicId, systemId): self.nodeName = name self._identified_mixin_init(publicId, systemId) class DOMImplementation(DOMImplementationLS): _features = [("core", "1.0"), ("core", "2.0"), ("core", None), ("xml", "1.0"), ("xml", "2.0"), ("xml", None), ("ls-load", "3.0"), ("ls-load", None), ] def hasFeature(self, feature, version): if version == "": version = None return (feature.lower(), version) in self._features def createDocument(self, namespaceURI, qualifiedName, doctype): if doctype and doctype.parentNode is not None: raise xml.dom.WrongDocumentErr( "doctype object owned by another DOM tree") doc = self._create_document() add_root_element = not (namespaceURI is None and qualifiedName is None and doctype is None) if not qualifiedName and add_root_element: # The spec is unclear what to raise here; SyntaxErr # would be the other obvious candidate. Since Xerces raises # InvalidCharacterErr, and since SyntaxErr is not listed # for createDocument, that seems to be the better choice. # XXX: need to check for illegal characters here and in # createElement. # DOM Level III clears this up when talking about the return value # of this function. If namespaceURI, qName and DocType are # Null the document is returned without a document element # Otherwise if doctype or namespaceURI are not None # Then we go back to the above problem raise xml.dom.InvalidCharacterErr("Element with no name") if add_root_element: prefix, localname = _nssplit(qualifiedName) if prefix == "xml" \ and namespaceURI != "http://www.w3.org/XML/1998/namespace": raise xml.dom.NamespaceErr("illegal use of 'xml' prefix") if prefix and not namespaceURI: raise xml.dom.NamespaceErr( "illegal use of prefix without namespaces") element = doc.createElementNS(namespaceURI, qualifiedName) if doctype: doc.appendChild(doctype) doc.appendChild(element) if doctype: doctype.parentNode = doctype.ownerDocument = doc doc.doctype = doctype doc.implementation = self return doc def createDocumentType(self, qualifiedName, publicId, systemId): doctype = DocumentType(qualifiedName) doctype.publicId = publicId doctype.systemId = systemId return doctype # DOM Level 3 (WD 9 April 2002) def getInterface(self, feature): if self.hasFeature(feature, None): return self else: return None # internal def _create_document(self): return Document() class ElementInfo(object): """Object that represents content-model information for an element. This implementation is not expected to be used in practice; DOM builders should provide implementations which do the right thing using information available to it. """ __slots__ = 'tagName', def __init__(self, name): self.tagName = name def getAttributeType(self, aname): return _no_type def getAttributeTypeNS(self, namespaceURI, localName): return _no_type def isElementContent(self): return False def isEmpty(self): """Returns true iff this element is declared to have an EMPTY content model.""" return False def isId(self, aname): """Returns true iff the named attribute is a DTD-style ID.""" return False def isIdNS(self, namespaceURI, localName): """Returns true iff the identified attribute is a DTD-style ID.""" return False def __getstate__(self): return self.tagName def __setstate__(self, state): self.tagName = state def _clear_id_cache(node): if node.nodeType == Node.DOCUMENT_NODE: node._id_cache.clear() node._id_search_stack = None elif _in_document(node): node.ownerDocument._id_cache.clear() node.ownerDocument._id_search_stack= None class Document(Node, DocumentLS): __slots__ = ('_elem_info', 'doctype', '_id_search_stack', 'childNodes', '_id_cache') _child_node_types = (Node.ELEMENT_NODE, Node.PROCESSING_INSTRUCTION_NODE, Node.COMMENT_NODE, Node.DOCUMENT_TYPE_NODE) implementation = DOMImplementation() nodeType = Node.DOCUMENT_NODE nodeName = "#document" nodeValue = None attributes = None parentNode = None previousSibling = nextSibling = None # Document attributes from Level 3 (WD 9 April 2002) actualEncoding = None encoding = None standalone = None version = None strictErrorChecking = False errorHandler = None documentURI = None _magic_id_count = 0 def __init__(self): self.doctype = None self.childNodes = NodeList() # mapping of (namespaceURI, localName) -> ElementInfo # and tagName -> ElementInfo self._elem_info = {} self._id_cache = {} self._id_search_stack = None def _get_elem_info(self, element): if element.namespaceURI: key = element.namespaceURI, element.localName else: key = element.tagName return self._elem_info.get(key) def _get_actualEncoding(self): return self.actualEncoding def _get_doctype(self): return self.doctype def _get_documentURI(self): return self.documentURI def _get_encoding(self): return self.encoding def _get_errorHandler(self): return self.errorHandler def _get_standalone(self): return self.standalone def _get_strictErrorChecking(self): return self.strictErrorChecking def _get_version(self): return self.version def appendChild(self, node): if node.nodeType not in self._child_node_types: raise xml.dom.HierarchyRequestErr( "%s cannot be child of %s" % (repr(node), repr(self))) if node.parentNode is not None: # This needs to be done before the next test since this # may *be* the document element, in which case it should # end up re-ordered to the end. node.parentNode.removeChild(node) if node.nodeType == Node.ELEMENT_NODE \ and self._get_documentElement(): raise xml.dom.HierarchyRequestErr( "two document elements disallowed") return Node.appendChild(self, node) def removeChild(self, oldChild): try: self.childNodes.remove(oldChild) except ValueError: raise xml.dom.NotFoundErr() oldChild.nextSibling = oldChild.previousSibling = None oldChild.parentNode = None if self.documentElement is oldChild: self.documentElement = None return oldChild def _get_documentElement(self): for node in self.childNodes: if node.nodeType == Node.ELEMENT_NODE: return node def unlink(self): if self.doctype is not None: self.doctype.unlink() self.doctype = None Node.unlink(self) def cloneNode(self, deep): if not deep: return None clone = self.implementation.createDocument(None, None, None) clone.encoding = self.encoding clone.standalone = self.standalone clone.version = self.version for n in self.childNodes: childclone = _clone_node(n, deep, clone) assert childclone.ownerDocument.isSameNode(clone) clone.childNodes.append(childclone) if childclone.nodeType == Node.DOCUMENT_NODE: assert clone.documentElement is None elif childclone.nodeType == Node.DOCUMENT_TYPE_NODE: assert clone.doctype is None clone.doctype = childclone childclone.parentNode = clone self._call_user_data_handler(xml.dom.UserDataHandler.NODE_CLONED, self, clone) return clone def createDocumentFragment(self): d = DocumentFragment() d.ownerDocument = self return d def createElement(self, tagName): e = Element(tagName) e.ownerDocument = self return e def createTextNode(self, data): if not isinstance(data, str): raise TypeError("node contents must be a string") t = Text() t.data = data t.ownerDocument = self return t def createCDATASection(self, data): if not isinstance(data, str): raise TypeError("node contents must be a string") c = CDATASection() c.data = data c.ownerDocument = self return c def createComment(self, data): c = Comment(data) c.ownerDocument = self return c def createProcessingInstruction(self, target, data): p = ProcessingInstruction(target, data) p.ownerDocument = self return p def createAttribute(self, qName): a = Attr(qName) a.ownerDocument = self a.value = "" return a def createElementNS(self, namespaceURI, qualifiedName): prefix, localName = _nssplit(qualifiedName) e = Element(qualifiedName, namespaceURI, prefix) e.ownerDocument = self return e def createAttributeNS(self, namespaceURI, qualifiedName): prefix, localName = _nssplit(qualifiedName) a = Attr(qualifiedName, namespaceURI, localName, prefix) a.ownerDocument = self a.value = "" return a # A couple of implementation-specific helpers to create node types # not supported by the W3C DOM specs: def _create_entity(self, name, publicId, systemId, notationName): e = Entity(name, publicId, systemId, notationName) e.ownerDocument = self return e def _create_notation(self, name, publicId, systemId): n = Notation(name, publicId, systemId) n.ownerDocument = self return n def getElementById(self, id): if id in self._id_cache: return self._id_cache[id] if not (self._elem_info or self._magic_id_count): return None stack = self._id_search_stack if stack is None: # we never searched before, or the cache has been cleared stack = [self.documentElement] self._id_search_stack = stack elif not stack: # Previous search was completed and cache is still valid; # no matching node. return None result = None while stack: node = stack.pop() # add child elements to stack for continued searching stack.extend([child for child in node.childNodes if child.nodeType in _nodeTypes_with_children]) # check this node info = self._get_elem_info(node) if info: # We have to process all ID attributes before # returning in order to get all the attributes set to # be IDs using Element.setIdAttribute*(). for attr in node.attributes.values(): if attr.namespaceURI: if info.isIdNS(attr.namespaceURI, attr.localName): self._id_cache[attr.value] = node if attr.value == id: result = node elif not node._magic_id_nodes: break elif info.isId(attr.name): self._id_cache[attr.value] = node if attr.value == id: result = node elif not node._magic_id_nodes: break elif attr._is_id: self._id_cache[attr.value] = node if attr.value == id: result = node elif node._magic_id_nodes == 1: break elif node._magic_id_nodes: for attr in node.attributes.values(): if attr._is_id: self._id_cache[attr.value] = node if attr.value == id: result = node if result is not None: break return result def getElementsByTagName(self, name): return _get_elements_by_tagName_helper(self, name, NodeList()) def getElementsByTagNameNS(self, namespaceURI, localName): return _get_elements_by_tagName_ns_helper( self, namespaceURI, localName, NodeList()) def isSupported(self, feature, version): return self.implementation.hasFeature(feature, version) def importNode(self, node, deep): if node.nodeType == Node.DOCUMENT_NODE: raise xml.dom.NotSupportedErr("cannot import document nodes") elif node.nodeType == Node.DOCUMENT_TYPE_NODE: raise xml.dom.NotSupportedErr("cannot import document type nodes") return _clone_node(node, deep, self) def writexml(self, writer, indent="", addindent="", newl="", encoding=None): if encoding is None: writer.write('<?xml version="1.0" ?>'+newl) else: writer.write('<?xml version="1.0" encoding="%s"?>%s' % ( encoding, newl)) for node in self.childNodes: node.writexml(writer, indent, addindent, newl) # DOM Level 3 (WD 9 April 2002) def renameNode(self, n, namespaceURI, name): if n.ownerDocument is not self: raise xml.dom.WrongDocumentErr( "cannot rename nodes from other documents;\n" "expected %s,\nfound %s" % (self, n.ownerDocument)) if n.nodeType not in (Node.ELEMENT_NODE, Node.ATTRIBUTE_NODE): raise xml.dom.NotSupportedErr( "renameNode() only applies to element and attribute nodes") if namespaceURI != EMPTY_NAMESPACE: if ':' in name: prefix, localName = name.split(':', 1) if ( prefix == "xmlns" and namespaceURI != xml.dom.XMLNS_NAMESPACE): raise xml.dom.NamespaceErr( "illegal use of 'xmlns' prefix") else: if ( name == "xmlns" and namespaceURI != xml.dom.XMLNS_NAMESPACE and n.nodeType == Node.ATTRIBUTE_NODE): raise xml.dom.NamespaceErr( "illegal use of the 'xmlns' attribute") prefix = None localName = name else: prefix = None localName = None if n.nodeType == Node.ATTRIBUTE_NODE: element = n.ownerElement if element is not None: is_id = n._is_id element.removeAttributeNode(n) else: element = None n.prefix = prefix n._localName = localName n.namespaceURI = namespaceURI n.nodeName = name if n.nodeType == Node.ELEMENT_NODE: n.tagName = name else: # attribute node n.name = name if element is not None: element.setAttributeNode(n) if is_id: element.setIdAttributeNode(n) # It's not clear from a semantic perspective whether we should # call the user data handlers for the NODE_RENAMED event since # we're re-using the existing node. The draft spec has been # interpreted as meaning "no, don't call the handler unless a # new node is created." return n defproperty(Document, "documentElement", doc="Top-level element of this document.") def _clone_node(node, deep, newOwnerDocument): """ Clone a node and give it the new owner document. Called by Node.cloneNode and Document.importNode """ if node.ownerDocument.isSameNode(newOwnerDocument): operation = xml.dom.UserDataHandler.NODE_CLONED else: operation = xml.dom.UserDataHandler.NODE_IMPORTED if node.nodeType == Node.ELEMENT_NODE: clone = newOwnerDocument.createElementNS(node.namespaceURI, node.nodeName) for attr in node.attributes.values(): clone.setAttributeNS(attr.namespaceURI, attr.nodeName, attr.value) a = clone.getAttributeNodeNS(attr.namespaceURI, attr.localName) a.specified = attr.specified if deep: for child in node.childNodes: c = _clone_node(child, deep, newOwnerDocument) clone.appendChild(c) elif node.nodeType == Node.DOCUMENT_FRAGMENT_NODE: clone = newOwnerDocument.createDocumentFragment() if deep: for child in node.childNodes: c = _clone_node(child, deep, newOwnerDocument) clone.appendChild(c) elif node.nodeType == Node.TEXT_NODE: clone = newOwnerDocument.createTextNode(node.data) elif node.nodeType == Node.CDATA_SECTION_NODE: clone = newOwnerDocument.createCDATASection(node.data) elif node.nodeType == Node.PROCESSING_INSTRUCTION_NODE: clone = newOwnerDocument.createProcessingInstruction(node.target, node.data) elif node.nodeType == Node.COMMENT_NODE: clone = newOwnerDocument.createComment(node.data) elif node.nodeType == Node.ATTRIBUTE_NODE: clone = newOwnerDocument.createAttributeNS(node.namespaceURI, node.nodeName) clone.specified = True clone.value = node.value elif node.nodeType == Node.DOCUMENT_TYPE_NODE: assert node.ownerDocument is not newOwnerDocument operation = xml.dom.UserDataHandler.NODE_IMPORTED clone = newOwnerDocument.implementation.createDocumentType( node.name, node.publicId, node.systemId) clone.ownerDocument = newOwnerDocument if deep: clone.entities._seq = [] clone.notations._seq = [] for n in node.notations._seq: notation = Notation(n.nodeName, n.publicId, n.systemId) notation.ownerDocument = newOwnerDocument clone.notations._seq.append(notation) if hasattr(n, '_call_user_data_handler'): n._call_user_data_handler(operation, n, notation) for e in node.entities._seq: entity = Entity(e.nodeName, e.publicId, e.systemId, e.notationName) entity.actualEncoding = e.actualEncoding entity.encoding = e.encoding entity.version = e.version entity.ownerDocument = newOwnerDocument clone.entities._seq.append(entity) if hasattr(e, '_call_user_data_handler'): e._call_user_data_handler(operation, n, entity) else: # Note the cloning of Document and DocumentType nodes is # implementation specific. minidom handles those cases # directly in the cloneNode() methods. raise xml.dom.NotSupportedErr("Cannot clone node %s" % repr(node)) # Check for _call_user_data_handler() since this could conceivably # used with other DOM implementations (one of the FourThought # DOMs, perhaps?). if hasattr(node, '_call_user_data_handler'): node._call_user_data_handler(operation, node, clone) return clone def _nssplit(qualifiedName): fields = qualifiedName.split(':', 1) if len(fields) == 2: return fields else: return (None, fields[0]) def _do_pulldom_parse(func, args, kwargs): events = func(*args, **kwargs) toktype, rootNode = events.getEvent() events.expandNode(rootNode) events.clear() return rootNode def parse(file, parser=None, bufsize=None): """Parse a file into a DOM by filename or file object.""" if parser is None and not bufsize: from xml.dom import expatbuilder return expatbuilder.parse(file) else: from xml.dom import pulldom return _do_pulldom_parse(pulldom.parse, (file,), {'parser': parser, 'bufsize': bufsize}) def parseString(string, parser=None): """Parse a file into a DOM from a string.""" if parser is None: from xml.dom import expatbuilder return expatbuilder.parseString(string) else: from xml.dom import pulldom return _do_pulldom_parse(pulldom.parseString, (string,), {'parser': parser}) def getDOMImplementation(features=None): if features: if isinstance(features, str): features = domreg._parse_feature_string(features) for f, v in features: if not Document.implementation.hasFeature(f, v): return None return Document.implementation
gpl-2.0
[ 624, 3184, 4514, 402, 314, 20400, 413, 14316, 14, 199, 199, 985, 10749, 436, 1163, 12612, 20400, 499, 4534, 787, 2597, 3748, 14, 199, 199, 1122, 480, 1421, 14, 1652, 531, 199, 199, 14934, 6757, 1421, 2535, 1700, 15, 2957, 1421, 9579, 199, 199, 52, 19657, 26, 199, 19989, 199, 627, 16777, 3102, 367, 10232, 4008, 436, 1318, 14, 199, 627, 1655, 5343, 199, 627, 330, 5985, 2005, 402, 314, 7060, 436, 7798, 1793, 1233, 1901, 406, 11478, 543, 642, 267, 3217, 199, 627, 19310, 499, 10747, 199, 624, 199, 199, 646, 5890, 199, 646, 2748, 14, 4556, 199, 199, 504, 2748, 14, 4556, 492, 16589, 63, 13001, 12, 16589, 63, 6351, 12, 4692, 2709, 63, 13001, 12, 8266, 1135, 199, 504, 2748, 14, 4556, 14, 18000, 5819, 492, 627, 199, 504, 2748, 14, 4556, 14, 1652, 5649, 492, 14316, 7921, 5296, 12, 7543, 5296, 199, 199, 3, 961, 365, 1202, 701, 314, 2870, 13, 1637, 3866, 425, 5920, 27, 314, 769, 5712, 1133, 199, 3, 5965, 4890, 12, 3967, 314, 3380, 3769, 7923, 911, 7078, 506, 314, 199, 3, 29970, 63, 8063, 503, 29970, 63, 28147, 63, 8063, 14, 221, 334, 1918, 1031, 3769, 7923, 365, 199, 3, 314, 1031, 3769, 3483, 503, 4829, 12, 440, 314, 1031, 3769, 6042, 4959, 199, 3, 199, 63, 932, 4100, 63, 1045, 63, 3223, 275, 334, 1652, 14, 4556, 14, 1716, 14, 12535, 63, 8063, 12, 1169, 2748, 14, 4556, 14, 1716, 14, 13630, 63, 31177, 63, 8063, 9, 421, 199, 533, 5013, 8, 1652, 14, 4556, 14, 1716, 304, 272, 3231, 7639, 275, 488, 327, 642, 365, 2222, 13, 2307, 1454, 367, 4008, 436, 3004, 272, 1676, 1716, 275, 488, 272, 5771, 5564, 275, 488, 272, 2163, 16016, 275, 488, 272, 4136, 16016, 275, 488, 339, 2403, 275, 16589, 63, 6351, 327, 2222, 13, 2307, 1454, 367, 9380, 4008, 436, 3004, 339, 347, 636, 2245, 721, 277, 304, 267, 372, 715, 339, 347, 370, 1652, 8, 277, 12, 2644, 29, 403, 304, 267, 372, 291, 14, 2119, 21958, 1652, 12398, 4873, 2644, 9, 339, 347, 370, 9118, 1652, 8, 277, 12, 4363, 21024, 84, 401, 892, 76, 21024, 78, 401, 2644, 29, 403, 304, 267, 340, 2644, 365, 488, 26, 288, 7060, 275, 5890, 14, 6424, 342, 267, 587, 26, 288, 7060, 275, 5890, 14, 1872, 29365, 8, 2308, 14, 15466, 1062, 4228, 2644, 29, 2991, 12, 4228, 2552, 628, 1652, 24253, 1814, 401, 4228, 8057, 17115, 78, 358, 267, 340, 291, 14, 12412, 508, 5013, 14, 7884, 63, 8063, 26, 288, 327, 6855, 986, 2644, 1454, 370, 2213, 12, 370, 5324, 652, 1901, 4692, 1406, 288, 291, 14, 952, 1652, 8, 5491, 12, 4873, 4363, 12, 892, 76, 12, 2644, 9, 267, 587, 26, 288, 291, 14, 952, 1652, 8, 5491, 12, 4873, 4363, 12, 892, 76, 9, 267, 340, 2644, 365, 488, 26, 288, 372, 7060, 14, 7150, 342, 267, 587, 26, 288, 372, 7060, 14, 14481, 1252, 7150, 342, 339, 347, 965, 3493, 6300, 8, 277, 304, 267, 372, 2155, 8, 277, 14, 10626, 9, 339, 347, 485, 362, 63, 10626, 8, 277, 304, 267, 372, 291, 14, 10626, 339, 347, 485, 362, 63, 22262, 8, 277, 304, 267, 340, 291, 14, 10626, 26, 288, 372, 291, 14, 10626, 59, 16, 61, 339, 347, 485, 362, 63, 2019, 3493, 8, 277, 304, 267, 340, 291, 14, 10626, 26, 288, 372, 291, 14, 10626, 1988, 17, 61, 339, 347, 5518, 13569, 8, 277, 12, 28482, 12, 2984, 3493, 304, 267, 340, 28482, 14, 12412, 508, 291, 14, 7884, 63, 28147, 63, 8063, 26, 288, 367, 286, 315, 2008, 8, 1222, 3493, 14, 10626, 304, 355, 291, 14, 3176, 13569, 8, 67, 12, 2984, 3493, 9, 288, 6754, 710, 14316, 1630, 440, 5436, 590, 4165, 4052, 370, 372, 315, 642, 1930, 288, 372, 28482, 267, 340, 28482, 14, 12412, 440, 315, 291, 423, 1739, 63, 932, 63, 1313, 26, 288, 746, 2748, 14, 4556, 14, 29460, 2017, 5432, 8, 355, 2071, 83, 3913, 506, 1982, 402, 450, 83, 2, 450, 334, 2722, 8, 1222, 3493, 395, 4700, 8, 277, 1724, 267, 340, 28482, 14, 24899, 365, 440, 488, 26, 288, 28482, 14, 24899, 14, 2168, 3493, 8, 1222, 3493, 9, 267, 340, 2984, 3493, 365, 488, 26, 288, 291, 14, 14988, 8, 1222, 3493, 9, 267, 587, 26, 288, 862, 26, 355, 1478, 275, 291, 14, 10626, 14, 1080, 8, 1121, 3493, 9, 288, 871, 1722, 26, 355, 746, 2748, 14, 4556, 14, 4667, 5432, 342, 288, 340, 28482, 14, 12412, 315, 485, 932, 4100, 63, 1045, 63, 3223, 26, 355, 485, 3584, 63, 344, 63, 1637, 8, 277, 9, 288, 291, 14, 10626, 14, 3176, 8, 1080, 12, 28482, 9, 288, 28482, 14, 30336, 275, 2984, 3493, 288, 2984, 3493, 14, 6352, 16016, 275, 28482, 288, 340, 1478, 26, 355, 1031, 275, 291, 14, 10626, 59, 1080, 13, 17, 61, 355, 1031, 14, 30336, 275, 28482, 355, 28482, 14, 6352, 16016, 275, 1031, 288, 587, 26, 355, 28482, 14, 6352, 16016, 275, 488, 288, 28482, 14, 24899, 275, 291, 267, 372, 28482, 339, 347, 5666, 3493, 8, 277, 12, 1031, 304, 267, 340, 1031, 14, 12412, 508, 291, 14, 7884, 63, 28147, 63, 8063, 26, 288, 367, 286, 315, 2008, 8, 932, 14, 10626, 304, 355, 291, 14, 14988, 8, 67, 9, 288, 6754, 710, 14316, 1630, 440, 5436, 590, 4165, 4052, 370, 372, 315, 642, 1930, 288, 372, 1031, 267, 340, 1031, 14, 12412, 440, 315, 291, 423, 1739, 63, 932, 63, 1313, 26, 288, 746, 2748, 14, 4556, 14, 29460, 2017, 5432, 8, 355, 2071, 83, 3913, 506, 1982, 402, 450, 83, 2, 450, 334, 2722, 8, 932, 395, 4700, 8, 277, 1724, 267, 916, 1031, 14, 12412, 315, 485, 932, 4100, 63, 1045, 63, 3223, 26, 288, 485, 3584, 63, 344, 63, 1637, 8, 277, 9, 267, 340, 1031, 14, 24899, 365, 440, 488, 26, 288, 1031, 14, 24899, 14, 2168, 3493, 8, 932, 9, 267, 485, 740, 63, 1739, 8, 277, 12, 1031, 9, 267, 1031, 14, 30336, 275, 488, 267, 372, 1031, 339, 347, 3350, 3493, 8, 277, 12, 28482, 12, 2269, 3493, 304, 267, 340, 28482, 14 ]
[ 3184, 4514, 402, 314, 20400, 413, 14316, 14, 199, 199, 985, 10749, 436, 1163, 12612, 20400, 499, 4534, 787, 2597, 3748, 14, 199, 199, 1122, 480, 1421, 14, 1652, 531, 199, 199, 14934, 6757, 1421, 2535, 1700, 15, 2957, 1421, 9579, 199, 199, 52, 19657, 26, 199, 19989, 199, 627, 16777, 3102, 367, 10232, 4008, 436, 1318, 14, 199, 627, 1655, 5343, 199, 627, 330, 5985, 2005, 402, 314, 7060, 436, 7798, 1793, 1233, 1901, 406, 11478, 543, 642, 267, 3217, 199, 627, 19310, 499, 10747, 199, 624, 199, 199, 646, 5890, 199, 646, 2748, 14, 4556, 199, 199, 504, 2748, 14, 4556, 492, 16589, 63, 13001, 12, 16589, 63, 6351, 12, 4692, 2709, 63, 13001, 12, 8266, 1135, 199, 504, 2748, 14, 4556, 14, 18000, 5819, 492, 627, 199, 504, 2748, 14, 4556, 14, 1652, 5649, 492, 14316, 7921, 5296, 12, 7543, 5296, 199, 199, 3, 961, 365, 1202, 701, 314, 2870, 13, 1637, 3866, 425, 5920, 27, 314, 769, 5712, 1133, 199, 3, 5965, 4890, 12, 3967, 314, 3380, 3769, 7923, 911, 7078, 506, 314, 199, 3, 29970, 63, 8063, 503, 29970, 63, 28147, 63, 8063, 14, 221, 334, 1918, 1031, 3769, 7923, 365, 199, 3, 314, 1031, 3769, 3483, 503, 4829, 12, 440, 314, 1031, 3769, 6042, 4959, 199, 3, 199, 63, 932, 4100, 63, 1045, 63, 3223, 275, 334, 1652, 14, 4556, 14, 1716, 14, 12535, 63, 8063, 12, 1169, 2748, 14, 4556, 14, 1716, 14, 13630, 63, 31177, 63, 8063, 9, 421, 199, 533, 5013, 8, 1652, 14, 4556, 14, 1716, 304, 272, 3231, 7639, 275, 488, 327, 642, 365, 2222, 13, 2307, 1454, 367, 4008, 436, 3004, 272, 1676, 1716, 275, 488, 272, 5771, 5564, 275, 488, 272, 2163, 16016, 275, 488, 272, 4136, 16016, 275, 488, 339, 2403, 275, 16589, 63, 6351, 327, 2222, 13, 2307, 1454, 367, 9380, 4008, 436, 3004, 339, 347, 636, 2245, 721, 277, 304, 267, 372, 715, 339, 347, 370, 1652, 8, 277, 12, 2644, 29, 403, 304, 267, 372, 291, 14, 2119, 21958, 1652, 12398, 4873, 2644, 9, 339, 347, 370, 9118, 1652, 8, 277, 12, 4363, 21024, 84, 401, 892, 76, 21024, 78, 401, 2644, 29, 403, 304, 267, 340, 2644, 365, 488, 26, 288, 7060, 275, 5890, 14, 6424, 342, 267, 587, 26, 288, 7060, 275, 5890, 14, 1872, 29365, 8, 2308, 14, 15466, 1062, 4228, 2644, 29, 2991, 12, 4228, 2552, 628, 1652, 24253, 1814, 401, 4228, 8057, 17115, 78, 358, 267, 340, 291, 14, 12412, 508, 5013, 14, 7884, 63, 8063, 26, 288, 327, 6855, 986, 2644, 1454, 370, 2213, 12, 370, 5324, 652, 1901, 4692, 1406, 288, 291, 14, 952, 1652, 8, 5491, 12, 4873, 4363, 12, 892, 76, 12, 2644, 9, 267, 587, 26, 288, 291, 14, 952, 1652, 8, 5491, 12, 4873, 4363, 12, 892, 76, 9, 267, 340, 2644, 365, 488, 26, 288, 372, 7060, 14, 7150, 342, 267, 587, 26, 288, 372, 7060, 14, 14481, 1252, 7150, 342, 339, 347, 965, 3493, 6300, 8, 277, 304, 267, 372, 2155, 8, 277, 14, 10626, 9, 339, 347, 485, 362, 63, 10626, 8, 277, 304, 267, 372, 291, 14, 10626, 339, 347, 485, 362, 63, 22262, 8, 277, 304, 267, 340, 291, 14, 10626, 26, 288, 372, 291, 14, 10626, 59, 16, 61, 339, 347, 485, 362, 63, 2019, 3493, 8, 277, 304, 267, 340, 291, 14, 10626, 26, 288, 372, 291, 14, 10626, 1988, 17, 61, 339, 347, 5518, 13569, 8, 277, 12, 28482, 12, 2984, 3493, 304, 267, 340, 28482, 14, 12412, 508, 291, 14, 7884, 63, 28147, 63, 8063, 26, 288, 367, 286, 315, 2008, 8, 1222, 3493, 14, 10626, 304, 355, 291, 14, 3176, 13569, 8, 67, 12, 2984, 3493, 9, 288, 6754, 710, 14316, 1630, 440, 5436, 590, 4165, 4052, 370, 372, 315, 642, 1930, 288, 372, 28482, 267, 340, 28482, 14, 12412, 440, 315, 291, 423, 1739, 63, 932, 63, 1313, 26, 288, 746, 2748, 14, 4556, 14, 29460, 2017, 5432, 8, 355, 2071, 83, 3913, 506, 1982, 402, 450, 83, 2, 450, 334, 2722, 8, 1222, 3493, 395, 4700, 8, 277, 1724, 267, 340, 28482, 14, 24899, 365, 440, 488, 26, 288, 28482, 14, 24899, 14, 2168, 3493, 8, 1222, 3493, 9, 267, 340, 2984, 3493, 365, 488, 26, 288, 291, 14, 14988, 8, 1222, 3493, 9, 267, 587, 26, 288, 862, 26, 355, 1478, 275, 291, 14, 10626, 14, 1080, 8, 1121, 3493, 9, 288, 871, 1722, 26, 355, 746, 2748, 14, 4556, 14, 4667, 5432, 342, 288, 340, 28482, 14, 12412, 315, 485, 932, 4100, 63, 1045, 63, 3223, 26, 355, 485, 3584, 63, 344, 63, 1637, 8, 277, 9, 288, 291, 14, 10626, 14, 3176, 8, 1080, 12, 28482, 9, 288, 28482, 14, 30336, 275, 2984, 3493, 288, 2984, 3493, 14, 6352, 16016, 275, 28482, 288, 340, 1478, 26, 355, 1031, 275, 291, 14, 10626, 59, 1080, 13, 17, 61, 355, 1031, 14, 30336, 275, 28482, 355, 28482, 14, 6352, 16016, 275, 1031, 288, 587, 26, 355, 28482, 14, 6352, 16016, 275, 488, 288, 28482, 14, 24899, 275, 291, 267, 372, 28482, 339, 347, 5666, 3493, 8, 277, 12, 1031, 304, 267, 340, 1031, 14, 12412, 508, 291, 14, 7884, 63, 28147, 63, 8063, 26, 288, 367, 286, 315, 2008, 8, 932, 14, 10626, 304, 355, 291, 14, 14988, 8, 67, 9, 288, 6754, 710, 14316, 1630, 440, 5436, 590, 4165, 4052, 370, 372, 315, 642, 1930, 288, 372, 1031, 267, 340, 1031, 14, 12412, 440, 315, 291, 423, 1739, 63, 932, 63, 1313, 26, 288, 746, 2748, 14, 4556, 14, 29460, 2017, 5432, 8, 355, 2071, 83, 3913, 506, 1982, 402, 450, 83, 2, 450, 334, 2722, 8, 932, 395, 4700, 8, 277, 1724, 267, 916, 1031, 14, 12412, 315, 485, 932, 4100, 63, 1045, 63, 3223, 26, 288, 485, 3584, 63, 344, 63, 1637, 8, 277, 9, 267, 340, 1031, 14, 24899, 365, 440, 488, 26, 288, 1031, 14, 24899, 14, 2168, 3493, 8, 932, 9, 267, 485, 740, 63, 1739, 8, 277, 12, 1031, 9, 267, 1031, 14, 30336, 275, 488, 267, 372, 1031, 339, 347, 3350, 3493, 8, 277, 12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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
morreene/tradenews
venv/Lib/site-packages/sqlalchemy/dialects/mssql/mxodbc.py
36
3856
# mssql/mxodbc.py # Copyright (C) 2005-2016 the SQLAlchemy authors and contributors # <see AUTHORS file> # # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php """ .. dialect:: mssql+mxodbc :name: mxODBC :dbapi: mxodbc :connectstring: mssql+mxodbc://<username>:<password>@<dsnname> :url: http://www.egenix.com/ Execution Modes --------------- mxODBC features two styles of statement execution, using the ``cursor.execute()`` and ``cursor.executedirect()`` methods (the second being an extension to the DBAPI specification). The former makes use of a particular API call specific to the SQL Server Native Client ODBC driver known SQLDescribeParam, while the latter does not. mxODBC apparently only makes repeated use of a single prepared statement when SQLDescribeParam is used. The advantage to prepared statement reuse is one of performance. The disadvantage is that SQLDescribeParam has a limited set of scenarios in which bind parameters are understood, including that they cannot be placed within the argument lists of function calls, anywhere outside the FROM, or even within subqueries within the FROM clause - making the usage of bind parameters within SELECT statements impossible for all but the most simplistic statements. For this reason, the mxODBC dialect uses the "native" mode by default only for INSERT, UPDATE, and DELETE statements, and uses the escaped string mode for all other statements. This behavior can be controlled via :meth:`~sqlalchemy.sql.expression.Executable.execution_options` using the ``native_odbc_execute`` flag with a value of ``True`` or ``False``, where a value of ``True`` will unconditionally use native bind parameters and a value of ``False`` will unconditionally use string-escaped parameters. """ from ... import types as sqltypes from ...connectors.mxodbc import MxODBCConnector from .pyodbc import MSExecutionContext_pyodbc, _MSNumeric_pyodbc from .base import (MSDialect, MSSQLStrictCompiler, _MSDateTime, _MSDate, _MSTime) class _MSNumeric_mxodbc(_MSNumeric_pyodbc): """Include pyodbc's numeric processor. """ class _MSDate_mxodbc(_MSDate): def bind_processor(self, dialect): def process(value): if value is not None: return "%s-%s-%s" % (value.year, value.month, value.day) else: return None return process class _MSTime_mxodbc(_MSTime): def bind_processor(self, dialect): def process(value): if value is not None: return "%s:%s:%s" % (value.hour, value.minute, value.second) else: return None return process class MSExecutionContext_mxodbc(MSExecutionContext_pyodbc): """ The pyodbc execution context is useful for enabling SELECT SCOPE_IDENTITY in cases where OUTPUT clause does not work (tables with insert triggers). """ # todo - investigate whether the pyodbc execution context # is really only being used in cases where OUTPUT # won't work. class MSDialect_mxodbc(MxODBCConnector, MSDialect): # this is only needed if "native ODBC" mode is used, # which is now disabled by default. # statement_compiler = MSSQLStrictCompiler execution_ctx_cls = MSExecutionContext_mxodbc # flag used by _MSNumeric_mxodbc _need_decimal_fix = True colspecs = { sqltypes.Numeric: _MSNumeric_mxodbc, sqltypes.DateTime: _MSDateTime, sqltypes.Date: _MSDate_mxodbc, sqltypes.Time: _MSTime_mxodbc, } def __init__(self, description_encoding=None, **params): super(MSDialect_mxodbc, self).__init__(**params) self.description_encoding = description_encoding dialect = MSDialect_mxodbc
bsd-3-clause
[ 3, 333, 385, 1710, 15, 9457, 19887, 14, 647, 199, 3, 1898, 334, 35, 9, 11811, 13, 9261, 314, 14303, 11462, 436, 8417, 199, 3, 665, 3239, 10610, 570, 30, 199, 3, 199, 3, 961, 859, 365, 1777, 402, 14303, 436, 365, 14286, 1334, 199, 3, 314, 10697, 844, 26, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 199, 199, 624, 199, 703, 10982, 447, 333, 385, 1710, 11, 9457, 19887, 272, 520, 354, 26, 8728, 47, 23317, 272, 520, 22103, 26, 8728, 19887, 272, 520, 2242, 875, 26, 333, 385, 1710, 11, 9457, 19887, 921, 28, 2473, 30, 16875, 2060, 30, 32, 28, 32510, 354, 30, 272, 520, 633, 26, 1455, 921, 1544, 14, 69, 2268, 1148, 14, 957, 15, 199, 199, 11310, 4900, 83, 199, 18964, 199, 199, 9457, 47, 23317, 4534, 2877, 15725, 402, 5164, 6451, 12, 1808, 314, 199, 1040, 3937, 14, 2526, 8497, 436, 1124, 3937, 14, 2526, 2275, 8497, 3102, 334, 1589, 3499, 3769, 199, 290, 3329, 370, 314, 27980, 8929, 680, 710, 26610, 7704, 675, 402, 282, 6770, 199, 3735, 1240, 2488, 370, 314, 5385, 7146, 653, 1905, 6810, 593, 23317, 5253, 6040, 199, 4657, 19506, 4098, 12, 1830, 314, 19045, 1630, 440, 14, 199, 199, 9457, 47, 23317, 27241, 590, 1454, 7704, 10877, 675, 402, 282, 2849, 16318, 5164, 199, 6526, 5385, 19506, 4098, 365, 1202, 14, 710, 30268, 370, 16318, 5164, 12598, 365, 199, 368, 402, 10238, 14, 710, 2153, 21650, 25331, 365, 626, 5385, 19506, 4098, 965, 282, 13988, 199, 409, 402, 28444, 315, 1314, 5398, 2633, 787, 1334, 14308, 364, 12, 5893, 626, 2985, 199, 11250, 506, 15090, 4453, 314, 1423, 5548, 402, 805, 4882, 12, 26523, 9682, 199, 1589, 4442, 12, 503, 2755, 4453, 1007, 10590, 4453, 314, 4442, 8502, 446, 10663, 314, 4503, 199, 1618, 5398, 2633, 4453, 10468, 9834, 26847, 367, 1006, 1325, 314, 4750, 199, 11184, 513, 530, 9834, 14, 199, 199, 1858, 642, 4499, 12, 314, 8728, 47, 23317, 10982, 4440, 314, 298, 6106, 2, 818, 701, 849, 1454, 367, 199, 10258, 12, 17148, 12, 436, 15137, 9834, 12, 436, 4440, 314, 11077, 1059, 818, 367, 199, 452, 1163, 9834, 14, 199, 199, 2765, 5953, 883, 506, 22284, 4799, 199, 26, 5247, 6054, 14536, 14, 3009, 14, 5599, 14, 18039, 14, 9416, 63, 1419, 64, 1808, 314, 199, 1040, 6106, 63, 19887, 63, 2526, 1040, 3305, 543, 282, 574, 402, 1124, 549, 1040, 503, 1124, 797, 4542, 2382, 282, 199, 585, 402, 1124, 549, 1040, 911, 625, 31565, 675, 5438, 5398, 2633, 436, 282, 574, 199, 1618, 1124, 797, 1040, 911, 625, 31565, 675, 1059, 13, 13572, 2633, 14, 199, 199, 624, 421, 199, 504, 2263, 492, 2943, 465, 23111, 199, 504, 2263, 2242, 1384, 14, 9457, 19887, 492, 603, 88, 47, 23317, 20476, 199, 504, 1275, 647, 19887, 492, 603, 899, 9542, 2206, 2998, 63, 647, 19887, 12, 485, 3053, 14687, 63, 647, 19887, 199, 504, 1275, 1095, 492, 334, 3053, 22080, 12, 673, 603, 2300, 2940, 18625, 9131, 12, 673, 485, 3053, 3926, 12, 485, 3053, 2506, 12, 485, 45, 840, 1036, 9, 421, 199, 533, 485, 3053, 14687, 63, 9457, 19887, 1547, 3053, 14687, 63, 647, 19887, 304, 272, 408, 7826, 1134, 19887, 1159, 8950, 12495, 14, 272, 408, 421, 199, 533, 485, 3053, 2506, 63, 9457, 19887, 1547, 3053, 2506, 304, 272, 347, 5398, 63, 6459, 8, 277, 12, 10982, 304, 267, 347, 2112, 8, 585, 304, 288, 340, 574, 365, 440, 488, 26, 355, 372, 2071, 83, 3295, 83, 3295, 83, 2, 450, 334, 585, 14, 3403, 12, 574, 14, 4482, 12, 574, 14, 2977, 9, 288, 587, 26, 355, 372, 488, 267, 372, 2112, 421, 199, 533, 485, 45, 840, 1036, 63, 9457, 19887, 1547, 45, 840, 1036, 304, 272, 347, 5398, 63, 6459, 8, 277, 12, 10982, 304, 267, 347, 2112, 8, 585, 304, 288, 340, 574, 365, 440, 488, 26, 355, 372, 2071, 83, 2689, 83, 2689, 83, 2, 450, 334, 585, 14, 5180, 12, 574, 14, 10698, 12, 574, 14, 4375, 9, 288, 587, 26, 355, 372, 488, 267, 372, 2112, 421, 199, 533, 603, 899, 9542, 2206, 2998, 63, 9457, 19887, 8, 45, 899, 9542, 2206, 2998, 63, 647, 19887, 304, 272, 408, 272, 710, 1134, 19887, 6451, 1067, 365, 2997, 367, 29310, 272, 10468, 428, 1439, 1510, 63, 7466, 1922, 315, 5560, 2382, 18746, 8502, 272, 1630, 440, 1736, 334, 5987, 543, 5518, 18899, 680, 272, 408, 272, 327, 11386, 446, 315, 27174, 323, 3775, 314, 1134, 19887, 6451, 1067, 272, 327, 755, 365, 7710, 1454, 3769, 1202, 315, 5560, 2382, 18746, 272, 327, 755, 7859, 1133, 1736, 14, 421, 199, 533, 14282, 22080, 63, 9457, 19887, 8, 45, 88, 47, 23317, 20476, 12, 14282, 22080, 304, 339, 327, 642, 365, 1454, 4346, 340, 298, 6106, 593, 23317, 2, 818, 365, 1202, 12, 272, 327, 1314, 365, 3063, 6980, 701, 849, 14, 272, 327, 5164, 63, 5772, 275, 603, 2300, 2940, 18625, 9131, 339, 6451, 63, 3799, 63, 1886, 275, 603, 899, 9542, 2206, 2998, 63, 9457, 19887, 339, 327, 3305, 1202, 701, 485, 3053, 14687, 63, 9457, 19887, 272, 485, 9321, 63, 6355, 63, 970, 275, 715, 339, 1048, 7273, 275, 469, 267, 23111, 14, 14687, 26, 485, 3053, 14687, 63, 9457, 19887, 12, 267, 23111, 14, 3926, 26, 485, 3053, 3926, 12, 267, 23111, 14, 2506, 26, 485, 3053, 2506, 63, 9457, 19887, 12, 267, 23111, 14, 1366, 26, 485, 45, 840, 1036, 63, 9457, 19887, 12, 272, 789, 339, 347, 636, 826, 721, 277, 12, 1369, 63, 2991, 29, 403, 12, 1011, 1162, 304, 267, 1613, 8, 3053, 22080, 63, 9457, 19887, 12, 291, 2843, 826, 14155, 1162, 9, 267, 291, 14, 1802, 63, 2991, 275, 1369, 63, 2991, 199, 199, 11072, 275, 14282, 22080, 63, 9457, 19887, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 333, 385, 1710, 15, 9457, 19887, 14, 647, 199, 3, 1898, 334, 35, 9, 11811, 13, 9261, 314, 14303, 11462, 436, 8417, 199, 3, 665, 3239, 10610, 570, 30, 199, 3, 199, 3, 961, 859, 365, 1777, 402, 14303, 436, 365, 14286, 1334, 199, 3, 314, 10697, 844, 26, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 199, 199, 624, 199, 703, 10982, 447, 333, 385, 1710, 11, 9457, 19887, 272, 520, 354, 26, 8728, 47, 23317, 272, 520, 22103, 26, 8728, 19887, 272, 520, 2242, 875, 26, 333, 385, 1710, 11, 9457, 19887, 921, 28, 2473, 30, 16875, 2060, 30, 32, 28, 32510, 354, 30, 272, 520, 633, 26, 1455, 921, 1544, 14, 69, 2268, 1148, 14, 957, 15, 199, 199, 11310, 4900, 83, 199, 18964, 199, 199, 9457, 47, 23317, 4534, 2877, 15725, 402, 5164, 6451, 12, 1808, 314, 199, 1040, 3937, 14, 2526, 8497, 436, 1124, 3937, 14, 2526, 2275, 8497, 3102, 334, 1589, 3499, 3769, 199, 290, 3329, 370, 314, 27980, 8929, 680, 710, 26610, 7704, 675, 402, 282, 6770, 199, 3735, 1240, 2488, 370, 314, 5385, 7146, 653, 1905, 6810, 593, 23317, 5253, 6040, 199, 4657, 19506, 4098, 12, 1830, 314, 19045, 1630, 440, 14, 199, 199, 9457, 47, 23317, 27241, 590, 1454, 7704, 10877, 675, 402, 282, 2849, 16318, 5164, 199, 6526, 5385, 19506, 4098, 365, 1202, 14, 710, 30268, 370, 16318, 5164, 12598, 365, 199, 368, 402, 10238, 14, 710, 2153, 21650, 25331, 365, 626, 5385, 19506, 4098, 965, 282, 13988, 199, 409, 402, 28444, 315, 1314, 5398, 2633, 787, 1334, 14308, 364, 12, 5893, 626, 2985, 199, 11250, 506, 15090, 4453, 314, 1423, 5548, 402, 805, 4882, 12, 26523, 9682, 199, 1589, 4442, 12, 503, 2755, 4453, 1007, 10590, 4453, 314, 4442, 8502, 446, 10663, 314, 4503, 199, 1618, 5398, 2633, 4453, 10468, 9834, 26847, 367, 1006, 1325, 314, 4750, 199, 11184, 513, 530, 9834, 14, 199, 199, 1858, 642, 4499, 12, 314, 8728, 47, 23317, 10982, 4440, 314, 298, 6106, 2, 818, 701, 849, 1454, 367, 199, 10258, 12, 17148, 12, 436, 15137, 9834, 12, 436, 4440, 314, 11077, 1059, 818, 367, 199, 452, 1163, 9834, 14, 199, 199, 2765, 5953, 883, 506, 22284, 4799, 199, 26, 5247, 6054, 14536, 14, 3009, 14, 5599, 14, 18039, 14, 9416, 63, 1419, 64, 1808, 314, 199, 1040, 6106, 63, 19887, 63, 2526, 1040, 3305, 543, 282, 574, 402, 1124, 549, 1040, 503, 1124, 797, 4542, 2382, 282, 199, 585, 402, 1124, 549, 1040, 911, 625, 31565, 675, 5438, 5398, 2633, 436, 282, 574, 199, 1618, 1124, 797, 1040, 911, 625, 31565, 675, 1059, 13, 13572, 2633, 14, 199, 199, 624, 421, 199, 504, 2263, 492, 2943, 465, 23111, 199, 504, 2263, 2242, 1384, 14, 9457, 19887, 492, 603, 88, 47, 23317, 20476, 199, 504, 1275, 647, 19887, 492, 603, 899, 9542, 2206, 2998, 63, 647, 19887, 12, 485, 3053, 14687, 63, 647, 19887, 199, 504, 1275, 1095, 492, 334, 3053, 22080, 12, 673, 603, 2300, 2940, 18625, 9131, 12, 673, 485, 3053, 3926, 12, 485, 3053, 2506, 12, 485, 45, 840, 1036, 9, 421, 199, 533, 485, 3053, 14687, 63, 9457, 19887, 1547, 3053, 14687, 63, 647, 19887, 304, 272, 408, 7826, 1134, 19887, 1159, 8950, 12495, 14, 272, 408, 421, 199, 533, 485, 3053, 2506, 63, 9457, 19887, 1547, 3053, 2506, 304, 272, 347, 5398, 63, 6459, 8, 277, 12, 10982, 304, 267, 347, 2112, 8, 585, 304, 288, 340, 574, 365, 440, 488, 26, 355, 372, 2071, 83, 3295, 83, 3295, 83, 2, 450, 334, 585, 14, 3403, 12, 574, 14, 4482, 12, 574, 14, 2977, 9, 288, 587, 26, 355, 372, 488, 267, 372, 2112, 421, 199, 533, 485, 45, 840, 1036, 63, 9457, 19887, 1547, 45, 840, 1036, 304, 272, 347, 5398, 63, 6459, 8, 277, 12, 10982, 304, 267, 347, 2112, 8, 585, 304, 288, 340, 574, 365, 440, 488, 26, 355, 372, 2071, 83, 2689, 83, 2689, 83, 2, 450, 334, 585, 14, 5180, 12, 574, 14, 10698, 12, 574, 14, 4375, 9, 288, 587, 26, 355, 372, 488, 267, 372, 2112, 421, 199, 533, 603, 899, 9542, 2206, 2998, 63, 9457, 19887, 8, 45, 899, 9542, 2206, 2998, 63, 647, 19887, 304, 272, 408, 272, 710, 1134, 19887, 6451, 1067, 365, 2997, 367, 29310, 272, 10468, 428, 1439, 1510, 63, 7466, 1922, 315, 5560, 2382, 18746, 8502, 272, 1630, 440, 1736, 334, 5987, 543, 5518, 18899, 680, 272, 408, 272, 327, 11386, 446, 315, 27174, 323, 3775, 314, 1134, 19887, 6451, 1067, 272, 327, 755, 365, 7710, 1454, 3769, 1202, 315, 5560, 2382, 18746, 272, 327, 755, 7859, 1133, 1736, 14, 421, 199, 533, 14282, 22080, 63, 9457, 19887, 8, 45, 88, 47, 23317, 20476, 12, 14282, 22080, 304, 339, 327, 642, 365, 1454, 4346, 340, 298, 6106, 593, 23317, 2, 818, 365, 1202, 12, 272, 327, 1314, 365, 3063, 6980, 701, 849, 14, 272, 327, 5164, 63, 5772, 275, 603, 2300, 2940, 18625, 9131, 339, 6451, 63, 3799, 63, 1886, 275, 603, 899, 9542, 2206, 2998, 63, 9457, 19887, 339, 327, 3305, 1202, 701, 485, 3053, 14687, 63, 9457, 19887, 272, 485, 9321, 63, 6355, 63, 970, 275, 715, 339, 1048, 7273, 275, 469, 267, 23111, 14, 14687, 26, 485, 3053, 14687, 63, 9457, 19887, 12, 267, 23111, 14, 3926, 26, 485, 3053, 3926, 12, 267, 23111, 14, 2506, 26, 485, 3053, 2506, 63, 9457, 19887, 12, 267, 23111, 14, 1366, 26, 485, 45, 840, 1036, 63, 9457, 19887, 12, 272, 789, 339, 347, 636, 826, 721, 277, 12, 1369, 63, 2991, 29, 403, 12, 1011, 1162, 304, 267, 1613, 8, 3053, 22080, 63, 9457, 19887, 12, 291, 2843, 826, 14155, 1162, 9, 267, 291, 14, 1802, 63, 2991, 275, 1369, 63, 2991, 199, 199, 11072, 275, 14282, 22080, 63, 9457, 19887, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
chase-qi/workload-automation
wlauto/core/entry_point.py
5
3530
# Copyright 2013-2015 ARM Limited # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import sys import argparse import logging import os import subprocess import warnings from wlauto.core.bootstrap import settings from wlauto.core.extension_loader import ExtensionLoader from wlauto.exceptions import WAError, ConfigError from wlauto.utils.misc import get_traceback from wlauto.utils.log import init_logging from wlauto.utils.cli import init_argument_parser from wlauto.utils.doc import format_body warnings.filterwarnings(action='ignore', category=UserWarning, module='zope') logger = logging.getLogger('command_line') def load_commands(subparsers): ext_loader = ExtensionLoader(paths=settings.extension_paths) for command in ext_loader.list_commands(): settings.commands[command.name] = ext_loader.get_command(command.name, subparsers=subparsers) def main(): try: description = ("Execute automated workloads on a remote device and process " "the resulting output.\n\nUse \"wa <subcommand> -h\" to see " "help for individual subcommands.") parser = argparse.ArgumentParser(description=format_body(description, 80), prog='wa', formatter_class=argparse.RawDescriptionHelpFormatter, ) init_argument_parser(parser) load_commands(parser.add_subparsers(dest='command')) # each command will add its own subparser args = parser.parse_args() settings.verbosity = args.verbose settings.debug = args.debug if args.config: if not os.path.exists(args.config): raise ConfigError("Config file {} not found".format(args.config)) settings.update(args.config) init_logging(settings.verbosity) command = settings.commands[args.command] sys.exit(command.execute(args)) except KeyboardInterrupt: logging.info('Got CTRL-C. Aborting.') sys.exit(3) except WAError as e: logging.critical(e) sys.exit(1) except subprocess.CalledProcessError as e: tb = get_traceback() logging.critical(tb) command = e.cmd if e.args: command = '{} {}'.format(command, ' '.join(e.args)) message = 'Command \'{}\' returned non-zero exit status {}\nOUTPUT:\n{}\n' logging.critical(message.format(command, e.returncode, e.output)) sys.exit(2) except SyntaxError as e: tb = get_traceback() logging.critical(tb) message = 'Syntax Error in {}, line {}, offset {}:' logging.critical(message.format(e.filename, e.lineno, e.offset)) logging.critical('\t{}'.format(e.msg)) sys.exit(2) except Exception as e: # pylint: disable=broad-except tb = get_traceback() logging.critical(tb) logging.critical('{}({})'.format(e.__class__.__name__, e)) sys.exit(2)
apache-2.0
[ 3, 259, 1898, 6171, 13, 7806, 27155, 23954, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 421, 199, 646, 984, 199, 646, 7534, 199, 646, 2050, 199, 646, 747, 199, 646, 3873, 199, 646, 3598, 199, 199, 504, 336, 416, 1283, 14, 1018, 14, 11146, 492, 2202, 199, 504, 336, 416, 1283, 14, 1018, 14, 3435, 63, 3422, 492, 13282, 5455, 199, 504, 336, 416, 1283, 14, 3924, 492, 644, 33, 547, 12, 4094, 547, 199, 504, 336, 416, 1283, 14, 1208, 14, 9923, 492, 664, 63, 6894, 199, 504, 336, 416, 1283, 14, 1208, 14, 793, 492, 4205, 63, 4806, 199, 504, 336, 416, 1283, 14, 1208, 14, 2764, 492, 4205, 63, 2094, 63, 2087, 199, 504, 336, 416, 1283, 14, 1208, 14, 1301, 492, 1475, 63, 2030, 421, 199, 5451, 14, 23945, 8, 1287, 534, 4247, 297, 4637, 29, 32114, 12, 859, 534, 90, 13458, 358, 421, 199, 2921, 275, 2050, 14, 5572, 360, 1531, 63, 604, 358, 421, 199, 318, 2248, 63, 4405, 8, 954, 11531, 304, 272, 1599, 63, 3422, 275, 13282, 5455, 8, 3771, 29, 1751, 14, 3435, 63, 3771, 9, 272, 367, 1414, 315, 1599, 63, 3422, 14, 513, 63, 4405, 837, 267, 2202, 14, 4405, 59, 1531, 14, 354, 61, 275, 1599, 63, 3422, 14, 362, 63, 1531, 8, 1531, 14, 354, 12, 26763, 29, 954, 11531, 9, 421, 199, 318, 2446, 837, 272, 862, 26, 267, 1369, 275, 1689, 12049, 6384, 23513, 1736, 3640, 641, 282, 3982, 2243, 436, 2112, 298, 2432, 298, 1589, 9183, 1072, 3134, 78, 60, 78, 6119, 8441, 758, 665, 954, 1531, 30, 446, 72, 4451, 370, 1937, 298, 2432, 298, 3437, 367, 8212, 1007, 4405, 2685, 267, 1798, 275, 7534, 14, 10730, 8, 1802, 29, 908, 63, 2030, 8, 1802, 12, 5939, 395, 1460, 13205, 534, 758, 297, 1460, 9698, 63, 533, 29, 18978, 14, 7963, 5831, 22779, 12, 1460, 776, 267, 4205, 63, 2094, 63, 2087, 8, 2087, 9, 267, 2248, 63, 4405, 8, 2087, 14, 525, 63, 954, 11531, 8, 2614, 534, 1531, 1333, 221, 327, 1924, 1414, 911, 1050, 2399, 5705, 1007, 2087, 267, 1249, 275, 1798, 14, 1122, 63, 589, 342, 267, 2202, 14, 9833, 275, 1249, 14, 3832, 267, 2202, 14, 1757, 275, 1249, 14, 1757, 267, 340, 1249, 14, 888, 26, 288, 340, 440, 747, 14, 515, 14, 2444, 8, 589, 14, 888, 304, 355, 746, 4094, 547, 480, 2028, 570, 1052, 440, 1911, 1674, 908, 8, 589, 14, 888, 430, 288, 2202, 14, 873, 8, 589, 14, 888, 9, 267, 4205, 63, 4806, 8, 1751, 14, 9833, 9, 398, 1414, 275, 2202, 14, 4405, 59, 589, 14, 1531, 61, 267, 984, 14, 2224, 8, 1531, 14, 2526, 8, 589, 430, 339, 871, 13483, 26, 267, 2050, 14, 815, 360, 13662, 445, 1766, 44, 13, 35, 14, 31455, 316, 2659, 267, 984, 14, 2224, 8, 19, 9, 272, 871, 644, 33, 547, 465, 325, 26, 267, 2050, 14, 13138, 8, 69, 9, 267, 984, 14, 2224, 8, 17, 9, 272, 871, 3873, 14, 24691, 465, 325, 26, 267, 7070, 275, 664, 63, 6894, 342, 267, 2050, 14, 13138, 8, 5842, 9, 267, 1414, 275, 325, 14, 1760, 267, 340, 325, 14, 589, 26, 288, 1414, 275, 9005, 9499, 908, 8, 1531, 12, 283, 1987, 904, 8, 69, 14, 589, 430, 267, 1245, 275, 283, 3110, 8891, 2440, 3985, 2138, 2222, 13, 4262, 4458, 2004, 22902, 78, 8414, 3427, 78, 24423, 78, 7, 267, 2050, 14, 13138, 8, 1188, 14, 908, 8, 1531, 12, 325, 14, 9913, 12, 325, 14, 1199, 430, 267, 984, 14, 2224, 8, 18, 9, 272, 871, 12053, 465, 325, 26, 267, 7070, 275, 664, 63, 6894, 342, 267, 2050, 14, 13138, 8, 5842, 9, 267, 1245, 275, 283, 16626, 4520, 315, 5479, 1004, 5479, 3268, 1052, 4881, 267, 2050, 14, 13138, 8, 1188, 14, 908, 8, 69, 14, 1501, 12, 325, 14, 3469, 12, 325, 14, 2743, 430, 267, 2050, 14, 13138, 2258, 84, 11123, 908, 8, 69, 14, 1328, 430, 267, 984, 14, 2224, 8, 18, 9, 272, 871, 2186, 465, 325, 26, 221, 327, 4287, 26, 3507, 29, 29047, 13, 2590, 267, 7070, 275, 664, 63, 6894, 342, 267, 2050, 14, 13138, 8, 5842, 9, 267, 2050, 14, 13138, 17519, 14079, 1370, 908, 8, 69, 855, 533, 4914, 354, 3108, 325, 430, 267, 984, 14, 2224, 8, 18, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 259, 1898, 6171, 13, 7806, 27155, 23954, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 421, 199, 646, 984, 199, 646, 7534, 199, 646, 2050, 199, 646, 747, 199, 646, 3873, 199, 646, 3598, 199, 199, 504, 336, 416, 1283, 14, 1018, 14, 11146, 492, 2202, 199, 504, 336, 416, 1283, 14, 1018, 14, 3435, 63, 3422, 492, 13282, 5455, 199, 504, 336, 416, 1283, 14, 3924, 492, 644, 33, 547, 12, 4094, 547, 199, 504, 336, 416, 1283, 14, 1208, 14, 9923, 492, 664, 63, 6894, 199, 504, 336, 416, 1283, 14, 1208, 14, 793, 492, 4205, 63, 4806, 199, 504, 336, 416, 1283, 14, 1208, 14, 2764, 492, 4205, 63, 2094, 63, 2087, 199, 504, 336, 416, 1283, 14, 1208, 14, 1301, 492, 1475, 63, 2030, 421, 199, 5451, 14, 23945, 8, 1287, 534, 4247, 297, 4637, 29, 32114, 12, 859, 534, 90, 13458, 358, 421, 199, 2921, 275, 2050, 14, 5572, 360, 1531, 63, 604, 358, 421, 199, 318, 2248, 63, 4405, 8, 954, 11531, 304, 272, 1599, 63, 3422, 275, 13282, 5455, 8, 3771, 29, 1751, 14, 3435, 63, 3771, 9, 272, 367, 1414, 315, 1599, 63, 3422, 14, 513, 63, 4405, 837, 267, 2202, 14, 4405, 59, 1531, 14, 354, 61, 275, 1599, 63, 3422, 14, 362, 63, 1531, 8, 1531, 14, 354, 12, 26763, 29, 954, 11531, 9, 421, 199, 318, 2446, 837, 272, 862, 26, 267, 1369, 275, 1689, 12049, 6384, 23513, 1736, 3640, 641, 282, 3982, 2243, 436, 2112, 298, 2432, 298, 1589, 9183, 1072, 3134, 78, 60, 78, 6119, 8441, 758, 665, 954, 1531, 30, 446, 72, 4451, 370, 1937, 298, 2432, 298, 3437, 367, 8212, 1007, 4405, 2685, 267, 1798, 275, 7534, 14, 10730, 8, 1802, 29, 908, 63, 2030, 8, 1802, 12, 5939, 395, 1460, 13205, 534, 758, 297, 1460, 9698, 63, 533, 29, 18978, 14, 7963, 5831, 22779, 12, 1460, 776, 267, 4205, 63, 2094, 63, 2087, 8, 2087, 9, 267, 2248, 63, 4405, 8, 2087, 14, 525, 63, 954, 11531, 8, 2614, 534, 1531, 1333, 221, 327, 1924, 1414, 911, 1050, 2399, 5705, 1007, 2087, 267, 1249, 275, 1798, 14, 1122, 63, 589, 342, 267, 2202, 14, 9833, 275, 1249, 14, 3832, 267, 2202, 14, 1757, 275, 1249, 14, 1757, 267, 340, 1249, 14, 888, 26, 288, 340, 440, 747, 14, 515, 14, 2444, 8, 589, 14, 888, 304, 355, 746, 4094, 547, 480, 2028, 570, 1052, 440, 1911, 1674, 908, 8, 589, 14, 888, 430, 288, 2202, 14, 873, 8, 589, 14, 888, 9, 267, 4205, 63, 4806, 8, 1751, 14, 9833, 9, 398, 1414, 275, 2202, 14, 4405, 59, 589, 14, 1531, 61, 267, 984, 14, 2224, 8, 1531, 14, 2526, 8, 589, 430, 339, 871, 13483, 26, 267, 2050, 14, 815, 360, 13662, 445, 1766, 44, 13, 35, 14, 31455, 316, 2659, 267, 984, 14, 2224, 8, 19, 9, 272, 871, 644, 33, 547, 465, 325, 26, 267, 2050, 14, 13138, 8, 69, 9, 267, 984, 14, 2224, 8, 17, 9, 272, 871, 3873, 14, 24691, 465, 325, 26, 267, 7070, 275, 664, 63, 6894, 342, 267, 2050, 14, 13138, 8, 5842, 9, 267, 1414, 275, 325, 14, 1760, 267, 340, 325, 14, 589, 26, 288, 1414, 275, 9005, 9499, 908, 8, 1531, 12, 283, 1987, 904, 8, 69, 14, 589, 430, 267, 1245, 275, 283, 3110, 8891, 2440, 3985, 2138, 2222, 13, 4262, 4458, 2004, 22902, 78, 8414, 3427, 78, 24423, 78, 7, 267, 2050, 14, 13138, 8, 1188, 14, 908, 8, 1531, 12, 325, 14, 9913, 12, 325, 14, 1199, 430, 267, 984, 14, 2224, 8, 18, 9, 272, 871, 12053, 465, 325, 26, 267, 7070, 275, 664, 63, 6894, 342, 267, 2050, 14, 13138, 8, 5842, 9, 267, 1245, 275, 283, 16626, 4520, 315, 5479, 1004, 5479, 3268, 1052, 4881, 267, 2050, 14, 13138, 8, 1188, 14, 908, 8, 69, 14, 1501, 12, 325, 14, 3469, 12, 325, 14, 2743, 430, 267, 2050, 14, 13138, 2258, 84, 11123, 908, 8, 69, 14, 1328, 430, 267, 984, 14, 2224, 8, 18, 9, 272, 871, 2186, 465, 325, 26, 221, 327, 4287, 26, 3507, 29, 29047, 13, 2590, 267, 7070, 275, 664, 63, 6894, 342, 267, 2050, 14, 13138, 8, 5842, 9, 267, 2050, 14, 13138, 17519, 14079, 1370, 908, 8, 69, 855, 533, 4914, 354, 3108, 325, 430, 267, 984, 14, 2224, 8, 18, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
raymondxyang/tensorflow
tensorflow/examples/get_started/regression/linear_regression.py
8
3291
# Copyright 2016 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """Linear regression using the LinearRegressor Estimator.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import numpy as np import tensorflow as tf import imports85 # pylint: disable=g-bad-import-order STEPS = 1000 def main(argv): """Builds, trains, and evaluates the model.""" assert len(argv) == 1 (x_train, y_train), (x_test, y_test) = imports85.load_data() # Build the training input_fn. input_train = tf.estimator.inputs.pandas_input_fn( x=x_train, y=y_train, # Setting `num_epochs` to `None` lets the `inpuf_fn` generate data # indefinitely, leaving the call to `Estimator.train` in control. num_epochs=None, shuffle=True) # Build the validation input_fn. input_test = tf.estimator.inputs.pandas_input_fn( x=x_test, y=y_test, shuffle=True) feature_columns = [ # "curb-weight" and "highway-mpg" are numeric columns. tf.feature_column.numeric_column(key="curb-weight"), tf.feature_column.numeric_column(key="highway-mpg"), ] # Build the Estimator. model = tf.estimator.LinearRegressor(feature_columns=feature_columns) # Train the model. # By default, the Estimators log output every 100 steps. model.train(input_fn=input_train, steps=STEPS) # Evaluate how the model performs on data it has not yet seen. eval_result = model.evaluate(input_fn=input_test) # The evaluation returns a Python dictionary. The "average_loss" key holds the # Mean Squared Error (MSE). average_loss = eval_result["average_loss"] # Convert MSE to Root Mean Square Error (RMSE). print("\n" + 80 * "*") print("\nRMS error for the test set: ${:.0f}".format(average_loss**0.5)) # Run the model in prediction mode. input_dict = { "curb-weight": np.array([2000, 3000]), "highway-mpg": np.array([30, 40]) } predict_input_fn = tf.estimator.inputs.numpy_input_fn( input_dict, shuffle=False) predict_results = model.predict(input_fn=predict_input_fn) # Print the prediction results. print("\nPrediction results:") for i, prediction in enumerate(predict_results): msg = ("Curb weight: {: 4d}lbs, " "Highway: {: 0d}mpg, " "Prediction: ${: 9.2f}") msg = msg.format(input_dict["curb-weight"][i], input_dict["highway-mpg"][i], prediction["predictions"][0]) print(" " + msg) print() if __name__ == "__main__": # The Estimator periodically generates "INFO" logs; make these logs visible. tf.logging.set_verbosity(tf.logging.INFO) tf.app.run(main=main)
apache-2.0
[ 3, 1898, 7800, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 10608, 10864, 1808, 314, 12489, 15155, 28992, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2680, 465, 980, 199, 646, 3228, 465, 2833, 199, 199, 646, 8925, 2426, 221, 327, 4287, 26, 3507, 29, 71, 13, 4087, 13, 646, 13, 1648, 199, 199, 840, 25711, 275, 5198, 421, 199, 318, 2446, 8, 3020, 304, 523, 408, 27856, 12, 3560, 83, 12, 436, 22014, 314, 1402, 1041, 523, 702, 822, 8, 3020, 9, 508, 413, 523, 334, 88, 63, 2834, 12, 612, 63, 2834, 395, 334, 88, 63, 396, 12, 612, 63, 396, 9, 275, 8925, 2426, 14, 912, 63, 576, 342, 819, 327, 6516, 314, 6093, 1324, 63, 2324, 14, 523, 1324, 63, 2834, 275, 2833, 14, 8627, 14, 3711, 14, 15718, 63, 1210, 63, 2324, 8, 489, 671, 29, 88, 63, 2834, 12, 489, 612, 29, 89, 63, 2834, 12, 489, 327, 13510, 658, 1507, 63, 13161, 64, 370, 658, 403, 64, 19083, 314, 658, 11416, 1286, 63, 2324, 64, 3550, 666, 489, 327, 315, 23442, 590, 12, 23188, 314, 1240, 370, 658, 13183, 14, 2834, 64, 315, 3304, 14, 489, 1967, 63, 13161, 29, 403, 12, 489, 13031, 29, 549, 9, 819, 327, 6516, 314, 6411, 1324, 63, 2324, 14, 523, 1324, 63, 396, 275, 2833, 14, 8627, 14, 3711, 14, 15718, 63, 1210, 63, 2324, 8, 489, 671, 29, 88, 63, 396, 12, 612, 29, 89, 63, 396, 12, 13031, 29, 549, 9, 819, 3878, 63, 3406, 275, 359, 489, 327, 298, 895, 66, 13, 3463, 2, 436, 298, 6260, 3316, 13, 311, 71, 2, 787, 8950, 4362, 14, 489, 2833, 14, 4445, 63, 2301, 14, 6677, 63, 2301, 8, 498, 628, 895, 66, 13, 3463, 1288, 489, 2833, 14, 4445, 63, 2301, 14, 6677, 63, 2301, 8, 498, 628, 6260, 3316, 13, 311, 71, 1288, 523, 1622, 819, 327, 6516, 314, 28992, 14, 523, 1402, 275, 2833, 14, 8627, 14, 10608, 15155, 8, 4445, 63, 3406, 29, 4445, 63, 3406, 9, 819, 327, 16732, 314, 1402, 14, 523, 327, 4885, 849, 12, 314, 15896, 9095, 943, 1072, 4036, 2948, 7124, 14, 523, 1402, 14, 2834, 8, 1210, 63, 2324, 29, 1210, 63, 2834, 12, 7124, 29, 840, 25711, 9, 819, 327, 27450, 4212, 314, 1402, 18628, 641, 666, 652, 965, 440, 5966, 6775, 14, 523, 3468, 63, 1099, 275, 1402, 14, 7383, 8, 1210, 63, 2324, 29, 1210, 63, 396, 9, 819, 327, 710, 11735, 2529, 282, 2018, 2600, 14, 710, 298, 8536, 63, 4358, 2, 790, 15164, 314, 523, 327, 25136, 428, 30458, 4520, 334, 45, 899, 680, 523, 8095, 63, 4358, 275, 3468, 63, 1099, 905, 8536, 63, 4358, 937, 819, 327, 7905, 603, 899, 370, 12826, 25136, 428, 5937, 4520, 334, 11026, 899, 680, 523, 870, 4582, 78, 2, 435, 5939, 627, 8969, 531, 523, 870, 4582, 78, 50, 3053, 1125, 367, 314, 511, 663, 26, 10839, 14010, 16, 70, 5469, 908, 8, 8536, 63, 4358, 538, 16, 14, 21, 430, 819, 327, 3378, 314, 1402, 315, 12044, 818, 14, 523, 1324, 63, 807, 275, 469, 489, 298, 895, 66, 13, 3463, 582, 980, 14, 1144, 779, 8269, 12, 29664, 2522, 489, 298, 6260, 3316, 13, 311, 71, 582, 980, 14, 1144, 779, 1216, 12, 6335, 566, 523, 789, 523, 12610, 63, 1210, 63, 2324, 275, 2833, 14, 8627, 14, 3711, 14, 4714, 63, 1210, 63, 2324, 8, 489, 1324, 63, 807, 12, 13031, 29, 797, 9, 523, 12610, 63, 2604, 275, 1402, 14, 6892, 8, 1210, 63, 2324, 29, 6892, 63, 1210, 63, 2324, 9, 819, 327, 9101, 314, 12044, 2058, 14, 523, 870, 4582, 78, 24261, 2058, 9107, 523, 367, 284, 12, 12044, 315, 3874, 8, 6892, 63, 2604, 304, 272, 1499, 275, 1689, 3864, 66, 5401, 26, 19850, 841, 68, 93, 76, 1533, 12, 298, 1779, 298, 11688, 3316, 26, 19850, 378, 68, 93, 311, 71, 12, 298, 1779, 298, 24261, 26, 10839, 26, 1749, 14, 18, 70, 15412, 272, 1499, 275, 1499, 14, 908, 8, 1210, 63, 807, 905, 895, 66, 13, 3463, 9210, 73, 467, 1324, 63, 807, 905, 6260, 3316, 13, 311, 71, 9210, 73, 467, 2151, 12044, 905, 9869, 9210, 16, 566, 339, 870, 480, 259, 298, 435, 1499, 9, 523, 870, 342, 421, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 523, 327, 710, 28992, 18745, 1183, 12821, 298, 4531, 2, 9610, 27, 1852, 3520, 9610, 8917, 14, 523, 2833, 14, 4806, 14, 409, 63, 9833, 8, 3249, 14, 4806, 14, 4531, 9, 523, 2833, 14, 571, 14, 1065, 8, 973, 29, 973, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1898, 7800, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 10608, 10864, 1808, 314, 12489, 15155, 28992, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2680, 465, 980, 199, 646, 3228, 465, 2833, 199, 199, 646, 8925, 2426, 221, 327, 4287, 26, 3507, 29, 71, 13, 4087, 13, 646, 13, 1648, 199, 199, 840, 25711, 275, 5198, 421, 199, 318, 2446, 8, 3020, 304, 523, 408, 27856, 12, 3560, 83, 12, 436, 22014, 314, 1402, 1041, 523, 702, 822, 8, 3020, 9, 508, 413, 523, 334, 88, 63, 2834, 12, 612, 63, 2834, 395, 334, 88, 63, 396, 12, 612, 63, 396, 9, 275, 8925, 2426, 14, 912, 63, 576, 342, 819, 327, 6516, 314, 6093, 1324, 63, 2324, 14, 523, 1324, 63, 2834, 275, 2833, 14, 8627, 14, 3711, 14, 15718, 63, 1210, 63, 2324, 8, 489, 671, 29, 88, 63, 2834, 12, 489, 612, 29, 89, 63, 2834, 12, 489, 327, 13510, 658, 1507, 63, 13161, 64, 370, 658, 403, 64, 19083, 314, 658, 11416, 1286, 63, 2324, 64, 3550, 666, 489, 327, 315, 23442, 590, 12, 23188, 314, 1240, 370, 658, 13183, 14, 2834, 64, 315, 3304, 14, 489, 1967, 63, 13161, 29, 403, 12, 489, 13031, 29, 549, 9, 819, 327, 6516, 314, 6411, 1324, 63, 2324, 14, 523, 1324, 63, 396, 275, 2833, 14, 8627, 14, 3711, 14, 15718, 63, 1210, 63, 2324, 8, 489, 671, 29, 88, 63, 396, 12, 612, 29, 89, 63, 396, 12, 13031, 29, 549, 9, 819, 3878, 63, 3406, 275, 359, 489, 327, 298, 895, 66, 13, 3463, 2, 436, 298, 6260, 3316, 13, 311, 71, 2, 787, 8950, 4362, 14, 489, 2833, 14, 4445, 63, 2301, 14, 6677, 63, 2301, 8, 498, 628, 895, 66, 13, 3463, 1288, 489, 2833, 14, 4445, 63, 2301, 14, 6677, 63, 2301, 8, 498, 628, 6260, 3316, 13, 311, 71, 1288, 523, 1622, 819, 327, 6516, 314, 28992, 14, 523, 1402, 275, 2833, 14, 8627, 14, 10608, 15155, 8, 4445, 63, 3406, 29, 4445, 63, 3406, 9, 819, 327, 16732, 314, 1402, 14, 523, 327, 4885, 849, 12, 314, 15896, 9095, 943, 1072, 4036, 2948, 7124, 14, 523, 1402, 14, 2834, 8, 1210, 63, 2324, 29, 1210, 63, 2834, 12, 7124, 29, 840, 25711, 9, 819, 327, 27450, 4212, 314, 1402, 18628, 641, 666, 652, 965, 440, 5966, 6775, 14, 523, 3468, 63, 1099, 275, 1402, 14, 7383, 8, 1210, 63, 2324, 29, 1210, 63, 396, 9, 819, 327, 710, 11735, 2529, 282, 2018, 2600, 14, 710, 298, 8536, 63, 4358, 2, 790, 15164, 314, 523, 327, 25136, 428, 30458, 4520, 334, 45, 899, 680, 523, 8095, 63, 4358, 275, 3468, 63, 1099, 905, 8536, 63, 4358, 937, 819, 327, 7905, 603, 899, 370, 12826, 25136, 428, 5937, 4520, 334, 11026, 899, 680, 523, 870, 4582, 78, 2, 435, 5939, 627, 8969, 531, 523, 870, 4582, 78, 50, 3053, 1125, 367, 314, 511, 663, 26, 10839, 14010, 16, 70, 5469, 908, 8, 8536, 63, 4358, 538, 16, 14, 21, 430, 819, 327, 3378, 314, 1402, 315, 12044, 818, 14, 523, 1324, 63, 807, 275, 469, 489, 298, 895, 66, 13, 3463, 582, 980, 14, 1144, 779, 8269, 12, 29664, 2522, 489, 298, 6260, 3316, 13, 311, 71, 582, 980, 14, 1144, 779, 1216, 12, 6335, 566, 523, 789, 523, 12610, 63, 1210, 63, 2324, 275, 2833, 14, 8627, 14, 3711, 14, 4714, 63, 1210, 63, 2324, 8, 489, 1324, 63, 807, 12, 13031, 29, 797, 9, 523, 12610, 63, 2604, 275, 1402, 14, 6892, 8, 1210, 63, 2324, 29, 6892, 63, 1210, 63, 2324, 9, 819, 327, 9101, 314, 12044, 2058, 14, 523, 870, 4582, 78, 24261, 2058, 9107, 523, 367, 284, 12, 12044, 315, 3874, 8, 6892, 63, 2604, 304, 272, 1499, 275, 1689, 3864, 66, 5401, 26, 19850, 841, 68, 93, 76, 1533, 12, 298, 1779, 298, 11688, 3316, 26, 19850, 378, 68, 93, 311, 71, 12, 298, 1779, 298, 24261, 26, 10839, 26, 1749, 14, 18, 70, 15412, 272, 1499, 275, 1499, 14, 908, 8, 1210, 63, 807, 905, 895, 66, 13, 3463, 9210, 73, 467, 1324, 63, 807, 905, 6260, 3316, 13, 311, 71, 9210, 73, 467, 2151, 12044, 905, 9869, 9210, 16, 566, 339, 870, 480, 259, 298, 435, 1499, 9, 523, 870, 342, 421, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 523, 327, 710, 28992, 18745, 1183, 12821, 298, 4531, 2, 9610, 27, 1852, 3520, 9610, 8917, 14, 523, 2833, 14, 4806, 14, 409, 63, 9833, 8, 3249, 14, 4806, 14, 4531, 9, 523, 2833, 14, 571, 14, 1065, 8, 973, 29, 973, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
bksim/chinese-translation
nltk/classify/megam.py
5
6265
# Natural Language Toolkit: Interface to Megam Classifier # # Copyright (C) 2001-2012 NLTK Project # Author: Edward Loper <edloper@gradient.cis.upenn.edu> # URL: <http://www.nltk.org/> # For license information, see LICENSE.TXT """ A set of functions used to interface with the external megam_ maxent optimization package. Before megam can be used, you should tell NLTK where it can find the megam binary, using the ``config_megam()`` function. Typical usage: .. doctest:: :options: +SKIP >>> from nltk.classify import megam >>> megam.config_megam() # pass path to megam if not found in PATH [Found megam: ...] Use with MaxentClassifier. Example below, see MaxentClassifier documentation for details. nltk.classify.MaxentClassifier.train(corpus, 'megam') .. _megam: http://www.cs.utah.edu/~hal/megam/ """ from __future__ import print_function import os import os.path import subprocess from nltk.internals import find_binary try: import numpy except ImportError: numpy = None ###################################################################### #{ Configuration ###################################################################### _megam_bin = None def config_megam(bin=None): """ Configure NLTK's interface to the ``megam`` maxent optimization package. :param bin: The full path to the ``megam`` binary. If not specified, then nltk will search the system for a ``megam`` binary; and if one is not found, it will raise a ``LookupError`` exception. :type bin: str """ global _megam_bin _megam_bin = find_binary( 'megam', bin, env_vars=['MEGAM', 'MEGAMHOME'], binary_names=['megam.opt', 'megam', 'megam_686', 'megam_i686.opt'], url='http://www.cs.utah.edu/~hal/megam/') ###################################################################### #{ Megam Interface Functions ###################################################################### def write_megam_file(train_toks, encoding, stream, bernoulli=True, explicit=True): """ Generate an input file for ``megam`` based on the given corpus of classified tokens. :type train_toks: list(tuple(dict, str)) :param train_toks: Training data, represented as a list of pairs, the first member of which is a feature dictionary, and the second of which is a classification label. :type encoding: MaxentFeatureEncodingI :param encoding: A feature encoding, used to convert featuresets into feature vectors. May optionally implement a cost() method in order to assign different costs to different class predictions. :type stream: stream :param stream: The stream to which the megam input file should be written. :param bernoulli: If true, then use the 'bernoulli' format. I.e., all joint features have binary values, and are listed iff they are true. Otherwise, list feature values explicitly. If ``bernoulli=False``, then you must call ``megam`` with the ``-fvals`` option. :param explicit: If true, then use the 'explicit' format. I.e., list the features that would fire for any of the possible labels, for each token. If ``explicit=True``, then you must call ``megam`` with the ``-explicit`` option. """ # Look up the set of labels. labels = encoding.labels() labelnum = dict([(label, i) for (i, label) in enumerate(labels)]) # Write the file, which contains one line per instance. for featureset, label in train_toks: # First, the instance number (or, in the weighted multiclass case, the cost of each label). if hasattr(encoding,'cost'): stream.write(':'.join(str(encoding.cost(featureset, label, l)) for l in labels)) else: stream.write('%d' % labelnum[label]) # For implicit file formats, just list the features that fire # for this instance's actual label. if not explicit: _write_megam_features(encoding.encode(featureset, label), stream, bernoulli) # For explicit formats, list the features that would fire for # any of the possible labels. else: for l in labels: stream.write(' #') _write_megam_features(encoding.encode(featureset, l), stream, bernoulli) # End of the instance. stream.write('\n') def parse_megam_weights(s, features_count, explicit=True): """ Given the stdout output generated by ``megam`` when training a model, return a ``numpy`` array containing the corresponding weight vector. This function does not currently handle bias features. """ if numpy is None: raise ValueError('This function requires that numpy be installed') assert explicit, 'non-explicit not supported yet' lines = s.strip().split('\n') weights = numpy.zeros(features_count, 'd') for line in lines: if line.strip(): fid, weight = line.split() weights[int(fid)] = float(weight) return weights def _write_megam_features(vector, stream, bernoulli): if not vector: raise ValueError('MEGAM classifier requires the use of an ' 'always-on feature.') for (fid, fval) in vector: if bernoulli: if fval == 1: stream.write(' %s' % fid) elif fval != 0: raise ValueError('If bernoulli=True, then all' 'features must be binary.') else: stream.write(' %s %s' % (fid, fval)) def call_megam(args): """ Call the ``megam`` binary with the given arguments. """ if isinstance(args, basestring): raise TypeError('args should be a list of strings') if _megam_bin is None: config_megam() # Call megam via a subprocess cmd = [_megam_bin] + args p = subprocess.Popen(cmd, stdout=subprocess.PIPE) (stdout, stderr) = p.communicate() # Check the return code. if p.returncode != 0: print() print(stderr) raise OSError('megam command failed!') return stdout
apache-2.0
[ 3, 653, 292, 4889, 8466, 15650, 6065, 26, 14816, 370, 3194, 17740, 8465, 5541, 199, 3, 199, 3, 1898, 334, 35, 9, 12521, 13, 7409, 24719, 15263, 7290, 199, 3, 6529, 26, 17379, 3079, 491, 2262, 665, 379, 320, 529, 32, 7490, 14, 67, 374, 14, 384, 287, 78, 14, 8654, 30, 199, 3, 2851, 26, 665, 1014, 921, 1544, 14, 7530, 2663, 14, 1308, 3133, 199, 3, 2104, 4190, 2556, 12, 1937, 5113, 14, 17715, 199, 199, 624, 199, 33, 663, 402, 3423, 1202, 370, 3217, 543, 314, 5957, 562, 17740, 63, 1390, 484, 199, 31405, 2559, 14, 21467, 562, 17740, 883, 506, 1202, 12, 1265, 1077, 11480, 24719, 15263, 2382, 652, 199, 2425, 2342, 314, 562, 17740, 3366, 12, 1808, 314, 1124, 888, 63, 278, 17740, 8497, 805, 14, 29267, 199, 3807, 26, 199, 199, 703, 8868, 447, 272, 520, 1419, 26, 435, 13525, 339, 1306, 687, 24706, 14, 12334, 1399, 492, 562, 17740, 272, 1306, 562, 17740, 14, 888, 63, 278, 17740, 342, 327, 986, 931, 370, 562, 17740, 340, 440, 1911, 315, 15097, 272, 359, 3601, 562, 17740, 26, 21214, 199, 199, 6119, 543, 8228, 484, 8508, 14, 5679, 5084, 12, 1937, 8228, 484, 8508, 3794, 199, 509, 2436, 14, 339, 24706, 14, 12334, 1399, 14, 4261, 484, 8508, 14, 2834, 8, 16780, 12, 283, 278, 17740, 358, 199, 199, 703, 485, 278, 17740, 26, 1455, 921, 1544, 14, 1259, 14, 337, 11326, 14, 8654, 22500, 19785, 15, 278, 17740, 15, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 646, 747, 199, 646, 747, 14, 515, 199, 646, 3873, 199, 199, 504, 24706, 14, 4404, 2551, 492, 2342, 63, 3008, 199, 893, 26, 272, 492, 2680, 199, 2590, 3545, 26, 272, 2680, 275, 488, 199, 199, 18022, 199, 3, 91, 11595, 199, 18022, 199, 199, 63, 278, 17740, 63, 1393, 275, 488, 199, 318, 1101, 63, 278, 17740, 8, 1393, 29, 403, 304, 272, 408, 272, 15453, 24719, 15263, 1159, 3217, 370, 314, 1124, 278, 17740, 1040, 1390, 484, 13712, 272, 2559, 14, 339, 520, 635, 2517, 26, 710, 2615, 931, 370, 314, 1124, 278, 17740, 1040, 3366, 14, 221, 982, 440, 2013, 12, 267, 2066, 24706, 911, 2754, 314, 2656, 367, 282, 1124, 278, 17740, 1040, 3366, 27, 436, 340, 267, 1373, 365, 440, 1911, 12, 652, 911, 746, 282, 1124, 32060, 1040, 1919, 14, 272, 520, 466, 2517, 26, 620, 272, 408, 272, 2288, 485, 278, 17740, 63, 1393, 272, 485, 278, 17740, 63, 1393, 275, 2342, 63, 3008, 8, 267, 283, 278, 17740, 297, 2517, 12, 267, 2589, 63, 2936, 2968, 3635, 39, 1156, 297, 221, 283, 3635, 39, 1156, 9524, 995, 267, 3366, 63, 1247, 2968, 278, 17740, 14, 2992, 297, 283, 278, 17740, 297, 283, 278, 17740, 63, 10253, 297, 283, 278, 17740, 63, 73, 10253, 14, 2992, 995, 267, 1166, 534, 1014, 921, 1544, 14, 1259, 14, 337, 11326, 14, 8654, 22500, 19785, 15, 278, 17740, 6217, 199, 199, 18022, 199, 3, 91, 3194, 17740, 14816, 17471, 199, 18022, 199, 199, 318, 2218, 63, 278, 17740, 63, 493, 8, 2834, 63, 29328, 12, 2644, 12, 2547, 12, 2151, 330, 281, 24992, 29, 549, 12, 5027, 29, 549, 304, 272, 408, 272, 7958, 376, 1324, 570, 367, 1124, 278, 17740, 1040, 4079, 641, 314, 1627, 16831, 402, 272, 11534, 1290, 4645, 14, 339, 520, 466, 3560, 63, 29328, 26, 769, 8, 2960, 8, 807, 12, 620, 430, 272, 520, 635, 3560, 63, 29328, 26, 22859, 666, 12, 11159, 465, 282, 769, 402, 267, 6342, 12, 314, 1642, 3653, 402, 1314, 365, 282, 3878, 2600, 12, 267, 436, 314, 3499, 402, 1314, 365, 282, 12505, 1768, 14, 339, 520, 466, 2644, 26, 8228, 484, 5968, 7630, 41, 272, 520, 635, 2644, 26, 437, 3878, 2644, 12, 1202, 370, 3957, 3878, 2193, 267, 1901, 3878, 11102, 14, 10162, 14190, 5669, 282, 7918, 342, 1083, 267, 315, 1865, 370, 5090, 3365, 26819, 370, 3365, 1021, 7914, 14, 339, 520, 466, 2547, 26, 2547, 272, 520, 635, 2547, 26, 710, 2547, 370, 1314, 314, 562, 17740, 1324, 570, 1077, 506, 267, 5313, 14, 339, 520, 635, 330, 281, 24992, 26, 982, 2549, 12, 2066, 675, 314, 283, 605, 24992, 7, 1475, 14, 221, 473, 14, 69, 2020, 267, 1006, 22211, 4534, 1172, 3366, 1338, 12, 436, 787, 10532, 17963, 2985, 267, 787, 2549, 14, 221, 6630, 12, 769, 3878, 1338, 7662, 14, 221, 982, 267, 1124, 605, 24992, 29, 797, 4542, 2066, 1265, 1471, 1240, 1124, 278, 17740, 1040, 543, 314, 267, 27810, 70, 3643, 1040, 945, 14, 339, 520, 635, 5027, 26, 982, 2549, 12, 2066, 675, 314, 283, 10306, 7, 1475, 14, 221, 473, 14, 69, 2020, 267, 769, 314, 4534, 626, 3955, 8344, 367, 1263, 402, 314, 3962, 267, 3628, 12, 367, 1924, 1526, 14, 221, 982, 1124, 10306, 29, 549, 4542, 2066, 1265, 1471, 267, 1240, 1124, 278, 17740, 1040, 543, 314, 27810, 10306, 1040, 945, 14, 272, 408, 272, 327, 12077, 1536, 314, 663, 402, 3628, 14, 272, 3628, 275, 2644, 14, 3512, 342, 272, 1768, 1507, 275, 1211, 7694, 1302, 12, 284, 9, 367, 334, 73, 12, 1768, 9, 315, 3874, 8, 3512, 3948, 339, 327, 6990, 314, 570, 12, 1314, 3509, 1373, 1004, 1126, 1256, 14, 272, 367, 3878, 409, 12, 1768, 315, 3560, 63, 29328, 26, 267, 327, 7758, 12, 314, 1256, 1329, 334, 269, 12, 315, 314, 14609, 3510, 533, 1930, 12, 314, 7918, 402, 1924, 1768, 680, 267, 340, 2688, 8, 2991, 2584, 6336, 735, 288, 2547, 14, 952, 6176, 1370, 904, 8, 495, 8, 2991, 14, 6336, 8, 4445, 409, 12, 1768, 12, 634, 430, 367, 634, 315, 3628, 430, 267, 587, 26, 288, 2547, 14, 952, 3508, 68, 7, 450, 1768, 1507, 59, 1302, 566, 398, 327, 2104, 9227, 570, 6752, 12, 2951, 769, 314, 4534, 626, 8344, 267, 327, 367, 642, 1256, 1159, 3503, 1768, 14, 267, 340, 440, 5027, 26, 288, 485, 952, 63, 278, 17740, 63, 3179, 8, 2991, 14, 2143, 8, 4445, 409, 12, 1768, 395, 3303, 2547, 12, 330, 281, 24992, 9, 398, 327, 2104, 5027, 6752, 12, 769, 314, 4534, 626, 3955, 8344, 367, 267, 327 ]
[ 653, 292, 4889, 8466, 15650, 6065, 26, 14816, 370, 3194, 17740, 8465, 5541, 199, 3, 199, 3, 1898, 334, 35, 9, 12521, 13, 7409, 24719, 15263, 7290, 199, 3, 6529, 26, 17379, 3079, 491, 2262, 665, 379, 320, 529, 32, 7490, 14, 67, 374, 14, 384, 287, 78, 14, 8654, 30, 199, 3, 2851, 26, 665, 1014, 921, 1544, 14, 7530, 2663, 14, 1308, 3133, 199, 3, 2104, 4190, 2556, 12, 1937, 5113, 14, 17715, 199, 199, 624, 199, 33, 663, 402, 3423, 1202, 370, 3217, 543, 314, 5957, 562, 17740, 63, 1390, 484, 199, 31405, 2559, 14, 21467, 562, 17740, 883, 506, 1202, 12, 1265, 1077, 11480, 24719, 15263, 2382, 652, 199, 2425, 2342, 314, 562, 17740, 3366, 12, 1808, 314, 1124, 888, 63, 278, 17740, 8497, 805, 14, 29267, 199, 3807, 26, 199, 199, 703, 8868, 447, 272, 520, 1419, 26, 435, 13525, 339, 1306, 687, 24706, 14, 12334, 1399, 492, 562, 17740, 272, 1306, 562, 17740, 14, 888, 63, 278, 17740, 342, 327, 986, 931, 370, 562, 17740, 340, 440, 1911, 315, 15097, 272, 359, 3601, 562, 17740, 26, 21214, 199, 199, 6119, 543, 8228, 484, 8508, 14, 5679, 5084, 12, 1937, 8228, 484, 8508, 3794, 199, 509, 2436, 14, 339, 24706, 14, 12334, 1399, 14, 4261, 484, 8508, 14, 2834, 8, 16780, 12, 283, 278, 17740, 358, 199, 199, 703, 485, 278, 17740, 26, 1455, 921, 1544, 14, 1259, 14, 337, 11326, 14, 8654, 22500, 19785, 15, 278, 17740, 15, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 646, 747, 199, 646, 747, 14, 515, 199, 646, 3873, 199, 199, 504, 24706, 14, 4404, 2551, 492, 2342, 63, 3008, 199, 893, 26, 272, 492, 2680, 199, 2590, 3545, 26, 272, 2680, 275, 488, 199, 199, 18022, 199, 3, 91, 11595, 199, 18022, 199, 199, 63, 278, 17740, 63, 1393, 275, 488, 199, 318, 1101, 63, 278, 17740, 8, 1393, 29, 403, 304, 272, 408, 272, 15453, 24719, 15263, 1159, 3217, 370, 314, 1124, 278, 17740, 1040, 1390, 484, 13712, 272, 2559, 14, 339, 520, 635, 2517, 26, 710, 2615, 931, 370, 314, 1124, 278, 17740, 1040, 3366, 14, 221, 982, 440, 2013, 12, 267, 2066, 24706, 911, 2754, 314, 2656, 367, 282, 1124, 278, 17740, 1040, 3366, 27, 436, 340, 267, 1373, 365, 440, 1911, 12, 652, 911, 746, 282, 1124, 32060, 1040, 1919, 14, 272, 520, 466, 2517, 26, 620, 272, 408, 272, 2288, 485, 278, 17740, 63, 1393, 272, 485, 278, 17740, 63, 1393, 275, 2342, 63, 3008, 8, 267, 283, 278, 17740, 297, 2517, 12, 267, 2589, 63, 2936, 2968, 3635, 39, 1156, 297, 221, 283, 3635, 39, 1156, 9524, 995, 267, 3366, 63, 1247, 2968, 278, 17740, 14, 2992, 297, 283, 278, 17740, 297, 283, 278, 17740, 63, 10253, 297, 283, 278, 17740, 63, 73, 10253, 14, 2992, 995, 267, 1166, 534, 1014, 921, 1544, 14, 1259, 14, 337, 11326, 14, 8654, 22500, 19785, 15, 278, 17740, 6217, 199, 199, 18022, 199, 3, 91, 3194, 17740, 14816, 17471, 199, 18022, 199, 199, 318, 2218, 63, 278, 17740, 63, 493, 8, 2834, 63, 29328, 12, 2644, 12, 2547, 12, 2151, 330, 281, 24992, 29, 549, 12, 5027, 29, 549, 304, 272, 408, 272, 7958, 376, 1324, 570, 367, 1124, 278, 17740, 1040, 4079, 641, 314, 1627, 16831, 402, 272, 11534, 1290, 4645, 14, 339, 520, 466, 3560, 63, 29328, 26, 769, 8, 2960, 8, 807, 12, 620, 430, 272, 520, 635, 3560, 63, 29328, 26, 22859, 666, 12, 11159, 465, 282, 769, 402, 267, 6342, 12, 314, 1642, 3653, 402, 1314, 365, 282, 3878, 2600, 12, 267, 436, 314, 3499, 402, 1314, 365, 282, 12505, 1768, 14, 339, 520, 466, 2644, 26, 8228, 484, 5968, 7630, 41, 272, 520, 635, 2644, 26, 437, 3878, 2644, 12, 1202, 370, 3957, 3878, 2193, 267, 1901, 3878, 11102, 14, 10162, 14190, 5669, 282, 7918, 342, 1083, 267, 315, 1865, 370, 5090, 3365, 26819, 370, 3365, 1021, 7914, 14, 339, 520, 466, 2547, 26, 2547, 272, 520, 635, 2547, 26, 710, 2547, 370, 1314, 314, 562, 17740, 1324, 570, 1077, 506, 267, 5313, 14, 339, 520, 635, 330, 281, 24992, 26, 982, 2549, 12, 2066, 675, 314, 283, 605, 24992, 7, 1475, 14, 221, 473, 14, 69, 2020, 267, 1006, 22211, 4534, 1172, 3366, 1338, 12, 436, 787, 10532, 17963, 2985, 267, 787, 2549, 14, 221, 6630, 12, 769, 3878, 1338, 7662, 14, 221, 982, 267, 1124, 605, 24992, 29, 797, 4542, 2066, 1265, 1471, 1240, 1124, 278, 17740, 1040, 543, 314, 267, 27810, 70, 3643, 1040, 945, 14, 339, 520, 635, 5027, 26, 982, 2549, 12, 2066, 675, 314, 283, 10306, 7, 1475, 14, 221, 473, 14, 69, 2020, 267, 769, 314, 4534, 626, 3955, 8344, 367, 1263, 402, 314, 3962, 267, 3628, 12, 367, 1924, 1526, 14, 221, 982, 1124, 10306, 29, 549, 4542, 2066, 1265, 1471, 267, 1240, 1124, 278, 17740, 1040, 543, 314, 27810, 10306, 1040, 945, 14, 272, 408, 272, 327, 12077, 1536, 314, 663, 402, 3628, 14, 272, 3628, 275, 2644, 14, 3512, 342, 272, 1768, 1507, 275, 1211, 7694, 1302, 12, 284, 9, 367, 334, 73, 12, 1768, 9, 315, 3874, 8, 3512, 3948, 339, 327, 6990, 314, 570, 12, 1314, 3509, 1373, 1004, 1126, 1256, 14, 272, 367, 3878, 409, 12, 1768, 315, 3560, 63, 29328, 26, 267, 327, 7758, 12, 314, 1256, 1329, 334, 269, 12, 315, 314, 14609, 3510, 533, 1930, 12, 314, 7918, 402, 1924, 1768, 680, 267, 340, 2688, 8, 2991, 2584, 6336, 735, 288, 2547, 14, 952, 6176, 1370, 904, 8, 495, 8, 2991, 14, 6336, 8, 4445, 409, 12, 1768, 12, 634, 430, 367, 634, 315, 3628, 430, 267, 587, 26, 288, 2547, 14, 952, 3508, 68, 7, 450, 1768, 1507, 59, 1302, 566, 398, 327, 2104, 9227, 570, 6752, 12, 2951, 769, 314, 4534, 626, 8344, 267, 327, 367, 642, 1256, 1159, 3503, 1768, 14, 267, 340, 440, 5027, 26, 288, 485, 952, 63, 278, 17740, 63, 3179, 8, 2991, 14, 2143, 8, 4445, 409, 12, 1768, 395, 3303, 2547, 12, 330, 281, 24992, 9, 398, 327, 2104, 5027, 6752, 12, 769, 314, 4534, 626, 3955, 8344, 367, 267, 327, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
proekt-po-python/Snooker-master-proekt-po-python
settings.py
1
1813
"""Настройки на топките""" WHITE = (255, 255, 255) RED = (255, 0, 0) YELLOW = (255, 255, 0) GREEN = (0, 128, 0) BROWN = (139, 69, 19) BLUE = (0, 0, 250) PINK = (250, 20, 147) BLACK = (0, 0, 0) POS_RED1 = (320, 287) POS_RED2 = (306, 279) POS_RED3 = (306, 296) POS_RED4 = (292, 271) POS_RED5 = (292, 288) POS_RED6 = (292, 305) POS_RED7 = (278, 263) POS_RED8 = (278, 280) POS_RED9 = (278, 297) POS_RED10 = (278, 314) POS_RED11 = (264, 255) POS_RED12 = (264, 272) POS_RED13 = (264, 289) POS_RED14 = (264, 306) POS_RED15 = (264, 323) POS_YELLOW = (799, 216) POS_GREEN = (799, 358) POS_BROWN = (799, 287) POS_BLUE = (550, 287) POS_PINK = (337, 287) POS_BLACK = (202, 287) POS_WHITE = (820, 260) """Настройки на масата""" TABLE_POS = (100, 50) UR_POCKET = (120, 70) UL_POCKET = (120, 502) MR_POCKET = (550, 64) ML_POCKET = (550, 508) DR_POCKET = (980, 70) DL_POCKET = (980, 502) UP_BORDER = 83 DOWN_BORDER = 490 LEFT_BORDER = 133 RIGHT_BORDER = 966 POCKET_R = 9 """Настройки на играта""" BACKGROUND_COLOR = (200, 200, 200) SCREEN_SIZE = (1200, 600) FRICTION = 30 TIMER = 0.01 CUE_WIDTH = 3 CUE_DEFAULT_R = 180 MIN_HITTING_FORCE = 20 RED_TARGET = 0 COLOR_TARGET = 1 STATICK = True NON_STATICK = False FOUL_POINTS = 4 STILL_RED = 'still red' RED_FREE = 'red free' """Настройки на таблото""" LEN_X = 900 LEN_Y = 50 SCORE_BORD_POS_X = 550 - LEN_X / 2 SCORE = (SCORE_BORD_POS_X, 530) POS_Y = LEN_Y / 2 CHARACTER_SIZE = 12 INDICATOR_SIZE = CHARACTER_SIZE * 3 POINTS_POS_ONE = (LEN_X - CHARACTER_SIZE - INDICATOR_SIZE) / 2 POINTS_POS_TWO = (LEN_X + CHARACTER_SIZE + INDICATOR_SIZE) / 2 FIRST_POS = INDICATOR_SIZE + 5 SECOND_POS = LEN_X - INDICATOR_SIZE - 5 IND_POS_ONE = 0 IND_POS_TWO = LEN_X - INDICATOR_SIZE SEPARETOR_POS_X = (LEN_X - CHARACTER_SIZE) / 2
gpl-3.0
[ 624, 141, 252, 5657, 18261, 7753, 8381, 118, 11487, 6500, 24917, 5657, 221, 7413, 8381, 124, 11487, 30019, 6286, 624, 199, 18817, 275, 334, 2299, 12, 5450, 12, 5450, 9, 199, 7387, 275, 334, 2299, 12, 378, 12, 378, 9, 199, 57, 23575, 275, 334, 2299, 12, 5450, 12, 378, 9, 199, 22501, 275, 334, 16, 12, 7960, 12, 378, 9, 199, 21111, 3705, 275, 334, 7491, 12, 14610, 12, 5851, 9, 199, 23536, 275, 334, 16, 12, 378, 12, 16074, 9, 199, 48, 12394, 275, 334, 7991, 12, 3388, 12, 28513, 9, 199, 23113, 275, 334, 16, 12, 378, 12, 378, 9, 199, 9263, 63, 7387, 17, 275, 334, 12122, 12, 499, 1555, 9, 199, 9263, 63, 7387, 18, 275, 334, 11363, 12, 499, 1965, 9, 199, 9263, 63, 7387, 19, 275, 334, 11363, 12, 499, 2534, 9, 199, 9263, 63, 7387, 20, 275, 334, 17027, 12, 499, 3172, 9, 199, 9263, 63, 7387, 21, 275, 334, 17027, 12, 32558, 9, 199, 9263, 63, 7387, 22, 275, 334, 17027, 12, 650, 1717, 9, 199, 9263, 63, 7387, 23, 275, 334, 13909, 12, 499, 2766, 9, 199, 9263, 63, 7387, 24, 275, 334, 13909, 12, 499, 1257, 9, 199, 9263, 63, 7387, 25, 275, 334, 13909, 12, 499, 2576, 9, 199, 9263, 63, 7387, 709, 275, 334, 13909, 12, 29182, 9, 199, 9263, 63, 7387, 845, 275, 334, 9408, 12, 5450, 9, 199, 9263, 63, 7387, 713, 275, 334, 9408, 12, 499, 2819, 9, 199, 9263, 63, 7387, 969, 275, 334, 9408, 12, 499, 1407, 9, 199, 9263, 63, 7387, 1079, 275, 334, 9408, 12, 650, 1690, 9, 199, 9263, 63, 7387, 1046, 275, 334, 9408, 12, 650, 1789, 9, 199, 9263, 63, 57, 23575, 275, 334, 31486, 12, 30630, 9, 199, 9263, 63, 22501, 275, 334, 31486, 12, 650, 2010, 9, 199, 9263, 63, 21111, 3705, 275, 334, 31486, 12, 499, 1555, 9, 199, 9263, 63, 23536, 275, 334, 16859, 12, 499, 1555, 9, 199, 9263, 63, 48, 12394, 275, 334, 11062, 12, 499, 1555, 9, 199, 9263, 63, 23113, 275, 334, 4999, 12, 499, 1555, 9, 199, 9263, 63, 18817, 275, 334, 24, 1165, 12, 499, 2259, 9, 199, 624, 141, 252, 5657, 18261, 7753, 8381, 118, 11487, 6500, 24917, 5657, 7038, 121, 5657, 8474, 24219, 5657, 624, 199, 8723, 63, 9263, 275, 334, 1960, 12, 5238, 9, 199, 1230, 63, 1512, 15244, 275, 334, 6708, 12, 10045, 9, 199, 1293, 63, 1512, 15244, 275, 334, 6708, 12, 959, 996, 9, 199, 22153, 63, 1512, 15244, 275, 334, 16859, 12, 5049, 9, 199, 1698, 63, 1512, 15244, 275, 334, 16859, 12, 959, 2036, 9, 199, 4564, 63, 1512, 15244, 275, 334, 29400, 12, 10045, 9, 199, 8045, 63, 1512, 15244, 275, 334, 29400, 12, 959, 996, 9, 199, 2160, 63, 30083, 275, 20582, 199, 8819, 63, 30083, 275, 841, 2710, 199, 9894, 63, 30083, 275, 28416, 199, 12811, 63, 30083, 275, 1749, 1272, 199, 1512, 15244, 63, 50, 275, 1749, 199, 624, 141, 252, 5657, 18261, 7753, 8381, 118, 11487, 6500, 24917, 5657, 221, 16863, 112, 7753, 24219, 5657, 624, 199, 7111, 29497, 63, 7134, 275, 334, 1840, 12, 1926, 12, 1926, 9, 199, 25070, 63, 4305, 275, 334, 23781, 12, 11624, 9, 199, 5372, 6196, 1075, 275, 4233, 199, 29108, 275, 378, 14, 614, 199, 35, 4187, 63, 11139, 275, 650, 199, 35, 4187, 63, 3472, 63, 50, 275, 13576, 199, 4896, 63, 40, 20779, 1206, 63, 27240, 275, 3388, 199, 7387, 63, 9268, 275, 378, 199, 7134, 63, 9268, 275, 413, 199, 10449, 43, 275, 715, 199, 13887, 63, 10449, 43, 275, 756, 199, 3230, 1293, 63, 7217, 51, 275, 841, 199, 840, 14961, 63, 7387, 275, 283, 32310, 8992, 7, 199, 7387, 63, 28170, 275, 283, 581, 2867, 7, 199, 624, 141, 252, 5657, 18261, 7753, 8381, 118, 11487, 6500, 24917, 5657, 221, 7413, 13111, 110, 10356, 5806, 7413, 5806, 624, 199, 5304, 63, 56, 275, 27151, 199, 5304, 63, 57, 275, 5238, 199, 5153, 5788, 63, 34, 3731, 63, 9263, 63, 56, 275, 959, 1400, 446, 491, 742, 63, 56, 1182, 499, 199, 5153, 5788, 275, 334, 5153, 5788, 63, 34, 3731, 63, 9263, 63, 56, 12, 959, 1216, 9, 199, 9263, 63, 57, 275, 491, 742, 63, 57, 1182, 499, 199, 29007, 63, 4305, 275, 3144, 199, 23723, 6467, 63, 4305, 275, 9502, 63, 4305, 627, 650, 199, 7217, 51, 63, 9263, 63, 4817, 275, 334, 5304, 63, 56, 446, 9502, 63, 4305, 446, 32361, 63, 4305, 9, 1182, 499, 199, 7217, 51, 63, 9263, 63, 52, 11325, 275, 334, 5304, 63, 56, 435, 9502, 63, 4305, 435, 32361, 63, 4305, 9, 1182, 499, 199, 12903, 63, 9263, 275, 32361, 63, 4305, 435, 959, 199, 24236, 63, 9263, 275, 491, 742, 63, 56, 446, 32361, 63, 4305, 446, 959, 199, 3192, 63, 9263, 63, 4817, 275, 378, 199, 3192, 63, 9263, 63, 52, 11325, 275, 491, 742, 63, 56, 446, 32361, 63, 4305, 199, 899, 4014, 775, 726, 63, 9263, 63, 56, 275, 334, 5304, 63, 56, 446, 9502, 63, 4305, 9, 1182, 499, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 141, 252, 5657, 18261, 7753, 8381, 118, 11487, 6500, 24917, 5657, 221, 7413, 8381, 124, 11487, 30019, 6286, 624, 199, 18817, 275, 334, 2299, 12, 5450, 12, 5450, 9, 199, 7387, 275, 334, 2299, 12, 378, 12, 378, 9, 199, 57, 23575, 275, 334, 2299, 12, 5450, 12, 378, 9, 199, 22501, 275, 334, 16, 12, 7960, 12, 378, 9, 199, 21111, 3705, 275, 334, 7491, 12, 14610, 12, 5851, 9, 199, 23536, 275, 334, 16, 12, 378, 12, 16074, 9, 199, 48, 12394, 275, 334, 7991, 12, 3388, 12, 28513, 9, 199, 23113, 275, 334, 16, 12, 378, 12, 378, 9, 199, 9263, 63, 7387, 17, 275, 334, 12122, 12, 499, 1555, 9, 199, 9263, 63, 7387, 18, 275, 334, 11363, 12, 499, 1965, 9, 199, 9263, 63, 7387, 19, 275, 334, 11363, 12, 499, 2534, 9, 199, 9263, 63, 7387, 20, 275, 334, 17027, 12, 499, 3172, 9, 199, 9263, 63, 7387, 21, 275, 334, 17027, 12, 32558, 9, 199, 9263, 63, 7387, 22, 275, 334, 17027, 12, 650, 1717, 9, 199, 9263, 63, 7387, 23, 275, 334, 13909, 12, 499, 2766, 9, 199, 9263, 63, 7387, 24, 275, 334, 13909, 12, 499, 1257, 9, 199, 9263, 63, 7387, 25, 275, 334, 13909, 12, 499, 2576, 9, 199, 9263, 63, 7387, 709, 275, 334, 13909, 12, 29182, 9, 199, 9263, 63, 7387, 845, 275, 334, 9408, 12, 5450, 9, 199, 9263, 63, 7387, 713, 275, 334, 9408, 12, 499, 2819, 9, 199, 9263, 63, 7387, 969, 275, 334, 9408, 12, 499, 1407, 9, 199, 9263, 63, 7387, 1079, 275, 334, 9408, 12, 650, 1690, 9, 199, 9263, 63, 7387, 1046, 275, 334, 9408, 12, 650, 1789, 9, 199, 9263, 63, 57, 23575, 275, 334, 31486, 12, 30630, 9, 199, 9263, 63, 22501, 275, 334, 31486, 12, 650, 2010, 9, 199, 9263, 63, 21111, 3705, 275, 334, 31486, 12, 499, 1555, 9, 199, 9263, 63, 23536, 275, 334, 16859, 12, 499, 1555, 9, 199, 9263, 63, 48, 12394, 275, 334, 11062, 12, 499, 1555, 9, 199, 9263, 63, 23113, 275, 334, 4999, 12, 499, 1555, 9, 199, 9263, 63, 18817, 275, 334, 24, 1165, 12, 499, 2259, 9, 199, 624, 141, 252, 5657, 18261, 7753, 8381, 118, 11487, 6500, 24917, 5657, 7038, 121, 5657, 8474, 24219, 5657, 624, 199, 8723, 63, 9263, 275, 334, 1960, 12, 5238, 9, 199, 1230, 63, 1512, 15244, 275, 334, 6708, 12, 10045, 9, 199, 1293, 63, 1512, 15244, 275, 334, 6708, 12, 959, 996, 9, 199, 22153, 63, 1512, 15244, 275, 334, 16859, 12, 5049, 9, 199, 1698, 63, 1512, 15244, 275, 334, 16859, 12, 959, 2036, 9, 199, 4564, 63, 1512, 15244, 275, 334, 29400, 12, 10045, 9, 199, 8045, 63, 1512, 15244, 275, 334, 29400, 12, 959, 996, 9, 199, 2160, 63, 30083, 275, 20582, 199, 8819, 63, 30083, 275, 841, 2710, 199, 9894, 63, 30083, 275, 28416, 199, 12811, 63, 30083, 275, 1749, 1272, 199, 1512, 15244, 63, 50, 275, 1749, 199, 624, 141, 252, 5657, 18261, 7753, 8381, 118, 11487, 6500, 24917, 5657, 221, 16863, 112, 7753, 24219, 5657, 624, 199, 7111, 29497, 63, 7134, 275, 334, 1840, 12, 1926, 12, 1926, 9, 199, 25070, 63, 4305, 275, 334, 23781, 12, 11624, 9, 199, 5372, 6196, 1075, 275, 4233, 199, 29108, 275, 378, 14, 614, 199, 35, 4187, 63, 11139, 275, 650, 199, 35, 4187, 63, 3472, 63, 50, 275, 13576, 199, 4896, 63, 40, 20779, 1206, 63, 27240, 275, 3388, 199, 7387, 63, 9268, 275, 378, 199, 7134, 63, 9268, 275, 413, 199, 10449, 43, 275, 715, 199, 13887, 63, 10449, 43, 275, 756, 199, 3230, 1293, 63, 7217, 51, 275, 841, 199, 840, 14961, 63, 7387, 275, 283, 32310, 8992, 7, 199, 7387, 63, 28170, 275, 283, 581, 2867, 7, 199, 624, 141, 252, 5657, 18261, 7753, 8381, 118, 11487, 6500, 24917, 5657, 221, 7413, 13111, 110, 10356, 5806, 7413, 5806, 624, 199, 5304, 63, 56, 275, 27151, 199, 5304, 63, 57, 275, 5238, 199, 5153, 5788, 63, 34, 3731, 63, 9263, 63, 56, 275, 959, 1400, 446, 491, 742, 63, 56, 1182, 499, 199, 5153, 5788, 275, 334, 5153, 5788, 63, 34, 3731, 63, 9263, 63, 56, 12, 959, 1216, 9, 199, 9263, 63, 57, 275, 491, 742, 63, 57, 1182, 499, 199, 29007, 63, 4305, 275, 3144, 199, 23723, 6467, 63, 4305, 275, 9502, 63, 4305, 627, 650, 199, 7217, 51, 63, 9263, 63, 4817, 275, 334, 5304, 63, 56, 446, 9502, 63, 4305, 446, 32361, 63, 4305, 9, 1182, 499, 199, 7217, 51, 63, 9263, 63, 52, 11325, 275, 334, 5304, 63, 56, 435, 9502, 63, 4305, 435, 32361, 63, 4305, 9, 1182, 499, 199, 12903, 63, 9263, 275, 32361, 63, 4305, 435, 959, 199, 24236, 63, 9263, 275, 491, 742, 63, 56, 446, 32361, 63, 4305, 446, 959, 199, 3192, 63, 9263, 63, 4817, 275, 378, 199, 3192, 63, 9263, 63, 52, 11325, 275, 491, 742, 63, 56, 446, 32361, 63, 4305, 199, 899, 4014, 775, 726, 63, 9263, 63, 56, 275, 334, 5304, 63, 56, 446, 9502, 63, 4305, 9, 1182, 499, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
kakkojc/DIE
DIE/Lib/IDAConnector.py
9
7909
import sark import idc import idaapi import idautils import re from sark.debug import Registers ################################################################ # # IDA Connector is a utility the wraps around IDA SDK. # It publishes convenience functions used to query and edit data # from IDA. # ################################################################ #TODO: 1. Gather all main IDA interaction functions to this file #TODO: 2. Create an abstract base class for the required functions, this might enable quick portability to other platforms. def get_function_name(ea): """ Get the real function name """ # Try to demangle function_name = idc.Demangle(idc.GetFunctionName(ea), idc.GetLongPrm(idc.INF_SHORT_DN)) if function_name: function_name = function_name.split("(")[0] # Function name is not mangled if not function_name: function_name = idc.GetFunctionName(ea) if not function_name: function_name = idc.Name(ea) # If we still have no function name, make one up. Format is - 'UNKN_FNC_4120000' if not function_name: function_name = "UNKN_FNC_%s" % hex(ea) return function_name def get_function_start_address(ea): """ Get function start address @param ea: ea from within the function boundaries. @return: The function start ea. If function start was not found return current ea. """ try: if ea is None: return None start_adrs = idc.GetFunctionAttr(ea, idc.FUNCATTR_START) if start_adrs != idc.BADADDR: return start_adrs return ea except Exception as ex: raise RuntimeError("Count not locate start address for function %s: %s" % (hex(ea), ex)) def get_function_end_address(ea): """ Get function end address @param ea: function start_ea. @return: The function end ea. If no function end ea found returns None. """ try: if ea is None: return None func_attr_end = idc.GetFunctionAttr(ea, idc.FUNCATTR_END) if func_attr_end == idc.BADADDR: return None return idc.PrevHead(func_attr_end, ea) except Exception as ex: raise RuntimeError("Count not locate end address for function %s: %s" % (hex(ea), ex)) def get_functions(): """ Get all current functions @return: a tuple of (function_name, function_ea) """ return {get_function_name(func_ea): func_ea for func_ea in idautils.Functions()} def get_native_size(): """ Get the native OS size @return: 16, 32, 64 value indicating the native size or None if failed. """ try: inf = idaapi.get_inf_structure() if inf.is_32bit(): return 32 elif inf.is_64bit(): return 64 else: # Native size is neither 32 or 64 bit. assuming 16 bit. return 16 except Exception as ex: raise RuntimeError("Could not Could not retrieve native OS size: %s" %ex) def get_proc_type(): """ Get processor type @return: Returns the processor type or None on failure. """ try: inf = idaapi.get_inf_structure() return inf.procName() except Exception as ex: raise RuntimeError("Could not retrieve processor type: %s" %ex) def is_call(ea): """ Check if the current instruction a CALL instruction """ return sark.Line(ea).insn.is_call def is_ret(ea): """ Check if the current instruction a RET instruction """ return sark.Line(ea).insn.is_ret def get_cur_ea(): """ Return the current effective address """ return idc.GetRegValue(Registers().ip.name) def get_sp(): """ Get the current stack pointer address """ return idc.GetRegValue(Registers().sp.name) def get_adrs_mem(ea): """ Get the memory at address according to native size (16, 32 or 64 bit) """ # Verify EA if not idc.isEnabled(ea): return None nativeSize = get_native_size() if nativeSize is 16: return idc.DbgWord(ea) if nativeSize is 32: return idc.DbgDword(ea) if nativeSize is 64: return idc.DbgQword(ea) # Ask hex-rays how can this be done a bit more gracefully.. def regOffsetToName(offset): """ Get register name from an offset to ph.regnames """ native_size = get_native_size() reg_name = idaapi.get_reg_name(offset, native_size / 8) if not reg_name: raise ValueError("Failed to retrieve register name.") return reg_name def get_stack_element_size(): """ Get size of a stack element @return: size of a stack element (in bytes) """ return get_native_size()/8 def is_indirect(ea): """ Check if a call instruction is direct or indirect. @param ea: Effective address of the call instruction. @return: """ try: operand = sark.Line(ea).insn.operands[0] except IndexError: # If there is no operands, it cannot be indirect ;-) return False except sark.exceptions.SarkNoInstruction: # If there is no instruction, it surely isn't indirect ;) return False except Exception: return False # If the CALL instruction first operand is either of [Base + Index] or [Base + Index + Displacement] type. if operand.type.is_phrase or operand.type.is_displ: return True return False def is_ida_debugger_present(): """ Check if IDA debugger is loaded and can be used @return: True if IDA debugger has been set correctly, Otherwise returns Fals """ return idaapi.dbg_can_query() def is_import_or_lib_func(ea): """ Is ea part of an imported function or a known library? @param ea: any ea within the function scope @return: True if function is either imported or a known library function. """ return sark.Function(ea).flags & (idaapi.FUNC_LIB | idaapi.FUNC_THUNK) def add_call_xref(frm, to): """ Add XREF to a call function @param frm: EA of From address (The CALL instruction address) @param to: EA of To Address (The called funciton address) @return: True if XREF was added successfully, otherwise False """ return idc.AddCodeXref(frm, to, 0x31) def is_call_xref(frm, to): """ Check the existence of a call XREF in a CALL instruction. @param frm: EA of From address (The CALL instruction address) @param to: EA of To Address (The called funciton address) @return: True if call XREF exist, otherwise False """ for xref in sark.Line(frm).xrefs_from: if xref.to == to: return True return False def is_system_lib(ea): """ Returns true if a segment belongs to a system library, in which case we don't want to recursively hook calls. Covers Windows, Linux, Mac, Android, iOS @param ea: an effective address within a function """ name = idc.SegName(ea) if not name: return False # the below is for Windows kernel debugging if name == 'nt': return True sysfolders = [re.compile("\\\\windows\\\\", re.I), re.compile("\\\\Program Files ", re.I), re.compile("/usr/", re.I), \ re.compile("/system/", re.I), re.compile("/lib/", re.I)] m = idc.GetFirstModule() while m: path = idc.GetModuleName(m) if re.search(name, path): if any(regex.search(path) for regex in sysfolders): return True else: return False m = idc.GetNextModule(m) return False
mit
[ 646, 308, 1096, 202, 199, 646, 1305, 67, 202, 199, 646, 284, 983, 1246, 202, 199, 646, 284, 983, 1208, 202, 199, 646, 295, 202, 199, 504, 308, 1096, 14, 1757, 492, 5044, 14186, 2999, 199, 3060, 202, 199, 3, 202, 199, 3, 2870, 33, 13482, 2406, 365, 282, 11420, 314, 14018, 6818, 2870, 33, 15610, 14, 202, 199, 3, 2779, 2780, 397, 16777, 3423, 1202, 370, 1827, 436, 5283, 666, 202, 199, 3, 687, 2870, 33, 14, 202, 199, 3, 202, 199, 3060, 2999, 199, 3, 11768, 26, 413, 14, 19634, 1006, 2446, 2870, 33, 18752, 3423, 370, 642, 570, 202, 199, 3, 11768, 26, 499, 14, 2790, 376, 9006, 1300, 1021, 367, 314, 1415, 3423, 12, 642, 5594, 4756, 12530, 1844, 3616, 370, 1163, 10677, 14, 2999, 199, 318, 664, 63, 1593, 63, 354, 8, 4489, 304, 1039, 408, 1039, 2372, 314, 3363, 805, 536, 1039, 408, 1039, 327, 7649, 370, 28548, 4593, 1039, 805, 63, 354, 275, 1305, 67, 14, 872, 29602, 8, 344, 67, 14, 1002, 3481, 985, 8, 4489, 395, 1305, 67, 14, 1002, 9551, 48, 5682, 8, 344, 67, 14, 11384, 63, 13003, 63, 10872, 430, 4341, 340, 805, 63, 354, 26, 1675, 805, 63, 354, 275, 805, 63, 354, 14, 1294, 480, 480, 2788, 16, 61, 4341, 327, 6801, 536, 365, 440, 333, 22183, 1039, 340, 440, 805, 63, 354, 26, 1675, 805, 63, 354, 275, 1305, 67, 14, 1002, 3481, 985, 8, 4489, 9, 4341, 340, 440, 805, 63, 354, 26, 1675, 805, 63, 354, 275, 1305, 67, 14, 985, 8, 4489, 9, 4341, 327, 982, 781, 5139, 1172, 949, 805, 536, 12, 1852, 1373, 1536, 14, 9701, 365, 446, 283, 8019, 46, 63, 4963, 35, 63, 25746, 993, 7, 1039, 340, 440, 805, 63, 354, 26, 1675, 805, 63, 354, 275, 298, 8019, 46, 63, 4963, 35, 4970, 83, 2, 450, 6318, 8, 4489, 9, 4341, 372, 805, 63, 354, 2999, 199, 318, 664, 63, 1593, 63, 928, 63, 1562, 8, 4489, 304, 1128, 408, 1128, 2372, 805, 1343, 2287, 1128, 768, 635, 24867, 26, 24867, 687, 4453, 314, 805, 18135, 14, 1128, 768, 1107, 26, 710, 805, 1343, 24867, 14, 982, 805, 1343, 1990, 440, 1911, 372, 1453, 24867, 14, 1128, 408, 1128, 862, 26, 1039, 340, 24867, 365, 488, 26, 1675, 372, 488, 4341, 1343, 63, 350, 2393, 275, 1305, 67, 14, 1002, 3481, 7144, 8, 4489, 12, 1305, 67, 14, 19587, 5280, 63, 7363, 9, 1039, 340, 1343, 63, 350, 2393, 1137, 1305, 67, 14, 9439, 7803, 26, 1675, 372, 1343, 63, 350, 2393, 4341, 372, 24867, 2958, 871, 2186, 465, 444, 26, 1039, 746, 6064, 480, 2353, 440, 16592, 1343, 2287, 367, 805, 450, 83, 26, 450, 83, 2, 450, 334, 4097, 8, 4489, 395, 444, 430, 2999, 199, 318, 664, 63, 1593, 63, 500, 63, 1562, 8, 4489, 304, 1128, 408, 1128, 2372, 805, 1284, 2287, 1128, 768, 635, 24867, 26, 805, 1343, 63, 4489, 14, 1128, 768, 1107, 26, 710, 805, 1284, 24867, 14, 982, 949, 805, 1284, 24867, 1911, 2529, 488, 14, 1128, 408, 1128, 862, 26, 1039, 340, 24867, 365, 488, 26, 1675, 372, 488, 4341, 2562, 63, 962, 63, 500, 275, 1305, 67, 14, 1002, 3481, 7144, 8, 4489, 12, 1305, 67, 14, 19587, 5280, 63, 3902, 9, 1039, 340, 2562, 63, 962, 63, 500, 508, 1305, 67, 14, 9439, 7803, 26, 1675, 372, 488, 4341, 372, 1305, 67, 14, 18873, 11664, 8, 1532, 63, 962, 63, 500, 12, 24867, 9, 2958, 871, 2186, 465, 444, 26, 1039, 746, 6064, 480, 2353, 440, 16592, 1284, 2287, 367, 805, 450, 83, 26, 450, 83, 2, 450, 334, 4097, 8, 4489, 395, 444, 430, 8065, 199, 318, 664, 63, 5777, 837, 1128, 408, 1128, 2372, 1006, 1453, 3423, 1128, 768, 1107, 26, 282, 2008, 402, 334, 1593, 63, 354, 12, 805, 63, 4489, 9, 1128, 408, 1128, 372, 469, 362, 63, 1593, 63, 354, 8, 1532, 63, 4489, 304, 2562, 63, 4489, 367, 2562, 63, 4489, 315, 284, 983, 1208, 14, 13967, 12737, 8065, 199, 318, 664, 63, 6106, 63, 890, 837, 1128, 408, 1128, 2372, 314, 5438, 4403, 1568, 1128, 768, 1107, 26, 3193, 12, 4337, 12, 5049, 574, 9297, 314, 5438, 1568, 503, 488, 340, 3405, 14, 1128, 408, 1128, 862, 26, 1039, 10739, 275, 284, 983, 1246, 14, 362, 63, 4904, 63, 6976, 342, 1039, 340, 10739, 14, 374, 63, 708, 2075, 837, 1675, 372, 4337, 1039, 916, 10739, 14, 374, 63, 772, 2075, 837, 1675, 372, 5049, 1039, 587, 26, 1675, 327, 653, 1905, 1568, 365, 15564, 4337, 503, 5049, 4546, 14, 18002, 3193, 4546, 14, 1675, 372, 3193, 2958, 871, 2186, 465, 444, 26, 1039, 746, 6064, 480, 6531, 440, 18615, 440, 8044, 5438, 4403, 1568, 26, 450, 83, 2, 450, 476, 9, 2999, 199, 318, 664, 63, 4687, 63, 466, 837, 1128, 408, 1128, 2372, 12495, 730, 1128, 768, 1107, 26, 1803, 314, 12495, 730, 503, 488, 641, 5988, 14, 1128, 408, 1128, 862, 26, 1039, 10739, 275, 284, 983, 1246, 14, 362, 63, 4904, 63, 6976, 342, 1039, 372, 10739, 14, 4687, 985, 342, 2958, 871, 2186, 465, 444, 26, 1039, 746, 6064, 480, 6531, 440, 8044, 12495, 730, 26, 450, 83, 2, 450, 476, 9, 2999, 199, 318, 365, 63, 1250, 8, 4489, 304, 1128, 408, 1128, 2670, 340, 314, 1453, 16329, 282, 24251, 16329, 1128, 408, 1128, 372, 308, 1096, 14, 3049, 8, 4489, 680, 15738, 14, 374, 63, 1250, 2999, 199, 318, 365, 63, 3292, 8, 4489, 304, 1128, 408, 1128, 2670, 340, 314, 1453, 16329, 282, 17409, 16329, 1128, 408, 1128, 372, 308, 1096, 14, 3049, 8, 4489, 680, 15738, 14, 374, 63, 3292, 2999, 199, 318, 664, 63, 895, 63, 4489, 837, 1128, 408, 1128, 1432, 314, 1453, 15826, 2287, 1128, 408, 1128, 372, 1305, 67, 14, 1002, 2872, 1110, 8, 31136, 1252, 711, 14, 354, 9, 2999, 199, 318, 664, 63, 681, 837, 1128, 408, 1128, 2372, 314, 1453, 3464, 7849, 2287, 1128, 408, 1128, 372, 1305, 67, 14, 1002, 2872, 1110, 8, 31136, 1252, 681, 14, 354, 9, 2999, 199, 318, 664, 63, 350, 2393, 63, 5286, 8, 4489, 304, 1128, 408, 1128, 2372 ]
[ 308, 1096, 202, 199, 646, 1305, 67, 202, 199, 646, 284, 983, 1246, 202, 199, 646, 284, 983, 1208, 202, 199, 646, 295, 202, 199, 504, 308, 1096, 14, 1757, 492, 5044, 14186, 2999, 199, 3060, 202, 199, 3, 202, 199, 3, 2870, 33, 13482, 2406, 365, 282, 11420, 314, 14018, 6818, 2870, 33, 15610, 14, 202, 199, 3, 2779, 2780, 397, 16777, 3423, 1202, 370, 1827, 436, 5283, 666, 202, 199, 3, 687, 2870, 33, 14, 202, 199, 3, 202, 199, 3060, 2999, 199, 3, 11768, 26, 413, 14, 19634, 1006, 2446, 2870, 33, 18752, 3423, 370, 642, 570, 202, 199, 3, 11768, 26, 499, 14, 2790, 376, 9006, 1300, 1021, 367, 314, 1415, 3423, 12, 642, 5594, 4756, 12530, 1844, 3616, 370, 1163, 10677, 14, 2999, 199, 318, 664, 63, 1593, 63, 354, 8, 4489, 304, 1039, 408, 1039, 2372, 314, 3363, 805, 536, 1039, 408, 1039, 327, 7649, 370, 28548, 4593, 1039, 805, 63, 354, 275, 1305, 67, 14, 872, 29602, 8, 344, 67, 14, 1002, 3481, 985, 8, 4489, 395, 1305, 67, 14, 1002, 9551, 48, 5682, 8, 344, 67, 14, 11384, 63, 13003, 63, 10872, 430, 4341, 340, 805, 63, 354, 26, 1675, 805, 63, 354, 275, 805, 63, 354, 14, 1294, 480, 480, 2788, 16, 61, 4341, 327, 6801, 536, 365, 440, 333, 22183, 1039, 340, 440, 805, 63, 354, 26, 1675, 805, 63, 354, 275, 1305, 67, 14, 1002, 3481, 985, 8, 4489, 9, 4341, 340, 440, 805, 63, 354, 26, 1675, 805, 63, 354, 275, 1305, 67, 14, 985, 8, 4489, 9, 4341, 327, 982, 781, 5139, 1172, 949, 805, 536, 12, 1852, 1373, 1536, 14, 9701, 365, 446, 283, 8019, 46, 63, 4963, 35, 63, 25746, 993, 7, 1039, 340, 440, 805, 63, 354, 26, 1675, 805, 63, 354, 275, 298, 8019, 46, 63, 4963, 35, 4970, 83, 2, 450, 6318, 8, 4489, 9, 4341, 372, 805, 63, 354, 2999, 199, 318, 664, 63, 1593, 63, 928, 63, 1562, 8, 4489, 304, 1128, 408, 1128, 2372, 805, 1343, 2287, 1128, 768, 635, 24867, 26, 24867, 687, 4453, 314, 805, 18135, 14, 1128, 768, 1107, 26, 710, 805, 1343, 24867, 14, 982, 805, 1343, 1990, 440, 1911, 372, 1453, 24867, 14, 1128, 408, 1128, 862, 26, 1039, 340, 24867, 365, 488, 26, 1675, 372, 488, 4341, 1343, 63, 350, 2393, 275, 1305, 67, 14, 1002, 3481, 7144, 8, 4489, 12, 1305, 67, 14, 19587, 5280, 63, 7363, 9, 1039, 340, 1343, 63, 350, 2393, 1137, 1305, 67, 14, 9439, 7803, 26, 1675, 372, 1343, 63, 350, 2393, 4341, 372, 24867, 2958, 871, 2186, 465, 444, 26, 1039, 746, 6064, 480, 2353, 440, 16592, 1343, 2287, 367, 805, 450, 83, 26, 450, 83, 2, 450, 334, 4097, 8, 4489, 395, 444, 430, 2999, 199, 318, 664, 63, 1593, 63, 500, 63, 1562, 8, 4489, 304, 1128, 408, 1128, 2372, 805, 1284, 2287, 1128, 768, 635, 24867, 26, 805, 1343, 63, 4489, 14, 1128, 768, 1107, 26, 710, 805, 1284, 24867, 14, 982, 949, 805, 1284, 24867, 1911, 2529, 488, 14, 1128, 408, 1128, 862, 26, 1039, 340, 24867, 365, 488, 26, 1675, 372, 488, 4341, 2562, 63, 962, 63, 500, 275, 1305, 67, 14, 1002, 3481, 7144, 8, 4489, 12, 1305, 67, 14, 19587, 5280, 63, 3902, 9, 1039, 340, 2562, 63, 962, 63, 500, 508, 1305, 67, 14, 9439, 7803, 26, 1675, 372, 488, 4341, 372, 1305, 67, 14, 18873, 11664, 8, 1532, 63, 962, 63, 500, 12, 24867, 9, 2958, 871, 2186, 465, 444, 26, 1039, 746, 6064, 480, 2353, 440, 16592, 1284, 2287, 367, 805, 450, 83, 26, 450, 83, 2, 450, 334, 4097, 8, 4489, 395, 444, 430, 8065, 199, 318, 664, 63, 5777, 837, 1128, 408, 1128, 2372, 1006, 1453, 3423, 1128, 768, 1107, 26, 282, 2008, 402, 334, 1593, 63, 354, 12, 805, 63, 4489, 9, 1128, 408, 1128, 372, 469, 362, 63, 1593, 63, 354, 8, 1532, 63, 4489, 304, 2562, 63, 4489, 367, 2562, 63, 4489, 315, 284, 983, 1208, 14, 13967, 12737, 8065, 199, 318, 664, 63, 6106, 63, 890, 837, 1128, 408, 1128, 2372, 314, 5438, 4403, 1568, 1128, 768, 1107, 26, 3193, 12, 4337, 12, 5049, 574, 9297, 314, 5438, 1568, 503, 488, 340, 3405, 14, 1128, 408, 1128, 862, 26, 1039, 10739, 275, 284, 983, 1246, 14, 362, 63, 4904, 63, 6976, 342, 1039, 340, 10739, 14, 374, 63, 708, 2075, 837, 1675, 372, 4337, 1039, 916, 10739, 14, 374, 63, 772, 2075, 837, 1675, 372, 5049, 1039, 587, 26, 1675, 327, 653, 1905, 1568, 365, 15564, 4337, 503, 5049, 4546, 14, 18002, 3193, 4546, 14, 1675, 372, 3193, 2958, 871, 2186, 465, 444, 26, 1039, 746, 6064, 480, 6531, 440, 18615, 440, 8044, 5438, 4403, 1568, 26, 450, 83, 2, 450, 476, 9, 2999, 199, 318, 664, 63, 4687, 63, 466, 837, 1128, 408, 1128, 2372, 12495, 730, 1128, 768, 1107, 26, 1803, 314, 12495, 730, 503, 488, 641, 5988, 14, 1128, 408, 1128, 862, 26, 1039, 10739, 275, 284, 983, 1246, 14, 362, 63, 4904, 63, 6976, 342, 1039, 372, 10739, 14, 4687, 985, 342, 2958, 871, 2186, 465, 444, 26, 1039, 746, 6064, 480, 6531, 440, 8044, 12495, 730, 26, 450, 83, 2, 450, 476, 9, 2999, 199, 318, 365, 63, 1250, 8, 4489, 304, 1128, 408, 1128, 2670, 340, 314, 1453, 16329, 282, 24251, 16329, 1128, 408, 1128, 372, 308, 1096, 14, 3049, 8, 4489, 680, 15738, 14, 374, 63, 1250, 2999, 199, 318, 365, 63, 3292, 8, 4489, 304, 1128, 408, 1128, 2670, 340, 314, 1453, 16329, 282, 17409, 16329, 1128, 408, 1128, 372, 308, 1096, 14, 3049, 8, 4489, 680, 15738, 14, 374, 63, 3292, 2999, 199, 318, 664, 63, 895, 63, 4489, 837, 1128, 408, 1128, 1432, 314, 1453, 15826, 2287, 1128, 408, 1128, 372, 1305, 67, 14, 1002, 2872, 1110, 8, 31136, 1252, 711, 14, 354, 9, 2999, 199, 318, 664, 63, 681, 837, 1128, 408, 1128, 2372, 314, 1453, 3464, 7849, 2287, 1128, 408, 1128, 372, 1305, 67, 14, 1002, 2872, 1110, 8, 31136, 1252, 681, 14, 354, 9, 2999, 199, 318, 664, 63, 350, 2393, 63, 5286, 8, 4489, 304, 1128, 408, 1128, 2372, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
nave91/dbt
dbt/task/serve.py
1
1050
import shutil import os import webbrowser from socketserver import TCPServer from dbt.include import DOCS_INDEX_FILE_PATH from dbt.compat import SimpleHTTPRequestHandler from dbt.logger import GLOBAL_LOGGER as logger from dbt.task.base_task import RunnableTask class ServeTask(RunnableTask): def run(self): os.chdir(self.project['target-path']) port = 8080 shutil.copyfile(DOCS_INDEX_FILE_PATH, 'index.html') logger.info("Serving docs at 0.0.0.0:{}".format(port)) logger.info( "To access from your browser, navigate to http://localhost:8080.") logger.info("Press Ctrl+C to exit.\n\n") httpd = TCPServer( ('0.0.0.0', port), SimpleHTTPRequestHandler ) try: webbrowser.open_new_tab('http://127.0.0.1:8080') except webbrowser.Error as e: pass try: httpd.serve_forever() # blocks finally: httpd.shutdown() httpd.server_close() return None
apache-2.0
[ 646, 5145, 199, 646, 747, 199, 646, 781, 29063, 199, 504, 2838, 1000, 492, 13488, 3120, 199, 199, 504, 1592, 84, 14, 2613, 492, 3506, 3298, 63, 10215, 63, 3817, 63, 3243, 199, 504, 1592, 84, 14, 5819, 492, 5870, 23518, 199, 504, 1592, 84, 14, 2921, 492, 598, 12667, 63, 10186, 465, 2512, 199, 199, 504, 1592, 84, 14, 1765, 14, 1095, 63, 1765, 492, 3378, 25757, 4476, 421, 199, 533, 3739, 432, 4476, 8, 2540, 25757, 4476, 304, 272, 347, 1255, 8, 277, 304, 267, 747, 14, 8563, 8, 277, 14, 1715, 459, 1375, 13, 515, 1105, 398, 1844, 275, 30220, 398, 5145, 14, 21997, 8, 30072, 63, 10215, 63, 3817, 63, 3243, 12, 283, 1080, 14, 1360, 358, 398, 2512, 14, 815, 480, 1505, 4007, 9149, 737, 378, 14, 16, 14, 16, 14, 16, 26, 13536, 908, 8, 719, 430, 267, 2512, 14, 815, 8, 288, 298, 1378, 2879, 687, 2195, 7042, 12, 20850, 370, 1455, 921, 5967, 26, 15844, 2685, 267, 2512, 14, 815, 480, 14414, 445, 7245, 11, 35, 370, 4458, 3134, 78, 60, 78, 531, 398, 23913, 275, 13488, 3120, 8, 288, 661, 16, 14, 16, 14, 16, 14, 16, 297, 1844, 395, 288, 5870, 23518, 267, 776, 398, 862, 26, 288, 781, 29063, 14, 1490, 63, 1222, 63, 2902, 360, 1014, 921, 4195, 14, 16, 14, 16, 14, 17, 26, 15844, 358, 267, 871, 781, 29063, 14, 547, 465, 325, 26, 288, 986, 398, 862, 26, 288, 23913, 14, 4909, 63, 21327, 342, 221, 327, 5664, 267, 3753, 26, 288, 23913, 14, 8831, 342, 288, 23913, 14, 1000, 63, 1600, 342, 398, 372, 488, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 5145, 199, 646, 747, 199, 646, 781, 29063, 199, 504, 2838, 1000, 492, 13488, 3120, 199, 199, 504, 1592, 84, 14, 2613, 492, 3506, 3298, 63, 10215, 63, 3817, 63, 3243, 199, 504, 1592, 84, 14, 5819, 492, 5870, 23518, 199, 504, 1592, 84, 14, 2921, 492, 598, 12667, 63, 10186, 465, 2512, 199, 199, 504, 1592, 84, 14, 1765, 14, 1095, 63, 1765, 492, 3378, 25757, 4476, 421, 199, 533, 3739, 432, 4476, 8, 2540, 25757, 4476, 304, 272, 347, 1255, 8, 277, 304, 267, 747, 14, 8563, 8, 277, 14, 1715, 459, 1375, 13, 515, 1105, 398, 1844, 275, 30220, 398, 5145, 14, 21997, 8, 30072, 63, 10215, 63, 3817, 63, 3243, 12, 283, 1080, 14, 1360, 358, 398, 2512, 14, 815, 480, 1505, 4007, 9149, 737, 378, 14, 16, 14, 16, 14, 16, 26, 13536, 908, 8, 719, 430, 267, 2512, 14, 815, 8, 288, 298, 1378, 2879, 687, 2195, 7042, 12, 20850, 370, 1455, 921, 5967, 26, 15844, 2685, 267, 2512, 14, 815, 480, 14414, 445, 7245, 11, 35, 370, 4458, 3134, 78, 60, 78, 531, 398, 23913, 275, 13488, 3120, 8, 288, 661, 16, 14, 16, 14, 16, 14, 16, 297, 1844, 395, 288, 5870, 23518, 267, 776, 398, 862, 26, 288, 781, 29063, 14, 1490, 63, 1222, 63, 2902, 360, 1014, 921, 4195, 14, 16, 14, 16, 14, 17, 26, 15844, 358, 267, 871, 781, 29063, 14, 547, 465, 325, 26, 288, 986, 398, 862, 26, 288, 23913, 14, 4909, 63, 21327, 342, 221, 327, 5664, 267, 3753, 26, 288, 23913, 14, 8831, 342, 288, 23913, 14, 1000, 63, 1600, 342, 398, 372, 488, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Naereen/notebooks
Py_Pi_Day_2017.py
1
42588
# coding: utf-8 # # Table of Contents # <p><div class="lev1 toc-item"><a href="#Python-Pi-Day-2017" data-toc-modified-id="Python-Pi-Day-2017-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Python Pi Day 2017</a></div><div class="lev1 toc-item"><a href="#Computing-a-lot-of-digits-of-$\pi$?" data-toc-modified-id="Computing-a-lot-of-digits-of-$\pi$?-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Computing a lot of digits of <span class="MathJax_Preview" style="color: inherit;"></span><span class="MathJax" id="MathJax-Element-388-Frame" tabindex="0" style="position: relative;" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>&amp;#x03C0;</mi></math>" role="presentation"><nobr aria-hidden="true"><span class="math" id="MathJax-Span-2745" role="math" style="width: 0.702em; display: inline-block;"><span style="display: inline-block; position: relative; width: 0.554em; height: 0px; font-size: 125%;"><span style="position: absolute; clip: rect(1.941em, 1000.55em, 2.572em, -1000em); top: -2.462em; left: 0em;"><span class="mrow" id="MathJax-Span-2746"><span class="mi" id="MathJax-Span-2747" style="font-family: STIXMathJax_Main; font-style: italic;">π<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.032em;"></span></span></span><span style="display: inline-block; width: 0px; height: 2.462em;"></span></span></span><span style="display: inline-block; overflow: hidden; vertical-align: -0.061em; border-left: 0px solid; width: 0px; height: 0.634em;"></span></span></nobr><span class="MJX_Assistive_MathML" role="presentation"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>π</mi></math></span></span><script type="math/tex" id="MathJax-Element-388">\pi</script>?</a></div><div class="lev2 toc-item"><a href="#Two-simple-methods-for-finding-the-first-digits-of-$\pi$" data-toc-modified-id="Two-simple-methods-for-finding-the-first-digits-of-$\pi$-21"><span class="toc-item-num">2.1&nbsp;&nbsp;</span>Two simple methods for finding the first digits of <span class="MathJax_Preview" style="color: inherit;"></span><span class="MathJax" id="MathJax-Element-391-Frame" tabindex="0" style="position: relative;" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>&amp;#x03C0;</mi></math>" role="presentation"><nobr aria-hidden="true"><span class="math" id="MathJax-Span-2754" role="math" style="width: 0.693em; display: inline-block;"><span style="display: inline-block; position: relative; width: 0.541em; height: 0px; font-size: 126%;"><span style="position: absolute; clip: rect(1.953em, 1000.54em, 2.615em, -1000em); top: -2.489em; left: 0em;"><span class="mrow" id="MathJax-Span-2755"><span class="mi" id="MathJax-Span-2756" style="font-family: STIXMathJax_Main; font-style: italic;">π<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.032em;"></span></span></span><span style="display: inline-block; width: 0px; height: 2.489em;"></span></span></span><span style="display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.653em;"></span></span></nobr><span class="MJX_Assistive_MathML" role="presentation"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>π</mi></math></span></span><script type="math/tex" id="MathJax-Element-391">\pi</script></a></div><div class="lev3 toc-item"><a href="#Fraction-approximations,-and-$\pi$-imported-from-the-math-module" data-toc-modified-id="Fraction-approximations,-and-$\pi$-imported-from-the-math-module-211"><span class="toc-item-num">2.1.1&nbsp;&nbsp;</span>Fraction approximations, and <span class="MathJax_Preview" style="color: inherit;"></span><span class="MathJax" id="MathJax-Element-392-Frame" tabindex="0" style="position: relative;" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>&amp;#x03C0;</mi></math>" role="presentation"><nobr aria-hidden="true"><span class="math" id="MathJax-Span-2757" role="math" style="width: 0.736em; display: inline-block;"><span style="display: inline-block; position: relative; width: 0.56em; height: 0px; font-size: 129%;"><span style="position: absolute; clip: rect(1.898em, 1000.56em, 2.602em, -1000em); top: -2.455em; left: 0em;"><span class="mrow" id="MathJax-Span-2758"><span class="mi" id="MathJax-Span-2759" style="font-family: STIXMathJax_Main; font-style: italic;">π<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.032em;"></span></span></span><span style="display: inline-block; width: 0px; height: 2.455em;"></span></span></span><span style="display: inline-block; overflow: hidden; vertical-align: -0.079em; border-left: 0px solid; width: 0px; height: 0.686em;"></span></span></nobr><span class="MJX_Assistive_MathML" role="presentation"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>π</mi></math></span></span><script type="math/tex" id="MathJax-Element-392">\pi</script> imported from the <code>math</code> module</a></div><div class="lev3 toc-item"><a href="#A-simple-Monte-Carlo-method" data-toc-modified-id="A-simple-Monte-Carlo-method-212"><span class="toc-item-num">2.1.2&nbsp;&nbsp;</span>A simple <a href="https://en.wikipedia.org/wiki/Pi#Monte_Carlo_methods" target="_blank">Monte-Carlo method</a></a></div><div class="lev2 toc-item"><a href="#$100$-first-digits-of-$\pi$" data-toc-modified-id="$100$-first-digits-of-$\pi$-22"><span class="toc-item-num">2.2&nbsp;&nbsp;</span><span class="MathJax_Preview" style="color: inherit;"></span><span class="MathJax" id="MathJax-Element-397-Frame" tabindex="0" style="position: relative;" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mn>100</mn></math>" role="presentation"><nobr aria-hidden="true"><span class="math" id="MathJax-Span-2778" role="math" style="width: 1.92em; display: inline-block;"><span style="display: inline-block; position: relative; width: 1.515em; height: 0px; font-size: 126%;"><span style="position: absolute; clip: rect(1.885em, 1001.49em, 2.792em, -1000em); top: -2.67em; left: 0em;"><span class="mrow" id="MathJax-Span-2779"><span class="mn" id="MathJax-Span-2780" style="font-family: STIXMathJax_Main;">100</span></span><span style="display: inline-block; width: 0px; height: 2.67em;"></span></span></span><span style="display: inline-block; overflow: hidden; vertical-align: -0.063em; border-left: 0px solid; width: 0px; height: 0.96em;"></span></span></nobr><span class="MJX_Assistive_MathML" role="presentation"><math xmlns="http://www.w3.org/1998/Math/MathML"><mn>100</mn></math></span></span><script type="math/tex" id="MathJax-Element-397">100</script> first digits of <span class="MathJax_Preview" style="color: inherit;"></span><span class="MathJax" id="MathJax-Element-398-Frame" tabindex="0" style="position: relative;" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>&amp;#x03C0;</mi></math>" role="presentation"><nobr aria-hidden="true"><span class="math" id="MathJax-Span-2781" role="math" style="width: 0.693em; display: inline-block;"><span style="display: inline-block; position: relative; width: 0.541em; height: 0px; font-size: 126%;"><span style="position: absolute; clip: rect(1.953em, 1000.54em, 2.615em, -1000em); top: -2.489em; left: 0em;"><span class="mrow" id="MathJax-Span-2782"><span class="mi" id="MathJax-Span-2783" style="font-family: STIXMathJax_Main; font-style: italic;">π<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.032em;"></span></span></span><span style="display: inline-block; width: 0px; height: 2.489em;"></span></span></span><span style="display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.653em;"></span></span></nobr><span class="MJX_Assistive_MathML" role="presentation"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>π</mi></math></span></span><script type="math/tex" id="MathJax-Element-398">\pi</script></a></div><div class="lev2 toc-item"><a href="#Using-mpmath" data-toc-modified-id="Using-mpmath-23"><span class="toc-item-num">2.3&nbsp;&nbsp;</span>Using <a href="http://mpmath.org/" target="_blank"><code>mpmath</code></a></a></div><div class="lev2 toc-item"><a href="#The-Gauss–Legendre-iterative-algorithm" data-toc-modified-id="The-Gauss–Legendre-iterative-algorithm-24"><span class="toc-item-num">2.4&nbsp;&nbsp;</span>The Gauss–Legendre iterative algorithm</a></div><div class="lev3 toc-item"><a href="#Using-float-numbers" data-toc-modified-id="Using-float-numbers-241"><span class="toc-item-num">2.4.1&nbsp;&nbsp;</span>Using float numbers</a></div><div class="lev3 toc-item"><a href="#Using-decimal.Decimal-to-improve-precision" data-toc-modified-id="Using-decimal.Decimal-to-improve-precision-242"><span class="toc-item-num">2.4.2&nbsp;&nbsp;</span>Using <code>decimal.Decimal</code> to improve precision</a></div><div class="lev2 toc-item"><a href="#Methods-based-on-a-convergent-series" data-toc-modified-id="Methods-based-on-a-convergent-series-25"><span class="toc-item-num">2.5&nbsp;&nbsp;</span>Methods based on a convergent series</a></div><div class="lev3 toc-item"><a href="#A-Leibniz-formula-(easy):" data-toc-modified-id="A-Leibniz-formula-(easy):-251"><span class="toc-item-num">2.5.1&nbsp;&nbsp;</span><a href="https://en.wikipedia.org/wiki/Leibniz_formula_for_pi" target="_blank">A Leibniz formula</a> (<em>easy</em>):</a></div><div class="lev3 toc-item"><a href="#Bailey-Borwein-Plouffe-series-(medium):" data-toc-modified-id="Bailey-Borwein-Plouffe-series-(medium):-252"><span class="toc-item-num">2.5.2&nbsp;&nbsp;</span><a href="https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula" target="_blank">Bailey-Borwein-Plouffe series</a> (<em>medium</em>):</a></div><div class="lev3 toc-item"><a href="#Bellard's-formula-(hard):" data-toc-modified-id="Bellard's-formula-(hard):-253"><span class="toc-item-num">2.5.3&nbsp;&nbsp;</span><a href="https://en.wikipedia.org/wiki/Bellard%27s_formula" target="_blank">Bellard's formula</a> (<em>hard</em>):</a></div><div class="lev3 toc-item"><a href="#One-Ramanujan's-formula-(hard):" data-toc-modified-id="One-Ramanujan's-formula-(hard):-254"><span class="toc-item-num">2.5.4&nbsp;&nbsp;</span>One <a href="https://en.wikipedia.org/wiki/Approximations_of_%CF%80#Efficient_methods" target="_blank">Ramanujan's formula</a> (<em>hard</em>):</a></div><div class="lev3 toc-item"><a href="#Chudnovsky-brothers'-formula-(hard):" data-toc-modified-id="Chudnovsky-brothers'-formula-(hard):-255"><span class="toc-item-num">2.5.5&nbsp;&nbsp;</span><a href="https://en.wikipedia.org/wiki/Chudnovsky_algorithm" target="_blank">Chudnovsky brothers' formula</a> (<em>hard</em>):</a></div><div class="lev2 toc-item"><a href="#Other-methods" data-toc-modified-id="Other-methods-26"><span class="toc-item-num">2.6&nbsp;&nbsp;</span>Other methods</a></div><div class="lev3 toc-item"><a href="#Trigonometric-methods-(hard)" data-toc-modified-id="Trigonometric-methods-(hard)-261"><span class="toc-item-num">2.6.1&nbsp;&nbsp;</span>Trigonometric methods (<em>hard</em>)</a></div><div class="lev4 toc-item"><a href="#High-precision-arccot-computation" data-toc-modified-id="High-precision-arccot-computation-2611"><span class="toc-item-num">2.6.1.1&nbsp;&nbsp;</span><a href="http://en.literateprograms.org/Pi_with_Machin%27s_formula_%28Python%29#High-precision_arccot_computation" target="_blank">High-precision arccot computation</a></a></div><div class="lev4 toc-item"><a href="#Applying-Machin's-formula" data-toc-modified-id="Applying-Machin's-formula-2612"><span class="toc-item-num">2.6.1.2&nbsp;&nbsp;</span>Applying Machin's formula</a></div><div class="lev4 toc-item"><a href="#Trying-to-solve-my-question!" data-toc-modified-id="Trying-to-solve-my-question!-2613"><span class="toc-item-num">2.6.1.3&nbsp;&nbsp;</span>Trying to solve my question!</a></div><div class="lev4 toc-item"><a href="#Conclusion" data-toc-modified-id="Conclusion-2614"><span class="toc-item-num">2.6.1.4&nbsp;&nbsp;</span>Conclusion</a></div><div class="lev3 toc-item"><a href="#(hard)-Unbounded-Spigot-Algorithm" data-toc-modified-id="(hard)-Unbounded-Spigot-Algorithm-262"><span class="toc-item-num">2.6.2&nbsp;&nbsp;</span>(<em>hard</em>) <a href="http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf" target="_blank">Unbounded Spigot Algorithm</a></a></div><div class="lev3 toc-item"><a href="#(hard)-Borwein's-algorithm" data-toc-modified-id="(hard)-Borwein's-algorithm-263"><span class="toc-item-num">2.6.3&nbsp;&nbsp;</span>(<em>hard</em>) <a href="https://en.wikipedia.org/wiki/Borwein%27s_algorithm#Nonic_convergence" target="_blank">Borwein's algorithm</a></a></div><div class="lev2 toc-item"><a href="#Examples-and-references" data-toc-modified-id="Examples-and-references-27"><span class="toc-item-num">2.7&nbsp;&nbsp;</span>Examples and references</a></div><div class="lev3 toc-item"><a href="#Links" data-toc-modified-id="Links-271"><span class="toc-item-num">2.7.1&nbsp;&nbsp;</span>Links</a></div><div class="lev3 toc-item"><a href="#Pie-!" data-toc-modified-id="Pie-!-272"><span class="toc-item-num">2.7.2&nbsp;&nbsp;</span>Pie !</a></div> # # Python Pi Day 2017 # > This is heavily inspired by what I did two years ago, see this page [cs101/hackhaton/14_03/2015](http://perso.crans.org/besson/cs101/hackathon/14_03_2015) on my website. # # Today is [Pi Day 2017](http://www.piday.org/), the day celebrating the number $\pi$. # For more details on this number, see [this Wikipedia page](https://en.wikipedia.org/wiki/Pi). # # ---- # # Let us use this occasion to showcase a few different approaches to compute the digits of the number $\pi$. # I will use the [Python](https://www.python.org/) programming language, and you are reading a [Jupyter notebook](https://www.jupyter.org/). # # [![made-with-jupyter](https://img.shields.io/badge/Made%20with-Jupyter-1f425f.svg)](http://jupyter.org/)[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) # # Computing a lot of digits of $\pi$? # # - **What to do ?** I will present and implement some methods that can be used to compute the first digits of the irrational number $\pi$. # - **How ?** One method is based on random numbers, but all the other are simple (or not so simple) iterative algorithm: the more steps you compute, the more digits you will have! # - **How to compare / assess the result ?** It is simple: the more digits you got, the better. We will also test the different methods implemented, and for the most efficient, see how fast it is to go up-to $140000$ digits. # # The simple goal is to write a *small* function that computes digits of pi, as fast as possible, and find the 10 digits from position 140317 to 140327! # (that's the challenge I posted on Facebook) # ---- # ## Two simple methods for finding the first digits of $\pi$ # ### Fraction approximations, and $\pi$ imported from the `math` module # Three approximations, using fractions, were known from a very long time (Aristote used $\frac{355}{113}$ !). # The first three approximations of pi are: # In[3]: print(" pi ~= 3.14 (two first digits).") print(" pi ~= 22/7 = {} (two first digits).".format(22.0 / 7.0)) print(" pi ~= 355/113 = {} (six first digits).".format(355.0 / 113.0)) # This method is extremely limited, and will not give you more than 13 correct digits, as `math.pi` is stored as a *float* number (limited precision). # In[4]: def mathpi(): from math import pi return pi print("First method: using math.pi gives pi ~= {:.17f} (17 digits are displayed here).".format(mathpi())) # If we know the digits, we can directly print them: # In[5]: from decimal import Decimal bigpi = Decimal('3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679') print("The first 100 digits of pi are {}.".format(bigpi)) # ### A simple [Monte-Carlo method](https://en.wikipedia.org/wiki/Pi#Monte_Carlo_methods) # A simple Monte Carlo method for computing $\pi$ is to draw a circle inscribed in a square, and randomly place dots in the square. # The ratio of dots inside the circle to the total number of dots will approximately equal $\pi / 4$, which is also the ratio of the area of the circle by the area of the square: # # ![Example of a random simulation of this Monte-Carlo method](https://upload.wikimedia.org/wikipedia/commons/8/84/Pi_30K.gif "Example of a random simulation of this Monte-Carlo method") # # In Python, such simulation can basically be implemented like this: # In[6]: from random import uniform def montecarlo_pi(nbPoints=10000): """Returns a probabilist estimate of pi, as a float number.""" nbInside = 0 # we pick a certain number of points (nbPoints) for i in range(nbPoints): x = uniform(0, 1) y = uniform(0, 1) # (x, y) is now a random point in the square [0, 1] × [0, 1] if (x**2 + y**2) < 1: # This point (x, y) is inside the circle C(0, 1) nbInside += 1 return 4 * float(nbInside) / floor(nbPoints) # In[9]: print("The simple Monte-Carlo method with {} random points gave pi = {}".format(10000, montecarlo_pi(10000))) # It is an interesting method, but it is just too limited for approximating digits of $\pi$. # # # The previous two methods are quite limited, and not efficient enough if you want more than 13 digits (resp. 4 digits for the Monte-Carlo method). # ## $100$ first digits of $\pi$ # $\pi \simeq 3.1415926535 ~ 8979323846 ~ 2643383279 ~ 5028841971 \\\\ 6939937510 ~ 5820974944 ~ 5923078164 ~ 9862803482 ~ 53421170679$ when computed to the first $100$ digits. # # Can you compute up to $1000$ digits? Up to $10000$ digits? Up to $100000$ digits? **Up to 1 million digits?** # ## Using [`mpmath`](http://mpmath.org/) # This is a simple and lazy method, using the [`mpmath`](http://mpmath.org/) module. # MPmath is a Python library for arbitrary-precision floating-point arithmetic (Multi-Precision), and it has a builtin highly-optimized algorithm to compute digits of $\pi$. # # It works really fine up-to 1000000 digits (56 ms), from 1 million digits to be printed, printing them starts to get too time consuming (the IDE or the system might freeze). # In[10]: import mpmath # from sympy import mpmath # on older sympy versions mp = mpmath.mp # We can [arbitrarily set the precision](http://docs.sympy.org/dev/modules/mpmath/basics.html#setting-the-precision), with the constant `mp.dps` (digit numbers). # In[11]: mp.dps = 1000 # number of digits my_pi = mp.pi # Gives pi to a thousand places print("A lazy method using the mpmath module:\npi is approximatly {} (with {} digits).".format(my_pi, mp.dps)) # Let save it for further comparison of simpler methods. # In[87]: mp.dps = 100000 # number of digits len(str(mp.pi)) mpmath_pi = Decimal(str(mp.pi)) # We can solve the initial challenge easily: # In[86]: mp.dps = 140330 print(str(mp.pi)[2:][140317:140317+10]) # And it will most probably be the quickest method presented here: # In[14]: get_ipython().run_line_magic('timeit', 'mp.dps=140330;print(str(mp.pi)[2:][140317:140317+10])') # Asking for $10$ times more digits take about $100$ more of time (that's a bad news). # In[43]: get_ipython().run_line_magic('timeit', 'mp.dps=1403230;print(str(mp.pi)[2:][1403217:1403217+10])') # ## The Gauss–Legendre iterative algorithm # > More details can be found on [this page](https://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_algorithm). # # The first method given here is explained in detail. # This algorithm is called the [Gauss-Legendre method](https://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_algorithm), and for example it was used to compute the first $206 158 430 000$ decimal digits of $\pi$ on September 18th to 20th, $1999$. # # It is a very simply **iterative algorithm** (ie. step by step, you update the variables, as long as you want): # # 1. First, start with 4 variables $a_0, b_0, t_0, p_0$, and their initial values are $a_0 = 1, b_0 = 1/\sqrt{2}, t_0 = 1/4, p_0 = 1$. # # 2. Then, update the variables (or create 4 new ones $a_{n+1}, b_{n+1}, t_{n+1}, p_{n+1}$) by repeating the following instructions (in this order) until the difference of $a_{n}$ and $b_{n}$, is within the desired accuracy: # - $a_{n+1} = \frac{a_n + b_n}{2}$, # - $b_{n+1} = \sqrt{a_n \times b_n}$, # - $t_{n+1} = t_n - p_n (a_n - a_{n+1})^2$, # - $p_{n+1} = 2 p_n$. # # 3. Finally, the desired approximation of $\pi$ is: $$\pi \simeq \frac{(a_{n+1} + b_{n+1})^2}{4 t_{n+1}}.$$ # ### Using float numbers # The first three iterations give (approximations given up to and including the first incorrect digit): # # 3.140 … # 3.14159264 … # 3.1415926535897932382 … # # The algorithm has **second-order convergent nature**, which essentially means that the number of correct digits doubles with each step of the algorithm. # Try to see how far it can go in less than 120 seconds (print the approximation of $\pi$ after every step, and stop/kill the program after 2 minutes). # # > This method is based on [computing the limits of the arithmetic–geometric mean](https://en.wikipedia.org/wiki/Arithmetic%E2%80%93geometric_mean) of some well-chosen number ([see on Wikipédia for more mathematical details](https://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_algorithm#Mathematical_background)). # In[17]: import math def gauss_legendre_1(max_step): """Float number implementation of the Gauss-Legendre algorithm, for max_step steps.""" a = 1. b = 1./math.sqrt(2) t = 1./4.0 p = 1. for i in range(max_step): at = (a + b) / 2.0 bt = math.sqrt(a*b) tt = t - p*(a-at)**2 pt = 2.0 * p a, b, t, p = at, bt, tt, pt my_pi = ((a+b)**2)/(4.0*t) return my_pi # In[89]: my_pi = gauss_legendre_1(4) my_pi print("pi is approximately: {:.15f} (as a float number, precision is limited).".format(my_pi)) accuracy = 100*abs(math.pi - my_pi)/math.pi print("Accuracy % with math.pi: {:.4g}".format(accuracy)) accuracy = 100*abs(float(mpmath_pi) - my_pi)/float(mpmath_pi) print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # In[90]: my_pi = gauss_legendre_1(40) my_pi print("pi is approximately: {:.15f} (as a float number, precision is limited).".format(my_pi)) accuracy = 100*abs(math.pi - my_pi)/math.pi print("Accuracy % with math.pi: {:.4g}".format(accuracy)) accuracy = 100*abs(float(mpmath_pi) - my_pi)/float(mpmath_pi) print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # This first implementation of the Gauss-Legendre algorithm is limited to a precision of 13 or 14 digits. But it converges quickly ! (4 steps here). # ### Using `decimal.Decimal` to improve precision # The limitation of this first algorithm came from using simple *float* numbers. # Let us now use [`Decimal`](https://docs.python.org/3/library/decimal.html) numbers to keep as many digits after the decimal as we need. # In[24]: from decimal import Decimal, getcontext # In[25]: def gauss_legendre_2(max_step): """Decimal number implementation of the Gauss-Legendre algorithm, for max_step steps.""" # trick to improve precision getcontext().prec = 3 + 2**(max_step + 2) cst_2 = Decimal(2.0) cst_4 = Decimal(4.0) a = Decimal(1.0) b = Decimal(0.5).sqrt() t = Decimal(0.25) p = Decimal(1.0) for i in range(max_step): new_a = (a+b)/cst_2 new_b = (a*b).sqrt() new_t = Decimal(t - p*(a - new_a)**2) new_p = cst_2*p a, b, t, p = new_a, new_b, new_t, new_p my_pi = Decimal(((a+b)**2)/(cst_4*t)) return my_pi # In[91]: my_pi = gauss_legendre_2(5) print("pi is approximately: {}.".format(my_pi.to_eng_string()[:2**(5+1)])) accuracy = 100*abs(Decimal(math.pi) - my_pi)/Decimal(math.pi) print("Accuracy % with math.pi: {:.4g}".format(accuracy)) accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # The second implementation of the Gauss-Legendre algorithm is now working better (when we adapt the precision). And it converges quickly ! (8 steps give a precision upto the 697th digits). # # How much did we lost in term of performance by using decimal numbers? About a factor $1000$, but that's normal as the second solution stores a lot of digits. They don't even compute the same response. # In[92]: get_ipython().run_line_magic('timeit', 'gauss_legendre_1(8)') get_ipython().run_line_magic('timeit', 'gauss_legendre_2(8)') # ## Methods based on a convergent series # For the following formulae, you can try to write a program that computes the partial sum of the series, up to a certain number of term ($N \geq 1$). # Basically, the bigger the $N$, the more digits you get (but the longer the program will run). # # Some methods might be really efficient, only needing a few number of steps (a small $N$) for computing many digits. # Try to implement and compare at least two of these methods. # You can use the function `sum` (or `math.fsum`) to compute the sum, or a simple `while`/`for` loop. # # All these partial sums are written up to an integer $N \geq 1$. # ### [A Leibniz formula](https://en.wikipedia.org/wiki/Leibniz_formula_for_pi) (*easy*): # It has a number of digits sub-linear in the number $N$ of terms in the sum: we need $10$ times more terms to win just one digit. # $$\pi \simeq 4\sum_{n=0}^{N} \cfrac {(-1)^n}{2n+1}. $$ # In[30]: def leibniz(max_step): """ Computing an approximation of pi with Leibniz series.""" my_pi = Decimal(0) for k in range(max_step): my_pi += Decimal((-1)**k) / Decimal(2*k+1) return Decimal(4) * my_pi # In[98]: getcontext().prec = 20 # trick to improve precision my_pi = leibniz(1000) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # In[99]: getcontext().prec = 20 # trick to improve precision my_pi = leibniz(10000) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # This first formula is very inefficient! # ### [Bailey-Borwein-Plouffe series](https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula) (*medium*): # It also has a number of digits linear in the number $N$ of terms in the sum. # $$\pi \simeq \sum_{n = 1}^{N} \left( \frac{1}{16^{n}} \left( \frac{4}{8n+1} - \frac{2}{8n+4} - \frac{1}{8n+5} - \frac{1}{8n+6} \right) \right). $$ # In[100]: def bbp(max_step): """ Computing an approximation of pi with Bailey-Borwein-Plouffe series.""" my_pi = Decimal(0) for k in range(max_step): my_pi += (Decimal(1)/(16**k))*((Decimal(4)/(8*k+1))-(Decimal(2)/(8*k+4))-(Decimal(1)/(8*k+5))-(Decimal(1)/(8*k+6))) return my_pi # In[101]: getcontext().prec = 20 # trick to improve precision my_pi = bbp(10) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # That's pretty impressive, in only $10$ steps! # But that algorithm is highly dependent on the precision we ask, and on the number of terms in the sum. # In[102]: getcontext().prec = 200 # trick to improve precision my_pi = bbp(200) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # In[103]: getcontext().prec = 500 # trick to improve precision my_pi = bbp(500) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # It is, of course, slower than the optimized algorithm from `mpmath`. # And it does not scale well with the precision: # In[104]: getcontext().prec = 10 + 1000 # trick to improve precision get_ipython().run_line_magic('timeit', 'bbp(1000)') getcontext().prec = 10 + 2000 # trick to improve precision get_ipython().run_line_magic('timeit', 'bbp(2000)') # ### [Bellard's formula](https://en.wikipedia.org/wiki/Bellard%27s_formula) (*hard*): # It is a more efficient formula. # $$\pi \simeq \frac1{2^6} \sum_{n=0}^N \frac{(-1)^n}{2^{10n}} \, \left(-\frac{2^5}{4n+1} - \frac1{4n+3} + \frac{2^8}{10n+1} - \frac{2^6}{10n+3} - \frac{2^2}{10n+5} - \frac{2^2}{10n+7} + \frac1{10n+9} \right). $$ # In[105]: def bellard(max_step): """ Computing an approximation of pi with Bellard series.""" my_pi = Decimal(0) for k in range(max_step): my_pi += (Decimal(-1)**k/(1024**k))*( Decimal(256)/(10*k+1) + Decimal(1)/(10*k+9) - Decimal(64)/(10*k+3) - Decimal(32)/(4*k+1) - Decimal(4)/(10*k+5) - Decimal(4)/(10*k+7) -Decimal(1)/(4*k+3)) return my_pi * Decimal(1.0/(2**6)) # In[106]: getcontext().prec = 40 # trick to improve precision my_pi = bellard(10) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # That's pretty impressive, in only $10$ steps! # But that algorithm is again highly dependent on the precision we ask, and on the number of terms in the sum. # In[107]: getcontext().prec = 800 # trick to improve precision my_pi = bellard(200) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # It is, of course, slower than the optimized algorithm from `mpmath`. # And it does not scale well with the precision: # In[73]: getcontext().prec = 10 + 1000 # trick to improve precision get_ipython().run_line_magic('timeit', 'bellard(1000)') getcontext().prec = 10 + 2000 # trick to improve precision get_ipython().run_line_magic('timeit', 'bellard(2000)') # It is also slower than BBP formula. # ### One [Ramanujan's formula](https://en.wikipedia.org/wiki/Approximations_of_%CF%80#Efficient_methods) (*hard*): # It is efficient but harder to compute easily with high precision, due to the factorial. # But hopefully, the function `math.factorial` works with Python *integers*, of arbitrary size, so this won't be an issue. # # $$\frac{1}{\pi} \simeq \frac{2\sqrt{2}}{9801} \sum_{n=0}^N \frac{(4n)!(1103+26390n)}{(n!)^4 396^{4n}}. $$ # # *Remark:* This method and the next one compute approximation of $\frac{1}{\pi}$, not $\pi$. # # This method has a quadratic precision (the number of correct digits is of the order $\mathcal{O}(N^2)$. # In[123]: from math import factorial def ramanujan(max_step): """ Computing an approximation of pi with a Ramanujan's formula.""" my_pi = Decimal(0) d_1103 = Decimal(1103) d_26390 = Decimal(26390) d_396 = Decimal(396) for k in range(max_step): my_pi += ((Decimal(factorial(4 * k))) * (d_1103 + d_26390 * Decimal(k))) / ( (Decimal(factorial(k)))**4 * (d_396**(4*k))) my_pi = my_pi * 2 * Decimal(2).sqrt() / Decimal(9801) my_pi = my_pi**(-1) return my_pi # In[124]: getcontext().prec = 40 # trick to improve precision my_pi = ramanujan(4) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # In[125]: getcontext().prec = 400 # trick to improve precision my_pi = ramanujan(40) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # In[126]: getcontext().prec = 2000 # trick to improve precision my_pi = ramanujan(200) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # $1595$ correct digits with $200$ terms, that's quite good!! # In[127]: getcontext().prec = 10 + 2000 # trick to improve precision get_ipython().run_line_magic('timeit', 'ramanujan(200)') getcontext().prec = 10 + 5000 # trick to improve precision get_ipython().run_line_magic('timeit', 'ramanujan(400)') # Let's try to answer my initial question, using this naive implementation. # In[128]: get_ipython().run_cell_magic('time', '', 'getcontext().prec = 140350 # trick to improve precision\ni = 140317\nmy_pi = ramanujan(10000)\nprint(str(my_pi)[2:][i:i+10])\n\nmp.dps=140330\nprint(str(mp.pi)[2:][i:i+10])') # ... It was too slow! # ### [Chudnovsky brothers' formula](https://en.wikipedia.org/wiki/Chudnovsky_algorithm) (*hard*): # $$\frac{1}{\pi} \simeq 12 \sum_{n=0}^N \frac {(-1)^{n}(6n)!(545140134n+13591409)}{(3n)!(n!)^{3}640320^{{3n+3/2}}}. $$ # In 2015, the best method is still the Chudnovsky brothers's formula. # # > Be careful when you use these formulae, *check carefully* the constants you wrote (545140134 will work well, 545140135 might not work as well!). # # > This formula is used as the logo of the [French agrégation of Mathematics](https://en.wikipedia.org/wiki/Agr%C3%A9gation) [website `agreg.org`](http://agreg.org/) : # > ![http://agreg.org/LogoAgreg.gif](http://agreg.org/LogoAgreg.gif) # In[129]: from math import factorial def chudnovsky(max_step): """ Computing an approximation of pi with Bellard series.""" my_pi = Decimal(0) for k in range(max_step): my_pi += (Decimal(-1)**k)*(Decimal(factorial(6*k))/((factorial(k)**3)*(factorial(3*k)))* (13591409+545140134*k)/(640320**(3*k))) my_pi = my_pi * Decimal(10005).sqrt()/4270934400 my_pi = my_pi**(-1) return my_pi # It is very efficient, as Ramanujan's formula. # In[131]: getcontext().prec = 3000 # trick to improve precision my_pi = chudnovsky(200) my_pi accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # It gets $2834$ correct numbers in $200$ steps! # It is more efficient that Ramanujan's formula, but slower to compute. # In[134]: getcontext().prec = 6000 # trick to improve precision my_pi = chudnovsky(400) accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # In[135]: getcontext().prec = 3000 # trick to improve precision get_ipython().run_line_magic('timeit', 'chudnovsky(200)') getcontext().prec = 6000 # trick to improve precision get_ipython().run_line_magic('timeit', 'chudnovsky(400)') # About $2$ seconds to find correctly the first $5671$ digits? That's slow! But hey, it's Python (dynamic typing etc). # ---- # ## Other methods # ### Trigonometric methods (*hard*) # Some methods are based on the $\mathrm{arccot}$ or $\arctan$ functions, and use the appropriate Taylor series to approximate these functions. # The best example is [Machin's formula](http://en.literateprograms.org/Pi_with_Machin%27s_formula_%28Python%29): # $$\pi = 16 \;\mathrm{arccot}(5) - 4 \;\mathrm{arccot}(239).$$ # # And we use the Taylor series to approximate $\mathrm{arccot}(x)$: # $$\mathrm{arccot}(x) = \frac{1}{x} - \frac{1}{3x^3} + \frac{1}{5x^5} - \frac{1}{7x^7} + \dots = \sum_{n=0}^{+\infty} \frac{(-1)^n}{(2n+1) x^{2n+1}} .$$ # # This method is also explained here with some details. # In order to obtain $n$ digits, we will use *fixed-point* arithmetic to compute $\pi \times 10^n$ as a Python `long` integer. # #### [High-precision arccot computation](http://en.literateprograms.org/Pi_with_Machin%27s_formula_%28Python%29#High-precision_arccot_computation) # To calculate $\mathrm{arccot}$ of an argument $x$, we start by dividing the number $1$ (represented by $10^n$, which we provide as the argument `unity`) by $x$ to obtain the first term. # # We then repeatedly divide by $x^2$ and a counter value that runs over $3$, $5$, $7$ etc, to obtain each next term. # The summation is stopped at the first zero `term`, which in this *fixed-point* representation corresponds to a real value less than $10^{-n}$: # # ```python # def arccot(x, unity): # xpower = unity / x # sum = xpower # n = 3 # sign = -1 # while True: # xpower = xpower / (x*x) # term = xpower / n # if term == 0: # break # we are done # sum += sign * term # sign = -sign # n += 2 # return sum # ``` # Adapting it to use Decimal numbers is easy: # In[171]: def arccot(x, unity): """Compute arccot(x) with a certain level of precision.""" x = Decimal(x) unity = Decimal(unity) mysum = xpower = unity / x n = 3 sign = -1 while True: xpower = xpower / (x*x) term = xpower / n if not term: break mysum += sign * term sign = -sign # we alternate the sign n += 2 return mysum # #### Applying Machin's formula # Finally, the main function uses Machin's formula to compute $\pi$ using the necessary level of precision, by using this high precision $\mathrm{arccot}$ function: # $$\pi = 16 \;\mathrm{arccot}(5) - 4 \;\mathrm{arccot}(239).$$ # # ```python # def machin(digits): # unity = 10**(digits + 10) # pi = 4 * (4*arccot(5, unity) - arccot(239, unity)) # return pi / unity # ``` # # To avoid rounding errors in the result, we use 10 guard digits internally during the calculation. # We may now reproduce the historical result obtained by [Machin in 1706](https://en.wikipedia.org/wiki/John_Machin). # In[172]: def machin(digits): """Compute pi with Machin's formula, with precision at least digits.""" unity = 10**(digits + 10) my_pi = Decimal(4) * (Decimal(4)*arccot(5, unity) - arccot(239, unity)) return my_pi / Decimal(unity) # In[173]: getcontext().prec = 10000 # trick to improve precision my_pi = machin(100) accuracy = 100*abs(mpmath_pi - my_pi)/mpmath_pi print("Accuracy % with mpmath_pi: {:.4g}".format(accuracy)) # So we got the first $9995$ digits correctly... in $45$ seconds. # That will still be too slow to have the digits at position $130317$. # In[174]: getcontext().prec = 5000 # trick to improve precision get_ipython().run_line_magic('timeit', 'machin(50)') getcontext().prec = 10000 # trick to improve precision get_ipython().run_line_magic('timeit', 'machin(100)') # The program can be used to compute tens of thousands of digits in just a few seconds on a modern computer. # Typical implementation will be in highly efficient compiled language; like C or maybe Julia. # # Many [Machin-like formulas](https://en.wikipedia.org/wiki/Machin-like_formula) also exist, like: # $$\pi = 4\arctan\left(\frac{1}{2}\right) + 4 \arctan\left(\frac{1}{3}\right).$$ # #### Trying to solve my question! # The important parameter to tune is not the precision given to `machin()` but the `Decimal.prec` precision. # In[179]: get_ipython().run_cell_magic('time', '', 'i = 14031\ngetcontext().prec = i + 20 # trick to improve precision\nmp.dps = i + 20\nprint(str(mp.pi)[2:][i:i+10])\n\nmy_pi = machin(11)\nprint(str(my_pi)[2:][i:i+10])') # In[180]: get_ipython().run_cell_magic('time', '', 'i = 140317\ngetcontext().prec = i + 20 # trick to improve precision\nmp.dps = i + 20\nprint(str(mp.pi)[2:][i:i+10])\n\nmy_pi = machin(50)\nprint(str(my_pi)[2:][i:i+10])') # It was too slow too! But at least it worked! # # My manual implementation of Machin's formula took about $10$ minutes, on an old laptop with $1$ core running Python 3.5, to find the $10$ digits of $\pi$ at index $140317$. # # #### Conclusion # $\implies$ To the question "What are the $10$ digits of $\pi$ at index $140317..140326$", the answer is $9341076406$. # For more, see http://fredrikj.net/blog/2011/03/100-mpmath-one-liners-for-pi/. # ### (*hard*) [Unbounded Spigot Algorithm](http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf) # This algorithm is quite efficient, but not easy to explain. Go check on-line if you want. # # See this page (http://codepad.org/3yDnw0n9) for a 1-line C program that uses a simpler Spigot algorithm for computing the first 15000 digits # # A nice method, with a generator yielding the next digit each time, comes from http://stackoverflow.com/a/9005163. # It uses only integer, so no need to do any `Decimal` trick here. # In[149]: def next_pi_digit(max_step): q, r, t, k, m, x = 1, 0, 1, 1, 3, 3 for j in range(max_step): if 4 * q + r - t < m * t: yield m # More details on Python generators can be found here http://stackoverflow.com/a/231855 q, r, t, k, m, x = 10*q, 10*(r-m*t), t, k, (10*(3*q+r))//t - 10*m, x else: q, r, t, k, m, x = q*k, (2*q+r)*x, t*x, k+1, (q*(7*k+2)+r*x)//(t*x), x+2 # In[161]: def generator_pi(max_step): big_str = ''.join(str(d) for d in next_pi_digit(max_step)) return Decimal(big_str[0] + '.' + big_str[1:]) # It does not use `Decimal` numbers. # In[164]: getcontext().prec = 50 # trick to improve precision generator_pi(1000) # In[165]: getcontext().prec = 5000 # trick to improve precision generator_pi(1000) # ### (*hard*) [Borwein's algorithm](https://en.wikipedia.org/wiki/Borwein%27s_algorithm#Nonic_convergence) # It has several versions, one with a cubic convergence (each new step multiplies by $3$ the number of digits), one with a nonic convergence (of order $9$) etc. # They are not so easy to explain either. # Please check on-line, here [en.WikiPedia.org/wiki/Borwein's_algorithm](https://en.wikipedia.org/wiki/Borwein%27s_algorithm). # # The cubic method is similar to the Gauss-Legendre algorithm: # # 1. Start with $a_0 = 1/3$, and $s_0 = \frac{\sqrt{3}-1}{2}$, # 2. And then iterate, as much as you want, by defining $r_{k+1} = \frac{3}{1+2(1-s_k^3)^{1/3}}$, and updating $s_{k+1} = \frac{r_{k+1}-1}{2}$ and $a_{k+1} = r_{k+1}^2 a_k - 3^k (r_{k+1}^2 - 1)$. # # Then the numbers $a_k$ will converge to $\frac{1}{\pi}$. # ---- # ## Examples and references # ### Links # - [en.WikiPedia.org/wiki/Pi#Modern_quest_for_more_digits](https://en.wikipedia.org/wiki/Pi#Modern_quest_for_more_digits), # - [www.JoyOfPi.com/pi.html](http://www.joyofpi.com/pi.html) and [www.JoyOfPi.com/pilinks.html](http://www.joyofpi.com/pilinks.html), # - [www.EveAndersson.com/pi/digits/](http://www.eveandersson.com/pi/digits/) has great interactive tools, # - more crazy stuff [MathWorld.Wolfram.com/PiDigits.html](http://mathworld.wolfram.com/PiDigits.html), or [MathWorld.Wolfram.com/Pi.html](http://mathworld.wolfram.com/Pi.html), # - [one idea with Fibonacci numbers](http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibpi.html#section2), # - [and this incredibly long list of digits](http://piworld.calico.jp/estart.html) at [PiWorld.calico.jp/estart.html](http://piworld.calico.jp/estart.html). # - http://bellard.org/pi/ by Francois Bellard (and http://bellard.org/pi/pi_n2/pi_n2.html) # > That's it for today! Happy Pi Day! # ---- # ### Pie ! # ![](https://upload.wikimedia.org/wikipedia/commons/thumb/4/4b/Apple_pie.jpg/600px-Apple_pie.jpg) # # ----
mit
[ 199, 3, 2803, 26, 2774, 13, 24, 199, 199, 3, 327, 6957, 402, 6646, 83, 199, 3, 221, 665, 80, 2535, 3015, 1021, 628, 6972, 17, 22021, 13, 1053, 8186, 65, 4369, 13476, 4718, 13, 10542, 13, 12631, 13, 10680, 2, 666, 13, 13255, 13, 5540, 13, 344, 628, 4718, 13, 10542, 13, 12631, 13, 10680, 13, 17, 8186, 3751, 1021, 628, 13255, 13, 1053, 13, 1507, 1743, 17, 6, 10758, 15337, 10758, 12279, 3751, 30, 4718, 19835, 28358, 9708, 1108, 65, 2957, 3015, 2535, 3015, 1021, 628, 6972, 17, 22021, 13, 1053, 8186, 65, 4369, 13476, 2404, 4655, 13, 65, 13, 1653, 13, 1618, 13, 7022, 13, 1618, 13, 16827, 1038, 4, 13472, 666, 13, 13255, 13, 5540, 13, 344, 628, 2404, 4655, 13, 65, 13, 1653, 13, 1618, 13, 7022, 13, 1618, 13, 16827, 1038, 4, 31, 13, 18, 8186, 3751, 1021, 628, 13255, 13, 1053, 13, 1507, 1743, 18, 6, 10758, 15337, 10758, 12279, 3751, 30, 2404, 4655, 282, 13918, 402, 7576, 402, 665, 3751, 1021, 628, 18568, 42, 1219, 63, 27116, 2, 3449, 628, 2326, 26, 8287, 27, 10070, 3751, 2535, 3751, 1021, 628, 18568, 42, 1219, 2, 1305, 628, 18568, 42, 1219, 13, 2162, 13, 11403, 13, 3160, 2, 5174, 1080, 628, 16, 2, 3449, 628, 3124, 26, 3847, 9426, 666, 13, 27595, 28066, 3442, 9604, 19167, 5184, 27, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 23756, 15, 18568, 15, 18568, 1698, 6, 5184, 27, 2535, 2664, 18181, 5282, 27, 3, 88, 1644, 35, 16, 12279, 2664, 2957, 3442, 4335, 4719, 628, 31993, 8186, 13250, 14554, 65, 13, 5642, 628, 2052, 8186, 3751, 1021, 628, 3442, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 9014, 21, 2, 4719, 628, 3442, 2, 3449, 628, 2063, 26, 378, 14, 29422, 5633, 27, 2929, 26, 8308, 13, 1457, 27, 8186, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 3421, 26, 3847, 27, 3462, 26, 378, 14, 19264, 5633, 27, 4569, 26, 378, 5326, 27, 5023, 13, 890, 26, 19163, 5, 27, 8186, 3751, 3449, 628, 3124, 26, 3679, 27, 11353, 26, 8626, 8, 17, 14, 30308, 5633, 12, 5198, 14, 1229, 5633, 12, 499, 14, 17802, 5633, 12, 446, 5279, 5633, 2736, 2746, 26, 446, 18, 14, 24509, 5633, 27, 3602, 26, 378, 5633, 27, 8186, 3751, 1021, 628, 77, 1143, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 9014, 22, 8186, 3751, 1021, 628, 2664, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 9014, 23, 2, 3449, 628, 4246, 13, 6606, 26, 4384, 3867, 18568, 42, 1219, 63, 6756, 27, 5023, 13, 2487, 26, 652, 17999, 31328, 22955, 28, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 15784, 26, 8752, 27, 4569, 26, 413, 5326, 27, 3462, 26, 378, 14, 21683, 5633, 27, 10070, 3751, 2957, 3751, 2957, 3751, 2535, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 3462, 26, 378, 5326, 27, 4569, 26, 499, 14, 24509, 5633, 27, 10070, 3751, 2957, 3751, 2957, 3751, 2535, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 15784, 26, 8752, 27, 13763, 13, 5743, 26, 446, 16, 14, 22531, 5633, 27, 9162, 13, 3039, 26, 378, 5326, 18609, 27, 3462, 26, 378, 5326, 27, 4569, 26, 378, 14, 30604, 5633, 27, 10070, 3751, 2957, 3751, 2957, 13250, 2535, 3751, 1021, 628, 30495, 56, 63, 2822, 11734, 1912, 63, 18568, 1698, 2, 4719, 628, 31993, 8186, 3442, 9604, 628, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 23756, 15, 18568, 15, 18568, 1698, 8186, 2664, 30, 22955, 1108, 2664, 2957, 3442, 2957, 3751, 2957, 3751, 2535, 1579, 730, 628, 3442, 15, 3858, 2, 1305, 628, 18568, 42, 1219, 13, 2162, 13, 11403, 14559, 1038, 1108, 1579, 30, 31, 1108, 65, 2957, 3015, 2535, 3015, 1021, 628, 6972, 18, 22021, 13, 1053, 8186, 65, 4369, 13476, 11467, 13, 4129, 13, 2474, 13, 509, 13, 1623, 316, 13, 1589, 13, 2246, 13, 7022, 13, 1618, 13, 16827, 1038, 17351, 666, 13, 13255, 13, 5540, 13, 344, 628, 11467, 13, 4129, 13, 2474, 13, 509, 13, 1623, 316, 13, 1589, 13, 2246, 13, 7022, 13, 1618, 13, 16827, 1038, 4, 13, 2025, 8186, 3751, 1021, 628, 13255, 13, 1053, 13, 1507, 1743, 18, 14, 17, 6, 10758, 15337, 10758, 12279, 3751, 30, 11467, 3486, 3102, 367, 17196, 314, 1642, 7576, 402, 665, 3751, 1021, 628, 18568, 42, 1219, 63, 27116, 2, 3449, 628, 2326, 26, 8287, 27, 10070, 3751, 2535, 3751, 1021, 628, 18568, 42, 1219, 2, 1305, 628, 18568, 42, 1219, 13, 2162, 13, 16959, 13, 3160, 2, 5174, 1080, 628, 16, 2, 3449, 628, 3124, 26, 3847, 9426, 666, 13, 27595, 28066, 3442, 9604, 19167, 5184, 27, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 23756, 15, 18568, 15, 18568, 1698, 6, 5184, 27, 2535, 2664, 18181, 5282, 27, 3, 88, 1644, 35, 16, 12279, 2664, 2957, 3442, 4335, 4719, 628, 31993, 8186, 13250, 14554, 65, 13, 5642, 628, 2052, 8186, 3751, 1021, 628, 3442, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 1465, 1477, 2, 4719, 628, 3442, 2, 3449, 628, 2063, 26, 378, 14, 27370, 5633, 27, 2929, 26, 8308, 13, 1457, 27, 8186, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 3421, 26, 3847, 27, 3462, 26, 378, 14, 21278, 5633, 27, 4569, 26, 378, 5326, 27, 5023, 13, 890, 26, 21572, 5, 27, 8186, 3751, 3449, 628, 3124, 26, 3679, 27, 11353, 26, 8626, 8, 17, 14, 25, 2481, 5633, 12, 5198, 14, 1477, 5633, 12, 499, 14, 28249, 5633, 12, 446, 5279, 5633, 2736, 2746, 26, 446, 18, 14, 29743, 5633, 27, 3602, 26, 378, 5633, 27, 8186, 3751, 1021, 628, 77, 1143, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 1465, 1229, 8186, 3751, 1021, 628, 2664, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 1465, 1367, 2, 3449, 628, 4246, 13, 6606, 26, 4384, 3867, 18568, 42, 1219, 63, 6756, 27, 5023, 13, 2487, 26, 652, 17999, 31328, 22955, 28, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 15784, 26, 8752, 27, 4569, 26, 413, 5326, 27, 3462, 26, 378, 14, 21683, 5633, 27, 10070, 3751, 2957, 3751, 2957, 3751, 2535, 3751 ]
[ 3, 2803, 26, 2774, 13, 24, 199, 199, 3, 327, 6957, 402, 6646, 83, 199, 3, 221, 665, 80, 2535, 3015, 1021, 628, 6972, 17, 22021, 13, 1053, 8186, 65, 4369, 13476, 4718, 13, 10542, 13, 12631, 13, 10680, 2, 666, 13, 13255, 13, 5540, 13, 344, 628, 4718, 13, 10542, 13, 12631, 13, 10680, 13, 17, 8186, 3751, 1021, 628, 13255, 13, 1053, 13, 1507, 1743, 17, 6, 10758, 15337, 10758, 12279, 3751, 30, 4718, 19835, 28358, 9708, 1108, 65, 2957, 3015, 2535, 3015, 1021, 628, 6972, 17, 22021, 13, 1053, 8186, 65, 4369, 13476, 2404, 4655, 13, 65, 13, 1653, 13, 1618, 13, 7022, 13, 1618, 13, 16827, 1038, 4, 13472, 666, 13, 13255, 13, 5540, 13, 344, 628, 2404, 4655, 13, 65, 13, 1653, 13, 1618, 13, 7022, 13, 1618, 13, 16827, 1038, 4, 31, 13, 18, 8186, 3751, 1021, 628, 13255, 13, 1053, 13, 1507, 1743, 18, 6, 10758, 15337, 10758, 12279, 3751, 30, 2404, 4655, 282, 13918, 402, 7576, 402, 665, 3751, 1021, 628, 18568, 42, 1219, 63, 27116, 2, 3449, 628, 2326, 26, 8287, 27, 10070, 3751, 2535, 3751, 1021, 628, 18568, 42, 1219, 2, 1305, 628, 18568, 42, 1219, 13, 2162, 13, 11403, 13, 3160, 2, 5174, 1080, 628, 16, 2, 3449, 628, 3124, 26, 3847, 9426, 666, 13, 27595, 28066, 3442, 9604, 19167, 5184, 27, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 23756, 15, 18568, 15, 18568, 1698, 6, 5184, 27, 2535, 2664, 18181, 5282, 27, 3, 88, 1644, 35, 16, 12279, 2664, 2957, 3442, 4335, 4719, 628, 31993, 8186, 13250, 14554, 65, 13, 5642, 628, 2052, 8186, 3751, 1021, 628, 3442, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 9014, 21, 2, 4719, 628, 3442, 2, 3449, 628, 2063, 26, 378, 14, 29422, 5633, 27, 2929, 26, 8308, 13, 1457, 27, 8186, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 3421, 26, 3847, 27, 3462, 26, 378, 14, 19264, 5633, 27, 4569, 26, 378, 5326, 27, 5023, 13, 890, 26, 19163, 5, 27, 8186, 3751, 3449, 628, 3124, 26, 3679, 27, 11353, 26, 8626, 8, 17, 14, 30308, 5633, 12, 5198, 14, 1229, 5633, 12, 499, 14, 17802, 5633, 12, 446, 5279, 5633, 2736, 2746, 26, 446, 18, 14, 24509, 5633, 27, 3602, 26, 378, 5633, 27, 8186, 3751, 1021, 628, 77, 1143, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 9014, 22, 8186, 3751, 1021, 628, 2664, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 9014, 23, 2, 3449, 628, 4246, 13, 6606, 26, 4384, 3867, 18568, 42, 1219, 63, 6756, 27, 5023, 13, 2487, 26, 652, 17999, 31328, 22955, 28, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 15784, 26, 8752, 27, 4569, 26, 413, 5326, 27, 3462, 26, 378, 14, 21683, 5633, 27, 10070, 3751, 2957, 3751, 2957, 3751, 2535, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 3462, 26, 378, 5326, 27, 4569, 26, 499, 14, 24509, 5633, 27, 10070, 3751, 2957, 3751, 2957, 3751, 2535, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 15784, 26, 8752, 27, 13763, 13, 5743, 26, 446, 16, 14, 22531, 5633, 27, 9162, 13, 3039, 26, 378, 5326, 18609, 27, 3462, 26, 378, 5326, 27, 4569, 26, 378, 14, 30604, 5633, 27, 10070, 3751, 2957, 3751, 2957, 13250, 2535, 3751, 1021, 628, 30495, 56, 63, 2822, 11734, 1912, 63, 18568, 1698, 2, 4719, 628, 31993, 8186, 3442, 9604, 628, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 23756, 15, 18568, 15, 18568, 1698, 8186, 2664, 30, 22955, 1108, 2664, 2957, 3442, 2957, 3751, 2957, 3751, 2535, 1579, 730, 628, 3442, 15, 3858, 2, 1305, 628, 18568, 42, 1219, 13, 2162, 13, 11403, 14559, 1038, 1108, 1579, 30, 31, 1108, 65, 2957, 3015, 2535, 3015, 1021, 628, 6972, 18, 22021, 13, 1053, 8186, 65, 4369, 13476, 11467, 13, 4129, 13, 2474, 13, 509, 13, 1623, 316, 13, 1589, 13, 2246, 13, 7022, 13, 1618, 13, 16827, 1038, 17351, 666, 13, 13255, 13, 5540, 13, 344, 628, 11467, 13, 4129, 13, 2474, 13, 509, 13, 1623, 316, 13, 1589, 13, 2246, 13, 7022, 13, 1618, 13, 16827, 1038, 4, 13, 2025, 8186, 3751, 1021, 628, 13255, 13, 1053, 13, 1507, 1743, 18, 14, 17, 6, 10758, 15337, 10758, 12279, 3751, 30, 11467, 3486, 3102, 367, 17196, 314, 1642, 7576, 402, 665, 3751, 1021, 628, 18568, 42, 1219, 63, 27116, 2, 3449, 628, 2326, 26, 8287, 27, 10070, 3751, 2535, 3751, 1021, 628, 18568, 42, 1219, 2, 1305, 628, 18568, 42, 1219, 13, 2162, 13, 16959, 13, 3160, 2, 5174, 1080, 628, 16, 2, 3449, 628, 3124, 26, 3847, 9426, 666, 13, 27595, 28066, 3442, 9604, 19167, 5184, 27, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 23756, 15, 18568, 15, 18568, 1698, 6, 5184, 27, 2535, 2664, 18181, 5282, 27, 3, 88, 1644, 35, 16, 12279, 2664, 2957, 3442, 4335, 4719, 628, 31993, 8186, 13250, 14554, 65, 13, 5642, 628, 2052, 8186, 3751, 1021, 628, 3442, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 1465, 1477, 2, 4719, 628, 3442, 2, 3449, 628, 2063, 26, 378, 14, 27370, 5633, 27, 2929, 26, 8308, 13, 1457, 27, 8186, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 3421, 26, 3847, 27, 3462, 26, 378, 14, 21278, 5633, 27, 4569, 26, 378, 5326, 27, 5023, 13, 890, 26, 21572, 5, 27, 8186, 3751, 3449, 628, 3124, 26, 3679, 27, 11353, 26, 8626, 8, 17, 14, 25, 2481, 5633, 12, 5198, 14, 1477, 5633, 12, 499, 14, 28249, 5633, 12, 446, 5279, 5633, 2736, 2746, 26, 446, 18, 14, 29743, 5633, 27, 3602, 26, 378, 5633, 27, 8186, 3751, 1021, 628, 77, 1143, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 1465, 1229, 8186, 3751, 1021, 628, 2664, 2, 1305, 628, 18568, 42, 1219, 13, 23717, 13, 1465, 1367, 2, 3449, 628, 4246, 13, 6606, 26, 4384, 3867, 18568, 42, 1219, 63, 6756, 27, 5023, 13, 2487, 26, 652, 17999, 31328, 22955, 28, 3751, 3449, 628, 2918, 26, 8308, 13, 1457, 27, 15784, 26, 8752, 27, 4569, 26, 413, 5326, 27, 3462, 26, 378, 14, 21683, 5633, 27, 10070, 3751, 2957, 3751, 2957, 3751, 2535, 3751, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
electrolinux/pootle
tests/fixtures/models/translation_project.py
5
2021
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright (C) Pootle contributors. # # This file is a part of the Pootle project. It is distributed under the GPL3 # or later license. See the LICENSE file for a copy of the license and the # AUTHORS file for copyright and authorship information. import pytest def _require_tp(language, project): """Helper to get/create a new translation project.""" from pootle_translationproject.models import create_translation_project return create_translation_project(language, project) def _require_tp_with_obsolete_dir(language, project): """Helper to get/create a translation project in obsolete state.""" from pootle_translationproject.models import create_translation_project tp = create_translation_project(language, project) tp.directory.makeobsolete() return tp @pytest.fixture def afrikaans_tutorial(afrikaans, tutorial): """Require Afrikaans Tutorial.""" return _require_tp(afrikaans, tutorial) @pytest.fixture def arabic_tutorial_obsolete(arabic, tutorial): """Require Arabic Tutorial in obsolete state.""" return _require_tp_with_obsolete_dir(arabic, tutorial) @pytest.fixture def english_tutorial(english, tutorial): """Require English Tutorial.""" return _require_tp(english, tutorial) @pytest.fixture def french_tutorial(french, tutorial): """Require French Tutorial.""" return _require_tp(french, tutorial) @pytest.fixture def spanish_tutorial(spanish, tutorial): """Require Spanish Tutorial.""" return _require_tp(spanish, tutorial) @pytest.fixture def italian_tutorial(italian, tutorial): """Require Italian Tutorial.""" return _require_tp(italian, tutorial) @pytest.fixture def russian_tutorial(russian, tutorial): """Require Russian Tutorial.""" return _require_tp(russian, tutorial) @pytest.fixture def afrikaans_vfolder_test(afrikaans, vfolder_test): """Require Afrikaans Virtual Folder Test.""" return _require_tp(afrikaans, vfolder_test)
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 334, 35, 9, 4376, 24629, 8417, 14, 199, 3, 199, 3, 961, 570, 365, 282, 1777, 402, 314, 4376, 24629, 2199, 14, 2779, 365, 1854, 1334, 314, 14629, 19, 199, 3, 503, 2945, 4190, 14, 1666, 314, 5113, 570, 367, 282, 1331, 402, 314, 4190, 436, 314, 199, 3, 10610, 570, 367, 4248, 436, 4132, 3319, 2556, 14, 199, 199, 646, 4613, 421, 199, 318, 485, 4365, 63, 683, 8, 3671, 12, 2199, 304, 272, 408, 4433, 370, 664, 15, 981, 282, 892, 7761, 2199, 1041, 272, 687, 1115, 24629, 63, 6893, 1715, 14, 992, 492, 1218, 63, 6893, 63, 1715, 339, 372, 1218, 63, 6893, 63, 1715, 8, 3671, 12, 2199, 9, 421, 199, 318, 485, 4365, 63, 683, 63, 1045, 63, 25385, 63, 694, 8, 3671, 12, 2199, 304, 272, 408, 4433, 370, 664, 15, 981, 282, 7761, 2199, 315, 24985, 1174, 1041, 272, 687, 1115, 24629, 63, 6893, 1715, 14, 992, 492, 1218, 63, 6893, 63, 1715, 339, 9253, 275, 1218, 63, 6893, 63, 1715, 8, 3671, 12, 2199, 9, 272, 9253, 14, 3619, 14, 1875, 25385, 342, 339, 372, 9253, 421, 199, 32, 4462, 14, 5997, 199, 318, 15871, 322, 7351, 796, 63, 23561, 8, 2756, 322, 7351, 796, 12, 307, 15888, 304, 272, 408, 13902, 437, 25876, 7351, 796, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 2756, 322, 7351, 796, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 282, 24176, 63, 23561, 63, 25385, 8, 13998, 12, 307, 15888, 304, 272, 408, 13902, 437, 24176, 377, 15888, 315, 24985, 1174, 1041, 272, 372, 485, 4365, 63, 683, 63, 1045, 63, 25385, 63, 694, 8, 13998, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 20171, 1891, 63, 23561, 8, 17872, 12, 307, 15888, 304, 272, 408, 13902, 20144, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 17872, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 289, 15148, 63, 23561, 8, 20874, 12, 307, 15888, 304, 272, 408, 13902, 481, 15148, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 20874, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 13598, 2453, 63, 23561, 8, 3751, 2453, 12, 307, 15888, 304, 272, 408, 13902, 32091, 2453, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 3751, 2453, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 652, 25861, 63, 23561, 8, 6910, 5653, 12, 307, 15888, 304, 272, 408, 13902, 2779, 25861, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 6910, 5653, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 519, 8630, 63, 23561, 8, 82, 8630, 12, 307, 15888, 304, 272, 408, 13902, 820, 8630, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 82, 8630, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 15871, 322, 7351, 796, 63, 86, 3741, 63, 396, 8, 2756, 322, 7351, 796, 12, 373, 3741, 63, 396, 304, 272, 408, 13902, 437, 25876, 7351, 796, 13311, 29121, 1379, 1041, 272, 372, 485, 4365, 63, 683, 8, 2756, 322, 7351, 796, 12, 373, 3741, 63, 396, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 334, 35, 9, 4376, 24629, 8417, 14, 199, 3, 199, 3, 961, 570, 365, 282, 1777, 402, 314, 4376, 24629, 2199, 14, 2779, 365, 1854, 1334, 314, 14629, 19, 199, 3, 503, 2945, 4190, 14, 1666, 314, 5113, 570, 367, 282, 1331, 402, 314, 4190, 436, 314, 199, 3, 10610, 570, 367, 4248, 436, 4132, 3319, 2556, 14, 199, 199, 646, 4613, 421, 199, 318, 485, 4365, 63, 683, 8, 3671, 12, 2199, 304, 272, 408, 4433, 370, 664, 15, 981, 282, 892, 7761, 2199, 1041, 272, 687, 1115, 24629, 63, 6893, 1715, 14, 992, 492, 1218, 63, 6893, 63, 1715, 339, 372, 1218, 63, 6893, 63, 1715, 8, 3671, 12, 2199, 9, 421, 199, 318, 485, 4365, 63, 683, 63, 1045, 63, 25385, 63, 694, 8, 3671, 12, 2199, 304, 272, 408, 4433, 370, 664, 15, 981, 282, 7761, 2199, 315, 24985, 1174, 1041, 272, 687, 1115, 24629, 63, 6893, 1715, 14, 992, 492, 1218, 63, 6893, 63, 1715, 339, 9253, 275, 1218, 63, 6893, 63, 1715, 8, 3671, 12, 2199, 9, 272, 9253, 14, 3619, 14, 1875, 25385, 342, 339, 372, 9253, 421, 199, 32, 4462, 14, 5997, 199, 318, 15871, 322, 7351, 796, 63, 23561, 8, 2756, 322, 7351, 796, 12, 307, 15888, 304, 272, 408, 13902, 437, 25876, 7351, 796, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 2756, 322, 7351, 796, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 282, 24176, 63, 23561, 63, 25385, 8, 13998, 12, 307, 15888, 304, 272, 408, 13902, 437, 24176, 377, 15888, 315, 24985, 1174, 1041, 272, 372, 485, 4365, 63, 683, 63, 1045, 63, 25385, 63, 694, 8, 13998, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 20171, 1891, 63, 23561, 8, 17872, 12, 307, 15888, 304, 272, 408, 13902, 20144, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 17872, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 289, 15148, 63, 23561, 8, 20874, 12, 307, 15888, 304, 272, 408, 13902, 481, 15148, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 20874, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 13598, 2453, 63, 23561, 8, 3751, 2453, 12, 307, 15888, 304, 272, 408, 13902, 32091, 2453, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 3751, 2453, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 652, 25861, 63, 23561, 8, 6910, 5653, 12, 307, 15888, 304, 272, 408, 13902, 2779, 25861, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 6910, 5653, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 519, 8630, 63, 23561, 8, 82, 8630, 12, 307, 15888, 304, 272, 408, 13902, 820, 8630, 377, 15888, 1041, 272, 372, 485, 4365, 63, 683, 8, 82, 8630, 12, 307, 15888, 9, 421, 199, 32, 4462, 14, 5997, 199, 318, 15871, 322, 7351, 796, 63, 86, 3741, 63, 396, 8, 2756, 322, 7351, 796, 12, 373, 3741, 63, 396, 304, 272, 408, 13902, 437, 25876, 7351, 796, 13311, 29121, 1379, 1041, 272, 372, 485, 4365, 63, 683, 8, 2756, 322, 7351, 796, 12, 373, 3741, 63, 396, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
vybstat/scikit-learn
examples/linear_model/plot_ard.py
248
2622
""" ================================================== Automatic Relevance Determination Regression (ARD) ================================================== Fit regression model with Bayesian Ridge Regression. See :ref:`bayesian_ridge_regression` for more information on the regressor. Compared to the OLS (ordinary least squares) estimator, the coefficient weights are slightly shifted toward zeros, which stabilises them. The histogram of the estimated weights is very peaked, as a sparsity-inducing prior is implied on the weights. The estimation of the model is done by iteratively maximizing the marginal log-likelihood of the observations. """ print(__doc__) import numpy as np import matplotlib.pyplot as plt from scipy import stats from sklearn.linear_model import ARDRegression, LinearRegression ############################################################################### # Generating simulated data with Gaussian weights # Parameters of the example np.random.seed(0) n_samples, n_features = 100, 100 # Create Gaussian data X = np.random.randn(n_samples, n_features) # Create weigts with a precision lambda_ of 4. lambda_ = 4. w = np.zeros(n_features) # Only keep 10 weights of interest relevant_features = np.random.randint(0, n_features, 10) for i in relevant_features: w[i] = stats.norm.rvs(loc=0, scale=1. / np.sqrt(lambda_)) # Create noite with a precision alpha of 50. alpha_ = 50. noise = stats.norm.rvs(loc=0, scale=1. / np.sqrt(alpha_), size=n_samples) # Create the target y = np.dot(X, w) + noise ############################################################################### # Fit the ARD Regression clf = ARDRegression(compute_score=True) clf.fit(X, y) ols = LinearRegression() ols.fit(X, y) ############################################################################### # Plot the true weights, the estimated weights and the histogram of the # weights plt.figure(figsize=(6, 5)) plt.title("Weights of the model") plt.plot(clf.coef_, 'b-', label="ARD estimate") plt.plot(ols.coef_, 'r--', label="OLS estimate") plt.plot(w, 'g-', label="Ground truth") plt.xlabel("Features") plt.ylabel("Values of the weights") plt.legend(loc=1) plt.figure(figsize=(6, 5)) plt.title("Histogram of the weights") plt.hist(clf.coef_, bins=n_features, log=True) plt.plot(clf.coef_[relevant_features], 5 * np.ones(len(relevant_features)), 'ro', label="Relevant features") plt.ylabel("Features") plt.xlabel("Values of the weights") plt.legend(loc=1) plt.figure(figsize=(6, 5)) plt.title("Marginal log-likelihood") plt.plot(clf.scores_) plt.ylabel("Score") plt.xlabel("Iterations") plt.show()
bsd-3-clause
[ 624, 199, 12813, 389, 199, 3358, 3889, 799, 28791, 1487, 20667, 13262, 334, 7816, 9, 199, 12813, 389, 199, 199, 13776, 10864, 1402, 543, 29434, 69, 6214, 31196, 13262, 14, 199, 199, 9295, 520, 1121, 1705, 19558, 69, 6214, 63, 5562, 63, 12513, 64, 367, 1655, 2556, 641, 314, 1295, 11686, 14, 199, 199, 2404, 2899, 370, 314, 593, 5296, 334, 4055, 695, 5210, 26170, 9, 8943, 12, 314, 9421, 199, 4916, 787, 18023, 31915, 370, 3079, 10136, 12, 1314, 410, 25007, 874, 3062, 14, 199, 199, 1918, 15379, 402, 314, 20077, 4931, 365, 7437, 4837, 16702, 12, 465, 282, 28668, 3677, 13, 688, 947, 316, 199, 13775, 365, 2478, 641, 314, 4931, 14, 199, 199, 1918, 27156, 402, 314, 1402, 365, 4224, 701, 4826, 9462, 1390, 1017, 9147, 314, 199, 9650, 279, 943, 13, 20704, 402, 314, 19739, 14, 199, 624, 199, 1361, 3460, 1301, 3368, 199, 199, 646, 2680, 465, 980, 199, 646, 8027, 14, 13563, 465, 4488, 199, 504, 7026, 492, 5020, 199, 199, 504, 6357, 14, 6676, 63, 1238, 492, 4160, 36, 13013, 12, 12489, 13013, 199, 199, 11490, 199, 3, 1464, 1958, 4389, 8097, 666, 543, 17131, 4931, 199, 199, 3, 3897, 402, 314, 2893, 199, 1590, 14, 2355, 14, 5176, 8, 16, 9, 199, 78, 63, 3356, 12, 302, 63, 3179, 275, 2948, 12, 2948, 199, 3, 2790, 17131, 666, 199, 56, 275, 980, 14, 2355, 14, 10843, 8, 78, 63, 3356, 12, 302, 63, 3179, 9, 199, 3, 2790, 781, 528, 1086, 543, 282, 7151, 2400, 63, 402, 841, 14, 199, 2734, 63, 275, 841, 14, 199, 87, 275, 980, 14, 4250, 8, 78, 63, 3179, 9, 199, 3, 5972, 4215, 1616, 4931, 402, 13518, 199, 21906, 63, 3179, 275, 980, 14, 2355, 14, 8393, 8, 16, 12, 302, 63, 3179, 12, 1616, 9, 199, 509, 284, 315, 12082, 63, 3179, 26, 272, 336, 59, 73, 61, 275, 5020, 14, 4791, 14, 23322, 8, 2102, 29, 16, 12, 4666, 29, 17, 14, 1182, 980, 14, 5079, 8, 2734, 13309, 199, 3, 2790, 949, 1175, 543, 282, 7151, 5131, 402, 5238, 14, 199, 4468, 63, 275, 5238, 14, 199, 11838, 275, 5020, 14, 4791, 14, 23322, 8, 2102, 29, 16, 12, 4666, 29, 17, 14, 1182, 980, 14, 5079, 8, 4468, 29425, 1568, 29, 78, 63, 3356, 9, 199, 3, 2790, 314, 1347, 199, 89, 275, 980, 14, 3287, 8, 56, 12, 336, 9, 435, 11145, 199, 199, 11490, 199, 3, 25971, 314, 4160, 36, 13262, 199, 9694, 275, 4160, 36, 13013, 8, 3357, 63, 3397, 29, 549, 9, 199, 9694, 14, 3269, 8, 56, 12, 612, 9, 199, 199, 1446, 275, 12489, 13013, 342, 199, 1446, 14, 3269, 8, 56, 12, 612, 9, 199, 199, 11490, 199, 3, 14794, 314, 2549, 4931, 12, 314, 20077, 4931, 436, 314, 15379, 402, 314, 199, 3, 4931, 199, 6003, 14, 8941, 8, 23899, 2687, 22, 12, 959, 430, 199, 6003, 14, 1213, 480, 23885, 402, 314, 1402, 531, 199, 6003, 14, 2798, 8, 9694, 14, 8009, 3131, 283, 66, 14382, 1768, 628, 7816, 14497, 531, 199, 6003, 14, 2798, 8, 1446, 14, 8009, 3131, 283, 82, 306, 297, 1768, 628, 2228, 51, 14497, 531, 199, 6003, 14, 2798, 8, 87, 12, 283, 71, 14382, 1768, 628, 39, 2363, 16865, 531, 199, 6003, 14, 14168, 480, 10807, 531, 199, 6003, 14, 13849, 480, 6550, 402, 314, 4931, 531, 199, 6003, 14, 10231, 8, 2102, 29, 17, 9, 199, 199, 6003, 14, 8941, 8, 23899, 2687, 22, 12, 959, 430, 199, 6003, 14, 1213, 480, 25055, 402, 314, 4931, 531, 199, 6003, 14, 11141, 8, 9694, 14, 8009, 3131, 13341, 29, 78, 63, 3179, 12, 943, 29, 549, 9, 199, 6003, 14, 2798, 8, 9694, 14, 8009, 9925, 21906, 63, 3179, 467, 959, 627, 980, 14, 4548, 8, 552, 8, 21906, 63, 3179, 1826, 268, 283, 293, 297, 1768, 628, 497, 9723, 4534, 531, 199, 6003, 14, 13849, 480, 10807, 531, 199, 6003, 14, 14168, 480, 6550, 402, 314, 4931, 531, 199, 6003, 14, 10231, 8, 2102, 29, 17, 9, 199, 199, 6003, 14, 8941, 8, 23899, 2687, 22, 12, 959, 430, 199, 6003, 14, 1213, 480, 15182, 279, 943, 13, 20704, 531, 199, 6003, 14, 2798, 8, 9694, 14, 7107, 4602, 199, 6003, 14, 13849, 480, 12642, 531, 199, 6003, 14, 14168, 480, 26292, 531, 199, 6003, 14, 2384, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 12813, 389, 199, 3358, 3889, 799, 28791, 1487, 20667, 13262, 334, 7816, 9, 199, 12813, 389, 199, 199, 13776, 10864, 1402, 543, 29434, 69, 6214, 31196, 13262, 14, 199, 199, 9295, 520, 1121, 1705, 19558, 69, 6214, 63, 5562, 63, 12513, 64, 367, 1655, 2556, 641, 314, 1295, 11686, 14, 199, 199, 2404, 2899, 370, 314, 593, 5296, 334, 4055, 695, 5210, 26170, 9, 8943, 12, 314, 9421, 199, 4916, 787, 18023, 31915, 370, 3079, 10136, 12, 1314, 410, 25007, 874, 3062, 14, 199, 199, 1918, 15379, 402, 314, 20077, 4931, 365, 7437, 4837, 16702, 12, 465, 282, 28668, 3677, 13, 688, 947, 316, 199, 13775, 365, 2478, 641, 314, 4931, 14, 199, 199, 1918, 27156, 402, 314, 1402, 365, 4224, 701, 4826, 9462, 1390, 1017, 9147, 314, 199, 9650, 279, 943, 13, 20704, 402, 314, 19739, 14, 199, 624, 199, 1361, 3460, 1301, 3368, 199, 199, 646, 2680, 465, 980, 199, 646, 8027, 14, 13563, 465, 4488, 199, 504, 7026, 492, 5020, 199, 199, 504, 6357, 14, 6676, 63, 1238, 492, 4160, 36, 13013, 12, 12489, 13013, 199, 199, 11490, 199, 3, 1464, 1958, 4389, 8097, 666, 543, 17131, 4931, 199, 199, 3, 3897, 402, 314, 2893, 199, 1590, 14, 2355, 14, 5176, 8, 16, 9, 199, 78, 63, 3356, 12, 302, 63, 3179, 275, 2948, 12, 2948, 199, 3, 2790, 17131, 666, 199, 56, 275, 980, 14, 2355, 14, 10843, 8, 78, 63, 3356, 12, 302, 63, 3179, 9, 199, 3, 2790, 781, 528, 1086, 543, 282, 7151, 2400, 63, 402, 841, 14, 199, 2734, 63, 275, 841, 14, 199, 87, 275, 980, 14, 4250, 8, 78, 63, 3179, 9, 199, 3, 5972, 4215, 1616, 4931, 402, 13518, 199, 21906, 63, 3179, 275, 980, 14, 2355, 14, 8393, 8, 16, 12, 302, 63, 3179, 12, 1616, 9, 199, 509, 284, 315, 12082, 63, 3179, 26, 272, 336, 59, 73, 61, 275, 5020, 14, 4791, 14, 23322, 8, 2102, 29, 16, 12, 4666, 29, 17, 14, 1182, 980, 14, 5079, 8, 2734, 13309, 199, 3, 2790, 949, 1175, 543, 282, 7151, 5131, 402, 5238, 14, 199, 4468, 63, 275, 5238, 14, 199, 11838, 275, 5020, 14, 4791, 14, 23322, 8, 2102, 29, 16, 12, 4666, 29, 17, 14, 1182, 980, 14, 5079, 8, 4468, 29425, 1568, 29, 78, 63, 3356, 9, 199, 3, 2790, 314, 1347, 199, 89, 275, 980, 14, 3287, 8, 56, 12, 336, 9, 435, 11145, 199, 199, 11490, 199, 3, 25971, 314, 4160, 36, 13262, 199, 9694, 275, 4160, 36, 13013, 8, 3357, 63, 3397, 29, 549, 9, 199, 9694, 14, 3269, 8, 56, 12, 612, 9, 199, 199, 1446, 275, 12489, 13013, 342, 199, 1446, 14, 3269, 8, 56, 12, 612, 9, 199, 199, 11490, 199, 3, 14794, 314, 2549, 4931, 12, 314, 20077, 4931, 436, 314, 15379, 402, 314, 199, 3, 4931, 199, 6003, 14, 8941, 8, 23899, 2687, 22, 12, 959, 430, 199, 6003, 14, 1213, 480, 23885, 402, 314, 1402, 531, 199, 6003, 14, 2798, 8, 9694, 14, 8009, 3131, 283, 66, 14382, 1768, 628, 7816, 14497, 531, 199, 6003, 14, 2798, 8, 1446, 14, 8009, 3131, 283, 82, 306, 297, 1768, 628, 2228, 51, 14497, 531, 199, 6003, 14, 2798, 8, 87, 12, 283, 71, 14382, 1768, 628, 39, 2363, 16865, 531, 199, 6003, 14, 14168, 480, 10807, 531, 199, 6003, 14, 13849, 480, 6550, 402, 314, 4931, 531, 199, 6003, 14, 10231, 8, 2102, 29, 17, 9, 199, 199, 6003, 14, 8941, 8, 23899, 2687, 22, 12, 959, 430, 199, 6003, 14, 1213, 480, 25055, 402, 314, 4931, 531, 199, 6003, 14, 11141, 8, 9694, 14, 8009, 3131, 13341, 29, 78, 63, 3179, 12, 943, 29, 549, 9, 199, 6003, 14, 2798, 8, 9694, 14, 8009, 9925, 21906, 63, 3179, 467, 959, 627, 980, 14, 4548, 8, 552, 8, 21906, 63, 3179, 1826, 268, 283, 293, 297, 1768, 628, 497, 9723, 4534, 531, 199, 6003, 14, 13849, 480, 10807, 531, 199, 6003, 14, 14168, 480, 6550, 402, 314, 4931, 531, 199, 6003, 14, 10231, 8, 2102, 29, 17, 9, 199, 199, 6003, 14, 8941, 8, 23899, 2687, 22, 12, 959, 430, 199, 6003, 14, 1213, 480, 15182, 279, 943, 13, 20704, 531, 199, 6003, 14, 2798, 8, 9694, 14, 7107, 4602, 199, 6003, 14, 13849, 480, 12642, 531, 199, 6003, 14, 14168, 480, 26292, 531, 199, 6003, 14, 2384, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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Created by Sagar Uprety at Bengaluru, India on May 14th, 2016. # This is a simple stopwatch utility implemented as shell. Can be used in absence of a smartphone/smartwatch. # Run this file using the python command and then see the list of commands to proceed. # Any comments/suggestions/feedback is welcomed at sagaruprety@gmail.com import datetime import time from config import conf_exit_message from config import conf_welcome_message from config import conf_help_message class stopwatch(): # Function to display information regarding current lap. def display(self, lap_no, time_elapsed): print('Lap '+str(lap_no)); print(time_elapsed); # Function to give a list of commands in case one forgets the exact command name. def helpme(self): print(conf_help_message); # Function which does the actual time computation and stopwatch implementation. def timer(self): user_input = 'start'; # Shell input default. lap_no = 0; # Lap number before start. format = '%H:%M:%S'; # format followed for displaying time. t_prev = time.time(); # default time starts with the start of the app. while (user_input != 'stop'): # Loop until stop command is entered. user_input = raw_input('>>> '); # Shell input from user. if (user_input == 'start'): # Start the stopwatch. lap_no = lap_no + 1; t_prev = time.time(); self.display(lap_no, '00:00:00'); elif (user_input == 'lap'): # Lap signalled. lap_no = lap_no + 1; t_lap = time.time(); t_diff = t_lap - t_prev; time_elapsed = datetime.timedelta(seconds = t_diff); # Gives the time elaspsed between two laps. self.display(lap_no, time_elapsed); t_prev = t_lap; # to compute the time elapsed between current lap and the next. elif (user_input == 'help'): # Help availed. self.helpme(); # Call help function in case user types a wrong command name. elif (user_input == 'stop'): # Quitting the stopwatch. t_lap = time.time(); t_diff = t_lap - t_prev; time_elapsed = datetime.timedelta(seconds = t_diff); # Gives the time elaspsed between two laps. self.display(time_elapsed, conf_exit_message); elif (user_input == 'license'): # Displaying the license agreement. f = open('LICENSE', 'r'); for line in f.readlines(): print line; f.close(); else: # Incorrect command typed. print('Command not found. Type help to get the list of valid commands.'); def main(): print(conf_welcome_message); s = stopwatch(); s.helpme(); s.timer(); if __name__ == '__main__': main()
mit
[ 3168, 2647, 15, 1393, 15, 1548, 199, 3, 18208, 701, 428, 643, 285, 738, 657, 369, 737, 699, 7420, 279, 300, 85, 12, 1010, 2391, 641, 10162, 4329, 273, 12, 7800, 14, 199, 3, 961, 365, 282, 3486, 3631, 6821, 11420, 6366, 465, 5218, 14, 6855, 506, 1202, 315, 2236, 14073, 402, 282, 11179, 9339, 15, 7853, 6821, 14, 221, 199, 3, 3378, 642, 570, 1808, 314, 2366, 1414, 436, 2066, 1937, 314, 769, 402, 3718, 370, 20320, 14, 199, 3, 6184, 6786, 15, 19957, 15293, 15, 13485, 365, 336, 352, 331, 3594, 737, 308, 643, 285, 384, 264, 369, 32, 6799, 14, 957, 199, 199, 646, 2197, 199, 646, 900, 199, 504, 1101, 492, 3743, 63, 2224, 63, 1188, 199, 504, 1101, 492, 3743, 63, 28508, 63, 1188, 199, 504, 1101, 492, 3743, 63, 3437, 63, 1188, 199, 199, 533, 3631, 6821, 837, 199, 198, 3, 6801, 370, 2929, 2556, 12602, 1453, 28938, 14, 199, 198, 318, 2929, 8, 277, 12, 28938, 63, 889, 12, 900, 63, 16691, 304, 507, 198, 1361, 360, 44, 439, 6681, 495, 8, 4762, 63, 889, 16674, 507, 198, 1361, 8, 521, 63, 16691, 2736, 421, 198, 3, 6801, 370, 8120, 282, 769, 402, 3718, 315, 1930, 1373, 19459, 83, 314, 5835, 1414, 536, 14, 199, 198, 318, 1720, 278, 8, 277, 304, 507, 198, 1361, 8, 2190, 63, 3437, 63, 1188, 2736, 421, 198, 3, 6801, 1314, 1630, 314, 3503, 900, 14009, 436, 3631, 6821, 4514, 14, 199, 198, 318, 9715, 8, 277, 304, 507, 198, 751, 63, 1210, 221, 275, 283, 928, 13619, 221, 7542, 327, 24599, 1324, 849, 14, 2742, 198, 4762, 63, 889, 221, 275, 378, 27, 755, 198, 259, 7542, 327, 491, 439, 1329, 2544, 1343, 14, 507, 198, 908, 221, 275, 1543, 40, 2689, 45, 2689, 51, 13619, 257, 7542, 327, 1475, 9437, 367, 20589, 900, 14, 507, 198, 84, 63, 5701, 221, 275, 900, 14, 521, 7303, 221, 7542, 327, 849, 900, 9174, 543, 314, 1343, 402, 314, 1145, 14, 2742, 198, 6710, 334, 751, 63, 1210, 1137, 283, 2379, 735, 257, 198, 258, 327, 18175, 5133, 3631, 1414, 365, 19138, 14, 686, 198, 751, 63, 1210, 221, 275, 3066, 63, 1210, 360, 6071, 283, 2736, 327, 24599, 1324, 687, 922, 14, 686, 198, 692, 334, 751, 63, 1210, 508, 283, 928, 735, 420, 327, 7707, 314, 3631, 6821, 14, 1585, 198, 4762, 63, 889, 221, 275, 28938, 63, 889, 435, 413, 27, 1585, 198, 84, 63, 5701, 221, 275, 900, 14, 521, 7303, 1585, 198, 277, 14, 2918, 8, 4762, 63, 889, 12, 283, 383, 26, 383, 26, 383, 11339, 221, 6319, 198, 4164, 334, 751, 63, 1210, 508, 283, 4762, 735, 22427, 327, 491, 439, 2070, 1843, 14, 1585, 198, 4762, 63, 889, 221, 275, 28938, 63, 889, 435, 413, 27, 1585, 198, 84, 63, 4762, 257, 275, 900, 14, 521, 7303, 1585, 198, 84, 63, 3028, 221, 275, 307, 63, 4762, 446, 307, 63, 5701, 27, 1585, 198, 521, 63, 16691, 275, 2197, 14, 7473, 8, 4515, 275, 307, 63, 3028, 2736, 327, 598, 7602, 314, 900, 579, 20222, 939, 3382, 2877, 1127, 1190, 14, 1585, 198, 277, 14, 2918, 8, 4762, 63, 889, 12, 900, 63, 16691, 2736, 1585, 198, 84, 63, 5701, 221, 275, 307, 63, 4762, 27, 221, 9622, 327, 370, 4526, 314, 900, 14439, 3382, 1453, 28938, 436, 314, 2163, 14, 6319, 198, 4164, 334, 751, 63, 1210, 508, 283, 3437, 735, 22427, 327, 15456, 2289, 65, 1672, 14, 198, 1585, 198, 277, 14, 3437, 278, 7303, 257, 1057, 22427, 327, 6523, 1720, 805, 315, 1930, 922, 2943, 282, 6835, 1414, 536, 14, 6319, 198, 4164, 334, 751, 63, 1210, 508, 283, 2379, 735, 22427, 327, 1413, 4993, 1337, 314, 3631, 6821, 14, 1585, 198, 84, 63, 4762, 257, 275, 900, 14, 521, 7303, 1585, 198, 84, 63, 3028, 221, 275, 307, 63, 4762, 446, 307, 63, 5701, 27, 1585, 198, 521, 63, 16691, 275, 2197, 14, 7473, 8, 4515, 275, 307, 63, 3028, 2736, 327, 598, 7602, 314, 900, 579, 20222, 939, 3382, 2877, 1127, 1190, 14, 1585, 198, 277, 14, 2918, 8, 521, 63, 16691, 12, 3743, 63, 2224, 63, 1188, 2736, 6319, 198, 4164, 334, 751, 63, 1210, 508, 283, 1682, 735, 221, 327, 12175, 316, 314, 4190, 25025, 14, 1585, 198, 70, 275, 1551, 360, 3961, 297, 283, 82, 11339, 1585, 198, 509, 1004, 315, 289, 14, 9684, 837, 1871, 198, 1361, 1004, 27, 1585, 198, 70, 14, 1600, 7303, 6319, 198, 2836, 26, 221, 7542, 9622, 327, 1010, 4525, 1414, 20041, 14, 1585, 198, 1361, 360, 3110, 440, 1911, 14, 2434, 1720, 370, 664, 314, 769, 402, 1686, 3718, 2659, 27, 6319, 199, 199, 318, 2446, 837, 199, 198, 1361, 8, 2190, 63, 28508, 63, 1188, 2736, 199, 198, 83, 275, 3631, 6821, 7303, 199, 198, 83, 14, 3437, 278, 7303, 199, 198, 83, 14, 7414, 7303, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 199, 198, 973, 342, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 18208, 701, 428, 643, 285, 738, 657, 369, 737, 699, 7420, 279, 300, 85, 12, 1010, 2391, 641, 10162, 4329, 273, 12, 7800, 14, 199, 3, 961, 365, 282, 3486, 3631, 6821, 11420, 6366, 465, 5218, 14, 6855, 506, 1202, 315, 2236, 14073, 402, 282, 11179, 9339, 15, 7853, 6821, 14, 221, 199, 3, 3378, 642, 570, 1808, 314, 2366, 1414, 436, 2066, 1937, 314, 769, 402, 3718, 370, 20320, 14, 199, 3, 6184, 6786, 15, 19957, 15293, 15, 13485, 365, 336, 352, 331, 3594, 737, 308, 643, 285, 384, 264, 369, 32, 6799, 14, 957, 199, 199, 646, 2197, 199, 646, 900, 199, 504, 1101, 492, 3743, 63, 2224, 63, 1188, 199, 504, 1101, 492, 3743, 63, 28508, 63, 1188, 199, 504, 1101, 492, 3743, 63, 3437, 63, 1188, 199, 199, 533, 3631, 6821, 837, 199, 198, 3, 6801, 370, 2929, 2556, 12602, 1453, 28938, 14, 199, 198, 318, 2929, 8, 277, 12, 28938, 63, 889, 12, 900, 63, 16691, 304, 507, 198, 1361, 360, 44, 439, 6681, 495, 8, 4762, 63, 889, 16674, 507, 198, 1361, 8, 521, 63, 16691, 2736, 421, 198, 3, 6801, 370, 8120, 282, 769, 402, 3718, 315, 1930, 1373, 19459, 83, 314, 5835, 1414, 536, 14, 199, 198, 318, 1720, 278, 8, 277, 304, 507, 198, 1361, 8, 2190, 63, 3437, 63, 1188, 2736, 421, 198, 3, 6801, 1314, 1630, 314, 3503, 900, 14009, 436, 3631, 6821, 4514, 14, 199, 198, 318, 9715, 8, 277, 304, 507, 198, 751, 63, 1210, 221, 275, 283, 928, 13619, 221, 7542, 327, 24599, 1324, 849, 14, 2742, 198, 4762, 63, 889, 221, 275, 378, 27, 755, 198, 259, 7542, 327, 491, 439, 1329, 2544, 1343, 14, 507, 198, 908, 221, 275, 1543, 40, 2689, 45, 2689, 51, 13619, 257, 7542, 327, 1475, 9437, 367, 20589, 900, 14, 507, 198, 84, 63, 5701, 221, 275, 900, 14, 521, 7303, 221, 7542, 327, 849, 900, 9174, 543, 314, 1343, 402, 314, 1145, 14, 2742, 198, 6710, 334, 751, 63, 1210, 1137, 283, 2379, 735, 257, 198, 258, 327, 18175, 5133, 3631, 1414, 365, 19138, 14, 686, 198, 751, 63, 1210, 221, 275, 3066, 63, 1210, 360, 6071, 283, 2736, 327, 24599, 1324, 687, 922, 14, 686, 198, 692, 334, 751, 63, 1210, 508, 283, 928, 735, 420, 327, 7707, 314, 3631, 6821, 14, 1585, 198, 4762, 63, 889, 221, 275, 28938, 63, 889, 435, 413, 27, 1585, 198, 84, 63, 5701, 221, 275, 900, 14, 521, 7303, 1585, 198, 277, 14, 2918, 8, 4762, 63, 889, 12, 283, 383, 26, 383, 26, 383, 11339, 221, 6319, 198, 4164, 334, 751, 63, 1210, 508, 283, 4762, 735, 22427, 327, 491, 439, 2070, 1843, 14, 1585, 198, 4762, 63, 889, 221, 275, 28938, 63, 889, 435, 413, 27, 1585, 198, 84, 63, 4762, 257, 275, 900, 14, 521, 7303, 1585, 198, 84, 63, 3028, 221, 275, 307, 63, 4762, 446, 307, 63, 5701, 27, 1585, 198, 521, 63, 16691, 275, 2197, 14, 7473, 8, 4515, 275, 307, 63, 3028, 2736, 327, 598, 7602, 314, 900, 579, 20222, 939, 3382, 2877, 1127, 1190, 14, 1585, 198, 277, 14, 2918, 8, 4762, 63, 889, 12, 900, 63, 16691, 2736, 1585, 198, 84, 63, 5701, 221, 275, 307, 63, 4762, 27, 221, 9622, 327, 370, 4526, 314, 900, 14439, 3382, 1453, 28938, 436, 314, 2163, 14, 6319, 198, 4164, 334, 751, 63, 1210, 508, 283, 3437, 735, 22427, 327, 15456, 2289, 65, 1672, 14, 198, 1585, 198, 277, 14, 3437, 278, 7303, 257, 1057, 22427, 327, 6523, 1720, 805, 315, 1930, 922, 2943, 282, 6835, 1414, 536, 14, 6319, 198, 4164, 334, 751, 63, 1210, 508, 283, 2379, 735, 22427, 327, 1413, 4993, 1337, 314, 3631, 6821, 14, 1585, 198, 84, 63, 4762, 257, 275, 900, 14, 521, 7303, 1585, 198, 84, 63, 3028, 221, 275, 307, 63, 4762, 446, 307, 63, 5701, 27, 1585, 198, 521, 63, 16691, 275, 2197, 14, 7473, 8, 4515, 275, 307, 63, 3028, 2736, 327, 598, 7602, 314, 900, 579, 20222, 939, 3382, 2877, 1127, 1190, 14, 1585, 198, 277, 14, 2918, 8, 521, 63, 16691, 12, 3743, 63, 2224, 63, 1188, 2736, 6319, 198, 4164, 334, 751, 63, 1210, 508, 283, 1682, 735, 221, 327, 12175, 316, 314, 4190, 25025, 14, 1585, 198, 70, 275, 1551, 360, 3961, 297, 283, 82, 11339, 1585, 198, 509, 1004, 315, 289, 14, 9684, 837, 1871, 198, 1361, 1004, 27, 1585, 198, 70, 14, 1600, 7303, 6319, 198, 2836, 26, 221, 7542, 9622, 327, 1010, 4525, 1414, 20041, 14, 1585, 198, 1361, 360, 3110, 440, 1911, 14, 2434, 1720, 370, 664, 314, 769, 402, 1686, 3718, 2659, 27, 6319, 199, 199, 318, 2446, 837, 199, 198, 1361, 8, 2190, 63, 28508, 63, 1188, 2736, 199, 198, 83, 275, 3631, 6821, 7303, 199, 198, 83, 14, 3437, 278, 7303, 199, 198, 83, 14, 7414, 7303, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 199, 198, 973, 342, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
figment/falloutsnip
Vendor/IronPython/Lib/distutils/text_file.py
204
12410
"""text_file provides the TextFile class, which gives an interface to text files that (optionally) takes care of stripping comments, ignoring blank lines, and joining lines with backslashes.""" __revision__ = "$Id$" import sys class TextFile: """Provides a file-like object that takes care of all the things you commonly want to do when processing a text file that has some line-by-line syntax: strip comments (as long as "#" is your comment character), skip blank lines, join adjacent lines by escaping the newline (ie. backslash at end of line), strip leading and/or trailing whitespace. All of these are optional and independently controllable. Provides a 'warn()' method so you can generate warning messages that report physical line number, even if the logical line in question spans multiple physical lines. Also provides 'unreadline()' for implementing line-at-a-time lookahead. Constructor is called as: TextFile (filename=None, file=None, **options) It bombs (RuntimeError) if both 'filename' and 'file' are None; 'filename' should be a string, and 'file' a file object (or something that provides 'readline()' and 'close()' methods). It is recommended that you supply at least 'filename', so that TextFile can include it in warning messages. If 'file' is not supplied, TextFile creates its own using the 'open()' builtin. The options are all boolean, and affect the value returned by 'readline()': strip_comments [default: true] strip from "#" to end-of-line, as well as any whitespace leading up to the "#" -- unless it is escaped by a backslash lstrip_ws [default: false] strip leading whitespace from each line before returning it rstrip_ws [default: true] strip trailing whitespace (including line terminator!) from each line before returning it skip_blanks [default: true} skip lines that are empty *after* stripping comments and whitespace. (If both lstrip_ws and rstrip_ws are false, then some lines may consist of solely whitespace: these will *not* be skipped, even if 'skip_blanks' is true.) join_lines [default: false] if a backslash is the last non-newline character on a line after stripping comments and whitespace, join the following line to it to form one "logical line"; if N consecutive lines end with a backslash, then N+1 physical lines will be joined to form one logical line. collapse_join [default: false] strip leading whitespace from lines that are joined to their predecessor; only matters if (join_lines and not lstrip_ws) Note that since 'rstrip_ws' can strip the trailing newline, the semantics of 'readline()' must differ from those of the builtin file object's 'readline()' method! In particular, 'readline()' returns None for end-of-file: an empty string might just be a blank line (or an all-whitespace line), if 'rstrip_ws' is true but 'skip_blanks' is not.""" default_options = { 'strip_comments': 1, 'skip_blanks': 1, 'lstrip_ws': 0, 'rstrip_ws': 1, 'join_lines': 0, 'collapse_join': 0, } def __init__ (self, filename=None, file=None, **options): """Construct a new TextFile object. At least one of 'filename' (a string) and 'file' (a file-like object) must be supplied. They keyword argument options are described above and affect the values returned by 'readline()'.""" if filename is None and file is None: raise RuntimeError, \ "you must supply either or both of 'filename' and 'file'" # set values for all options -- either from client option hash # or fallback to default_options for opt in self.default_options.keys(): if opt in options: setattr (self, opt, options[opt]) else: setattr (self, opt, self.default_options[opt]) # sanity check client option hash for opt in options.keys(): if opt not in self.default_options: raise KeyError, "invalid TextFile option '%s'" % opt if file is None: self.open (filename) else: self.filename = filename self.file = file self.current_line = 0 # assuming that file is at BOF! # 'linebuf' is a stack of lines that will be emptied before we # actually read from the file; it's only populated by an # 'unreadline()' operation self.linebuf = [] def open (self, filename): """Open a new file named 'filename'. This overrides both the 'filename' and 'file' arguments to the constructor.""" self.filename = filename self.file = open (self.filename, 'r') self.current_line = 0 def close (self): """Close the current file and forget everything we know about it (filename, current line number).""" self.file.close () self.file = None self.filename = None self.current_line = None def gen_error (self, msg, line=None): outmsg = [] if line is None: line = self.current_line outmsg.append(self.filename + ", ") if isinstance(line, (list, tuple)): outmsg.append("lines %d-%d: " % tuple (line)) else: outmsg.append("line %d: " % line) outmsg.append(str(msg)) return ''.join(outmsg) def error (self, msg, line=None): raise ValueError, "error: " + self.gen_error(msg, line) def warn (self, msg, line=None): """Print (to stderr) a warning message tied to the current logical line in the current file. If the current logical line in the file spans multiple physical lines, the warning refers to the whole range, eg. "lines 3-5". If 'line' supplied, it overrides the current line number; it may be a list or tuple to indicate a range of physical lines, or an integer for a single physical line.""" sys.stderr.write("warning: " + self.gen_error(msg, line) + "\n") def readline (self): """Read and return a single logical line from the current file (or from an internal buffer if lines have previously been "unread" with 'unreadline()'). If the 'join_lines' option is true, this may involve reading multiple physical lines concatenated into a single string. Updates the current line number, so calling 'warn()' after 'readline()' emits a warning about the physical line(s) just read. Returns None on end-of-file, since the empty string can occur if 'rstrip_ws' is true but 'strip_blanks' is not.""" # If any "unread" lines waiting in 'linebuf', return the top # one. (We don't actually buffer read-ahead data -- lines only # get put in 'linebuf' if the client explicitly does an # 'unreadline()'. if self.linebuf: line = self.linebuf[-1] del self.linebuf[-1] return line buildup_line = '' while 1: # read the line, make it None if EOF line = self.file.readline() if line == '': line = None if self.strip_comments and line: # Look for the first "#" in the line. If none, never # mind. If we find one and it's the first character, or # is not preceded by "\", then it starts a comment -- # strip the comment, strip whitespace before it, and # carry on. Otherwise, it's just an escaped "#", so # unescape it (and any other escaped "#"'s that might be # lurking in there) and otherwise leave the line alone. pos = line.find("#") if pos == -1: # no "#" -- no comments pass # It's definitely a comment -- either "#" is the first # character, or it's elsewhere and unescaped. elif pos == 0 or line[pos-1] != "\\": # Have to preserve the trailing newline, because it's # the job of a later step (rstrip_ws) to remove it -- # and if rstrip_ws is false, we'd better preserve it! # (NB. this means that if the final line is all comment # and has no trailing newline, we will think that it's # EOF; I think that's OK.) eol = (line[-1] == '\n') and '\n' or '' line = line[0:pos] + eol # If all that's left is whitespace, then skip line # *now*, before we try to join it to 'buildup_line' -- # that way constructs like # hello \\ # # comment that should be ignored # there # result in "hello there". if line.strip() == "": continue else: # it's an escaped "#" line = line.replace("\\#", "#") # did previous line end with a backslash? then accumulate if self.join_lines and buildup_line: # oops: end of file if line is None: self.warn ("continuation line immediately precedes " "end-of-file") return buildup_line if self.collapse_join: line = line.lstrip() line = buildup_line + line # careful: pay attention to line number when incrementing it if isinstance(self.current_line, list): self.current_line[1] = self.current_line[1] + 1 else: self.current_line = [self.current_line, self.current_line+1] # just an ordinary line, read it as usual else: if line is None: # eof return None # still have to be careful about incrementing the line number! if isinstance(self.current_line, list): self.current_line = self.current_line[1] + 1 else: self.current_line = self.current_line + 1 # strip whitespace however the client wants (leading and # trailing, or one or the other, or neither) if self.lstrip_ws and self.rstrip_ws: line = line.strip() elif self.lstrip_ws: line = line.lstrip() elif self.rstrip_ws: line = line.rstrip() # blank line (whether we rstrip'ed or not)? skip to next line # if appropriate if (line == '' or line == '\n') and self.skip_blanks: continue if self.join_lines: if line[-1] == '\\': buildup_line = line[:-1] continue if line[-2:] == '\\\n': buildup_line = line[0:-2] + '\n' continue # well, I guess there's some actual content there: return it return line # readline () def readlines (self): """Read and return the list of all logical lines remaining in the current file.""" lines = [] while 1: line = self.readline() if line is None: return lines lines.append (line) def unreadline (self, line): """Push 'line' (a string) onto an internal buffer that will be checked by future 'readline()' calls. Handy for implementing a parser with line-at-a-time lookahead.""" self.linebuf.append (line)
gpl-3.0
[ 624, 505, 63, 493, 199, 199, 20121, 314, 4516, 1173, 1021, 12, 1314, 10557, 376, 3217, 370, 1318, 1584, 199, 9099, 334, 1422, 1183, 9, 6181, 10296, 402, 4024, 3637, 6786, 12, 17289, 4596, 199, 1278, 12, 436, 4263, 316, 2385, 543, 23396, 1041, 199, 199, 363, 5792, 363, 275, 7880, 1304, 17351, 199, 199, 646, 984, 421, 199, 533, 4516, 1173, 26, 339, 408, 17473, 282, 570, 13, 2930, 909, 626, 6181, 10296, 402, 1006, 314, 7645, 1265, 2126, 28829, 2934, 370, 886, 1380, 6661, 282, 1318, 570, 626, 965, 2005, 2126, 1004, 13, 991, 13, 604, 6302, 26, 6202, 6786, 334, 305, 1846, 465, 5426, 2, 365, 2195, 2126, 3721, 4528, 395, 3372, 4596, 2385, 12, 4263, 24113, 2385, 701, 2126, 21375, 314, 8057, 334, 1873, 14, 13831, 737, 1284, 402, 1004, 395, 6202, 2126, 9186, 436, 15, 269, 8520, 8139, 14, 221, 2900, 402, 3520, 787, 2716, 2126, 436, 30426, 25516, 914, 461, 14, 10817, 21552, 282, 283, 4050, 11716, 1083, 880, 1265, 883, 3550, 5721, 3788, 626, 2126, 3622, 14095, 1004, 1329, 12, 2755, 340, 314, 11461, 1004, 315, 7894, 2126, 2249, 796, 3663, 14095, 2385, 14, 221, 6121, 6571, 283, 324, 6407, 11716, 367, 2126, 18234, 1004, 13, 292, 13, 65, 13, 521, 16076, 14, 10817, 20297, 365, 2797, 465, 26, 13596, 4516, 1173, 334, 1501, 29, 403, 12, 570, 29, 403, 12, 1011, 1419, 9, 10817, 2779, 17190, 1533, 334, 13281, 9, 340, 3865, 283, 1501, 7, 436, 283, 493, 7, 787, 488, 27, 2126, 283, 1501, 7, 1077, 506, 282, 1059, 12, 436, 283, 493, 7, 282, 570, 909, 334, 269, 2126, 6020, 626, 6571, 283, 6407, 11716, 436, 283, 1600, 11716, 3102, 680, 221, 2779, 365, 2126, 14318, 626, 1265, 17169, 737, 5210, 283, 1501, 297, 880, 626, 4516, 1173, 2126, 883, 2387, 652, 315, 5721, 3788, 14, 221, 982, 283, 493, 7, 365, 440, 6841, 12, 2126, 4516, 1173, 8491, 2399, 5705, 1808, 314, 283, 1490, 11716, 6762, 14, 10817, 710, 1511, 787, 1006, 5046, 12, 436, 12787, 314, 574, 2138, 701, 2126, 283, 6407, 342, 356, 268, 6202, 63, 6223, 359, 885, 26, 2549, 61, 1779, 6202, 687, 5426, 2, 370, 1284, 13, 1618, 13, 604, 12, 465, 5521, 465, 1263, 8139, 1779, 9186, 1536, 370, 314, 5426, 2, 1553, 7444, 652, 365, 11077, 701, 282, 13831, 268, 634, 1913, 63, 3569, 359, 885, 26, 3055, 61, 1779, 6202, 9186, 8139, 687, 1924, 1004, 2544, 8152, 652, 268, 519, 1913, 63, 3569, 359, 885, 26, 2549, 61, 1779, 6202, 8520, 8139, 334, 15768, 1004, 31298, 21866, 687, 1779, 1924, 1004, 2544, 8152, 652, 268, 3372, 63, 2500, 83, 359, 885, 26, 2549, 93, 1779, 3372, 2385, 626, 787, 2701, 627, 4399, 10, 4024, 3637, 6786, 436, 1779, 8139, 14, 221, 334, 3917, 3865, 634, 1913, 63, 3569, 436, 519, 1913, 63, 3569, 787, 3055, 12, 1779, 2066, 2005, 2385, 1443, 17568, 402, 30869, 590, 8139, 26, 3520, 911, 1779, 627, 1397, 10, 506, 9645, 12, 2755, 340, 283, 2759, 63, 2500, 83, 7, 365, 2549, 4959, 268, 4263, 63, 1278, 359, 885, 26, 3055, 61, 1779, 340, 282, 13831, 365, 314, 2061, 2222, 13, 12210, 4528, 641, 282, 1004, 1779, 2410, 4024, 3637, 6786, 436, 8139, 12, 4263, 314, 2569, 1004, 1779, 370, 652, 370, 1824, 1373, 298, 7954, 1004, 11436, 340, 653, 23376, 2385, 1284, 1779, 543, 282, 13831, 12, 2066, 653, 11, 17, 14095, 2385, 911, 506, 16538, 370, 1779, 1824, 1373, 11461, 1004, 14, 268, 24311, 63, 904, 359, 885, 26, 3055, 61, 1779, 6202, 9186, 8139, 687, 2385, 626, 787, 16538, 370, 3932, 1779, 876, 27914, 269, 27, 1454, 2530, 878, 340, 334, 904, 63, 1278, 436, 440, 634, 1913, 63, 3569, 9, 10817, 3390, 626, 3967, 283, 6735, 63, 3569, 7, 883, 6202, 314, 8520, 8057, 12, 314, 2126, 19002, 402, 283, 6407, 11716, 1471, 14460, 687, 5204, 402, 314, 6762, 570, 2126, 909, 1159, 283, 6407, 11716, 1083, 1, 221, 1010, 6770, 12, 283, 6407, 11716, 2529, 2126, 488, 367, 1284, 13, 1618, 13, 493, 26, 376, 2701, 1059, 5594, 2951, 506, 282, 4596, 1004, 334, 269, 2126, 376, 1006, 13, 8506, 1004, 395, 340, 283, 6735, 63, 3569, 7, 365, 2549, 1325, 283, 2759, 63, 2500, 83, 7, 365, 2126, 440, 1041, 339, 849, 63, 1419, 275, 469, 283, 1913, 63, 6223, 356, 413, 12, 717, 283, 2759, 63, 2500, 83, 356, 259, 413, 12, 717, 283, 10124, 63, 3569, 356, 420, 378, 12, 717, 283, 6735, 63, 3569, 356, 420, 413, 12, 717, 283, 904, 63, 1278, 356, 258, 378, 12, 717, 283, 20681, 63, 904, 356, 221, 378, 12, 1993, 789, 339, 347, 636, 826, 363, 334, 277, 12, 1788, 29, 403, 12, 570, 29, 403, 12, 1011, 1419, 304, 267, 408, 11493, 282, 892, 4516, 1173, 909, 14, 221, 2854, 5210, 1373, 402, 283, 1501, 7, 1779, 334, 65, 1059, 9, 436, 283, 493, 7, 334, 65, 570, 13, 2930, 909, 9, 1471, 506, 6841, 14, 1779, 9322, 4252, 1423, 1511, 787, 11736, 3432, 436, 12787, 1779, 314, 1338, 2138, 701, 283, 6407, 11716, 1041, 398, 340, 1788, 365, 488, 436, 570, 365, 488, 26, 288, 746, 6064, 12, 971, 2116, 298, 13297, 1471, 17169, 1902, 503, 3865, 402, 283, 1501, 7, 436, 283, 493, 4065, 398, 327, 663, 1338, 367, 1006, 1511, 1553, 1902, 687, 1890, 945, 2631, 267, 327, 503, 9567, 370, 849, 63, 1419, 267, 367, 2450, 315, 291, 14, 885, 63, 1419, 14, 1612, 837, 288, 340, 2450, 315, 1511, 26, 355, 5371, 334, 277, 12, 2450, 12, 1511, 59, 2992, 566, 953, 587, 26, 355, 5371, 334, 277, 12, 2450, 12, 291, 14, 885, 63, 1419, 59, 2992, 566, 398, 327, 16740, 1104, 1890, 945, 2631, 267, 367, 2450, 315, 1511, 14, 1612, 837, 288, 340, 2450, 440, 315, 291, 14, 885, 63, 1419, 26, 355, 746, 4067, 12, 298, 3197, 4516, 1173, 945, 1543, 83, 4065, 450, 2450, 398, 340, 570, 365, 488, 26, 288, 291, 14, 1490, 334, 1501, 9, 267, 587, 26, 288, 291, 14, 1501, 275, 1788, 288, 291, 14, 493, 275, 570, 288, 291, 14, 1818, 63, 604, 275, 378, 755, 327, 18002, 626 ]
[ 505, 63, 493, 199, 199, 20121, 314, 4516, 1173, 1021, 12, 1314, 10557, 376, 3217, 370, 1318, 1584, 199, 9099, 334, 1422, 1183, 9, 6181, 10296, 402, 4024, 3637, 6786, 12, 17289, 4596, 199, 1278, 12, 436, 4263, 316, 2385, 543, 23396, 1041, 199, 199, 363, 5792, 363, 275, 7880, 1304, 17351, 199, 199, 646, 984, 421, 199, 533, 4516, 1173, 26, 339, 408, 17473, 282, 570, 13, 2930, 909, 626, 6181, 10296, 402, 1006, 314, 7645, 1265, 2126, 28829, 2934, 370, 886, 1380, 6661, 282, 1318, 570, 626, 965, 2005, 2126, 1004, 13, 991, 13, 604, 6302, 26, 6202, 6786, 334, 305, 1846, 465, 5426, 2, 365, 2195, 2126, 3721, 4528, 395, 3372, 4596, 2385, 12, 4263, 24113, 2385, 701, 2126, 21375, 314, 8057, 334, 1873, 14, 13831, 737, 1284, 402, 1004, 395, 6202, 2126, 9186, 436, 15, 269, 8520, 8139, 14, 221, 2900, 402, 3520, 787, 2716, 2126, 436, 30426, 25516, 914, 461, 14, 10817, 21552, 282, 283, 4050, 11716, 1083, 880, 1265, 883, 3550, 5721, 3788, 626, 2126, 3622, 14095, 1004, 1329, 12, 2755, 340, 314, 11461, 1004, 315, 7894, 2126, 2249, 796, 3663, 14095, 2385, 14, 221, 6121, 6571, 283, 324, 6407, 11716, 367, 2126, 18234, 1004, 13, 292, 13, 65, 13, 521, 16076, 14, 10817, 20297, 365, 2797, 465, 26, 13596, 4516, 1173, 334, 1501, 29, 403, 12, 570, 29, 403, 12, 1011, 1419, 9, 10817, 2779, 17190, 1533, 334, 13281, 9, 340, 3865, 283, 1501, 7, 436, 283, 493, 7, 787, 488, 27, 2126, 283, 1501, 7, 1077, 506, 282, 1059, 12, 436, 283, 493, 7, 282, 570, 909, 334, 269, 2126, 6020, 626, 6571, 283, 6407, 11716, 436, 283, 1600, 11716, 3102, 680, 221, 2779, 365, 2126, 14318, 626, 1265, 17169, 737, 5210, 283, 1501, 297, 880, 626, 4516, 1173, 2126, 883, 2387, 652, 315, 5721, 3788, 14, 221, 982, 283, 493, 7, 365, 440, 6841, 12, 2126, 4516, 1173, 8491, 2399, 5705, 1808, 314, 283, 1490, 11716, 6762, 14, 10817, 710, 1511, 787, 1006, 5046, 12, 436, 12787, 314, 574, 2138, 701, 2126, 283, 6407, 342, 356, 268, 6202, 63, 6223, 359, 885, 26, 2549, 61, 1779, 6202, 687, 5426, 2, 370, 1284, 13, 1618, 13, 604, 12, 465, 5521, 465, 1263, 8139, 1779, 9186, 1536, 370, 314, 5426, 2, 1553, 7444, 652, 365, 11077, 701, 282, 13831, 268, 634, 1913, 63, 3569, 359, 885, 26, 3055, 61, 1779, 6202, 9186, 8139, 687, 1924, 1004, 2544, 8152, 652, 268, 519, 1913, 63, 3569, 359, 885, 26, 2549, 61, 1779, 6202, 8520, 8139, 334, 15768, 1004, 31298, 21866, 687, 1779, 1924, 1004, 2544, 8152, 652, 268, 3372, 63, 2500, 83, 359, 885, 26, 2549, 93, 1779, 3372, 2385, 626, 787, 2701, 627, 4399, 10, 4024, 3637, 6786, 436, 1779, 8139, 14, 221, 334, 3917, 3865, 634, 1913, 63, 3569, 436, 519, 1913, 63, 3569, 787, 3055, 12, 1779, 2066, 2005, 2385, 1443, 17568, 402, 30869, 590, 8139, 26, 3520, 911, 1779, 627, 1397, 10, 506, 9645, 12, 2755, 340, 283, 2759, 63, 2500, 83, 7, 365, 2549, 4959, 268, 4263, 63, 1278, 359, 885, 26, 3055, 61, 1779, 340, 282, 13831, 365, 314, 2061, 2222, 13, 12210, 4528, 641, 282, 1004, 1779, 2410, 4024, 3637, 6786, 436, 8139, 12, 4263, 314, 2569, 1004, 1779, 370, 652, 370, 1824, 1373, 298, 7954, 1004, 11436, 340, 653, 23376, 2385, 1284, 1779, 543, 282, 13831, 12, 2066, 653, 11, 17, 14095, 2385, 911, 506, 16538, 370, 1779, 1824, 1373, 11461, 1004, 14, 268, 24311, 63, 904, 359, 885, 26, 3055, 61, 1779, 6202, 9186, 8139, 687, 2385, 626, 787, 16538, 370, 3932, 1779, 876, 27914, 269, 27, 1454, 2530, 878, 340, 334, 904, 63, 1278, 436, 440, 634, 1913, 63, 3569, 9, 10817, 3390, 626, 3967, 283, 6735, 63, 3569, 7, 883, 6202, 314, 8520, 8057, 12, 314, 2126, 19002, 402, 283, 6407, 11716, 1471, 14460, 687, 5204, 402, 314, 6762, 570, 2126, 909, 1159, 283, 6407, 11716, 1083, 1, 221, 1010, 6770, 12, 283, 6407, 11716, 2529, 2126, 488, 367, 1284, 13, 1618, 13, 493, 26, 376, 2701, 1059, 5594, 2951, 506, 282, 4596, 1004, 334, 269, 2126, 376, 1006, 13, 8506, 1004, 395, 340, 283, 6735, 63, 3569, 7, 365, 2549, 1325, 283, 2759, 63, 2500, 83, 7, 365, 2126, 440, 1041, 339, 849, 63, 1419, 275, 469, 283, 1913, 63, 6223, 356, 413, 12, 717, 283, 2759, 63, 2500, 83, 356, 259, 413, 12, 717, 283, 10124, 63, 3569, 356, 420, 378, 12, 717, 283, 6735, 63, 3569, 356, 420, 413, 12, 717, 283, 904, 63, 1278, 356, 258, 378, 12, 717, 283, 20681, 63, 904, 356, 221, 378, 12, 1993, 789, 339, 347, 636, 826, 363, 334, 277, 12, 1788, 29, 403, 12, 570, 29, 403, 12, 1011, 1419, 304, 267, 408, 11493, 282, 892, 4516, 1173, 909, 14, 221, 2854, 5210, 1373, 402, 283, 1501, 7, 1779, 334, 65, 1059, 9, 436, 283, 493, 7, 334, 65, 570, 13, 2930, 909, 9, 1471, 506, 6841, 14, 1779, 9322, 4252, 1423, 1511, 787, 11736, 3432, 436, 12787, 1779, 314, 1338, 2138, 701, 283, 6407, 11716, 1041, 398, 340, 1788, 365, 488, 436, 570, 365, 488, 26, 288, 746, 6064, 12, 971, 2116, 298, 13297, 1471, 17169, 1902, 503, 3865, 402, 283, 1501, 7, 436, 283, 493, 4065, 398, 327, 663, 1338, 367, 1006, 1511, 1553, 1902, 687, 1890, 945, 2631, 267, 327, 503, 9567, 370, 849, 63, 1419, 267, 367, 2450, 315, 291, 14, 885, 63, 1419, 14, 1612, 837, 288, 340, 2450, 315, 1511, 26, 355, 5371, 334, 277, 12, 2450, 12, 1511, 59, 2992, 566, 953, 587, 26, 355, 5371, 334, 277, 12, 2450, 12, 291, 14, 885, 63, 1419, 59, 2992, 566, 398, 327, 16740, 1104, 1890, 945, 2631, 267, 367, 2450, 315, 1511, 14, 1612, 837, 288, 340, 2450, 440, 315, 291, 14, 885, 63, 1419, 26, 355, 746, 4067, 12, 298, 3197, 4516, 1173, 945, 1543, 83, 4065, 450, 2450, 398, 340, 570, 365, 488, 26, 288, 291, 14, 1490, 334, 1501, 9, 267, 587, 26, 288, 291, 14, 1501, 275, 1788, 288, 291, 14, 493, 275, 570, 288, 291, 14, 1818, 63, 604, 275, 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1, 1, 1, 1, 1, 1, 1, 1 ]
joelpinheiro/safebox-smartcard-auth
Server/veserver/lib/python2.7/site-packages/pip/_vendor/requests/packages/chardet/charsetgroupprober.py
2929
3791
######################## BEGIN LICENSE BLOCK ######################## # The Original Code is Mozilla Communicator client code. # # The Initial Developer of the Original Code is # Netscape Communications Corporation. # Portions created by the Initial Developer are Copyright (C) 1998 # the Initial Developer. All Rights Reserved. # # Contributor(s): # Mark Pilgrim - port to Python # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA # 02110-1301 USA ######################### END LICENSE BLOCK ######################### from . import constants import sys from .charsetprober import CharSetProber class CharSetGroupProber(CharSetProber): def __init__(self): CharSetProber.__init__(self) self._mActiveNum = 0 self._mProbers = [] self._mBestGuessProber = None def reset(self): CharSetProber.reset(self) self._mActiveNum = 0 for prober in self._mProbers: if prober: prober.reset() prober.active = True self._mActiveNum += 1 self._mBestGuessProber = None def get_charset_name(self): if not self._mBestGuessProber: self.get_confidence() if not self._mBestGuessProber: return None # self._mBestGuessProber = self._mProbers[0] return self._mBestGuessProber.get_charset_name() def feed(self, aBuf): for prober in self._mProbers: if not prober: continue if not prober.active: continue st = prober.feed(aBuf) if not st: continue if st == constants.eFoundIt: self._mBestGuessProber = prober return self.get_state() elif st == constants.eNotMe: prober.active = False self._mActiveNum -= 1 if self._mActiveNum <= 0: self._mState = constants.eNotMe return self.get_state() return self.get_state() def get_confidence(self): st = self.get_state() if st == constants.eFoundIt: return 0.99 elif st == constants.eNotMe: return 0.01 bestConf = 0.0 self._mBestGuessProber = None for prober in self._mProbers: if not prober: continue if not prober.active: if constants._debug: sys.stderr.write(prober.get_charset_name() + ' not active\n') continue cf = prober.get_confidence() if constants._debug: sys.stderr.write('%s confidence = %s\n' % (prober.get_charset_name(), cf)) if bestConf < cf: bestConf = cf self._mBestGuessProber = prober if not self._mBestGuessProber: return 0.0 return bestConf # else: # self._mBestGuessProber = self._mProbers[0] # return self._mBestGuessProber.get_confidence()
gpl-2.0
[ 6565, 16427, 5113, 8068, 11945, 199, 3, 710, 12769, 5495, 365, 17728, 13338, 707, 1890, 1233, 14, 199, 3, 221, 199, 3, 710, 6026, 9607, 402, 314, 12769, 5495, 365, 199, 3, 20433, 18686, 11098, 14, 199, 3, 20825, 2737, 701, 314, 6026, 9607, 787, 1898, 334, 35, 9, 19960, 199, 3, 314, 6026, 9607, 14, 2900, 5924, 5702, 14, 199, 3, 221, 199, 3, 17636, 8, 83, 304, 199, 3, 257, 7173, 19641, 446, 1844, 370, 2018, 199, 3, 199, 3, 961, 3555, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 199, 3, 1015, 499, 14, 17, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 221, 199, 3, 961, 3555, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 221, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 3180, 543, 642, 3555, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8026, 11236, 1933, 12, 12066, 11844, 12, 8226, 12, 4828, 199, 3, 11315, 13, 10067, 221, 8217, 199, 19054, 7729, 5113, 8068, 21186, 199, 199, 504, 1275, 492, 5262, 199, 646, 984, 199, 504, 1275, 6043, 19903, 492, 31727, 421, 199, 533, 6659, 1084, 2448, 8029, 8, 15159, 304, 272, 347, 636, 826, 721, 277, 304, 267, 31727, 855, 826, 721, 277, 9, 267, 291, 423, 77, 7472, 5667, 275, 378, 267, 291, 423, 77, 8029, 83, 275, 942, 267, 291, 423, 77, 19478, 25541, 8029, 275, 488, 339, 347, 5305, 8, 277, 304, 267, 31727, 14, 3958, 8, 277, 9, 267, 291, 423, 77, 7472, 5667, 275, 378, 267, 367, 16118, 315, 291, 423, 77, 8029, 83, 26, 288, 340, 16118, 26, 355, 16118, 14, 3958, 342, 355, 16118, 14, 2682, 275, 715, 355, 291, 423, 77, 7472, 5667, 847, 413, 267, 291, 423, 77, 19478, 25541, 8029, 275, 488, 339, 347, 664, 63, 6043, 63, 354, 8, 277, 304, 267, 340, 440, 291, 423, 77, 19478, 25541, 8029, 26, 288, 291, 14, 362, 63, 13969, 342, 288, 340, 440, 291, 423, 77, 19478, 25541, 8029, 26, 355, 372, 488, 199, 3, 4483, 291, 423, 77, 19478, 25541, 8029, 275, 291, 423, 77, 8029, 83, 59, 16, 61, 267, 372, 291, 423, 77, 19478, 25541, 8029, 14, 362, 63, 6043, 63, 354, 342, 339, 347, 4733, 8, 277, 12, 17407, 304, 267, 367, 16118, 315, 291, 423, 77, 8029, 83, 26, 288, 340, 440, 16118, 26, 355, 1980, 288, 340, 440, 16118, 14, 2682, 26, 355, 1980, 288, 410, 275, 16118, 14, 3871, 8, 22353, 9, 288, 340, 440, 410, 26, 355, 1980, 288, 340, 410, 508, 5262, 14, 69, 3601, 7940, 26, 355, 291, 423, 77, 19478, 25541, 8029, 275, 16118, 355, 372, 291, 14, 362, 63, 929, 342, 288, 916, 410, 508, 5262, 14, 69, 1763, 1352, 26, 355, 16118, 14, 2682, 275, 756, 355, 291, 423, 77, 7472, 5667, 4862, 413, 355, 340, 291, 423, 77, 7472, 5667, 2695, 378, 26, 490, 291, 423, 31984, 275, 5262, 14, 69, 1763, 1352, 490, 372, 291, 14, 362, 63, 929, 342, 267, 372, 291, 14, 362, 63, 929, 342, 339, 347, 664, 63, 13969, 8, 277, 304, 267, 410, 275, 291, 14, 362, 63, 929, 342, 267, 340, 410, 508, 5262, 14, 69, 3601, 7940, 26, 288, 372, 378, 14, 1020, 267, 916, 410, 508, 5262, 14, 69, 1763, 1352, 26, 288, 372, 378, 14, 614, 267, 5526, 8930, 275, 378, 14, 16, 267, 291, 423, 77, 19478, 25541, 8029, 275, 488, 267, 367, 16118, 315, 291, 423, 77, 8029, 83, 26, 288, 340, 440, 16118, 26, 355, 1980, 288, 340, 440, 16118, 14, 2682, 26, 355, 340, 5262, 423, 1757, 26, 490, 984, 14, 3083, 14, 952, 8, 19903, 14, 362, 63, 6043, 63, 354, 342, 3660, 435, 283, 440, 4702, 60, 78, 358, 355, 1980, 288, 3980, 275, 16118, 14, 362, 63, 13969, 342, 288, 340, 5262, 423, 1757, 26, 355, 984, 14, 3083, 14, 952, 3508, 83, 15197, 275, 450, 83, 60, 78, 7, 450, 639, 334, 19903, 14, 362, 63, 6043, 63, 354, 1062, 3980, 430, 288, 340, 5526, 8930, 665, 3980, 26, 355, 5526, 8930, 275, 3980, 355, 291, 423, 77, 19478, 25541, 8029, 275, 16118, 267, 340, 440, 291, 423, 77, 19478, 25541, 8029, 26, 288, 372, 378, 14, 16, 267, 372, 5526, 8930, 199, 3, 263, 587, 26, 199, 3, 3322, 291, 423, 77, 19478, 25541, 8029, 275, 291, 423, 77, 8029, 83, 59, 16, 61, 199, 3, 3322, 372, 291, 423, 77, 19478, 25541, 8029, 14, 362, 63, 13969, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 16427, 5113, 8068, 11945, 199, 3, 710, 12769, 5495, 365, 17728, 13338, 707, 1890, 1233, 14, 199, 3, 221, 199, 3, 710, 6026, 9607, 402, 314, 12769, 5495, 365, 199, 3, 20433, 18686, 11098, 14, 199, 3, 20825, 2737, 701, 314, 6026, 9607, 787, 1898, 334, 35, 9, 19960, 199, 3, 314, 6026, 9607, 14, 2900, 5924, 5702, 14, 199, 3, 221, 199, 3, 17636, 8, 83, 304, 199, 3, 257, 7173, 19641, 446, 1844, 370, 2018, 199, 3, 199, 3, 961, 3555, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 199, 3, 1015, 499, 14, 17, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 221, 199, 3, 961, 3555, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 221, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 3180, 543, 642, 3555, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8026, 11236, 1933, 12, 12066, 11844, 12, 8226, 12, 4828, 199, 3, 11315, 13, 10067, 221, 8217, 199, 19054, 7729, 5113, 8068, 21186, 199, 199, 504, 1275, 492, 5262, 199, 646, 984, 199, 504, 1275, 6043, 19903, 492, 31727, 421, 199, 533, 6659, 1084, 2448, 8029, 8, 15159, 304, 272, 347, 636, 826, 721, 277, 304, 267, 31727, 855, 826, 721, 277, 9, 267, 291, 423, 77, 7472, 5667, 275, 378, 267, 291, 423, 77, 8029, 83, 275, 942, 267, 291, 423, 77, 19478, 25541, 8029, 275, 488, 339, 347, 5305, 8, 277, 304, 267, 31727, 14, 3958, 8, 277, 9, 267, 291, 423, 77, 7472, 5667, 275, 378, 267, 367, 16118, 315, 291, 423, 77, 8029, 83, 26, 288, 340, 16118, 26, 355, 16118, 14, 3958, 342, 355, 16118, 14, 2682, 275, 715, 355, 291, 423, 77, 7472, 5667, 847, 413, 267, 291, 423, 77, 19478, 25541, 8029, 275, 488, 339, 347, 664, 63, 6043, 63, 354, 8, 277, 304, 267, 340, 440, 291, 423, 77, 19478, 25541, 8029, 26, 288, 291, 14, 362, 63, 13969, 342, 288, 340, 440, 291, 423, 77, 19478, 25541, 8029, 26, 355, 372, 488, 199, 3, 4483, 291, 423, 77, 19478, 25541, 8029, 275, 291, 423, 77, 8029, 83, 59, 16, 61, 267, 372, 291, 423, 77, 19478, 25541, 8029, 14, 362, 63, 6043, 63, 354, 342, 339, 347, 4733, 8, 277, 12, 17407, 304, 267, 367, 16118, 315, 291, 423, 77, 8029, 83, 26, 288, 340, 440, 16118, 26, 355, 1980, 288, 340, 440, 16118, 14, 2682, 26, 355, 1980, 288, 410, 275, 16118, 14, 3871, 8, 22353, 9, 288, 340, 440, 410, 26, 355, 1980, 288, 340, 410, 508, 5262, 14, 69, 3601, 7940, 26, 355, 291, 423, 77, 19478, 25541, 8029, 275, 16118, 355, 372, 291, 14, 362, 63, 929, 342, 288, 916, 410, 508, 5262, 14, 69, 1763, 1352, 26, 355, 16118, 14, 2682, 275, 756, 355, 291, 423, 77, 7472, 5667, 4862, 413, 355, 340, 291, 423, 77, 7472, 5667, 2695, 378, 26, 490, 291, 423, 31984, 275, 5262, 14, 69, 1763, 1352, 490, 372, 291, 14, 362, 63, 929, 342, 267, 372, 291, 14, 362, 63, 929, 342, 339, 347, 664, 63, 13969, 8, 277, 304, 267, 410, 275, 291, 14, 362, 63, 929, 342, 267, 340, 410, 508, 5262, 14, 69, 3601, 7940, 26, 288, 372, 378, 14, 1020, 267, 916, 410, 508, 5262, 14, 69, 1763, 1352, 26, 288, 372, 378, 14, 614, 267, 5526, 8930, 275, 378, 14, 16, 267, 291, 423, 77, 19478, 25541, 8029, 275, 488, 267, 367, 16118, 315, 291, 423, 77, 8029, 83, 26, 288, 340, 440, 16118, 26, 355, 1980, 288, 340, 440, 16118, 14, 2682, 26, 355, 340, 5262, 423, 1757, 26, 490, 984, 14, 3083, 14, 952, 8, 19903, 14, 362, 63, 6043, 63, 354, 342, 3660, 435, 283, 440, 4702, 60, 78, 358, 355, 1980, 288, 3980, 275, 16118, 14, 362, 63, 13969, 342, 288, 340, 5262, 423, 1757, 26, 355, 984, 14, 3083, 14, 952, 3508, 83, 15197, 275, 450, 83, 60, 78, 7, 450, 639, 334, 19903, 14, 362, 63, 6043, 63, 354, 1062, 3980, 430, 288, 340, 5526, 8930, 665, 3980, 26, 355, 5526, 8930, 275, 3980, 355, 291, 423, 77, 19478, 25541, 8029, 275, 16118, 267, 340, 440, 291, 423, 77, 19478, 25541, 8029, 26, 288, 372, 378, 14, 16, 267, 372, 5526, 8930, 199, 3, 263, 587, 26, 199, 3, 3322, 291, 423, 77, 19478, 25541, 8029, 275, 291, 423, 77, 8029, 83, 59, 16, 61, 199, 3, 3322, 372, 291, 423, 77, 19478, 25541, 8029, 14, 362, 63, 13969, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
sathieu/samba
buildtools/wafsamba/samba_install.py
10
8530
########################### # this handles the magic we need to do for installing # with all the configure options that affect rpath and shared # library use import os import Utils from TaskGen import feature, before, after from samba_utils import LIB_PATH, MODE_755, install_rpath, build_rpath @feature('install_bin') @after('apply_core') @before('apply_link', 'apply_obj_vars') def install_binary(self): '''install a binary, taking account of the different rpath varients''' bld = self.bld # get the ldflags we will use for install and build install_ldflags = install_rpath(self) build_ldflags = build_rpath(bld) if not self.bld.is_install: # just need to set rpath if we are not installing self.env.RPATH = build_ldflags return # work out the install path, expanding variables install_path = getattr(self, 'samba_inst_path', None) or '${BINDIR}' install_path = bld.EXPAND_VARIABLES(install_path) orig_target = os.path.basename(self.target) if install_ldflags != build_ldflags: # we will be creating a new target name, and using that for the # install link. That stops us from overwriting the existing build # target, which has different ldflags self.target += '.inst' # setup the right rpath link flags for the install self.env.RPATH = install_ldflags if not self.samba_install: # this binary is marked not to be installed return # tell waf to install the right binary bld.install_as(os.path.join(install_path, orig_target), os.path.join(self.path.abspath(bld.env), self.target), chmod=MODE_755) @feature('install_lib') @after('apply_core') @before('apply_link', 'apply_obj_vars') def install_library(self): '''install a library, taking account of the different rpath varients''' if getattr(self, 'done_install_library', False): return bld = self.bld default_env = bld.all_envs['default'] try: if self.env['IS_EXTRA_PYTHON']: bld.all_envs['default'] = bld.all_envs['extrapython'] install_ldflags = install_rpath(self) build_ldflags = build_rpath(bld) if not self.bld.is_install or not getattr(self, 'samba_install', True): # just need to set the build rpath if we are not installing self.env.RPATH = build_ldflags return # setup the install path, expanding variables install_path = getattr(self, 'samba_inst_path', None) if install_path is None: if getattr(self, 'private_library', False): install_path = '${PRIVATELIBDIR}' else: install_path = '${LIBDIR}' install_path = bld.EXPAND_VARIABLES(install_path) target_name = self.target if install_ldflags != build_ldflags: # we will be creating a new target name, and using that for the # install link. That stops us from overwriting the existing build # target, which has different ldflags self.done_install_library = True t = self.clone(self.env) t.posted = False t.target += '.inst' t.name = self.name + '.inst' self.env.RPATH = build_ldflags else: t = self t.env.RPATH = install_ldflags dev_link = None # in the following the names are: # - inst_name is the name with .inst. in it, in the build # directory # - install_name is the name in the install directory # - install_link is a symlink in the install directory, to install_name if getattr(self, 'samba_realname', None): install_name = self.samba_realname install_link = None if getattr(self, 'soname', ''): install_link = self.soname if getattr(self, 'samba_type', None) == 'PYTHON': inst_name = bld.make_libname(t.target, nolibprefix=True, python=True) else: inst_name = bld.make_libname(t.target) elif self.vnum: vnum_base = self.vnum.split('.')[0] install_name = bld.make_libname(target_name, version=self.vnum) install_link = bld.make_libname(target_name, version=vnum_base) inst_name = bld.make_libname(t.target) if not self.private_library: # only generate the dev link for non-bundled libs dev_link = bld.make_libname(target_name) elif getattr(self, 'soname', ''): install_name = bld.make_libname(target_name) install_link = self.soname inst_name = bld.make_libname(t.target) else: install_name = bld.make_libname(target_name) install_link = None inst_name = bld.make_libname(t.target) if t.env.SONAME_ST: # ensure we get the right names in the library if install_link: t.env.append_value('LINKFLAGS', t.env.SONAME_ST % install_link) else: t.env.append_value('LINKFLAGS', t.env.SONAME_ST % install_name) t.env.SONAME_ST = '' # tell waf to install the library bld.install_as(os.path.join(install_path, install_name), os.path.join(self.path.abspath(bld.env), inst_name), chmod=MODE_755) if install_link and install_link != install_name: # and the symlink if needed bld.symlink_as(os.path.join(install_path, install_link), os.path.basename(install_name)) if dev_link: bld.symlink_as(os.path.join(install_path, dev_link), os.path.basename(install_name)) finally: bld.all_envs['default'] = default_env @feature('cshlib') @after('apply_implib') @before('apply_vnum') def apply_soname(self): '''install a library, taking account of the different rpath varients''' if self.env.SONAME_ST and getattr(self, 'soname', ''): self.env.append_value('LINKFLAGS', self.env.SONAME_ST % self.soname) self.env.SONAME_ST = '' @feature('cshlib') @after('apply_implib') @before('apply_vnum') def apply_vscript(self): '''add version-script arguments to library build''' if self.env.HAVE_LD_VERSION_SCRIPT and getattr(self, 'version_script', ''): self.env.append_value('LINKFLAGS', "-Wl,--version-script=%s" % self.version_script) self.version_script = None ############################## # handle the creation of links for libraries and binaries in the build tree @feature('symlink_lib') @after('apply_link') def symlink_lib(self): '''symlink a shared lib''' if self.target.endswith('.inst'): return blddir = os.path.dirname(self.bld.srcnode.abspath(self.bld.env)) libpath = self.link_task.outputs[0].abspath(self.env) # calculat the link target and put it in the environment soext="" vnum = getattr(self, 'vnum', None) if vnum is not None: soext = '.' + vnum.split('.')[0] link_target = getattr(self, 'link_name', '') if link_target == '': basename = os.path.basename(self.bld.make_libname(self.target, version=soext)) if getattr(self, "private_library", False): link_target = '%s/private/%s' % (LIB_PATH, basename) else: link_target = '%s/%s' % (LIB_PATH, basename) link_target = os.path.join(blddir, link_target) if os.path.lexists(link_target): if os.path.islink(link_target) and os.readlink(link_target) == libpath: return os.unlink(link_target) link_container = os.path.dirname(link_target) if not os.path.isdir(link_container): os.makedirs(link_container) os.symlink(libpath, link_target) @feature('symlink_bin') @after('apply_link') def symlink_bin(self): '''symlink a binary into the build directory''' if self.target.endswith('.inst'): return if not self.link_task.outputs or not self.link_task.outputs[0]: raise Utils.WafError('no outputs found for %s in symlink_bin' % self.name) binpath = self.link_task.outputs[0].abspath(self.env) bldpath = os.path.join(self.bld.env.BUILD_DIRECTORY, self.link_task.outputs[0].name) if os.path.lexists(bldpath): if os.path.islink(bldpath) and os.readlink(bldpath) == binpath: return os.unlink(bldpath) os.symlink(binpath, bldpath)
gpl-3.0
[ 6565, 5680, 199, 3, 642, 10022, 314, 10628, 781, 1929, 370, 886, 367, 22200, 199, 3, 543, 1006, 314, 7908, 1511, 626, 12787, 519, 515, 436, 5709, 199, 3, 3555, 675, 199, 199, 646, 747, 199, 646, 17397, 199, 504, 8495, 8168, 492, 3878, 12, 2544, 12, 2410, 199, 504, 31710, 63, 1208, 492, 25764, 63, 3243, 12, 27065, 63, 12315, 12, 3907, 63, 27841, 12, 1900, 63, 27841, 199, 199, 32, 4445, 360, 3174, 63, 1393, 358, 199, 32, 4399, 360, 4998, 63, 1018, 358, 199, 32, 5182, 360, 4998, 63, 1073, 297, 283, 4998, 63, 1113, 63, 2936, 358, 199, 318, 3907, 63, 3008, 8, 277, 304, 272, 1449, 3174, 282, 3366, 12, 16466, 2933, 402, 314, 3365, 519, 515, 4172, 24871, 2344, 272, 27971, 275, 291, 14, 14341, 339, 327, 664, 314, 19585, 781, 911, 675, 367, 3907, 436, 1900, 272, 3907, 63, 25601, 275, 3907, 63, 27841, 8, 277, 9, 272, 1900, 63, 25601, 257, 275, 1900, 63, 27841, 8, 14341, 9, 339, 340, 440, 291, 14, 14341, 14, 374, 63, 3174, 26, 267, 327, 2951, 1929, 370, 663, 519, 515, 340, 781, 787, 440, 22200, 267, 291, 14, 1813, 14, 50, 3243, 275, 1900, 63, 25601, 267, 372, 339, 327, 1736, 734, 314, 3907, 931, 12, 6544, 316, 2860, 272, 3907, 63, 515, 275, 2519, 8, 277, 12, 283, 21693, 63, 3615, 63, 515, 297, 488, 9, 503, 20044, 9431, 3022, 6834, 272, 3907, 63, 515, 275, 27971, 14, 20612, 63, 21161, 8, 3174, 63, 515, 9, 339, 2306, 63, 1375, 275, 747, 14, 515, 14, 4846, 8, 277, 14, 1375, 9, 339, 340, 3907, 63, 25601, 1137, 1900, 63, 25601, 26, 267, 327, 781, 911, 506, 6425, 282, 892, 1347, 536, 12, 436, 1808, 626, 367, 314, 267, 327, 3907, 2142, 14, 10314, 20922, 2739, 687, 32592, 314, 3411, 1900, 267, 327, 1347, 12, 1314, 965, 3365, 19585, 267, 291, 14, 1375, 847, 1987, 3615, 7, 339, 327, 3272, 314, 2451, 519, 515, 2142, 3285, 367, 314, 3907, 272, 291, 14, 1813, 14, 50, 3243, 275, 3907, 63, 25601, 339, 340, 440, 291, 14, 21693, 63, 3174, 26, 267, 327, 642, 3366, 365, 11584, 440, 370, 506, 4903, 267, 372, 339, 327, 11480, 25782, 370, 3907, 314, 2451, 3366, 272, 27971, 14, 3174, 63, 305, 8, 736, 14, 515, 14, 904, 8, 3174, 63, 515, 12, 2306, 63, 1375, 395, 673, 747, 14, 515, 14, 904, 8, 277, 14, 515, 14, 4832, 8, 14341, 14, 1813, 395, 291, 14, 1375, 395, 673, 30106, 29, 6963, 63, 12315, 9, 4388, 199, 32, 4445, 360, 3174, 63, 773, 358, 199, 32, 4399, 360, 4998, 63, 1018, 358, 199, 32, 5182, 360, 4998, 63, 1073, 297, 283, 4998, 63, 1113, 63, 2936, 358, 199, 318, 3907, 63, 4342, 8, 277, 304, 272, 1449, 3174, 282, 3555, 12, 16466, 2933, 402, 314, 3365, 519, 515, 4172, 24871, 2344, 272, 340, 2519, 8, 277, 12, 283, 4456, 63, 3174, 63, 4342, 297, 756, 304, 267, 372, 339, 27971, 275, 291, 14, 14341, 339, 849, 63, 1813, 275, 27971, 14, 452, 63, 27900, 459, 885, 418, 272, 862, 26, 267, 340, 291, 14, 1813, 459, 1311, 63, 18555, 63, 11720, 2565, 288, 27971, 14, 452, 63, 27900, 459, 885, 418, 275, 27971, 14, 452, 63, 27900, 459, 2911, 1548, 418, 398, 3907, 63, 25601, 275, 3907, 63, 27841, 8, 277, 9, 267, 1900, 63, 25601, 257, 275, 1900, 63, 27841, 8, 14341, 9, 398, 340, 440, 291, 14, 14341, 14, 374, 63, 3174, 503, 440, 2519, 8, 277, 12, 283, 21693, 63, 3174, 297, 715, 304, 288, 327, 2951, 1929, 370, 663, 314, 1900, 519, 515, 340, 781, 787, 440, 22200, 288, 291, 14, 1813, 14, 50, 3243, 275, 1900, 63, 25601, 288, 372, 398, 327, 3272, 314, 3907, 931, 12, 6544, 316, 2860, 267, 3907, 63, 515, 275, 2519, 8, 277, 12, 283, 21693, 63, 3615, 63, 515, 297, 488, 9, 267, 340, 3907, 63, 515, 365, 488, 26, 288, 340, 2519, 8, 277, 12, 283, 4239, 63, 4342, 297, 756, 304, 355, 3907, 63, 515, 275, 20044, 18748, 5617, 3022, 6834, 288, 587, 26, 355, 3907, 63, 515, 275, 20044, 5617, 3022, 6834, 267, 3907, 63, 515, 275, 27971, 14, 20612, 63, 21161, 8, 3174, 63, 515, 9, 398, 1347, 63, 354, 275, 291, 14, 1375, 398, 340, 3907, 63, 25601, 1137, 1900, 63, 25601, 26, 288, 327, 781, 911, 506, 6425, 282, 892, 1347, 536, 12, 436, 1808, 626, 367, 314, 288, 327, 3907, 2142, 14, 10314, 20922, 2739, 687, 32592, 314, 3411, 1900, 288, 327, 1347, 12, 1314, 965, 3365, 19585, 288, 291, 14, 4456, 63, 3174, 63, 4342, 275, 715, 288, 307, 275, 291, 14, 6311, 8, 277, 14, 1813, 9, 288, 307, 14, 21760, 275, 756, 288, 307, 14, 1375, 847, 1987, 3615, 7, 288, 307, 14, 354, 275, 291, 14, 354, 435, 1987, 3615, 7, 288, 291, 14, 1813, 14, 50, 3243, 275, 1900, 63, 25601, 267, 587, 26, 288, 307, 275, 291, 398, 307, 14, 1813, 14, 50, 3243, 275, 3907, 63, 25601, 398, 4866, 63, 1073, 258, 275, 488, 398, 327, 315, 314, 2569, 314, 1561, 787, 26, 267, 327, 446, 2727, 63, 354, 365, 314, 536, 543, 1275, 3615, 14, 315, 652, 12, 315, 314, 1900, 267, 327, 257, 2082, 267, 327, 446, 3907, 63, 354, 365, 314, 536, 315, 314, 3907, 2082, 267, 327, 446, 3907, 63, 1073, 365, 282, 15296, 315, 314, 3907, 2082, 12, 370, 3907, 63, 354, 398, 340, 2519, 8, 277, 12, 283, 21693, 63, 3093, 354, 297, 488, 304, 288, 3907, 63, 354, 275, 291, 14, 21693, 63, 3093, 354, 288, 3907, 63, 1073, 275, 488, 288, 340, 2519, 8, 277, 12, 283, 834, 313, 297, 21019, 355, 3907, 63, 1073, 275, 291, 14, 834, 313, 288, 340, 2519, 8, 277, 12, 283, 21693, 63, 466, 297, 488, 9, 508, 283, 11720, 356, 355, 2727, 63, 354, 259, 275, 27971, 14, 1875, 63, 773, 354, 8, 84, 14, 1375, 12, 949, 773, 1861, 29, 549, 12, 2366, 29, 549, 9, 288, 587, 26, 355, 2727, 63, 354, 259, 275, 27971, 14, 1875, 63, 773, 354, 8, 84, 14 ]
[ 5680, 199, 3, 642, 10022, 314, 10628, 781, 1929, 370, 886, 367, 22200, 199, 3, 543, 1006, 314, 7908, 1511, 626, 12787, 519, 515, 436, 5709, 199, 3, 3555, 675, 199, 199, 646, 747, 199, 646, 17397, 199, 504, 8495, 8168, 492, 3878, 12, 2544, 12, 2410, 199, 504, 31710, 63, 1208, 492, 25764, 63, 3243, 12, 27065, 63, 12315, 12, 3907, 63, 27841, 12, 1900, 63, 27841, 199, 199, 32, 4445, 360, 3174, 63, 1393, 358, 199, 32, 4399, 360, 4998, 63, 1018, 358, 199, 32, 5182, 360, 4998, 63, 1073, 297, 283, 4998, 63, 1113, 63, 2936, 358, 199, 318, 3907, 63, 3008, 8, 277, 304, 272, 1449, 3174, 282, 3366, 12, 16466, 2933, 402, 314, 3365, 519, 515, 4172, 24871, 2344, 272, 27971, 275, 291, 14, 14341, 339, 327, 664, 314, 19585, 781, 911, 675, 367, 3907, 436, 1900, 272, 3907, 63, 25601, 275, 3907, 63, 27841, 8, 277, 9, 272, 1900, 63, 25601, 257, 275, 1900, 63, 27841, 8, 14341, 9, 339, 340, 440, 291, 14, 14341, 14, 374, 63, 3174, 26, 267, 327, 2951, 1929, 370, 663, 519, 515, 340, 781, 787, 440, 22200, 267, 291, 14, 1813, 14, 50, 3243, 275, 1900, 63, 25601, 267, 372, 339, 327, 1736, 734, 314, 3907, 931, 12, 6544, 316, 2860, 272, 3907, 63, 515, 275, 2519, 8, 277, 12, 283, 21693, 63, 3615, 63, 515, 297, 488, 9, 503, 20044, 9431, 3022, 6834, 272, 3907, 63, 515, 275, 27971, 14, 20612, 63, 21161, 8, 3174, 63, 515, 9, 339, 2306, 63, 1375, 275, 747, 14, 515, 14, 4846, 8, 277, 14, 1375, 9, 339, 340, 3907, 63, 25601, 1137, 1900, 63, 25601, 26, 267, 327, 781, 911, 506, 6425, 282, 892, 1347, 536, 12, 436, 1808, 626, 367, 314, 267, 327, 3907, 2142, 14, 10314, 20922, 2739, 687, 32592, 314, 3411, 1900, 267, 327, 1347, 12, 1314, 965, 3365, 19585, 267, 291, 14, 1375, 847, 1987, 3615, 7, 339, 327, 3272, 314, 2451, 519, 515, 2142, 3285, 367, 314, 3907, 272, 291, 14, 1813, 14, 50, 3243, 275, 3907, 63, 25601, 339, 340, 440, 291, 14, 21693, 63, 3174, 26, 267, 327, 642, 3366, 365, 11584, 440, 370, 506, 4903, 267, 372, 339, 327, 11480, 25782, 370, 3907, 314, 2451, 3366, 272, 27971, 14, 3174, 63, 305, 8, 736, 14, 515, 14, 904, 8, 3174, 63, 515, 12, 2306, 63, 1375, 395, 673, 747, 14, 515, 14, 904, 8, 277, 14, 515, 14, 4832, 8, 14341, 14, 1813, 395, 291, 14, 1375, 395, 673, 30106, 29, 6963, 63, 12315, 9, 4388, 199, 32, 4445, 360, 3174, 63, 773, 358, 199, 32, 4399, 360, 4998, 63, 1018, 358, 199, 32, 5182, 360, 4998, 63, 1073, 297, 283, 4998, 63, 1113, 63, 2936, 358, 199, 318, 3907, 63, 4342, 8, 277, 304, 272, 1449, 3174, 282, 3555, 12, 16466, 2933, 402, 314, 3365, 519, 515, 4172, 24871, 2344, 272, 340, 2519, 8, 277, 12, 283, 4456, 63, 3174, 63, 4342, 297, 756, 304, 267, 372, 339, 27971, 275, 291, 14, 14341, 339, 849, 63, 1813, 275, 27971, 14, 452, 63, 27900, 459, 885, 418, 272, 862, 26, 267, 340, 291, 14, 1813, 459, 1311, 63, 18555, 63, 11720, 2565, 288, 27971, 14, 452, 63, 27900, 459, 885, 418, 275, 27971, 14, 452, 63, 27900, 459, 2911, 1548, 418, 398, 3907, 63, 25601, 275, 3907, 63, 27841, 8, 277, 9, 267, 1900, 63, 25601, 257, 275, 1900, 63, 27841, 8, 14341, 9, 398, 340, 440, 291, 14, 14341, 14, 374, 63, 3174, 503, 440, 2519, 8, 277, 12, 283, 21693, 63, 3174, 297, 715, 304, 288, 327, 2951, 1929, 370, 663, 314, 1900, 519, 515, 340, 781, 787, 440, 22200, 288, 291, 14, 1813, 14, 50, 3243, 275, 1900, 63, 25601, 288, 372, 398, 327, 3272, 314, 3907, 931, 12, 6544, 316, 2860, 267, 3907, 63, 515, 275, 2519, 8, 277, 12, 283, 21693, 63, 3615, 63, 515, 297, 488, 9, 267, 340, 3907, 63, 515, 365, 488, 26, 288, 340, 2519, 8, 277, 12, 283, 4239, 63, 4342, 297, 756, 304, 355, 3907, 63, 515, 275, 20044, 18748, 5617, 3022, 6834, 288, 587, 26, 355, 3907, 63, 515, 275, 20044, 5617, 3022, 6834, 267, 3907, 63, 515, 275, 27971, 14, 20612, 63, 21161, 8, 3174, 63, 515, 9, 398, 1347, 63, 354, 275, 291, 14, 1375, 398, 340, 3907, 63, 25601, 1137, 1900, 63, 25601, 26, 288, 327, 781, 911, 506, 6425, 282, 892, 1347, 536, 12, 436, 1808, 626, 367, 314, 288, 327, 3907, 2142, 14, 10314, 20922, 2739, 687, 32592, 314, 3411, 1900, 288, 327, 1347, 12, 1314, 965, 3365, 19585, 288, 291, 14, 4456, 63, 3174, 63, 4342, 275, 715, 288, 307, 275, 291, 14, 6311, 8, 277, 14, 1813, 9, 288, 307, 14, 21760, 275, 756, 288, 307, 14, 1375, 847, 1987, 3615, 7, 288, 307, 14, 354, 275, 291, 14, 354, 435, 1987, 3615, 7, 288, 291, 14, 1813, 14, 50, 3243, 275, 1900, 63, 25601, 267, 587, 26, 288, 307, 275, 291, 398, 307, 14, 1813, 14, 50, 3243, 275, 3907, 63, 25601, 398, 4866, 63, 1073, 258, 275, 488, 398, 327, 315, 314, 2569, 314, 1561, 787, 26, 267, 327, 446, 2727, 63, 354, 365, 314, 536, 543, 1275, 3615, 14, 315, 652, 12, 315, 314, 1900, 267, 327, 257, 2082, 267, 327, 446, 3907, 63, 354, 365, 314, 536, 315, 314, 3907, 2082, 267, 327, 446, 3907, 63, 1073, 365, 282, 15296, 315, 314, 3907, 2082, 12, 370, 3907, 63, 354, 398, 340, 2519, 8, 277, 12, 283, 21693, 63, 3093, 354, 297, 488, 304, 288, 3907, 63, 354, 275, 291, 14, 21693, 63, 3093, 354, 288, 3907, 63, 1073, 275, 488, 288, 340, 2519, 8, 277, 12, 283, 834, 313, 297, 21019, 355, 3907, 63, 1073, 275, 291, 14, 834, 313, 288, 340, 2519, 8, 277, 12, 283, 21693, 63, 466, 297, 488, 9, 508, 283, 11720, 356, 355, 2727, 63, 354, 259, 275, 27971, 14, 1875, 63, 773, 354, 8, 84, 14, 1375, 12, 949, 773, 1861, 29, 549, 12, 2366, 29, 549, 9, 288, 587, 26, 355, 2727, 63, 354, 259, 275, 27971, 14, 1875, 63, 773, 354, 8, 84, 14, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
jgcobb3/growth-yield-batch
scripts/build_keys.py
2
6669
#!/usr/bin/env python """build_keys.py Construct key files from project directory containing Rx and Condition data. See https://github.com/Ecotrust/growth-yield-batch#building-the-batch-directory-structure-from-base-data for details on how to set up your project directory (example below) project_directory |-- config.json |-- cond | |-- 31566.cli | |-- 31566.fvs | |-- 31566.site | `-- 31566.std `-- rx |-- varWC_rx1.key |-- varWC_rx25.key `-- include `-- spotted_owl.txt Usage: build_keys.py [options] [DIR] build_keys.py (-h | --help) build_keys.py --version Options: -h --help Show this screen. --cores=<cpus> Number of CPU Cores [default: 1] --version Show version. """ from docopt import docopt from shutil import copyfile, rmtree import os import glob import json from jinja2 import Template import itertools def check_indir(indir): """ make sure this logic matches the top-level docstring """ # TODO MORE REQUIREMENTS ...... subdirs = [name for name in os.listdir(indir) if os.path.isdir(os.path.join(indir, name))] required = ['rx', 'cond'] for req in required: if req not in subdirs: return False return True def func_star(data): return generate_keyfiles_for_cond(*data) def generate_keyfiles_for_cond(fvs, indir, plotsdir, conf, include): # Default site classes based on DF 50yr default_site_classes = { "1": "SITECODE DF 148 1", "2": "SITECODE DF 125 1", "3": "SITECODE DF 105 1", "4": "SITECODE DF 85 1", "5": "SITECODE DF 62 1"} condid = os.path.splitext(os.path.basename(fvs))[0] print "Generating keyfiles for condition", condid cli = fvs.replace('.fvs','.cli') std = fvs.replace('.fvs','.std') rxfile = fvs.replace('.fvs','.rx') stdinfo_path = fvs.replace(".fvs", ".std") stdinfo = open(stdinfo_path, 'r').read().strip() if os.path.exists(rxfile): with open(rxfile, 'r') as fh: var_rxs = [tuple(x.strip().split(",")) for x in fh.readlines()] else: var_rxs = None # implies ALL rxs get run cli = fvs.replace(".fvs", ".cli") sitecls_override = fvs.replace(".fvs", ".site") var_sites = None if os.path.exists(sitecls_override): with open(sitecls_override, 'r') as fh: lines = fh.readlines() try: var_sites = dict([tuple(x.strip().split(",")) for x in lines]) except: # just a single site value site_class = lines[0].strip() else: site_class = "2" # default for basekey in basekeys: key_prefix = os.path.splitext(os.path.basename(basekey))[0] variant, rx = key_prefix.split('_') variant = variant.replace('var','') rx = rx.replace('rx','') if var_rxs and \ (variant, rx) not in var_rxs and (variant, "*") not in var_rxs: # print "WARNING, skipping basekey, no variant/rxs like", (variant, rx), "in", var_rxs continue # Skip it print "\t %s %s" % (variant, rx) if var_sites: # If needed, adjust site class on a per-variant basis try: site_class = var_sites[variant] except: site_class = "2" # revert to default try: sitecode = conf['site_classes'][variant][site_class] except KeyError: sitecode = default_site_classes[site_class] with open(basekey, 'r') as fh: template = Template(fh.read()) for climate in conf['climate_scenarios']: climate_safe = climate.replace("_", '-') # no underscores out = "var%s_rx%s_cond%s_site%s_clim%s" % ( variant, rx, condid, site_class, climate_safe) #print "\t", out outdir = os.path.join(plotsdir, out) os.makedirs(outdir) copyfile(fvs, os.path.join(outdir, os.path.basename(fvs))) try: copyfile(cli, os.path.join(outdir, os.path.basename(cli))) except IOError: pass # not required copyfile(std, os.path.join(outdir, os.path.basename(std))) for offset in conf['offsets']: if rx == '1' and offset > 0: # special case continue keyout = out + "_off%s.key" % (offset, ) keyoutpath = os.path.join(outdir, keyout) content = template.render(locals()) with open(keyoutpath, 'w') as fh: fh.write(content) if __name__ == "__main__": args = docopt(__doc__, version='Build Keys 1.0') indir = args['DIR'] cores = int(args['--cores']) if not indir: indir = os.path.curdir indir = os.path.abspath(indir) indir = os.path.abspath(os.path.curdir) plotsdir = os.path.join(indir, "plots") if not os.path.exists(indir): raise Exception("%s does not exist" % indir) if not check_indir(indir): raise Exception("%s is not configured correctly; see --help" % indir) if os.path.exists(plotsdir): rmtree(plotsdir) with open(os.path.join(indir, 'config.json'), 'r') as fh: conf = json.loads(fh.read()) basekeys = glob.glob(os.path.join(indir, 'rx', '*.key')) include = {} for inc_path in glob.glob(os.path.join(indir, 'rx', 'include',"*")): inc_var = os.path.splitext(os.path.basename(inc_path))[0] with open(inc_path, 'r') as fh: inc_content = fh.read() include[inc_var] = inc_content fvss = glob.glob(os.path.join(indir, 'cond', '*.fvs')) if cores == 1: # Single core map(generate_keyfiles_for_cond, fvss, itertools.repeat(indir, len(fvss)), itertools.repeat(plotsdir, len(fvss)), itertools.repeat(conf, len(fvss)), itertools.repeat(include, len(fvss)),) elif cores > 1: # Multicore from multiprocessing import Pool pool = Pool(cores) args = itertools.izip( fvss, itertools.repeat(indir, len(fvss)), itertools.repeat(plotsdir, len(fvss)), itertools.repeat(conf, len(fvss)), itertools.repeat(include, len(fvss)), ) pool.map(func_star, args) pool.close() pool.join() else: raise Exception("cores must be >= 1") print print "Batch keyfile directory output to", plotsdir
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 624, 1506, 63, 1612, 14, 647, 199, 199, 11493, 790, 1584, 687, 2199, 2082, 3035, 820, 88, 436, 28401, 666, 14, 199, 199, 9295, 4178, 921, 5031, 14, 957, 15, 37, 331, 15756, 15, 22890, 273, 13, 11481, 13, 2912, 3, 17952, 13, 1589, 13, 2912, 13, 3619, 13, 6976, 13, 504, 13, 1095, 13, 576, 199, 509, 2436, 641, 4212, 370, 663, 1536, 2195, 2199, 2082, 334, 2694, 5084, 9, 199, 199, 1715, 63, 3619, 199, 92, 306, 1101, 14, 1001, 199, 92, 306, 9288, 199, 92, 257, 1204, 306, 650, 1046, 1272, 14, 2764, 199, 92, 257, 1204, 306, 650, 1046, 1272, 14, 70, 3122, 199, 92, 257, 1204, 306, 650, 1046, 1272, 14, 2124, 199, 92, 257, 658, 306, 650, 1046, 1272, 14, 1516, 199, 64, 306, 12951, 272, 1204, 306, 2729, 55, 35, 63, 6872, 17, 14, 498, 272, 1204, 306, 2729, 55, 35, 63, 6872, 821, 14, 498, 272, 658, 306, 2387, 267, 658, 306, 23226, 471, 63, 583, 76, 14, 2424, 199, 199, 7692, 26, 523, 1900, 63, 1612, 14, 647, 359, 1419, 61, 359, 3022, 61, 523, 1900, 63, 1612, 14, 647, 5868, 72, 1204, 1553, 3437, 9, 523, 1900, 63, 1612, 14, 647, 1553, 1023, 199, 199, 4558, 26, 523, 446, 72, 1553, 3437, 263, 12968, 642, 6426, 14, 523, 1553, 4630, 18987, 8896, 30, 257, 4860, 402, 11952, 1849, 470, 359, 885, 26, 413, 61, 523, 1553, 1023, 263, 12968, 1015, 14, 199, 624, 199, 504, 886, 32626, 492, 886, 32626, 199, 504, 5145, 492, 1331, 493, 12, 20978, 199, 646, 747, 199, 646, 5739, 199, 646, 2022, 199, 504, 10321, 18, 492, 5458, 199, 646, 7975, 421, 199, 318, 1104, 63, 262, 694, 8, 262, 694, 304, 272, 408, 1852, 3238, 642, 9661, 4450, 314, 2746, 13, 1896, 9214, 408, 272, 327, 3254, 603, 5788, 17023, 21201, 20967, 2508, 4496, 272, 31396, 275, 359, 354, 367, 536, 315, 747, 14, 7374, 8, 262, 694, 9, 340, 747, 14, 515, 14, 6027, 8, 736, 14, 515, 14, 904, 8, 262, 694, 12, 536, 10524, 272, 1415, 275, 788, 6872, 297, 283, 2067, 418, 272, 367, 2648, 315, 1415, 26, 267, 340, 2648, 440, 315, 31396, 26, 288, 372, 756, 272, 372, 715, 199, 199, 318, 2562, 63, 7848, 8, 576, 304, 272, 372, 3550, 63, 498, 1725, 63, 509, 63, 2067, 2031, 576, 9, 199, 199, 318, 3550, 63, 498, 1725, 63, 509, 63, 2067, 8, 70, 3122, 12, 315, 694, 12, 19695, 694, 12, 3743, 12, 2387, 304, 272, 327, 3758, 4770, 3992, 4079, 641, 577, 38, 5238, 21897, 272, 849, 63, 2124, 63, 2888, 275, 469, 15166, 298, 17, 582, 298, 7917, 6012, 3515, 577, 38, 755, 30300, 260, 413, 401, 489, 298, 18, 582, 298, 7917, 6012, 3515, 577, 38, 755, 19163, 260, 413, 401, 489, 298, 19, 582, 298, 7917, 6012, 3515, 577, 38, 755, 20462, 260, 413, 401, 489, 298, 20, 582, 298, 7917, 6012, 3515, 577, 38, 263, 16412, 260, 413, 401, 489, 298, 21, 582, 298, 7917, 6012, 3515, 577, 38, 263, 16202, 260, 413, 3570, 339, 406, 14887, 275, 747, 14, 515, 14, 7973, 8, 736, 14, 515, 14, 4846, 8, 70, 3122, 11515, 16, 61, 272, 870, 298, 29244, 790, 1725, 367, 5558, 401, 406, 14887, 272, 5053, 275, 289, 3122, 14, 1814, 5175, 70, 3122, 26409, 2764, 358, 272, 2418, 275, 289, 3122, 14, 1814, 5175, 70, 3122, 26409, 1516, 358, 272, 12951, 493, 275, 289, 3122, 14, 1814, 5175, 70, 3122, 26409, 6872, 358, 339, 2418, 815, 63, 515, 275, 289, 3122, 14, 1814, 9520, 70, 3122, 401, 3680, 1516, 531, 272, 2418, 815, 275, 1551, 8, 1516, 815, 63, 515, 12, 283, 82, 1959, 739, 1252, 1913, 342, 339, 340, 747, 14, 515, 14, 2444, 8, 6872, 493, 304, 267, 543, 1551, 8, 6872, 493, 12, 283, 82, 358, 465, 11155, 26, 288, 2729, 63, 6872, 83, 275, 359, 2960, 8, 88, 14, 1913, 1252, 1294, 11854, 2237, 367, 671, 315, 11155, 14, 9684, 5106, 272, 587, 26, 267, 2729, 63, 6872, 83, 275, 488, 221, 327, 22660, 11727, 519, 7977, 664, 1255, 339, 5053, 275, 289, 3122, 14, 1814, 9520, 70, 3122, 401, 3680, 2764, 531, 339, 4770, 1886, 63, 4415, 275, 289, 3122, 14, 1814, 9520, 70, 3122, 401, 3680, 2124, 531, 272, 2729, 63, 8619, 275, 488, 272, 340, 747, 14, 515, 14, 2444, 8, 2124, 1886, 63, 4415, 304, 267, 543, 1551, 8, 2124, 1886, 63, 4415, 12, 283, 82, 358, 465, 11155, 26, 288, 2385, 275, 11155, 14, 9684, 342, 288, 862, 26, 355, 2729, 63, 8619, 275, 1211, 779, 2960, 8, 88, 14, 1913, 1252, 1294, 11854, 2237, 367, 671, 315, 2385, 566, 288, 871, 26, 221, 327, 2951, 282, 2849, 4770, 574, 355, 4770, 63, 533, 275, 2385, 59, 16, 1055, 1913, 342, 272, 587, 26, 267, 4770, 63, 533, 275, 298, 18, 2, 221, 327, 849, 339, 367, 1300, 498, 315, 1300, 1612, 26, 267, 790, 63, 1861, 275, 747, 14, 515, 14, 7973, 8, 736, 14, 515, 14, 4846, 8, 1095, 498, 11515, 16, 61, 267, 9854, 12, 12951, 275, 790, 63, 1861, 14, 1294, 26341, 398, 9854, 275, 9854, 14, 1814, 360, 1391, 20944, 267, 12951, 275, 12951, 14, 1814, 360, 6872, 20944, 267, 340, 2729, 63, 6872, 83, 436, 971, 1779, 334, 8759, 12, 12951, 9, 440, 315, 2729, 63, 6872, 83, 436, 334, 8759, 12, 8969, 531, 440, 315, 2729, 63, 6872, 83, 26, 288, 327, 870, 298, 9171, 12, 16068, 1300, 498, 12, 949, 9854, 15, 6872, 83, 2839, 401, 334, 8759, 12, 12951, 395, 298, 262, 401, 2729, 63, 6872, 83, 288, 1980, 221, 327, 8232, 652, 267, 870, 1867, 84, 450, 83, 450, 83, 2, 450, 334, 8759, 12, 12951, 9, 398, 340, 2729, 63, 8619, 26, 288, 327, 982, 4346, 12, 11311, 4770, 1021, 641, 282, 1126, 13, 8759, 5597, 288, 862, 26, 355, 4770, 63, 533, 275, 2729, 63, 8619, 59, 8759, 61, 288, 871, 26, 355, 4770, 63, 533, 275, 298, 18, 2, 327, 23347, 370, 849, 398, 862, 26, 288, 4770, 600, 275, 3743, 459, 2124 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 624, 1506, 63, 1612, 14, 647, 199, 199, 11493, 790, 1584, 687, 2199, 2082, 3035, 820, 88, 436, 28401, 666, 14, 199, 199, 9295, 4178, 921, 5031, 14, 957, 15, 37, 331, 15756, 15, 22890, 273, 13, 11481, 13, 2912, 3, 17952, 13, 1589, 13, 2912, 13, 3619, 13, 6976, 13, 504, 13, 1095, 13, 576, 199, 509, 2436, 641, 4212, 370, 663, 1536, 2195, 2199, 2082, 334, 2694, 5084, 9, 199, 199, 1715, 63, 3619, 199, 92, 306, 1101, 14, 1001, 199, 92, 306, 9288, 199, 92, 257, 1204, 306, 650, 1046, 1272, 14, 2764, 199, 92, 257, 1204, 306, 650, 1046, 1272, 14, 70, 3122, 199, 92, 257, 1204, 306, 650, 1046, 1272, 14, 2124, 199, 92, 257, 658, 306, 650, 1046, 1272, 14, 1516, 199, 64, 306, 12951, 272, 1204, 306, 2729, 55, 35, 63, 6872, 17, 14, 498, 272, 1204, 306, 2729, 55, 35, 63, 6872, 821, 14, 498, 272, 658, 306, 2387, 267, 658, 306, 23226, 471, 63, 583, 76, 14, 2424, 199, 199, 7692, 26, 523, 1900, 63, 1612, 14, 647, 359, 1419, 61, 359, 3022, 61, 523, 1900, 63, 1612, 14, 647, 5868, 72, 1204, 1553, 3437, 9, 523, 1900, 63, 1612, 14, 647, 1553, 1023, 199, 199, 4558, 26, 523, 446, 72, 1553, 3437, 263, 12968, 642, 6426, 14, 523, 1553, 4630, 18987, 8896, 30, 257, 4860, 402, 11952, 1849, 470, 359, 885, 26, 413, 61, 523, 1553, 1023, 263, 12968, 1015, 14, 199, 624, 199, 504, 886, 32626, 492, 886, 32626, 199, 504, 5145, 492, 1331, 493, 12, 20978, 199, 646, 747, 199, 646, 5739, 199, 646, 2022, 199, 504, 10321, 18, 492, 5458, 199, 646, 7975, 421, 199, 318, 1104, 63, 262, 694, 8, 262, 694, 304, 272, 408, 1852, 3238, 642, 9661, 4450, 314, 2746, 13, 1896, 9214, 408, 272, 327, 3254, 603, 5788, 17023, 21201, 20967, 2508, 4496, 272, 31396, 275, 359, 354, 367, 536, 315, 747, 14, 7374, 8, 262, 694, 9, 340, 747, 14, 515, 14, 6027, 8, 736, 14, 515, 14, 904, 8, 262, 694, 12, 536, 10524, 272, 1415, 275, 788, 6872, 297, 283, 2067, 418, 272, 367, 2648, 315, 1415, 26, 267, 340, 2648, 440, 315, 31396, 26, 288, 372, 756, 272, 372, 715, 199, 199, 318, 2562, 63, 7848, 8, 576, 304, 272, 372, 3550, 63, 498, 1725, 63, 509, 63, 2067, 2031, 576, 9, 199, 199, 318, 3550, 63, 498, 1725, 63, 509, 63, 2067, 8, 70, 3122, 12, 315, 694, 12, 19695, 694, 12, 3743, 12, 2387, 304, 272, 327, 3758, 4770, 3992, 4079, 641, 577, 38, 5238, 21897, 272, 849, 63, 2124, 63, 2888, 275, 469, 15166, 298, 17, 582, 298, 7917, 6012, 3515, 577, 38, 755, 30300, 260, 413, 401, 489, 298, 18, 582, 298, 7917, 6012, 3515, 577, 38, 755, 19163, 260, 413, 401, 489, 298, 19, 582, 298, 7917, 6012, 3515, 577, 38, 755, 20462, 260, 413, 401, 489, 298, 20, 582, 298, 7917, 6012, 3515, 577, 38, 263, 16412, 260, 413, 401, 489, 298, 21, 582, 298, 7917, 6012, 3515, 577, 38, 263, 16202, 260, 413, 3570, 339, 406, 14887, 275, 747, 14, 515, 14, 7973, 8, 736, 14, 515, 14, 4846, 8, 70, 3122, 11515, 16, 61, 272, 870, 298, 29244, 790, 1725, 367, 5558, 401, 406, 14887, 272, 5053, 275, 289, 3122, 14, 1814, 5175, 70, 3122, 26409, 2764, 358, 272, 2418, 275, 289, 3122, 14, 1814, 5175, 70, 3122, 26409, 1516, 358, 272, 12951, 493, 275, 289, 3122, 14, 1814, 5175, 70, 3122, 26409, 6872, 358, 339, 2418, 815, 63, 515, 275, 289, 3122, 14, 1814, 9520, 70, 3122, 401, 3680, 1516, 531, 272, 2418, 815, 275, 1551, 8, 1516, 815, 63, 515, 12, 283, 82, 1959, 739, 1252, 1913, 342, 339, 340, 747, 14, 515, 14, 2444, 8, 6872, 493, 304, 267, 543, 1551, 8, 6872, 493, 12, 283, 82, 358, 465, 11155, 26, 288, 2729, 63, 6872, 83, 275, 359, 2960, 8, 88, 14, 1913, 1252, 1294, 11854, 2237, 367, 671, 315, 11155, 14, 9684, 5106, 272, 587, 26, 267, 2729, 63, 6872, 83, 275, 488, 221, 327, 22660, 11727, 519, 7977, 664, 1255, 339, 5053, 275, 289, 3122, 14, 1814, 9520, 70, 3122, 401, 3680, 2764, 531, 339, 4770, 1886, 63, 4415, 275, 289, 3122, 14, 1814, 9520, 70, 3122, 401, 3680, 2124, 531, 272, 2729, 63, 8619, 275, 488, 272, 340, 747, 14, 515, 14, 2444, 8, 2124, 1886, 63, 4415, 304, 267, 543, 1551, 8, 2124, 1886, 63, 4415, 12, 283, 82, 358, 465, 11155, 26, 288, 2385, 275, 11155, 14, 9684, 342, 288, 862, 26, 355, 2729, 63, 8619, 275, 1211, 779, 2960, 8, 88, 14, 1913, 1252, 1294, 11854, 2237, 367, 671, 315, 2385, 566, 288, 871, 26, 221, 327, 2951, 282, 2849, 4770, 574, 355, 4770, 63, 533, 275, 2385, 59, 16, 1055, 1913, 342, 272, 587, 26, 267, 4770, 63, 533, 275, 298, 18, 2, 221, 327, 849, 339, 367, 1300, 498, 315, 1300, 1612, 26, 267, 790, 63, 1861, 275, 747, 14, 515, 14, 7973, 8, 736, 14, 515, 14, 4846, 8, 1095, 498, 11515, 16, 61, 267, 9854, 12, 12951, 275, 790, 63, 1861, 14, 1294, 26341, 398, 9854, 275, 9854, 14, 1814, 360, 1391, 20944, 267, 12951, 275, 12951, 14, 1814, 360, 6872, 20944, 267, 340, 2729, 63, 6872, 83, 436, 971, 1779, 334, 8759, 12, 12951, 9, 440, 315, 2729, 63, 6872, 83, 436, 334, 8759, 12, 8969, 531, 440, 315, 2729, 63, 6872, 83, 26, 288, 327, 870, 298, 9171, 12, 16068, 1300, 498, 12, 949, 9854, 15, 6872, 83, 2839, 401, 334, 8759, 12, 12951, 395, 298, 262, 401, 2729, 63, 6872, 83, 288, 1980, 221, 327, 8232, 652, 267, 870, 1867, 84, 450, 83, 450, 83, 2, 450, 334, 8759, 12, 12951, 9, 398, 340, 2729, 63, 8619, 26, 288, 327, 982, 4346, 12, 11311, 4770, 1021, 641, 282, 1126, 13, 8759, 5597, 288, 862, 26, 355, 4770, 63, 533, 275, 2729, 63, 8619, 59, 8759, 61, 288, 871, 26, 355, 4770, 63, 533, 275, 298, 18, 2, 327, 23347, 370, 849, 398, 862, 26, 288, 4770, 600, 275, 3743, 459, 2124, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
delighted/phantomjs
src/qt/qtwebkit/Tools/Scripts/webkitpy/tool/commands/queues_unittest.py
115
26224
# Copyright (C) 2009 Google Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os import StringIO from webkitpy.common.checkout.scm import CheckoutNeedsUpdate from webkitpy.common.checkout.scm.scm_mock import MockSCM from webkitpy.common.net.bugzilla import Attachment from webkitpy.common.system.outputcapture import OutputCapture from webkitpy.layout_tests.models import test_results from webkitpy.layout_tests.models import test_failures from webkitpy.thirdparty.mock import Mock from webkitpy.tool.commands.commandtest import CommandsTest from webkitpy.tool.commands.queues import * from webkitpy.tool.commands.queuestest import QueuesTest from webkitpy.tool.commands.stepsequence import StepSequence from webkitpy.common.net.statusserver_mock import MockStatusServer from webkitpy.tool.mocktool import MockTool, MockOptions class TestCommitQueue(CommitQueue): def __init__(self, tool=None): CommitQueue.__init__(self) if tool: self.bind_to_tool(tool) self._options = MockOptions(confirm=False, parent_command="commit-queue", port=None) def begin_work_queue(self): output_capture = OutputCapture() output_capture.capture_output() CommitQueue.begin_work_queue(self) output_capture.restore_output() class TestQueue(AbstractPatchQueue): name = "test-queue" class TestReviewQueue(AbstractReviewQueue): name = "test-review-queue" class TestFeederQueue(FeederQueue): _sleep_duration = 0 class AbstractQueueTest(CommandsTest): def test_log_directory(self): self.assertEqual(TestQueue()._log_directory(), os.path.join("..", "test-queue-logs")) def _assert_run_webkit_patch(self, run_args, port=None): queue = TestQueue() tool = MockTool() tool.status_server.bot_id = "gort" tool.executive = Mock() queue.bind_to_tool(tool) queue._options = Mock() queue._options.port = port queue.run_webkit_patch(run_args) expected_run_args = ["echo", "--status-host=example.com", "--bot-id=gort"] if port: expected_run_args.append("--port=%s" % port) expected_run_args.extend(run_args) tool.executive.run_command.assert_called_with(expected_run_args, cwd='/mock-checkout') def test_run_webkit_patch(self): self._assert_run_webkit_patch([1]) self._assert_run_webkit_patch(["one", 2]) self._assert_run_webkit_patch([1], port="mockport") def test_iteration_count(self): queue = TestQueue() queue._options = Mock() queue._options.iterations = 3 self.assertTrue(queue.should_continue_work_queue()) self.assertTrue(queue.should_continue_work_queue()) self.assertTrue(queue.should_continue_work_queue()) self.assertFalse(queue.should_continue_work_queue()) def test_no_iteration_count(self): queue = TestQueue() queue._options = Mock() self.assertTrue(queue.should_continue_work_queue()) self.assertTrue(queue.should_continue_work_queue()) self.assertTrue(queue.should_continue_work_queue()) self.assertTrue(queue.should_continue_work_queue()) def _assert_log_message(self, script_error, log_message): failure_log = AbstractQueue._log_from_script_error_for_upload(script_error, output_limit=10) self.assertTrue(failure_log.read(), log_message) def test_log_from_script_error_for_upload(self): self._assert_log_message(ScriptError("test"), "test") unicode_tor = u"WebKit \u2661 Tor Arne Vestb\u00F8!" utf8_tor = unicode_tor.encode("utf-8") self._assert_log_message(ScriptError(unicode_tor), utf8_tor) script_error = ScriptError(unicode_tor, output=unicode_tor) expected_output = "%s\nLast %s characters of output:\n%s" % (utf8_tor, 10, utf8_tor[-10:]) self._assert_log_message(script_error, expected_output) class FeederQueueTest(QueuesTest): def test_feeder_queue(self): queue = TestFeederQueue() tool = MockTool(log_executive=True) expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("feeder-queue"), "process_work_item": """Warning, attachment 10001 on bug 50000 has invalid committer (non-committer@example.com) Warning, attachment 10001 on bug 50000 has invalid committer (non-committer@example.com) MOCK setting flag 'commit-queue' to '-' on attachment '10001' with comment 'Rejecting attachment 10001 from commit-queue.\n\nnon-committer@example.com does not have committer permissions according to http://trac.webkit.org/browser/trunk/Tools/Scripts/webkitpy/common/config/committers.py. - If you do not have committer rights please read http://webkit.org/coding/contributing.html for instructions on how to use bugzilla flags. - If you have committer rights please correct the error in Tools/Scripts/webkitpy/common/config/committers.py by adding yourself to the file (no review needed). The commit-queue restarts itself every 2 hours. After restart the commit-queue will correctly respect your committer rights.' MOCK: update_work_items: commit-queue [10005, 10000] Feeding commit-queue items [10005, 10000] Feeding EWS (1 r? patch, 1 new) MOCK: submit_to_ews: 10002 """, "handle_unexpected_error": "Mock error message\n", } self.assert_queue_outputs(queue, tool=tool, expected_logs=expected_logs) class AbstractPatchQueueTest(CommandsTest): def test_next_patch(self): queue = AbstractPatchQueue() tool = MockTool() queue.bind_to_tool(tool) queue._options = Mock() queue._options.port = None self.assertIsNone(queue._next_patch()) tool.status_server = MockStatusServer(work_items=[2, 10000, 10001]) expected_stdout = "MOCK: fetch_attachment: 2 is not a known attachment id\n" # A mock-only message to prevent us from making mistakes. expected_logs = "MOCK: release_work_item: None 2\n" patch = OutputCapture().assert_outputs(self, queue._next_patch, expected_stdout=expected_stdout, expected_logs=expected_logs) # The patch.id() == 2 is ignored because it doesn't exist. self.assertEqual(patch.id(), 10000) self.assertEqual(queue._next_patch().id(), 10001) self.assertEqual(queue._next_patch(), None) # When the queue is empty class PatchProcessingQueueTest(CommandsTest): def test_upload_results_archive_for_patch(self): queue = PatchProcessingQueue() queue.name = "mock-queue" tool = MockTool() queue.bind_to_tool(tool) queue._options = Mock() queue._options.port = None patch = queue._tool.bugs.fetch_attachment(10001) expected_logs = """MOCK add_attachment_to_bug: bug_id=50000, description=Archive of layout-test-results from bot for mac-snowleopard filename=layout-test-results.zip mimetype=None -- Begin comment -- The attached test failures were seen while running run-webkit-tests on the mock-queue. Port: mac-snowleopard Platform: MockPlatform 1.0 -- End comment -- """ OutputCapture().assert_outputs(self, queue._upload_results_archive_for_patch, [patch, Mock()], expected_logs=expected_logs) class NeedsUpdateSequence(StepSequence): def _run(self, tool, options, state): raise CheckoutNeedsUpdate([], 1, "", None) class AlwaysCommitQueueTool(object): def __init__(self): self.status_server = MockStatusServer() def command_by_name(self, name): return CommitQueue class SecondThoughtsCommitQueue(TestCommitQueue): def __init__(self, tool=None): self._reject_patch = False TestCommitQueue.__init__(self, tool) def run_command(self, command): # We want to reject the patch after the first validation, # so wait to reject it until after some other command has run. self._reject_patch = True return CommitQueue.run_command(self, command) def refetch_patch(self, patch): if not self._reject_patch: return self._tool.bugs.fetch_attachment(patch.id()) attachment_dictionary = { "id": patch.id(), "bug_id": patch.bug_id(), "name": "Rejected", "is_obsolete": True, "is_patch": False, "review": "-", "reviewer_email": "foo@bar.com", "commit-queue": "-", "committer_email": "foo@bar.com", "attacher_email": "Contributer1", } return Attachment(attachment_dictionary, None) class CommitQueueTest(QueuesTest): def _mock_test_result(self, testname): return test_results.TestResult(testname, [test_failures.FailureTextMismatch()]) def test_commit_queue(self): tool = MockTool() tool.filesystem.write_text_file('/tmp/layout-test-results/full_results.json', '') # Otherwise the commit-queue will hit a KeyError trying to read the results from the MockFileSystem. tool.filesystem.write_text_file('/tmp/layout-test-results/webkit_unit_tests_output.xml', '') expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("commit-queue"), "process_work_item": """Running: webkit-patch --status-host=example.com clean --port=mac MOCK: update_status: commit-queue Cleaned working directory Running: webkit-patch --status-host=example.com update --port=mac MOCK: update_status: commit-queue Updated working directory Running: webkit-patch --status-host=example.com apply-attachment --no-update --non-interactive 10000 --port=mac MOCK: update_status: commit-queue Applied patch Running: webkit-patch --status-host=example.com validate-changelog --check-oops --non-interactive 10000 --port=mac MOCK: update_status: commit-queue ChangeLog validated Running: webkit-patch --status-host=example.com build --no-clean --no-update --build-style=release --port=mac MOCK: update_status: commit-queue Built patch Running: webkit-patch --status-host=example.com build-and-test --no-clean --no-update --test --non-interactive --port=mac MOCK: update_status: commit-queue Passed tests Running: webkit-patch --status-host=example.com land-attachment --force-clean --non-interactive --parent-command=commit-queue 10000 --port=mac MOCK: update_status: commit-queue Landed patch MOCK: update_status: commit-queue Pass MOCK: release_work_item: commit-queue 10000 """, "handle_script_error": "ScriptError error message\n\nMOCK output\n", "handle_unexpected_error": "MOCK setting flag 'commit-queue' to '-' on attachment '10000' with comment 'Rejecting attachment 10000 from commit-queue.\n\nMock error message'\n", } self.assert_queue_outputs(CommitQueue(), tool=tool, expected_logs=expected_logs) def test_commit_queue_failure(self): expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("commit-queue"), "process_work_item": """MOCK: update_status: commit-queue Cleaned working directory MOCK: update_status: commit-queue Updated working directory MOCK: update_status: commit-queue Patch does not apply MOCK setting flag 'commit-queue' to '-' on attachment '10000' with comment 'Rejecting attachment 10000 from commit-queue.\n\nMOCK script error Full output: http://dummy_url' MOCK: update_status: commit-queue Fail MOCK: release_work_item: commit-queue 10000 """, "handle_script_error": "ScriptError error message\n\nMOCK output\n", "handle_unexpected_error": "MOCK setting flag 'commit-queue' to '-' on attachment '10000' with comment 'Rejecting attachment 10000 from commit-queue.\n\nMock error message'\n", } queue = CommitQueue() def mock_run_webkit_patch(command): if command[0] == 'clean' or command[0] == 'update': # We want cleaning to succeed so we can error out on a step # that causes the commit-queue to reject the patch. return raise ScriptError('MOCK script error') queue.run_webkit_patch = mock_run_webkit_patch self.assert_queue_outputs(queue, expected_logs=expected_logs) def test_commit_queue_failure_with_failing_tests(self): expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("commit-queue"), "process_work_item": """MOCK: update_status: commit-queue Cleaned working directory MOCK: update_status: commit-queue Updated working directory MOCK: update_status: commit-queue Patch does not apply MOCK setting flag 'commit-queue' to '-' on attachment '10000' with comment 'Rejecting attachment 10000 from commit-queue.\n\nNew failing tests: mock_test_name.html another_test_name.html Full output: http://dummy_url' MOCK: update_status: commit-queue Fail MOCK: release_work_item: commit-queue 10000 """, "handle_script_error": "ScriptError error message\n\nMOCK output\n", "handle_unexpected_error": "MOCK setting flag 'commit-queue' to '-' on attachment '10000' with comment 'Rejecting attachment 10000 from commit-queue.\n\nMock error message'\n", } queue = CommitQueue() def mock_run_webkit_patch(command): if command[0] == 'clean' or command[0] == 'update': # We want cleaning to succeed so we can error out on a step # that causes the commit-queue to reject the patch. return queue._expected_failures.unexpected_failures_observed = lambda results: ["mock_test_name.html", "another_test_name.html"] raise ScriptError('MOCK script error') queue.run_webkit_patch = mock_run_webkit_patch self.assert_queue_outputs(queue, expected_logs=expected_logs) def test_rollout(self): tool = MockTool() tool.filesystem.write_text_file('/tmp/layout-test-results/full_results.json', '') # Otherwise the commit-queue will hit a KeyError trying to read the results from the MockFileSystem. tool.filesystem.write_text_file('/tmp/layout-test-results/webkit_unit_tests_output.xml', '') tool.buildbot.light_tree_on_fire() expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("commit-queue"), "process_work_item": """Running: webkit-patch --status-host=example.com clean --port=%(port)s MOCK: update_status: commit-queue Cleaned working directory Running: webkit-patch --status-host=example.com update --port=%(port)s MOCK: update_status: commit-queue Updated working directory Running: webkit-patch --status-host=example.com apply-attachment --no-update --non-interactive 10000 --port=%(port)s MOCK: update_status: commit-queue Applied patch Running: webkit-patch --status-host=example.com validate-changelog --check-oops --non-interactive 10000 --port=%(port)s MOCK: update_status: commit-queue ChangeLog validated Running: webkit-patch --status-host=example.com build --no-clean --no-update --build-style=release --port=%(port)s MOCK: update_status: commit-queue Built patch Running: webkit-patch --status-host=example.com build-and-test --no-clean --no-update --test --non-interactive --port=%(port)s MOCK: update_status: commit-queue Passed tests Running: webkit-patch --status-host=example.com land-attachment --force-clean --non-interactive --parent-command=commit-queue 10000 --port=%(port)s MOCK: update_status: commit-queue Landed patch MOCK: update_status: commit-queue Pass MOCK: release_work_item: commit-queue 10000 """ % {"port": "mac"}, "handle_script_error": "ScriptError error message\n\nMOCK output\n", "handle_unexpected_error": "MOCK setting flag 'commit-queue' to '-' on attachment '10000' with comment 'Rejecting attachment 10000 from commit-queue.\n\nMock error message'\n", } self.assert_queue_outputs(CommitQueue(), tool=tool, expected_logs=expected_logs) def test_rollout_lands(self): tool = MockTool() tool.buildbot.light_tree_on_fire() rollout_patch = tool.bugs.fetch_attachment(10005) # _patch6, a rollout patch. assert(rollout_patch.is_rollout()) expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("commit-queue"), "process_work_item": """Running: webkit-patch --status-host=example.com clean --port=%(port)s MOCK: update_status: commit-queue Cleaned working directory Running: webkit-patch --status-host=example.com update --port=%(port)s MOCK: update_status: commit-queue Updated working directory Running: webkit-patch --status-host=example.com apply-attachment --no-update --non-interactive 10005 --port=%(port)s MOCK: update_status: commit-queue Applied patch Running: webkit-patch --status-host=example.com validate-changelog --check-oops --non-interactive 10005 --port=%(port)s MOCK: update_status: commit-queue ChangeLog validated Running: webkit-patch --status-host=example.com land-attachment --force-clean --non-interactive --parent-command=commit-queue 10005 --port=%(port)s MOCK: update_status: commit-queue Landed patch MOCK: update_status: commit-queue Pass MOCK: release_work_item: commit-queue 10005 """ % {"port": "mac"}, "handle_script_error": "ScriptError error message\n\nMOCK output\n", "handle_unexpected_error": "MOCK setting flag 'commit-queue' to '-' on attachment '10005' with comment 'Rejecting attachment 10005 from commit-queue.\n\nMock error message'\n", } self.assert_queue_outputs(CommitQueue(), tool=tool, work_item=rollout_patch, expected_logs=expected_logs) def test_auto_retry(self): queue = CommitQueue() options = Mock() options.parent_command = "commit-queue" tool = AlwaysCommitQueueTool() sequence = NeedsUpdateSequence(None) expected_logs = """Commit failed because the checkout is out of date. Please update and try again. MOCK: update_status: commit-queue Tests passed, but commit failed (checkout out of date). Updating, then landing without building or re-running tests. """ state = {'patch': None} OutputCapture().assert_outputs(self, sequence.run_and_handle_errors, [tool, options, state], expected_exception=TryAgain, expected_logs=expected_logs) self.assertTrue(options.update) self.assertFalse(options.build) self.assertFalse(options.test) def test_manual_reject_during_processing(self): queue = SecondThoughtsCommitQueue(MockTool()) queue.begin_work_queue() queue._tool.filesystem.write_text_file('/tmp/layout-test-results/full_results.json', '') # Otherwise the commit-queue will hit a KeyError trying to read the results from the MockFileSystem. queue._tool.filesystem.write_text_file('/tmp/layout-test-results/webkit_unit_tests_output.xml', '') queue._options = Mock() queue._options.port = None expected_logs = """Running: webkit-patch --status-host=example.com clean --port=mac MOCK: update_status: commit-queue Cleaned working directory Running: webkit-patch --status-host=example.com update --port=mac MOCK: update_status: commit-queue Updated working directory Running: webkit-patch --status-host=example.com apply-attachment --no-update --non-interactive 10000 --port=mac MOCK: update_status: commit-queue Applied patch Running: webkit-patch --status-host=example.com validate-changelog --check-oops --non-interactive 10000 --port=mac MOCK: update_status: commit-queue ChangeLog validated Running: webkit-patch --status-host=example.com build --no-clean --no-update --build-style=release --port=mac MOCK: update_status: commit-queue Built patch Running: webkit-patch --status-host=example.com build-and-test --no-clean --no-update --test --non-interactive --port=mac MOCK: update_status: commit-queue Passed tests MOCK: update_status: commit-queue Retry MOCK: release_work_item: commit-queue 10000 """ self.maxDiff = None OutputCapture().assert_outputs(self, queue.process_work_item, [QueuesTest.mock_work_item], expected_logs=expected_logs) def test_report_flaky_tests(self): queue = TestCommitQueue(MockTool()) expected_logs = """MOCK bug comment: bug_id=50002, cc=None --- Begin comment --- The commit-queue just saw foo/bar.html flake (text diff) while processing attachment 10000 on bug 50000. Port: MockPort Platform: MockPlatform 1.0 --- End comment --- MOCK add_attachment_to_bug: bug_id=50002, description=Failure diff from bot filename=failure.diff mimetype=None MOCK bug comment: bug_id=50002, cc=None --- Begin comment --- The commit-queue just saw bar/baz.html flake (text diff) while processing attachment 10000 on bug 50000. Port: MockPort Platform: MockPlatform 1.0 --- End comment --- bar/baz-diffs.txt does not exist in results archive, uploading entire archive. MOCK add_attachment_to_bug: bug_id=50002, description=Archive of layout-test-results from bot filename=layout-test-results.zip mimetype=None MOCK bug comment: bug_id=50000, cc=None --- Begin comment --- The commit-queue encountered the following flaky tests while processing attachment 10000: foo/bar.html bug 50002 (author: abarth@webkit.org) bar/baz.html bug 50002 (author: abarth@webkit.org) The commit-queue is continuing to process your patch. --- End comment --- """ test_names = ["foo/bar.html", "bar/baz.html"] test_results = [self._mock_test_result(name) for name in test_names] class MockZipFile(object): def __init__(self): self.fp = StringIO() def read(self, path): return "" def namelist(self): # This is intentionally missing one diffs.txt to exercise the "upload the whole zip" codepath. return ['foo/bar-diffs.txt'] OutputCapture().assert_outputs(self, queue.report_flaky_tests, [QueuesTest.mock_work_item, test_results, MockZipFile()], expected_logs=expected_logs) def test_did_pass_testing_ews(self): tool = MockTool() patch = tool.bugs.fetch_attachment(10000) queue = TestCommitQueue(tool) self.assertFalse(queue.did_pass_testing_ews(patch)) class StyleQueueTest(QueuesTest): def test_style_queue_with_style_exception(self): expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("style-queue"), "process_work_item": """Running: webkit-patch --status-host=example.com clean MOCK: update_status: style-queue Cleaned working directory Running: webkit-patch --status-host=example.com update MOCK: update_status: style-queue Updated working directory Running: webkit-patch --status-host=example.com apply-attachment --no-update --non-interactive 10000 MOCK: update_status: style-queue Applied patch Running: webkit-patch --status-host=example.com apply-watchlist-local 50000 MOCK: update_status: style-queue Watchlist applied Running: webkit-patch --status-host=example.com check-style-local --non-interactive --quiet MOCK: update_status: style-queue Style checked MOCK: update_status: style-queue Pass MOCK: release_work_item: style-queue 10000 """, "handle_unexpected_error": "Mock error message\n", "handle_script_error": "MOCK output\n", } tool = MockTool(executive_throws_when_run=set(['check-style'])) self.assert_queue_outputs(StyleQueue(), expected_logs=expected_logs, tool=tool) def test_style_queue_with_watch_list_exception(self): expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("style-queue"), "process_work_item": """Running: webkit-patch --status-host=example.com clean MOCK: update_status: style-queue Cleaned working directory Running: webkit-patch --status-host=example.com update MOCK: update_status: style-queue Updated working directory Running: webkit-patch --status-host=example.com apply-attachment --no-update --non-interactive 10000 MOCK: update_status: style-queue Applied patch Running: webkit-patch --status-host=example.com apply-watchlist-local 50000 Exception for ['echo', '--status-host=example.com', 'apply-watchlist-local', 50000] MOCK command output MOCK: update_status: style-queue Unabled to apply watchlist Running: webkit-patch --status-host=example.com check-style-local --non-interactive --quiet MOCK: update_status: style-queue Style checked MOCK: update_status: style-queue Pass MOCK: release_work_item: style-queue 10000 """, "handle_unexpected_error": "Mock error message\n", "handle_script_error": "MOCK output\n", } tool = MockTool(executive_throws_when_run=set(['apply-watchlist-local'])) self.assert_queue_outputs(StyleQueue(), expected_logs=expected_logs, tool=tool)
bsd-3-clause
[ 3, 1898, 334, 35, 9, 8937, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 259, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 259, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 259, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 646, 747, 199, 646, 5228, 199, 199, 504, 18007, 14, 2330, 14, 12891, 14, 17143, 492, 2670, 548, 28390, 4152, 199, 504, 18007, 14, 2330, 14, 12891, 14, 17143, 14, 17143, 63, 1805, 492, 4420, 5153, 45, 199, 504, 18007, 14, 2330, 14, 846, 14, 29220, 492, 21328, 434, 199, 504, 18007, 14, 2330, 14, 2253, 14, 1199, 12685, 492, 7242, 16640, 199, 504, 18007, 14, 4209, 63, 2219, 14, 992, 492, 511, 63, 2604, 199, 504, 18007, 14, 4209, 63, 2219, 14, 992, 492, 511, 63, 9968, 199, 504, 18007, 14, 11470, 7522, 14, 1805, 492, 4420, 199, 504, 18007, 14, 3557, 14, 4405, 14, 1531, 396, 492, 5817, 26935, 199, 504, 18007, 14, 3557, 14, 4405, 14, 18849, 492, 627, 199, 504, 18007, 14, 3557, 14, 4405, 14, 18849, 396, 492, 10703, 26935, 199, 504, 18007, 14, 3557, 14, 4405, 14, 2926, 4041, 492, 13382, 5826, 199, 504, 18007, 14, 2330, 14, 846, 14, 1205, 1000, 63, 1805, 492, 4420, 3694, 3120, 199, 504, 18007, 14, 3557, 14, 1805, 3557, 492, 4420, 5157, 12, 4420, 4558, 421, 199, 533, 1379, 11421, 3737, 8, 11421, 3737, 304, 272, 347, 636, 826, 721, 277, 12, 4744, 29, 403, 304, 267, 21447, 3737, 855, 826, 721, 277, 9, 267, 340, 4744, 26, 288, 291, 14, 3409, 63, 475, 63, 3557, 8, 3557, 9, 267, 291, 423, 1419, 275, 4420, 4558, 8, 9548, 29, 797, 12, 1676, 63, 1531, 628, 3543, 13, 1825, 401, 1844, 29, 403, 9, 339, 347, 5386, 63, 800, 63, 1825, 8, 277, 304, 267, 1072, 63, 12685, 275, 7242, 16640, 342, 267, 1072, 63, 12685, 14, 12685, 63, 1199, 342, 267, 21447, 3737, 14, 5037, 63, 800, 63, 1825, 8, 277, 9, 267, 1072, 63, 12685, 14, 8011, 63, 1199, 342, 421, 199, 533, 1379, 3737, 8, 8458, 11173, 3737, 304, 272, 536, 275, 298, 396, 13, 1825, 2, 421, 199, 533, 1379, 21000, 3737, 8, 8458, 21000, 3737, 304, 272, 536, 275, 298, 396, 13, 8578, 13, 1825, 2, 421, 199, 533, 1379, 28042, 424, 3737, 8, 28042, 424, 3737, 304, 272, 485, 4532, 63, 5553, 275, 378, 421, 199, 533, 11836, 3737, 774, 8, 14680, 774, 304, 272, 347, 511, 63, 793, 63, 3619, 8, 277, 304, 267, 291, 14, 629, 8, 774, 3737, 19050, 793, 63, 3619, 1062, 747, 14, 515, 14, 904, 480, 703, 401, 298, 396, 13, 1825, 13, 7270, 2237, 339, 347, 485, 479, 63, 1065, 63, 12554, 63, 2068, 8, 277, 12, 1255, 63, 589, 12, 1844, 29, 403, 304, 267, 4126, 275, 1379, 3737, 342, 267, 4744, 275, 4420, 5157, 342, 267, 4744, 14, 1205, 63, 1000, 14, 3018, 63, 344, 275, 298, 71, 361, 2, 267, 4744, 14, 1628, 13441, 275, 4420, 342, 267, 4126, 14, 3409, 63, 475, 63, 3557, 8, 3557, 9, 267, 4126, 423, 1419, 275, 4420, 342, 267, 4126, 423, 1419, 14, 719, 275, 1844, 398, 4126, 14, 1065, 63, 12554, 63, 2068, 8, 1065, 63, 589, 9, 267, 1420, 63, 1065, 63, 589, 275, 2097, 7878, 401, 4320, 1205, 13, 1102, 29, 2694, 14, 957, 401, 4320, 3018, 13, 344, 29, 71, 361, 937, 267, 340, 1844, 26, 288, 1420, 63, 1065, 63, 589, 14, 740, 6739, 719, 2458, 83, 2, 450, 1844, 9, 267, 1420, 63, 1065, 63, 589, 14, 2880, 8, 1065, 63, 589, 9, 267, 4744, 14, 1628, 13441, 14, 1065, 63, 1531, 14, 479, 63, 3527, 63, 1045, 8, 2062, 63, 1065, 63, 589, 12, 8288, 8805, 1805, 13, 12891, 358, 339, 347, 511, 63, 1065, 63, 12554, 63, 2068, 8, 277, 304, 267, 291, 423, 479, 63, 1065, 63, 12554, 63, 2068, 779, 17, 566, 267, 291, 423, 479, 63, 1065, 63, 12554, 63, 2068, 5234, 368, 401, 499, 566, 267, 291, 423, 479, 63, 1065, 63, 12554, 63, 2068, 779, 17, 467, 1844, 628, 1805, 719, 531, 339, 347, 511, 63, 12575, 63, 835, 8, 277, 304, 267, 4126, 275, 1379, 3737, 342, 267, 4126, 423, 1419, 275, 4420, 342, 267, 4126, 423, 1419, 14, 13570, 275, 650, 267, 291, 14, 1815, 8, 1825, 14, 5626, 63, 6958, 63, 800, 63, 1825, 1012, 267, 291, 14, 1815, 8, 1825, 14, 5626, 63, 6958, 63, 800, 63, 1825, 1012, 267 ]
[ 1898, 334, 35, 9, 8937, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 259, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 259, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 259, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 646, 747, 199, 646, 5228, 199, 199, 504, 18007, 14, 2330, 14, 12891, 14, 17143, 492, 2670, 548, 28390, 4152, 199, 504, 18007, 14, 2330, 14, 12891, 14, 17143, 14, 17143, 63, 1805, 492, 4420, 5153, 45, 199, 504, 18007, 14, 2330, 14, 846, 14, 29220, 492, 21328, 434, 199, 504, 18007, 14, 2330, 14, 2253, 14, 1199, 12685, 492, 7242, 16640, 199, 504, 18007, 14, 4209, 63, 2219, 14, 992, 492, 511, 63, 2604, 199, 504, 18007, 14, 4209, 63, 2219, 14, 992, 492, 511, 63, 9968, 199, 504, 18007, 14, 11470, 7522, 14, 1805, 492, 4420, 199, 504, 18007, 14, 3557, 14, 4405, 14, 1531, 396, 492, 5817, 26935, 199, 504, 18007, 14, 3557, 14, 4405, 14, 18849, 492, 627, 199, 504, 18007, 14, 3557, 14, 4405, 14, 18849, 396, 492, 10703, 26935, 199, 504, 18007, 14, 3557, 14, 4405, 14, 2926, 4041, 492, 13382, 5826, 199, 504, 18007, 14, 2330, 14, 846, 14, 1205, 1000, 63, 1805, 492, 4420, 3694, 3120, 199, 504, 18007, 14, 3557, 14, 1805, 3557, 492, 4420, 5157, 12, 4420, 4558, 421, 199, 533, 1379, 11421, 3737, 8, 11421, 3737, 304, 272, 347, 636, 826, 721, 277, 12, 4744, 29, 403, 304, 267, 21447, 3737, 855, 826, 721, 277, 9, 267, 340, 4744, 26, 288, 291, 14, 3409, 63, 475, 63, 3557, 8, 3557, 9, 267, 291, 423, 1419, 275, 4420, 4558, 8, 9548, 29, 797, 12, 1676, 63, 1531, 628, 3543, 13, 1825, 401, 1844, 29, 403, 9, 339, 347, 5386, 63, 800, 63, 1825, 8, 277, 304, 267, 1072, 63, 12685, 275, 7242, 16640, 342, 267, 1072, 63, 12685, 14, 12685, 63, 1199, 342, 267, 21447, 3737, 14, 5037, 63, 800, 63, 1825, 8, 277, 9, 267, 1072, 63, 12685, 14, 8011, 63, 1199, 342, 421, 199, 533, 1379, 3737, 8, 8458, 11173, 3737, 304, 272, 536, 275, 298, 396, 13, 1825, 2, 421, 199, 533, 1379, 21000, 3737, 8, 8458, 21000, 3737, 304, 272, 536, 275, 298, 396, 13, 8578, 13, 1825, 2, 421, 199, 533, 1379, 28042, 424, 3737, 8, 28042, 424, 3737, 304, 272, 485, 4532, 63, 5553, 275, 378, 421, 199, 533, 11836, 3737, 774, 8, 14680, 774, 304, 272, 347, 511, 63, 793, 63, 3619, 8, 277, 304, 267, 291, 14, 629, 8, 774, 3737, 19050, 793, 63, 3619, 1062, 747, 14, 515, 14, 904, 480, 703, 401, 298, 396, 13, 1825, 13, 7270, 2237, 339, 347, 485, 479, 63, 1065, 63, 12554, 63, 2068, 8, 277, 12, 1255, 63, 589, 12, 1844, 29, 403, 304, 267, 4126, 275, 1379, 3737, 342, 267, 4744, 275, 4420, 5157, 342, 267, 4744, 14, 1205, 63, 1000, 14, 3018, 63, 344, 275, 298, 71, 361, 2, 267, 4744, 14, 1628, 13441, 275, 4420, 342, 267, 4126, 14, 3409, 63, 475, 63, 3557, 8, 3557, 9, 267, 4126, 423, 1419, 275, 4420, 342, 267, 4126, 423, 1419, 14, 719, 275, 1844, 398, 4126, 14, 1065, 63, 12554, 63, 2068, 8, 1065, 63, 589, 9, 267, 1420, 63, 1065, 63, 589, 275, 2097, 7878, 401, 4320, 1205, 13, 1102, 29, 2694, 14, 957, 401, 4320, 3018, 13, 344, 29, 71, 361, 937, 267, 340, 1844, 26, 288, 1420, 63, 1065, 63, 589, 14, 740, 6739, 719, 2458, 83, 2, 450, 1844, 9, 267, 1420, 63, 1065, 63, 589, 14, 2880, 8, 1065, 63, 589, 9, 267, 4744, 14, 1628, 13441, 14, 1065, 63, 1531, 14, 479, 63, 3527, 63, 1045, 8, 2062, 63, 1065, 63, 589, 12, 8288, 8805, 1805, 13, 12891, 358, 339, 347, 511, 63, 1065, 63, 12554, 63, 2068, 8, 277, 304, 267, 291, 423, 479, 63, 1065, 63, 12554, 63, 2068, 779, 17, 566, 267, 291, 423, 479, 63, 1065, 63, 12554, 63, 2068, 5234, 368, 401, 499, 566, 267, 291, 423, 479, 63, 1065, 63, 12554, 63, 2068, 779, 17, 467, 1844, 628, 1805, 719, 531, 339, 347, 511, 63, 12575, 63, 835, 8, 277, 304, 267, 4126, 275, 1379, 3737, 342, 267, 4126, 423, 1419, 275, 4420, 342, 267, 4126, 423, 1419, 14, 13570, 275, 650, 267, 291, 14, 1815, 8, 1825, 14, 5626, 63, 6958, 63, 800, 63, 1825, 1012, 267, 291, 14, 1815, 8, 1825, 14, 5626, 63, 6958, 63, 800, 63, 1825, 1012, 267, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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- coding: utf-8; -*- # # This file is part of Superdesk. # # Copyright 2018 Sourcefabric z.u. and contributors. # # For the full copyright and license information, please see the # AUTHORS and LICENSE files distributed with this source code, or # at https://www.sourcefabric.org/superdesk/license from superdesk.io.registry import register_feed_parser from superdesk.io.feed_parsers.newsml_2_0 import NewsMLTwoFeedParser from .utils import ingest_category_from_subject, filter_missing_subjects, set_default_service class NTBNewsMLTwoFeedParser(NewsMLTwoFeedParser): NAME = 'ntbnewsml2' label = 'NTB NewsML-G2 Parser' def parse(self, xml, provider=None): items = super().parse(xml, provider) for item in items: item['slugline'] = '' category = ingest_category_from_subject(item.get('subject')) # check for sports using all ingested subjects item['subject'] = filter_missing_subjects(item.get('subject')) item['subject'].append(category) urgency = item.get('urgency', None) if urgency == 2: item['urgency'] = 3 elif urgency == 4: item['urgency'] = 5 set_default_service(item) return items register_feed_parser(NTBNewsMLTwoFeedParser.NAME, NTBNewsMLTwoFeedParser())
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 27, 1882, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 17897, 10368, 14, 199, 3, 199, 3, 1898, 14894, 5800, 4991, 1315, 14, 85, 14, 436, 8417, 14, 199, 3, 199, 3, 2104, 314, 2615, 4248, 436, 4190, 2556, 12, 8749, 1937, 314, 199, 3, 10610, 436, 5113, 1584, 1854, 543, 642, 1350, 1233, 12, 503, 199, 3, 737, 4178, 921, 1544, 14, 1365, 4991, 14, 1308, 15, 4792, 10368, 15, 1682, 199, 199, 504, 1613, 10368, 14, 2308, 14, 5189, 492, 2274, 63, 3871, 63, 2087, 199, 504, 1613, 10368, 14, 2308, 14, 3871, 63, 11531, 14, 13224, 757, 63, 18, 63, 16, 492, 30951, 1698, 11467, 7658, 2842, 199, 504, 1275, 1208, 492, 315, 3199, 63, 3710, 63, 504, 63, 5875, 12, 2457, 63, 4752, 63, 25660, 12, 663, 63, 885, 63, 1364, 421, 199, 533, 653, 20098, 24730, 1698, 11467, 7658, 2842, 8, 24730, 1698, 11467, 7658, 2842, 304, 339, 13637, 275, 283, 343, 66, 13224, 757, 18, 7, 272, 1768, 275, 283, 12460, 34, 30951, 1698, 13, 39, 18, 10191, 7, 339, 347, 2198, 8, 277, 12, 2748, 12, 5022, 29, 403, 304, 267, 2974, 275, 1613, 1252, 1122, 8, 1652, 12, 5022, 9, 267, 367, 1242, 315, 2974, 26, 288, 1242, 459, 5464, 604, 418, 275, 2125, 288, 4637, 275, 315, 3199, 63, 3710, 63, 504, 63, 5875, 8, 1053, 14, 362, 360, 5875, 1333, 221, 327, 1104, 367, 308, 5203, 1808, 1006, 315, 16663, 32446, 288, 1242, 459, 5875, 418, 275, 2457, 63, 4752, 63, 25660, 8, 1053, 14, 362, 360, 5875, 1333, 288, 1242, 459, 5875, 2278, 740, 8, 3710, 9, 953, 7629, 27798, 275, 1242, 14, 362, 360, 300, 27798, 297, 488, 9, 288, 340, 7629, 27798, 508, 499, 26, 355, 1242, 459, 300, 27798, 418, 275, 650, 288, 916, 7629, 27798, 508, 841, 26, 355, 1242, 459, 300, 27798, 418, 275, 959, 953, 663, 63, 885, 63, 1364, 8, 1053, 9, 267, 372, 2974, 421, 199, 2683, 63, 3871, 63, 2087, 8, 12460, 34, 24730, 1698, 11467, 7658, 2842, 14, 2339, 12, 653, 20098, 24730, 1698, 11467, 7658, 2842, 1012, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 27, 1882, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 17897, 10368, 14, 199, 3, 199, 3, 1898, 14894, 5800, 4991, 1315, 14, 85, 14, 436, 8417, 14, 199, 3, 199, 3, 2104, 314, 2615, 4248, 436, 4190, 2556, 12, 8749, 1937, 314, 199, 3, 10610, 436, 5113, 1584, 1854, 543, 642, 1350, 1233, 12, 503, 199, 3, 737, 4178, 921, 1544, 14, 1365, 4991, 14, 1308, 15, 4792, 10368, 15, 1682, 199, 199, 504, 1613, 10368, 14, 2308, 14, 5189, 492, 2274, 63, 3871, 63, 2087, 199, 504, 1613, 10368, 14, 2308, 14, 3871, 63, 11531, 14, 13224, 757, 63, 18, 63, 16, 492, 30951, 1698, 11467, 7658, 2842, 199, 504, 1275, 1208, 492, 315, 3199, 63, 3710, 63, 504, 63, 5875, 12, 2457, 63, 4752, 63, 25660, 12, 663, 63, 885, 63, 1364, 421, 199, 533, 653, 20098, 24730, 1698, 11467, 7658, 2842, 8, 24730, 1698, 11467, 7658, 2842, 304, 339, 13637, 275, 283, 343, 66, 13224, 757, 18, 7, 272, 1768, 275, 283, 12460, 34, 30951, 1698, 13, 39, 18, 10191, 7, 339, 347, 2198, 8, 277, 12, 2748, 12, 5022, 29, 403, 304, 267, 2974, 275, 1613, 1252, 1122, 8, 1652, 12, 5022, 9, 267, 367, 1242, 315, 2974, 26, 288, 1242, 459, 5464, 604, 418, 275, 2125, 288, 4637, 275, 315, 3199, 63, 3710, 63, 504, 63, 5875, 8, 1053, 14, 362, 360, 5875, 1333, 221, 327, 1104, 367, 308, 5203, 1808, 1006, 315, 16663, 32446, 288, 1242, 459, 5875, 418, 275, 2457, 63, 4752, 63, 25660, 8, 1053, 14, 362, 360, 5875, 1333, 288, 1242, 459, 5875, 2278, 740, 8, 3710, 9, 953, 7629, 27798, 275, 1242, 14, 362, 360, 300, 27798, 297, 488, 9, 288, 340, 7629, 27798, 508, 499, 26, 355, 1242, 459, 300, 27798, 418, 275, 650, 288, 916, 7629, 27798, 508, 841, 26, 355, 1242, 459, 300, 27798, 418, 275, 959, 953, 663, 63, 885, 63, 1364, 8, 1053, 9, 267, 372, 2974, 421, 199, 2683, 63, 3871, 63, 2087, 8, 12460, 34, 24730, 1698, 11467, 7658, 2842, 14, 2339, 12, 653, 20098, 24730, 1698, 11467, 7658, 2842, 1012, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
AudreyFrancisco/AliPhysics
PWGJE/EMCALJetTasks/Tracks/analysis/base/ResultDataBuilder.py
41
1799
#************************************************************************** #* Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. * #* * #* Author: The ALICE Off-line Project. * #* Contributors are mentioned in the code where appropriate. * #* * #* Permission to use, copy, modify and distribute this software and its * #* documentation strictly for non-commercial purposes is hereby granted * #* without fee, provided that the above copyright notice appears in all * #* copies and that both the copyright notice and this permission notice * #* appear in the supporting documentation. The authors make no claims * #* about the suitability of this software for any purpose. It is * #* provided "as is" without express or implied warranty. * #************************************************************************** from PWGJE.EMCALJetTasks.Tracks.analysis.base.FileHandler import LegoTrainFileReader, ResultStructureReader class ResultDataBuilder(object): """ General data structure builder interfacing different input file formats """ def __init__(self, filetype, filename): """ Constructor """ reader = None if filetype == "lego": reader = LegoTrainFileReader(filename) elif filetype == "resultfile": reader = ResultStructureReader(filename) self.__results = None if reader: self.__results = reader.ReadFile() def GetResults(self): """ Access to data """ return self.__results
bsd-3-clause
[ 3, 14355, 538, 199, 15002, 1898, 8, 67, 9, 19960, 13, 7280, 12, 437, 2507, 37, 23997, 737, 24354, 12, 2900, 4481, 4644, 14, 627, 199, 15002, 6208, 263, 627, 199, 15002, 6529, 26, 710, 437, 2507, 37, 28856, 13, 604, 7290, 14, 27503, 627, 199, 15002, 23212, 787, 26239, 315, 314, 1233, 2382, 5827, 14, 4519, 627, 199, 15002, 6208, 263, 627, 199, 15002, 8779, 370, 675, 12, 1331, 12, 2811, 436, 11207, 642, 2032, 436, 2399, 257, 627, 199, 15002, 3794, 22699, 367, 2222, 13, 957, 23012, 12901, 365, 11882, 10009, 257, 627, 199, 15002, 1928, 14751, 12, 2741, 626, 314, 3432, 4248, 4245, 11337, 315, 1006, 257, 627, 199, 15002, 6866, 436, 626, 3865, 314, 4248, 4245, 436, 642, 4983, 4245, 257, 627, 199, 15002, 7468, 315, 314, 21038, 3794, 14, 710, 11462, 1852, 949, 6108, 11171, 258, 627, 199, 15002, 3595, 314, 308, 4993, 3616, 402, 642, 2032, 367, 1263, 12016, 14, 2779, 365, 3515, 627, 199, 15002, 2741, 298, 305, 365, 2, 1928, 4056, 503, 2478, 3750, 14, 8295, 627, 199, 3, 14355, 538, 199, 504, 510, 55, 39, 25074, 14, 2769, 13329, 42, 386, 19295, 14, 2437, 5618, 14, 10466, 14, 1095, 14, 21982, 492, 7005, 1939, 18591, 1173, 5929, 12, 10695, 10766, 5929, 199, 199, 533, 10695, 1451, 6437, 8, 785, 304, 272, 408, 272, 1696, 666, 5523, 6545, 1640, 32552, 3365, 1324, 570, 6752, 272, 408, 2286, 347, 636, 826, 721, 277, 12, 26245, 12, 1788, 304, 267, 408, 267, 20297, 267, 408, 267, 7002, 275, 488, 267, 340, 26245, 508, 298, 274, 1939, 582, 288, 7002, 275, 7005, 1939, 18591, 1173, 5929, 8, 1501, 9, 267, 916, 26245, 508, 298, 1099, 493, 582, 288, 7002, 275, 10695, 10766, 5929, 8, 1501, 9, 267, 291, 855, 2604, 275, 488, 267, 340, 7002, 26, 288, 291, 855, 2604, 275, 7002, 14, 32356, 342, 15567, 347, 2372, 6579, 8, 277, 304, 267, 408, 267, 11003, 370, 666, 267, 408, 267, 372, 291, 855, 2604, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 14355, 538, 199, 15002, 1898, 8, 67, 9, 19960, 13, 7280, 12, 437, 2507, 37, 23997, 737, 24354, 12, 2900, 4481, 4644, 14, 627, 199, 15002, 6208, 263, 627, 199, 15002, 6529, 26, 710, 437, 2507, 37, 28856, 13, 604, 7290, 14, 27503, 627, 199, 15002, 23212, 787, 26239, 315, 314, 1233, 2382, 5827, 14, 4519, 627, 199, 15002, 6208, 263, 627, 199, 15002, 8779, 370, 675, 12, 1331, 12, 2811, 436, 11207, 642, 2032, 436, 2399, 257, 627, 199, 15002, 3794, 22699, 367, 2222, 13, 957, 23012, 12901, 365, 11882, 10009, 257, 627, 199, 15002, 1928, 14751, 12, 2741, 626, 314, 3432, 4248, 4245, 11337, 315, 1006, 257, 627, 199, 15002, 6866, 436, 626, 3865, 314, 4248, 4245, 436, 642, 4983, 4245, 257, 627, 199, 15002, 7468, 315, 314, 21038, 3794, 14, 710, 11462, 1852, 949, 6108, 11171, 258, 627, 199, 15002, 3595, 314, 308, 4993, 3616, 402, 642, 2032, 367, 1263, 12016, 14, 2779, 365, 3515, 627, 199, 15002, 2741, 298, 305, 365, 2, 1928, 4056, 503, 2478, 3750, 14, 8295, 627, 199, 3, 14355, 538, 199, 504, 510, 55, 39, 25074, 14, 2769, 13329, 42, 386, 19295, 14, 2437, 5618, 14, 10466, 14, 1095, 14, 21982, 492, 7005, 1939, 18591, 1173, 5929, 12, 10695, 10766, 5929, 199, 199, 533, 10695, 1451, 6437, 8, 785, 304, 272, 408, 272, 1696, 666, 5523, 6545, 1640, 32552, 3365, 1324, 570, 6752, 272, 408, 2286, 347, 636, 826, 721, 277, 12, 26245, 12, 1788, 304, 267, 408, 267, 20297, 267, 408, 267, 7002, 275, 488, 267, 340, 26245, 508, 298, 274, 1939, 582, 288, 7002, 275, 7005, 1939, 18591, 1173, 5929, 8, 1501, 9, 267, 916, 26245, 508, 298, 1099, 493, 582, 288, 7002, 275, 10695, 10766, 5929, 8, 1501, 9, 267, 291, 855, 2604, 275, 488, 267, 340, 7002, 26, 288, 291, 855, 2604, 275, 7002, 14, 32356, 342, 15567, 347, 2372, 6579, 8, 277, 304, 267, 408, 267, 11003, 370, 666, 267, 408, 267, 372, 291, 855, 2604, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
edmond-chhung/linkchecker
linkcheck/checker/urlbase.py
9
30871
# -*- coding: iso-8859-1 -*- # Copyright (C) 2000-2014 Bastian Kleineidam # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ Base URL handler. """ import sys import os try: import urlparse except ImportError: # Python 3 from urllib import parse as urlparse try: from urllib2 import urlopen except ImportError: # Python 3 from urllib.request import urlopen import urllib import time import errno import socket import select try: from cStringIO import StringIO except ImportError: # Python 3 from io import StringIO from . import absolute_url, get_url_from from .. import (log, LOG_CHECK, strformat, LinkCheckerError, url as urlutil, trace, get_link_pat) from ..network import iputil from .const import (WARN_URL_EFFECTIVE_URL, WARN_URL_ERROR_GETTING_CONTENT, WARN_URL_OBFUSCATED_IP, WARN_URL_CONTENT_SIZE_ZERO, WARN_URL_CONTENT_SIZE_TOO_LARGE, WARN_URL_WHITESPACE, URL_MAX_LENGTH, WARN_URL_TOO_LONG, ExcList, ExcSyntaxList, ExcNoCacheList) # helper alias unicode_safe = strformat.unicode_safe # schemes that are invalid with an empty hostname scheme_requires_host = ("ftp", "http", "telnet") def urljoin (parent, url): """ If url is relative, join parent and url. Else leave url as-is. @return joined url """ if urlutil.url_is_absolute(url): return url return urlparse.urljoin(parent, url) def url_norm (url, encoding=None): """Wrapper for url.url_norm() to convert UnicodeError in LinkCheckerError.""" try: return urlutil.url_norm(url, encoding=encoding) except UnicodeError: msg = _("URL has unparsable domain name: %(name)s") % \ {"name": sys.exc_info()[1]} raise LinkCheckerError(msg) class UrlBase (object): """An URL with additional information like validity etc.""" # file types that can be parsed recursively ContentMimetypes = { "text/html": "html", "application/xhtml+xml": "html", # Include PHP file which helps when checking local .php files. # It does not harm other URL schemes like HTTP since HTTP servers # should not send this content type. They send text/html instead. "application/x-httpd-php": "html", "text/css": "css", "application/x-shockwave-flash": "swf", "application/msword": "word", "text/plain+linkchecker": "text", "text/plain+opera": "opera", "text/plain+chromium": "chromium", "application/x-plist+safari": "safari", "text/vnd.wap.wml": "wml", "application/xml+sitemap": "sitemap", "application/xml+sitemapindex": "sitemapindex", "application/pdf": "pdf", "application/x-pdf": "pdf", } # Read in 16kb chunks ReadChunkBytes = 1024*16 def __init__ (self, base_url, recursion_level, aggregate, parent_url=None, base_ref=None, line=-1, column=-1, page=-1, name=u"", url_encoding=None, extern=None): """ Initialize check data, and store given variables. @param base_url: unquoted and possibly unnormed url @param recursion_level: on what check level lies the base url @param aggregate: aggregate instance @param parent_url: quoted and normed url of parent or None @param base_ref: quoted and normed url of <base href=""> or None @param line: line number of url in parent content @param column: column number of url in parent content @param page: page number of url in parent content @param name: name of url or empty @param url_encoding: encoding of URL or None @param extern: None or (is_extern, is_strict) """ self.reset() self.init(base_ref, base_url, parent_url, recursion_level, aggregate, line, column, page, name, url_encoding, extern) self.check_syntax() if recursion_level == 0: self.add_intern_pattern() self.set_extern(self.url) if self.extern[0] and self.extern[1]: self.add_info(_("The URL is outside of the domain " "filter, checked only syntax.")) if not self.has_result: self.set_result(_("filtered")) def init (self, base_ref, base_url, parent_url, recursion_level, aggregate, line, column, page, name, url_encoding, extern): """ Initialize internal data. """ self.base_ref = base_ref if self.base_ref is not None: assert isinstance(self.base_ref, unicode), repr(self.base_ref) self.base_url = base_url.strip() if base_url else base_url if self.base_url is not None: assert isinstance(self.base_url, unicode), repr(self.base_url) self.parent_url = parent_url if self.parent_url is not None: assert isinstance(self.parent_url, unicode), repr(self.parent_url) self.recursion_level = recursion_level self.aggregate = aggregate self.line = line self.column = column self.page = page self.name = name assert isinstance(self.name, unicode), repr(self.name) self.encoding = url_encoding self.charset = None self.extern = extern if self.base_ref: assert not urlutil.url_needs_quoting(self.base_ref), \ "unquoted base reference URL %r" % self.base_ref if self.parent_url: assert not urlutil.url_needs_quoting(self.parent_url), \ "unquoted parent URL %r" % self.parent_url url = absolute_url(self.base_url, base_ref, parent_url) # assume file link if no scheme is found self.scheme = url.split(":", 1)[0].lower() or "file" if self.base_url != base_url: self.add_warning(_("Leading or trailing whitespace in URL `%(url)s'.") % {"url": base_url}, tag=WARN_URL_WHITESPACE) def reset (self): """ Reset all variables to default values. """ # self.url is constructed by self.build_url() out of base_url # and (base_ref or parent) as absolute and normed url. # This the real url we use when checking so it also referred to # as 'real url' self.url = None # a splitted version of url for convenience self.urlparts = None # the scheme, host, port and anchor part of url self.scheme = self.host = self.port = self.anchor = None # the result message string and flag self.result = u"" self.has_result = False # valid or not self.valid = True # list of warnings (without duplicates) self.warnings = [] # list of infos self.info = [] # content size self.size = -1 # last modification time of content in HTTP-date format as specified in RFC2616 chapter 3.3.1 self.modified = None # download time self.dltime = -1 # check time self.checktime = 0 # connection object self.url_connection = None # data of url content, (data == None) means no data is available self.data = None # cache url is set by build_url() calling set_cache_url() self.cache_url = None # extern flags (is_extern, is_strict) self.extern = None # flag if the result should be cached self.caching = True # title is either the URL or parsed from content self.title = None # flag if content should be checked or not self.do_check_content = True # MIME content type self.content_type = u"" # URLs seen through redirections self.aliases = [] def set_result (self, msg, valid=True, overwrite=False): """ Set result string and validity. """ if self.has_result and not overwrite: log.warn(LOG_CHECK, "Double result %r (previous %r) for %s", msg, self.result, self) else: self.has_result = True if not isinstance(msg, unicode): log.warn(LOG_CHECK, "Non-unicode result for %s: %r", self, msg) elif not msg: log.warn(LOG_CHECK, "Empty result for %s", self) self.result = msg self.valid = valid # free content data self.data = None def get_title (self): """Return title of page the URL refers to. This is per default the filename or the URL.""" if self.title is None: url = u"" if self.base_url: url = self.base_url elif self.url: url = self.url self.title = url if "/" in url: title = url.rsplit("/", 1)[1] if title: self.title = title return self.title def is_parseable (self): """ Return True iff content of this url is parseable. """ return False def is_html (self): """Return True iff content of this url is HTML formatted.""" return self._is_ctype("html") def is_css (self): """Return True iff content of this url is CSS stylesheet.""" return self._is_ctype("css") def _is_ctype(self, ctype): """Return True iff content is valid and of the given type.""" if not self.valid: return False mime = self.content_type return self.ContentMimetypes.get(mime) == ctype def is_http (self): """Return True for http:// or https:// URLs.""" return self.scheme in ("http", "https") def is_file (self): """Return True for file:// URLs.""" return self.scheme == "file" def is_directory(self): """Return True if current URL represents a directory.""" return False def is_local(self): """Return True for local (ie. file://) URLs.""" return self.is_file() def add_warning (self, s, tag=None): """ Add a warning string. """ item = (tag, s) if item not in self.warnings and \ tag not in self.aggregate.config["ignorewarnings"]: self.warnings.append(item) def add_info (self, s): """ Add an info string. """ if s not in self.info: self.info.append(s) def set_cache_url (self): """Set the URL to be used for caching.""" # remove anchor from cached target url since we assume # URLs with different anchors to have the same content self.cache_url = urlutil.urlunsplit(self.urlparts[:4]+[u'']) if self.cache_url is not None: assert isinstance(self.cache_url, unicode), repr(self.cache_url) def check_syntax (self): """ Called before self.check(), this function inspects the url syntax. Success enables further checking, failure immediately logs this url. Syntax checks must not use any network resources. """ log.debug(LOG_CHECK, "checking syntax") if self.base_url is None: self.base_url = u"" if not (self.base_url or self.parent_url): self.set_result(_("URL is empty"), valid=False) return try: self.build_url() self.check_url_warnings() except tuple(ExcSyntaxList) as msg: self.set_result(unicode_safe(msg), valid=False) else: self.set_cache_url() def check_url_warnings(self): """Check URL name and length.""" effectiveurl = urlutil.urlunsplit(self.urlparts) if self.url != effectiveurl: self.add_warning(_("Effective URL %(url)r.") % {"url": effectiveurl}, tag=WARN_URL_EFFECTIVE_URL) self.url = effectiveurl if len(self.url) > URL_MAX_LENGTH and self.scheme != u"data": args = dict(len=len(self.url), max=URL_MAX_LENGTH) self.add_warning(_("URL length %(len)d is longer than %(max)d.") % args, tag=WARN_URL_TOO_LONG) def build_url (self): """ Construct self.url and self.urlparts out of the given base url information self.base_url, self.parent_url and self.base_ref. """ # norm base url - can raise UnicodeError from url.idna_encode() base_url, is_idn = url_norm(self.base_url, self.encoding) # make url absolute if self.base_ref: # use base reference as parent url if ":" not in self.base_ref: # some websites have a relative base reference self.base_ref = urljoin(self.parent_url, self.base_ref) self.url = urljoin(self.base_ref, base_url) elif self.parent_url: # strip the parent url query and anchor urlparts = list(urlparse.urlsplit(self.parent_url)) urlparts[4] = "" parent_url = urlutil.urlunsplit(urlparts) self.url = urljoin(parent_url, base_url) else: self.url = base_url # urljoin can unnorm the url path, so norm it again urlparts = list(urlparse.urlsplit(self.url)) if urlparts[2]: urlparts[2] = urlutil.collapse_segments(urlparts[2]) self.url = urlutil.urlunsplit(urlparts) # split into (modifiable) list self.urlparts = strformat.url_unicode_split(self.url) self.build_url_parts() # and unsplit again self.url = urlutil.urlunsplit(self.urlparts) def build_url_parts (self): """Set userinfo, host, port and anchor from self.urlparts. Also checks for obfuscated IP addresses. """ # check userinfo@host:port syntax self.userinfo, host = urllib.splituser(self.urlparts[1]) port = urlutil.default_ports.get(self.scheme, 0) host, port = urlutil.splitport(host, port=port) if port is None: raise LinkCheckerError(_("URL host %(host)r has invalid port") % {"host": host}) self.port = port # set host lowercase self.host = host.lower() if self.scheme in scheme_requires_host: if not self.host: raise LinkCheckerError(_("URL has empty hostname")) self.check_obfuscated_ip() if not self.port or self.port == urlutil.default_ports.get(self.scheme): host = self.host else: host = "%s:%d" % (self.host, self.port) if self.userinfo: self.urlparts[1] = "%s@%s" % (self.userinfo, host) else: self.urlparts[1] = host # safe anchor for later checking self.anchor = self.urlparts[4] if self.anchor is not None: assert isinstance(self.anchor, unicode), repr(self.anchor) def check_obfuscated_ip (self): """Warn if host of this URL is obfuscated IP address.""" # check if self.host can be an IP address # check for obfuscated IP address if iputil.is_obfuscated_ip(self.host): ips = iputil.resolve_host(self.host) if ips: self.host = ips[0] self.add_warning( _("URL %(url)s has obfuscated IP address %(ip)s") % \ {"url": self.base_url, "ip": ips[0]}, tag=WARN_URL_OBFUSCATED_IP) def check (self): """Main check function for checking this URL.""" if self.aggregate.config["trace"]: trace.trace_on() try: self.local_check() except (socket.error, select.error): # on Unix, ctrl-c can raise # error: (4, 'Interrupted system call') etype, value = sys.exc_info()[:2] if etype == errno.EINTR: raise KeyboardInterrupt(value) else: raise def local_check (self): """Local check function can be overridden in subclasses.""" log.debug(LOG_CHECK, "Checking %s", unicode(self)) # strict extern URLs should not be checked assert not self.extern[1], 'checking strict extern URL' # check connection log.debug(LOG_CHECK, "checking connection") try: self.check_connection() self.set_content_type() self.add_size_info() self.aggregate.plugin_manager.run_connection_plugins(self) except tuple(ExcList) as exc: value = self.handle_exception() # make nicer error msg for unknown hosts if isinstance(exc, socket.error) and exc.args[0] == -2: value = _('Hostname not found') elif isinstance(exc, UnicodeError): # idna.encode(host) failed value = _('Bad hostname %(host)r: %(msg)s') % {'host': self.host, 'msg': str(value)} self.set_result(unicode_safe(value), valid=False) def check_content(self): """Check content of URL. @return: True if content can be parsed, else False """ if self.do_check_content and self.valid: # check content and recursion try: if self.can_get_content(): self.aggregate.plugin_manager.run_content_plugins(self) if self.allows_recursion(): return True except tuple(ExcList): value = self.handle_exception() self.add_warning(_("could not get content: %(msg)s") % {"msg": str(value)}, tag=WARN_URL_ERROR_GETTING_CONTENT) return False def close_connection (self): """ Close an opened url connection. """ if self.url_connection is None: # no connection is open return try: self.url_connection.close() except Exception: # ignore close errors pass self.url_connection = None def handle_exception (self): """ An exception occurred. Log it and set the cache flag. """ etype, evalue = sys.exc_info()[:2] log.debug(LOG_CHECK, "Error in %s: %s %s", self.url, etype, evalue, exception=True) # note: etype must be the exact class, not a subclass if (etype in ExcNoCacheList) or \ (etype == socket.error and evalue.args[0]==errno.EBADF) or \ not evalue: # EBADF occurs when operating on an already socket self.caching = False # format unicode message "<exception name>: <error message>" errmsg = unicode(etype.__name__) uvalue = strformat.unicode_safe(evalue) if uvalue: errmsg += u": %s" % uvalue # limit length to 240 return strformat.limit(errmsg, length=240) def check_connection (self): """ The basic connection check uses urlopen to initialize a connection object. """ self.url_connection = urlopen(self.url) def add_size_info (self): """Set size of URL content (if any).. Should be overridden in subclasses.""" maxbytes = self.aggregate.config["maxfilesizedownload"] if self.size > maxbytes: self.add_warning( _("Content size %(size)s is larger than %(maxbytes)s.") % dict(size=strformat.strsize(self.size), maxbytes=strformat.strsize(maxbytes)), tag=WARN_URL_CONTENT_SIZE_TOO_LARGE) def allows_simple_recursion(self): """Check recursion level and extern status.""" rec_level = self.aggregate.config["recursionlevel"] if rec_level >= 0 and self.recursion_level >= rec_level: log.debug(LOG_CHECK, "... no, maximum recursion level reached.") return False if self.extern[0]: log.debug(LOG_CHECK, "... no, extern.") return False return True def allows_recursion (self): """ Return True iff we can recurse into the url's content. """ log.debug(LOG_CHECK, "checking recursion of %r ...", self.url) if not self.valid: log.debug(LOG_CHECK, "... no, invalid.") return False if not self.can_get_content(): log.debug(LOG_CHECK, "... no, cannot get content.") return False if not self.allows_simple_recursion(): return False if self.size > self.aggregate.config["maxfilesizeparse"]: log.debug(LOG_CHECK, "... no, maximum parse size.") return False if not self.is_parseable(): log.debug(LOG_CHECK, "... no, not parseable.") return False if not self.content_allows_robots(): log.debug(LOG_CHECK, "... no, robots.") return False log.debug(LOG_CHECK, "... yes, recursion.") return True def content_allows_robots(self): """Returns True: only check robots.txt on HTTP links.""" return True def set_extern (self, url): """ Match URL against extern and intern link patterns. If no pattern matches the URL is extern. Sets self.extern to a tuple (bool, bool) with content (is_extern, is_strict). @return: None """ if self.extern: return if not url: self.extern = (1, 1) return for entry in self.aggregate.config["externlinks"]: match = entry['pattern'].search(url) if (entry['negate'] and not match) or \ (match and not entry['negate']): log.debug(LOG_CHECK, "Extern URL %r", url) self.extern = (1, entry['strict']) return for entry in self.aggregate.config["internlinks"]: match = entry['pattern'].search(url) if (entry['negate'] and not match) or \ (match and not entry['negate']): log.debug(LOG_CHECK, "Intern URL %r", url) self.extern = (0, 0) return if self.aggregate.config['checkextern']: self.extern = (1, 0) else: self.extern = (1, 1) def set_content_type (self): """Set content MIME type. Should be overridden in subclasses.""" pass def can_get_content (self): """Indicate wether url get_content() can be called.""" return self.size <= self.aggregate.config["maxfilesizedownload"] def get_content (self): """Precondition: url_connection is an opened URL.""" if self.data is None: log.debug(LOG_CHECK, "Get content of %r", self.url) t = time.time() self.data = self.read_content() self.size = len(self.data) self.dltime = time.time() - t if self.size == 0: self.add_warning(_("Content size is zero."), tag=WARN_URL_CONTENT_SIZE_ZERO) else: self.aggregate.add_downloaded_bytes(self.size) return self.data def read_content(self): """Return data for this URL. Can be overridden in subclasses.""" buf = StringIO() data = self.read_content_chunk() while data: if buf.tell() + len(data) > self.aggregate.config["maxfilesizedownload"]: raise LinkCheckerError(_("File size too large")) buf.write(data) data = self.read_content_chunk() return buf.getvalue() def read_content_chunk(self): """Read one chunk of content from this URL.""" return self.url_connection.read(self.ReadChunkBytes) def get_user_password (self): """Get tuple (user, password) from configured authentication. Both user and password can be None. """ if self.userinfo: # URL itself has authentication info return urllib.splitpasswd(self.userinfo) return self.aggregate.config.get_user_password(self.url) def add_url (self, url, line=0, column=0, page=0, name=u"", base=None): """Add new URL to queue.""" if base: base_ref = urlutil.url_norm(base)[0] else: base_ref = None url_data = get_url_from(url, self.recursion_level+1, self.aggregate, parent_url=self.url, base_ref=base_ref, line=line, column=column, page=page, name=name, parent_content_type=self.content_type) self.aggregate.urlqueue.put(url_data) def serialized (self, sep=os.linesep): """ Return serialized url check data as unicode string. """ return unicode_safe(sep).join([ u"%s link" % self.scheme, u"base_url=%r" % self.base_url, u"parent_url=%r" % self.parent_url, u"base_ref=%r" % self.base_ref, u"recursion_level=%d" % self.recursion_level, u"url_connection=%s" % self.url_connection, u"line=%d" % self.line, u"column=%d" % self.column, u"page=%d" % self.page, u"name=%r" % self.name, u"anchor=%r" % self.anchor, u"cache_url=%s" % self.cache_url, ]) def get_intern_pattern (self, url=None): """Get pattern for intern URL matching. @param url: the URL to set intern pattern for, else self.url @ptype url: unicode or None @return non-empty regex pattern or None @rtype String or None """ return None def add_intern_pattern(self, url=None): """Add intern URL regex to config.""" try: pat = self.get_intern_pattern(url=url) if pat: log.debug(LOG_CHECK, "Add intern pattern %r", pat) self.aggregate.config['internlinks'].append(get_link_pat(pat)) except UnicodeError as msg: res = _("URL has unparsable domain name: %(domain)s") % \ {"domain": msg} self.set_result(res, valid=False) def __unicode__(self): """ Get URL info. @return: URL info @rtype: unicode """ return self.serialized() def __str__(self): """ Get URL info. @return: URL info, encoded with the output logger encoding @rtype: string """ s = unicode(self) return self.aggregate.config['logger'].encode(s) def __repr__ (self): """ Get URL info. @return: URL info @rtype: unicode """ return u"<%s>" % self.serialized(sep=u", ") def to_wire_dict (self): """Return a simplified transport object for logging and caching. The transport object must contain these attributes: - url_data.valid: bool Indicates if URL is valid - url_data.result: unicode Result string - url_data.warnings: list of tuples (tag, warning message) List of tagged warnings for this URL. - url_data.name: unicode string or None name of URL (eg. filename or link name) - url_data.parent_url: unicode or None Parent URL - url_data.base_ref: unicode HTML base reference URL of parent - url_data.url: unicode Fully qualified URL. - url_data.domain: unicode URL domain part. - url_data.checktime: int Number of seconds needed to check this link, default: zero. - url_data.dltime: int Number of seconds needed to download URL content, default: -1 - url_data.size: int Size of downloaded URL content, default: -1 - url_data.info: list of unicode Additional information about this URL. - url_data.line: int Line number of this URL at parent document, or -1 - url_data.column: int Column number of this URL at parent document, or -1 - url_data.page: int Page number of this URL at parent document, or -1 - url_data.cache_url: unicode Cache url for this URL. - url_data.content_type: unicode MIME content type for URL content. - url_data.level: int Recursion level until reaching this URL from start URL - url_data.last_modified: datetime Last modification date of retrieved page (or None). """ return dict(valid=self.valid, extern=self.extern[0], result=self.result, warnings=self.warnings[:], name=self.name or u"", title=self.get_title(), parent_url=self.parent_url or u"", base_ref=self.base_ref or u"", base_url=self.base_url or u"", url=self.url or u"", domain=(self.urlparts[1] if self.urlparts else u""), checktime=self.checktime, dltime=self.dltime, size=self.size, info=self.info, line=self.line, column=self.column, page=self.page, cache_url=self.cache_url, content_type=self.content_type, level=self.recursion_level, modified=self.modified, ) def to_wire (self): """Return compact UrlData object with information from to_wire_dict(). """ return CompactUrlData(self.to_wire_dict()) urlDataAttr = [ 'valid', 'extern', 'result', 'warnings', 'name', 'title', 'parent_url', 'base_ref', 'base_url', 'url', 'domain', 'checktime', 'dltime', 'size', 'info', 'modified', 'line', 'column', 'page', 'cache_url', 'content_type', 'level', ] class CompactUrlData (object): """Store selected UrlData attributes in slots to minimize memory usage.""" __slots__ = urlDataAttr def __init__(self, wired_url_data): '''Set all attributes according to the dictionnary wired_url_data''' for attr in urlDataAttr: setattr(self, attr, wired_url_data[attr])
gpl-2.0
[ 3, 1882, 2803, 26, 11601, 13, 4830, 13, 17, 1882, 199, 3, 1898, 334, 35, 9, 12293, 13, 7280, 699, 1810, 5653, 1804, 274, 1132, 344, 455, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 3180, 199, 3, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 199, 3, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 11315, 13, 10067, 8217, 14, 199, 624, 199, 1563, 2851, 3016, 14, 199, 624, 199, 646, 984, 199, 646, 747, 199, 893, 26, 272, 492, 7097, 199, 2590, 3545, 26, 272, 327, 2018, 650, 272, 687, 4011, 492, 2198, 465, 7097, 199, 893, 26, 272, 687, 4011, 18, 492, 18279, 199, 2590, 3545, 26, 272, 327, 2018, 650, 272, 687, 4011, 14, 1069, 492, 18279, 199, 646, 4011, 199, 646, 900, 199, 646, 7554, 199, 646, 2838, 199, 646, 3504, 199, 893, 26, 272, 687, 15073, 492, 5228, 199, 2590, 3545, 26, 272, 327, 2018, 650, 272, 687, 5890, 492, 5228, 199, 199, 504, 1275, 492, 3679, 63, 633, 12, 664, 63, 633, 63, 504, 199, 504, 2508, 492, 334, 793, 12, 5051, 63, 8936, 12, 523, 620, 908, 12, 10967, 3048, 547, 12, 1166, 465, 1166, 1974, 12, 3307, 12, 664, 63, 1073, 63, 10853, 9, 199, 504, 2508, 1200, 492, 3384, 1974, 199, 504, 1275, 1297, 492, 334, 17449, 63, 2632, 63, 29512, 3582, 5399, 63, 2632, 12, 272, 13253, 46, 63, 2632, 63, 3170, 63, 2970, 52, 1206, 63, 9663, 12, 13253, 46, 63, 2632, 63, 5488, 38, 1668, 35, 6989, 63, 1772, 12, 272, 13253, 46, 63, 2632, 63, 9663, 63, 4305, 63, 24655, 12, 13253, 46, 63, 2632, 63, 9663, 63, 4305, 63, 30947, 63, 15806, 12, 272, 13253, 46, 63, 2632, 63, 20620, 12, 2851, 63, 4283, 63, 9127, 12, 13253, 46, 63, 2632, 63, 30947, 63, 12375, 12, 272, 1316, 67, 1296, 12, 1316, 67, 16626, 1296, 12, 1316, 67, 1944, 4437, 1296, 9, 199, 199, 3, 5922, 5162, 199, 2975, 63, 3489, 275, 620, 908, 14, 2975, 63, 3489, 199, 199, 3, 21149, 626, 787, 3866, 543, 376, 2701, 6246, 199, 5512, 63, 6537, 63, 1102, 275, 1689, 8915, 401, 298, 1014, 401, 298, 31085, 531, 199, 199, 318, 20818, 334, 1708, 12, 1166, 304, 272, 408, 272, 982, 1166, 365, 3847, 12, 4263, 1676, 436, 1166, 14, 19524, 10137, 1166, 465, 13, 374, 14, 339, 768, 1107, 16538, 1166, 272, 408, 272, 340, 1166, 1974, 14, 633, 63, 374, 63, 6116, 8, 633, 304, 267, 372, 1166, 272, 372, 7097, 14, 17755, 8, 1708, 12, 1166, 9, 421, 199, 318, 1166, 63, 4791, 334, 633, 12, 2644, 29, 403, 304, 272, 408, 4590, 367, 1166, 14, 633, 63, 4791, 342, 370, 3957, 20872, 315, 272, 10967, 3048, 547, 1041, 272, 862, 26, 267, 372, 1166, 1974, 14, 633, 63, 4791, 8, 633, 12, 2644, 29, 2991, 9, 272, 871, 20872, 26, 267, 1499, 275, 3824, 2632, 965, 625, 21152, 461, 2881, 536, 26, 2818, 354, 9, 83, 531, 450, 971, 288, 2420, 354, 582, 984, 14, 2804, 63, 815, 3430, 17, 9420, 267, 746, 10967, 3048, 547, 8, 1328, 9, 421, 199, 533, 20503, 1563, 334, 785, 304, 272, 408, 2493, 2851, 543, 4722, 2556, 2839, 25667, 5423, 1041, 339, 327, 570, 2943, 626, 883, 506, 4565, 15035, 272, 6646, 45, 1036, 1313, 275, 469, 267, 298, 505, 15, 1360, 582, 298, 1360, 401, 267, 298, 3578, 15, 12909, 11, 1652, 582, 298, 1360, 401, 267, 327, 15783, 510, 18635, 570, 1314, 22577, 1380, 7907, 2257, 1275, 8624, 1584, 14, 267, 327, 2779, 1630, 440, 394, 5362, 1163, 2851, 21149, 2839, 3101, 3967, 3101, 8037, 267, 327, 1077, 440, 3222, 642, 1564, 730, 14, 9322, 3222, 1318, 15, 1360, 3140, 14, 267, 298, 3578, 15, 88, 13, 21594, 13, 8624, 582, 298, 1360, 401, 267, 298, 505, 15, 3919, 582, 298, 3919, 401, 267, 298, 3578, 15, 88, 13, 13927, 346, 10024, 13, 11331, 582, 298, 20426, 401, 267, 298, 3578, 15, 706, 1027, 582, 298, 1027, 401, 267, 298, 505, 15, 6104, 11, 1073, 6743, 582, 298, 505, 401, 267, 298, 505, 15, 6104, 11, 2262, 65, 582, 298, 2262, 65, 401, 267, 298, 505, 15, 6104, 11, 13211, 582, 298, 13211, 401, 267, 298, 3578, 15, 88, 13, 10265, 11, 2231, 70, 759, 582, 298, 2231, 70, 759, 401, 267, 298, 505, 15, 26379, 14, 25529, 14, 87, 757, 582, 298, 87, 757, 401, 267, 298, 3578, 15, 1652, 11, 17205, 582, 298, 17205, 401, 267, 298, 3578, 15, 1652, 11, 17205, 1080, 582, 298, 17205, 1080, 401, 267, 298, 3578, 15, 5607, 582, 298, 5607, 401, 267, 298, 3578, 15, 88, 13, 5607, 582, 298, 5607, 401, 272, 789, 339, 327, 5574, 315, 3193, 7862, 8291, 272, 5574, 9856, 5571, 275, 6619, 10, 975, 339, 347, 636, 826, 363, 334, 277, 12, 1300, 63, 633, 12, 16189, 63, 1896, 12, 9531, 12, 2116, 1676, 63, 633, 29, 403, 12, 1300, 63, 1121, 29, 403, 12, 1004, 4022, 17, 12, 2763, 4022, 17, 12, 2034, 4022, 17, 12, 2116, 536, 29, 85, 5151, 1166, 63, 2991, 29, 403, 12, 21815, 29, 403, 304, 267, 408, 267, 11578, 1104, 666, 12, 436, 3877, 1627, 2860, 14, 398, 768, 635, 1300, 63, 633, 26, 31791, 436, 12570, 625, 6505, 3594, 1166, 267, 768, 635, 16189, 63, 1896, 26, 641, 4052, 1104, 2166, 1212, 397, 314, 1300, 1166, 267, 768 ]
[ 1882, 2803, 26, 11601, 13, 4830, 13, 17, 1882, 199, 3, 1898, 334, 35, 9, 12293, 13, 7280, 699, 1810, 5653, 1804, 274, 1132, 344, 455, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 3180, 199, 3, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 199, 3, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 11315, 13, 10067, 8217, 14, 199, 624, 199, 1563, 2851, 3016, 14, 199, 624, 199, 646, 984, 199, 646, 747, 199, 893, 26, 272, 492, 7097, 199, 2590, 3545, 26, 272, 327, 2018, 650, 272, 687, 4011, 492, 2198, 465, 7097, 199, 893, 26, 272, 687, 4011, 18, 492, 18279, 199, 2590, 3545, 26, 272, 327, 2018, 650, 272, 687, 4011, 14, 1069, 492, 18279, 199, 646, 4011, 199, 646, 900, 199, 646, 7554, 199, 646, 2838, 199, 646, 3504, 199, 893, 26, 272, 687, 15073, 492, 5228, 199, 2590, 3545, 26, 272, 327, 2018, 650, 272, 687, 5890, 492, 5228, 199, 199, 504, 1275, 492, 3679, 63, 633, 12, 664, 63, 633, 63, 504, 199, 504, 2508, 492, 334, 793, 12, 5051, 63, 8936, 12, 523, 620, 908, 12, 10967, 3048, 547, 12, 1166, 465, 1166, 1974, 12, 3307, 12, 664, 63, 1073, 63, 10853, 9, 199, 504, 2508, 1200, 492, 3384, 1974, 199, 504, 1275, 1297, 492, 334, 17449, 63, 2632, 63, 29512, 3582, 5399, 63, 2632, 12, 272, 13253, 46, 63, 2632, 63, 3170, 63, 2970, 52, 1206, 63, 9663, 12, 13253, 46, 63, 2632, 63, 5488, 38, 1668, 35, 6989, 63, 1772, 12, 272, 13253, 46, 63, 2632, 63, 9663, 63, 4305, 63, 24655, 12, 13253, 46, 63, 2632, 63, 9663, 63, 4305, 63, 30947, 63, 15806, 12, 272, 13253, 46, 63, 2632, 63, 20620, 12, 2851, 63, 4283, 63, 9127, 12, 13253, 46, 63, 2632, 63, 30947, 63, 12375, 12, 272, 1316, 67, 1296, 12, 1316, 67, 16626, 1296, 12, 1316, 67, 1944, 4437, 1296, 9, 199, 199, 3, 5922, 5162, 199, 2975, 63, 3489, 275, 620, 908, 14, 2975, 63, 3489, 199, 199, 3, 21149, 626, 787, 3866, 543, 376, 2701, 6246, 199, 5512, 63, 6537, 63, 1102, 275, 1689, 8915, 401, 298, 1014, 401, 298, 31085, 531, 199, 199, 318, 20818, 334, 1708, 12, 1166, 304, 272, 408, 272, 982, 1166, 365, 3847, 12, 4263, 1676, 436, 1166, 14, 19524, 10137, 1166, 465, 13, 374, 14, 339, 768, 1107, 16538, 1166, 272, 408, 272, 340, 1166, 1974, 14, 633, 63, 374, 63, 6116, 8, 633, 304, 267, 372, 1166, 272, 372, 7097, 14, 17755, 8, 1708, 12, 1166, 9, 421, 199, 318, 1166, 63, 4791, 334, 633, 12, 2644, 29, 403, 304, 272, 408, 4590, 367, 1166, 14, 633, 63, 4791, 342, 370, 3957, 20872, 315, 272, 10967, 3048, 547, 1041, 272, 862, 26, 267, 372, 1166, 1974, 14, 633, 63, 4791, 8, 633, 12, 2644, 29, 2991, 9, 272, 871, 20872, 26, 267, 1499, 275, 3824, 2632, 965, 625, 21152, 461, 2881, 536, 26, 2818, 354, 9, 83, 531, 450, 971, 288, 2420, 354, 582, 984, 14, 2804, 63, 815, 3430, 17, 9420, 267, 746, 10967, 3048, 547, 8, 1328, 9, 421, 199, 533, 20503, 1563, 334, 785, 304, 272, 408, 2493, 2851, 543, 4722, 2556, 2839, 25667, 5423, 1041, 339, 327, 570, 2943, 626, 883, 506, 4565, 15035, 272, 6646, 45, 1036, 1313, 275, 469, 267, 298, 505, 15, 1360, 582, 298, 1360, 401, 267, 298, 3578, 15, 12909, 11, 1652, 582, 298, 1360, 401, 267, 327, 15783, 510, 18635, 570, 1314, 22577, 1380, 7907, 2257, 1275, 8624, 1584, 14, 267, 327, 2779, 1630, 440, 394, 5362, 1163, 2851, 21149, 2839, 3101, 3967, 3101, 8037, 267, 327, 1077, 440, 3222, 642, 1564, 730, 14, 9322, 3222, 1318, 15, 1360, 3140, 14, 267, 298, 3578, 15, 88, 13, 21594, 13, 8624, 582, 298, 1360, 401, 267, 298, 505, 15, 3919, 582, 298, 3919, 401, 267, 298, 3578, 15, 88, 13, 13927, 346, 10024, 13, 11331, 582, 298, 20426, 401, 267, 298, 3578, 15, 706, 1027, 582, 298, 1027, 401, 267, 298, 505, 15, 6104, 11, 1073, 6743, 582, 298, 505, 401, 267, 298, 505, 15, 6104, 11, 2262, 65, 582, 298, 2262, 65, 401, 267, 298, 505, 15, 6104, 11, 13211, 582, 298, 13211, 401, 267, 298, 3578, 15, 88, 13, 10265, 11, 2231, 70, 759, 582, 298, 2231, 70, 759, 401, 267, 298, 505, 15, 26379, 14, 25529, 14, 87, 757, 582, 298, 87, 757, 401, 267, 298, 3578, 15, 1652, 11, 17205, 582, 298, 17205, 401, 267, 298, 3578, 15, 1652, 11, 17205, 1080, 582, 298, 17205, 1080, 401, 267, 298, 3578, 15, 5607, 582, 298, 5607, 401, 267, 298, 3578, 15, 88, 13, 5607, 582, 298, 5607, 401, 272, 789, 339, 327, 5574, 315, 3193, 7862, 8291, 272, 5574, 9856, 5571, 275, 6619, 10, 975, 339, 347, 636, 826, 363, 334, 277, 12, 1300, 63, 633, 12, 16189, 63, 1896, 12, 9531, 12, 2116, 1676, 63, 633, 29, 403, 12, 1300, 63, 1121, 29, 403, 12, 1004, 4022, 17, 12, 2763, 4022, 17, 12, 2034, 4022, 17, 12, 2116, 536, 29, 85, 5151, 1166, 63, 2991, 29, 403, 12, 21815, 29, 403, 304, 267, 408, 267, 11578, 1104, 666, 12, 436, 3877, 1627, 2860, 14, 398, 768, 635, 1300, 63, 633, 26, 31791, 436, 12570, 625, 6505, 3594, 1166, 267, 768, 635, 16189, 63, 1896, 26, 641, 4052, 1104, 2166, 1212, 397, 314, 1300, 1166, 267, 768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
singhkay/azure-quickstart-templates
splunk-on-ubuntu/scripts/config.py
119
1408
#      The MIT License (MIT) # #      Copyright (c) 2016 Microsoft. All rights reserved. # #      Permission is hereby granted, free of charge, to any person obtaining a copy #      of this software and associated documentation files (the "Software"), to deal #      in the Software without restriction, including without limitation the rights #      to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #      copies of the Software, and to permit persons to whom the Software is #      furnished to do so, subject to the following conditions: # #      The above copyright notice and this permission notice shall be included in #      all copies or substantial portions of the Software. # #      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #      OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN #      THE SOFTWARE. STORAGE_ACCOUNT_NAME = 'YOUR_STORAGE_ACCOUNT_NAME' STORAGE_ACCOUNT_KEY = 'YOUR_STORAGE_ACCOUNT_KEY'
mit
[ 3, 10619, 10619, 10619, 10619, 10619, 710, 10697, 844, 334, 13965, 9, 199, 3, 199, 3, 10619, 10619, 10619, 10619, 10619, 1898, 334, 67, 9, 7800, 15332, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10619, 10619, 10619, 10619, 10619, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 1331, 199, 3, 10619, 10619, 10619, 10619, 10619, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 298, 10337, 1288, 370, 7962, 199, 3, 10619, 10619, 10619, 10619, 10619, 315, 314, 2290, 1928, 10588, 12, 5893, 1928, 12305, 314, 4481, 199, 3, 10619, 10619, 10619, 10619, 10619, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 12743, 199, 3, 10619, 10619, 10619, 10619, 10619, 6866, 402, 314, 2290, 12, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 199, 3, 10619, 10619, 10619, 10619, 10619, 13985, 370, 886, 880, 12, 5420, 370, 314, 2569, 3704, 26, 199, 3, 199, 3, 10619, 10619, 10619, 10619, 10619, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 315, 199, 3, 10619, 10619, 10619, 10619, 10619, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 10619, 10619, 10619, 10619, 10619, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 1549, 199, 3, 10619, 10619, 10619, 10619, 10619, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 3169, 12, 199, 3, 10619, 10619, 10619, 10619, 10619, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 7000, 2334, 199, 3, 10619, 10619, 10619, 10619, 10619, 10610, 1549, 5877, 8164, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 199, 3, 10619, 10619, 10619, 10619, 10619, 5603, 12, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 10619, 10619, 10619, 10619, 10619, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 199, 3, 10619, 10619, 10619, 10619, 10619, 2334, 4141, 14, 199, 199, 17467, 63, 18928, 63, 2339, 275, 283, 57, 11237, 63, 17467, 63, 18928, 63, 2339, 7, 199, 17467, 63, 18928, 63, 3078, 221, 275, 283, 57, 11237, 63, 17467, 63, 18928, 63, 3078, 7, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 10619, 10619, 10619, 10619, 10619, 710, 10697, 844, 334, 13965, 9, 199, 3, 199, 3, 10619, 10619, 10619, 10619, 10619, 1898, 334, 67, 9, 7800, 15332, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10619, 10619, 10619, 10619, 10619, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 1331, 199, 3, 10619, 10619, 10619, 10619, 10619, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 298, 10337, 1288, 370, 7962, 199, 3, 10619, 10619, 10619, 10619, 10619, 315, 314, 2290, 1928, 10588, 12, 5893, 1928, 12305, 314, 4481, 199, 3, 10619, 10619, 10619, 10619, 10619, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 12743, 199, 3, 10619, 10619, 10619, 10619, 10619, 6866, 402, 314, 2290, 12, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 199, 3, 10619, 10619, 10619, 10619, 10619, 13985, 370, 886, 880, 12, 5420, 370, 314, 2569, 3704, 26, 199, 3, 199, 3, 10619, 10619, 10619, 10619, 10619, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 315, 199, 3, 10619, 10619, 10619, 10619, 10619, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 10619, 10619, 10619, 10619, 10619, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 1549, 199, 3, 10619, 10619, 10619, 10619, 10619, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 3169, 12, 199, 3, 10619, 10619, 10619, 10619, 10619, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 7000, 2334, 199, 3, 10619, 10619, 10619, 10619, 10619, 10610, 1549, 5877, 8164, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 199, 3, 10619, 10619, 10619, 10619, 10619, 5603, 12, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 10619, 10619, 10619, 10619, 10619, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 199, 3, 10619, 10619, 10619, 10619, 10619, 2334, 4141, 14, 199, 199, 17467, 63, 18928, 63, 2339, 275, 283, 57, 11237, 63, 17467, 63, 18928, 63, 2339, 7, 199, 17467, 63, 18928, 63, 3078, 221, 275, 283, 57, 11237, 63, 17467, 63, 18928, 63, 3078, 7, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
FATSLiM/fatslim
fatslimlib/test/test_03_apl.py
1
12484
# -*- coding: utf-8; Mode: python; tab-width: 4; indent-tabs-mode:nil; -*- # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 # # Copyright (C) 2013-2016 Sébastien Buchoux <sebastien.buchoux@gmail.com> # # This file is part of FATSLiM. # # FATSLiM is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # FATSLiM is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with FATSLiM. If not, see <http://www.gnu.org/licenses/>. from __future__ import print_function # Global imports import numpy as np from numpy.testing import assert_almost_equal, assert_allclose # Local imports from .. import core_geometry from .. import core_analysis from . import frame_model_bilayer, frame_bilayer, frame_model_vesicle, frame_vesicle, frame_model_bilayer_prot,\ frame_bilayer_prot, frame_bilayer_peptide, frame_bilayer_chol RTOL = 5e-3 triangle_points = [(200., 50), (150, 100), (250, 150)] square_points = [[100., 100], [300, 100], [300, 300], [100, 300]] small_square_points = [[150., 100], [250, 100], [250, 200], [150, 200]] far_square_points = [[1100., 100], [1300, 1100], [1300, 1300], [1100, 1300]] concave_points = [[50., 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]] def test_polygon_perimeter_triangle(): ref_perimeter = 294.3174758686337 perimeter = core_geometry.get_polygon_perimeter(np.array(triangle_points)) assert_almost_equal(perimeter, ref_perimeter) def test_polygon_area_triangle(): ref_area = 3750.0 area = core_geometry.get_polygon_area(np.array(triangle_points)) assert_almost_equal(area, ref_area) def test_polygon_perimeter_square(): ref_perimeter = 800.0 perimeter = core_geometry.get_polygon_perimeter(np.array(square_points)) assert_almost_equal(perimeter, ref_perimeter) def test_polygon_area_square(): ref_area = 40000.0 area = core_geometry.get_polygon_area(np.array(square_points)) assert_almost_equal(area, ref_area) def test_polygon_is_inside(): poly = np.array(square_points) point_inside = np.array([200., 200]) point_outside = np.array([2000., 2000]) assert core_geometry.is_inside_polygon(poly, point_inside) assert not core_geometry.is_inside_polygon(poly, point_outside) def test_polygon_clipping_intersecting(): concave = np.array(concave_points) square = np.array(square_points) ref_clipped = [[100, 116.66], [125, 100], [275, 100], [300, 116.66], [300, 300], [250, 300], [200, 250], [175, 300], [125, 300], [100, 250]] clipped = core_geometry.get_clipped_polygon(concave, square) assert_almost_equal(clipped, ref_clipped, 2) ref_area = 37083.333 area = core_geometry.get_polygon_area(clipped) assert_almost_equal(area, ref_area, 3) def test_polygon_clipping_not_intersecting(): concave = np.array(concave_points) square = np.array(far_square_points) clipped = core_geometry.get_clipped_polygon(concave, square) assert len(clipped) == 0 ref_area = -1.0 area = core_geometry.get_polygon_area(clipped) assert_almost_equal(area, ref_area, 3) def test_polygon_clipping_contained(): concave = np.array(concave_points) square = np.array(small_square_points) ref_clipped = [small_square_points[i - 1] for i in range(len(small_square_points))] clipped = core_geometry.get_clipped_polygon(concave, square) assert_almost_equal(clipped, ref_clipped, 2) ref_area = 10000 area = core_geometry.get_polygon_area(clipped) assert_almost_equal(area, ref_area, 3) def test_put_atoms_on_plane_model_bilayer(frame_model_bilayer): frame = frame_model_bilayer membrane = frame.get_membranes()[0] ref_2dpoints = [(-1.60, -0.80), (-1.60, -0.00), (-1.60, 0.80), (-0.80, -1.60), (-0.80, -0.80), (-0.80, -0.00), (-0.80, 0.80), (-0.80, 1.60), (0.00, -1.60), (0.00, -0.80), (0.00, 0.80), (0.00, 1.60), (0.80, -1.60), (0.80, -0.80), (0.80, 0.00), (0.80, 0.80), (0.80, 1.60), (1.60, -0.80), (1.60, 0.00), (1.60, 0.80)] for leaflet in membrane: leaflet_2dpoints = core_analysis.test_put_atoms_on_plane(leaflet) for points in leaflet_2dpoints: points = np.array([tuple(val) for val in np.round(points, decimals=2)], dtype=[(str('x'), float), (str('y'), float)]) points.sort(order=(str('x'), str('y'))) assert_almost_equal(points.tolist(), ref_2dpoints) def test_apl_model_bilayer(frame_model_bilayer): frame = frame_model_bilayer membrane = frame.get_membranes()[0] apl = membrane.get_apl(by_type=False, only_average=False) ref_apl = [np.array([0.64] * 36), np.array([0.64] * 36)] for i, value in enumerate(apl[1:]): assert_allclose(value, ref_apl[i], rtol=1e-2) def test_apl_bilayer(frame_bilayer): frame = frame_bilayer membrane = frame.get_membranes()[0] ref_apl = (0.664, 0.664, 0.663) apl = membrane.get_apl(by_type=False) print("APL: avg:%.3f - L1 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f - L2 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f " % ( apl[0], len(membrane.leaflet1), apl[1][0], apl[1][1], apl[1][2], apl[1][3], len(membrane.leaflet2), apl[2][0], apl[2][1], apl[2][2], apl[2][3])) assert_allclose(apl[0], ref_apl[0], rtol=RTOL) assert_allclose(apl[1][0], ref_apl[1], rtol=RTOL) assert_allclose(apl[2][0], ref_apl[2], rtol=RTOL) def test_apl_bilayer_chol(frame_bilayer_chol): frame = frame_bilayer_chol membrane = frame.get_membranes()[0] ref_apl = (0.490, 0.489, 0.491) ref_area = (477.810, 475.138) apl = membrane.get_apl(by_type=False) print("APL: avg:%.3f - L1 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f - L2 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f " % ( apl[0], len(membrane.leaflet1), apl[1][0], apl[1][1], apl[1][2], apl[1][3], len(membrane.leaflet2), apl[2][0], apl[2][1], apl[2][2], apl[2][3])) assert_allclose(apl[0], ref_apl[0], rtol=RTOL) assert_allclose(apl[1][0], ref_apl[1], rtol=RTOL) assert_allclose(apl[2][0], ref_apl[2], rtol=RTOL) assert_allclose(apl[1][3], ref_area[0], rtol=RTOL) assert_allclose(apl[2][3], ref_area[1], rtol=RTOL) def test_apl_bilayer_chol_by_type(frame_bilayer_chol): frame = frame_bilayer_chol membrane = frame.get_membranes()[0] ref_apl_chol = (0.389, 0.387) ref_area_chol = (114.109, 109.63) ref_apl_dppc = (0.456, 0.471) ref_area_dppc = (188.035, 196.033) ref_apl_dupc = (0.647, 0.633) ref_area_dupc = (176.071, 169.683) apl = membrane.get_apl() for lid in [1, 2]: for key, val in apl[lid].items(): print("Leaflet #%i - %i %s: APL=%.3f (min:%.3f, max:%.3f) - Area=%.3f" % (lid, val[0], key, val[1], val[2], val[3], val[4])) # Test Cholesterol assert_allclose(apl[1]["CHOL"][1], ref_apl_chol[0], rtol=1e-2) assert_allclose(apl[2]["CHOL"][1], ref_apl_chol[1], rtol=1e-2) assert_allclose(apl[1]["CHOL"][4], ref_area_chol[0], rtol=1e-2) assert_allclose(apl[2]["CHOL"][4], ref_area_chol[1], rtol=1e-2) # Test DPPC assert_allclose(apl[1]["DPPC"][1], ref_apl_dppc[0], rtol=1e-2) assert_allclose(apl[2]["DPPC"][1], ref_apl_dppc[1], rtol=1e-2) assert_allclose(apl[1]["DPPC"][4], ref_area_dppc[0], rtol=1e-2) assert_allclose(apl[2]["DPPC"][4], ref_area_dppc[1], rtol=1e-2) # Test DUPC assert_allclose(apl[1]["DUPC"][1], ref_apl_dupc[0], rtol=1e-2) assert_allclose(apl[2]["DUPC"][1], ref_apl_dupc[1], rtol=1e-2) assert_allclose(apl[1]["DUPC"][4], ref_area_dupc[0], rtol=1e-2) assert_allclose(apl[2]["DUPC"][4], ref_area_dupc[1], rtol=1e-2) def test_apl_vesicle_model(frame_model_vesicle): frame = frame_model_vesicle membrane = frame.get_membranes()[0] ref_apl = (0.570, 0.639, 0.398) ref_area = (1254.087, 312.537) apl = membrane.get_apl(by_type=False) print("APL: avg:%.3f - L1 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f - L2 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f " % ( apl[0], len(membrane.leaflet1), apl[1][0], apl[1][1], apl[1][2], apl[1][3], len(membrane.leaflet2), apl[2][0], apl[2][1], apl[2][2], apl[2][3])) assert_allclose(apl[0], ref_apl[0], rtol=RTOL) assert_allclose(apl[1][0], ref_apl[1], rtol=RTOL) assert_allclose(apl[2][0], ref_apl[2], rtol=RTOL) assert_allclose(apl[1][3], ref_area[0], rtol=RTOL) assert_allclose(apl[2][3], ref_area[1], rtol=RTOL) def test_apl_vesicle(frame_vesicle): frame = frame_vesicle membrane = frame.get_membranes()[0] ref_apl = (0.681, 0.797, 0.499) ref_area = (1474.557, 588.391) apl = membrane.get_apl(by_type=False) print("APL: avg:%.3f - L1 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f - L2 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f " % ( apl[0], len(membrane.leaflet1), apl[1][0], apl[1][1], apl[1][2], apl[1][3], len(membrane.leaflet2), apl[2][0], apl[2][1], apl[2][2], apl[2][3])) assert_allclose(apl[0], ref_apl[0], rtol=RTOL) assert_allclose(apl[1][0], ref_apl[1], rtol=RTOL) assert_allclose(apl[2][0], ref_apl[2], rtol=RTOL) assert_allclose(apl[1][3], ref_area[0], rtol=RTOL) assert_allclose(apl[2][3], ref_area[1], rtol=RTOL) def test_apl_bilayer_peptide(frame_bilayer_peptide): frame = frame_bilayer_peptide membrane = frame.get_membranes()[0] ref_apl = (0.614, 0.609, 0.618) ref_area = (38.397, 38.934) apl = membrane.get_apl(by_type=False) print("APL: avg:%.3f - L1 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f - L2 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f " % ( apl[0], len(membrane.leaflet1), apl[1][0], apl[1][1], apl[1][2], apl[1][3], len(membrane.leaflet2), apl[2][0], apl[2][1], apl[2][2], apl[2][3])) assert_allclose(apl[0], ref_apl[0], rtol=RTOL) assert_allclose(apl[1][0], ref_apl[1], rtol=RTOL) assert_allclose(apl[2][0], ref_apl[2], rtol=RTOL) assert_allclose(apl[1][3], ref_area[0], rtol=RTOL) assert_allclose(apl[2][3], ref_area[1], rtol=RTOL) def test_apl_model_bilayer_prot(frame_model_bilayer_prot): frame = frame_model_bilayer_prot membrane = frame.get_membranes()[0] ref_apl = (0.653, 0.653, 0.653) ref_area = (156.627, 156.707) apl = membrane.get_apl(by_type=False) print("APL: avg:%.3f - L1 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f - L2 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f " % ( apl[0], len(membrane.leaflet1), apl[1][0], apl[1][1], apl[1][2], apl[1][3], len(membrane.leaflet2), apl[2][0], apl[2][1], apl[2][2], apl[2][3])) assert_allclose(apl[0], ref_apl[0], rtol=RTOL) assert_allclose(apl[1][0], ref_apl[1], rtol=RTOL) assert_allclose(apl[2][0], ref_apl[2], rtol=RTOL) assert_allclose(apl[1][3], ref_area[0], rtol=RTOL) assert_allclose(apl[2][3], ref_area[1], rtol=RTOL) def test_apl_bilayer_prot(frame_bilayer_prot): frame = frame_bilayer_prot membrane = frame.get_membranes()[0] ref_apl = (0.689, 0.672, 0.707) ref_area = (37.640, 39.564) apl = membrane.get_apl(by_type=False) print("APL: avg:%.3f - L1 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f - L2 (%i lipids): APL=%.3f (min:%.3f - max:%.3f), area=%.3f " % ( apl[0], len(membrane.leaflet1), apl[1][0], apl[1][1], apl[1][2], apl[1][3], len(membrane.leaflet2), apl[2][0], apl[2][1], apl[2][2], apl[2][3])) assert_allclose(apl[0], ref_apl[0], rtol=RTOL) assert_allclose(apl[1][0], ref_apl[1], rtol=RTOL) assert_allclose(apl[2][0], ref_apl[2], rtol=RTOL) assert_allclose(apl[1][3], ref_area[0], rtol=RTOL) assert_allclose(apl[2][3], ref_area[1], rtol=RTOL)
gpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 27, 4900, 26, 2366, 27, 5174, 13, 2063, 26, 841, 27, 4363, 13, 8741, 13, 632, 26, 20613, 27, 1882, 199, 3, 6695, 26, 20849, 29, 20, 26414, 20105, 29, 20, 25966, 29, 20, 199, 3, 199, 3, 221, 1898, 334, 35, 9, 6171, 13, 9261, 221, 428, 5741, 66, 1810, 24555, 699, 2133, 810, 88, 665, 261, 66, 1810, 24555, 14, 464, 335, 810, 88, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 259, 961, 570, 365, 1777, 402, 481, 619, 4929, 73, 45, 14, 199, 3, 199, 3, 259, 481, 619, 4929, 73, 45, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 259, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 259, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 481, 619, 4929, 73, 45, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 259, 3180, 543, 481, 619, 4929, 73, 45, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 3, 13641, 8925, 199, 646, 2680, 465, 980, 199, 504, 2680, 14, 4776, 492, 702, 63, 4398, 63, 1452, 12, 702, 63, 7520, 199, 199, 3, 10111, 8925, 199, 504, 2508, 492, 6170, 63, 7660, 199, 504, 2508, 492, 6170, 63, 10466, 199, 504, 1275, 492, 2787, 63, 1238, 63, 66, 382, 1187, 281, 12, 2787, 63, 66, 382, 1187, 281, 12, 2787, 63, 1238, 63, 432, 338, 2265, 12, 2787, 63, 432, 338, 2265, 12, 2787, 63, 1238, 63, 66, 382, 1187, 281, 63, 2745, 4202, 272, 2787, 63, 66, 382, 1187, 281, 63, 2745, 12, 2787, 63, 66, 382, 1187, 281, 63, 12636, 280, 271, 12, 2787, 63, 66, 382, 1187, 281, 63, 27972, 199, 199, 11876, 2228, 275, 959, 69, 13, 19, 199, 199, 21584, 63, 3438, 275, 3842, 1840, 2020, 5238, 395, 673, 334, 8251, 12, 2948, 395, 673, 334, 7991, 12, 14711, 1874, 199, 199, 9646, 63, 3438, 275, 3474, 1960, 2020, 2948, 467, 359, 5863, 12, 2948, 467, 359, 5863, 12, 9601, 467, 359, 1960, 12, 9601, 2677, 199, 199, 7241, 63, 9646, 63, 3438, 275, 3474, 8251, 2020, 2948, 467, 359, 7991, 12, 2948, 467, 359, 7991, 12, 1926, 467, 359, 8251, 12, 1926, 2677, 199, 199, 15315, 63, 9646, 63, 3438, 275, 3474, 26451, 2020, 2948, 467, 359, 969, 383, 12, 413, 1960, 467, 359, 969, 383, 12, 4944, 383, 467, 359, 26451, 12, 4944, 383, 2677, 199, 199, 388, 696, 432, 63, 3438, 275, 3474, 1400, 2020, 14711, 467, 359, 1840, 12, 5238, 467, 359, 13595, 12, 14711, 467, 359, 13595, 12, 9601, 467, 359, 7991, 12, 9601, 467, 359, 1840, 12, 16074, 467, 359, 8251, 12, 31921, 467, 359, 1960, 12, 16074, 467, 2116, 359, 1960, 12, 1926, 2677, 421, 199, 318, 511, 63, 16295, 63, 529, 27936, 63, 21584, 837, 272, 2984, 63, 529, 27936, 275, 499, 2635, 14, 19, 9892, 2194, 1184, 1184, 11062, 272, 1126, 27936, 275, 6170, 63, 7660, 14, 362, 63, 16295, 63, 529, 27936, 8, 1590, 14, 1144, 8, 21584, 63, 3438, 430, 339, 702, 63, 4398, 63, 1452, 8, 529, 27936, 12, 2984, 63, 529, 27936, 9, 421, 199, 318, 511, 63, 16295, 63, 6789, 63, 21584, 837, 272, 2984, 63, 6789, 275, 6877, 1400, 14, 16, 272, 9150, 275, 6170, 63, 7660, 14, 362, 63, 16295, 63, 6789, 8, 1590, 14, 1144, 8, 21584, 63, 3438, 430, 339, 702, 63, 4398, 63, 1452, 8, 6789, 12, 2984, 63, 6789, 9, 421, 199, 318, 511, 63, 16295, 63, 529, 27936, 63, 9646, 837, 272, 2984, 63, 529, 27936, 275, 23466, 14, 16, 272, 1126, 27936, 275, 6170, 63, 7660, 14, 362, 63, 16295, 63, 529, 27936, 8, 1590, 14, 1144, 8, 9646, 63, 3438, 430, 339, 702, 63, 4398, 63, 1452, 8, 529, 27936, 12, 2984, 63, 529, 27936, 9, 421, 199, 318, 511, 63, 16295, 63, 6789, 63, 9646, 837, 272, 2984, 63, 6789, 275, 841, 993, 14, 16, 272, 9150, 275, 6170, 63, 7660, 14, 362, 63, 16295, 63, 6789, 8, 1590, 14, 1144, 8, 9646, 63, 3438, 430, 339, 702, 63, 4398, 63, 1452, 8, 6789, 12, 2984, 63, 6789, 9, 421, 199, 318, 511, 63, 16295, 63, 374, 63, 17183, 837, 272, 8446, 275, 980, 14, 1144, 8, 9646, 63, 3438, 9, 272, 2376, 63, 17183, 275, 980, 14, 1144, 779, 1840, 2020, 1926, 566, 272, 2376, 63, 22431, 275, 980, 14, 1144, 779, 8269, 2020, 12293, 566, 339, 702, 6170, 63, 7660, 14, 374, 63, 17183, 63, 16295, 8, 6023, 12, 2376, 63, 17183, 9, 272, 702, 440, 6170, 63, 7660, 14, 374, 63, 17183, 63, 16295, 8, 6023, 12, 2376, 63, 22431, 9, 421, 199, 318, 511, 63, 16295, 63, 2764, 3637, 63, 23149, 316, 837, 272, 406, 696, 432, 275, 980, 14, 1144, 8, 388, 696, 432, 63, 3438, 9, 272, 12386, 275, 980, 14, 1144, 8, 9646, 63, 3438, 9, 339, 2984, 63, 7548, 1915, 275, 3474, 1960, 12, 25186, 14, 1272, 467, 359, 6889, 12, 2948, 467, 359, 13643, 12, 2948, 467, 359, 5863, 12, 25186, 14, 1272, 467, 673, 359, 5863, 12, 9601, 467, 359, 7991, 12, 9601, 467, 359, 1840, 12, 16074, 467, 359, 10848, 12, 9601, 467, 359, 6889, 12, 9601, 467, 359, 1960, 12, 16074, 2677, 272, 11353, 1915, 275, 6170, 63, 7660, 14, 362, 63, 7548, 1915, 63, 16295, 8, 388, 696, 432, 12, 12386, 9, 272, 702, 63, 4398, 63, 1452, 8, 7548, 1915, 12, 2984, 63, 7548, 1915, 12, 499, 9, 339, 2984, 63, 6789, 275 ]
[ 1882, 2803, 26, 2774, 13, 24, 27, 4900, 26, 2366, 27, 5174, 13, 2063, 26, 841, 27, 4363, 13, 8741, 13, 632, 26, 20613, 27, 1882, 199, 3, 6695, 26, 20849, 29, 20, 26414, 20105, 29, 20, 25966, 29, 20, 199, 3, 199, 3, 221, 1898, 334, 35, 9, 6171, 13, 9261, 221, 428, 5741, 66, 1810, 24555, 699, 2133, 810, 88, 665, 261, 66, 1810, 24555, 14, 464, 335, 810, 88, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 259, 961, 570, 365, 1777, 402, 481, 619, 4929, 73, 45, 14, 199, 3, 199, 3, 259, 481, 619, 4929, 73, 45, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 259, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 259, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 481, 619, 4929, 73, 45, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 259, 3180, 543, 481, 619, 4929, 73, 45, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 3, 13641, 8925, 199, 646, 2680, 465, 980, 199, 504, 2680, 14, 4776, 492, 702, 63, 4398, 63, 1452, 12, 702, 63, 7520, 199, 199, 3, 10111, 8925, 199, 504, 2508, 492, 6170, 63, 7660, 199, 504, 2508, 492, 6170, 63, 10466, 199, 504, 1275, 492, 2787, 63, 1238, 63, 66, 382, 1187, 281, 12, 2787, 63, 66, 382, 1187, 281, 12, 2787, 63, 1238, 63, 432, 338, 2265, 12, 2787, 63, 432, 338, 2265, 12, 2787, 63, 1238, 63, 66, 382, 1187, 281, 63, 2745, 4202, 272, 2787, 63, 66, 382, 1187, 281, 63, 2745, 12, 2787, 63, 66, 382, 1187, 281, 63, 12636, 280, 271, 12, 2787, 63, 66, 382, 1187, 281, 63, 27972, 199, 199, 11876, 2228, 275, 959, 69, 13, 19, 199, 199, 21584, 63, 3438, 275, 3842, 1840, 2020, 5238, 395, 673, 334, 8251, 12, 2948, 395, 673, 334, 7991, 12, 14711, 1874, 199, 199, 9646, 63, 3438, 275, 3474, 1960, 2020, 2948, 467, 359, 5863, 12, 2948, 467, 359, 5863, 12, 9601, 467, 359, 1960, 12, 9601, 2677, 199, 199, 7241, 63, 9646, 63, 3438, 275, 3474, 8251, 2020, 2948, 467, 359, 7991, 12, 2948, 467, 359, 7991, 12, 1926, 467, 359, 8251, 12, 1926, 2677, 199, 199, 15315, 63, 9646, 63, 3438, 275, 3474, 26451, 2020, 2948, 467, 359, 969, 383, 12, 413, 1960, 467, 359, 969, 383, 12, 4944, 383, 467, 359, 26451, 12, 4944, 383, 2677, 199, 199, 388, 696, 432, 63, 3438, 275, 3474, 1400, 2020, 14711, 467, 359, 1840, 12, 5238, 467, 359, 13595, 12, 14711, 467, 359, 13595, 12, 9601, 467, 359, 7991, 12, 9601, 467, 359, 1840, 12, 16074, 467, 359, 8251, 12, 31921, 467, 359, 1960, 12, 16074, 467, 2116, 359, 1960, 12, 1926, 2677, 421, 199, 318, 511, 63, 16295, 63, 529, 27936, 63, 21584, 837, 272, 2984, 63, 529, 27936, 275, 499, 2635, 14, 19, 9892, 2194, 1184, 1184, 11062, 272, 1126, 27936, 275, 6170, 63, 7660, 14, 362, 63, 16295, 63, 529, 27936, 8, 1590, 14, 1144, 8, 21584, 63, 3438, 430, 339, 702, 63, 4398, 63, 1452, 8, 529, 27936, 12, 2984, 63, 529, 27936, 9, 421, 199, 318, 511, 63, 16295, 63, 6789, 63, 21584, 837, 272, 2984, 63, 6789, 275, 6877, 1400, 14, 16, 272, 9150, 275, 6170, 63, 7660, 14, 362, 63, 16295, 63, 6789, 8, 1590, 14, 1144, 8, 21584, 63, 3438, 430, 339, 702, 63, 4398, 63, 1452, 8, 6789, 12, 2984, 63, 6789, 9, 421, 199, 318, 511, 63, 16295, 63, 529, 27936, 63, 9646, 837, 272, 2984, 63, 529, 27936, 275, 23466, 14, 16, 272, 1126, 27936, 275, 6170, 63, 7660, 14, 362, 63, 16295, 63, 529, 27936, 8, 1590, 14, 1144, 8, 9646, 63, 3438, 430, 339, 702, 63, 4398, 63, 1452, 8, 529, 27936, 12, 2984, 63, 529, 27936, 9, 421, 199, 318, 511, 63, 16295, 63, 6789, 63, 9646, 837, 272, 2984, 63, 6789, 275, 841, 993, 14, 16, 272, 9150, 275, 6170, 63, 7660, 14, 362, 63, 16295, 63, 6789, 8, 1590, 14, 1144, 8, 9646, 63, 3438, 430, 339, 702, 63, 4398, 63, 1452, 8, 6789, 12, 2984, 63, 6789, 9, 421, 199, 318, 511, 63, 16295, 63, 374, 63, 17183, 837, 272, 8446, 275, 980, 14, 1144, 8, 9646, 63, 3438, 9, 272, 2376, 63, 17183, 275, 980, 14, 1144, 779, 1840, 2020, 1926, 566, 272, 2376, 63, 22431, 275, 980, 14, 1144, 779, 8269, 2020, 12293, 566, 339, 702, 6170, 63, 7660, 14, 374, 63, 17183, 63, 16295, 8, 6023, 12, 2376, 63, 17183, 9, 272, 702, 440, 6170, 63, 7660, 14, 374, 63, 17183, 63, 16295, 8, 6023, 12, 2376, 63, 22431, 9, 421, 199, 318, 511, 63, 16295, 63, 2764, 3637, 63, 23149, 316, 837, 272, 406, 696, 432, 275, 980, 14, 1144, 8, 388, 696, 432, 63, 3438, 9, 272, 12386, 275, 980, 14, 1144, 8, 9646, 63, 3438, 9, 339, 2984, 63, 7548, 1915, 275, 3474, 1960, 12, 25186, 14, 1272, 467, 359, 6889, 12, 2948, 467, 359, 13643, 12, 2948, 467, 359, 5863, 12, 25186, 14, 1272, 467, 673, 359, 5863, 12, 9601, 467, 359, 7991, 12, 9601, 467, 359, 1840, 12, 16074, 467, 359, 10848, 12, 9601, 467, 359, 6889, 12, 9601, 467, 359, 1960, 12, 16074, 2677, 272, 11353, 1915, 275, 6170, 63, 7660, 14, 362, 63, 7548, 1915, 63, 16295, 8, 388, 696, 432, 12, 12386, 9, 272, 702, 63, 4398, 63, 1452, 8, 7548, 1915, 12, 2984, 63, 7548, 1915, 12, 499, 9, 339, 2984, 63, 6789, 275, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
tareqalayan/ansible
lib/ansible/modules/cloud/openstack/os_image.py
25
6182
#!/usr/bin/python # Copyright (c) 2015 Hewlett-Packard Development Company, L.P. # Copyright (c) 2013, Benno Joy <benno@ansible.com> # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type # TODO(mordred): we need to support "location"(v1) and "locations"(v2) ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} DOCUMENTATION = ''' --- module: os_image short_description: Add/Delete images from OpenStack Cloud extends_documentation_fragment: openstack version_added: "2.0" author: "Monty Taylor (@emonty)" description: - Add or Remove images from the OpenStack Image Repository options: name: description: - Name that has to be given to the image required: true id: version_added: "2.4" description: - The Id of the image checksum: version_added: "2.5" description: - The checksum of the image disk_format: description: - The format of the disk that is getting uploaded default: qcow2 container_format: description: - The format of the container default: bare owner: description: - The owner of the image min_disk: description: - The minimum disk space (in GB) required to boot this image min_ram: description: - The minimum ram (in MB) required to boot this image is_public: description: - Whether the image can be accessed publicly. Note that publicizing an image requires admin role by default. type: bool default: 'yes' filename: description: - The path to the file which has to be uploaded ramdisk: description: - The name of an existing ramdisk image that will be associated with this image kernel: description: - The name of an existing kernel image that will be associated with this image properties: description: - Additional properties to be associated with this image default: {} state: description: - Should the resource be present or absent. choices: [present, absent] default: present availability_zone: description: - Ignored. Present for backwards compatibility requirements: ["openstacksdk"] ''' EXAMPLES = ''' # Upload an image from a local file named cirros-0.3.0-x86_64-disk.img - os_image: auth: auth_url: https://identity.example.com username: admin password: passme project_name: admin name: cirros container_format: bare disk_format: qcow2 state: present filename: cirros-0.3.0-x86_64-disk.img kernel: cirros-vmlinuz ramdisk: cirros-initrd properties: cpu_arch: x86_64 distro: ubuntu ''' from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module def main(): argument_spec = openstack_full_argument_spec( name=dict(required=True), id=dict(default=None), checksum=dict(default=None), disk_format=dict(default='qcow2', choices=['ami', 'ari', 'aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi', 'iso', 'vhdx', 'ploop']), container_format=dict(default='bare', choices=['ami', 'aki', 'ari', 'bare', 'ovf', 'ova', 'docker']), owner=dict(default=None), min_disk=dict(type='int', default=0), min_ram=dict(type='int', default=0), is_public=dict(type='bool', default=False), filename=dict(default=None), ramdisk=dict(default=None), kernel=dict(default=None), properties=dict(type='dict', default={}), state=dict(default='present', choices=['absent', 'present']), ) module_kwargs = openstack_module_kwargs() module = AnsibleModule(argument_spec, **module_kwargs) sdk, cloud = openstack_cloud_from_module(module) try: changed = False if module.params['checksum']: image = cloud.get_image(name_or_id=None, filters={'checksum': module.params['checksum']}) else: image = cloud.get_image(name_or_id=module.params['name']) if module.params['state'] == 'present': if not image: kwargs = {} if module.params['id'] is not None: kwargs['id'] = module.params['id'] image = cloud.create_image( name=module.params['name'], filename=module.params['filename'], disk_format=module.params['disk_format'], container_format=module.params['container_format'], wait=module.params['wait'], timeout=module.params['timeout'], is_public=module.params['is_public'], min_disk=module.params['min_disk'], min_ram=module.params['min_ram'], **kwargs ) changed = True if not module.params['wait']: module.exit_json(changed=changed, image=image, id=image.id) cloud.update_image_properties( image=image, kernel=module.params['kernel'], ramdisk=module.params['ramdisk'], **module.params['properties']) image = cloud.get_image(name_or_id=image.id) module.exit_json(changed=changed, image=image, id=image.id) elif module.params['state'] == 'absent': if not image: changed = False else: cloud.delete_image( name_or_id=module.params['name'], wait=module.params['wait'], timeout=module.params['timeout']) changed = True module.exit_json(changed=changed) except sdk.exceptions.OpenStackCloudException as e: module.fail_json(msg=str(e), extra_data=e.extra_data) if __name__ == "__main__": main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 199, 3, 1898, 334, 67, 9, 6900, 27849, 13, 29471, 15290, 15878, 12, 491, 14, 48, 14, 199, 3, 1898, 334, 67, 9, 6171, 12, 26844, 889, 7135, 89, 665, 18486, 889, 32, 4853, 14, 957, 30, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 421, 199, 3, 3254, 8, 77, 2181, 581, 304, 781, 1929, 370, 2291, 298, 1985, 26507, 86, 17, 9, 436, 298, 8022, 26507, 86, 18, 9, 199, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 421, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 747, 63, 1569, 199, 3612, 63, 1802, 26, 2654, 15, 5392, 5935, 687, 14260, 8142, 199, 11036, 63, 9970, 63, 7677, 26, 13869, 199, 1023, 63, 3270, 26, 298, 18, 14, 16, 2, 199, 2502, 26, 298, 6671, 369, 377, 1187, 25339, 8593, 69, 2106, 369, 2924, 199, 1802, 26, 2043, 446, 2654, 503, 5852, 5935, 687, 314, 14260, 6047, 24426, 199, 1419, 26, 2043, 536, 26, 1362, 1369, 26, 267, 446, 2812, 626, 965, 370, 506, 1627, 370, 314, 1834, 1362, 1415, 26, 2549, 2043, 1305, 26, 1362, 1015, 63, 3270, 26, 298, 18, 14, 20, 2, 1362, 1369, 26, 267, 446, 710, 15418, 402, 314, 1834, 2043, 9040, 26, 1362, 1015, 63, 3270, 26, 298, 18, 14, 21, 2, 1362, 1369, 26, 267, 446, 710, 9040, 402, 314, 1834, 2043, 4543, 63, 908, 26, 1362, 1369, 26, 267, 446, 710, 1475, 402, 314, 4543, 626, 365, 10232, 14238, 1362, 849, 26, 1894, 19969, 18, 2043, 3970, 63, 908, 26, 1362, 1369, 26, 267, 446, 710, 1475, 402, 314, 3970, 1362, 849, 26, 18753, 2043, 5771, 26, 1362, 1369, 26, 267, 446, 710, 5771, 402, 314, 1834, 2043, 1748, 63, 4032, 26, 1362, 1369, 26, 267, 446, 710, 7481, 4543, 4601, 334, 262, 18553, 9, 1415, 370, 8498, 642, 1834, 2043, 1748, 63, 5975, 26, 1362, 1369, 26, 267, 446, 710, 7481, 21394, 334, 262, 19487, 9, 1415, 370, 8498, 642, 1834, 2043, 365, 63, 3455, 26, 1362, 1369, 26, 267, 446, 7480, 314, 1834, 883, 506, 13810, 7974, 317, 429, 89, 14, 3390, 626, 7974, 317, 559, 20135, 376, 1834, 5074, 4628, 4719, 701, 849, 14, 1362, 730, 26, 2155, 1362, 849, 26, 283, 5066, 7, 2043, 1788, 26, 1362, 1369, 26, 267, 446, 710, 931, 370, 314, 570, 1314, 965, 370, 506, 14238, 2043, 21394, 4032, 26, 1362, 1369, 26, 267, 446, 710, 536, 402, 376, 3411, 21394, 4032, 1834, 626, 911, 506, 4568, 543, 642, 1834, 2043, 5114, 26, 1362, 1369, 26, 267, 446, 710, 536, 402, 376, 3411, 5114, 1834, 626, 911, 506, 4568, 543, 642, 1834, 2043, 4382, 26, 1362, 1369, 26, 267, 446, 10961, 4382, 370, 506, 4568, 543, 642, 1834, 1362, 849, 26, 1052, 2043, 1174, 26, 1362, 1369, 26, 2126, 446, 7719, 314, 2073, 506, 3451, 503, 9552, 14, 1362, 3415, 26, 359, 1881, 12, 9552, 61, 1362, 849, 26, 3451, 2043, 14962, 63, 2619, 26, 1362, 1369, 26, 2126, 446, 27662, 14, 5543, 1150, 367, 8552, 7163, 199, 7538, 26, 2097, 8512, 9277, 937, 199, 2344, 199, 199, 8918, 275, 1449, 199, 3, 19149, 376, 1834, 687, 282, 2257, 570, 4310, 286, 723, 4796, 13, 16, 14, 19, 14, 16, 13, 88, 1184, 63, 772, 13, 4032, 14, 4060, 199, 13, 747, 63, 1569, 26, 272, 1790, 26, 489, 1790, 63, 633, 26, 4178, 921, 5582, 14, 2694, 14, 957, 489, 3434, 26, 4628, 489, 2505, 26, 986, 278, 489, 2199, 63, 354, 26, 4628, 272, 536, 26, 286, 723, 4796, 272, 3970, 63, 908, 26, 18753, 272, 4543, 63, 908, 26, 1894, 19969, 18, 272, 1174, 26, 3451, 272, 1788, 26, 286, 723, 4796, 13, 16, 14, 19, 14, 16, 13, 88, 1184, 63, 772, 13, 4032, 14, 4060, 272, 5114, 26, 286, 723, 4796, 13, 2611, 472, 9494, 272, 21394, 4032, 26, 286, 723, 4796, 13, 826, 6883, 272, 4382, 26, 489, 5033, 63, 1047, 26, 671, 1184, 63, 772, 489, 20499, 26, 399, 19313, 199, 2344, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 8512, 492, 13869, 63, 2861, 63, 2094, 63, 1650, 12, 13869, 63, 578, 63, 958, 12, 13869, 63, 4091, 63, 504, 63, 578, 421, 199, 318, 2446, 837, 339, 1423, 63, 1650, 275, 13869, 63, 2861, 63, 2094, 63, 1650, 8, 267, 536, 29, 807, 8, 2427, 29, 549, 395, 267, 1305, 29, 807, 8, 885, 29, 403, 395, 267, 9040, 29, 807, 8, 885, 29, 403, 395, 267, 4543, 63, 908, 29, 807, 8, 885, 534, 81, 19969, 18, 297, 3415, 2968, 13496, 297, 283, 759, 297, 283, 27387, 297, 283, 20961, 297, 283, 29499, 297, 283, 1773, 297, 283, 81, 19969, 18, 297, 283, 17493, 297, 283, 4595, 297, 283, 20961, 88, 297, 283, 80, 3813, 3815, 267, 3970, 63, 908, 29, 807, 8, 885, 534, 14890, 297, 3415, 2968, 13496, 297, 283, 27387, 297, 283, 759, 297, 283, 14890, 297, 283, 8822, 70, 297, 283, 79, 3042, 297, 283, 9991, 3815, 267, 5771, 29, 807, 8, 885, 29, 403, 395, 267, 1748, 63, 4032, 29, 807, 8, 466, 534, 442, 297, 849, 29, 16, 395, 267, 1748, 63, 5975, 29, 807, 8, 466, 534, 442, 297, 849, 29, 16, 395, 267, 365, 63, 3455, 29, 807, 8, 466, 534, 2245, 297, 849, 29, 797, 395, 267, 1788, 29, 807, 8, 885, 29, 403, 395, 267, 21394, 4032, 29, 807, 8, 885, 29, 403, 395, 267, 5114, 29, 807, 8, 885, 29, 403, 395, 267, 4382, 29, 807, 8, 466, 534, 807, 297, 849, 7622, 395, 267, 1174, 29, 807, 8, 885, 534, 1881, 297, 3415, 2968, 5575, 297, 283, 1881, 3815, 272, 776, 272, 859 ]
[ 2647, 15, 1393, 15, 1548, 199, 199, 3, 1898, 334, 67, 9, 6900, 27849, 13, 29471, 15290, 15878, 12, 491, 14, 48, 14, 199, 3, 1898, 334, 67, 9, 6171, 12, 26844, 889, 7135, 89, 665, 18486, 889, 32, 4853, 14, 957, 30, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 421, 199, 3, 3254, 8, 77, 2181, 581, 304, 781, 1929, 370, 2291, 298, 1985, 26507, 86, 17, 9, 436, 298, 8022, 26507, 86, 18, 9, 199, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 421, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 747, 63, 1569, 199, 3612, 63, 1802, 26, 2654, 15, 5392, 5935, 687, 14260, 8142, 199, 11036, 63, 9970, 63, 7677, 26, 13869, 199, 1023, 63, 3270, 26, 298, 18, 14, 16, 2, 199, 2502, 26, 298, 6671, 369, 377, 1187, 25339, 8593, 69, 2106, 369, 2924, 199, 1802, 26, 2043, 446, 2654, 503, 5852, 5935, 687, 314, 14260, 6047, 24426, 199, 1419, 26, 2043, 536, 26, 1362, 1369, 26, 267, 446, 2812, 626, 965, 370, 506, 1627, 370, 314, 1834, 1362, 1415, 26, 2549, 2043, 1305, 26, 1362, 1015, 63, 3270, 26, 298, 18, 14, 20, 2, 1362, 1369, 26, 267, 446, 710, 15418, 402, 314, 1834, 2043, 9040, 26, 1362, 1015, 63, 3270, 26, 298, 18, 14, 21, 2, 1362, 1369, 26, 267, 446, 710, 9040, 402, 314, 1834, 2043, 4543, 63, 908, 26, 1362, 1369, 26, 267, 446, 710, 1475, 402, 314, 4543, 626, 365, 10232, 14238, 1362, 849, 26, 1894, 19969, 18, 2043, 3970, 63, 908, 26, 1362, 1369, 26, 267, 446, 710, 1475, 402, 314, 3970, 1362, 849, 26, 18753, 2043, 5771, 26, 1362, 1369, 26, 267, 446, 710, 5771, 402, 314, 1834, 2043, 1748, 63, 4032, 26, 1362, 1369, 26, 267, 446, 710, 7481, 4543, 4601, 334, 262, 18553, 9, 1415, 370, 8498, 642, 1834, 2043, 1748, 63, 5975, 26, 1362, 1369, 26, 267, 446, 710, 7481, 21394, 334, 262, 19487, 9, 1415, 370, 8498, 642, 1834, 2043, 365, 63, 3455, 26, 1362, 1369, 26, 267, 446, 7480, 314, 1834, 883, 506, 13810, 7974, 317, 429, 89, 14, 3390, 626, 7974, 317, 559, 20135, 376, 1834, 5074, 4628, 4719, 701, 849, 14, 1362, 730, 26, 2155, 1362, 849, 26, 283, 5066, 7, 2043, 1788, 26, 1362, 1369, 26, 267, 446, 710, 931, 370, 314, 570, 1314, 965, 370, 506, 14238, 2043, 21394, 4032, 26, 1362, 1369, 26, 267, 446, 710, 536, 402, 376, 3411, 21394, 4032, 1834, 626, 911, 506, 4568, 543, 642, 1834, 2043, 5114, 26, 1362, 1369, 26, 267, 446, 710, 536, 402, 376, 3411, 5114, 1834, 626, 911, 506, 4568, 543, 642, 1834, 2043, 4382, 26, 1362, 1369, 26, 267, 446, 10961, 4382, 370, 506, 4568, 543, 642, 1834, 1362, 849, 26, 1052, 2043, 1174, 26, 1362, 1369, 26, 2126, 446, 7719, 314, 2073, 506, 3451, 503, 9552, 14, 1362, 3415, 26, 359, 1881, 12, 9552, 61, 1362, 849, 26, 3451, 2043, 14962, 63, 2619, 26, 1362, 1369, 26, 2126, 446, 27662, 14, 5543, 1150, 367, 8552, 7163, 199, 7538, 26, 2097, 8512, 9277, 937, 199, 2344, 199, 199, 8918, 275, 1449, 199, 3, 19149, 376, 1834, 687, 282, 2257, 570, 4310, 286, 723, 4796, 13, 16, 14, 19, 14, 16, 13, 88, 1184, 63, 772, 13, 4032, 14, 4060, 199, 13, 747, 63, 1569, 26, 272, 1790, 26, 489, 1790, 63, 633, 26, 4178, 921, 5582, 14, 2694, 14, 957, 489, 3434, 26, 4628, 489, 2505, 26, 986, 278, 489, 2199, 63, 354, 26, 4628, 272, 536, 26, 286, 723, 4796, 272, 3970, 63, 908, 26, 18753, 272, 4543, 63, 908, 26, 1894, 19969, 18, 272, 1174, 26, 3451, 272, 1788, 26, 286, 723, 4796, 13, 16, 14, 19, 14, 16, 13, 88, 1184, 63, 772, 13, 4032, 14, 4060, 272, 5114, 26, 286, 723, 4796, 13, 2611, 472, 9494, 272, 21394, 4032, 26, 286, 723, 4796, 13, 826, 6883, 272, 4382, 26, 489, 5033, 63, 1047, 26, 671, 1184, 63, 772, 489, 20499, 26, 399, 19313, 199, 2344, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 8512, 492, 13869, 63, 2861, 63, 2094, 63, 1650, 12, 13869, 63, 578, 63, 958, 12, 13869, 63, 4091, 63, 504, 63, 578, 421, 199, 318, 2446, 837, 339, 1423, 63, 1650, 275, 13869, 63, 2861, 63, 2094, 63, 1650, 8, 267, 536, 29, 807, 8, 2427, 29, 549, 395, 267, 1305, 29, 807, 8, 885, 29, 403, 395, 267, 9040, 29, 807, 8, 885, 29, 403, 395, 267, 4543, 63, 908, 29, 807, 8, 885, 534, 81, 19969, 18, 297, 3415, 2968, 13496, 297, 283, 759, 297, 283, 27387, 297, 283, 20961, 297, 283, 29499, 297, 283, 1773, 297, 283, 81, 19969, 18, 297, 283, 17493, 297, 283, 4595, 297, 283, 20961, 88, 297, 283, 80, 3813, 3815, 267, 3970, 63, 908, 29, 807, 8, 885, 534, 14890, 297, 3415, 2968, 13496, 297, 283, 27387, 297, 283, 759, 297, 283, 14890, 297, 283, 8822, 70, 297, 283, 79, 3042, 297, 283, 9991, 3815, 267, 5771, 29, 807, 8, 885, 29, 403, 395, 267, 1748, 63, 4032, 29, 807, 8, 466, 534, 442, 297, 849, 29, 16, 395, 267, 1748, 63, 5975, 29, 807, 8, 466, 534, 442, 297, 849, 29, 16, 395, 267, 365, 63, 3455, 29, 807, 8, 466, 534, 2245, 297, 849, 29, 797, 395, 267, 1788, 29, 807, 8, 885, 29, 403, 395, 267, 21394, 4032, 29, 807, 8, 885, 29, 403, 395, 267, 5114, 29, 807, 8, 885, 29, 403, 395, 267, 4382, 29, 807, 8, 466, 534, 807, 297, 849, 7622, 395, 267, 1174, 29, 807, 8, 885, 534, 1881, 297, 3415, 2968, 5575, 297, 283, 1881, 3815, 272, 776, 272, 859, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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ests.py
48
6008
# coding=utf-8 from django.db import IntegrityError from django.test import TestCase from django.core.exceptions import ValidationError from oscar.apps.catalogue.models import (Product, ProductClass, ProductAttribute, AttributeOption) from oscar.test import factories from oscar.test.decorators import ignore_deprecation_warnings class ProductTests(TestCase): def setUp(self): self.product_class, _ = ProductClass.objects.get_or_create( name='Clothing') class ProductCreationTests(ProductTests): def setUp(self): super(ProductCreationTests, self).setUp() ProductAttribute.objects.create(product_class=self.product_class, name='Number of pages', code='num_pages', type='integer') Product.ENABLE_ATTRIBUTE_BINDING = True def tearDown(self): Product.ENABLE_ATTRIBUTE_BINDING = False def test_create_products_with_attributes(self): product = Product(upc='1234', product_class=self.product_class, title='testing') product.attr.num_pages = 100 product.save() def test_none_upc_is_represented_as_empty_string(self): product = Product(product_class=self.product_class, title='testing', upc=None) self.assertEqual(product.upc, u'') def test_upc_uniqueness_enforced(self): Product.objects.create(product_class=self.product_class, title='testing', upc='bah') self.assertRaises(IntegrityError, Product.objects.create, product_class=self.product_class, title='testing', upc='bah') def test_allow_two_products_without_upc(self): for x in range(2): Product.objects.create(product_class=self.product_class, title='testing', upc=None) class TopLevelProductTests(ProductTests): def test_top_level_products_must_have_titles(self): product = Product(product_class=self.product_class) self.assertRaises(ValidationError, product.clean) def test_top_level_products_must_have_product_class(self): product = Product(title=u"Kopfhörer") self.assertRaises(ValidationError, product.clean) def test_top_level_products_are_part_of_browsable_set(self): product = Product.objects.create( product_class=self.product_class, title=u"Kopfhörer") self.assertEqual(set([product]), set(Product.browsable.all())) class ChildProductTests(ProductTests): def setUp(self): super(ChildProductTests, self).setUp() self.parent = Product.objects.create( title="Parent product", product_class=self.product_class, structure=Product.PARENT, is_discountable=False) def test_child_products_dont_need_titles(self): Product.objects.create( parent=self.parent, structure=Product.CHILD) def test_child_products_dont_need_a_product_class(self): Product.objects.create(parent=self.parent, structure=Product.CHILD) def test_child_products_inherit_fields(self): p = Product.objects.create( parent=self.parent, structure=Product.CHILD, is_discountable=True) self.assertEqual("Parent product", p.get_title()) self.assertEqual("Clothing", p.get_product_class().name) self.assertEqual(False, p.get_is_discountable()) def test_child_products_are_not_part_of_browsable_set(self): Product.objects.create( product_class=self.product_class, parent=self.parent, structure=Product.CHILD) self.assertEqual(set([self.parent]), set(Product.browsable.all())) @ignore_deprecation_warnings def test_have_a_minimum_price(self): self.assertIsNone(self.parent.min_child_price_excl_tax) factories.ProductFactory( parent=self.parent, structure=Product.CHILD, stockrecords__price_excl_tax=5) self.assertEqual(5, self.parent.min_child_price_excl_tax) factories.ProductFactory( parent=self.parent, structure=Product.CHILD, stockrecords__price_excl_tax=3) self.assertEqual(3, self.parent.min_child_price_excl_tax) class TestAChildProduct(TestCase): def setUp(self): clothing = ProductClass.objects.create( name='Clothing', requires_shipping=True) self.parent = clothing.products.create( title="Parent", structure=Product.PARENT) self.child = self.parent.children.create(structure=Product.CHILD) def test_delegates_requires_shipping_logic(self): self.assertTrue(self.child.is_shipping_required) class ProductAttributeCreationTests(TestCase): def test_validating_option_attribute(self): option_group = factories.AttributeOptionGroupFactory() option_1 = factories.AttributeOptionFactory(group=option_group) option_2 = factories.AttributeOptionFactory(group=option_group) pa = factories.ProductAttribute( type='option', option_group=option_group) self.assertRaises(ValidationError, pa.validate_value, 'invalid') pa.validate_value(option_1) pa.validate_value(option_2) invalid_option = AttributeOption(option='invalid option') self.assertRaises( ValidationError, pa.validate_value, invalid_option) def test_entity_attributes(self): unrelated_object = factories.PartnerFactory() attribute = factories.ProductAttributeFactory(type='entity') attribute_value = factories.ProductAttributeValueFactory( attribute=attribute, value_entity=unrelated_object) self.assertEqual(attribute_value.value, unrelated_object)
bsd-3-clause
[ 3, 2803, 29, 1624, 13, 24, 199, 504, 1639, 14, 697, 492, 26864, 199, 504, 1639, 14, 396, 492, 7640, 199, 504, 1639, 14, 1018, 14, 3924, 492, 8505, 199, 199, 504, 312, 22707, 14, 5181, 14, 22330, 14, 992, 492, 334, 5884, 12, 12705, 2543, 12, 1460, 12705, 1646, 12, 1460, 3882, 2602, 9, 199, 504, 312, 22707, 14, 396, 492, 22115, 199, 504, 312, 22707, 14, 396, 14, 11582, 492, 3686, 63, 15383, 63, 5451, 421, 199, 533, 12705, 2925, 8, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 2558, 63, 533, 12, 485, 275, 12705, 2543, 14, 1462, 14, 362, 63, 269, 63, 981, 8, 288, 536, 534, 3337, 2127, 358, 421, 199, 533, 12705, 13921, 2925, 8, 5884, 2925, 304, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 5884, 13921, 2925, 12, 291, 680, 5996, 342, 267, 12705, 1646, 14, 1462, 14, 981, 8, 2558, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 3147, 536, 534, 3259, 402, 6497, 297, 3147, 1233, 534, 1507, 63, 5856, 297, 3147, 730, 534, 4115, 358, 267, 12705, 14, 8898, 63, 17075, 63, 28347, 275, 715, 339, 347, 6766, 8, 277, 304, 267, 12705, 14, 8898, 63, 17075, 63, 28347, 275, 756, 339, 347, 511, 63, 981, 63, 13336, 63, 1045, 63, 2987, 8, 277, 304, 267, 3336, 275, 12705, 8, 384, 67, 534, 4321, 297, 2079, 3336, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 2079, 2538, 534, 4776, 358, 267, 3336, 14, 962, 14, 1507, 63, 5856, 275, 2948, 267, 3336, 14, 2117, 342, 339, 347, 511, 63, 3592, 63, 384, 67, 63, 374, 63, 264, 10317, 63, 305, 63, 1667, 63, 875, 8, 277, 304, 267, 3336, 275, 12705, 8, 2558, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 2079, 2538, 534, 4776, 297, 1536, 67, 29, 403, 9, 267, 291, 14, 629, 8, 2558, 14, 384, 67, 12, 399, 17483, 339, 347, 511, 63, 384, 67, 63, 5411, 31820, 63, 19817, 68, 8, 277, 304, 267, 12705, 14, 1462, 14, 981, 8, 2558, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 3044, 2538, 534, 4776, 297, 1536, 67, 534, 2470, 72, 358, 267, 291, 14, 1855, 8, 24823, 12, 12705, 14, 1462, 14, 981, 12, 2079, 3336, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 2079, 2538, 534, 4776, 297, 1536, 67, 534, 2470, 72, 358, 339, 347, 511, 63, 3306, 63, 5601, 63, 13336, 63, 7395, 63, 384, 67, 8, 277, 304, 267, 367, 671, 315, 1425, 8, 18, 304, 288, 12705, 14, 1462, 14, 981, 8, 2558, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 3521, 2538, 534, 4776, 297, 1536, 67, 29, 403, 9, 421, 199, 533, 14132, 4670, 5884, 2925, 8, 5884, 2925, 304, 339, 347, 511, 63, 2119, 63, 1896, 63, 13336, 63, 7790, 63, 7804, 63, 8916, 8, 277, 304, 267, 3336, 275, 12705, 8, 2558, 63, 533, 29, 277, 14, 2558, 63, 533, 9, 267, 291, 14, 1855, 8, 8172, 12, 3336, 14, 3118, 9, 339, 347, 511, 63, 2119, 63, 1896, 63, 13336, 63, 7790, 63, 7804, 63, 2558, 63, 533, 8, 277, 304, 267, 3336, 275, 12705, 8, 1213, 29, 85, 2, 43, 411, 12853, 14614, 3859, 531, 267, 291, 14, 1855, 8, 8172, 12, 3336, 14, 3118, 9, 339, 347, 511, 63, 2119, 63, 1896, 63, 13336, 63, 1530, 63, 2064, 63, 1618, 63, 3208, 83, 461, 63, 409, 8, 277, 304, 267, 3336, 275, 12705, 14, 1462, 14, 981, 8, 288, 3336, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 2538, 29, 85, 2, 43, 411, 12853, 14614, 3859, 531, 267, 291, 14, 629, 8, 409, 779, 2558, 2522, 663, 8, 5884, 14, 3208, 83, 461, 14, 452, 4059, 421, 199, 533, 12988, 5884, 2925, 8, 5884, 2925, 304, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 3493, 5884, 2925, 12, 291, 680, 5996, 342, 267, 291, 14, 1708, 275, 12705, 14, 1462, 14, 981, 8, 288, 2538, 628, 6652, 3336, 401, 288, 3336, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 288, 5523, 29, 5884, 14, 20562, 12, 288, 365, 63, 15446, 461, 29, 797, 9, 339, 347, 511, 63, 1739, 63, 13336, 63, 18671, 63, 9321, 63, 8916, 8, 277, 304, 267, 12705, 14, 1462, 14, 981, 8, 288, 1676, 29, 277, 14, 1708, 12, 5523, 29, 5884, 14, 30460, 9, 339, 347, 511, 63, 1739, 63, 13336, 63, 18671, 63, 9321, 63, 65, 63, 2558, 63, 533, 8, 277, 304, 267, 12705, 14, 1462, 14, 981, 8, 1708, 29, 277, 14, 1708, 12, 5523, 29, 5884, 14, 30460, 9, 339, 347, 511, 63, 1739, 63, 13336, 63, 6486, 63, 955, 8, 277, 304, 267, 299, 275, 12705, 14, 1462, 14, 981, 8, 288, 1676, 29, 277, 14, 1708, 12, 288, 5523, 29, 5884, 14, 30460, 12, 288, 365, 63, 15446, 461, 29, 549, 9, 267, 291, 14, 629, 480, 6652, 3336, 401, 299, 14, 362, 63, 1213, 1012, 267, 291, 14, 629, 480, 3337, 2127, 401, 299, 14, 362, 63, 2558, 63, 533, 1252, 354, 9, 267, 291, 14, 629, 8, 797, 12, 299, 14, 362, 63, 374, 63, 15446, 461, 1012, 339, 347, 511, 63, 1739, 63, 13336, 63, 1530, 63, 1397, 63, 2064, 63, 1618, 63, 3208, 83, 461, 63, 409, 8, 277, 304, 267, 12705, 14, 1462, 14, 981, 8, 288, 3336, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 1676, 29, 277, 14, 1708, 12, 288, 5523, 29, 5884, 14, 30460, 9, 267, 291, 14, 629, 8, 409, 779, 277, 14, 1708, 2522, 663, 8, 5884, 14, 3208, 83, 461, 14, 452, 4059, 339, 768, 4247, 63, 15383, 63, 5451, 272, 347, 511, 63, 7804, 63, 65, 63, 10700, 63, 4777, 8, 277, 304, 267, 291, 14, 7702, 8, 277, 14, 1708, 14, 827, 63, 1739, 63, 4777, 63, 476, 429, 63, 5530, 9, 267, 22115, 14, 5884, 2927, 8, 288, 1676, 29, 277, 14, 1708, 12, 5523, 29, 5884, 14, 30460, 12, 288, 10952, 6502, 363, 4777, 63, 476, 429, 63, 5530, 29, 21, 9, 267, 291, 14, 629, 8, 21, 12, 291, 14, 1708, 14, 827 ]
[ 2803, 29, 1624, 13, 24, 199, 504, 1639, 14, 697, 492, 26864, 199, 504, 1639, 14, 396, 492, 7640, 199, 504, 1639, 14, 1018, 14, 3924, 492, 8505, 199, 199, 504, 312, 22707, 14, 5181, 14, 22330, 14, 992, 492, 334, 5884, 12, 12705, 2543, 12, 1460, 12705, 1646, 12, 1460, 3882, 2602, 9, 199, 504, 312, 22707, 14, 396, 492, 22115, 199, 504, 312, 22707, 14, 396, 14, 11582, 492, 3686, 63, 15383, 63, 5451, 421, 199, 533, 12705, 2925, 8, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 2558, 63, 533, 12, 485, 275, 12705, 2543, 14, 1462, 14, 362, 63, 269, 63, 981, 8, 288, 536, 534, 3337, 2127, 358, 421, 199, 533, 12705, 13921, 2925, 8, 5884, 2925, 304, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 5884, 13921, 2925, 12, 291, 680, 5996, 342, 267, 12705, 1646, 14, 1462, 14, 981, 8, 2558, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 3147, 536, 534, 3259, 402, 6497, 297, 3147, 1233, 534, 1507, 63, 5856, 297, 3147, 730, 534, 4115, 358, 267, 12705, 14, 8898, 63, 17075, 63, 28347, 275, 715, 339, 347, 6766, 8, 277, 304, 267, 12705, 14, 8898, 63, 17075, 63, 28347, 275, 756, 339, 347, 511, 63, 981, 63, 13336, 63, 1045, 63, 2987, 8, 277, 304, 267, 3336, 275, 12705, 8, 384, 67, 534, 4321, 297, 2079, 3336, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 2079, 2538, 534, 4776, 358, 267, 3336, 14, 962, 14, 1507, 63, 5856, 275, 2948, 267, 3336, 14, 2117, 342, 339, 347, 511, 63, 3592, 63, 384, 67, 63, 374, 63, 264, 10317, 63, 305, 63, 1667, 63, 875, 8, 277, 304, 267, 3336, 275, 12705, 8, 2558, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 2079, 2538, 534, 4776, 297, 1536, 67, 29, 403, 9, 267, 291, 14, 629, 8, 2558, 14, 384, 67, 12, 399, 17483, 339, 347, 511, 63, 384, 67, 63, 5411, 31820, 63, 19817, 68, 8, 277, 304, 267, 12705, 14, 1462, 14, 981, 8, 2558, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 3044, 2538, 534, 4776, 297, 1536, 67, 534, 2470, 72, 358, 267, 291, 14, 1855, 8, 24823, 12, 12705, 14, 1462, 14, 981, 12, 2079, 3336, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 2079, 2538, 534, 4776, 297, 1536, 67, 534, 2470, 72, 358, 339, 347, 511, 63, 3306, 63, 5601, 63, 13336, 63, 7395, 63, 384, 67, 8, 277, 304, 267, 367, 671, 315, 1425, 8, 18, 304, 288, 12705, 14, 1462, 14, 981, 8, 2558, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 3521, 2538, 534, 4776, 297, 1536, 67, 29, 403, 9, 421, 199, 533, 14132, 4670, 5884, 2925, 8, 5884, 2925, 304, 339, 347, 511, 63, 2119, 63, 1896, 63, 13336, 63, 7790, 63, 7804, 63, 8916, 8, 277, 304, 267, 3336, 275, 12705, 8, 2558, 63, 533, 29, 277, 14, 2558, 63, 533, 9, 267, 291, 14, 1855, 8, 8172, 12, 3336, 14, 3118, 9, 339, 347, 511, 63, 2119, 63, 1896, 63, 13336, 63, 7790, 63, 7804, 63, 2558, 63, 533, 8, 277, 304, 267, 3336, 275, 12705, 8, 1213, 29, 85, 2, 43, 411, 12853, 14614, 3859, 531, 267, 291, 14, 1855, 8, 8172, 12, 3336, 14, 3118, 9, 339, 347, 511, 63, 2119, 63, 1896, 63, 13336, 63, 1530, 63, 2064, 63, 1618, 63, 3208, 83, 461, 63, 409, 8, 277, 304, 267, 3336, 275, 12705, 14, 1462, 14, 981, 8, 288, 3336, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 2538, 29, 85, 2, 43, 411, 12853, 14614, 3859, 531, 267, 291, 14, 629, 8, 409, 779, 2558, 2522, 663, 8, 5884, 14, 3208, 83, 461, 14, 452, 4059, 421, 199, 533, 12988, 5884, 2925, 8, 5884, 2925, 304, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 3493, 5884, 2925, 12, 291, 680, 5996, 342, 267, 291, 14, 1708, 275, 12705, 14, 1462, 14, 981, 8, 288, 2538, 628, 6652, 3336, 401, 288, 3336, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 288, 5523, 29, 5884, 14, 20562, 12, 288, 365, 63, 15446, 461, 29, 797, 9, 339, 347, 511, 63, 1739, 63, 13336, 63, 18671, 63, 9321, 63, 8916, 8, 277, 304, 267, 12705, 14, 1462, 14, 981, 8, 288, 1676, 29, 277, 14, 1708, 12, 5523, 29, 5884, 14, 30460, 9, 339, 347, 511, 63, 1739, 63, 13336, 63, 18671, 63, 9321, 63, 65, 63, 2558, 63, 533, 8, 277, 304, 267, 12705, 14, 1462, 14, 981, 8, 1708, 29, 277, 14, 1708, 12, 5523, 29, 5884, 14, 30460, 9, 339, 347, 511, 63, 1739, 63, 13336, 63, 6486, 63, 955, 8, 277, 304, 267, 299, 275, 12705, 14, 1462, 14, 981, 8, 288, 1676, 29, 277, 14, 1708, 12, 288, 5523, 29, 5884, 14, 30460, 12, 288, 365, 63, 15446, 461, 29, 549, 9, 267, 291, 14, 629, 480, 6652, 3336, 401, 299, 14, 362, 63, 1213, 1012, 267, 291, 14, 629, 480, 3337, 2127, 401, 299, 14, 362, 63, 2558, 63, 533, 1252, 354, 9, 267, 291, 14, 629, 8, 797, 12, 299, 14, 362, 63, 374, 63, 15446, 461, 1012, 339, 347, 511, 63, 1739, 63, 13336, 63, 1530, 63, 1397, 63, 2064, 63, 1618, 63, 3208, 83, 461, 63, 409, 8, 277, 304, 267, 12705, 14, 1462, 14, 981, 8, 288, 3336, 63, 533, 29, 277, 14, 2558, 63, 533, 12, 1676, 29, 277, 14, 1708, 12, 288, 5523, 29, 5884, 14, 30460, 9, 267, 291, 14, 629, 8, 409, 779, 277, 14, 1708, 2522, 663, 8, 5884, 14, 3208, 83, 461, 14, 452, 4059, 339, 768, 4247, 63, 15383, 63, 5451, 272, 347, 511, 63, 7804, 63, 65, 63, 10700, 63, 4777, 8, 277, 304, 267, 291, 14, 7702, 8, 277, 14, 1708, 14, 827, 63, 1739, 63, 4777, 63, 476, 429, 63, 5530, 9, 267, 22115, 14, 5884, 2927, 8, 288, 1676, 29, 277, 14, 1708, 12, 5523, 29, 5884, 14, 30460, 12, 288, 10952, 6502, 363, 4777, 63, 476, 429, 63, 5530, 29, 21, 9, 267, 291, 14, 629, 8, 21, 12, 291, 14, 1708, 14, 827, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
Southpaw-TACTIC/Team
src/python/Lib/optparse.py
5
62547
"""A powerful, extensible, and easy-to-use option parser. By Greg Ward <gward@python.net> Originally distributed as Optik. For support, use the optik-users@lists.sourceforge.net mailing list (http://lists.sourceforge.net/lists/listinfo/optik-users). Simple usage example: from optparse import OptionParser parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="write report to FILE", metavar="FILE") parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=True, help="don't print status messages to stdout") (options, args) = parser.parse_args() """ __version__ = "1.5.3" __all__ = ['Option', 'make_option', 'SUPPRESS_HELP', 'SUPPRESS_USAGE', 'Values', 'OptionContainer', 'OptionGroup', 'OptionParser', 'HelpFormatter', 'IndentedHelpFormatter', 'TitledHelpFormatter', 'OptParseError', 'OptionError', 'OptionConflictError', 'OptionValueError', 'BadOptionError'] __copyright__ = """ Copyright (c) 2001-2006 Gregory P. Ward. All rights reserved. Copyright (c) 2002-2006 Python Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ import sys, os import types import textwrap def _repr(self): return "<%s at 0x%x: %s>" % (self.__class__.__name__, id(self), self) # This file was generated from: # Id: option_parser.py 527 2006-07-23 15:21:30Z greg # Id: option.py 522 2006-06-11 16:22:03Z gward # Id: help.py 527 2006-07-23 15:21:30Z greg # Id: errors.py 509 2006-04-20 00:58:24Z gward try: from gettext import gettext except ImportError: def gettext(message): return message _ = gettext class OptParseError (Exception): def __init__(self, msg): self.msg = msg def __str__(self): return self.msg class OptionError (OptParseError): """ Raised if an Option instance is created with invalid or inconsistent arguments. """ def __init__(self, msg, option): self.msg = msg self.option_id = str(option) def __str__(self): if self.option_id: return "option %s: %s" % (self.option_id, self.msg) else: return self.msg class OptionConflictError (OptionError): """ Raised if conflicting options are added to an OptionParser. """ class OptionValueError (OptParseError): """ Raised if an invalid option value is encountered on the command line. """ class BadOptionError (OptParseError): """ Raised if an invalid option is seen on the command line. """ def __init__(self, opt_str): self.opt_str = opt_str def __str__(self): return _("no such option: %s") % self.opt_str class AmbiguousOptionError (BadOptionError): """ Raised if an ambiguous option is seen on the command line. """ def __init__(self, opt_str, possibilities): BadOptionError.__init__(self, opt_str) self.possibilities = possibilities def __str__(self): return (_("ambiguous option: %s (%s?)") % (self.opt_str, ", ".join(self.possibilities))) class HelpFormatter: """ Abstract base class for formatting option help. OptionParser instances should use one of the HelpFormatter subclasses for formatting help; by default IndentedHelpFormatter is used. Instance attributes: parser : OptionParser the controlling OptionParser instance indent_increment : int the number of columns to indent per nesting level max_help_position : int the maximum starting column for option help text help_position : int the calculated starting column for option help text; initially the same as the maximum width : int total number of columns for output (pass None to constructor for this value to be taken from the $COLUMNS environment variable) level : int current indentation level current_indent : int current indentation level (in columns) help_width : int number of columns available for option help text (calculated) default_tag : str text to replace with each option's default value, "%default" by default. Set to false value to disable default value expansion. option_strings : { Option : str } maps Option instances to the snippet of help text explaining the syntax of that option, e.g. "-h, --help" or "-fFILE, --file=FILE" _short_opt_fmt : str format string controlling how short options with values are printed in help text. Must be either "%s%s" ("-fFILE") or "%s %s" ("-f FILE"), because those are the two syntaxes that Optik supports. _long_opt_fmt : str similar but for long options; must be either "%s %s" ("--file FILE") or "%s=%s" ("--file=FILE"). """ NO_DEFAULT_VALUE = "none" def __init__(self, indent_increment, max_help_position, width, short_first): self.parser = None self.indent_increment = indent_increment self.help_position = self.max_help_position = max_help_position if width is None: try: width = int(os.environ['COLUMNS']) except (KeyError, ValueError): width = 80 width -= 2 self.width = width self.current_indent = 0 self.level = 0 self.help_width = None # computed later self.short_first = short_first self.default_tag = "%default" self.option_strings = {} self._short_opt_fmt = "%s %s" self._long_opt_fmt = "%s=%s" def set_parser(self, parser): self.parser = parser def set_short_opt_delimiter(self, delim): if delim not in ("", " "): raise ValueError( "invalid metavar delimiter for short options: %r" % delim) self._short_opt_fmt = "%s" + delim + "%s" def set_long_opt_delimiter(self, delim): if delim not in ("=", " "): raise ValueError( "invalid metavar delimiter for long options: %r" % delim) self._long_opt_fmt = "%s" + delim + "%s" def indent(self): self.current_indent += self.indent_increment self.level += 1 def dedent(self): self.current_indent -= self.indent_increment assert self.current_indent >= 0, "Indent decreased below 0." self.level -= 1 def format_usage(self, usage): raise NotImplementedError, "subclasses must implement" def format_heading(self, heading): raise NotImplementedError, "subclasses must implement" def _format_text(self, text): """ Format a paragraph of free-form text for inclusion in the help output at the current indentation level. """ text_width = self.width - self.current_indent indent = " "*self.current_indent return textwrap.fill(text, text_width, initial_indent=indent, subsequent_indent=indent) def format_description(self, description): if description: return self._format_text(description) + "\n" else: return "" def format_epilog(self, epilog): if epilog: return "\n" + self._format_text(epilog) + "\n" else: return "" def expand_default(self, option): if self.parser is None or not self.default_tag: return option.help default_value = self.parser.defaults.get(option.dest) if default_value is NO_DEFAULT or default_value is None: default_value = self.NO_DEFAULT_VALUE return option.help.replace(self.default_tag, str(default_value)) def format_option(self, option): # The help for each option consists of two parts: # * the opt strings and metavars # eg. ("-x", or "-fFILENAME, --file=FILENAME") # * the user-supplied help string # eg. ("turn on expert mode", "read data from FILENAME") # # If possible, we write both of these on the same line: # -x turn on expert mode # # But if the opt string list is too long, we put the help # string on a second line, indented to the same column it would # start in if it fit on the first line. # -fFILENAME, --file=FILENAME # read data from FILENAME result = [] opts = self.option_strings[option] opt_width = self.help_position - self.current_indent - 2 if len(opts) > opt_width: opts = "%*s%s\n" % (self.current_indent, "", opts) indent_first = self.help_position else: # start help on same line as opts opts = "%*s%-*s " % (self.current_indent, "", opt_width, opts) indent_first = 0 result.append(opts) if option.help: help_text = self.expand_default(option) help_lines = textwrap.wrap(help_text, self.help_width) result.append("%*s%s\n" % (indent_first, "", help_lines[0])) result.extend(["%*s%s\n" % (self.help_position, "", line) for line in help_lines[1:]]) elif opts[-1] != "\n": result.append("\n") return "".join(result) def store_option_strings(self, parser): self.indent() max_len = 0 for opt in parser.option_list: strings = self.format_option_strings(opt) self.option_strings[opt] = strings max_len = max(max_len, len(strings) + self.current_indent) self.indent() for group in parser.option_groups: for opt in group.option_list: strings = self.format_option_strings(opt) self.option_strings[opt] = strings max_len = max(max_len, len(strings) + self.current_indent) self.dedent() self.dedent() self.help_position = min(max_len + 2, self.max_help_position) self.help_width = self.width - self.help_position def format_option_strings(self, option): """Return a comma-separated list of option strings & metavariables.""" if option.takes_value(): metavar = option.metavar or option.dest.upper() short_opts = [self._short_opt_fmt % (sopt, metavar) for sopt in option._short_opts] long_opts = [self._long_opt_fmt % (lopt, metavar) for lopt in option._long_opts] else: short_opts = option._short_opts long_opts = option._long_opts if self.short_first: opts = short_opts + long_opts else: opts = long_opts + short_opts return ", ".join(opts) class IndentedHelpFormatter (HelpFormatter): """Format help with indented section bodies. """ def __init__(self, indent_increment=2, max_help_position=24, width=None, short_first=1): HelpFormatter.__init__( self, indent_increment, max_help_position, width, short_first) def format_usage(self, usage): return _("Usage: %s\n") % usage def format_heading(self, heading): return "%*s%s:\n" % (self.current_indent, "", heading) class TitledHelpFormatter (HelpFormatter): """Format help with underlined section headers. """ def __init__(self, indent_increment=0, max_help_position=24, width=None, short_first=0): HelpFormatter.__init__ ( self, indent_increment, max_help_position, width, short_first) def format_usage(self, usage): return "%s %s\n" % (self.format_heading(_("Usage")), usage) def format_heading(self, heading): return "%s\n%s\n" % (heading, "=-"[self.level] * len(heading)) def _parse_num(val, type): if val[:2].lower() == "0x": # hexadecimal radix = 16 elif val[:2].lower() == "0b": # binary radix = 2 val = val[2:] or "0" # have to remove "0b" prefix elif val[:1] == "0": # octal radix = 8 else: # decimal radix = 10 return type(val, radix) def _parse_int(val): return _parse_num(val, int) def _parse_long(val): return _parse_num(val, long) _builtin_cvt = { "int" : (_parse_int, _("integer")), "long" : (_parse_long, _("long integer")), "float" : (float, _("floating-point")), "complex" : (complex, _("complex")) } def check_builtin(option, opt, value): (cvt, what) = _builtin_cvt[option.type] try: return cvt(value) except ValueError: raise OptionValueError( _("option %s: invalid %s value: %r") % (opt, what, value)) def check_choice(option, opt, value): if value in option.choices: return value else: choices = ", ".join(map(repr, option.choices)) raise OptionValueError( _("option %s: invalid choice: %r (choose from %s)") % (opt, value, choices)) # Not supplying a default is different from a default of None, # so we need an explicit "not supplied" value. NO_DEFAULT = ("NO", "DEFAULT") class Option: """ Instance attributes: _short_opts : [string] _long_opts : [string] action : string type : string dest : string default : any nargs : int const : any choices : [string] callback : function callback_args : (any*) callback_kwargs : { string : any } help : string metavar : string """ # The list of instance attributes that may be set through # keyword args to the constructor. ATTRS = ['action', 'type', 'dest', 'default', 'nargs', 'const', 'choices', 'callback', 'callback_args', 'callback_kwargs', 'help', 'metavar'] # The set of actions allowed by option parsers. Explicitly listed # here so the constructor can validate its arguments. ACTIONS = ("store", "store_const", "store_true", "store_false", "append", "append_const", "count", "callback", "help", "version") # The set of actions that involve storing a value somewhere; # also listed just for constructor argument validation. (If # the action is one of these, there must be a destination.) STORE_ACTIONS = ("store", "store_const", "store_true", "store_false", "append", "append_const", "count") # The set of actions for which it makes sense to supply a value # type, ie. which may consume an argument from the command line. TYPED_ACTIONS = ("store", "append", "callback") # The set of actions which *require* a value type, ie. that # always consume an argument from the command line. ALWAYS_TYPED_ACTIONS = ("store", "append") # The set of actions which take a 'const' attribute. CONST_ACTIONS = ("store_const", "append_const") # The set of known types for option parsers. Again, listed here for # constructor argument validation. TYPES = ("string", "int", "long", "float", "complex", "choice") # Dictionary of argument checking functions, which convert and # validate option arguments according to the option type. # # Signature of checking functions is: # check(option : Option, opt : string, value : string) -> any # where # option is the Option instance calling the checker # opt is the actual option seen on the command-line # (eg. "-a", "--file") # value is the option argument seen on the command-line # # The return value should be in the appropriate Python type # for option.type -- eg. an integer if option.type == "int". # # If no checker is defined for a type, arguments will be # unchecked and remain strings. TYPE_CHECKER = { "int" : check_builtin, "long" : check_builtin, "float" : check_builtin, "complex": check_builtin, "choice" : check_choice, } # CHECK_METHODS is a list of unbound method objects; they are called # by the constructor, in order, after all attributes are # initialized. The list is created and filled in later, after all # the methods are actually defined. (I just put it here because I # like to define and document all class attributes in the same # place.) Subclasses that add another _check_*() method should # define their own CHECK_METHODS list that adds their check method # to those from this class. CHECK_METHODS = None # -- Constructor/initialization methods ---------------------------- def __init__(self, *opts, **attrs): # Set _short_opts, _long_opts attrs from 'opts' tuple. # Have to be set now, in case no option strings are supplied. self._short_opts = [] self._long_opts = [] opts = self._check_opt_strings(opts) self._set_opt_strings(opts) # Set all other attrs (action, type, etc.) from 'attrs' dict self._set_attrs(attrs) # Check all the attributes we just set. There are lots of # complicated interdependencies, but luckily they can be farmed # out to the _check_*() methods listed in CHECK_METHODS -- which # could be handy for subclasses! The one thing these all share # is that they raise OptionError if they discover a problem. for checker in self.CHECK_METHODS: checker(self) def _check_opt_strings(self, opts): # Filter out None because early versions of Optik had exactly # one short option and one long option, either of which # could be None. opts = filter(None, opts) if not opts: raise TypeError("at least one option string must be supplied") return opts def _set_opt_strings(self, opts): for opt in opts: if len(opt) < 2: raise OptionError( "invalid option string %r: " "must be at least two characters long" % opt, self) elif len(opt) == 2: if not (opt[0] == "-" and opt[1] != "-"): raise OptionError( "invalid short option string %r: " "must be of the form -x, (x any non-dash char)" % opt, self) self._short_opts.append(opt) else: if not (opt[0:2] == "--" and opt[2] != "-"): raise OptionError( "invalid long option string %r: " "must start with --, followed by non-dash" % opt, self) self._long_opts.append(opt) def _set_attrs(self, attrs): for attr in self.ATTRS: if attr in attrs: setattr(self, attr, attrs[attr]) del attrs[attr] else: if attr == 'default': setattr(self, attr, NO_DEFAULT) else: setattr(self, attr, None) if attrs: attrs = attrs.keys() attrs.sort() raise OptionError( "invalid keyword arguments: %s" % ", ".join(attrs), self) # -- Constructor validation methods -------------------------------- def _check_action(self): if self.action is None: self.action = "store" elif self.action not in self.ACTIONS: raise OptionError("invalid action: %r" % self.action, self) def _check_type(self): if self.type is None: if self.action in self.ALWAYS_TYPED_ACTIONS: if self.choices is not None: # The "choices" attribute implies "choice" type. self.type = "choice" else: # No type given? "string" is the most sensible default. self.type = "string" else: # Allow type objects or builtin type conversion functions # (int, str, etc.) as an alternative to their names. (The # complicated check of __builtin__ is only necessary for # Python 2.1 and earlier, and is short-circuited by the # first check on modern Pythons.) import __builtin__ if ( type(self.type) is types.TypeType or (hasattr(self.type, "__name__") and getattr(__builtin__, self.type.__name__, None) is self.type) ): self.type = self.type.__name__ if self.type == "str": self.type = "string" if self.type not in self.TYPES: raise OptionError("invalid option type: %r" % self.type, self) if self.action not in self.TYPED_ACTIONS: raise OptionError( "must not supply a type for action %r" % self.action, self) def _check_choice(self): if self.type == "choice": if self.choices is None: raise OptionError( "must supply a list of choices for type 'choice'", self) elif type(self.choices) not in (types.TupleType, types.ListType): raise OptionError( "choices must be a list of strings ('%s' supplied)" % str(type(self.choices)).split("'")[1], self) elif self.choices is not None: raise OptionError( "must not supply choices for type %r" % self.type, self) def _check_dest(self): # No destination given, and we need one for this action. The # self.type check is for callbacks that take a value. takes_value = (self.action in self.STORE_ACTIONS or self.type is not None) if self.dest is None and takes_value: # Glean a destination from the first long option string, # or from the first short option string if no long options. if self._long_opts: # eg. "--foo-bar" -> "foo_bar" self.dest = self._long_opts[0][2:].replace('-', '_') else: self.dest = self._short_opts[0][1] def _check_const(self): if self.action not in self.CONST_ACTIONS and self.const is not None: raise OptionError( "'const' must not be supplied for action %r" % self.action, self) def _check_nargs(self): if self.action in self.TYPED_ACTIONS: if self.nargs is None: self.nargs = 1 elif self.nargs is not None: raise OptionError( "'nargs' must not be supplied for action %r" % self.action, self) def _check_callback(self): if self.action == "callback": if not hasattr(self.callback, '__call__'): raise OptionError( "callback not callable: %r" % self.callback, self) if (self.callback_args is not None and type(self.callback_args) is not types.TupleType): raise OptionError( "callback_args, if supplied, must be a tuple: not %r" % self.callback_args, self) if (self.callback_kwargs is not None and type(self.callback_kwargs) is not types.DictType): raise OptionError( "callback_kwargs, if supplied, must be a dict: not %r" % self.callback_kwargs, self) else: if self.callback is not None: raise OptionError( "callback supplied (%r) for non-callback option" % self.callback, self) if self.callback_args is not None: raise OptionError( "callback_args supplied for non-callback option", self) if self.callback_kwargs is not None: raise OptionError( "callback_kwargs supplied for non-callback option", self) CHECK_METHODS = [_check_action, _check_type, _check_choice, _check_dest, _check_const, _check_nargs, _check_callback] # -- Miscellaneous methods ----------------------------------------- def __str__(self): return "/".join(self._short_opts + self._long_opts) __repr__ = _repr def takes_value(self): return self.type is not None def get_opt_string(self): if self._long_opts: return self._long_opts[0] else: return self._short_opts[0] # -- Processing methods -------------------------------------------- def check_value(self, opt, value): checker = self.TYPE_CHECKER.get(self.type) if checker is None: return value else: return checker(self, opt, value) def convert_value(self, opt, value): if value is not None: if self.nargs == 1: return self.check_value(opt, value) else: return tuple([self.check_value(opt, v) for v in value]) def process(self, opt, value, values, parser): # First, convert the value(s) to the right type. Howl if any # value(s) are bogus. value = self.convert_value(opt, value) # And then take whatever action is expected of us. # This is a separate method to make life easier for # subclasses to add new actions. return self.take_action( self.action, self.dest, opt, value, values, parser) def take_action(self, action, dest, opt, value, values, parser): if action == "store": setattr(values, dest, value) elif action == "store_const": setattr(values, dest, self.const) elif action == "store_true": setattr(values, dest, True) elif action == "store_false": setattr(values, dest, False) elif action == "append": values.ensure_value(dest, []).append(value) elif action == "append_const": values.ensure_value(dest, []).append(self.const) elif action == "count": setattr(values, dest, values.ensure_value(dest, 0) + 1) elif action == "callback": args = self.callback_args or () kwargs = self.callback_kwargs or {} self.callback(self, opt, value, parser, *args, **kwargs) elif action == "help": parser.print_help() parser.exit() elif action == "version": parser.print_version() parser.exit() else: raise RuntimeError, "unknown action %r" % self.action return 1 # class Option SUPPRESS_HELP = "SUPPRESS"+"HELP" SUPPRESS_USAGE = "SUPPRESS"+"USAGE" try: basestring except NameError: def isbasestring(x): return isinstance(x, (types.StringType, types.UnicodeType)) else: def isbasestring(x): return isinstance(x, basestring) class Values: def __init__(self, defaults=None): if defaults: for (attr, val) in defaults.items(): setattr(self, attr, val) def __str__(self): return str(self.__dict__) __repr__ = _repr def __cmp__(self, other): if isinstance(other, Values): return cmp(self.__dict__, other.__dict__) elif isinstance(other, types.DictType): return cmp(self.__dict__, other) else: return -1 def _update_careful(self, dict): """ Update the option values from an arbitrary dictionary, but only use keys from dict that already have a corresponding attribute in self. Any keys in dict without a corresponding attribute are silently ignored. """ for attr in dir(self): if attr in dict: dval = dict[attr] if dval is not None: setattr(self, attr, dval) def _update_loose(self, dict): """ Update the option values from an arbitrary dictionary, using all keys from the dictionary regardless of whether they have a corresponding attribute in self or not. """ self.__dict__.update(dict) def _update(self, dict, mode): if mode == "careful": self._update_careful(dict) elif mode == "loose": self._update_loose(dict) else: raise ValueError, "invalid update mode: %r" % mode def read_module(self, modname, mode="careful"): __import__(modname) mod = sys.modules[modname] self._update(vars(mod), mode) def read_file(self, filename, mode="careful"): vars = {} execfile(filename, vars) self._update(vars, mode) def ensure_value(self, attr, value): if not hasattr(self, attr) or getattr(self, attr) is None: setattr(self, attr, value) return getattr(self, attr) class OptionContainer: """ Abstract base class. Class attributes: standard_option_list : [Option] list of standard options that will be accepted by all instances of this parser class (intended to be overridden by subclasses). Instance attributes: option_list : [Option] the list of Option objects contained by this OptionContainer _short_opt : { string : Option } dictionary mapping short option strings, eg. "-f" or "-X", to the Option instances that implement them. If an Option has multiple short option strings, it will appears in this dictionary multiple times. [1] _long_opt : { string : Option } dictionary mapping long option strings, eg. "--file" or "--exclude", to the Option instances that implement them. Again, a given Option can occur multiple times in this dictionary. [1] defaults : { string : any } dictionary mapping option destination names to default values for each destination [1] [1] These mappings are common to (shared by) all components of the controlling OptionParser, where they are initially created. """ def __init__(self, option_class, conflict_handler, description): # Initialize the option list and related data structures. # This method must be provided by subclasses, and it must # initialize at least the following instance attributes: # option_list, _short_opt, _long_opt, defaults. self._create_option_list() self.option_class = option_class self.set_conflict_handler(conflict_handler) self.set_description(description) def _create_option_mappings(self): # For use by OptionParser constructor -- create the master # option mappings used by this OptionParser and all # OptionGroups that it owns. self._short_opt = {} # single letter -> Option instance self._long_opt = {} # long option -> Option instance self.defaults = {} # maps option dest -> default value def _share_option_mappings(self, parser): # For use by OptionGroup constructor -- use shared option # mappings from the OptionParser that owns this OptionGroup. self._short_opt = parser._short_opt self._long_opt = parser._long_opt self.defaults = parser.defaults def set_conflict_handler(self, handler): if handler not in ("error", "resolve"): raise ValueError, "invalid conflict_resolution value %r" % handler self.conflict_handler = handler def set_description(self, description): self.description = description def get_description(self): return self.description def destroy(self): """see OptionParser.destroy().""" del self._short_opt del self._long_opt del self.defaults # -- Option-adding methods ----------------------------------------- def _check_conflict(self, option): conflict_opts = [] for opt in option._short_opts: if opt in self._short_opt: conflict_opts.append((opt, self._short_opt[opt])) for opt in option._long_opts: if opt in self._long_opt: conflict_opts.append((opt, self._long_opt[opt])) if conflict_opts: handler = self.conflict_handler if handler == "error": raise OptionConflictError( "conflicting option string(s): %s" % ", ".join([co[0] for co in conflict_opts]), option) elif handler == "resolve": for (opt, c_option) in conflict_opts: if opt.startswith("--"): c_option._long_opts.remove(opt) del self._long_opt[opt] else: c_option._short_opts.remove(opt) del self._short_opt[opt] if not (c_option._short_opts or c_option._long_opts): c_option.container.option_list.remove(c_option) def add_option(self, *args, **kwargs): """add_option(Option) add_option(opt_str, ..., kwarg=val, ...) """ if type(args[0]) in types.StringTypes: option = self.option_class(*args, **kwargs) elif len(args) == 1 and not kwargs: option = args[0] if not isinstance(option, Option): raise TypeError, "not an Option instance: %r" % option else: raise TypeError, "invalid arguments" self._check_conflict(option) self.option_list.append(option) option.container = self for opt in option._short_opts: self._short_opt[opt] = option for opt in option._long_opts: self._long_opt[opt] = option if option.dest is not None: # option has a dest, we need a default if option.default is not NO_DEFAULT: self.defaults[option.dest] = option.default elif option.dest not in self.defaults: self.defaults[option.dest] = None return option def add_options(self, option_list): for option in option_list: self.add_option(option) # -- Option query/removal methods ---------------------------------- def get_option(self, opt_str): return (self._short_opt.get(opt_str) or self._long_opt.get(opt_str)) def has_option(self, opt_str): return (opt_str in self._short_opt or opt_str in self._long_opt) def remove_option(self, opt_str): option = self._short_opt.get(opt_str) if option is None: option = self._long_opt.get(opt_str) if option is None: raise ValueError("no such option %r" % opt_str) for opt in option._short_opts: del self._short_opt[opt] for opt in option._long_opts: del self._long_opt[opt] option.container.option_list.remove(option) # -- Help-formatting methods --------------------------------------- def format_option_help(self, formatter): if not self.option_list: return "" result = [] for option in self.option_list: if not option.help is SUPPRESS_HELP: result.append(formatter.format_option(option)) return "".join(result) def format_description(self, formatter): return formatter.format_description(self.get_description()) def format_help(self, formatter): result = [] if self.description: result.append(self.format_description(formatter)) if self.option_list: result.append(self.format_option_help(formatter)) return "\n".join(result) class OptionGroup (OptionContainer): def __init__(self, parser, title, description=None): self.parser = parser OptionContainer.__init__( self, parser.option_class, parser.conflict_handler, description) self.title = title def _create_option_list(self): self.option_list = [] self._share_option_mappings(self.parser) def set_title(self, title): self.title = title def destroy(self): """see OptionParser.destroy().""" OptionContainer.destroy(self) del self.option_list # -- Help-formatting methods --------------------------------------- def format_help(self, formatter): result = formatter.format_heading(self.title) formatter.indent() result += OptionContainer.format_help(self, formatter) formatter.dedent() return result class OptionParser (OptionContainer): """ Class attributes: standard_option_list : [Option] list of standard options that will be accepted by all instances of this parser class (intended to be overridden by subclasses). Instance attributes: usage : string a usage string for your program. Before it is displayed to the user, "%prog" will be expanded to the name of your program (self.prog or os.path.basename(sys.argv[0])). prog : string the name of the current program (to override os.path.basename(sys.argv[0])). epilog : string paragraph of help text to print after option help option_groups : [OptionGroup] list of option groups in this parser (option groups are irrelevant for parsing the command-line, but very useful for generating help) allow_interspersed_args : bool = true if true, positional arguments may be interspersed with options. Assuming -a and -b each take a single argument, the command-line -ablah foo bar -bboo baz will be interpreted the same as -ablah -bboo -- foo bar baz If this flag were false, that command line would be interpreted as -ablah -- foo bar -bboo baz -- ie. we stop processing options as soon as we see the first non-option argument. (This is the tradition followed by Python's getopt module, Perl's Getopt::Std, and other argument- parsing libraries, but it is generally annoying to users.) process_default_values : bool = true if true, option default values are processed similarly to option values from the command line: that is, they are passed to the type-checking function for the option's type (as long as the default value is a string). (This really only matters if you have defined custom types; see SF bug #955889.) Set it to false to restore the behaviour of Optik 1.4.1 and earlier. rargs : [string] the argument list currently being parsed. Only set when parse_args() is active, and continually trimmed down as we consume arguments. Mainly there for the benefit of callback options. largs : [string] the list of leftover arguments that we have skipped while parsing options. If allow_interspersed_args is false, this list is always empty. values : Values the set of option values currently being accumulated. Only set when parse_args() is active. Also mainly for callbacks. Because of the 'rargs', 'largs', and 'values' attributes, OptionParser is not thread-safe. If, for some perverse reason, you need to parse command-line arguments simultaneously in different threads, use different OptionParser instances. """ standard_option_list = [] def __init__(self, usage=None, option_list=None, option_class=Option, version=None, conflict_handler="error", description=None, formatter=None, add_help_option=True, prog=None, epilog=None): OptionContainer.__init__( self, option_class, conflict_handler, description) self.set_usage(usage) self.prog = prog self.version = version self.allow_interspersed_args = True self.process_default_values = True if formatter is None: formatter = IndentedHelpFormatter() self.formatter = formatter self.formatter.set_parser(self) self.epilog = epilog # Populate the option list; initial sources are the # standard_option_list class attribute, the 'option_list' # argument, and (if applicable) the _add_version_option() and # _add_help_option() methods. self._populate_option_list(option_list, add_help=add_help_option) self._init_parsing_state() def destroy(self): """ Declare that you are done with this OptionParser. This cleans up reference cycles so the OptionParser (and all objects referenced by it) can be garbage-collected promptly. After calling destroy(), the OptionParser is unusable. """ OptionContainer.destroy(self) for group in self.option_groups: group.destroy() del self.option_list del self.option_groups del self.formatter # -- Private methods ----------------------------------------------- # (used by our or OptionContainer's constructor) def _create_option_list(self): self.option_list = [] self.option_groups = [] self._create_option_mappings() def _add_help_option(self): self.add_option("-h", "--help", action="help", help=_("show this help message and exit")) def _add_version_option(self): self.add_option("--version", action="version", help=_("show program's version number and exit")) def _populate_option_list(self, option_list, add_help=True): if self.standard_option_list: self.add_options(self.standard_option_list) if option_list: self.add_options(option_list) if self.version: self._add_version_option() if add_help: self._add_help_option() def _init_parsing_state(self): # These are set in parse_args() for the convenience of callbacks. self.rargs = None self.largs = None self.values = None # -- Simple modifier methods --------------------------------------- def set_usage(self, usage): if usage is None: self.usage = _("%prog [options]") elif usage is SUPPRESS_USAGE: self.usage = None # For backwards compatibility with Optik 1.3 and earlier. elif usage.lower().startswith("usage: "): self.usage = usage[7:] else: self.usage = usage def enable_interspersed_args(self): """Set parsing to not stop on the first non-option, allowing interspersing switches with command arguments. This is the default behavior. See also disable_interspersed_args() and the class documentation description of the attribute allow_interspersed_args.""" self.allow_interspersed_args = True def disable_interspersed_args(self): """Set parsing to stop on the first non-option. Use this if you have a command processor which runs another command that has options of its own and you want to make sure these options don't get confused. """ self.allow_interspersed_args = False def set_process_default_values(self, process): self.process_default_values = process def set_default(self, dest, value): self.defaults[dest] = value def set_defaults(self, **kwargs): self.defaults.update(kwargs) def _get_all_options(self): options = self.option_list[:] for group in self.option_groups: options.extend(group.option_list) return options def get_default_values(self): if not self.process_default_values: # Old, pre-Optik 1.5 behaviour. return Values(self.defaults) defaults = self.defaults.copy() for option in self._get_all_options(): default = defaults.get(option.dest) if isbasestring(default): opt_str = option.get_opt_string() defaults[option.dest] = option.check_value(opt_str, default) return Values(defaults) # -- OptionGroup methods ------------------------------------------- def add_option_group(self, *args, **kwargs): # XXX lots of overlap with OptionContainer.add_option() if type(args[0]) is types.StringType: group = OptionGroup(self, *args, **kwargs) elif len(args) == 1 and not kwargs: group = args[0] if not isinstance(group, OptionGroup): raise TypeError, "not an OptionGroup instance: %r" % group if group.parser is not self: raise ValueError, "invalid OptionGroup (wrong parser)" else: raise TypeError, "invalid arguments" self.option_groups.append(group) return group def get_option_group(self, opt_str): option = (self._short_opt.get(opt_str) or self._long_opt.get(opt_str)) if option and option.container is not self: return option.container return None # -- Option-parsing methods ---------------------------------------- def _get_args(self, args): if args is None: return sys.argv[1:] else: return args[:] # don't modify caller's list def parse_args(self, args=None, values=None): """ parse_args(args : [string] = sys.argv[1:], values : Values = None) -> (values : Values, args : [string]) Parse the command-line options found in 'args' (default: sys.argv[1:]). Any errors result in a call to 'error()', which by default prints the usage message to stderr and calls sys.exit() with an error message. On success returns a pair (values, args) where 'values' is an Values instance (with all your option values) and 'args' is the list of arguments left over after parsing options. """ rargs = self._get_args(args) if values is None: values = self.get_default_values() # Store the halves of the argument list as attributes for the # convenience of callbacks: # rargs # the rest of the command-line (the "r" stands for # "remaining" or "right-hand") # largs # the leftover arguments -- ie. what's left after removing # options and their arguments (the "l" stands for "leftover" # or "left-hand") self.rargs = rargs self.largs = largs = [] self.values = values try: stop = self._process_args(largs, rargs, values) except (BadOptionError, OptionValueError), err: self.error(str(err)) args = largs + rargs return self.check_values(values, args) def check_values(self, values, args): """ check_values(values : Values, args : [string]) -> (values : Values, args : [string]) Check that the supplied option values and leftover arguments are valid. Returns the option values and leftover arguments (possibly adjusted, possibly completely new -- whatever you like). Default implementation just returns the passed-in values; subclasses may override as desired. """ return (values, args) def _process_args(self, largs, rargs, values): """_process_args(largs : [string], rargs : [string], values : Values) Process command-line arguments and populate 'values', consuming options and arguments from 'rargs'. If 'allow_interspersed_args' is false, stop at the first non-option argument. If true, accumulate any interspersed non-option arguments in 'largs'. """ while rargs: arg = rargs[0] # We handle bare "--" explicitly, and bare "-" is handled by the # standard arg handler since the short arg case ensures that the # len of the opt string is greater than 1. if arg == "--": del rargs[0] return elif arg[0:2] == "--": # process a single long option (possibly with value(s)) self._process_long_opt(rargs, values) elif arg[:1] == "-" and len(arg) > 1: # process a cluster of short options (possibly with # value(s) for the last one only) self._process_short_opts(rargs, values) elif self.allow_interspersed_args: largs.append(arg) del rargs[0] else: return # stop now, leave this arg in rargs # Say this is the original argument list: # [arg0, arg1, ..., arg(i-1), arg(i), arg(i+1), ..., arg(N-1)] # ^ # (we are about to process arg(i)). # # Then rargs is [arg(i), ..., arg(N-1)] and largs is a *subset* of # [arg0, ..., arg(i-1)] (any options and their arguments will have # been removed from largs). # # The while loop will usually consume 1 or more arguments per pass. # If it consumes 1 (eg. arg is an option that takes no arguments), # then after _process_arg() is done the situation is: # # largs = subset of [arg0, ..., arg(i)] # rargs = [arg(i+1), ..., arg(N-1)] # # If allow_interspersed_args is false, largs will always be # *empty* -- still a subset of [arg0, ..., arg(i-1)], but # not a very interesting subset! def _match_long_opt(self, opt): """_match_long_opt(opt : string) -> string Determine which long option string 'opt' matches, ie. which one it is an unambiguous abbrevation for. Raises BadOptionError if 'opt' doesn't unambiguously match any long option string. """ return _match_abbrev(opt, self._long_opt) def _process_long_opt(self, rargs, values): arg = rargs.pop(0) # Value explicitly attached to arg? Pretend it's the next # argument. if "=" in arg: (opt, next_arg) = arg.split("=", 1) rargs.insert(0, next_arg) had_explicit_value = True else: opt = arg had_explicit_value = False opt = self._match_long_opt(opt) option = self._long_opt[opt] if option.takes_value(): nargs = option.nargs if len(rargs) < nargs: if nargs == 1: self.error(_("%s option requires an argument") % opt) else: self.error(_("%s option requires %d arguments") % (opt, nargs)) elif nargs == 1: value = rargs.pop(0) else: value = tuple(rargs[0:nargs]) del rargs[0:nargs] elif had_explicit_value: self.error(_("%s option does not take a value") % opt) else: value = None option.process(opt, value, values, self) def _process_short_opts(self, rargs, values): arg = rargs.pop(0) stop = False i = 1 for ch in arg[1:]: opt = "-" + ch option = self._short_opt.get(opt) i += 1 # we have consumed a character if not option: raise BadOptionError(opt) if option.takes_value(): # Any characters left in arg? Pretend they're the # next arg, and stop consuming characters of arg. if i < len(arg): rargs.insert(0, arg[i:]) stop = True nargs = option.nargs if len(rargs) < nargs: if nargs == 1: self.error(_("%s option requires an argument") % opt) else: self.error(_("%s option requires %d arguments") % (opt, nargs)) elif nargs == 1: value = rargs.pop(0) else: value = tuple(rargs[0:nargs]) del rargs[0:nargs] else: # option doesn't take a value value = None option.process(opt, value, values, self) if stop: break # -- Feedback methods ---------------------------------------------- def get_prog_name(self): if self.prog is None: return os.path.basename(sys.argv[0]) else: return self.prog def expand_prog_name(self, s): return s.replace("%prog", self.get_prog_name()) def get_description(self): return self.expand_prog_name(self.description) def exit(self, status=0, msg=None): if msg: sys.stderr.write(msg) sys.exit(status) def error(self, msg): """error(msg : string) Print a usage message incorporating 'msg' to stderr and exit. If you override this in a subclass, it should not return -- it should either exit or raise an exception. """ self.print_usage(sys.stderr) self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg)) def get_usage(self): if self.usage: return self.formatter.format_usage( self.expand_prog_name(self.usage)) else: return "" def print_usage(self, file=None): """print_usage(file : file = stdout) Print the usage message for the current program (self.usage) to 'file' (default stdout). Any occurrence of the string "%prog" in self.usage is replaced with the name of the current program (basename of sys.argv[0]). Does nothing if self.usage is empty or not defined. """ if self.usage: print >>file, self.get_usage() def get_version(self): if self.version: return self.expand_prog_name(self.version) else: return "" def print_version(self, file=None): """print_version(file : file = stdout) Print the version message for this program (self.version) to 'file' (default stdout). As with print_usage(), any occurrence of "%prog" in self.version is replaced by the current program's name. Does nothing if self.version is empty or undefined. """ if self.version: print >>file, self.get_version() def format_option_help(self, formatter=None): if formatter is None: formatter = self.formatter formatter.store_option_strings(self) result = [] result.append(formatter.format_heading(_("Options"))) formatter.indent() if self.option_list: result.append(OptionContainer.format_option_help(self, formatter)) result.append("\n") for group in self.option_groups: result.append(group.format_help(formatter)) result.append("\n") formatter.dedent() # Drop the last "\n", or the header if no options or option groups: return "".join(result[:-1]) def format_epilog(self, formatter): return formatter.format_epilog(self.epilog) def format_help(self, formatter=None): if formatter is None: formatter = self.formatter result = [] if self.usage: result.append(self.get_usage() + "\n") if self.description: result.append(self.format_description(formatter) + "\n") result.append(self.format_option_help(formatter)) result.append(self.format_epilog(formatter)) return "".join(result) # used by test suite def _get_encoding(self, file): encoding = getattr(file, "encoding", None) if not encoding: encoding = sys.getdefaultencoding() return encoding def print_help(self, file=None): """print_help(file : file = stdout) Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout). """ if file is None: file = sys.stdout encoding = self._get_encoding(file) file.write(self.format_help().encode(encoding, "replace")) # class OptionParser def _match_abbrev(s, wordmap): """_match_abbrev(s : string, wordmap : {string : Option}) -> string Return the string key in 'wordmap' for which 's' is an unambiguous abbreviation. If 's' is found to be ambiguous or doesn't match any of 'words', raise BadOptionError. """ # Is there an exact match? if s in wordmap: return s else: # Isolate all words with s as a prefix. possibilities = [word for word in wordmap.keys() if word.startswith(s)] # No exact match, so there had better be just one possibility. if len(possibilities) == 1: return possibilities[0] elif not possibilities: raise BadOptionError(s) else: # More than one possible completion: ambiguous prefix. possibilities.sort() raise AmbiguousOptionError(s, possibilities) # Some day, there might be many Option classes. As of Optik 1.3, the # preferred way to instantiate Options is indirectly, via make_option(), # which will become a factory function when there are many Option # classes. make_option = Option
epl-1.0
[ 624, 33, 7074, 1893, 12, 2178, 1164, 12, 436, 8837, 13, 475, 13, 1180, 945, 1798, 14, 2999, 199, 2175, 29096, 644, 1005, 665, 71, 3079, 32, 1548, 14, 846, 30, 2999, 199, 12834, 1183, 1854, 465, 9319, 30298, 14, 2999, 199, 1858, 2291, 12, 675, 314, 1687, 30298, 13, 3707, 32, 6717, 14, 22943, 14, 846, 30939, 769, 202, 199, 8, 1014, 921, 6717, 14, 22943, 14, 846, 15, 6717, 15, 513, 815, 15, 411, 30298, 13, 3707, 680, 2999, 199, 3184, 4503, 2893, 26, 10060, 257, 687, 8691, 492, 13491, 10060, 257, 1798, 275, 13491, 342, 15497, 1798, 14, 525, 63, 1422, 6096, 70, 401, 4320, 493, 401, 2053, 628, 1501, 401, 27843, 1720, 628, 952, 3622, 370, 13024, 401, 8214, 628, 3817, 531, 15497, 1798, 14, 525, 63, 1422, 6096, 81, 401, 4320, 10243, 401, 27843, 1595, 628, 1617, 63, 3910, 401, 2053, 628, 3832, 401, 849, 29, 549, 12, 27843, 1720, 628, 13196, 1133, 870, 2004, 3788, 370, 3839, 531, 10060, 257, 334, 1419, 12, 1249, 9, 275, 1798, 14, 1122, 63, 589, 342, 202, 199, 624, 2999, 199, 363, 1023, 363, 275, 298, 17, 14, 21, 14, 19, 2, 2999, 199, 363, 452, 363, 275, 788, 2602, 297, 18691, 283, 1875, 63, 1422, 297, 18691, 283, 24023, 63, 17930, 297, 18691, 283, 24023, 63, 20274, 297, 18691, 283, 6550, 297, 18691, 283, 2602, 4076, 297, 18691, 283, 2602, 2448, 297, 18691, 283, 14553, 297, 18691, 283, 22779, 297, 18691, 283, 607, 14032, 22779, 297, 18691, 283, 52, 390, 1146, 22779, 297, 18691, 283, 9985, 9123, 297, 18691, 283, 16546, 297, 18691, 283, 2602, 15919, 547, 297, 18691, 283, 2602, 3393, 297, 18691, 283, 5725, 16546, 418, 2999, 199, 363, 7307, 363, 275, 408, 202, 199, 7384, 334, 67, 9, 12521, 13, 7968, 29096, 1089, 510, 14, 644, 1005, 14, 221, 2900, 4481, 4644, 14, 202, 199, 7384, 334, 67, 9, 14790, 13, 7968, 2018, 2290, 2752, 14, 221, 2900, 4481, 4644, 14, 2999, 199, 497, 4972, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 202, 199, 20945, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 202, 199, 10207, 26, 25052, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 1128, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 25052, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 1128, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 1128, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 25052, 627, 11443, 314, 536, 402, 314, 4132, 6590, 314, 1561, 402, 2399, 1128, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 1128, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 2999, 199, 24571, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 202, 199, 1311, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 202, 199, 2566, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 437, 202, 199, 14848, 3106, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 17632, 1549, 202, 199, 1864, 1766, 6436, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 202, 199, 1438, 9776, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 5471, 2296, 12, 202, 199, 6072, 3942, 4479, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 7126, 12, 1549, 202, 199, 2514, 9037, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 1634, 202, 199, 2673, 2477, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 202, 199, 6388, 9179, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 202, 199, 26734, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 202, 199, 624, 2999, 199, 646, 984, 12, 747, 202, 199, 646, 2943, 202, 199, 646, 13390, 2999, 199, 318, 485, 2722, 8, 277, 304, 1128, 372, 23054, 83, 737, 378, 88, 5, 88, 26, 450, 83, 4335, 450, 334, 277, 855, 533, 4914, 354, 3108, 1305, 8, 277, 395, 291, 9, 8065, 199, 3, 961, 570, 1990, 4046, 687, 26, 202, 199, 3, 257, 15418, 26, 945, 63, 2087, 14, 647, 959, 1465, 8315, 13, 1780, 13, 1789, 4114, 26, 2025, 26, 1216, 58, 486, 1135, 202, 199, 3, 257, 15418, 26, 945, 14, 647, 959, 1081, 8315, 13, 1690, 13, 845, 3193, 26, 1081, 26, 1644, 58, 486, 3079, 202, 199, 3, 257, 15418, 26, 1720, 14, 647, 959, 1465, 8315, 13, 1780, 13, 1789, 4114, 26, 2025, 26, 1216, 58, 486, 1135, 202, 199, 3, 257, 15418, 26, 2552, 14, 647, 959, 1643, 8315, 13, 966, 13, 1165, 8733, 26, 2010, 26, 1194, 58, 486, 3079, 2999, 199, 893, 26, 1128, 687, 9796, 492, 9796, 202, 199, 2590, 3545, 26, 1128, 347, 9796, 8, 1188, 304, 1039, 372, 1245, 202, 199, 63, 275, 9796, 8065, 199, 533, 593, 541, 9123, 334, 1726, 304, 1128, 347, 636, 826, 721, 277, 12, 1499, 304, 1039, 291, 14, 1328, 275, 1499, 2958, 347, 636, 495, 721, 277, 304, 1039, 372, 291, 14, 1328, 8065, 199, 533, 3207, 547, 334, 9985, 9123, 304, 1128, 408, 1128, 24997, 340, 376, 3207, 1256, 365, 2737, 543, 3866, 503, 1128, 27253, 2368, 14, 1128, 408, 2958, 347, 636, 826, 721, 277, 12, 1499, 12, 945, 304, 1039, 291, 14, 1328, 275, 1499, 1039, 291, 14, 1422, 63, 344, 275, 620, 8, 1422, 9, 2958, 347, 636, 495, 721, 277, 304, 1039, 340, 291, 14, 1422, 63, 344, 26, 1675, 372, 298, 1422, 450, 83, 26, 450, 83, 2, 450, 334, 277, 14, 1422, 63, 344, 12, 291, 14, 1328, 9, 1039, 587, 26, 1675, 372, 291, 14, 1328, 2999, 199, 533, 3207, 15919, 547, 334, 16546, 304, 1128, 408, 1128, 24997, 340, 28204, 1511, 787, 3483, 370, 376, 13491, 14, 1128, 408, 2999, 199, 533, 3207, 3393, 334, 9985, 9123, 304, 1128, 408, 1128, 24997, 340, 376, 3866, 945, 574, 365, 14556, 641, 314, 1414, 1128, 1004, 14, 1128, 408, 2999, 199, 533, 8857, 16546, 334, 9985, 9123, 304, 1128, 408, 1128, 24997, 340, 376, 3866, 945, 365, 6775, 641, 314, 1414, 1004, 14, 1128 ]
[ 33, 7074, 1893, 12, 2178, 1164, 12, 436, 8837, 13, 475, 13, 1180, 945, 1798, 14, 2999, 199, 2175, 29096, 644, 1005, 665, 71, 3079, 32, 1548, 14, 846, 30, 2999, 199, 12834, 1183, 1854, 465, 9319, 30298, 14, 2999, 199, 1858, 2291, 12, 675, 314, 1687, 30298, 13, 3707, 32, 6717, 14, 22943, 14, 846, 30939, 769, 202, 199, 8, 1014, 921, 6717, 14, 22943, 14, 846, 15, 6717, 15, 513, 815, 15, 411, 30298, 13, 3707, 680, 2999, 199, 3184, 4503, 2893, 26, 10060, 257, 687, 8691, 492, 13491, 10060, 257, 1798, 275, 13491, 342, 15497, 1798, 14, 525, 63, 1422, 6096, 70, 401, 4320, 493, 401, 2053, 628, 1501, 401, 27843, 1720, 628, 952, 3622, 370, 13024, 401, 8214, 628, 3817, 531, 15497, 1798, 14, 525, 63, 1422, 6096, 81, 401, 4320, 10243, 401, 27843, 1595, 628, 1617, 63, 3910, 401, 2053, 628, 3832, 401, 849, 29, 549, 12, 27843, 1720, 628, 13196, 1133, 870, 2004, 3788, 370, 3839, 531, 10060, 257, 334, 1419, 12, 1249, 9, 275, 1798, 14, 1122, 63, 589, 342, 202, 199, 624, 2999, 199, 363, 1023, 363, 275, 298, 17, 14, 21, 14, 19, 2, 2999, 199, 363, 452, 363, 275, 788, 2602, 297, 18691, 283, 1875, 63, 1422, 297, 18691, 283, 24023, 63, 17930, 297, 18691, 283, 24023, 63, 20274, 297, 18691, 283, 6550, 297, 18691, 283, 2602, 4076, 297, 18691, 283, 2602, 2448, 297, 18691, 283, 14553, 297, 18691, 283, 22779, 297, 18691, 283, 607, 14032, 22779, 297, 18691, 283, 52, 390, 1146, 22779, 297, 18691, 283, 9985, 9123, 297, 18691, 283, 16546, 297, 18691, 283, 2602, 15919, 547, 297, 18691, 283, 2602, 3393, 297, 18691, 283, 5725, 16546, 418, 2999, 199, 363, 7307, 363, 275, 408, 202, 199, 7384, 334, 67, 9, 12521, 13, 7968, 29096, 1089, 510, 14, 644, 1005, 14, 221, 2900, 4481, 4644, 14, 202, 199, 7384, 334, 67, 9, 14790, 13, 7968, 2018, 2290, 2752, 14, 221, 2900, 4481, 4644, 14, 2999, 199, 497, 4972, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 202, 199, 20945, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 202, 199, 10207, 26, 25052, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 1128, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 25052, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 1128, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 1128, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 25052, 627, 11443, 314, 536, 402, 314, 4132, 6590, 314, 1561, 402, 2399, 1128, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 1128, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 2999, 199, 24571, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 202, 199, 1311, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 202, 199, 2566, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 437, 202, 199, 14848, 3106, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 17632, 1549, 202, 199, 1864, 1766, 6436, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 202, 199, 1438, 9776, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 5471, 2296, 12, 202, 199, 6072, 3942, 4479, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 7126, 12, 1549, 202, 199, 2514, 9037, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 1634, 202, 199, 2673, 2477, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 202, 199, 6388, 9179, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 202, 199, 26734, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 202, 199, 624, 2999, 199, 646, 984, 12, 747, 202, 199, 646, 2943, 202, 199, 646, 13390, 2999, 199, 318, 485, 2722, 8, 277, 304, 1128, 372, 23054, 83, 737, 378, 88, 5, 88, 26, 450, 83, 4335, 450, 334, 277, 855, 533, 4914, 354, 3108, 1305, 8, 277, 395, 291, 9, 8065, 199, 3, 961, 570, 1990, 4046, 687, 26, 202, 199, 3, 257, 15418, 26, 945, 63, 2087, 14, 647, 959, 1465, 8315, 13, 1780, 13, 1789, 4114, 26, 2025, 26, 1216, 58, 486, 1135, 202, 199, 3, 257, 15418, 26, 945, 14, 647, 959, 1081, 8315, 13, 1690, 13, 845, 3193, 26, 1081, 26, 1644, 58, 486, 3079, 202, 199, 3, 257, 15418, 26, 1720, 14, 647, 959, 1465, 8315, 13, 1780, 13, 1789, 4114, 26, 2025, 26, 1216, 58, 486, 1135, 202, 199, 3, 257, 15418, 26, 2552, 14, 647, 959, 1643, 8315, 13, 966, 13, 1165, 8733, 26, 2010, 26, 1194, 58, 486, 3079, 2999, 199, 893, 26, 1128, 687, 9796, 492, 9796, 202, 199, 2590, 3545, 26, 1128, 347, 9796, 8, 1188, 304, 1039, 372, 1245, 202, 199, 63, 275, 9796, 8065, 199, 533, 593, 541, 9123, 334, 1726, 304, 1128, 347, 636, 826, 721, 277, 12, 1499, 304, 1039, 291, 14, 1328, 275, 1499, 2958, 347, 636, 495, 721, 277, 304, 1039, 372, 291, 14, 1328, 8065, 199, 533, 3207, 547, 334, 9985, 9123, 304, 1128, 408, 1128, 24997, 340, 376, 3207, 1256, 365, 2737, 543, 3866, 503, 1128, 27253, 2368, 14, 1128, 408, 2958, 347, 636, 826, 721, 277, 12, 1499, 12, 945, 304, 1039, 291, 14, 1328, 275, 1499, 1039, 291, 14, 1422, 63, 344, 275, 620, 8, 1422, 9, 2958, 347, 636, 495, 721, 277, 304, 1039, 340, 291, 14, 1422, 63, 344, 26, 1675, 372, 298, 1422, 450, 83, 26, 450, 83, 2, 450, 334, 277, 14, 1422, 63, 344, 12, 291, 14, 1328, 9, 1039, 587, 26, 1675, 372, 291, 14, 1328, 2999, 199, 533, 3207, 15919, 547, 334, 16546, 304, 1128, 408, 1128, 24997, 340, 28204, 1511, 787, 3483, 370, 376, 13491, 14, 1128, 408, 2999, 199, 533, 3207, 3393, 334, 9985, 9123, 304, 1128, 408, 1128, 24997, 340, 376, 3866, 945, 574, 365, 14556, 641, 314, 1414, 1128, 1004, 14, 1128, 408, 2999, 199, 533, 8857, 16546, 334, 9985, 9123, 304, 1128, 408, 1128, 24997, 340, 376, 3866, 945, 365, 6775, 641, 314, 1414, 1004, 14, 1128, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
vrenaville/OCB
openerp/workflow/instance.py
314
5594
# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2014 Tiny SPRL (<http://tiny.be>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## import workitem from openerp.workflow.helpers import Session from openerp.workflow.helpers import Record from openerp.workflow.workitem import WorkflowItem class WorkflowInstance(object): def __init__(self, session, record, values): assert isinstance(session, Session) assert isinstance(record, Record) self.session = session self.record = record if not values: values = {} assert isinstance(values, dict) self.instance = values @classmethod def create(cls, session, record, workflow_id): assert isinstance(session, Session) assert isinstance(record, Record) assert isinstance(workflow_id, (int, long)) cr = session.cr cr.execute('insert into wkf_instance (res_type,res_id,uid,wkf_id,state) values (%s,%s,%s,%s,%s) RETURNING id', (record.model, record.id, session.uid, workflow_id, 'active')) instance_id = cr.fetchone()[0] cr.execute('select * from wkf_activity where flow_start=True and wkf_id=%s', (workflow_id,)) stack = [] activities = cr.dictfetchall() for activity in activities: WorkflowItem.create(session, record, activity, instance_id, stack) cr.execute('SELECT * FROM wkf_instance WHERE id = %s', (instance_id,)) values = cr.dictfetchone() wi = WorkflowInstance(session, record, values) wi.update() return wi def delete(self): self.session.cr.execute('delete from wkf_instance where res_id=%s and res_type=%s', (self.record.id, self.record.model)) def validate(self, signal, force_running=False): assert isinstance(signal, basestring) assert isinstance(force_running, bool) cr = self.session.cr cr.execute("select * from wkf_workitem where inst_id=%s", (self.instance['id'],)) stack = [] for work_item_values in cr.dictfetchall(): wi = WorkflowItem(self.session, self.record, work_item_values) wi.process(signal=signal, force_running=force_running, stack=stack) # An action is returned self._update_end() return stack and stack[0] or False def update(self): cr = self.session.cr cr.execute("select * from wkf_workitem where inst_id=%s", (self.instance['id'],)) for work_item_values in cr.dictfetchall(): stack = [] WorkflowItem(self.session, self.record, work_item_values).process(stack=stack) return self._update_end() def _update_end(self): cr = self.session.cr instance_id = self.instance['id'] cr.execute('select wkf_id from wkf_instance where id=%s', (instance_id,)) wkf_id = cr.fetchone()[0] cr.execute('select state,flow_stop from wkf_workitem w left join wkf_activity a on (a.id=w.act_id) where w.inst_id=%s', (instance_id,)) ok=True for r in cr.fetchall(): if (r[0]<>'complete') or not r[1]: ok=False break if ok: cr.execute('select distinct a.name from wkf_activity a left join wkf_workitem w on (a.id=w.act_id) where w.inst_id=%s', (instance_id,)) act_names = cr.fetchall() cr.execute("update wkf_instance set state='complete' where id=%s", (instance_id,)) cr.execute("update wkf_workitem set state='complete' where subflow_id=%s", (instance_id,)) cr.execute("select i.id,w.osv,i.res_id from wkf_instance i left join wkf w on (i.wkf_id=w.id) where i.id IN (select inst_id from wkf_workitem where subflow_id=%s)", (instance_id,)) for cur_instance_id, cur_model_name, cur_record_id in cr.fetchall(): cur_record = Record(cur_model_name, cur_record_id) for act_name in act_names: WorkflowInstance(self.session, cur_record, {'id':cur_instance_id}).validate('subflow.%s' % act_name[0]) return ok def create(session, record, workflow_id): return WorkflowInstance(session, record).create(workflow_id) def delete(session, record): return WorkflowInstance(session, record).delete() def validate(session, record, instance_id, signal, force_running=False): return WorkflowInstance(session, record).validate(instance_id, signal, force_running) def update(session, record, instance_id): return WorkflowInstance(session, record).update(instance_id) def _update_end(session, record, instance_id): return WorkflowInstance(session, record)._update_end(instance_id) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 7280, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 646, 1736, 1053, 199, 504, 5166, 14, 8856, 14, 7546, 492, 8596, 199, 504, 5166, 14, 8856, 14, 7546, 492, 12651, 199, 504, 5166, 14, 8856, 14, 800, 1053, 492, 27282, 2081, 199, 199, 533, 27282, 3244, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 2351, 12, 2777, 12, 1338, 304, 267, 702, 1228, 8, 1730, 12, 8596, 9, 267, 702, 1228, 8, 3059, 12, 12651, 9, 267, 291, 14, 1730, 275, 2351, 267, 291, 14, 3059, 275, 2777, 398, 340, 440, 1338, 26, 288, 1338, 275, 1052, 398, 702, 1228, 8, 1459, 12, 1211, 9, 267, 291, 14, 842, 275, 1338, 339, 768, 3744, 272, 347, 1218, 8, 1886, 12, 2351, 12, 2777, 12, 10431, 63, 344, 304, 267, 702, 1228, 8, 1730, 12, 8596, 9, 267, 702, 1228, 8, 3059, 12, 12651, 9, 267, 702, 1228, 8, 8856, 63, 344, 12, 334, 442, 12, 1846, 430, 398, 2467, 275, 2351, 14, 1556, 267, 2467, 14, 2526, 360, 3176, 1901, 32727, 63, 842, 334, 470, 63, 466, 12, 470, 63, 344, 12, 1535, 12, 14947, 70, 63, 344, 12, 929, 9, 1338, 4366, 83, 8719, 83, 8719, 83, 8719, 83, 8719, 83, 9, 17409, 1230, 6024, 1305, 297, 334, 3059, 14, 1238, 12, 2777, 14, 344, 12, 2351, 14, 1535, 12, 10431, 63, 344, 12, 283, 2682, 1333, 267, 1256, 63, 344, 275, 2467, 14, 11591, 3430, 16, 61, 398, 2467, 14, 2526, 360, 2416, 627, 687, 32727, 63, 8240, 2382, 6369, 63, 928, 29, 549, 436, 32727, 63, 344, 2458, 83, 297, 334, 8856, 63, 344, 4641, 267, 3464, 275, 942, 398, 30744, 275, 2467, 14, 807, 10174, 342, 267, 367, 10679, 315, 30744, 26, 288, 27282, 2081, 14, 981, 8, 1730, 12, 2777, 12, 10679, 12, 1256, 63, 344, 12, 3464, 9, 398, 2467, 14, 2526, 360, 4859, 627, 4442, 32727, 63, 842, 6038, 1305, 275, 450, 83, 297, 334, 842, 63, 344, 4641, 267, 1338, 275, 2467, 14, 807, 11591, 342, 267, 26038, 275, 27282, 3244, 8, 1730, 12, 2777, 12, 1338, 9, 267, 26038, 14, 873, 342, 398, 372, 26038, 339, 347, 3145, 8, 277, 304, 267, 291, 14, 1730, 14, 1556, 14, 2526, 360, 1807, 687, 32727, 63, 842, 2382, 522, 63, 344, 2458, 83, 436, 522, 63, 466, 2458, 83, 297, 334, 277, 14, 3059, 14, 344, 12, 291, 14, 3059, 14, 1238, 430, 339, 347, 4107, 8, 277, 12, 4673, 12, 3542, 63, 5720, 29, 797, 304, 267, 702, 1228, 8, 4653, 12, 7116, 9, 267, 702, 1228, 8, 3990, 63, 5720, 12, 2155, 9, 398, 2467, 275, 291, 14, 1730, 14, 1556, 267, 2467, 14, 2526, 480, 2416, 627, 687, 32727, 63, 800, 1053, 2382, 2727, 63, 344, 2458, 83, 401, 334, 277, 14, 842, 459, 344, 995, 430, 267, 3464, 275, 942, 267, 367, 1736, 63, 1053, 63, 1459, 315, 2467, 14, 807, 10174, 837, 288, 26038, 275, 27282, 2081, 8, 277, 14, 1730, 12, 291, 14, 3059, 12, 1736, 63, 1053, 63, 1459, 9, 288, 26038, 14, 1412, 8, 4653, 29, 4653, 12, 3542, 63, 5720, 29, 3990, 63, 5720, 12, 3464, 29, 2340, 9, 288, 327, 1626, 1595, 365, 2138, 267, 291, 423, 873, 63, 500, 342, 267, 372, 3464, 436, 3464, 59, 16, 61, 503, 756, 339, 347, 1678, 8, 277, 304, 267, 2467, 275, 291, 14, 1730, 14, 1556, 398, 2467, 14, 2526, 480, 2416, 627, 687, 32727, 63, 800, 1053, 2382, 2727, 63, 344, 2458, 83, 401, 334, 277, 14, 842, 459, 344, 995, 430, 267, 367, 1736, 63, 1053, 63, 1459, 315, 2467, 14, 807, 10174, 837, 288, 3464, 275, 942, 288, 27282, 2081, 8, 277, 14, 1730, 12, 291, 14, 3059, 12, 1736, 63, 1053, 63, 1459, 680, 1412, 8, 2340, 29, 2340, 9, 267, 372, 291, 423, 873, 63, 500, 342, 339, 347, 485, 873, 63, 500, 8, 277, 304, 267, 2467, 275, 291, 14, 1730, 14, 1556, 267, 1256, 63, 344, 275, 291, 14, 842, 459, 344, 418, 267, 2467, 14, 2526, 360, 2416, 32727, 63, 344, 687, 32727, 63, 842, 2382, 1305, 2458, 83, 297, 334, 842, 63, 344, 4641, 267, 32727, 63, 344, 275, 2467, 14, 11591, 3430, 16, 61, 267, 2467, 14, 2526, 360, 2416, 1174, 12, 1659, 63, 2379, 687, 32727, 63, 800, 1053, 336, 3602, 4263, 32727, 63, 8240, 282, 641, 334, 65, 14, 344, 29, 87, 14, 2442, 63, 344, 9, 2382, 336, 14, 3615, 63, 344, 2458, 83, 297, 334, 842, 63, 344, 4641, 267, 4112, 29, 549, 267, 367, 519, 315, 2467, 14, 10174, 837, 288, 340, 334, 82, 59, 16, 61, 28, 3524, 4883, 358, 503, 440, 519, 59, 17, 2189, 355, 4112, 29, 797, 355, 2059, 267, 340, 4112, 26, 288, 2467, 14, 2526, 360, 2416, 15392, 282, 14, 354, 687, 32727, 63, 8240, 282, 3602, 4263, 32727, 63, 800, 1053, 336, 641, 334, 65, 14, 344, 29, 87, 14, 2442, 63, 344, 9 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 7280, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 646, 1736, 1053, 199, 504, 5166, 14, 8856, 14, 7546, 492, 8596, 199, 504, 5166, 14, 8856, 14, 7546, 492, 12651, 199, 504, 5166, 14, 8856, 14, 800, 1053, 492, 27282, 2081, 199, 199, 533, 27282, 3244, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 2351, 12, 2777, 12, 1338, 304, 267, 702, 1228, 8, 1730, 12, 8596, 9, 267, 702, 1228, 8, 3059, 12, 12651, 9, 267, 291, 14, 1730, 275, 2351, 267, 291, 14, 3059, 275, 2777, 398, 340, 440, 1338, 26, 288, 1338, 275, 1052, 398, 702, 1228, 8, 1459, 12, 1211, 9, 267, 291, 14, 842, 275, 1338, 339, 768, 3744, 272, 347, 1218, 8, 1886, 12, 2351, 12, 2777, 12, 10431, 63, 344, 304, 267, 702, 1228, 8, 1730, 12, 8596, 9, 267, 702, 1228, 8, 3059, 12, 12651, 9, 267, 702, 1228, 8, 8856, 63, 344, 12, 334, 442, 12, 1846, 430, 398, 2467, 275, 2351, 14, 1556, 267, 2467, 14, 2526, 360, 3176, 1901, 32727, 63, 842, 334, 470, 63, 466, 12, 470, 63, 344, 12, 1535, 12, 14947, 70, 63, 344, 12, 929, 9, 1338, 4366, 83, 8719, 83, 8719, 83, 8719, 83, 8719, 83, 9, 17409, 1230, 6024, 1305, 297, 334, 3059, 14, 1238, 12, 2777, 14, 344, 12, 2351, 14, 1535, 12, 10431, 63, 344, 12, 283, 2682, 1333, 267, 1256, 63, 344, 275, 2467, 14, 11591, 3430, 16, 61, 398, 2467, 14, 2526, 360, 2416, 627, 687, 32727, 63, 8240, 2382, 6369, 63, 928, 29, 549, 436, 32727, 63, 344, 2458, 83, 297, 334, 8856, 63, 344, 4641, 267, 3464, 275, 942, 398, 30744, 275, 2467, 14, 807, 10174, 342, 267, 367, 10679, 315, 30744, 26, 288, 27282, 2081, 14, 981, 8, 1730, 12, 2777, 12, 10679, 12, 1256, 63, 344, 12, 3464, 9, 398, 2467, 14, 2526, 360, 4859, 627, 4442, 32727, 63, 842, 6038, 1305, 275, 450, 83, 297, 334, 842, 63, 344, 4641, 267, 1338, 275, 2467, 14, 807, 11591, 342, 267, 26038, 275, 27282, 3244, 8, 1730, 12, 2777, 12, 1338, 9, 267, 26038, 14, 873, 342, 398, 372, 26038, 339, 347, 3145, 8, 277, 304, 267, 291, 14, 1730, 14, 1556, 14, 2526, 360, 1807, 687, 32727, 63, 842, 2382, 522, 63, 344, 2458, 83, 436, 522, 63, 466, 2458, 83, 297, 334, 277, 14, 3059, 14, 344, 12, 291, 14, 3059, 14, 1238, 430, 339, 347, 4107, 8, 277, 12, 4673, 12, 3542, 63, 5720, 29, 797, 304, 267, 702, 1228, 8, 4653, 12, 7116, 9, 267, 702, 1228, 8, 3990, 63, 5720, 12, 2155, 9, 398, 2467, 275, 291, 14, 1730, 14, 1556, 267, 2467, 14, 2526, 480, 2416, 627, 687, 32727, 63, 800, 1053, 2382, 2727, 63, 344, 2458, 83, 401, 334, 277, 14, 842, 459, 344, 995, 430, 267, 3464, 275, 942, 267, 367, 1736, 63, 1053, 63, 1459, 315, 2467, 14, 807, 10174, 837, 288, 26038, 275, 27282, 2081, 8, 277, 14, 1730, 12, 291, 14, 3059, 12, 1736, 63, 1053, 63, 1459, 9, 288, 26038, 14, 1412, 8, 4653, 29, 4653, 12, 3542, 63, 5720, 29, 3990, 63, 5720, 12, 3464, 29, 2340, 9, 288, 327, 1626, 1595, 365, 2138, 267, 291, 423, 873, 63, 500, 342, 267, 372, 3464, 436, 3464, 59, 16, 61, 503, 756, 339, 347, 1678, 8, 277, 304, 267, 2467, 275, 291, 14, 1730, 14, 1556, 398, 2467, 14, 2526, 480, 2416, 627, 687, 32727, 63, 800, 1053, 2382, 2727, 63, 344, 2458, 83, 401, 334, 277, 14, 842, 459, 344, 995, 430, 267, 367, 1736, 63, 1053, 63, 1459, 315, 2467, 14, 807, 10174, 837, 288, 3464, 275, 942, 288, 27282, 2081, 8, 277, 14, 1730, 12, 291, 14, 3059, 12, 1736, 63, 1053, 63, 1459, 680, 1412, 8, 2340, 29, 2340, 9, 267, 372, 291, 423, 873, 63, 500, 342, 339, 347, 485, 873, 63, 500, 8, 277, 304, 267, 2467, 275, 291, 14, 1730, 14, 1556, 267, 1256, 63, 344, 275, 291, 14, 842, 459, 344, 418, 267, 2467, 14, 2526, 360, 2416, 32727, 63, 344, 687, 32727, 63, 842, 2382, 1305, 2458, 83, 297, 334, 842, 63, 344, 4641, 267, 32727, 63, 344, 275, 2467, 14, 11591, 3430, 16, 61, 267, 2467, 14, 2526, 360, 2416, 1174, 12, 1659, 63, 2379, 687, 32727, 63, 800, 1053, 336, 3602, 4263, 32727, 63, 8240, 282, 641, 334, 65, 14, 344, 29, 87, 14, 2442, 63, 344, 9, 2382, 336, 14, 3615, 63, 344, 2458, 83, 297, 334, 842, 63, 344, 4641, 267, 4112, 29, 549, 267, 367, 519, 315, 2467, 14, 10174, 837, 288, 340, 334, 82, 59, 16, 61, 28, 3524, 4883, 358, 503, 440, 519, 59, 17, 2189, 355, 4112, 29, 797, 355, 2059, 267, 340, 4112, 26, 288, 2467, 14, 2526, 360, 2416, 15392, 282, 14, 354, 687, 32727, 63, 8240, 282, 3602, 4263, 32727, 63, 800, 1053, 336, 641, 334, 65, 14, 344, 29, 87, 14, 2442, 63, 344, 9, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
zhjunlang/kbengine
kbe/res/scripts/common/Lib/test/test_index.py
98
8567
import unittest from test import support import operator maxsize = support.MAX_Py_ssize_t class newstyle: def __index__(self): return self.ind class TrapInt(int): def __index__(self): return int(self) class BaseTestCase(unittest.TestCase): def setUp(self): self.o = newstyle() self.n = newstyle() def test_basic(self): self.o.ind = -2 self.n.ind = 2 self.assertEqual(operator.index(self.o), -2) self.assertEqual(operator.index(self.n), 2) def test_slice(self): self.o.ind = 1 self.n.ind = 2 slc = slice(self.o, self.o, self.o) check_slc = slice(1, 1, 1) self.assertEqual(slc.indices(self.o), check_slc.indices(1)) slc = slice(self.n, self.n, self.n) check_slc = slice(2, 2, 2) self.assertEqual(slc.indices(self.n), check_slc.indices(2)) def test_wrappers(self): self.o.ind = 4 self.n.ind = 5 self.assertEqual(6 .__index__(), 6) self.assertEqual(-7 .__index__(), -7) self.assertEqual(self.o.__index__(), 4) self.assertEqual(self.n.__index__(), 5) self.assertEqual(True.__index__(), 1) self.assertEqual(False.__index__(), 0) def test_subclasses(self): r = list(range(10)) self.assertEqual(r[TrapInt(5):TrapInt(10)], r[5:10]) self.assertEqual(slice(TrapInt()).indices(0), (0,0,1)) def test_error(self): self.o.ind = 'dumb' self.n.ind = 'bad' self.assertRaises(TypeError, operator.index, self.o) self.assertRaises(TypeError, operator.index, self.n) self.assertRaises(TypeError, slice(self.o).indices, 0) self.assertRaises(TypeError, slice(self.n).indices, 0) def test_int_subclass_with_index(self): # __index__ should be used when computing indices, even for int # subclasses. See issue #17576. class MyInt(int): def __index__(self): return int(self) + 1 my_int = MyInt(7) direct_index = my_int.__index__() operator_index = operator.index(my_int) self.assertEqual(direct_index, 8) self.assertEqual(operator_index, 7) # Both results should be of exact type int. self.assertIs(type(direct_index), int) #self.assertIs(type(operator_index), int) def test_index_returns_int_subclass(self): class BadInt: def __index__(self): return True class BadInt2(int): def __index__(self): return True bad_int = BadInt() with self.assertWarns(DeprecationWarning): n = operator.index(bad_int) self.assertEqual(n, 1) bad_int = BadInt2() n = operator.index(bad_int) self.assertEqual(n, 0) class SeqTestCase: # This test case isn't run directly. It just defines common tests # to the different sequence types below def setUp(self): self.o = newstyle() self.n = newstyle() self.o2 = newstyle() self.n2 = newstyle() def test_index(self): self.o.ind = -2 self.n.ind = 2 self.assertEqual(self.seq[self.n], self.seq[2]) self.assertEqual(self.seq[self.o], self.seq[-2]) def test_slice(self): self.o.ind = 1 self.o2.ind = 3 self.n.ind = 2 self.n2.ind = 4 self.assertEqual(self.seq[self.o:self.o2], self.seq[1:3]) self.assertEqual(self.seq[self.n:self.n2], self.seq[2:4]) def test_slice_bug7532(self): seqlen = len(self.seq) self.o.ind = int(seqlen * 1.5) self.n.ind = seqlen + 2 self.assertEqual(self.seq[self.o:], self.seq[0:0]) self.assertEqual(self.seq[:self.o], self.seq) self.assertEqual(self.seq[self.n:], self.seq[0:0]) self.assertEqual(self.seq[:self.n], self.seq) self.o2.ind = -seqlen - 2 self.n2.ind = -int(seqlen * 1.5) self.assertEqual(self.seq[self.o2:], self.seq) self.assertEqual(self.seq[:self.o2], self.seq[0:0]) self.assertEqual(self.seq[self.n2:], self.seq) self.assertEqual(self.seq[:self.n2], self.seq[0:0]) def test_repeat(self): self.o.ind = 3 self.n.ind = 2 self.assertEqual(self.seq * self.o, self.seq * 3) self.assertEqual(self.seq * self.n, self.seq * 2) self.assertEqual(self.o * self.seq, self.seq * 3) self.assertEqual(self.n * self.seq, self.seq * 2) def test_wrappers(self): self.o.ind = 4 self.n.ind = 5 self.assertEqual(self.seq.__getitem__(self.o), self.seq[4]) self.assertEqual(self.seq.__mul__(self.o), self.seq * 4) self.assertEqual(self.seq.__rmul__(self.o), self.seq * 4) self.assertEqual(self.seq.__getitem__(self.n), self.seq[5]) self.assertEqual(self.seq.__mul__(self.n), self.seq * 5) self.assertEqual(self.seq.__rmul__(self.n), self.seq * 5) def test_subclasses(self): self.assertEqual(self.seq[TrapInt()], self.seq[0]) def test_error(self): self.o.ind = 'dumb' self.n.ind = 'bad' indexobj = lambda x, obj: obj.seq[x] self.assertRaises(TypeError, indexobj, self.o, self) self.assertRaises(TypeError, indexobj, self.n, self) sliceobj = lambda x, obj: obj.seq[x:] self.assertRaises(TypeError, sliceobj, self.o, self) self.assertRaises(TypeError, sliceobj, self.n, self) class ListTestCase(SeqTestCase, unittest.TestCase): seq = [0,10,20,30,40,50] def test_setdelitem(self): self.o.ind = -2 self.n.ind = 2 lst = list('ab!cdefghi!j') del lst[self.o] del lst[self.n] lst[self.o] = 'X' lst[self.n] = 'Y' self.assertEqual(lst, list('abYdefghXj')) lst = [5, 6, 7, 8, 9, 10, 11] lst.__setitem__(self.n, "here") self.assertEqual(lst, [5, 6, "here", 8, 9, 10, 11]) lst.__delitem__(self.n) self.assertEqual(lst, [5, 6, 8, 9, 10, 11]) def test_inplace_repeat(self): self.o.ind = 2 self.n.ind = 3 lst = [6, 4] lst *= self.o self.assertEqual(lst, [6, 4, 6, 4]) lst *= self.n self.assertEqual(lst, [6, 4, 6, 4] * 3) lst = [5, 6, 7, 8, 9, 11] l2 = lst.__imul__(self.n) self.assertIs(l2, lst) self.assertEqual(lst, [5, 6, 7, 8, 9, 11] * 3) class NewSeq: def __init__(self, iterable): self._list = list(iterable) def __repr__(self): return repr(self._list) def __eq__(self, other): return self._list == other def __len__(self): return len(self._list) def __mul__(self, n): return self.__class__(self._list*n) __rmul__ = __mul__ def __getitem__(self, index): return self._list[index] class TupleTestCase(SeqTestCase, unittest.TestCase): seq = (0,10,20,30,40,50) class ByteArrayTestCase(SeqTestCase, unittest.TestCase): seq = bytearray(b"this is a test") class BytesTestCase(SeqTestCase, unittest.TestCase): seq = b"this is a test" class StringTestCase(SeqTestCase, unittest.TestCase): seq = "this is a test" class NewSeqTestCase(SeqTestCase, unittest.TestCase): seq = NewSeq((0,10,20,30,40,50)) class RangeTestCase(unittest.TestCase): def test_range(self): n = newstyle() n.ind = 5 self.assertEqual(range(1, 20)[n], 6) self.assertEqual(range(1, 20).__getitem__(n), 6) class OverflowTestCase(unittest.TestCase): def setUp(self): self.pos = 2**100 self.neg = -self.pos def test_large_longs(self): self.assertEqual(self.pos.__index__(), self.pos) self.assertEqual(self.neg.__index__(), self.neg) def test_getitem(self): class GetItem: def __len__(self): assert False, "__len__ should not be invoked" def __getitem__(self, key): return key x = GetItem() self.assertEqual(x[self.pos], self.pos) self.assertEqual(x[self.neg], self.neg) self.assertEqual(x[self.neg:self.pos].indices(maxsize), (0, maxsize, 1)) self.assertEqual(x[self.neg:self.pos:1].indices(maxsize), (0, maxsize, 1)) def test_sequence_repeat(self): self.assertRaises(OverflowError, lambda: "a" * self.pos) self.assertRaises(OverflowError, lambda: "a" * self.neg) if __name__ == "__main__": unittest.main()
lgpl-3.0
[ 646, 2882, 199, 504, 511, 492, 2291, 199, 646, 4182, 199, 13634, 275, 2291, 14, 4283, 63, 2713, 63, 30104, 63, 84, 199, 199, 533, 892, 2487, 26, 272, 347, 636, 1080, 721, 277, 304, 267, 372, 291, 14, 688, 199, 199, 533, 377, 1330, 3241, 8, 442, 304, 272, 347, 636, 1080, 721, 277, 304, 267, 372, 1109, 8, 277, 9, 199, 199, 533, 3523, 1746, 8, 2796, 14, 1746, 304, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 79, 275, 892, 2487, 342, 267, 291, 14, 78, 275, 892, 2487, 342, 339, 347, 511, 63, 4316, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 446, 18, 267, 291, 14, 78, 14, 688, 275, 499, 267, 291, 14, 629, 8, 3856, 14, 1080, 8, 277, 14, 79, 395, 446, 18, 9, 267, 291, 14, 629, 8, 3856, 14, 1080, 8, 277, 14, 78, 395, 499, 9, 339, 347, 511, 63, 5224, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 413, 267, 291, 14, 78, 14, 688, 275, 499, 267, 5340, 67, 275, 6014, 8, 277, 14, 79, 12, 291, 14, 79, 12, 291, 14, 79, 9, 267, 1104, 63, 2482, 67, 275, 6014, 8, 17, 12, 413, 12, 413, 9, 267, 291, 14, 629, 8, 2482, 67, 14, 4108, 8, 277, 14, 79, 395, 1104, 63, 2482, 67, 14, 4108, 8, 17, 430, 267, 5340, 67, 275, 6014, 8, 277, 14, 78, 12, 291, 14, 78, 12, 291, 14, 78, 9, 267, 1104, 63, 2482, 67, 275, 6014, 8, 18, 12, 499, 12, 499, 9, 267, 291, 14, 629, 8, 2482, 67, 14, 4108, 8, 277, 14, 78, 395, 1104, 63, 2482, 67, 14, 4108, 8, 18, 430, 339, 347, 511, 63, 21148, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 841, 267, 291, 14, 78, 14, 688, 275, 959, 267, 291, 14, 629, 8, 22, 221, 855, 1080, 29709, 1227, 9, 267, 291, 14, 629, 2801, 23, 221, 855, 1080, 29709, 446, 23, 9, 267, 291, 14, 629, 8, 277, 14, 79, 855, 1080, 29709, 841, 9, 267, 291, 14, 629, 8, 277, 14, 78, 855, 1080, 29709, 959, 9, 267, 291, 14, 629, 8, 549, 855, 1080, 29709, 413, 9, 267, 291, 14, 629, 8, 797, 855, 1080, 29709, 378, 9, 339, 347, 511, 63, 19094, 8, 277, 304, 267, 519, 275, 769, 8, 1842, 8, 709, 430, 267, 291, 14, 629, 8, 82, 59, 52, 1330, 3241, 8, 21, 304, 52, 1330, 3241, 8, 709, 4360, 519, 59, 21, 26, 709, 566, 267, 291, 14, 629, 8, 5224, 8, 52, 1330, 3241, 8801, 4108, 8, 16, 395, 334, 16, 12, 16, 12, 17, 430, 339, 347, 511, 63, 705, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 283, 29271, 7, 267, 291, 14, 78, 14, 688, 275, 283, 4087, 7, 267, 291, 14, 1855, 8, 4333, 12, 4182, 14, 1080, 12, 291, 14, 79, 9, 267, 291, 14, 1855, 8, 4333, 12, 4182, 14, 1080, 12, 291, 14, 78, 9, 267, 291, 14, 1855, 8, 4333, 12, 6014, 8, 277, 14, 79, 680, 4108, 12, 378, 9, 267, 291, 14, 1855, 8, 4333, 12, 6014, 8, 277, 14, 78, 680, 4108, 12, 378, 9, 339, 347, 511, 63, 442, 63, 6083, 63, 1045, 63, 1080, 8, 277, 304, 267, 327, 636, 1080, 363, 1077, 506, 1202, 1380, 17226, 4918, 12, 2755, 367, 1109, 267, 327, 9180, 14, 221, 1666, 4976, 327, 1196, 12255, 14, 267, 1021, 4932, 3241, 8, 442, 304, 288, 347, 636, 1080, 721, 277, 304, 355, 372, 1109, 8, 277, 9, 435, 413, 398, 3002, 63, 442, 275, 4932, 3241, 8, 23, 9, 267, 4125, 63, 1080, 275, 3002, 63, 442, 855, 1080, 4533, 267, 4182, 63, 1080, 275, 4182, 14, 1080, 8, 1662, 63, 442, 9, 267, 291, 14, 629, 8, 2275, 63, 1080, 12, 1695, 9, 267, 291, 14, 629, 8, 3856, 63, 1080, 12, 1520, 9, 267, 327, 17650, 2058, 1077, 506, 402, 5835, 730, 1109, 14, 267, 291, 14, 3436, 8, 466, 8, 2275, 63, 1080, 395, 1109, 9, 267, 327, 277, 14, 3436, 8, 466, 8, 3856, 63, 1080, 395, 1109, 9, 339, 347, 511, 63, 1080, 63, 5808, 63, 442, 63, 6083, 8, 277, 304, 267, 1021, 8857, 3241, 26, 288, 347, 636, 1080, 721, 277, 304, 355, 372, 715, 398, 1021, 8857, 3241, 18, 8, 442, 304, 288, 347, 636, 1080, 721, 277, 304, 355, 372, 715, 398, 4875, 63, 442, 275, 8857, 3241, 342, 267, 543, 291, 14, 479, 29917, 8, 15561, 304, 288, 302, 275, 4182, 14, 1080, 8, 4087, 63, 442, 9, 267, 291, 14, 629, 8, 78, 12, 413, 9, 398, 4875, 63, 442, 275, 8857, 3241, 18, 342, 267, 302, 275, 4182, 14, 1080, 8, 4087, 63, 442, 9, 267, 291, 14, 629, 8, 78, 12, 378, 9, 421, 199, 533, 28534, 1746, 26, 272, 327, 961, 511, 1930, 5712, 1133, 1255, 5370, 14, 2779, 2951, 7890, 2863, 2295, 272, 327, 370, 314, 3365, 3414, 2943, 5084, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 79, 275, 892, 2487, 342, 267, 291, 14, 78, 275, 892, 2487, 342, 267, 291, 14, 79, 18, 275, 892, 2487, 342, 267, 291, 14, 78, 18, 275, 892, 2487, 342, 339, 347, 511, 63, 1080, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 446, 18, 267, 291, 14, 78, 14, 688, 275, 499, 267, 291, 14, 629, 8, 277, 14, 3610, 59, 277, 14, 78, 467, 291, 14, 3610, 59, 18, 566, 267, 291, 14, 629, 8, 277, 14, 3610, 59, 277, 14, 79, 467, 291, 14, 3610, 1988, 18, 566, 339, 347, 511, 63, 5224, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 413, 267, 291, 14, 79, 18, 14, 688, 275, 650, 267, 291, 14, 78, 14, 688, 275, 499, 267, 291, 14, 78, 18, 14, 688, 275, 841, 267, 291, 14, 629, 8, 277, 14, 3610, 59, 277, 14, 79, 26, 277, 14, 79, 18, 467, 291, 14, 3610, 59, 17, 26, 19, 566, 267, 291, 14, 629, 8, 277, 14, 3610, 59, 277, 14, 78, 26, 277, 14, 78, 18, 467 ]
[ 2882, 199, 504, 511, 492, 2291, 199, 646, 4182, 199, 13634, 275, 2291, 14, 4283, 63, 2713, 63, 30104, 63, 84, 199, 199, 533, 892, 2487, 26, 272, 347, 636, 1080, 721, 277, 304, 267, 372, 291, 14, 688, 199, 199, 533, 377, 1330, 3241, 8, 442, 304, 272, 347, 636, 1080, 721, 277, 304, 267, 372, 1109, 8, 277, 9, 199, 199, 533, 3523, 1746, 8, 2796, 14, 1746, 304, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 79, 275, 892, 2487, 342, 267, 291, 14, 78, 275, 892, 2487, 342, 339, 347, 511, 63, 4316, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 446, 18, 267, 291, 14, 78, 14, 688, 275, 499, 267, 291, 14, 629, 8, 3856, 14, 1080, 8, 277, 14, 79, 395, 446, 18, 9, 267, 291, 14, 629, 8, 3856, 14, 1080, 8, 277, 14, 78, 395, 499, 9, 339, 347, 511, 63, 5224, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 413, 267, 291, 14, 78, 14, 688, 275, 499, 267, 5340, 67, 275, 6014, 8, 277, 14, 79, 12, 291, 14, 79, 12, 291, 14, 79, 9, 267, 1104, 63, 2482, 67, 275, 6014, 8, 17, 12, 413, 12, 413, 9, 267, 291, 14, 629, 8, 2482, 67, 14, 4108, 8, 277, 14, 79, 395, 1104, 63, 2482, 67, 14, 4108, 8, 17, 430, 267, 5340, 67, 275, 6014, 8, 277, 14, 78, 12, 291, 14, 78, 12, 291, 14, 78, 9, 267, 1104, 63, 2482, 67, 275, 6014, 8, 18, 12, 499, 12, 499, 9, 267, 291, 14, 629, 8, 2482, 67, 14, 4108, 8, 277, 14, 78, 395, 1104, 63, 2482, 67, 14, 4108, 8, 18, 430, 339, 347, 511, 63, 21148, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 841, 267, 291, 14, 78, 14, 688, 275, 959, 267, 291, 14, 629, 8, 22, 221, 855, 1080, 29709, 1227, 9, 267, 291, 14, 629, 2801, 23, 221, 855, 1080, 29709, 446, 23, 9, 267, 291, 14, 629, 8, 277, 14, 79, 855, 1080, 29709, 841, 9, 267, 291, 14, 629, 8, 277, 14, 78, 855, 1080, 29709, 959, 9, 267, 291, 14, 629, 8, 549, 855, 1080, 29709, 413, 9, 267, 291, 14, 629, 8, 797, 855, 1080, 29709, 378, 9, 339, 347, 511, 63, 19094, 8, 277, 304, 267, 519, 275, 769, 8, 1842, 8, 709, 430, 267, 291, 14, 629, 8, 82, 59, 52, 1330, 3241, 8, 21, 304, 52, 1330, 3241, 8, 709, 4360, 519, 59, 21, 26, 709, 566, 267, 291, 14, 629, 8, 5224, 8, 52, 1330, 3241, 8801, 4108, 8, 16, 395, 334, 16, 12, 16, 12, 17, 430, 339, 347, 511, 63, 705, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 283, 29271, 7, 267, 291, 14, 78, 14, 688, 275, 283, 4087, 7, 267, 291, 14, 1855, 8, 4333, 12, 4182, 14, 1080, 12, 291, 14, 79, 9, 267, 291, 14, 1855, 8, 4333, 12, 4182, 14, 1080, 12, 291, 14, 78, 9, 267, 291, 14, 1855, 8, 4333, 12, 6014, 8, 277, 14, 79, 680, 4108, 12, 378, 9, 267, 291, 14, 1855, 8, 4333, 12, 6014, 8, 277, 14, 78, 680, 4108, 12, 378, 9, 339, 347, 511, 63, 442, 63, 6083, 63, 1045, 63, 1080, 8, 277, 304, 267, 327, 636, 1080, 363, 1077, 506, 1202, 1380, 17226, 4918, 12, 2755, 367, 1109, 267, 327, 9180, 14, 221, 1666, 4976, 327, 1196, 12255, 14, 267, 1021, 4932, 3241, 8, 442, 304, 288, 347, 636, 1080, 721, 277, 304, 355, 372, 1109, 8, 277, 9, 435, 413, 398, 3002, 63, 442, 275, 4932, 3241, 8, 23, 9, 267, 4125, 63, 1080, 275, 3002, 63, 442, 855, 1080, 4533, 267, 4182, 63, 1080, 275, 4182, 14, 1080, 8, 1662, 63, 442, 9, 267, 291, 14, 629, 8, 2275, 63, 1080, 12, 1695, 9, 267, 291, 14, 629, 8, 3856, 63, 1080, 12, 1520, 9, 267, 327, 17650, 2058, 1077, 506, 402, 5835, 730, 1109, 14, 267, 291, 14, 3436, 8, 466, 8, 2275, 63, 1080, 395, 1109, 9, 267, 327, 277, 14, 3436, 8, 466, 8, 3856, 63, 1080, 395, 1109, 9, 339, 347, 511, 63, 1080, 63, 5808, 63, 442, 63, 6083, 8, 277, 304, 267, 1021, 8857, 3241, 26, 288, 347, 636, 1080, 721, 277, 304, 355, 372, 715, 398, 1021, 8857, 3241, 18, 8, 442, 304, 288, 347, 636, 1080, 721, 277, 304, 355, 372, 715, 398, 4875, 63, 442, 275, 8857, 3241, 342, 267, 543, 291, 14, 479, 29917, 8, 15561, 304, 288, 302, 275, 4182, 14, 1080, 8, 4087, 63, 442, 9, 267, 291, 14, 629, 8, 78, 12, 413, 9, 398, 4875, 63, 442, 275, 8857, 3241, 18, 342, 267, 302, 275, 4182, 14, 1080, 8, 4087, 63, 442, 9, 267, 291, 14, 629, 8, 78, 12, 378, 9, 421, 199, 533, 28534, 1746, 26, 272, 327, 961, 511, 1930, 5712, 1133, 1255, 5370, 14, 2779, 2951, 7890, 2863, 2295, 272, 327, 370, 314, 3365, 3414, 2943, 5084, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 79, 275, 892, 2487, 342, 267, 291, 14, 78, 275, 892, 2487, 342, 267, 291, 14, 79, 18, 275, 892, 2487, 342, 267, 291, 14, 78, 18, 275, 892, 2487, 342, 339, 347, 511, 63, 1080, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 446, 18, 267, 291, 14, 78, 14, 688, 275, 499, 267, 291, 14, 629, 8, 277, 14, 3610, 59, 277, 14, 78, 467, 291, 14, 3610, 59, 18, 566, 267, 291, 14, 629, 8, 277, 14, 3610, 59, 277, 14, 79, 467, 291, 14, 3610, 1988, 18, 566, 339, 347, 511, 63, 5224, 8, 277, 304, 267, 291, 14, 79, 14, 688, 275, 413, 267, 291, 14, 79, 18, 14, 688, 275, 650, 267, 291, 14, 78, 14, 688, 275, 499, 267, 291, 14, 78, 18, 14, 688, 275, 841, 267, 291, 14, 629, 8, 277, 14, 3610, 59, 277, 14, 79, 26, 277, 14, 79, 18, 467, 291, 14, 3610, 59, 17, 26, 19, 566, 267, 291, 14, 629, 8, 277, 14, 3610, 59, 277, 14, 78, 26, 277, 14, 78, 18, 467, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
JavierDelgadoFernandez/invenio-previewer
invenio_previewer/views.py
1
3942
# -*- coding: utf-8 -*- # # This file is part of Invenio. # Copyright (C) 2016 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # Invenio is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Invenio; if not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307, USA. # # In applying this license, CERN does not # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. """Invenio module for previewing files.""" from __future__ import absolute_import, print_function import mimetypes import os from flask import Blueprint, Response, current_app, request from invenio_documents import Document from invenio_records import Record blueprint = Blueprint( 'invenio_previewer', __name__, template_folder='templates', static_folder='static', ) class DocumentPreviewer(object): """Provides some extra information about documents.""" def __init__(self, record_id, document): """Class initialization.""" self.record_id = record_id self.path = os.path.dirname(document.uri) self.extension = document.uri[document.uri.rfind('.') + 1:] self.name = document.uri[ len(self.path) + 1: - len(self.extension) - 1] self.document = document def get_filename(self): """Calculate the file name.""" return '{0}.{1}'.format(self.name, self.extension) def get_document_previewer(record_id, filename): """Look for a record and return the file.""" record = Record.get_record(record_id) len_documents = len(Document(record, '/files/').record['files']) for i_document in range(len_documents): document = Document(record, '/files/{0}/uri'.format(i_document)) document_previewer = DocumentPreviewer(record_id, document) if not filename or document_previewer.get_filename() == filename: return document_previewer def get_previewers(): """Return available previewers ordered by PREVIEWER_PREVIEWERS_ORDER.""" result = [] previewers_available = { previewer.__name__: previewer for previewer in current_app.extensions['invenio-previewer'].previewers } for previewer in current_app.config.get('PREVIEWER_PREVIEWERS_ORDER'): if previewer in previewers_available: result.append(previewers_available[previewer]) return result @blueprint.route('/<recid>/preview', methods=['GET', 'POST']) def preview(recid): """Preview file for given record.""" document_previewer = get_document_previewer( recid, request.args.get('filename', type=str)) for plugin in get_previewers(): if plugin.can_preview(document_previewer): return plugin.preview(document_previewer) @blueprint.route('/document/<recid>/<filename>') def document(recid, filename): """Return a stream with the file specified in the record.""" document_previewer = get_document_previewer(recid, filename) def stream_file(uri): with open(uri, 'rb') as f: while True: chunk = f.read(1024) if chunk: yield chunk else: return stream = stream_file(document_previewer.document.uri) return Response(stream, mimetype=mimetypes.guess_type( document_previewer.document.uri)[0])
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 12235, 14, 199, 3, 1898, 334, 35, 9, 7800, 24354, 14, 199, 3, 199, 3, 12235, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 199, 3, 436, 15, 269, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 199, 3, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 12235, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 199, 3, 2997, 12, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 12235, 27, 340, 440, 12, 2218, 370, 314, 199, 3, 2868, 2290, 2752, 12, 3277, 2020, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 199, 3, 4828, 15673, 13, 13421, 12, 8217, 14, 199, 3, 199, 3, 1010, 18876, 642, 4190, 12, 24354, 1630, 440, 199, 3, 14442, 1912, 314, 20001, 436, 25531, 22047, 10009, 370, 652, 701, 12043, 310, 402, 2399, 2004, 199, 3, 465, 376, 6551, 71, 27639, 279, 18863, 503, 11482, 6337, 370, 1263, 1335, 17656, 26382, 14, 199, 199, 624, 607, 7597, 859, 367, 19653, 316, 1584, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 870, 63, 1593, 199, 199, 646, 13290, 199, 646, 747, 199, 199, 504, 7209, 492, 22447, 1361, 12, 7232, 12, 1453, 63, 571, 12, 1056, 199, 504, 13640, 63, 12233, 492, 7543, 199, 504, 13640, 63, 6502, 492, 12651, 199, 199, 15918, 275, 22447, 1361, 8, 272, 283, 30628, 63, 7780, 281, 297, 272, 636, 354, 3108, 272, 1978, 63, 3741, 534, 5876, 297, 272, 2955, 63, 3741, 534, 1986, 297, 199, 9, 421, 199, 533, 7543, 2398, 16645, 8, 785, 304, 272, 408, 17473, 2005, 2402, 2556, 3595, 8247, 1041, 339, 347, 636, 826, 721, 277, 12, 2777, 63, 344, 12, 2213, 304, 267, 408, 2543, 11097, 1041, 267, 291, 14, 3059, 63, 344, 275, 2777, 63, 344, 267, 291, 14, 515, 275, 747, 14, 515, 14, 3475, 8, 3554, 14, 2302, 9, 267, 291, 14, 3435, 275, 2213, 14, 2302, 59, 3554, 14, 2302, 14, 14542, 7563, 435, 413, 2938, 267, 291, 14, 354, 275, 2213, 14, 2302, 59, 2151, 822, 8, 277, 14, 515, 9, 435, 413, 26, 446, 822, 8, 277, 14, 3435, 9, 446, 413, 61, 267, 291, 14, 3554, 275, 2213, 339, 347, 664, 63, 1501, 8, 277, 304, 267, 408, 14860, 314, 570, 536, 1041, 267, 372, 5041, 16, 26944, 17, 5285, 908, 8, 277, 14, 354, 12, 291, 14, 3435, 9, 421, 199, 318, 664, 63, 3554, 63, 7780, 281, 8, 3059, 63, 344, 12, 1788, 304, 272, 408, 20926, 367, 282, 2777, 436, 372, 314, 570, 1041, 272, 2777, 275, 12651, 14, 362, 63, 3059, 8, 3059, 63, 344, 9, 339, 822, 63, 12233, 275, 822, 8, 5564, 8, 3059, 12, 1994, 1725, 15, 1959, 3059, 459, 1725, 1105, 339, 367, 284, 63, 3554, 315, 1425, 8, 552, 63, 12233, 304, 267, 2213, 275, 7543, 8, 3059, 12, 1994, 1725, 5321, 16, 5995, 2302, 1370, 908, 8, 73, 63, 3554, 430, 267, 2213, 63, 7780, 281, 275, 7543, 2398, 16645, 8, 3059, 63, 344, 12, 2213, 9, 267, 340, 440, 1788, 503, 2213, 63, 7780, 281, 14, 362, 63, 1501, 342, 508, 1788, 26, 288, 372, 2213, 63, 7780, 281, 421, 199, 318, 664, 63, 7780, 1192, 837, 272, 408, 1767, 2808, 19653, 1192, 7741, 701, 19924, 12058, 540, 63, 4225, 12058, 3960, 63, 12125, 1041, 272, 754, 275, 942, 272, 19653, 1192, 63, 4561, 275, 469, 267, 876, 16645, 855, 354, 10651, 876, 16645, 367, 876, 16645, 315, 267, 1453, 63, 571, 14, 5359, 459, 30628, 13, 7780, 281, 2278, 7780, 1192, 272, 789, 339, 367, 876, 16645, 315, 1453, 63, 571, 14, 888, 14, 362, 360, 4225, 12058, 540, 63, 4225, 12058, 3960, 63, 12125, 735, 267, 340, 876, 16645, 315, 19653, 1192, 63, 4561, 26, 288, 754, 14, 740, 8, 7780, 1192, 63, 4561, 59, 7780, 281, 566, 272, 372, 754, 421, 199, 32, 15918, 14, 4449, 2336, 28, 17532, 12202, 7780, 297, 3102, 2968, 2970, 297, 283, 4030, 1105, 199, 318, 19653, 8, 17532, 304, 272, 408, 27116, 570, 367, 1627, 2777, 1041, 272, 2213, 63, 7780, 281, 275, 664, 63, 3554, 63, 7780, 281, 8, 267, 25305, 12, 1056, 14, 589, 14, 362, 360, 1501, 297, 730, 29, 495, 430, 339, 367, 3589, 315, 664, 63, 7780, 1192, 837, 267, 340, 3589, 14, 2425, 63, 7780, 8, 3554, 63, 7780, 281, 304, 288, 372, 3589, 14, 7780, 8, 3554, 63, 7780, 281, 9, 421, 199, 32, 15918, 14, 4449, 2336, 3554, 8316, 17532, 23220, 1501, 5971, 199, 318, 2213, 8, 17532, 12, 1788, 304, 272, 408, 1767, 282, 2547, 543, 314, 570, 2013, 315, 314, 2777, 1041, 272, 2213, 63, 7780, 281, 275, 664, 63, 3554, 63, 7780, 281, 8, 17532, 12, 1788, 9, 339, 347, 2547, 63, 493, 8, 2302, 304, 267, 543, 1551, 8, 2302, 12, 283, 4848, 358, 465, 289, 26, 288, 1830, 715, 26, 355, 3728, 275, 289, 14, 739, 8, 7727, 9, 355, 340, 3728, 26, 490, 1995, 3728, 355, 587, 26, 490, 372, 272, 2547, 275, 2547, 63, 493, 8, 3554, 63, 7780, 281, 14, 3554, 14, 2302, 9, 339, 372, 7232, 8, 1745, 12, 490, 12200, 29, 7626, 1313, 14, 11636, 63, 466, 8, 717, 2213, 63, 7780, 281, 14, 3554, 14, 2302, 2788, 16, 566, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 12235, 14, 199, 3, 1898, 334, 35, 9, 7800, 24354, 14, 199, 3, 199, 3, 12235, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 199, 3, 436, 15, 269, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 199, 3, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 12235, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 199, 3, 2997, 12, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 12235, 27, 340, 440, 12, 2218, 370, 314, 199, 3, 2868, 2290, 2752, 12, 3277, 2020, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 199, 3, 4828, 15673, 13, 13421, 12, 8217, 14, 199, 3, 199, 3, 1010, 18876, 642, 4190, 12, 24354, 1630, 440, 199, 3, 14442, 1912, 314, 20001, 436, 25531, 22047, 10009, 370, 652, 701, 12043, 310, 402, 2399, 2004, 199, 3, 465, 376, 6551, 71, 27639, 279, 18863, 503, 11482, 6337, 370, 1263, 1335, 17656, 26382, 14, 199, 199, 624, 607, 7597, 859, 367, 19653, 316, 1584, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 870, 63, 1593, 199, 199, 646, 13290, 199, 646, 747, 199, 199, 504, 7209, 492, 22447, 1361, 12, 7232, 12, 1453, 63, 571, 12, 1056, 199, 504, 13640, 63, 12233, 492, 7543, 199, 504, 13640, 63, 6502, 492, 12651, 199, 199, 15918, 275, 22447, 1361, 8, 272, 283, 30628, 63, 7780, 281, 297, 272, 636, 354, 3108, 272, 1978, 63, 3741, 534, 5876, 297, 272, 2955, 63, 3741, 534, 1986, 297, 199, 9, 421, 199, 533, 7543, 2398, 16645, 8, 785, 304, 272, 408, 17473, 2005, 2402, 2556, 3595, 8247, 1041, 339, 347, 636, 826, 721, 277, 12, 2777, 63, 344, 12, 2213, 304, 267, 408, 2543, 11097, 1041, 267, 291, 14, 3059, 63, 344, 275, 2777, 63, 344, 267, 291, 14, 515, 275, 747, 14, 515, 14, 3475, 8, 3554, 14, 2302, 9, 267, 291, 14, 3435, 275, 2213, 14, 2302, 59, 3554, 14, 2302, 14, 14542, 7563, 435, 413, 2938, 267, 291, 14, 354, 275, 2213, 14, 2302, 59, 2151, 822, 8, 277, 14, 515, 9, 435, 413, 26, 446, 822, 8, 277, 14, 3435, 9, 446, 413, 61, 267, 291, 14, 3554, 275, 2213, 339, 347, 664, 63, 1501, 8, 277, 304, 267, 408, 14860, 314, 570, 536, 1041, 267, 372, 5041, 16, 26944, 17, 5285, 908, 8, 277, 14, 354, 12, 291, 14, 3435, 9, 421, 199, 318, 664, 63, 3554, 63, 7780, 281, 8, 3059, 63, 344, 12, 1788, 304, 272, 408, 20926, 367, 282, 2777, 436, 372, 314, 570, 1041, 272, 2777, 275, 12651, 14, 362, 63, 3059, 8, 3059, 63, 344, 9, 339, 822, 63, 12233, 275, 822, 8, 5564, 8, 3059, 12, 1994, 1725, 15, 1959, 3059, 459, 1725, 1105, 339, 367, 284, 63, 3554, 315, 1425, 8, 552, 63, 12233, 304, 267, 2213, 275, 7543, 8, 3059, 12, 1994, 1725, 5321, 16, 5995, 2302, 1370, 908, 8, 73, 63, 3554, 430, 267, 2213, 63, 7780, 281, 275, 7543, 2398, 16645, 8, 3059, 63, 344, 12, 2213, 9, 267, 340, 440, 1788, 503, 2213, 63, 7780, 281, 14, 362, 63, 1501, 342, 508, 1788, 26, 288, 372, 2213, 63, 7780, 281, 421, 199, 318, 664, 63, 7780, 1192, 837, 272, 408, 1767, 2808, 19653, 1192, 7741, 701, 19924, 12058, 540, 63, 4225, 12058, 3960, 63, 12125, 1041, 272, 754, 275, 942, 272, 19653, 1192, 63, 4561, 275, 469, 267, 876, 16645, 855, 354, 10651, 876, 16645, 367, 876, 16645, 315, 267, 1453, 63, 571, 14, 5359, 459, 30628, 13, 7780, 281, 2278, 7780, 1192, 272, 789, 339, 367, 876, 16645, 315, 1453, 63, 571, 14, 888, 14, 362, 360, 4225, 12058, 540, 63, 4225, 12058, 3960, 63, 12125, 735, 267, 340, 876, 16645, 315, 19653, 1192, 63, 4561, 26, 288, 754, 14, 740, 8, 7780, 1192, 63, 4561, 59, 7780, 281, 566, 272, 372, 754, 421, 199, 32, 15918, 14, 4449, 2336, 28, 17532, 12202, 7780, 297, 3102, 2968, 2970, 297, 283, 4030, 1105, 199, 318, 19653, 8, 17532, 304, 272, 408, 27116, 570, 367, 1627, 2777, 1041, 272, 2213, 63, 7780, 281, 275, 664, 63, 3554, 63, 7780, 281, 8, 267, 25305, 12, 1056, 14, 589, 14, 362, 360, 1501, 297, 730, 29, 495, 430, 339, 367, 3589, 315, 664, 63, 7780, 1192, 837, 267, 340, 3589, 14, 2425, 63, 7780, 8, 3554, 63, 7780, 281, 304, 288, 372, 3589, 14, 7780, 8, 3554, 63, 7780, 281, 9, 421, 199, 32, 15918, 14, 4449, 2336, 3554, 8316, 17532, 23220, 1501, 5971, 199, 318, 2213, 8, 17532, 12, 1788, 304, 272, 408, 1767, 282, 2547, 543, 314, 570, 2013, 315, 314, 2777, 1041, 272, 2213, 63, 7780, 281, 275, 664, 63, 3554, 63, 7780, 281, 8, 17532, 12, 1788, 9, 339, 347, 2547, 63, 493, 8, 2302, 304, 267, 543, 1551, 8, 2302, 12, 283, 4848, 358, 465, 289, 26, 288, 1830, 715, 26, 355, 3728, 275, 289, 14, 739, 8, 7727, 9, 355, 340, 3728, 26, 490, 1995, 3728, 355, 587, 26, 490, 372, 272, 2547, 275, 2547, 63, 493, 8, 3554, 63, 7780, 281, 14, 3554, 14, 2302, 9, 339, 372, 7232, 8, 1745, 12, 490, 12200, 29, 7626, 1313, 14, 11636, 63, 466, 8, 717, 2213, 63, 7780, 281, 14, 3554, 14, 2302, 2788, 16, 566, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
wangmiao1981/spark
python/pyspark/sql/tests/test_pandas_cogrouped_map.py
20
9306
# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import unittest from pyspark.sql.functions import array, explode, col, lit, udf, pandas_udf from pyspark.sql.types import DoubleType, StructType, StructField, Row from pyspark.testing.sqlutils import ReusedSQLTestCase, have_pandas, have_pyarrow, \ pandas_requirement_message, pyarrow_requirement_message from pyspark.testing.utils import QuietTest if have_pandas: import pandas as pd from pandas.testing import assert_frame_equal if have_pyarrow: import pyarrow as pa # noqa: F401 @unittest.skipIf( not have_pandas or not have_pyarrow, pandas_requirement_message or pyarrow_requirement_message) # type: ignore[arg-type] class CogroupedMapInPandasTests(ReusedSQLTestCase): @property def data1(self): return self.spark.range(10).toDF('id') \ .withColumn("ks", array([lit(i) for i in range(20, 30)])) \ .withColumn("k", explode(col('ks')))\ .withColumn("v", col('k') * 10)\ .drop('ks') @property def data2(self): return self.spark.range(10).toDF('id') \ .withColumn("ks", array([lit(i) for i in range(20, 30)])) \ .withColumn("k", explode(col('ks'))) \ .withColumn("v2", col('k') * 100) \ .drop('ks') def test_simple(self): self._test_merge(self.data1, self.data2) def test_left_group_empty(self): left = self.data1.where(col("id") % 2 == 0) self._test_merge(left, self.data2) def test_right_group_empty(self): right = self.data2.where(col("id") % 2 == 0) self._test_merge(self.data1, right) def test_different_schemas(self): right = self.data2.withColumn('v3', lit('a')) self._test_merge(self.data1, right, 'id long, k int, v int, v2 int, v3 string') def test_complex_group_by(self): left = pd.DataFrame.from_dict({ 'id': [1, 2, 3], 'k': [5, 6, 7], 'v': [9, 10, 11] }) right = pd.DataFrame.from_dict({ 'id': [11, 12, 13], 'k': [5, 6, 7], 'v2': [90, 100, 110] }) left_gdf = self.spark\ .createDataFrame(left)\ .groupby(col('id') % 2 == 0) right_gdf = self.spark \ .createDataFrame(right) \ .groupby(col('id') % 2 == 0) def merge_pandas(l, r): return pd.merge(l[['k', 'v']], r[['k', 'v2']], on=['k']) result = left_gdf \ .cogroup(right_gdf) \ .applyInPandas(merge_pandas, 'k long, v long, v2 long') \ .sort(['k']) \ .toPandas() expected = pd.DataFrame.from_dict({ 'k': [5, 6, 7], 'v': [9, 10, 11], 'v2': [90, 100, 110] }) assert_frame_equal(expected, result) def test_empty_group_by(self): left = self.data1 right = self.data2 def merge_pandas(l, r): return pd.merge(l, r, on=['id', 'k']) result = left.groupby().cogroup(right.groupby())\ .applyInPandas(merge_pandas, 'id long, k int, v int, v2 int') \ .sort(['id', 'k']) \ .toPandas() left = left.toPandas() right = right.toPandas() expected = pd \ .merge(left, right, on=['id', 'k']) \ .sort_values(by=['id', 'k']) assert_frame_equal(expected, result) def test_mixed_scalar_udfs_followed_by_cogrouby_apply(self): df = self.spark.range(0, 10).toDF('v1') df = df.withColumn('v2', udf(lambda x: x + 1, 'int')(df['v1'])) \ .withColumn('v3', pandas_udf(lambda x: x + 2, 'int')(df['v1'])) result = df.groupby().cogroup(df.groupby()) \ .applyInPandas(lambda x, y: pd.DataFrame([(x.sum().sum(), y.sum().sum())]), 'sum1 int, sum2 int').collect() self.assertEqual(result[0]['sum1'], 165) self.assertEqual(result[0]['sum2'], 165) def test_with_key_left(self): self._test_with_key(self.data1, self.data1, isLeft=True) def test_with_key_right(self): self._test_with_key(self.data1, self.data1, isLeft=False) def test_with_key_left_group_empty(self): left = self.data1.where(col("id") % 2 == 0) self._test_with_key(left, self.data1, isLeft=True) def test_with_key_right_group_empty(self): right = self.data1.where(col("id") % 2 == 0) self._test_with_key(self.data1, right, isLeft=False) def test_with_key_complex(self): def left_assign_key(key, l, _): return l.assign(key=key[0]) result = self.data1 \ .groupby(col('id') % 2 == 0)\ .cogroup(self.data2.groupby(col('id') % 2 == 0)) \ .applyInPandas(left_assign_key, 'id long, k int, v int, key boolean') \ .sort(['id', 'k']) \ .toPandas() expected = self.data1.toPandas() expected = expected.assign(key=expected.id % 2 == 0) assert_frame_equal(expected, result) def test_wrong_return_type(self): # Test that we get a sensible exception invalid values passed to apply left = self.data1 right = self.data2 with QuietTest(self.sc): with self.assertRaisesRegex( NotImplementedError, 'Invalid return type.*ArrayType.*TimestampType'): left.groupby('id').cogroup(right.groupby('id')).applyInPandas( lambda l, r: l, 'id long, v array<timestamp>') def test_wrong_args(self): left = self.data1 right = self.data2 with self.assertRaisesRegex(ValueError, 'Invalid function'): left.groupby('id').cogroup(right.groupby('id')) \ .applyInPandas(lambda: 1, StructType([StructField("d", DoubleType())])) def test_case_insensitive_grouping_column(self): # SPARK-31915: case-insensitive grouping column should work. df1 = self.spark.createDataFrame([(1, 1)], ("column", "value")) row = df1.groupby("ColUmn").cogroup( df1.groupby("COLUMN") ).applyInPandas(lambda r, l: r + l, "column long, value long").first() self.assertEqual(row.asDict(), Row(column=2, value=2).asDict()) df2 = self.spark.createDataFrame([(1, 1)], ("column", "value")) row = df1.groupby("ColUmn").cogroup( df2.groupby("COLUMN") ).applyInPandas(lambda r, l: r + l, "column long, value long").first() self.assertEqual(row.asDict(), Row(column=2, value=2).asDict()) def test_self_join(self): # SPARK-34319: self-join with FlatMapCoGroupsInPandas df = self.spark.createDataFrame([(1, 1)], ("column", "value")) row = df.groupby("ColUmn").cogroup( df.groupby("COLUMN") ).applyInPandas(lambda r, l: r + l, "column long, value long") row = row.join(row).first() self.assertEqual(row.asDict(), Row(column=2, value=2).asDict()) @staticmethod def _test_with_key(left, right, isLeft): def right_assign_key(key, l, r): return l.assign(key=key[0]) if isLeft else r.assign(key=key[0]) result = left \ .groupby('id') \ .cogroup(right.groupby('id')) \ .applyInPandas(right_assign_key, 'id long, k int, v int, key long') \ .toPandas() expected = left.toPandas() if isLeft else right.toPandas() expected = expected.assign(key=expected.id) assert_frame_equal(expected, result) @staticmethod def _test_merge(left, right, output_schema='id long, k int, v int, v2 int'): def merge_pandas(l, r): return pd.merge(l, r, on=['id', 'k']) result = left \ .groupby('id') \ .cogroup(right.groupby('id')) \ .applyInPandas(merge_pandas, output_schema)\ .sort(['id', 'k']) \ .toPandas() left = left.toPandas() right = right.toPandas() expected = pd \ .merge(left, right, on=['id', 'k']) \ .sort_values(by=['id', 'k']) assert_frame_equal(expected, result) if __name__ == "__main__": from pyspark.sql.tests.test_pandas_cogrouped_map import * # noqa: F401 try: import xmlrunner # type: ignore[import] testRunner = xmlrunner.XMLTestRunner(output='target/test-reports', verbosity=2) except ImportError: testRunner = None unittest.main(testRunner=testRunner, verbosity=2)
apache-2.0
[ 3, 199, 3, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 503, 1655, 199, 3, 11615, 4190, 14024, 14, 221, 1666, 314, 12840, 570, 1854, 543, 199, 3, 642, 1736, 367, 4722, 2556, 12602, 4248, 12715, 14, 199, 3, 710, 14857, 12378, 642, 570, 370, 2047, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 199, 3, 334, 1589, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 199, 3, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 259, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 199, 646, 2882, 199, 199, 504, 15847, 14, 3009, 14, 5777, 492, 1625, 12, 15868, 271, 12, 1048, 12, 28649, 12, 399, 1587, 12, 10634, 63, 10031, 199, 504, 15847, 14, 3009, 14, 1313, 492, 22945, 804, 12, 13039, 804, 12, 13039, 792, 12, 15231, 199, 504, 15847, 14, 4776, 14, 3009, 1208, 492, 799, 2972, 4657, 1746, 12, 1172, 63, 15718, 12, 1172, 63, 647, 7691, 12, 971, 272, 10634, 63, 12434, 63, 1188, 12, 1134, 7691, 63, 12434, 63, 1188, 199, 504, 15847, 14, 4776, 14, 1208, 492, 1413, 1907, 386, 774, 199, 199, 692, 1172, 63, 15718, 26, 272, 492, 10634, 465, 6454, 272, 687, 10634, 14, 4776, 492, 702, 63, 1943, 63, 1452, 199, 199, 692, 1172, 63, 647, 7691, 26, 272, 492, 1134, 7691, 465, 691, 221, 327, 8151, 26, 481, 8854, 421, 199, 32, 2796, 14, 15118, 8, 272, 440, 1172, 63, 15718, 503, 440, 1172, 63, 647, 7691, 12, 272, 10634, 63, 12434, 63, 1188, 503, 1134, 7691, 63, 12434, 63, 1188, 9, 221, 327, 730, 26, 3686, 59, 1273, 13, 466, 61, 199, 533, 445, 974, 11330, 2956, 607, 48, 7683, 2925, 8, 497, 2972, 4657, 1746, 304, 339, 768, 1829, 272, 347, 666, 17, 8, 277, 304, 267, 372, 291, 14, 9852, 14, 1842, 8, 709, 680, 475, 3888, 360, 344, 358, 971, 288, 1275, 1045, 4547, 480, 6080, 401, 1625, 779, 1051, 8, 73, 9, 367, 284, 315, 1425, 8, 1165, 12, 4233, 19563, 971, 288, 1275, 1045, 4547, 480, 75, 401, 15868, 271, 8, 761, 360, 6080, 7058, 60, 288, 1275, 1045, 4547, 480, 86, 401, 1048, 360, 75, 358, 627, 1616, 2862, 288, 1275, 4824, 360, 6080, 358, 339, 768, 1829, 272, 347, 666, 18, 8, 277, 304, 267, 372, 291, 14, 9852, 14, 1842, 8, 709, 680, 475, 3888, 360, 344, 358, 971, 288, 1275, 1045, 4547, 480, 6080, 401, 1625, 779, 1051, 8, 73, 9, 367, 284, 315, 1425, 8, 1165, 12, 4233, 19563, 971, 288, 1275, 1045, 4547, 480, 75, 401, 15868, 271, 8, 761, 360, 6080, 7058, 971, 288, 1275, 1045, 4547, 480, 86, 18, 401, 1048, 360, 75, 358, 627, 2948, 9, 971, 288, 1275, 4824, 360, 6080, 358, 339, 347, 511, 63, 4129, 8, 277, 304, 267, 291, 423, 396, 63, 5628, 8, 277, 14, 576, 17, 12, 291, 14, 576, 18, 9, 339, 347, 511, 63, 3039, 63, 923, 63, 1667, 8, 277, 304, 267, 3602, 275, 291, 14, 576, 17, 14, 4509, 8, 761, 480, 344, 531, 450, 499, 508, 378, 9, 267, 291, 423, 396, 63, 5628, 8, 3039, 12, 291, 14, 576, 18, 9, 339, 347, 511, 63, 1019, 63, 923, 63, 1667, 8, 277, 304, 267, 2451, 275, 291, 14, 576, 18, 14, 4509, 8, 761, 480, 344, 531, 450, 499, 508, 378, 9, 267, 291, 423, 396, 63, 5628, 8, 277, 14, 576, 17, 12, 2451, 9, 339, 347, 511, 63, 14020, 63, 9482, 8, 277, 304, 267, 2451, 275, 291, 14, 576, 18, 14, 1045, 4547, 360, 86, 19, 297, 28649, 360, 65, 1333, 267, 291, 423, 396, 63, 5628, 8, 277, 14, 576, 17, 12, 2451, 12, 283, 344, 1846, 12, 1022, 1109, 12, 373, 1109, 12, 373, 18, 1109, 12, 373, 19, 1059, 358, 339, 347, 511, 63, 5254, 63, 923, 63, 991, 8, 277, 304, 267, 3602, 275, 6454, 14, 9205, 14, 504, 63, 807, 2561, 288, 283, 344, 356, 359, 17, 12, 499, 12, 650, 467, 288, 283, 75, 356, 221, 359, 21, 12, 1227, 12, 1520, 467, 288, 283, 86, 356, 359, 25, 12, 1616, 12, 4119, 61, 267, 3828, 398, 2451, 275, 6454, 14, 9205, 14, 504, 63, 807, 2561, 288, 283, 344, 356, 359, 845, 12, 3144, 12, 4944, 467, 288, 283, 75, 356, 359, 21, 12, 1227, 12, 1520, 467, 288, 283, 86, 18, 356, 359, 2710, 12, 2948, 12, 16814, 61, 267, 3828, 398, 3602, 63, 71, 1587, 275, 291, 14, 9852, 60, 288, 1275, 25482, 8, 3039, 2862, 288, 1275, 16968, 8, 761, 360, 344, 358, 450, 499, 508, 378, 9, 398, 2451, 63, 71, 1587, 275, 291, 14, 9852, 971, 288, 1275, 25482, 8, 1019, 9, 971, 288, 1275, 16968, 8, 761, 360, 344, 358, 450, 499, 508, 378, 9, 398, 347, 5389, 63, 15718, 8, 76, 12, 519, 304, 288, 372, 6454, 14, 5628, 8, 76, 59, 459, 75, 297, 283, 86, 2157, 519, 59, 459, 75, 297, 283, 86, 18, 2157, 641, 2968, 75, 1105, 398, 754, 275, 3602, 63, 71, 1587, 971, 288, 1275, 331, 923, 8, 1019, 63, 71, 1587, 9, 971, 288, 1275, 4998, 607, 48, 7683, 8, 5628, 63, 15718, 12, 283, 75, 1846, 12, 373, 1846, 12, 373, 18, 1846, 358, 971, 288, 1275, 3191, 2941, 75, 1105, 971, 288, 1275, 475, 48, 7683, 342, 398, 1420, 275, 6454, 14, 9205, 14, 504, 63, 807, 2561, 288, 283, 75, 356, 359, 21, 12, 1227, 12, 1520, 467, 288, 283, 86, 356, 359, 25, 12, 1616, 12, 4119, 467, 288, 283, 86, 18, 356, 359, 2710, 12, 2948, 12, 16814, 61, 267, 3828 ]
[ 199, 3, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 503, 1655, 199, 3, 11615, 4190, 14024, 14, 221, 1666, 314, 12840, 570, 1854, 543, 199, 3, 642, 1736, 367, 4722, 2556, 12602, 4248, 12715, 14, 199, 3, 710, 14857, 12378, 642, 570, 370, 2047, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 199, 3, 334, 1589, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 199, 3, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 259, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 199, 646, 2882, 199, 199, 504, 15847, 14, 3009, 14, 5777, 492, 1625, 12, 15868, 271, 12, 1048, 12, 28649, 12, 399, 1587, 12, 10634, 63, 10031, 199, 504, 15847, 14, 3009, 14, 1313, 492, 22945, 804, 12, 13039, 804, 12, 13039, 792, 12, 15231, 199, 504, 15847, 14, 4776, 14, 3009, 1208, 492, 799, 2972, 4657, 1746, 12, 1172, 63, 15718, 12, 1172, 63, 647, 7691, 12, 971, 272, 10634, 63, 12434, 63, 1188, 12, 1134, 7691, 63, 12434, 63, 1188, 199, 504, 15847, 14, 4776, 14, 1208, 492, 1413, 1907, 386, 774, 199, 199, 692, 1172, 63, 15718, 26, 272, 492, 10634, 465, 6454, 272, 687, 10634, 14, 4776, 492, 702, 63, 1943, 63, 1452, 199, 199, 692, 1172, 63, 647, 7691, 26, 272, 492, 1134, 7691, 465, 691, 221, 327, 8151, 26, 481, 8854, 421, 199, 32, 2796, 14, 15118, 8, 272, 440, 1172, 63, 15718, 503, 440, 1172, 63, 647, 7691, 12, 272, 10634, 63, 12434, 63, 1188, 503, 1134, 7691, 63, 12434, 63, 1188, 9, 221, 327, 730, 26, 3686, 59, 1273, 13, 466, 61, 199, 533, 445, 974, 11330, 2956, 607, 48, 7683, 2925, 8, 497, 2972, 4657, 1746, 304, 339, 768, 1829, 272, 347, 666, 17, 8, 277, 304, 267, 372, 291, 14, 9852, 14, 1842, 8, 709, 680, 475, 3888, 360, 344, 358, 971, 288, 1275, 1045, 4547, 480, 6080, 401, 1625, 779, 1051, 8, 73, 9, 367, 284, 315, 1425, 8, 1165, 12, 4233, 19563, 971, 288, 1275, 1045, 4547, 480, 75, 401, 15868, 271, 8, 761, 360, 6080, 7058, 60, 288, 1275, 1045, 4547, 480, 86, 401, 1048, 360, 75, 358, 627, 1616, 2862, 288, 1275, 4824, 360, 6080, 358, 339, 768, 1829, 272, 347, 666, 18, 8, 277, 304, 267, 372, 291, 14, 9852, 14, 1842, 8, 709, 680, 475, 3888, 360, 344, 358, 971, 288, 1275, 1045, 4547, 480, 6080, 401, 1625, 779, 1051, 8, 73, 9, 367, 284, 315, 1425, 8, 1165, 12, 4233, 19563, 971, 288, 1275, 1045, 4547, 480, 75, 401, 15868, 271, 8, 761, 360, 6080, 7058, 971, 288, 1275, 1045, 4547, 480, 86, 18, 401, 1048, 360, 75, 358, 627, 2948, 9, 971, 288, 1275, 4824, 360, 6080, 358, 339, 347, 511, 63, 4129, 8, 277, 304, 267, 291, 423, 396, 63, 5628, 8, 277, 14, 576, 17, 12, 291, 14, 576, 18, 9, 339, 347, 511, 63, 3039, 63, 923, 63, 1667, 8, 277, 304, 267, 3602, 275, 291, 14, 576, 17, 14, 4509, 8, 761, 480, 344, 531, 450, 499, 508, 378, 9, 267, 291, 423, 396, 63, 5628, 8, 3039, 12, 291, 14, 576, 18, 9, 339, 347, 511, 63, 1019, 63, 923, 63, 1667, 8, 277, 304, 267, 2451, 275, 291, 14, 576, 18, 14, 4509, 8, 761, 480, 344, 531, 450, 499, 508, 378, 9, 267, 291, 423, 396, 63, 5628, 8, 277, 14, 576, 17, 12, 2451, 9, 339, 347, 511, 63, 14020, 63, 9482, 8, 277, 304, 267, 2451, 275, 291, 14, 576, 18, 14, 1045, 4547, 360, 86, 19, 297, 28649, 360, 65, 1333, 267, 291, 423, 396, 63, 5628, 8, 277, 14, 576, 17, 12, 2451, 12, 283, 344, 1846, 12, 1022, 1109, 12, 373, 1109, 12, 373, 18, 1109, 12, 373, 19, 1059, 358, 339, 347, 511, 63, 5254, 63, 923, 63, 991, 8, 277, 304, 267, 3602, 275, 6454, 14, 9205, 14, 504, 63, 807, 2561, 288, 283, 344, 356, 359, 17, 12, 499, 12, 650, 467, 288, 283, 75, 356, 221, 359, 21, 12, 1227, 12, 1520, 467, 288, 283, 86, 356, 359, 25, 12, 1616, 12, 4119, 61, 267, 3828, 398, 2451, 275, 6454, 14, 9205, 14, 504, 63, 807, 2561, 288, 283, 344, 356, 359, 845, 12, 3144, 12, 4944, 467, 288, 283, 75, 356, 359, 21, 12, 1227, 12, 1520, 467, 288, 283, 86, 18, 356, 359, 2710, 12, 2948, 12, 16814, 61, 267, 3828, 398, 3602, 63, 71, 1587, 275, 291, 14, 9852, 60, 288, 1275, 25482, 8, 3039, 2862, 288, 1275, 16968, 8, 761, 360, 344, 358, 450, 499, 508, 378, 9, 398, 2451, 63, 71, 1587, 275, 291, 14, 9852, 971, 288, 1275, 25482, 8, 1019, 9, 971, 288, 1275, 16968, 8, 761, 360, 344, 358, 450, 499, 508, 378, 9, 398, 347, 5389, 63, 15718, 8, 76, 12, 519, 304, 288, 372, 6454, 14, 5628, 8, 76, 59, 459, 75, 297, 283, 86, 2157, 519, 59, 459, 75, 297, 283, 86, 18, 2157, 641, 2968, 75, 1105, 398, 754, 275, 3602, 63, 71, 1587, 971, 288, 1275, 331, 923, 8, 1019, 63, 71, 1587, 9, 971, 288, 1275, 4998, 607, 48, 7683, 8, 5628, 63, 15718, 12, 283, 75, 1846, 12, 373, 1846, 12, 373, 18, 1846, 358, 971, 288, 1275, 3191, 2941, 75, 1105, 971, 288, 1275, 475, 48, 7683, 342, 398, 1420, 275, 6454, 14, 9205, 14, 504, 63, 807, 2561, 288, 283, 75, 356, 359, 21, 12, 1227, 12, 1520, 467, 288, 283, 86, 356, 359, 25, 12, 1616, 12, 4119, 467, 288, 283, 86, 18, 356, 359, 2710, 12, 2948, 12, 16814, 61, 267, 3828, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
Qbicz/multi-secret-sharing
python/tests/test_MultiSecretCommon.py
1
2841
from nose.tools import assert_equal from nose.tools import assert_not_equal from nose.tools import assert_raises from multisecret.MultiSecretRoyAdhikari import Dealer import multisecret.MultiSecretCommon as common """ Declare basic params used to initialize Dealer in test cases """ # large prime from NIST P-256 elliptic curve p256 = 2**256 - 2**224 + 2**192 + 2**96 - 1 # multi secret sharing parameters s_secrets = [7, 313, 671] # s_i n_participants = 3 # access structure: to which secret what group has access # Gamma(s_i) = [A1, A2, ... Al], Aq = (P1, P2, Pm), q=1,2...l # gamma1 is a group of users authorized to reconstruct s1 gamma1 = [(1,3)] gamma2 = [(1,2), (2,3)] # A1, A2 implicitly gamma3 = [(1,2,3)] # to secret s3 only all 3 users together can gain access access_structures = [gamma1, gamma2, gamma3] def test_modulo_p(): p = 1009 dealer = Dealer(p, n_participants, s_secrets, access_structures) assert_equal(common.modulo_p(p, 2011), 1002) def test_list_of_random_in_modulo_p(): """ test: list_of_random_in_modulo_p """ dealer = Dealer(4099, n_participants, s_secrets, access_structures) n = 5 randomList = common.list_of_random_in_modulo_p(n, dealer.hash_len, dealer.p) common.print_list_of_hex(randomList, 'test randomList') # check the length of the list assert_equal(len(randomList), n) # check the type of object in the list assert_equal(isinstance(randomList[0], bytes), True) # dealer_short = Dealer(1009, 2, [13], [[(1,2), ()]]) # randomListShort = dealer_short.list_of_random_in_modulo_p(n) # dealer_short.print_list_of_hex(randomListShort, 'test randomListShort') # assert_equal(len(randomListShort[0]), 1) def test_provide_id(): dealer = Dealer(p256, n_participants, s_secrets, access_structures) id_list = common.provide_id(n_participants, dealer.hash_len, dealer.p) # check the length of the list assert_equal(len(id_list), n_participants) # check the type of object in the list assert_equal(isinstance(id_list[0], bytes), True) def test_shamir_polynomial_compute(): dealer = Dealer(p256, n_participants, s_secrets, access_structures) dealer.access_group_polynomial_coeffs() # override coeffs dealer.d[0][0] = [bytes([0x05]), bytes([0x07])] coeffs = dealer.get_d_polynomial_coeffs(0, 0) secret_value = dealer.s_secrets[0] value = common.shamir_polynomial_compute(bytes([0x01]), coeffs, secret_value, dealer.p) assert_equal(value, 12 + s_secrets[0]) value = common.shamir_polynomial_compute(bytes([0x02]), coeffs, secret_value, dealer.p) assert_equal(value, 38 + s_secrets[0])
mit
[ 504, 11354, 14, 2537, 492, 702, 63, 1452, 199, 504, 11354, 14, 2537, 492, 702, 63, 1397, 63, 1452, 199, 504, 11354, 14, 2537, 492, 702, 63, 3536, 199, 504, 3510, 4731, 14, 3947, 13790, 3863, 89, 2767, 72, 3258, 759, 492, 1487, 29706, 199, 646, 3510, 4731, 14, 3947, 13790, 7844, 465, 2863, 199, 199, 624, 13966, 29200, 5678, 1862, 1202, 370, 8265, 1487, 29706, 315, 511, 5560, 408, 199, 3, 7031, 21619, 687, 653, 6225, 510, 13, 3912, 16028, 764, 15318, 199, 80, 3912, 275, 499, 538, 3912, 446, 499, 538, 8731, 435, 499, 538, 5756, 435, 499, 538, 2534, 446, 413, 199, 3, 3510, 7565, 26994, 2633, 199, 83, 63, 16153, 275, 359, 23, 12, 650, 969, 12, 1227, 3172, 61, 327, 308, 63, 73, 199, 78, 63, 31790, 275, 650, 199, 3, 2879, 5523, 26, 370, 1314, 7565, 4052, 1572, 965, 2879, 199, 3, 598, 4746, 8, 83, 63, 73, 9, 275, 359, 33, 17, 12, 437, 18, 12, 2263, 4580, 467, 437, 81, 275, 334, 48, 17, 12, 510, 18, 12, 510, 77, 395, 1894, 29, 17, 12, 18, 1396, 76, 199, 3, 10169, 17, 365, 282, 1572, 402, 4390, 18788, 370, 28462, 308, 17, 199, 7325, 17, 275, 3842, 17, 12, 19, 1874, 199, 7325, 18, 275, 3842, 17, 12, 18, 395, 334, 18, 12, 19, 1874, 327, 437, 17, 12, 437, 18, 19796, 199, 7325, 19, 275, 3842, 17, 12, 18, 12, 19, 1874, 327, 370, 7565, 308, 19, 1454, 1006, 650, 4390, 10451, 883, 15334, 2879, 199, 2732, 63, 13547, 275, 359, 7325, 17, 12, 10169, 18, 12, 10169, 19, 61, 421, 199, 318, 511, 63, 1494, 13957, 63, 80, 837, 272, 299, 275, 2948, 25, 272, 477, 29706, 275, 1487, 29706, 8, 80, 12, 302, 63, 31790, 12, 308, 63, 16153, 12, 2879, 63, 13547, 9, 272, 702, 63, 1452, 8, 2330, 14, 1494, 13957, 63, 80, 8, 80, 12, 7760, 395, 2948, 18, 9, 421, 199, 318, 511, 63, 513, 63, 1618, 63, 2355, 63, 262, 63, 1494, 13957, 63, 80, 837, 272, 408, 511, 26, 769, 63, 1618, 63, 2355, 63, 262, 63, 1494, 13957, 63, 80, 408, 272, 477, 29706, 275, 1487, 29706, 8, 2167, 1020, 12, 302, 63, 31790, 12, 308, 63, 16153, 12, 2879, 63, 13547, 9, 339, 302, 275, 959, 272, 2196, 1296, 275, 2863, 14, 513, 63, 1618, 63, 2355, 63, 262, 63, 1494, 13957, 63, 80, 8, 78, 12, 8962, 477, 29706, 14, 2227, 63, 552, 12, 8962, 477, 29706, 14, 80, 9, 272, 2863, 14, 1361, 63, 513, 63, 1618, 63, 4097, 8, 2355, 1296, 12, 283, 396, 2196, 1296, 358, 272, 327, 1104, 314, 2582, 402, 314, 769, 272, 702, 63, 1452, 8, 552, 8, 2355, 1296, 395, 302, 9, 272, 327, 1104, 314, 730, 402, 909, 315, 314, 769, 272, 702, 63, 1452, 8, 6074, 8, 2355, 1296, 59, 16, 467, 2783, 395, 715, 9, 339, 327, 477, 29706, 63, 3612, 275, 1487, 29706, 8, 1960, 25, 12, 499, 12, 359, 969, 467, 3474, 8, 17, 12, 18, 395, 334, 1874, 566, 272, 327, 2196, 1296, 10039, 275, 477, 29706, 63, 3612, 14, 513, 63, 1618, 63, 2355, 63, 262, 63, 1494, 13957, 63, 80, 8, 78, 9, 272, 327, 477, 29706, 63, 3612, 14, 1361, 63, 513, 63, 1618, 63, 4097, 8, 2355, 1296, 10039, 12, 283, 396, 2196, 1296, 10039, 358, 272, 327, 702, 63, 1452, 8, 552, 8, 2355, 1296, 10039, 59, 16, 2522, 413, 9, 421, 199, 318, 511, 63, 20824, 63, 344, 837, 272, 477, 29706, 275, 1487, 29706, 8, 80, 3912, 12, 302, 63, 31790, 12, 308, 63, 16153, 12, 2879, 63, 13547, 9, 339, 1305, 63, 513, 275, 2863, 14, 20824, 63, 344, 8, 78, 63, 31790, 12, 477, 29706, 14, 2227, 63, 552, 12, 477, 29706, 14, 80, 9, 272, 327, 1104, 314, 2582, 402, 314, 769, 272, 702, 63, 1452, 8, 552, 8, 344, 63, 513, 395, 302, 63, 31790, 9, 272, 327, 1104, 314, 730, 402, 909, 315, 314, 769, 272, 702, 63, 1452, 8, 6074, 8, 344, 63, 513, 59, 16, 467, 2783, 395, 715, 9, 421, 199, 318, 511, 63, 609, 455, 723, 63, 22104, 63, 3357, 837, 272, 477, 29706, 275, 1487, 29706, 8, 80, 3912, 12, 302, 63, 31790, 12, 308, 63, 16153, 12, 2879, 63, 13547, 9, 272, 477, 29706, 14, 2732, 63, 923, 63, 22104, 63, 15958, 342, 272, 327, 4278, 29868, 272, 477, 29706, 14, 68, 59, 16, 1527, 16, 61, 275, 359, 2394, 779, 16, 88, 1717, 2522, 2783, 779, 16, 88, 1780, 12457, 339, 29868, 275, 477, 29706, 14, 362, 63, 68, 63, 22104, 63, 15958, 8, 16, 12, 378, 9, 272, 7565, 63, 585, 275, 477, 29706, 14, 83, 63, 16153, 59, 16, 61, 339, 574, 275, 2863, 14, 609, 455, 723, 63, 22104, 63, 3357, 8, 2394, 779, 16, 88, 614, 2522, 29868, 12, 6163, 7565, 63, 585, 12, 477, 29706, 14, 80, 9, 272, 702, 63, 1452, 8, 585, 12, 3144, 435, 308, 63, 16153, 59, 16, 566, 339, 574, 275, 2863, 14, 609, 455, 723, 63, 22104, 63, 3357, 8, 2394, 779, 16, 88, 996, 2522, 29868, 12, 6163, 7565, 63, 585, 12, 477, 29706, 14, 80, 9, 272, 702, 63, 1452, 8, 585, 12, 10448, 435, 308, 63, 16153, 59, 16, 566, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 11354, 14, 2537, 492, 702, 63, 1452, 199, 504, 11354, 14, 2537, 492, 702, 63, 1397, 63, 1452, 199, 504, 11354, 14, 2537, 492, 702, 63, 3536, 199, 504, 3510, 4731, 14, 3947, 13790, 3863, 89, 2767, 72, 3258, 759, 492, 1487, 29706, 199, 646, 3510, 4731, 14, 3947, 13790, 7844, 465, 2863, 199, 199, 624, 13966, 29200, 5678, 1862, 1202, 370, 8265, 1487, 29706, 315, 511, 5560, 408, 199, 3, 7031, 21619, 687, 653, 6225, 510, 13, 3912, 16028, 764, 15318, 199, 80, 3912, 275, 499, 538, 3912, 446, 499, 538, 8731, 435, 499, 538, 5756, 435, 499, 538, 2534, 446, 413, 199, 3, 3510, 7565, 26994, 2633, 199, 83, 63, 16153, 275, 359, 23, 12, 650, 969, 12, 1227, 3172, 61, 327, 308, 63, 73, 199, 78, 63, 31790, 275, 650, 199, 3, 2879, 5523, 26, 370, 1314, 7565, 4052, 1572, 965, 2879, 199, 3, 598, 4746, 8, 83, 63, 73, 9, 275, 359, 33, 17, 12, 437, 18, 12, 2263, 4580, 467, 437, 81, 275, 334, 48, 17, 12, 510, 18, 12, 510, 77, 395, 1894, 29, 17, 12, 18, 1396, 76, 199, 3, 10169, 17, 365, 282, 1572, 402, 4390, 18788, 370, 28462, 308, 17, 199, 7325, 17, 275, 3842, 17, 12, 19, 1874, 199, 7325, 18, 275, 3842, 17, 12, 18, 395, 334, 18, 12, 19, 1874, 327, 437, 17, 12, 437, 18, 19796, 199, 7325, 19, 275, 3842, 17, 12, 18, 12, 19, 1874, 327, 370, 7565, 308, 19, 1454, 1006, 650, 4390, 10451, 883, 15334, 2879, 199, 2732, 63, 13547, 275, 359, 7325, 17, 12, 10169, 18, 12, 10169, 19, 61, 421, 199, 318, 511, 63, 1494, 13957, 63, 80, 837, 272, 299, 275, 2948, 25, 272, 477, 29706, 275, 1487, 29706, 8, 80, 12, 302, 63, 31790, 12, 308, 63, 16153, 12, 2879, 63, 13547, 9, 272, 702, 63, 1452, 8, 2330, 14, 1494, 13957, 63, 80, 8, 80, 12, 7760, 395, 2948, 18, 9, 421, 199, 318, 511, 63, 513, 63, 1618, 63, 2355, 63, 262, 63, 1494, 13957, 63, 80, 837, 272, 408, 511, 26, 769, 63, 1618, 63, 2355, 63, 262, 63, 1494, 13957, 63, 80, 408, 272, 477, 29706, 275, 1487, 29706, 8, 2167, 1020, 12, 302, 63, 31790, 12, 308, 63, 16153, 12, 2879, 63, 13547, 9, 339, 302, 275, 959, 272, 2196, 1296, 275, 2863, 14, 513, 63, 1618, 63, 2355, 63, 262, 63, 1494, 13957, 63, 80, 8, 78, 12, 8962, 477, 29706, 14, 2227, 63, 552, 12, 8962, 477, 29706, 14, 80, 9, 272, 2863, 14, 1361, 63, 513, 63, 1618, 63, 4097, 8, 2355, 1296, 12, 283, 396, 2196, 1296, 358, 272, 327, 1104, 314, 2582, 402, 314, 769, 272, 702, 63, 1452, 8, 552, 8, 2355, 1296, 395, 302, 9, 272, 327, 1104, 314, 730, 402, 909, 315, 314, 769, 272, 702, 63, 1452, 8, 6074, 8, 2355, 1296, 59, 16, 467, 2783, 395, 715, 9, 339, 327, 477, 29706, 63, 3612, 275, 1487, 29706, 8, 1960, 25, 12, 499, 12, 359, 969, 467, 3474, 8, 17, 12, 18, 395, 334, 1874, 566, 272, 327, 2196, 1296, 10039, 275, 477, 29706, 63, 3612, 14, 513, 63, 1618, 63, 2355, 63, 262, 63, 1494, 13957, 63, 80, 8, 78, 9, 272, 327, 477, 29706, 63, 3612, 14, 1361, 63, 513, 63, 1618, 63, 4097, 8, 2355, 1296, 10039, 12, 283, 396, 2196, 1296, 10039, 358, 272, 327, 702, 63, 1452, 8, 552, 8, 2355, 1296, 10039, 59, 16, 2522, 413, 9, 421, 199, 318, 511, 63, 20824, 63, 344, 837, 272, 477, 29706, 275, 1487, 29706, 8, 80, 3912, 12, 302, 63, 31790, 12, 308, 63, 16153, 12, 2879, 63, 13547, 9, 339, 1305, 63, 513, 275, 2863, 14, 20824, 63, 344, 8, 78, 63, 31790, 12, 477, 29706, 14, 2227, 63, 552, 12, 477, 29706, 14, 80, 9, 272, 327, 1104, 314, 2582, 402, 314, 769, 272, 702, 63, 1452, 8, 552, 8, 344, 63, 513, 395, 302, 63, 31790, 9, 272, 327, 1104, 314, 730, 402, 909, 315, 314, 769, 272, 702, 63, 1452, 8, 6074, 8, 344, 63, 513, 59, 16, 467, 2783, 395, 715, 9, 421, 199, 318, 511, 63, 609, 455, 723, 63, 22104, 63, 3357, 837, 272, 477, 29706, 275, 1487, 29706, 8, 80, 3912, 12, 302, 63, 31790, 12, 308, 63, 16153, 12, 2879, 63, 13547, 9, 272, 477, 29706, 14, 2732, 63, 923, 63, 22104, 63, 15958, 342, 272, 327, 4278, 29868, 272, 477, 29706, 14, 68, 59, 16, 1527, 16, 61, 275, 359, 2394, 779, 16, 88, 1717, 2522, 2783, 779, 16, 88, 1780, 12457, 339, 29868, 275, 477, 29706, 14, 362, 63, 68, 63, 22104, 63, 15958, 8, 16, 12, 378, 9, 272, 7565, 63, 585, 275, 477, 29706, 14, 83, 63, 16153, 59, 16, 61, 339, 574, 275, 2863, 14, 609, 455, 723, 63, 22104, 63, 3357, 8, 2394, 779, 16, 88, 614, 2522, 29868, 12, 6163, 7565, 63, 585, 12, 477, 29706, 14, 80, 9, 272, 702, 63, 1452, 8, 585, 12, 3144, 435, 308, 63, 16153, 59, 16, 566, 339, 574, 275, 2863, 14, 609, 455, 723, 63, 22104, 63, 3357, 8, 2394, 779, 16, 88, 996, 2522, 29868, 12, 6163, 7565, 63, 585, 12, 477, 29706, 14, 80, 9, 272, 702, 63, 1452, 8, 585, 12, 10448, 435, 308, 63, 16153, 59, 16, 566, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
gaddman/ansible
test/units/modules/network/netscaler/test_netscaler_servicegroup.py
68
23150
# Copyright (c) 2017 Citrix Systems # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # from units.compat.mock import patch, Mock, MagicMock, call import sys if sys.version_info[:2] != (2, 6): import requests from units.modules.utils import set_module_args from .netscaler_module import TestModule, nitro_base_patcher class TestNetscalerServicegroupModule(TestModule): @classmethod def setUpClass(cls): class MockException(Exception): pass cls.MockException = MockException m = MagicMock() cls.servicegroup_mock = MagicMock() cls.servicegroup_mock.__class__ = MagicMock() nssrc_modules_mock = { 'nssrc.com.citrix.netscaler.nitro.resource.config.basic': m, 'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup': m, 'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup.servicegroup': cls.servicegroup_mock, 'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup_servicegroupmember_binding': m, 'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup_servicegroupmember_binding.servicegroup_servicegroupmember_binding': m, 'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup_lbmonitor_binding': m, 'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup_lbmonitor_binding.servicegroup_lbmonitor_binding': m, 'nssrc.com.citrix.netscaler.nitro.resource.config.lb': m, 'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonitor_servicegroup_binding': m, 'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonitor_servicegroup_binding.lbmonitor_servicegroup_binding': m } cls.nitro_specific_patcher = patch.dict(sys.modules, nssrc_modules_mock) cls.nitro_base_patcher = nitro_base_patcher @classmethod def tearDownClass(cls): cls.nitro_base_patcher.stop() cls.nitro_specific_patcher.stop() def set_module_state(self, state): set_module_args(dict( nitro_user='user', nitro_pass='pass', nsip='192.0.2.1', state=state, )) def setUp(self): super(TestNetscalerServicegroupModule, self).setUp() self.nitro_base_patcher.start() self.nitro_specific_patcher.start() # Setup minimal required arguments to pass AnsibleModule argument parsing def tearDown(self): super(TestNetscalerServicegroupModule, self).tearDown() self.nitro_base_patcher.stop() self.nitro_specific_patcher.stop() def test_graceful_nitro_api_import_error(self): # Stop nitro api patching to cause ImportError self.set_module_state('present') self.nitro_base_patcher.stop() self.nitro_specific_patcher.stop() from ansible.modules.network.netscaler import netscaler_servicegroup self.module = netscaler_servicegroup result = self.failed() self.assertEqual(result['msg'], 'Could not load nitro python sdk') def test_graceful_nitro_error_on_login(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup class MockException(Exception): def __init__(self, *args, **kwargs): self.errorcode = 0 self.message = '' client_mock = Mock() client_mock.login = Mock(side_effect=MockException) m = Mock(return_value=client_mock) with patch('ansible.modules.network.netscaler.netscaler_servicegroup.get_nitro_client', m): with patch('ansible.modules.network.netscaler.netscaler_servicegroup.nitro_exception', MockException): self.module = netscaler_servicegroup result = self.failed() self.assertTrue(result['msg'].startswith('nitro exception'), msg='nitro exception during login not handled properly') def test_graceful_no_connection_error(self): if sys.version_info[:2] == (2, 6): self.skipTest('requests library not available under python2.6') self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup client_mock = Mock() attrs = {'login.side_effect': requests.exceptions.ConnectionError} client_mock.configure_mock(**attrs) m = Mock(return_value=client_mock) with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', get_nitro_client=m, nitro_exception=self.MockException, ): self.module = netscaler_servicegroup result = self.failed() self.assertTrue(result['msg'].startswith('Connection error'), msg='Connection error was not handled gracefully') def test_graceful_login_error(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup if sys.version_info[:2] == (2, 6): self.skipTest('requests library not available under python2.6') client_mock = Mock() attrs = {'login.side_effect': requests.exceptions.SSLError} client_mock.configure_mock(**attrs) m = Mock(return_value=client_mock) with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', get_nitro_client=m, nitro_exception=self.MockException, ): self.module = netscaler_servicegroup result = self.failed() self.assertTrue(result['msg'].startswith('SSL Error'), msg='SSL Error was not handled gracefully') def test_create_non_existing_servicegroup(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) servicegroup_exists_mock = Mock(side_effect=[False, True]) servicegroup_servicegroupmember_binding_mock = Mock(count=Mock(return_value=0)) with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=servicegroup_exists_mock, servicemembers_identical=Mock(side_effect=[False, True]), do_state_change=Mock(return_value=Mock(errorcode=0)), servicegroup_servicegroupmember_binding=servicegroup_servicegroupmember_binding_mock, nitro_exception=self.MockException, ): self.module = netscaler_servicegroup result = self.exited() servicegroup_proxy_mock.assert_has_calls([call.add()]) self.assertTrue(result['changed'], msg='Change not recorded') def test_update_servicegroup_when_servicegroup_differs(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) servicegroup_exists_mock = Mock(side_effect=[True, True]) servicegroup_identical_mock = Mock(side_effect=[False, True]) monitor_bindings_identical_mock = Mock(side_effect=[True, True]) with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=servicegroup_exists_mock, servicegroup_identical=servicegroup_identical_mock, monitor_bindings_identical=monitor_bindings_identical_mock, servicemembers_identical=Mock(side_effect=[True, True]), do_state_change=Mock(return_value=Mock(errorcode=0)), nitro_exception=self.MockException, ): self.module = netscaler_servicegroup result = self.exited() servicegroup_proxy_mock.assert_has_calls([call.update()]) self.assertTrue(result['changed'], msg='Change not recorded') def test_update_servicegroup_when_monitor_bindings_differ(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) servicegroup_exists_mock = Mock(side_effect=[True, True]) servicegroup_identical_mock = Mock(side_effect=[True, True]) monitor_bindings_identical_mock = Mock(side_effect=[False, True]) sync_monitor_bindings_mock = Mock() with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=servicegroup_exists_mock, servicegroup_identical=servicegroup_identical_mock, monitor_bindings_identical=monitor_bindings_identical_mock, nitro_exception=self.MockException, servicemembers_identical=Mock(side_effect=[True, True]), sync_monitor_bindings=sync_monitor_bindings_mock, do_state_change=Mock(return_value=Mock(errorcode=0)), ): self.module = netscaler_servicegroup result = self.exited() # poor man's assert_called_once since python3.5 does not implement that mock method self.assertEqual(len(sync_monitor_bindings_mock.mock_calls), 1, msg='sync monitor bindings not called once') self.assertTrue(result['changed'], msg='Change not recorded') def test_update_servicegroup_when_service_members_differ(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) sync_mock = Mock() with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=Mock(side_effect=[True, True]), servicegroup_identical=Mock(side_effect=[True, True]), monitor_bindings_identical=Mock(side_effect=[True, True]), sync_monitor_bindings=Mock(), servicemembers_identical=Mock(side_effect=[False, True]), sync_service_members=sync_mock, do_state_change=Mock(return_value=Mock(errorcode=0)), ): self.module = netscaler_servicegroup result = self.exited() # poor man's assert_called_once since python3.5 does not implement that mock method self.assertEqual(len(sync_mock.mock_calls), 1, msg='sync monitor bindings not called once') self.assertTrue(result['changed'], msg='Change not recorded') def test_immutables_changed(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=Mock(side_effect=[True, True]), servicegroup_identical=Mock(side_effect=[False, True]), get_immutables_intersection=Mock(return_value=['some']), nitro_exception=self.MockException, ): self.module = netscaler_servicegroup result = self.failed() self.assertTrue(result['msg'].startswith('Cannot update immutable attributes')) def test_servicegroup_exists_sanity(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) sync_mock = Mock() with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=Mock(side_effect=[False, False]), servicegroup_identical=Mock(side_effect=[False, False]), monitor_bindings_identical=Mock(side_effect=[True, True]), sync_monitor_bindings=Mock(), servicemembers_identical=Mock(side_effect=[False, True]), nitro_exception=self.MockException, sync_service_members=sync_mock, do_state_change=Mock(return_value=Mock(errorcode=0)), ): self.module = netscaler_servicegroup result = self.failed() self.assertEqual(result['msg'], 'Service group is not present') def test_servicegroup_differ_sanity(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) sync_mock = Mock() with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=Mock(side_effect=[True, True]), servicegroup_identical=Mock(side_effect=[False, False]), monitor_bindings_identical=Mock(side_effect=[True, True]), sync_monitor_bindings=Mock(), servicemembers_identical=Mock(side_effect=[False, True]), nitro_exception=self.MockException, sync_service_members=sync_mock, do_state_change=Mock(return_value=Mock(errorcode=0)), ): self.module = netscaler_servicegroup result = self.failed() self.assertEqual(result['msg'], 'Service group is not identical to configuration') def test_servicegroup_servicemembers_differ_sanity(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) sync_mock = Mock() with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=Mock(side_effect=[True, True]), servicegroup_identical=Mock(side_effect=[True, True]), monitor_bindings_identical=Mock(side_effect=[True, True]), sync_monitor_bindings=Mock(), servicemembers_identical=Mock(side_effect=[False, False]), nitro_exception=self.MockException, sync_service_members=sync_mock, do_state_change=Mock(return_value=Mock(errorcode=0)), ): self.module = netscaler_servicegroup result = self.failed() self.assertEqual(result['msg'], 'Service group members differ from configuration') def test_servicegroup_monitor_bindings_sanity(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) sync_mock = Mock() with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=Mock(side_effect=[True, True]), servicegroup_identical=Mock(side_effect=[True, True]), monitor_bindings_identical=Mock(side_effect=[False, False]), sync_monitor_bindings=Mock(), servicemembers_identical=Mock(side_effect=[True, True]), nitro_exception=self.MockException, sync_service_members=sync_mock, do_state_change=Mock(return_value=Mock(errorcode=0)), ): self.module = netscaler_servicegroup result = self.failed() self.assertEqual(result['msg'], 'Monitor bindings are not identical') def test_no_change_to_module_when_all_identical(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) servicegroup_exists_mock = Mock(side_effect=[True, True]) servicegroup_identical_mock = Mock(side_effect=[True, True]) monitor_bindings_identical_mock = Mock(side_effect=[True, True]) with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=servicegroup_exists_mock, servicegroup_identical=servicegroup_identical_mock, servicemembers_identical=Mock(side_effect=[True, True]), monitor_bindings_identical=monitor_bindings_identical_mock, do_state_change=Mock(return_value=Mock(errorcode=0)), nitro_exception=self.MockException, ): self.module = netscaler_servicegroup result = self.exited() self.assertFalse(result['changed'], msg='Erroneous changed status update') def test_absent_operation(self): self.set_module_state('absent') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) servicegroup_exists_mock = Mock(side_effect=[True, False]) with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=servicegroup_exists_mock, ): self.module = netscaler_servicegroup result = self.exited() servicegroup_proxy_mock.assert_has_calls([call.delete()]) self.assertTrue(result['changed'], msg='Changed status not set correctly') def test_absent_operation_no_change(self): self.set_module_state('absent') from ansible.modules.network.netscaler import netscaler_servicegroup servicegroup_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } servicegroup_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=servicegroup_proxy_mock) servicegroup_exists_mock = Mock(side_effect=[False, False]) with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=m, servicegroup_exists=servicegroup_exists_mock, ): self.module = netscaler_servicegroup result = self.exited() servicegroup_proxy_mock.assert_not_called() self.assertFalse(result['changed'], msg='Changed status not set correctly') def test_absent_operation_sanity(self): self.set_module_state('absent') from ansible.modules.network.netscaler import netscaler_servicegroup with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', ConfigProxy=MagicMock(), servicegroup_exists=Mock(side_effect=[True, True]), nitro_exception=self.MockException, ): self.module = netscaler_servicegroup result = self.failed() self.assertEqual(result['msg'], 'Service group is present') def test_graceful_nitro_exception_operation_present(self): self.set_module_state('present') from ansible.modules.network.netscaler import netscaler_servicegroup class MockException(Exception): def __init__(self, *args, **kwargs): self.errorcode = 0 self.message = '' m = Mock(side_effect=MockException) with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', servicegroup_exists=m, nitro_exception=MockException ): self.module = netscaler_servicegroup result = self.failed() self.assertTrue( result['msg'].startswith('nitro exception'), msg='Nitro exception not caught on operation present' ) def test_graceful_nitro_exception_operation_absent(self): self.set_module_state('absent') from ansible.modules.network.netscaler import netscaler_servicegroup class MockException(Exception): def __init__(self, *args, **kwargs): self.errorcode = 0 self.message = '' m = Mock(side_effect=MockException) with patch.multiple( 'ansible.modules.network.netscaler.netscaler_servicegroup', servicegroup_exists=m, nitro_exception=MockException ): self.module = netscaler_servicegroup result = self.failed() self.assertTrue( result['msg'].startswith('nitro exception'), msg='Nitro exception not caught on operation absent' )
gpl-3.0
[ 199, 3, 221, 1898, 334, 67, 9, 9708, 445, 390, 1904, 15285, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 199, 504, 6204, 14, 5819, 14, 1805, 492, 3371, 12, 4420, 12, 10079, 12, 1240, 199, 199, 646, 984, 199, 199, 692, 984, 14, 1023, 63, 815, 1491, 18, 61, 1137, 334, 18, 12, 1227, 304, 272, 492, 4145, 421, 199, 504, 6204, 14, 3112, 14, 1208, 492, 663, 63, 578, 63, 589, 199, 504, 1275, 18860, 63, 578, 492, 1379, 2377, 12, 20107, 63, 1095, 63, 11238, 421, 199, 533, 1379, 2480, 11494, 3167, 923, 2377, 8, 774, 2377, 304, 339, 768, 3744, 272, 347, 18561, 8, 1886, 304, 267, 1021, 4420, 1726, 8, 1726, 304, 288, 986, 267, 843, 14, 3346, 1726, 275, 4420, 1726, 267, 333, 275, 10079, 342, 267, 843, 14, 29409, 63, 1805, 275, 10079, 342, 267, 843, 14, 29409, 63, 1805, 855, 533, 363, 275, 10079, 342, 267, 302, 32231, 63, 3112, 63, 1805, 275, 469, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 14, 29409, 356, 843, 14, 29409, 63, 1805, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 63, 29409, 1114, 63, 9140, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 63, 29409, 1114, 63, 9140, 14, 29409, 63, 29409, 1114, 63, 9140, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 63, 6374, 7157, 63, 9140, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 63, 6374, 7157, 63, 9140, 14, 29409, 63, 6374, 7157, 63, 9140, 356, 333, 12, 953, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 6374, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 6374, 14, 6374, 7157, 63, 29409, 63, 9140, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 6374, 14, 6374, 7157, 63, 29409, 63, 9140, 14, 6374, 7157, 63, 29409, 63, 9140, 356, 333, 267, 789, 398, 843, 14, 18893, 63, 6100, 63, 11238, 275, 3371, 14, 807, 8, 1274, 14, 3112, 12, 302, 32231, 63, 3112, 63, 1805, 9, 267, 843, 14, 18893, 63, 1095, 63, 11238, 275, 20107, 63, 1095, 63, 11238, 339, 768, 3744, 272, 347, 24468, 8, 1886, 304, 267, 843, 14, 18893, 63, 1095, 63, 11238, 14, 2379, 342, 267, 843, 14, 18893, 63, 6100, 63, 11238, 14, 2379, 342, 339, 347, 663, 63, 578, 63, 929, 8, 277, 12, 1174, 304, 267, 663, 63, 578, 63, 589, 8, 807, 8, 288, 20107, 63, 751, 534, 751, 297, 288, 20107, 63, 1529, 534, 1529, 297, 288, 302, 17839, 534, 5756, 14, 16, 14, 18, 14, 17, 297, 288, 1174, 29, 929, 12, 267, 5082, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 774, 2480, 11494, 3167, 923, 2377, 12, 291, 680, 5996, 342, 267, 291, 14, 18893, 63, 1095, 63, 11238, 14, 928, 342, 267, 291, 14, 18893, 63, 6100, 63, 11238, 14, 928, 342, 398, 327, 12439, 13460, 1415, 2368, 370, 986, 6953, 1423, 6057, 339, 347, 6766, 8, 277, 304, 267, 1613, 8, 774, 2480, 11494, 3167, 923, 2377, 12, 291, 680, 12336, 342, 267, 291, 14, 18893, 63, 1095, 63, 11238, 14, 2379, 342, 267, 291, 14, 18893, 63, 6100, 63, 11238, 14, 2379, 342, 339, 347, 511, 63, 20631, 1893, 63, 18893, 63, 1246, 63, 646, 63, 705, 8, 277, 304, 267, 327, 8015, 20107, 2986, 3371, 316, 370, 7675, 3545, 267, 291, 14, 409, 63, 578, 63, 929, 360, 1881, 358, 267, 291, 14, 18893, 63, 1095, 63, 11238, 14, 2379, 342, 267, 291, 14, 18893, 63, 6100, 63, 11238, 14, 2379, 342, 267, 687, 3242, 14, 3112, 14, 1200, 14, 18860, 492, 26067, 63, 29409, 267, 291, 14, 578, 275, 26067, 63, 29409, 267, 754, 275, 291, 14, 4892, 342, 267, 291, 14, 629, 8, 1099, 459, 1328, 995, 283, 6531, 440, 2248, 20107, 2366, 13628, 358, 339, 347, 511, 63, 20631, 1893, 63, 18893, 63, 705, 63, 265, 63, 2886, 8, 277, 304, 267, 291, 14, 409, 63, 578, 63, 929, 360, 1881, 358, 267, 687, 3242, 14, 3112, 14, 1200, 14, 18860, 492, 26067, 63, 29409, 398, 1021, 4420, 1726, 8, 1726, 304, 288, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 355, 291, 14, 28857, 275, 378, 355, 291, 14, 1188, 275, 2125, 398, 1890, 63, 1805, 275, 4420, 342, 267, 1890, 63, 1805, 14, 2886, 275, 4420, 8, 2441, 63, 5881 ]
[ 3, 221, 1898, 334, 67, 9, 9708, 445, 390, 1904, 15285, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 199, 504, 6204, 14, 5819, 14, 1805, 492, 3371, 12, 4420, 12, 10079, 12, 1240, 199, 199, 646, 984, 199, 199, 692, 984, 14, 1023, 63, 815, 1491, 18, 61, 1137, 334, 18, 12, 1227, 304, 272, 492, 4145, 421, 199, 504, 6204, 14, 3112, 14, 1208, 492, 663, 63, 578, 63, 589, 199, 504, 1275, 18860, 63, 578, 492, 1379, 2377, 12, 20107, 63, 1095, 63, 11238, 421, 199, 533, 1379, 2480, 11494, 3167, 923, 2377, 8, 774, 2377, 304, 339, 768, 3744, 272, 347, 18561, 8, 1886, 304, 267, 1021, 4420, 1726, 8, 1726, 304, 288, 986, 267, 843, 14, 3346, 1726, 275, 4420, 1726, 267, 333, 275, 10079, 342, 267, 843, 14, 29409, 63, 1805, 275, 10079, 342, 267, 843, 14, 29409, 63, 1805, 855, 533, 363, 275, 10079, 342, 267, 302, 32231, 63, 3112, 63, 1805, 275, 469, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 14, 29409, 356, 843, 14, 29409, 63, 1805, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 63, 29409, 1114, 63, 9140, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 63, 29409, 1114, 63, 9140, 14, 29409, 63, 29409, 1114, 63, 9140, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 63, 6374, 7157, 63, 9140, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 4316, 14, 29409, 63, 6374, 7157, 63, 9140, 14, 29409, 63, 6374, 7157, 63, 9140, 356, 333, 12, 953, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 6374, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 6374, 14, 6374, 7157, 63, 29409, 63, 9140, 356, 333, 12, 288, 283, 78, 32231, 14, 957, 14, 14422, 1904, 14, 18860, 14, 18893, 14, 1927, 14, 888, 14, 6374, 14, 6374, 7157, 63, 29409, 63, 9140, 14, 6374, 7157, 63, 29409, 63, 9140, 356, 333, 267, 789, 398, 843, 14, 18893, 63, 6100, 63, 11238, 275, 3371, 14, 807, 8, 1274, 14, 3112, 12, 302, 32231, 63, 3112, 63, 1805, 9, 267, 843, 14, 18893, 63, 1095, 63, 11238, 275, 20107, 63, 1095, 63, 11238, 339, 768, 3744, 272, 347, 24468, 8, 1886, 304, 267, 843, 14, 18893, 63, 1095, 63, 11238, 14, 2379, 342, 267, 843, 14, 18893, 63, 6100, 63, 11238, 14, 2379, 342, 339, 347, 663, 63, 578, 63, 929, 8, 277, 12, 1174, 304, 267, 663, 63, 578, 63, 589, 8, 807, 8, 288, 20107, 63, 751, 534, 751, 297, 288, 20107, 63, 1529, 534, 1529, 297, 288, 302, 17839, 534, 5756, 14, 16, 14, 18, 14, 17, 297, 288, 1174, 29, 929, 12, 267, 5082, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 774, 2480, 11494, 3167, 923, 2377, 12, 291, 680, 5996, 342, 267, 291, 14, 18893, 63, 1095, 63, 11238, 14, 928, 342, 267, 291, 14, 18893, 63, 6100, 63, 11238, 14, 928, 342, 398, 327, 12439, 13460, 1415, 2368, 370, 986, 6953, 1423, 6057, 339, 347, 6766, 8, 277, 304, 267, 1613, 8, 774, 2480, 11494, 3167, 923, 2377, 12, 291, 680, 12336, 342, 267, 291, 14, 18893, 63, 1095, 63, 11238, 14, 2379, 342, 267, 291, 14, 18893, 63, 6100, 63, 11238, 14, 2379, 342, 339, 347, 511, 63, 20631, 1893, 63, 18893, 63, 1246, 63, 646, 63, 705, 8, 277, 304, 267, 327, 8015, 20107, 2986, 3371, 316, 370, 7675, 3545, 267, 291, 14, 409, 63, 578, 63, 929, 360, 1881, 358, 267, 291, 14, 18893, 63, 1095, 63, 11238, 14, 2379, 342, 267, 291, 14, 18893, 63, 6100, 63, 11238, 14, 2379, 342, 267, 687, 3242, 14, 3112, 14, 1200, 14, 18860, 492, 26067, 63, 29409, 267, 291, 14, 578, 275, 26067, 63, 29409, 267, 754, 275, 291, 14, 4892, 342, 267, 291, 14, 629, 8, 1099, 459, 1328, 995, 283, 6531, 440, 2248, 20107, 2366, 13628, 358, 339, 347, 511, 63, 20631, 1893, 63, 18893, 63, 705, 63, 265, 63, 2886, 8, 277, 304, 267, 291, 14, 409, 63, 578, 63, 929, 360, 1881, 358, 267, 687, 3242, 14, 3112, 14, 1200, 14, 18860, 492, 26067, 63, 29409, 398, 1021, 4420, 1726, 8, 1726,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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
cloudera/hue
desktop/core/ext-py/amqp-2.4.1/amqp/platform.py
3
2484
"""Platform compatibility.""" from __future__ import absolute_import, unicode_literals import platform import re import struct import sys # Jython does not have this attribute try: from socket import SOL_TCP except ImportError: # pragma: no cover from socket import IPPROTO_TCP as SOL_TCP # noqa RE_NUM = re.compile(r'(\d+).+') def _linux_version_to_tuple(s): # type: (str) -> Tuple[int, int, int] return tuple(map(_versionatom, s.split('.')[:3])) def _versionatom(s): # type: (str) -> int if s.isdigit(): return int(s) match = RE_NUM.match(s) return int(match.groups()[0]) if match else 0 # available socket options for TCP level KNOWN_TCP_OPTS = { 'TCP_CORK', 'TCP_DEFER_ACCEPT', 'TCP_KEEPCNT', 'TCP_KEEPIDLE', 'TCP_KEEPINTVL', 'TCP_LINGER2', 'TCP_MAXSEG', 'TCP_NODELAY', 'TCP_QUICKACK', 'TCP_SYNCNT', 'TCP_USER_TIMEOUT', 'TCP_WINDOW_CLAMP', } LINUX_VERSION = None if sys.platform.startswith('linux'): LINUX_VERSION = _linux_version_to_tuple(platform.release()) if LINUX_VERSION < (2, 6, 37): KNOWN_TCP_OPTS.remove('TCP_USER_TIMEOUT') # Windows Subsystem for Linux is an edge-case: the Python socket library # returns most TCP_* enums, but they aren't actually supported if platform.release().endswith("Microsoft"): KNOWN_TCP_OPTS = {'TCP_NODELAY', 'TCP_KEEPIDLE', 'TCP_KEEPINTVL', 'TCP_KEEPCNT'} elif sys.platform.startswith('darwin'): KNOWN_TCP_OPTS.remove('TCP_USER_TIMEOUT') elif 'bsd' in sys.platform: KNOWN_TCP_OPTS.remove('TCP_USER_TIMEOUT') # According to MSDN Windows platforms support getsockopt(TCP_MAXSSEG) but not # setsockopt(TCP_MAXSEG) on IPPROTO_TCP sockets. elif sys.platform.startswith('win'): KNOWN_TCP_OPTS = {'TCP_NODELAY'} if sys.version_info < (2, 7, 7): # pragma: no cover import functools def _to_bytes_arg(fun): @functools.wraps(fun) def _inner(s, *args, **kwargs): return fun(s.encode(), *args, **kwargs) return _inner pack = _to_bytes_arg(struct.pack) pack_into = _to_bytes_arg(struct.pack_into) unpack = _to_bytes_arg(struct.unpack) unpack_from = _to_bytes_arg(struct.unpack_from) else: pack = struct.pack pack_into = struct.pack_into unpack = struct.unpack unpack_from = struct.unpack_from __all__ = [ 'LINUX_VERSION', 'SOL_TCP', 'KNOWN_TCP_OPTS', 'pack', 'pack_into', 'unpack', 'unpack_from', ]
apache-2.0
[ 624, 10397, 7163, 1041, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 2649, 63, 5955, 199, 199, 646, 4298, 199, 646, 295, 199, 646, 2702, 199, 646, 984, 199, 199, 3, 25333, 1630, 440, 1172, 642, 2225, 199, 893, 26, 272, 687, 2838, 492, 17524, 63, 9735, 199, 2590, 3545, 26, 221, 327, 11942, 26, 949, 8486, 272, 687, 2838, 492, 3531, 7459, 63, 9735, 465, 17524, 63, 9735, 221, 327, 8151, 421, 199, 907, 63, 7125, 275, 295, 14, 2014, 8, 82, 13445, 68, 11, 680, 13854, 421, 199, 318, 485, 5135, 63, 1023, 63, 475, 63, 2960, 8, 83, 304, 272, 327, 730, 26, 334, 495, 9, 1035, 11634, 59, 442, 12, 1109, 12, 1109, 61, 272, 372, 2008, 8, 1130, 1547, 1023, 4188, 12, 308, 14, 1294, 7563, 1491, 19, 2459, 421, 199, 318, 485, 1023, 4188, 8, 83, 304, 272, 327, 730, 26, 334, 495, 9, 1035, 1109, 272, 340, 308, 14, 13896, 837, 267, 372, 1109, 8, 83, 9, 272, 1336, 275, 5363, 63, 7125, 14, 1431, 8, 83, 9, 272, 372, 1109, 8, 1431, 14, 2634, 3430, 16, 566, 340, 1336, 587, 378, 421, 199, 3, 2808, 2838, 1511, 367, 13488, 2166, 199, 20004, 63, 9735, 63, 25636, 275, 469, 272, 283, 9735, 63, 18650, 43, 297, 283, 9735, 63, 5638, 540, 63, 13089, 297, 283, 9735, 63, 2430, 37, 4222, 12460, 297, 272, 283, 9735, 63, 32162, 23715, 297, 283, 9735, 63, 32162, 2919, 32458, 297, 283, 9735, 63, 44, 1206, 540, 18, 297, 272, 283, 9735, 63, 4283, 21981, 297, 283, 9735, 63, 2826, 18616, 297, 283, 9735, 63, 2328, 13884, 3099, 297, 272, 283, 9735, 63, 22012, 12460, 297, 283, 9735, 63, 3791, 63, 8899, 297, 283, 9735, 63, 15480, 63, 1981, 7089, 297, 199, 93, 199, 199, 26030, 63, 4612, 275, 488, 199, 692, 984, 14, 3246, 14, 2460, 360, 5135, 735, 272, 491, 568, 14272, 63, 4612, 275, 485, 5135, 63, 1023, 63, 475, 63, 2960, 8, 3246, 14, 3221, 1012, 272, 340, 491, 568, 14272, 63, 4612, 665, 334, 18, 12, 1227, 12, 6877, 304, 267, 1804, 9165, 63, 9735, 63, 25636, 14, 2168, 360, 9735, 63, 3791, 63, 8899, 358, 339, 327, 5417, 4804, 2253, 367, 10130, 365, 376, 6275, 13, 2546, 26, 314, 2018, 2838, 3555, 272, 327, 2529, 4750, 13488, 15192, 28441, 12, 1325, 2985, 10621, 1133, 5965, 3748, 272, 340, 4298, 14, 3221, 1252, 4130, 480, 12940, 2349, 267, 1804, 9165, 63, 9735, 63, 25636, 275, 791, 9735, 63, 2826, 18616, 297, 283, 9735, 63, 32162, 23715, 297, 283, 9735, 63, 32162, 2919, 32458, 297, 2079, 283, 9735, 63, 2430, 37, 4222, 12460, 936, 199, 4164, 984, 14, 3246, 14, 2460, 360, 13245, 735, 272, 1804, 9165, 63, 9735, 63, 25636, 14, 2168, 360, 9735, 63, 3791, 63, 8899, 358, 199, 199, 4164, 283, 15746, 7, 315, 984, 14, 3246, 26, 272, 1804, 9165, 63, 9735, 63, 25636, 14, 2168, 360, 9735, 63, 3791, 63, 8899, 358, 199, 199, 3, 31970, 370, 603, 3693, 46, 5417, 10677, 2291, 664, 5096, 2992, 8, 9735, 63, 4283, 51, 21981, 9, 1325, 440, 199, 3, 663, 5096, 2992, 8, 9735, 63, 4283, 21981, 9, 641, 3531, 7459, 63, 9735, 18772, 14, 199, 4164, 984, 14, 3246, 14, 2460, 360, 2676, 735, 272, 1804, 9165, 63, 9735, 63, 25636, 275, 791, 9735, 63, 2826, 18616, 936, 199, 199, 692, 984, 14, 1023, 63, 815, 665, 334, 18, 12, 1520, 12, 1520, 304, 221, 327, 11942, 26, 949, 8486, 272, 492, 9143, 339, 347, 485, 475, 63, 2394, 63, 1273, 8, 7036, 304, 267, 768, 17869, 14, 13582, 8, 7036, 9, 267, 347, 485, 5216, 8, 83, 12, 627, 589, 12, 1011, 958, 304, 288, 372, 9627, 8, 83, 14, 2143, 1062, 627, 589, 12, 1011, 958, 9, 267, 372, 485, 5216, 339, 1706, 275, 485, 475, 63, 2394, 63, 1273, 8, 1820, 14, 1389, 9, 272, 1706, 63, 9924, 275, 485, 475, 63, 2394, 63, 1273, 8, 1820, 14, 1389, 63, 9924, 9, 272, 7787, 275, 485, 475, 63, 2394, 63, 1273, 8, 1820, 14, 5301, 9, 272, 7787, 63, 504, 275, 485, 475, 63, 2394, 63, 1273, 8, 1820, 14, 5301, 63, 504, 9, 199, 2836, 26, 272, 1706, 275, 2702, 14, 1389, 272, 1706, 63, 9924, 275, 2702, 14, 1389, 63, 9924, 272, 7787, 275, 2702, 14, 5301, 272, 7787, 63, 504, 275, 2702, 14, 5301, 63, 504, 199, 199, 363, 452, 363, 275, 359, 272, 283, 26030, 63, 4612, 297, 272, 283, 15096, 63, 9735, 297, 272, 283, 20004, 63, 9735, 63, 25636, 297, 272, 283, 1389, 297, 272, 283, 1389, 63, 9924, 297, 272, 283, 5301, 297, 272, 283, 5301, 63, 504, 297, 199, 61, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 10397, 7163, 1041, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 2649, 63, 5955, 199, 199, 646, 4298, 199, 646, 295, 199, 646, 2702, 199, 646, 984, 199, 199, 3, 25333, 1630, 440, 1172, 642, 2225, 199, 893, 26, 272, 687, 2838, 492, 17524, 63, 9735, 199, 2590, 3545, 26, 221, 327, 11942, 26, 949, 8486, 272, 687, 2838, 492, 3531, 7459, 63, 9735, 465, 17524, 63, 9735, 221, 327, 8151, 421, 199, 907, 63, 7125, 275, 295, 14, 2014, 8, 82, 13445, 68, 11, 680, 13854, 421, 199, 318, 485, 5135, 63, 1023, 63, 475, 63, 2960, 8, 83, 304, 272, 327, 730, 26, 334, 495, 9, 1035, 11634, 59, 442, 12, 1109, 12, 1109, 61, 272, 372, 2008, 8, 1130, 1547, 1023, 4188, 12, 308, 14, 1294, 7563, 1491, 19, 2459, 421, 199, 318, 485, 1023, 4188, 8, 83, 304, 272, 327, 730, 26, 334, 495, 9, 1035, 1109, 272, 340, 308, 14, 13896, 837, 267, 372, 1109, 8, 83, 9, 272, 1336, 275, 5363, 63, 7125, 14, 1431, 8, 83, 9, 272, 372, 1109, 8, 1431, 14, 2634, 3430, 16, 566, 340, 1336, 587, 378, 421, 199, 3, 2808, 2838, 1511, 367, 13488, 2166, 199, 20004, 63, 9735, 63, 25636, 275, 469, 272, 283, 9735, 63, 18650, 43, 297, 283, 9735, 63, 5638, 540, 63, 13089, 297, 283, 9735, 63, 2430, 37, 4222, 12460, 297, 272, 283, 9735, 63, 32162, 23715, 297, 283, 9735, 63, 32162, 2919, 32458, 297, 283, 9735, 63, 44, 1206, 540, 18, 297, 272, 283, 9735, 63, 4283, 21981, 297, 283, 9735, 63, 2826, 18616, 297, 283, 9735, 63, 2328, 13884, 3099, 297, 272, 283, 9735, 63, 22012, 12460, 297, 283, 9735, 63, 3791, 63, 8899, 297, 283, 9735, 63, 15480, 63, 1981, 7089, 297, 199, 93, 199, 199, 26030, 63, 4612, 275, 488, 199, 692, 984, 14, 3246, 14, 2460, 360, 5135, 735, 272, 491, 568, 14272, 63, 4612, 275, 485, 5135, 63, 1023, 63, 475, 63, 2960, 8, 3246, 14, 3221, 1012, 272, 340, 491, 568, 14272, 63, 4612, 665, 334, 18, 12, 1227, 12, 6877, 304, 267, 1804, 9165, 63, 9735, 63, 25636, 14, 2168, 360, 9735, 63, 3791, 63, 8899, 358, 339, 327, 5417, 4804, 2253, 367, 10130, 365, 376, 6275, 13, 2546, 26, 314, 2018, 2838, 3555, 272, 327, 2529, 4750, 13488, 15192, 28441, 12, 1325, 2985, 10621, 1133, 5965, 3748, 272, 340, 4298, 14, 3221, 1252, 4130, 480, 12940, 2349, 267, 1804, 9165, 63, 9735, 63, 25636, 275, 791, 9735, 63, 2826, 18616, 297, 283, 9735, 63, 32162, 23715, 297, 283, 9735, 63, 32162, 2919, 32458, 297, 2079, 283, 9735, 63, 2430, 37, 4222, 12460, 936, 199, 4164, 984, 14, 3246, 14, 2460, 360, 13245, 735, 272, 1804, 9165, 63, 9735, 63, 25636, 14, 2168, 360, 9735, 63, 3791, 63, 8899, 358, 199, 199, 4164, 283, 15746, 7, 315, 984, 14, 3246, 26, 272, 1804, 9165, 63, 9735, 63, 25636, 14, 2168, 360, 9735, 63, 3791, 63, 8899, 358, 199, 199, 3, 31970, 370, 603, 3693, 46, 5417, 10677, 2291, 664, 5096, 2992, 8, 9735, 63, 4283, 51, 21981, 9, 1325, 440, 199, 3, 663, 5096, 2992, 8, 9735, 63, 4283, 21981, 9, 641, 3531, 7459, 63, 9735, 18772, 14, 199, 4164, 984, 14, 3246, 14, 2460, 360, 2676, 735, 272, 1804, 9165, 63, 9735, 63, 25636, 275, 791, 9735, 63, 2826, 18616, 936, 199, 199, 692, 984, 14, 1023, 63, 815, 665, 334, 18, 12, 1520, 12, 1520, 304, 221, 327, 11942, 26, 949, 8486, 272, 492, 9143, 339, 347, 485, 475, 63, 2394, 63, 1273, 8, 7036, 304, 267, 768, 17869, 14, 13582, 8, 7036, 9, 267, 347, 485, 5216, 8, 83, 12, 627, 589, 12, 1011, 958, 304, 288, 372, 9627, 8, 83, 14, 2143, 1062, 627, 589, 12, 1011, 958, 9, 267, 372, 485, 5216, 339, 1706, 275, 485, 475, 63, 2394, 63, 1273, 8, 1820, 14, 1389, 9, 272, 1706, 63, 9924, 275, 485, 475, 63, 2394, 63, 1273, 8, 1820, 14, 1389, 63, 9924, 9, 272, 7787, 275, 485, 475, 63, 2394, 63, 1273, 8, 1820, 14, 5301, 9, 272, 7787, 63, 504, 275, 485, 475, 63, 2394, 63, 1273, 8, 1820, 14, 5301, 63, 504, 9, 199, 2836, 26, 272, 1706, 275, 2702, 14, 1389, 272, 1706, 63, 9924, 275, 2702, 14, 1389, 63, 9924, 272, 7787, 275, 2702, 14, 5301, 272, 7787, 63, 504, 275, 2702, 14, 5301, 63, 504, 199, 199, 363, 452, 363, 275, 359, 272, 283, 26030, 63, 4612, 297, 272, 283, 15096, 63, 9735, 297, 272, 283, 20004, 63, 9735, 63, 25636, 297, 272, 283, 1389, 297, 272, 283, 1389, 63, 9924, 297, 272, 283, 5301, 297, 272, 283, 5301, 63, 504, 297, 199, 61, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
ayepezv/GAD_ERP
addons/hw_escpos/escpos/exceptions.py
67
2868
""" ESC/POS Exceptions classes """ class Error(Exception): """ Base class for ESC/POS errors """ def __init__(self, msg, status=None): Exception.__init__(self) self.msg = msg self.resultcode = 1 if status is not None: self.resultcode = status def __str__(self): return self.msg # Result/Exit codes # 0 = success # 10 = No Barcode type defined # 20 = Barcode size values are out of range # 30 = Barcode text not supplied # 40 = Image height is too large # 50 = No string supplied to be printed # 60 = Invalid pin to send Cash Drawer pulse class BarcodeTypeError(Error): def __init__(self, msg=""): Error.__init__(self, msg) self.msg = msg self.resultcode = 10 def __str__(self): return "No Barcode type is defined" class BarcodeSizeError(Error): def __init__(self, msg=""): Error.__init__(self, msg) self.msg = msg self.resultcode = 20 def __str__(self): return "Barcode size is out of range" class BarcodeCodeError(Error): def __init__(self, msg=""): Error.__init__(self, msg) self.msg = msg self.resultcode = 30 def __str__(self): return "Code was not supplied" class ImageSizeError(Error): def __init__(self, msg=""): Error.__init__(self, msg) self.msg = msg self.resultcode = 40 def __str__(self): return "Image height is longer than 255px and can't be printed" class TextError(Error): def __init__(self, msg=""): Error.__init__(self, msg) self.msg = msg self.resultcode = 50 def __str__(self): return "Text string must be supplied to the text() method" class CashDrawerError(Error): def __init__(self, msg=""): Error.__init__(self, msg) self.msg = msg self.resultcode = 60 def __str__(self): return "Valid pin must be set to send pulse" class NoStatusError(Error): def __init__(self, msg=""): Error.__init__(self, msg) self.msg = msg self.resultcode = 70 def __str__(self): return "Impossible to get status from the printer: " + str(self.msg) class TicketNotPrinted(Error): def __init__(self, msg=""): Error.__init__(self, msg) self.msg = msg self.resultcode = 80 def __str__(self): return "A part of the ticket was not been printed: " + str(self.msg) class NoDeviceError(Error): def __init__(self, msg=""): Error.__init__(self, msg) self.msg = msg self.resultcode = 90 def __str__(self): return str(self.msg) class HandleDeviceError(Error): def __init__(self, msg=""): Error.__init__(self, msg) self.msg = msg self.resultcode = 100 def __str__(self): return str(self.msg)
gpl-3.0
[ 624, 10427, 35, 15, 9263, 24873, 3992, 408, 421, 199, 533, 4520, 8, 1726, 304, 272, 408, 3523, 1021, 367, 10427, 35, 15, 9263, 2552, 408, 272, 347, 636, 826, 721, 277, 12, 1499, 12, 2004, 29, 403, 304, 267, 2186, 855, 826, 721, 277, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 413, 267, 340, 2004, 365, 440, 488, 26, 288, 291, 14, 1099, 600, 275, 2004, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 1328, 199, 199, 3, 10695, 15, 6699, 9479, 199, 3, 378, 221, 275, 3182, 199, 3, 1616, 275, 3091, 12377, 600, 730, 3247, 199, 3, 3388, 275, 12377, 600, 1568, 1338, 787, 734, 402, 1425, 199, 3, 4233, 275, 12377, 600, 1318, 440, 6841, 199, 3, 6335, 275, 6047, 4569, 365, 4634, 7031, 199, 3, 5238, 275, 3091, 1059, 6841, 370, 506, 12487, 199, 3, 5212, 275, 6378, 10713, 370, 3222, 445, 1119, 17813, 281, 27949, 421, 199, 533, 12377, 600, 4333, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 1616, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 1944, 12377, 600, 730, 365, 3247, 2, 199, 199, 533, 12377, 600, 2320, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 3388, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 5281, 600, 1568, 365, 734, 402, 1425, 2, 199, 199, 533, 12377, 600, 3034, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 4233, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 3034, 1990, 440, 6841, 2, 199, 199, 533, 6047, 2320, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 6335, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 3491, 4569, 365, 8088, 2419, 5450, 5326, 436, 883, 1133, 506, 12487, 2, 199, 199, 533, 4516, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 5238, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 1872, 1059, 1471, 506, 6841, 370, 314, 1318, 342, 1083, 2, 421, 199, 533, 445, 1119, 9654, 281, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 5212, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 3490, 10713, 1471, 506, 663, 370, 3222, 27949, 2, 199, 199, 533, 3091, 3694, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 10045, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 8499, 12716, 370, 664, 2004, 687, 314, 16639, 26, 298, 435, 620, 8, 277, 14, 1328, 9, 199, 199, 533, 21932, 1763, 9779, 9082, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 5939, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 33, 1777, 402, 314, 12052, 1990, 440, 2757, 12487, 26, 298, 435, 620, 8, 277, 14, 1328, 9, 199, 199, 533, 3091, 2510, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 9137, 339, 347, 636, 495, 721, 277, 304, 267, 372, 620, 8, 277, 14, 1328, 9, 199, 199, 533, 8690, 2510, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 2948, 339, 347, 636, 495, 721, 277, 304, 267, 372, 620, 8, 277, 14, 1328, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 10427, 35, 15, 9263, 24873, 3992, 408, 421, 199, 533, 4520, 8, 1726, 304, 272, 408, 3523, 1021, 367, 10427, 35, 15, 9263, 2552, 408, 272, 347, 636, 826, 721, 277, 12, 1499, 12, 2004, 29, 403, 304, 267, 2186, 855, 826, 721, 277, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 413, 267, 340, 2004, 365, 440, 488, 26, 288, 291, 14, 1099, 600, 275, 2004, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 1328, 199, 199, 3, 10695, 15, 6699, 9479, 199, 3, 378, 221, 275, 3182, 199, 3, 1616, 275, 3091, 12377, 600, 730, 3247, 199, 3, 3388, 275, 12377, 600, 1568, 1338, 787, 734, 402, 1425, 199, 3, 4233, 275, 12377, 600, 1318, 440, 6841, 199, 3, 6335, 275, 6047, 4569, 365, 4634, 7031, 199, 3, 5238, 275, 3091, 1059, 6841, 370, 506, 12487, 199, 3, 5212, 275, 6378, 10713, 370, 3222, 445, 1119, 17813, 281, 27949, 421, 199, 533, 12377, 600, 4333, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 1616, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 1944, 12377, 600, 730, 365, 3247, 2, 199, 199, 533, 12377, 600, 2320, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 3388, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 5281, 600, 1568, 365, 734, 402, 1425, 2, 199, 199, 533, 12377, 600, 3034, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 4233, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 3034, 1990, 440, 6841, 2, 199, 199, 533, 6047, 2320, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 6335, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 3491, 4569, 365, 8088, 2419, 5450, 5326, 436, 883, 1133, 506, 12487, 2, 199, 199, 533, 4516, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 5238, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 1872, 1059, 1471, 506, 6841, 370, 314, 1318, 342, 1083, 2, 421, 199, 533, 445, 1119, 9654, 281, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 5212, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 3490, 10713, 1471, 506, 663, 370, 3222, 27949, 2, 199, 199, 533, 3091, 3694, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 10045, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 8499, 12716, 370, 664, 2004, 687, 314, 16639, 26, 298, 435, 620, 8, 277, 14, 1328, 9, 199, 199, 533, 21932, 1763, 9779, 9082, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 5939, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 33, 1777, 402, 314, 12052, 1990, 440, 2757, 12487, 26, 298, 435, 620, 8, 277, 14, 1328, 9, 199, 199, 533, 3091, 2510, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 9137, 339, 347, 636, 495, 721, 277, 304, 267, 372, 620, 8, 277, 14, 1328, 9, 199, 199, 533, 8690, 2510, 547, 8, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 17364, 267, 4520, 855, 826, 721, 277, 12, 1499, 9, 267, 291, 14, 1328, 275, 1499, 267, 291, 14, 1099, 600, 275, 2948, 339, 347, 636, 495, 721, 277, 304, 267, 372, 620, 8, 277, 14, 1328, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
unnikrishnankgs/va
venv/lib/python3.5/site-packages/nbformat/v3/tests/formattest.py
28
1496
# -*- coding: utf8 -*- import io import os import shutil import tempfile pjoin = os.path.join from ..nbbase import ( NotebookNode, new_code_cell, new_text_cell, new_worksheet, new_notebook ) from ..nbpy import reads, writes, read, write from .nbexamples import nb0, nb0_py def open_utf8(fname, mode): return io.open(fname, mode=mode, encoding='utf-8') class NBFormatTest: """Mixin for writing notebook format tests""" # override with appropriate values in subclasses nb0_ref = None ext = None mod = None def setUp(self): self.wd = tempfile.mkdtemp() def tearDown(self): shutil.rmtree(self.wd) def assertNBEquals(self, nba, nbb): self.assertEqual(nba, nbb) def test_writes(self): s = self.mod.writes(nb0) if self.nb0_ref: self.assertEqual(s, self.nb0_ref) def test_reads(self): s = self.mod.writes(nb0) nb = self.mod.reads(s) def test_roundtrip(self): s = self.mod.writes(nb0) self.assertNBEquals(self.mod.reads(s),nb0) def test_write_file(self): with open_utf8(pjoin(self.wd, "nb0.%s" % self.ext), 'w') as f: self.mod.write(nb0, f) def test_read_file(self): with open_utf8(pjoin(self.wd, "nb0.%s" % self.ext), 'w') as f: self.mod.write(nb0, f) with open_utf8(pjoin(self.wd, "nb0.%s" % self.ext), 'r') as f: nb = self.mod.read(f)
bsd-2-clause
[ 3, 1882, 2803, 26, 2774, 24, 1882, 199, 646, 5890, 199, 646, 747, 199, 646, 5145, 199, 646, 5549, 199, 199, 80, 904, 275, 747, 14, 515, 14, 904, 199, 199, 504, 2508, 4994, 1095, 492, 334, 272, 3390, 2706, 1716, 12, 272, 892, 63, 600, 63, 3890, 12, 892, 63, 505, 63, 3890, 12, 892, 63, 29776, 12, 892, 63, 19174, 199, 9, 199, 199, 504, 2508, 4994, 647, 492, 11597, 12, 14511, 12, 1586, 12, 2218, 199, 504, 1275, 4994, 8589, 492, 8526, 16, 12, 8526, 16, 63, 647, 421, 199, 318, 1551, 63, 1624, 24, 8, 5252, 12, 818, 304, 272, 372, 5890, 14, 1490, 8, 5252, 12, 818, 29, 632, 12, 2644, 534, 1624, 13, 24, 358, 199, 199, 533, 25377, 3484, 774, 26, 272, 408, 4256, 367, 3575, 20751, 1475, 2295, 624, 339, 327, 4278, 543, 5827, 1338, 315, 9180, 272, 8526, 16, 63, 1121, 275, 488, 272, 1599, 275, 488, 272, 3413, 275, 488, 2286, 347, 3613, 8, 277, 304, 267, 291, 14, 2989, 275, 5549, 14, 11983, 342, 2286, 347, 6766, 8, 277, 304, 267, 5145, 14, 9242, 8, 277, 14, 2989, 9, 2286, 347, 702, 16170, 13317, 8, 277, 12, 302, 2470, 12, 302, 2501, 304, 267, 291, 14, 629, 8, 78, 2470, 12, 302, 2501, 9, 5493, 347, 511, 63, 16334, 8, 277, 304, 267, 308, 275, 291, 14, 1494, 14, 16334, 8, 4994, 16, 9, 267, 340, 291, 14, 4994, 16, 63, 1121, 26, 288, 291, 14, 629, 8, 83, 12, 291, 14, 4994, 16, 63, 1121, 9, 339, 347, 511, 63, 15656, 8, 277, 304, 267, 308, 275, 291, 14, 1494, 14, 16334, 8, 4994, 16, 9, 267, 8526, 275, 291, 14, 1494, 14, 15656, 8, 83, 9, 339, 347, 511, 63, 25920, 8, 277, 304, 267, 308, 275, 291, 14, 1494, 14, 16334, 8, 4994, 16, 9, 267, 291, 14, 479, 16170, 13317, 8, 277, 14, 1494, 14, 15656, 8, 83, 395, 4994, 16, 9, 339, 347, 511, 63, 952, 63, 493, 8, 277, 304, 267, 543, 1551, 63, 1624, 24, 8, 80, 904, 8, 277, 14, 2989, 12, 298, 4994, 16, 4111, 83, 2, 450, 291, 14, 832, 395, 283, 87, 358, 465, 289, 26, 288, 291, 14, 1494, 14, 952, 8, 4994, 16, 12, 289, 9, 2286, 347, 511, 63, 739, 63, 493, 8, 277, 304, 267, 543, 1551, 63, 1624, 24, 8, 80, 904, 8, 277, 14, 2989, 12, 298, 4994, 16, 4111, 83, 2, 450, 291, 14, 832, 395, 283, 87, 358, 465, 289, 26, 288, 291, 14, 1494, 14, 952, 8, 4994, 16, 12, 289, 9, 2728, 543, 1551, 63, 1624, 24, 8, 80, 904, 8, 277, 14, 2989, 12, 298, 4994, 16, 4111, 83, 2, 450, 291, 14, 832, 395, 283, 82, 358, 465, 289, 26, 288, 8526, 275, 291, 14, 1494, 14, 739, 8, 70, 9, 268, 4388, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 24, 1882, 199, 646, 5890, 199, 646, 747, 199, 646, 5145, 199, 646, 5549, 199, 199, 80, 904, 275, 747, 14, 515, 14, 904, 199, 199, 504, 2508, 4994, 1095, 492, 334, 272, 3390, 2706, 1716, 12, 272, 892, 63, 600, 63, 3890, 12, 892, 63, 505, 63, 3890, 12, 892, 63, 29776, 12, 892, 63, 19174, 199, 9, 199, 199, 504, 2508, 4994, 647, 492, 11597, 12, 14511, 12, 1586, 12, 2218, 199, 504, 1275, 4994, 8589, 492, 8526, 16, 12, 8526, 16, 63, 647, 421, 199, 318, 1551, 63, 1624, 24, 8, 5252, 12, 818, 304, 272, 372, 5890, 14, 1490, 8, 5252, 12, 818, 29, 632, 12, 2644, 534, 1624, 13, 24, 358, 199, 199, 533, 25377, 3484, 774, 26, 272, 408, 4256, 367, 3575, 20751, 1475, 2295, 624, 339, 327, 4278, 543, 5827, 1338, 315, 9180, 272, 8526, 16, 63, 1121, 275, 488, 272, 1599, 275, 488, 272, 3413, 275, 488, 2286, 347, 3613, 8, 277, 304, 267, 291, 14, 2989, 275, 5549, 14, 11983, 342, 2286, 347, 6766, 8, 277, 304, 267, 5145, 14, 9242, 8, 277, 14, 2989, 9, 2286, 347, 702, 16170, 13317, 8, 277, 12, 302, 2470, 12, 302, 2501, 304, 267, 291, 14, 629, 8, 78, 2470, 12, 302, 2501, 9, 5493, 347, 511, 63, 16334, 8, 277, 304, 267, 308, 275, 291, 14, 1494, 14, 16334, 8, 4994, 16, 9, 267, 340, 291, 14, 4994, 16, 63, 1121, 26, 288, 291, 14, 629, 8, 83, 12, 291, 14, 4994, 16, 63, 1121, 9, 339, 347, 511, 63, 15656, 8, 277, 304, 267, 308, 275, 291, 14, 1494, 14, 16334, 8, 4994, 16, 9, 267, 8526, 275, 291, 14, 1494, 14, 15656, 8, 83, 9, 339, 347, 511, 63, 25920, 8, 277, 304, 267, 308, 275, 291, 14, 1494, 14, 16334, 8, 4994, 16, 9, 267, 291, 14, 479, 16170, 13317, 8, 277, 14, 1494, 14, 15656, 8, 83, 395, 4994, 16, 9, 339, 347, 511, 63, 952, 63, 493, 8, 277, 304, 267, 543, 1551, 63, 1624, 24, 8, 80, 904, 8, 277, 14, 2989, 12, 298, 4994, 16, 4111, 83, 2, 450, 291, 14, 832, 395, 283, 87, 358, 465, 289, 26, 288, 291, 14, 1494, 14, 952, 8, 4994, 16, 12, 289, 9, 2286, 347, 511, 63, 739, 63, 493, 8, 277, 304, 267, 543, 1551, 63, 1624, 24, 8, 80, 904, 8, 277, 14, 2989, 12, 298, 4994, 16, 4111, 83, 2, 450, 291, 14, 832, 395, 283, 87, 358, 465, 289, 26, 288, 291, 14, 1494, 14, 952, 8, 4994, 16, 12, 289, 9, 2728, 543, 1551, 63, 1624, 24, 8, 80, 904, 8, 277, 14, 2989, 12, 298, 4994, 16, 4111, 83, 2, 450, 291, 14, 832, 395, 283, 82, 358, 465, 289, 26, 288, 8526, 275, 291, 14, 1494, 14, 739, 8, 70, 9, 268, 4388, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
caseylucas/ansible-modules-core
windows/win_ping.py
208
1376
#!/usr/bin/python # -*- coding: utf-8 -*- # (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>, and others # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # this is a windows documentation stub. actual code lives in the .ps1 # file of the same name DOCUMENTATION = ''' --- module: win_ping version_added: "1.7" short_description: A windows version of the classic ping module. description: - Checks management connectivity of a windows host options: data: description: - Alternate data to return instead of 'pong' required: false default: 'pong' aliases: [] author: "Chris Church (@cchurch)" ''' EXAMPLES = ''' # Test connectivity to a windows host ansible winserver -m win_ping # Example from an Ansible Playbook - action: win_ping '''
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 334, 67, 9, 6029, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 14, 957, 6244, 436, 11789, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 642, 365, 282, 10061, 3794, 10098, 14, 221, 3503, 1233, 27576, 315, 314, 1275, 1190, 17, 199, 3, 570, 402, 314, 2011, 536, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 4747, 63, 4073, 199, 1023, 63, 3270, 26, 298, 17, 14, 23, 2, 199, 3612, 63, 1802, 26, 437, 10061, 1015, 402, 314, 31205, 18249, 859, 14, 199, 1802, 26, 523, 446, 13813, 10041, 20170, 402, 282, 10061, 1591, 199, 1419, 26, 523, 666, 26, 272, 1369, 26, 489, 446, 17669, 323, 666, 370, 372, 3140, 402, 283, 26992, 7, 272, 1415, 26, 3055, 272, 849, 26, 283, 26992, 7, 272, 5481, 26, 942, 199, 2502, 26, 298, 1049, 5719, 2799, 300, 335, 8593, 67, 335, 300, 335, 2924, 199, 2344, 199, 199, 8918, 275, 1449, 199, 3, 1379, 20170, 370, 282, 10061, 1591, 199, 4853, 4747, 1000, 446, 77, 4747, 63, 4073, 199, 199, 3, 5679, 687, 376, 2622, 16527, 2706, 199, 13, 1595, 26, 4747, 63, 4073, 199, 2344, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 334, 67, 9, 6029, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 14, 957, 6244, 436, 11789, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 642, 365, 282, 10061, 3794, 10098, 14, 221, 3503, 1233, 27576, 315, 314, 1275, 1190, 17, 199, 3, 570, 402, 314, 2011, 536, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 4747, 63, 4073, 199, 1023, 63, 3270, 26, 298, 17, 14, 23, 2, 199, 3612, 63, 1802, 26, 437, 10061, 1015, 402, 314, 31205, 18249, 859, 14, 199, 1802, 26, 523, 446, 13813, 10041, 20170, 402, 282, 10061, 1591, 199, 1419, 26, 523, 666, 26, 272, 1369, 26, 489, 446, 17669, 323, 666, 370, 372, 3140, 402, 283, 26992, 7, 272, 1415, 26, 3055, 272, 849, 26, 283, 26992, 7, 272, 5481, 26, 942, 199, 2502, 26, 298, 1049, 5719, 2799, 300, 335, 8593, 67, 335, 300, 335, 2924, 199, 2344, 199, 199, 8918, 275, 1449, 199, 3, 1379, 20170, 370, 282, 10061, 1591, 199, 4853, 4747, 1000, 446, 77, 4747, 63, 4073, 199, 199, 3, 5679, 687, 376, 2622, 16527, 2706, 199, 13, 1595, 26, 4747, 63, 4073, 199, 2344, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
eeshangarg/oh-mainline
vendor/packages/Django/django/db/models/query.py
63
74029
""" The main QuerySet implementation. This provides the public API for the ORM. """ import copy import itertools import sys import warnings from django.core import exceptions from django.db import connections, router, transaction, IntegrityError from django.db.models.constants import LOOKUP_SEP from django.db.models.fields import AutoField from django.db.models.query_utils import (Q, select_related_descend, deferred_class_factory, InvalidQuery) from django.db.models.deletion import Collector from django.db.models import sql from django.utils.functional import partition from django.utils import six # Used to control how many objects are worked with at once in some cases (e.g. # when deleting objects). CHUNK_SIZE = 100 ITER_CHUNK_SIZE = CHUNK_SIZE # The maximum number of items to display in a QuerySet.__repr__ REPR_OUTPUT_SIZE = 20 # Pull into this namespace for backwards compatibility. EmptyResultSet = sql.EmptyResultSet class QuerySet(object): """ Represents a lazy database lookup for a set of objects. """ def __init__(self, model=None, query=None, using=None): self.model = model # EmptyQuerySet instantiates QuerySet with model as None self._db = using self.query = query or sql.Query(self.model) self._result_cache = None self._iter = None self._sticky_filter = False self._for_write = False self._prefetch_related_lookups = [] self._prefetch_done = False self._known_related_objects = {} # {rel_field, {pk: rel_obj}} ######################## # PYTHON MAGIC METHODS # ######################## def __deepcopy__(self, memo): """ Deep copy of a QuerySet doesn't populate the cache """ obj = self.__class__() for k,v in self.__dict__.items(): if k in ('_iter','_result_cache'): obj.__dict__[k] = None else: obj.__dict__[k] = copy.deepcopy(v, memo) return obj def __getstate__(self): """ Allows the QuerySet to be pickled. """ # Force the cache to be fully populated. len(self) obj_dict = self.__dict__.copy() obj_dict['_iter'] = None obj_dict['_known_related_objects'] = dict( (field.name, val) for field, val in self._known_related_objects.items() ) return obj_dict def __setstate__(self, obj_dict): model = obj_dict['model'] if model is None: # if model is None, then self should be emptyqs and the related # objects do not matter. obj_dict['_known_related_objects'] = {} else: opts = model._meta obj_dict['_known_related_objects'] = dict( (opts.get_field(field.name if hasattr(field, 'name') else field), val) for field, val in obj_dict['_known_related_objects'].items() ) self.__dict__.update(obj_dict) def __repr__(self): data = list(self[:REPR_OUTPUT_SIZE + 1]) if len(data) > REPR_OUTPUT_SIZE: data[-1] = "...(remaining elements truncated)..." return repr(data) def __len__(self): # Since __len__ is called quite frequently (for example, as part of # list(qs), we make some effort here to be as efficient as possible # whilst not messing up any existing iterators against the QuerySet. if self._result_cache is None: if self._iter: self._result_cache = list(self._iter) else: self._result_cache = list(self.iterator()) elif self._iter: self._result_cache.extend(self._iter) if self._prefetch_related_lookups and not self._prefetch_done: self._prefetch_related_objects() return len(self._result_cache) def __iter__(self): if self._prefetch_related_lookups and not self._prefetch_done: # We need all the results in order to be able to do the prefetch # in one go. To minimize code duplication, we use the __len__ # code path which also forces this, and also does the prefetch len(self) if self._result_cache is None: self._iter = self.iterator() self._result_cache = [] if self._iter: return self._result_iter() # Python's list iterator is better than our version when we're just # iterating over the cache. return iter(self._result_cache) def _result_iter(self): pos = 0 while 1: upper = len(self._result_cache) while pos < upper: yield self._result_cache[pos] pos = pos + 1 if not self._iter: raise StopIteration if len(self._result_cache) <= pos: self._fill_cache() def __bool__(self): if self._prefetch_related_lookups and not self._prefetch_done: # We need all the results in order to be able to do the prefetch # in one go. To minimize code duplication, we use the __len__ # code path which also forces this, and also does the prefetch len(self) if self._result_cache is not None: return bool(self._result_cache) try: next(iter(self)) except StopIteration: return False return True def __nonzero__(self): # Python 2 compatibility return type(self).__bool__(self) def __contains__(self, val): # The 'in' operator works without this method, due to __iter__. This # implementation exists only to shortcut the creation of Model # instances, by bailing out early if we find a matching element. pos = 0 if self._result_cache is not None: if val in self._result_cache: return True elif self._iter is None: # iterator is exhausted, so we have our answer return False # remember not to check these again: pos = len(self._result_cache) else: # We need to start filling the result cache out. The following # ensures that self._iter is not None and self._result_cache is not # None it = iter(self) # Carry on, one result at a time. while True: if len(self._result_cache) <= pos: self._fill_cache(num=1) if self._iter is None: # we ran out of items return False if self._result_cache[pos] == val: return True pos += 1 def __getitem__(self, k): """ Retrieves an item or slice from the set of results. """ if not isinstance(k, (slice,) + six.integer_types): raise TypeError assert ((not isinstance(k, slice) and (k >= 0)) or (isinstance(k, slice) and (k.start is None or k.start >= 0) and (k.stop is None or k.stop >= 0))), \ "Negative indexing is not supported." if self._result_cache is not None: if self._iter is not None: # The result cache has only been partially populated, so we may # need to fill it out a bit more. if isinstance(k, slice): if k.stop is not None: # Some people insist on passing in strings here. bound = int(k.stop) else: bound = None else: bound = k + 1 if len(self._result_cache) < bound: self._fill_cache(bound - len(self._result_cache)) return self._result_cache[k] if isinstance(k, slice): qs = self._clone() if k.start is not None: start = int(k.start) else: start = None if k.stop is not None: stop = int(k.stop) else: stop = None qs.query.set_limits(start, stop) return k.step and list(qs)[::k.step] or qs try: qs = self._clone() qs.query.set_limits(k, k + 1) return list(qs)[0] except self.model.DoesNotExist as e: raise IndexError(e.args) def __and__(self, other): self._merge_sanity_check(other) if isinstance(other, EmptyQuerySet): return other._clone() combined = self._clone() combined._merge_known_related_objects(other) combined.query.combine(other.query, sql.AND) return combined def __or__(self, other): self._merge_sanity_check(other) combined = self._clone() if isinstance(other, EmptyQuerySet): return combined combined._merge_known_related_objects(other) combined.query.combine(other.query, sql.OR) return combined #################################### # METHODS THAT DO DATABASE QUERIES # #################################### def iterator(self): """ An iterator over the results from applying this QuerySet to the database. """ fill_cache = False if connections[self.db].features.supports_select_related: fill_cache = self.query.select_related if isinstance(fill_cache, dict): requested = fill_cache else: requested = None max_depth = self.query.max_depth extra_select = list(self.query.extra_select) aggregate_select = list(self.query.aggregate_select) only_load = self.query.get_loaded_field_names() if not fill_cache: fields = self.model._meta.fields load_fields = [] # If only/defer clauses have been specified, # build the list of fields that are to be loaded. if only_load: for field, model in self.model._meta.get_fields_with_model(): if model is None: model = self.model try: if field.name in only_load[model]: # Add a field that has been explicitly included load_fields.append(field.name) except KeyError: # Model wasn't explicitly listed in the only_load table # Therefore, we need to load all fields from this model load_fields.append(field.name) index_start = len(extra_select) aggregate_start = index_start + len(load_fields or self.model._meta.fields) skip = None if load_fields and not fill_cache: # Some fields have been deferred, so we have to initialise # via keyword arguments. skip = set() init_list = [] for field in fields: if field.name not in load_fields: skip.add(field.attname) else: init_list.append(field.attname) model_cls = deferred_class_factory(self.model, skip) # Cache db and model outside the loop db = self.db model = self.model compiler = self.query.get_compiler(using=db) if fill_cache: klass_info = get_klass_info(model, max_depth=max_depth, requested=requested, only_load=only_load) for row in compiler.results_iter(): if fill_cache: obj, _ = get_cached_row(row, index_start, db, klass_info, offset=len(aggregate_select)) else: # Omit aggregates in object creation. row_data = row[index_start:aggregate_start] if skip: obj = model_cls(**dict(zip(init_list, row_data))) else: obj = model(*row_data) # Store the source database of the object obj._state.db = db # This object came from the database; it's not being added. obj._state.adding = False if extra_select: for i, k in enumerate(extra_select): setattr(obj, k, row[i]) # Add the aggregates to the model if aggregate_select: for i, aggregate in enumerate(aggregate_select): setattr(obj, aggregate, row[i + aggregate_start]) # Add the known related objects to the model, if there are any if self._known_related_objects: for field, rel_objs in self._known_related_objects.items(): pk = getattr(obj, field.get_attname()) try: rel_obj = rel_objs[pk] except KeyError: pass # may happen in qs1 | qs2 scenarios else: setattr(obj, field.name, rel_obj) yield obj def aggregate(self, *args, **kwargs): """ Returns a dictionary containing the calculations (aggregation) over the current queryset If args is present the expression is passed as a kwarg using the Aggregate object's default alias. """ if self.query.distinct_fields: raise NotImplementedError("aggregate() + distinct(fields) not implemented.") for arg in args: kwargs[arg.default_alias] = arg query = self.query.clone() for (alias, aggregate_expr) in kwargs.items(): query.add_aggregate(aggregate_expr, self.model, alias, is_summary=True) return query.get_aggregation(using=self.db) def count(self): """ Performs a SELECT COUNT() and returns the number of records as an integer. If the QuerySet is already fully cached this simply returns the length of the cached results set to avoid multiple SELECT COUNT(*) calls. """ if self._result_cache is not None and not self._iter: return len(self._result_cache) return self.query.get_count(using=self.db) def get(self, *args, **kwargs): """ Performs the query and returns a single object matching the given keyword arguments. """ clone = self.filter(*args, **kwargs) if self.query.can_filter(): clone = clone.order_by() num = len(clone) if num == 1: return clone._result_cache[0] if not num: raise self.model.DoesNotExist( "%s matching query does not exist." % self.model._meta.object_name) raise self.model.MultipleObjectsReturned( "get() returned more than one %s -- it returned %s!" % (self.model._meta.object_name, num)) def create(self, **kwargs): """ Creates a new object with the given kwargs, saving it to the database and returning the created object. """ obj = self.model(**kwargs) self._for_write = True obj.save(force_insert=True, using=self.db) return obj def bulk_create(self, objs, batch_size=None): """ Inserts each of the instances into the database. This does *not* call save() on each of the instances, does not send any pre/post save signals, and does not set the primary key attribute if it is an autoincrement field. """ # So this case is fun. When you bulk insert you don't get the primary # keys back (if it's an autoincrement), so you can't insert into the # child tables which references this. There are two workarounds, 1) # this could be implemented if you didn't have an autoincrement pk, # and 2) you could do it by doing O(n) normal inserts into the parent # tables to get the primary keys back, and then doing a single bulk # insert into the childmost table. Some databases might allow doing # this by using RETURNING clause for the insert query. We're punting # on these for now because they are relatively rare cases. assert batch_size is None or batch_size > 0 if self.model._meta.parents: raise ValueError("Can't bulk create an inherited model") if not objs: return objs self._for_write = True connection = connections[self.db] fields = self.model._meta.local_fields if not transaction.is_managed(using=self.db): transaction.enter_transaction_management(using=self.db) forced_managed = True else: forced_managed = False try: if (connection.features.can_combine_inserts_with_and_without_auto_increment_pk and self.model._meta.has_auto_field): self._batched_insert(objs, fields, batch_size) else: objs_with_pk, objs_without_pk = partition(lambda o: o.pk is None, objs) if objs_with_pk: self._batched_insert(objs_with_pk, fields, batch_size) if objs_without_pk: fields= [f for f in fields if not isinstance(f, AutoField)] self._batched_insert(objs_without_pk, fields, batch_size) if forced_managed: transaction.commit(using=self.db) else: transaction.commit_unless_managed(using=self.db) finally: if forced_managed: transaction.leave_transaction_management(using=self.db) return objs def get_or_create(self, **kwargs): """ Looks up an object with the given kwargs, creating one if necessary. Returns a tuple of (object, created), where created is a boolean specifying whether an object was created. """ assert kwargs, \ 'get_or_create() must be passed at least one keyword argument' defaults = kwargs.pop('defaults', {}) lookup = kwargs.copy() for f in self.model._meta.fields: if f.attname in lookup: lookup[f.name] = lookup.pop(f.attname) try: self._for_write = True return self.get(**lookup), False except self.model.DoesNotExist: try: params = dict([(k, v) for k, v in kwargs.items() if '__' not in k]) params.update(defaults) obj = self.model(**params) sid = transaction.savepoint(using=self.db) obj.save(force_insert=True, using=self.db) transaction.savepoint_commit(sid, using=self.db) return obj, True except IntegrityError as e: transaction.savepoint_rollback(sid, using=self.db) exc_info = sys.exc_info() try: return self.get(**lookup), False except self.model.DoesNotExist: # Re-raise the IntegrityError with its original traceback. six.reraise(*exc_info) def latest(self, field_name=None): """ Returns the latest object, according to the model's 'get_latest_by' option or optional given field_name. """ latest_by = field_name or self.model._meta.get_latest_by assert bool(latest_by), "latest() requires either a field_name parameter or 'get_latest_by' in the model" assert self.query.can_filter(), \ "Cannot change a query once a slice has been taken." obj = self._clone() obj.query.set_limits(high=1) obj.query.clear_ordering() obj.query.add_ordering('-%s' % latest_by) return obj.get() def in_bulk(self, id_list): """ Returns a dictionary mapping each of the given IDs to the object with that ID. """ assert self.query.can_filter(), \ "Cannot use 'limit' or 'offset' with in_bulk" if not id_list: return {} qs = self.filter(pk__in=id_list).order_by() return dict([(obj._get_pk_val(), obj) for obj in qs]) def delete(self): """ Deletes the records in the current QuerySet. """ assert self.query.can_filter(), \ "Cannot use 'limit' or 'offset' with delete." del_query = self._clone() # The delete is actually 2 queries - one to find related objects, # and one to delete. Make sure that the discovery of related # objects is performed on the same database as the deletion. del_query._for_write = True # Disable non-supported fields. del_query.query.select_for_update = False del_query.query.select_related = False del_query.query.clear_ordering(force_empty=True) collector = Collector(using=del_query.db) collector.collect(del_query) collector.delete() # Clear the result cache, in case this QuerySet gets reused. self._result_cache = None delete.alters_data = True def _raw_delete(self, using): """ Deletes objects found from the given queryset in single direct SQL query. No signals are sent, and there is no protection for cascades. """ sql.DeleteQuery(self.model).delete_qs(self, using) _raw_delete.alters_data = True def update(self, **kwargs): """ Updates all elements in the current QuerySet, setting all the given fields to the appropriate values. """ assert self.query.can_filter(), \ "Cannot update a query once a slice has been taken." self._for_write = True query = self.query.clone(sql.UpdateQuery) query.add_update_values(kwargs) if not transaction.is_managed(using=self.db): transaction.enter_transaction_management(using=self.db) forced_managed = True else: forced_managed = False try: rows = query.get_compiler(self.db).execute_sql(None) if forced_managed: transaction.commit(using=self.db) else: transaction.commit_unless_managed(using=self.db) finally: if forced_managed: transaction.leave_transaction_management(using=self.db) self._result_cache = None return rows update.alters_data = True def _update(self, values): """ A version of update that accepts field objects instead of field names. Used primarily for model saving and not intended for use by general code (it requires too much poking around at model internals to be useful at that level). """ assert self.query.can_filter(), \ "Cannot update a query once a slice has been taken." query = self.query.clone(sql.UpdateQuery) query.add_update_fields(values) self._result_cache = None return query.get_compiler(self.db).execute_sql(None) _update.alters_data = True def exists(self): if self._result_cache is None: return self.query.has_results(using=self.db) return bool(self._result_cache) def _prefetch_related_objects(self): # This method can only be called once the result cache has been filled. prefetch_related_objects(self._result_cache, self._prefetch_related_lookups) self._prefetch_done = True ################################################## # PUBLIC METHODS THAT RETURN A QUERYSET SUBCLASS # ################################################## def values(self, *fields): return self._clone(klass=ValuesQuerySet, setup=True, _fields=fields) def values_list(self, *fields, **kwargs): flat = kwargs.pop('flat', False) if kwargs: raise TypeError('Unexpected keyword arguments to values_list: %s' % (list(kwargs),)) if flat and len(fields) > 1: raise TypeError("'flat' is not valid when values_list is called with more than one field.") return self._clone(klass=ValuesListQuerySet, setup=True, flat=flat, _fields=fields) def dates(self, field_name, kind, order='ASC'): """ Returns a list of datetime objects representing all available dates for the given field_name, scoped to 'kind'. """ assert kind in ("month", "year", "day"), \ "'kind' must be one of 'year', 'month' or 'day'." assert order in ('ASC', 'DESC'), \ "'order' must be either 'ASC' or 'DESC'." return self._clone(klass=DateQuerySet, setup=True, _field_name=field_name, _kind=kind, _order=order) def none(self): """ Returns an empty QuerySet. """ return self._clone(klass=EmptyQuerySet) ################################################################## # PUBLIC METHODS THAT ALTER ATTRIBUTES AND RETURN A NEW QUERYSET # ################################################################## def all(self): """ Returns a new QuerySet that is a copy of the current one. This allows a QuerySet to proxy for a model manager in some cases. """ return self._clone() def filter(self, *args, **kwargs): """ Returns a new QuerySet instance with the args ANDed to the existing set. """ return self._filter_or_exclude(False, *args, **kwargs) def exclude(self, *args, **kwargs): """ Returns a new QuerySet instance with NOT (args) ANDed to the existing set. """ return self._filter_or_exclude(True, *args, **kwargs) def _filter_or_exclude(self, negate, *args, **kwargs): if args or kwargs: assert self.query.can_filter(), \ "Cannot filter a query once a slice has been taken." clone = self._clone() if negate: clone.query.add_q(~Q(*args, **kwargs)) else: clone.query.add_q(Q(*args, **kwargs)) return clone def complex_filter(self, filter_obj): """ Returns a new QuerySet instance with filter_obj added to the filters. filter_obj can be a Q object (or anything with an add_to_query() method) or a dictionary of keyword lookup arguments. This exists to support framework features such as 'limit_choices_to', and usually it will be more natural to use other methods. """ if isinstance(filter_obj, Q) or hasattr(filter_obj, 'add_to_query'): clone = self._clone() clone.query.add_q(filter_obj) return clone else: return self._filter_or_exclude(None, **filter_obj) def select_for_update(self, **kwargs): """ Returns a new QuerySet instance that will select objects with a FOR UPDATE lock. """ # Default to false for nowait nowait = kwargs.pop('nowait', False) obj = self._clone() obj.query.select_for_update = True obj.query.select_for_update_nowait = nowait return obj def select_related(self, *fields, **kwargs): """ Returns a new QuerySet instance that will select related objects. If fields are specified, they must be ForeignKey fields and only those related objects are included in the selection. """ if 'depth' in kwargs: warnings.warn('The "depth" keyword argument has been deprecated.\n' 'Use related field names instead.', PendingDeprecationWarning) depth = kwargs.pop('depth', 0) if kwargs: raise TypeError('Unexpected keyword arguments to select_related: %s' % (list(kwargs),)) obj = self._clone() if fields: if depth: raise TypeError('Cannot pass both "depth" and fields to select_related()') obj.query.add_select_related(fields) else: obj.query.select_related = True if depth: obj.query.max_depth = depth return obj def prefetch_related(self, *lookups): """ Returns a new QuerySet instance that will prefetch the specified Many-To-One and Many-To-Many related objects when the QuerySet is evaluated. When prefetch_related() is called more than once, the list of lookups to prefetch is appended to. If prefetch_related(None) is called, the the list is cleared. """ clone = self._clone() if lookups == (None,): clone._prefetch_related_lookups = [] else: clone._prefetch_related_lookups.extend(lookups) return clone def dup_select_related(self, other): """ Copies the related selection status from the QuerySet 'other' to the current QuerySet. """ self.query.select_related = other.query.select_related def annotate(self, *args, **kwargs): """ Return a query set in which the returned objects have been annotated with data aggregated from related fields. """ for arg in args: if arg.default_alias in kwargs: raise ValueError("The named annotation '%s' conflicts with the " "default name for another annotation." % arg.default_alias) kwargs[arg.default_alias] = arg names = getattr(self, '_fields', None) if names is None: names = set(self.model._meta.get_all_field_names()) for aggregate in kwargs: if aggregate in names: raise ValueError("The annotation '%s' conflicts with a field on " "the model." % aggregate) obj = self._clone() obj._setup_aggregate_query(list(kwargs)) # Add the aggregates to the query for (alias, aggregate_expr) in kwargs.items(): obj.query.add_aggregate(aggregate_expr, self.model, alias, is_summary=False) return obj def order_by(self, *field_names): """ Returns a new QuerySet instance with the ordering changed. """ assert self.query.can_filter(), \ "Cannot reorder a query once a slice has been taken." obj = self._clone() obj.query.clear_ordering() obj.query.add_ordering(*field_names) return obj def distinct(self, *field_names): """ Returns a new QuerySet instance that will select only distinct results. """ assert self.query.can_filter(), \ "Cannot create distinct fields once a slice has been taken." obj = self._clone() obj.query.add_distinct_fields(*field_names) return obj def extra(self, select=None, where=None, params=None, tables=None, order_by=None, select_params=None): """ Adds extra SQL fragments to the query. """ assert self.query.can_filter(), \ "Cannot change a query once a slice has been taken" clone = self._clone() clone.query.add_extra(select, select_params, where, params, tables, order_by) return clone def reverse(self): """ Reverses the ordering of the QuerySet. """ clone = self._clone() clone.query.standard_ordering = not clone.query.standard_ordering return clone def defer(self, *fields): """ Defers the loading of data for certain fields until they are accessed. The set of fields to defer is added to any existing set of deferred fields. The only exception to this is if None is passed in as the only parameter, in which case all deferrals are removed (None acts as a reset option). """ clone = self._clone() if fields == (None,): clone.query.clear_deferred_loading() else: clone.query.add_deferred_loading(fields) return clone def only(self, *fields): """ Essentially, the opposite of defer. Only the fields passed into this method and that are not already specified as deferred are loaded immediately when the queryset is evaluated. """ if fields == (None,): # Can only pass None to defer(), not only(), as the rest option. # That won't stop people trying to do this, so let's be explicit. raise TypeError("Cannot pass None as an argument to only().") clone = self._clone() clone.query.add_immediate_loading(fields) return clone def using(self, alias): """ Selects which database this QuerySet should excecute its query against. """ clone = self._clone() clone._db = alias return clone ################################### # PUBLIC INTROSPECTION ATTRIBUTES # ################################### def ordered(self): """ Returns True if the QuerySet is ordered -- i.e. has an order_by() clause or a default ordering on the model. """ if self.query.extra_order_by or self.query.order_by: return True elif self.query.default_ordering and self.query.model._meta.ordering: return True else: return False ordered = property(ordered) @property def db(self): "Return the database that will be used if this query is executed now" if self._for_write: return self._db or router.db_for_write(self.model) return self._db or router.db_for_read(self.model) ################### # PRIVATE METHODS # ################### def _batched_insert(self, objs, fields, batch_size): """ A little helper method for bulk_insert to insert the bulk one batch at a time. Inserts recursively a batch from the front of the bulk and then _batched_insert() the remaining objects again. """ if not objs: return ops = connections[self.db].ops batch_size = (batch_size or max(ops.bulk_batch_size(fields, objs), 1)) for batch in [objs[i:i+batch_size] for i in range(0, len(objs), batch_size)]: self.model._base_manager._insert(batch, fields=fields, using=self.db) def _clone(self, klass=None, setup=False, **kwargs): if klass is None: klass = self.__class__ query = self.query.clone() if self._sticky_filter: query.filter_is_sticky = True c = klass(model=self.model, query=query, using=self._db) c._for_write = self._for_write c._prefetch_related_lookups = self._prefetch_related_lookups[:] c._known_related_objects = self._known_related_objects c.__dict__.update(kwargs) if setup and hasattr(c, '_setup_query'): c._setup_query() return c def _fill_cache(self, num=None): """ Fills the result cache with 'num' more entries (or until the results iterator is exhausted). """ if self._iter: try: for i in range(num or ITER_CHUNK_SIZE): self._result_cache.append(next(self._iter)) except StopIteration: self._iter = None def _next_is_sticky(self): """ Indicates that the next filter call and the one following that should be treated as a single filter. This is only important when it comes to determining when to reuse tables for many-to-many filters. Required so that we can filter naturally on the results of related managers. This doesn't return a clone of the current QuerySet (it returns "self"). The method is only used internally and should be immediately followed by a filter() that does create a clone. """ self._sticky_filter = True return self def _merge_sanity_check(self, other): """ Checks that we are merging two comparable QuerySet classes. By default this does nothing, but see the ValuesQuerySet for an example of where it's useful. """ pass def _merge_known_related_objects(self, other): """ Keep track of all known related objects from either QuerySet instance. """ for field, objects in other._known_related_objects.items(): self._known_related_objects.setdefault(field, {}).update(objects) def _setup_aggregate_query(self, aggregates): """ Prepare the query for computing a result that contains aggregate annotations. """ opts = self.model._meta if self.query.group_by is None: field_names = [f.attname for f in opts.fields] self.query.add_fields(field_names, False) self.query.set_group_by() def _prepare(self): return self def _as_sql(self, connection): """ Returns the internal query's SQL and parameters (as a tuple). """ obj = self.values("pk") if obj._db is None or connection == connections[obj._db]: return obj.query.get_compiler(connection=connection).as_nested_sql() raise ValueError("Can't do subqueries with queries on different DBs.") # When used as part of a nested query, a queryset will never be an "always # empty" result. value_annotation = True class ValuesQuerySet(QuerySet): def __init__(self, *args, **kwargs): super(ValuesQuerySet, self).__init__(*args, **kwargs) # select_related isn't supported in values(). (FIXME -#3358) self.query.select_related = False # QuerySet.clone() will also set up the _fields attribute with the # names of the model fields to select. def iterator(self): # Purge any extra columns that haven't been explicitly asked for extra_names = list(self.query.extra_select) field_names = self.field_names aggregate_names = list(self.query.aggregate_select) names = extra_names + field_names + aggregate_names for row in self.query.get_compiler(self.db).results_iter(): yield dict(zip(names, row)) def delete(self): # values().delete() doesn't work currently - make sure it raises an # user friendly error. raise TypeError("Queries with .values() or .values_list() applied " "can't be deleted") def _setup_query(self): """ Constructs the field_names list that the values query will be retrieving. Called by the _clone() method after initializing the rest of the instance. """ self.query.clear_deferred_loading() self.query.clear_select_fields() if self._fields: self.extra_names = [] self.aggregate_names = [] if not self.query.extra and not self.query.aggregates: # Short cut - if there are no extra or aggregates, then # the values() clause must be just field names. self.field_names = list(self._fields) else: self.query.default_cols = False self.field_names = [] for f in self._fields: # we inspect the full extra_select list since we might # be adding back an extra select item that we hadn't # had selected previously. if f in self.query.extra: self.extra_names.append(f) elif f in self.query.aggregate_select: self.aggregate_names.append(f) else: self.field_names.append(f) else: # Default to all fields. self.extra_names = None self.field_names = [f.attname for f in self.model._meta.fields] self.aggregate_names = None self.query.select = [] if self.extra_names is not None: self.query.set_extra_mask(self.extra_names) self.query.add_fields(self.field_names, True) if self.aggregate_names is not None: self.query.set_aggregate_mask(self.aggregate_names) def _clone(self, klass=None, setup=False, **kwargs): """ Cloning a ValuesQuerySet preserves the current fields. """ c = super(ValuesQuerySet, self)._clone(klass, **kwargs) if not hasattr(c, '_fields'): # Only clone self._fields if _fields wasn't passed into the cloning # call directly. c._fields = self._fields[:] c.field_names = self.field_names c.extra_names = self.extra_names c.aggregate_names = self.aggregate_names if setup and hasattr(c, '_setup_query'): c._setup_query() return c def _merge_sanity_check(self, other): super(ValuesQuerySet, self)._merge_sanity_check(other) if (set(self.extra_names) != set(other.extra_names) or set(self.field_names) != set(other.field_names) or self.aggregate_names != other.aggregate_names): raise TypeError("Merging '%s' classes must involve the same values in each case." % self.__class__.__name__) def _setup_aggregate_query(self, aggregates): """ Prepare the query for computing a result that contains aggregate annotations. """ self.query.set_group_by() if self.aggregate_names is not None: self.aggregate_names.extend(aggregates) self.query.set_aggregate_mask(self.aggregate_names) super(ValuesQuerySet, self)._setup_aggregate_query(aggregates) def _as_sql(self, connection): """ For ValueQuerySet (and subclasses like ValuesListQuerySet), they can only be used as nested queries if they're already set up to select only a single field (in which case, that is the field column that is returned). This differs from QuerySet.as_sql(), where the column to select is set up by Django. """ if ((self._fields and len(self._fields) > 1) or (not self._fields and len(self.model._meta.fields) > 1)): raise TypeError('Cannot use a multi-field %s as a filter value.' % self.__class__.__name__) obj = self._clone() if obj._db is None or connection == connections[obj._db]: return obj.query.get_compiler(connection=connection).as_nested_sql() raise ValueError("Can't do subqueries with queries on different DBs.") def _prepare(self): """ Validates that we aren't trying to do a query like value__in=qs.values('value1', 'value2'), which isn't valid. """ if ((self._fields and len(self._fields) > 1) or (not self._fields and len(self.model._meta.fields) > 1)): raise TypeError('Cannot use a multi-field %s as a filter value.' % self.__class__.__name__) return self class ValuesListQuerySet(ValuesQuerySet): def iterator(self): if self.flat and len(self._fields) == 1: for row in self.query.get_compiler(self.db).results_iter(): yield row[0] elif not self.query.extra_select and not self.query.aggregate_select: for row in self.query.get_compiler(self.db).results_iter(): yield tuple(row) else: # When extra(select=...) or an annotation is involved, the extra # cols are always at the start of the row, and we need to reorder # the fields to match the order in self._fields. extra_names = list(self.query.extra_select) field_names = self.field_names aggregate_names = list(self.query.aggregate_select) names = extra_names + field_names + aggregate_names # If a field list has been specified, use it. Otherwise, use the # full list of fields, including extras and aggregates. if self._fields: fields = list(self._fields) + [f for f in aggregate_names if f not in self._fields] else: fields = names for row in self.query.get_compiler(self.db).results_iter(): data = dict(zip(names, row)) yield tuple([data[f] for f in fields]) def _clone(self, *args, **kwargs): clone = super(ValuesListQuerySet, self)._clone(*args, **kwargs) if not hasattr(clone, "flat"): # Only assign flat if the clone didn't already get it from kwargs clone.flat = self.flat return clone class DateQuerySet(QuerySet): def iterator(self): return self.query.get_compiler(self.db).results_iter() def _setup_query(self): """ Sets up any special features of the query attribute. Called by the _clone() method after initializing the rest of the instance. """ self.query.clear_deferred_loading() self.query = self.query.clone(klass=sql.DateQuery, setup=True) self.query.select = [] self.query.add_date_select(self._field_name, self._kind, self._order) def _clone(self, klass=None, setup=False, **kwargs): c = super(DateQuerySet, self)._clone(klass, False, **kwargs) c._field_name = self._field_name c._kind = self._kind if setup and hasattr(c, '_setup_query'): c._setup_query() return c class EmptyQuerySet(QuerySet): def __init__(self, model=None, query=None, using=None): super(EmptyQuerySet, self).__init__(model, query, using) self._result_cache = [] def __and__(self, other): return self._clone() def __or__(self, other): return other._clone() def count(self): return 0 def delete(self): pass def _clone(self, klass=None, setup=False, **kwargs): c = super(EmptyQuerySet, self)._clone(klass, setup=setup, **kwargs) c._result_cache = [] return c def iterator(self): # This slightly odd construction is because we need an empty generator # (it raises StopIteration immediately). yield next(iter([])) def all(self): """ Always returns EmptyQuerySet. """ return self def filter(self, *args, **kwargs): """ Always returns EmptyQuerySet. """ return self def exclude(self, *args, **kwargs): """ Always returns EmptyQuerySet. """ return self def complex_filter(self, filter_obj): """ Always returns EmptyQuerySet. """ return self def select_related(self, *fields, **kwargs): """ Always returns EmptyQuerySet. """ return self def annotate(self, *args, **kwargs): """ Always returns EmptyQuerySet. """ return self def order_by(self, *field_names): """ Always returns EmptyQuerySet. """ return self def distinct(self, *field_names): """ Always returns EmptyQuerySet. """ return self def extra(self, select=None, where=None, params=None, tables=None, order_by=None, select_params=None): """ Always returns EmptyQuerySet. """ assert self.query.can_filter(), \ "Cannot change a query once a slice has been taken" return self def reverse(self): """ Always returns EmptyQuerySet. """ return self def defer(self, *fields): """ Always returns EmptyQuerySet. """ return self def only(self, *fields): """ Always returns EmptyQuerySet. """ return self def update(self, **kwargs): """ Don't update anything. """ return 0 def aggregate(self, *args, **kwargs): """ Return a dict mapping the aggregate names to None """ for arg in args: kwargs[arg.default_alias] = arg return dict([(key, None) for key in kwargs]) def values(self, *fields): """ Always returns EmptyQuerySet. """ return self def values_list(self, *fields, **kwargs): """ Always returns EmptyQuerySet. """ return self # EmptyQuerySet is always an empty result in where-clauses (and similar # situations). value_annotation = False def get_klass_info(klass, max_depth=0, cur_depth=0, requested=None, only_load=None, local_only=False): """ Helper function that recursively returns an information for a klass, to be used in get_cached_row. It exists just to compute this information only once for entire queryset. Otherwise it would be computed for each row, which leads to poor perfomance on large querysets. Arguments: * klass - the class to retrieve (and instantiate) * max_depth - the maximum depth to which a select_related() relationship should be explored. * cur_depth - the current depth in the select_related() tree. Used in recursive calls to determin if we should dig deeper. * requested - A dictionary describing the select_related() tree that is to be retrieved. keys are field names; values are dictionaries describing the keys on that related object that are themselves to be select_related(). * only_load - if the query has had only() or defer() applied, this is the list of field names that will be returned. If None, the full field list for `klass` can be assumed. * local_only - Only populate local fields. This is used when following reverse select-related relations """ if max_depth and requested is None and cur_depth > max_depth: # We've recursed deeply enough; stop now. return None if only_load: load_fields = only_load.get(klass) or set() # When we create the object, we will also be creating populating # all the parent classes, so traverse the parent classes looking # for fields that must be included on load. for parent in klass._meta.get_parent_list(): fields = only_load.get(parent) if fields: load_fields.update(fields) else: load_fields = None if load_fields: # Handle deferred fields. skip = set() init_list = [] # Build the list of fields that *haven't* been requested for field, model in klass._meta.get_fields_with_model(): if field.name not in load_fields: skip.add(field.attname) elif local_only and model is not None: continue else: init_list.append(field.attname) # Retrieve all the requested fields field_count = len(init_list) if skip: klass = deferred_class_factory(klass, skip) field_names = init_list else: field_names = () else: # Load all fields on klass # We trying to not populate field_names variable for perfomance reason. # If field_names variable is set, it is used to instantiate desired fields, # by passing **dict(zip(field_names, fields)) as kwargs to Model.__init__ method. # But kwargs version of Model.__init__ is slower, so we should avoid using # it when it is not really neccesary. if local_only and len(klass._meta.local_fields) != len(klass._meta.fields): field_count = len(klass._meta.local_fields) field_names = [f.attname for f in klass._meta.local_fields] else: field_count = len(klass._meta.fields) field_names = () restricted = requested is not None related_fields = [] for f in klass._meta.fields: if select_related_descend(f, restricted, requested, load_fields): if restricted: next = requested[f.name] else: next = None klass_info = get_klass_info(f.rel.to, max_depth=max_depth, cur_depth=cur_depth+1, requested=next, only_load=only_load) related_fields.append((f, klass_info)) reverse_related_fields = [] if restricted: for o in klass._meta.get_all_related_objects(): if o.field.unique and select_related_descend(o.field, restricted, requested, only_load.get(o.model), reverse=True): next = requested[o.field.related_query_name()] klass_info = get_klass_info(o.model, max_depth=max_depth, cur_depth=cur_depth+1, requested=next, only_load=only_load, local_only=True) reverse_related_fields.append((o.field, klass_info)) if field_names: pk_idx = field_names.index(klass._meta.pk.attname) else: pk_idx = klass._meta.pk_index() return klass, field_names, field_count, related_fields, reverse_related_fields, pk_idx def get_cached_row(row, index_start, using, klass_info, offset=0): """ Helper function that recursively returns an object with the specified related attributes already populated. This method may be called recursively to populate deep select_related() clauses. Arguments: * row - the row of data returned by the database cursor * index_start - the index of the row at which data for this object is known to start * offset - the number of additional fields that are known to exist in row for `klass`. This usually means the number of annotated results on `klass`. * using - the database alias on which the query is being executed. * klass_info - result of the get_klass_info function """ if klass_info is None: return None klass, field_names, field_count, related_fields, reverse_related_fields, pk_idx = klass_info fields = row[index_start : index_start + field_count] # If the pk column is None (or the Oracle equivalent ''), then the related # object must be non-existent - set the relation to None. if fields[pk_idx] == None or fields[pk_idx] == '': obj = None elif field_names: obj = klass(**dict(zip(field_names, fields))) else: obj = klass(*fields) # If an object was retrieved, set the database state. if obj: obj._state.db = using obj._state.adding = False # Instantiate related fields index_end = index_start + field_count + offset # Iterate over each related object, populating any # select_related() fields for f, klass_info in related_fields: # Recursively retrieve the data for the related object cached_row = get_cached_row(row, index_end, using, klass_info) # If the recursive descent found an object, populate the # descriptor caches relevant to the object if cached_row: rel_obj, index_end = cached_row if obj is not None: # If the base object exists, populate the # descriptor cache setattr(obj, f.get_cache_name(), rel_obj) if f.unique and rel_obj is not None: # If the field is unique, populate the # reverse descriptor cache on the related object setattr(rel_obj, f.related.get_cache_name(), obj) # Now do the same, but for reverse related objects. # Only handle the restricted case - i.e., don't do a depth # descent into reverse relations unless explicitly requested for f, klass_info in reverse_related_fields: # Recursively retrieve the data for the related object cached_row = get_cached_row(row, index_end, using, klass_info) # If the recursive descent found an object, populate the # descriptor caches relevant to the object if cached_row: rel_obj, index_end = cached_row if obj is not None: # If the field is unique, populate the # reverse descriptor cache setattr(obj, f.related.get_cache_name(), rel_obj) if rel_obj is not None: # If the related object exists, populate # the descriptor cache. setattr(rel_obj, f.get_cache_name(), obj) # Now populate all the non-local field values on the related # object. If this object has deferred fields, we need to use # the opts from the original model to get non-local fields # correctly. opts = rel_obj._meta if getattr(rel_obj, '_deferred'): opts = opts.proxy_for_model._meta for rel_field, rel_model in opts.get_fields_with_model(): if rel_model is not None: setattr(rel_obj, rel_field.attname, getattr(obj, rel_field.attname)) # populate the field cache for any related object # that has already been retrieved if rel_field.rel: try: cached_obj = getattr(obj, rel_field.get_cache_name()) setattr(rel_obj, rel_field.get_cache_name(), cached_obj) except AttributeError: # Related object hasn't been cached yet pass return obj, index_end class RawQuerySet(object): """ Provides an iterator which converts the results of raw SQL queries into annotated model instances. """ def __init__(self, raw_query, model=None, query=None, params=None, translations=None, using=None): self.raw_query = raw_query self.model = model self._db = using self.query = query or sql.RawQuery(sql=raw_query, using=self.db, params=params) self.params = params or () self.translations = translations or {} def __iter__(self): # Mapping of attrnames to row column positions. Used for constructing # the model using kwargs, needed when not all model's fields are present # in the query. model_init_field_names = {} # A list of tuples of (column name, column position). Used for # annotation fields. annotation_fields = [] # Cache some things for performance reasons outside the loop. db = self.db compiler = connections[db].ops.compiler('SQLCompiler')( self.query, connections[db], db ) need_resolv_columns = hasattr(compiler, 'resolve_columns') query = iter(self.query) # Find out which columns are model's fields, and which ones should be # annotated to the model. for pos, column in enumerate(self.columns): if column in self.model_fields: model_init_field_names[self.model_fields[column].attname] = pos else: annotation_fields.append((column, pos)) # Find out which model's fields are not present in the query. skip = set() for field in self.model._meta.fields: if field.attname not in model_init_field_names: skip.add(field.attname) if skip: if self.model._meta.pk.attname in skip: raise InvalidQuery('Raw query must include the primary key') model_cls = deferred_class_factory(self.model, skip) else: model_cls = self.model # All model's fields are present in the query. So, it is possible # to use *args based model instantation. For each field of the model, # record the query column position matching that field. model_init_field_pos = [] for field in self.model._meta.fields: model_init_field_pos.append(model_init_field_names[field.attname]) if need_resolv_columns: fields = [self.model_fields.get(c, None) for c in self.columns] # Begin looping through the query values. for values in query: if need_resolv_columns: values = compiler.resolve_columns(values, fields) # Associate fields to values if skip: model_init_kwargs = {} for attname, pos in six.iteritems(model_init_field_names): model_init_kwargs[attname] = values[pos] instance = model_cls(**model_init_kwargs) else: model_init_args = [values[pos] for pos in model_init_field_pos] instance = model_cls(*model_init_args) if annotation_fields: for column, pos in annotation_fields: setattr(instance, column, values[pos]) instance._state.db = db instance._state.adding = False yield instance def __repr__(self): return "<RawQuerySet: %r>" % (self.raw_query % tuple(self.params)) def __getitem__(self, k): return list(self)[k] @property def db(self): "Return the database that will be used if this query is executed now" return self._db or router.db_for_read(self.model) def using(self, alias): """ Selects which database this Raw QuerySet should excecute it's query against. """ return RawQuerySet(self.raw_query, model=self.model, query=self.query.clone(using=alias), params=self.params, translations=self.translations, using=alias) @property def columns(self): """ A list of model field names in the order they'll appear in the query results. """ if not hasattr(self, '_columns'): self._columns = self.query.get_columns() # Adjust any column names which don't match field names for (query_name, model_name) in self.translations.items(): try: index = self._columns.index(query_name) self._columns[index] = model_name except ValueError: # Ignore translations for non-existant column names pass return self._columns @property def model_fields(self): """ A dict mapping column names to model field names. """ if not hasattr(self, '_model_fields'): converter = connections[self.db].introspection.table_name_converter self._model_fields = {} for field in self.model._meta.fields: name, column = field.get_attname_column() self._model_fields[converter(column)] = field return self._model_fields def insert_query(model, objs, fields, return_id=False, raw=False, using=None): """ Inserts a new record for the given model. This provides an interface to the InsertQuery class and is how Model.save() is implemented. It is not part of the public API. """ query = sql.InsertQuery(model) query.insert_values(fields, objs, raw=raw) return query.get_compiler(using=using).execute_sql(return_id) def prefetch_related_objects(result_cache, related_lookups): """ Helper function for prefetch_related functionality Populates prefetched objects caches for a list of results from a QuerySet """ if len(result_cache) == 0: return # nothing to do model = result_cache[0].__class__ # We need to be able to dynamically add to the list of prefetch_related # lookups that we look up (see below). So we need some book keeping to # ensure we don't do duplicate work. done_lookups = set() # list of lookups like foo__bar__baz done_queries = {} # dictionary of things like 'foo__bar': [results] auto_lookups = [] # we add to this as we go through. followed_descriptors = set() # recursion protection all_lookups = itertools.chain(related_lookups, auto_lookups) for lookup in all_lookups: if lookup in done_lookups: # We've done exactly this already, skip the whole thing continue done_lookups.add(lookup) # Top level, the list of objects to decorate is the result cache # from the primary QuerySet. It won't be for deeper levels. obj_list = result_cache attrs = lookup.split(LOOKUP_SEP) for level, attr in enumerate(attrs): # Prepare main instances if len(obj_list) == 0: break current_lookup = LOOKUP_SEP.join(attrs[0:level+1]) if current_lookup in done_queries: # Skip any prefetching, and any object preparation obj_list = done_queries[current_lookup] continue # Prepare objects: good_objects = True for obj in obj_list: # Since prefetching can re-use instances, it is possible to have # the same instance multiple times in obj_list, so obj might # already be prepared. if not hasattr(obj, '_prefetched_objects_cache'): try: obj._prefetched_objects_cache = {} except AttributeError: # Must be in a QuerySet subclass that is not returning # Model instances, either in Django or 3rd # party. prefetch_related() doesn't make sense, so quit # now. good_objects = False break if not good_objects: break # Descend down tree # We assume that objects retrieved are homogenous (which is the premise # of prefetch_related), so what applies to first object applies to all. first_obj = obj_list[0] prefetcher, descriptor, attr_found, is_fetched = get_prefetcher(first_obj, attr) if not attr_found: raise AttributeError("Cannot find '%s' on %s object, '%s' is an invalid " "parameter to prefetch_related()" % (attr, first_obj.__class__.__name__, lookup)) if level == len(attrs) - 1 and prefetcher is None: # Last one, this *must* resolve to something that supports # prefetching, otherwise there is no point adding it and the # developer asking for it has made a mistake. raise ValueError("'%s' does not resolve to a item that supports " "prefetching - this is an invalid parameter to " "prefetch_related()." % lookup) if prefetcher is not None and not is_fetched: obj_list, additional_prl = prefetch_one_level(obj_list, prefetcher, attr) # We need to ensure we don't keep adding lookups from the # same relationships to stop infinite recursion. So, if we # are already on an automatically added lookup, don't add # the new lookups from relationships we've seen already. if not (lookup in auto_lookups and descriptor in followed_descriptors): for f in additional_prl: new_prl = LOOKUP_SEP.join([current_lookup, f]) auto_lookups.append(new_prl) done_queries[current_lookup] = obj_list followed_descriptors.add(descriptor) else: # Either a singly related object that has already been fetched # (e.g. via select_related), or hopefully some other property # that doesn't support prefetching but needs to be traversed. # We replace the current list of parent objects with the list # of related objects, filtering out empty or missing values so # that we can continue with nullable or reverse relations. new_obj_list = [] for obj in obj_list: try: new_obj = getattr(obj, attr) except exceptions.ObjectDoesNotExist: continue if new_obj is None: continue new_obj_list.append(new_obj) obj_list = new_obj_list def get_prefetcher(instance, attr): """ For the attribute 'attr' on the given instance, finds an object that has a get_prefetch_query_set(). Returns a 4 tuple containing: (the object with get_prefetch_query_set (or None), the descriptor object representing this relationship (or None), a boolean that is False if the attribute was not found at all, a boolean that is True if the attribute has already been fetched) """ prefetcher = None attr_found = False is_fetched = False # For singly related objects, we have to avoid getting the attribute # from the object, as this will trigger the query. So we first try # on the class, in order to get the descriptor object. rel_obj_descriptor = getattr(instance.__class__, attr, None) if rel_obj_descriptor is None: try: rel_obj = getattr(instance, attr) attr_found = True except AttributeError: pass else: attr_found = True if rel_obj_descriptor: # singly related object, descriptor object has the # get_prefetch_query_set() method. if hasattr(rel_obj_descriptor, 'get_prefetch_query_set'): prefetcher = rel_obj_descriptor if rel_obj_descriptor.is_cached(instance): is_fetched = True else: # descriptor doesn't support prefetching, so we go ahead and get # the attribute on the instance rather than the class to # support many related managers rel_obj = getattr(instance, attr) if hasattr(rel_obj, 'get_prefetch_query_set'): prefetcher = rel_obj return prefetcher, rel_obj_descriptor, attr_found, is_fetched def prefetch_one_level(instances, prefetcher, attname): """ Helper function for prefetch_related_objects Runs prefetches on all instances using the prefetcher object, assigning results to relevant caches in instance. The prefetched objects are returned, along with any additional prefetches that must be done due to prefetch_related lookups found from default managers. """ # prefetcher must have a method get_prefetch_query_set() which takes a list # of instances, and returns a tuple: # (queryset of instances of self.model that are related to passed in instances, # callable that gets value to be matched for returned instances, # callable that gets value to be matched for passed in instances, # boolean that is True for singly related objects, # cache name to assign to). # The 'values to be matched' must be hashable as they will be used # in a dictionary. rel_qs, rel_obj_attr, instance_attr, single, cache_name =\ prefetcher.get_prefetch_query_set(instances) # We have to handle the possibility that the default manager itself added # prefetch_related lookups to the QuerySet we just got back. We don't want to # trigger the prefetch_related functionality by evaluating the query. # Rather, we need to merge in the prefetch_related lookups. additional_prl = getattr(rel_qs, '_prefetch_related_lookups', []) if additional_prl: # Don't need to clone because the manager should have given us a fresh # instance, so we access an internal instead of using public interface # for performance reasons. rel_qs._prefetch_related_lookups = [] all_related_objects = list(rel_qs) rel_obj_cache = {} for rel_obj in all_related_objects: rel_attr_val = rel_obj_attr(rel_obj) rel_obj_cache.setdefault(rel_attr_val, []).append(rel_obj) for obj in instances: instance_attr_val = instance_attr(obj) vals = rel_obj_cache.get(instance_attr_val, []) if single: # Need to assign to single cache on instance setattr(obj, cache_name, vals[0] if vals else None) else: # Multi, attribute represents a manager with an .all() method that # returns a QuerySet qs = getattr(obj, attname).all() qs._result_cache = vals # We don't want the individual qs doing prefetch_related now, since we # have merged this into the current work. qs._prefetch_done = True obj._prefetched_objects_cache[cache_name] = qs return all_related_objects, additional_prl
agpl-3.0
[ 624, 199, 1918, 2446, 18397, 4514, 14, 961, 6571, 314, 4575, 3261, 367, 314, 23383, 14, 199, 624, 199, 199, 646, 1331, 199, 646, 7975, 199, 646, 984, 199, 646, 3598, 199, 199, 504, 1639, 14, 1018, 492, 4967, 199, 504, 1639, 14, 697, 492, 6947, 12, 6197, 12, 6008, 12, 26864, 199, 504, 1639, 14, 697, 14, 992, 14, 5559, 492, 3412, 3593, 2160, 63, 20848, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 492, 9195, 792, 199, 504, 1639, 14, 697, 14, 992, 14, 1131, 63, 1208, 492, 334, 49, 12, 3504, 63, 2407, 63, 18180, 12, 272, 12309, 63, 533, 63, 3702, 12, 6378, 3227, 9, 199, 504, 1639, 14, 697, 14, 992, 14, 14281, 492, 3626, 3283, 199, 504, 1639, 14, 697, 14, 992, 492, 3875, 199, 504, 1639, 14, 1208, 14, 15481, 492, 6484, 199, 504, 1639, 14, 1208, 492, 3816, 199, 199, 3, 8051, 370, 3304, 4212, 5002, 2251, 787, 26731, 543, 737, 5403, 315, 2005, 5560, 334, 69, 14, 71, 14, 199, 3, 1380, 13794, 2251, 680, 199, 20512, 63, 4305, 275, 2948, 199, 11084, 63, 20512, 63, 4305, 275, 6624, 8019, 63, 4305, 199, 199, 3, 710, 5696, 1329, 402, 2974, 370, 2929, 315, 282, 18397, 855, 2722, 363, 199, 907, 3311, 63, 8414, 63, 4305, 275, 3388, 199, 199, 3, 27705, 1901, 642, 3231, 367, 8552, 7163, 14, 199, 4699, 21722, 275, 3875, 14, 4699, 21722, 199, 199, 533, 18397, 8, 785, 304, 272, 408, 272, 21591, 282, 9617, 3050, 4237, 367, 282, 663, 402, 2251, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 1402, 29, 403, 12, 1827, 29, 403, 12, 1808, 29, 403, 304, 267, 291, 14, 1238, 275, 1402, 267, 327, 9630, 13689, 9034, 2335, 18397, 543, 1402, 465, 488, 267, 291, 423, 697, 275, 1808, 267, 291, 14, 1131, 275, 1827, 503, 3875, 14, 3227, 8, 277, 14, 1238, 9, 267, 291, 423, 1099, 63, 1637, 275, 488, 267, 291, 423, 1661, 275, 488, 267, 291, 423, 27364, 63, 1541, 275, 756, 267, 291, 423, 509, 63, 952, 275, 756, 267, 291, 423, 15576, 63, 2407, 63, 17438, 275, 942, 267, 291, 423, 15576, 63, 4456, 275, 756, 267, 291, 423, 3159, 63, 2407, 63, 1462, 275, 1052, 263, 327, 469, 3369, 63, 698, 12, 469, 2051, 26, 4668, 63, 1113, 4863, 339, 11945, 272, 327, 18280, 23336, 27411, 3177, 327, 272, 11945, 339, 347, 636, 8293, 721, 277, 12, 11955, 304, 267, 408, 267, 577, 7840, 1331, 402, 282, 18397, 3181, 1133, 13904, 314, 2581, 267, 408, 267, 1559, 275, 291, 855, 533, 4533, 267, 367, 1022, 12, 86, 315, 291, 855, 807, 4343, 1744, 837, 288, 340, 1022, 315, 12331, 1661, 1673, 63, 1099, 63, 1637, 735, 355, 1559, 855, 807, 12298, 75, 61, 275, 488, 288, 587, 26, 355, 1559, 855, 807, 12298, 75, 61, 275, 1331, 14, 8293, 8, 86, 12, 11955, 9, 267, 372, 1559, 339, 347, 636, 16011, 721, 277, 304, 267, 408, 267, 22819, 314, 18397, 370, 506, 18731, 14, 267, 408, 267, 327, 18771, 314, 2581, 370, 506, 9999, 16460, 14, 267, 822, 8, 277, 9, 267, 1559, 63, 807, 275, 291, 855, 807, 4343, 1574, 342, 267, 1559, 63, 807, 8680, 1661, 418, 275, 488, 267, 1559, 63, 807, 8680, 3159, 63, 2407, 63, 1462, 418, 275, 1211, 8, 288, 334, 698, 14, 354, 12, 1139, 9, 367, 901, 12, 1139, 315, 291, 423, 3159, 63, 2407, 63, 1462, 14, 1744, 342, 267, 776, 267, 372, 1559, 63, 807, 339, 347, 636, 17212, 721, 277, 12, 1559, 63, 807, 304, 267, 1402, 275, 1559, 63, 807, 459, 1238, 418, 267, 340, 1402, 365, 488, 26, 288, 327, 340, 1402, 365, 488, 12, 2066, 291, 1077, 506, 2701, 6177, 436, 314, 4048, 288, 327, 2251, 886, 440, 17247, 14, 288, 1559, 63, 807, 8680, 3159, 63, 2407, 63, 1462, 418, 275, 1052, 267, 587, 26, 288, 3999, 275, 1402, 423, 2024, 288, 1559, 63, 807, 8680, 3159, 63, 2407, 63, 1462, 418, 275, 1211, 8, 355, 334, 3291, 14, 362, 63, 698, 8, 698, 14, 354, 340, 2688, 8, 698, 12, 283, 354, 358, 587, 901, 395, 1139, 9, 355, 367, 901, 12, 1139, 315, 1559, 63, 807, 8680, 3159, 63, 2407, 63, 1462, 2278, 1744, 342, 288, 776, 267, 291, 855, 807, 4343, 873, 8, 1113, 63, 807, 9, 339, 347, 636, 2722, 721, 277, 304, 267, 666, 275, 769, 8, 277, 1491, 907, 3311, 63, 8414, 63, 4305, 435, 413, 566, 267, 340, 822, 8, 576, 9, 690, 5363, 3311, 63, 8414, 63, 4305, 26, 288, 666, 1988, 17, 61, 275, 298, 1396, 8, 11266, 4008, 17661, 680, 703, 2, 267, 372, 4700, 8, 576, 9, 339, 347, 636, 552, 721, 277, 304, 267, 327, 9336, 636, 552, 363, 365, 2797, 18794, 28914, 590, 334, 509, 2893, 12, 465, 1777, 402, 267, 327, 769, 8, 6177, 395, 781, 1852, 2005, 28058, 2348, 370, 506, 465, 13402, 465, 3962, 267, 327, 704, 382, 270, 440, 15634, 316, 1536, 1263, 3411, 28241, 6169, 314, 18397, 14, 267, 340, 291, 423, 1099, 63, 1637, 365, 488, 26, 288, 340, 291, 423, 1661, 26, 355, 291, 423, 1099, 63, 1637, 275, 769, 8, 277, 423, 1661, 9, 288, 587, 26, 355, 291, 423, 1099, 63, 1637, 275, 769, 8, 277, 14, 5778, 1012, 267, 916, 291, 423, 1661, 26, 288, 291, 423, 1099, 63, 1637, 14, 2880, 8, 277, 423, 1661, 9, 267, 340, 291, 423, 15576, 63, 2407, 63, 17438, 436, 440, 291, 423, 15576, 63, 4456, 26, 288, 291, 423, 15576, 63, 2407, 63, 1462, 342, 267, 372, 822, 8, 277, 423, 1099, 63, 1637, 9, 339, 347, 636, 1661, 721, 277, 304, 267, 340, 291, 423, 15576, 63, 2407, 63, 17438, 436, 440, 291, 423, 15576, 63, 4456, 26, 288, 327, 2136, 1929, 1006, 314, 2058, 315, 1865, 370, 506, 7688, 370, 886, 314, 21544, 288, 327, 315, 1373, 2621, 14, 4005, 24720, 1233, 11866, 1863, 12, 781, 675, 314, 636, 552, 363, 288, 327, 1233, 931, 1314, 2597, 25983, 642, 12, 436, 2597, 1630, 314, 21544, 288, 822, 8, 277, 9, 398, 340, 291, 423, 1099, 63, 1637 ]
[ 199, 1918, 2446, 18397, 4514, 14, 961, 6571, 314, 4575, 3261, 367, 314, 23383, 14, 199, 624, 199, 199, 646, 1331, 199, 646, 7975, 199, 646, 984, 199, 646, 3598, 199, 199, 504, 1639, 14, 1018, 492, 4967, 199, 504, 1639, 14, 697, 492, 6947, 12, 6197, 12, 6008, 12, 26864, 199, 504, 1639, 14, 697, 14, 992, 14, 5559, 492, 3412, 3593, 2160, 63, 20848, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 492, 9195, 792, 199, 504, 1639, 14, 697, 14, 992, 14, 1131, 63, 1208, 492, 334, 49, 12, 3504, 63, 2407, 63, 18180, 12, 272, 12309, 63, 533, 63, 3702, 12, 6378, 3227, 9, 199, 504, 1639, 14, 697, 14, 992, 14, 14281, 492, 3626, 3283, 199, 504, 1639, 14, 697, 14, 992, 492, 3875, 199, 504, 1639, 14, 1208, 14, 15481, 492, 6484, 199, 504, 1639, 14, 1208, 492, 3816, 199, 199, 3, 8051, 370, 3304, 4212, 5002, 2251, 787, 26731, 543, 737, 5403, 315, 2005, 5560, 334, 69, 14, 71, 14, 199, 3, 1380, 13794, 2251, 680, 199, 20512, 63, 4305, 275, 2948, 199, 11084, 63, 20512, 63, 4305, 275, 6624, 8019, 63, 4305, 199, 199, 3, 710, 5696, 1329, 402, 2974, 370, 2929, 315, 282, 18397, 855, 2722, 363, 199, 907, 3311, 63, 8414, 63, 4305, 275, 3388, 199, 199, 3, 27705, 1901, 642, 3231, 367, 8552, 7163, 14, 199, 4699, 21722, 275, 3875, 14, 4699, 21722, 199, 199, 533, 18397, 8, 785, 304, 272, 408, 272, 21591, 282, 9617, 3050, 4237, 367, 282, 663, 402, 2251, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 1402, 29, 403, 12, 1827, 29, 403, 12, 1808, 29, 403, 304, 267, 291, 14, 1238, 275, 1402, 267, 327, 9630, 13689, 9034, 2335, 18397, 543, 1402, 465, 488, 267, 291, 423, 697, 275, 1808, 267, 291, 14, 1131, 275, 1827, 503, 3875, 14, 3227, 8, 277, 14, 1238, 9, 267, 291, 423, 1099, 63, 1637, 275, 488, 267, 291, 423, 1661, 275, 488, 267, 291, 423, 27364, 63, 1541, 275, 756, 267, 291, 423, 509, 63, 952, 275, 756, 267, 291, 423, 15576, 63, 2407, 63, 17438, 275, 942, 267, 291, 423, 15576, 63, 4456, 275, 756, 267, 291, 423, 3159, 63, 2407, 63, 1462, 275, 1052, 263, 327, 469, 3369, 63, 698, 12, 469, 2051, 26, 4668, 63, 1113, 4863, 339, 11945, 272, 327, 18280, 23336, 27411, 3177, 327, 272, 11945, 339, 347, 636, 8293, 721, 277, 12, 11955, 304, 267, 408, 267, 577, 7840, 1331, 402, 282, 18397, 3181, 1133, 13904, 314, 2581, 267, 408, 267, 1559, 275, 291, 855, 533, 4533, 267, 367, 1022, 12, 86, 315, 291, 855, 807, 4343, 1744, 837, 288, 340, 1022, 315, 12331, 1661, 1673, 63, 1099, 63, 1637, 735, 355, 1559, 855, 807, 12298, 75, 61, 275, 488, 288, 587, 26, 355, 1559, 855, 807, 12298, 75, 61, 275, 1331, 14, 8293, 8, 86, 12, 11955, 9, 267, 372, 1559, 339, 347, 636, 16011, 721, 277, 304, 267, 408, 267, 22819, 314, 18397, 370, 506, 18731, 14, 267, 408, 267, 327, 18771, 314, 2581, 370, 506, 9999, 16460, 14, 267, 822, 8, 277, 9, 267, 1559, 63, 807, 275, 291, 855, 807, 4343, 1574, 342, 267, 1559, 63, 807, 8680, 1661, 418, 275, 488, 267, 1559, 63, 807, 8680, 3159, 63, 2407, 63, 1462, 418, 275, 1211, 8, 288, 334, 698, 14, 354, 12, 1139, 9, 367, 901, 12, 1139, 315, 291, 423, 3159, 63, 2407, 63, 1462, 14, 1744, 342, 267, 776, 267, 372, 1559, 63, 807, 339, 347, 636, 17212, 721, 277, 12, 1559, 63, 807, 304, 267, 1402, 275, 1559, 63, 807, 459, 1238, 418, 267, 340, 1402, 365, 488, 26, 288, 327, 340, 1402, 365, 488, 12, 2066, 291, 1077, 506, 2701, 6177, 436, 314, 4048, 288, 327, 2251, 886, 440, 17247, 14, 288, 1559, 63, 807, 8680, 3159, 63, 2407, 63, 1462, 418, 275, 1052, 267, 587, 26, 288, 3999, 275, 1402, 423, 2024, 288, 1559, 63, 807, 8680, 3159, 63, 2407, 63, 1462, 418, 275, 1211, 8, 355, 334, 3291, 14, 362, 63, 698, 8, 698, 14, 354, 340, 2688, 8, 698, 12, 283, 354, 358, 587, 901, 395, 1139, 9, 355, 367, 901, 12, 1139, 315, 1559, 63, 807, 8680, 3159, 63, 2407, 63, 1462, 2278, 1744, 342, 288, 776, 267, 291, 855, 807, 4343, 873, 8, 1113, 63, 807, 9, 339, 347, 636, 2722, 721, 277, 304, 267, 666, 275, 769, 8, 277, 1491, 907, 3311, 63, 8414, 63, 4305, 435, 413, 566, 267, 340, 822, 8, 576, 9, 690, 5363, 3311, 63, 8414, 63, 4305, 26, 288, 666, 1988, 17, 61, 275, 298, 1396, 8, 11266, 4008, 17661, 680, 703, 2, 267, 372, 4700, 8, 576, 9, 339, 347, 636, 552, 721, 277, 304, 267, 327, 9336, 636, 552, 363, 365, 2797, 18794, 28914, 590, 334, 509, 2893, 12, 465, 1777, 402, 267, 327, 769, 8, 6177, 395, 781, 1852, 2005, 28058, 2348, 370, 506, 465, 13402, 465, 3962, 267, 327, 704, 382, 270, 440, 15634, 316, 1536, 1263, 3411, 28241, 6169, 314, 18397, 14, 267, 340, 291, 423, 1099, 63, 1637, 365, 488, 26, 288, 340, 291, 423, 1661, 26, 355, 291, 423, 1099, 63, 1637, 275, 769, 8, 277, 423, 1661, 9, 288, 587, 26, 355, 291, 423, 1099, 63, 1637, 275, 769, 8, 277, 14, 5778, 1012, 267, 916, 291, 423, 1661, 26, 288, 291, 423, 1099, 63, 1637, 14, 2880, 8, 277, 423, 1661, 9, 267, 340, 291, 423, 15576, 63, 2407, 63, 17438, 436, 440, 291, 423, 15576, 63, 4456, 26, 288, 291, 423, 15576, 63, 2407, 63, 1462, 342, 267, 372, 822, 8, 277, 423, 1099, 63, 1637, 9, 339, 347, 636, 1661, 721, 277, 304, 267, 340, 291, 423, 15576, 63, 2407, 63, 17438, 436, 440, 291, 423, 15576, 63, 4456, 26, 288, 327, 2136, 1929, 1006, 314, 2058, 315, 1865, 370, 506, 7688, 370, 886, 314, 21544, 288, 327, 315, 1373, 2621, 14, 4005, 24720, 1233, 11866, 1863, 12, 781, 675, 314, 636, 552, 363, 288, 327, 1233, 931, 1314, 2597, 25983, 642, 12, 436, 2597, 1630, 314, 21544, 288, 822, 8, 277, 9, 398, 340, 291, 423, 1099, 63, 1637, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
w1ll1am23/home-assistant
tests/components/homekit_controller/test_device_trigger.py
5
9761
"""Test homekit_controller stateless triggers.""" from aiohomekit.model.characteristics import CharacteristicsTypes from aiohomekit.model.services import ServicesTypes import pytest import homeassistant.components.automation as automation from homeassistant.components.homekit_controller.const import DOMAIN from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component from tests.common import ( assert_lists_same, async_get_device_automations, async_mock_service, ) from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.homekit_controller.common import setup_test_component # pylint: disable=redefined-outer-name @pytest.fixture def calls(hass): """Track calls to a mock service.""" return async_mock_service(hass, "test", "automation") def create_remote(accessory): """Define characteristics for a button (that is inn a group).""" service_label = accessory.add_service(ServicesTypes.SERVICE_LABEL) char = service_label.add_char(CharacteristicsTypes.SERVICE_LABEL_NAMESPACE) char.value = 1 for i in range(4): button = accessory.add_service(ServicesTypes.STATELESS_PROGRAMMABLE_SWITCH) button.linked.append(service_label) char = button.add_char(CharacteristicsTypes.INPUT_EVENT) char.value = 0 char.perms = ["pw", "pr", "ev"] char = button.add_char(CharacteristicsTypes.NAME) char.value = f"Button {i + 1}" char = button.add_char(CharacteristicsTypes.SERVICE_LABEL_INDEX) char.value = i battery = accessory.add_service(ServicesTypes.BATTERY_SERVICE) battery.add_char(CharacteristicsTypes.BATTERY_LEVEL) def create_button(accessory): """Define a button (that is not in a group).""" button = accessory.add_service(ServicesTypes.STATELESS_PROGRAMMABLE_SWITCH) char = button.add_char(CharacteristicsTypes.INPUT_EVENT) char.value = 0 char.perms = ["pw", "pr", "ev"] char = button.add_char(CharacteristicsTypes.NAME) char.value = "Button 1" battery = accessory.add_service(ServicesTypes.BATTERY_SERVICE) battery.add_char(CharacteristicsTypes.BATTERY_LEVEL) def create_doorbell(accessory): """Define a button (that is not in a group).""" button = accessory.add_service(ServicesTypes.DOORBELL) char = button.add_char(CharacteristicsTypes.INPUT_EVENT) char.value = 0 char.perms = ["pw", "pr", "ev"] char = button.add_char(CharacteristicsTypes.NAME) char.value = "Doorbell" battery = accessory.add_service(ServicesTypes.BATTERY_SERVICE) battery.add_char(CharacteristicsTypes.BATTERY_LEVEL) async def test_enumerate_remote(hass, utcnow): """Test that remote is correctly enumerated.""" await setup_test_component(hass, create_remote) entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.testdevice_battery") device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) expected = [ { "device_id": device.id, "domain": "sensor", "entity_id": "sensor.testdevice_battery", "platform": "device", "type": "battery_level", } ] for button in ("button1", "button2", "button3", "button4"): for subtype in ("single_press", "double_press", "long_press"): expected.append( { "device_id": device.id, "domain": "homekit_controller", "platform": "device", "type": button, "subtype": subtype, } ) triggers = await async_get_device_automations(hass, "trigger", device.id) assert_lists_same(triggers, expected) async def test_enumerate_button(hass, utcnow): """Test that a button is correctly enumerated.""" await setup_test_component(hass, create_button) entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.testdevice_battery") device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) expected = [ { "device_id": device.id, "domain": "sensor", "entity_id": "sensor.testdevice_battery", "platform": "device", "type": "battery_level", } ] for subtype in ("single_press", "double_press", "long_press"): expected.append( { "device_id": device.id, "domain": "homekit_controller", "platform": "device", "type": "button1", "subtype": subtype, } ) triggers = await async_get_device_automations(hass, "trigger", device.id) assert_lists_same(triggers, expected) async def test_enumerate_doorbell(hass, utcnow): """Test that a button is correctly enumerated.""" await setup_test_component(hass, create_doorbell) entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.testdevice_battery") device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) expected = [ { "device_id": device.id, "domain": "sensor", "entity_id": "sensor.testdevice_battery", "platform": "device", "type": "battery_level", } ] for subtype in ("single_press", "double_press", "long_press"): expected.append( { "device_id": device.id, "domain": "homekit_controller", "platform": "device", "type": "doorbell", "subtype": subtype, } ) triggers = await async_get_device_automations(hass, "trigger", device.id) assert_lists_same(triggers, expected) async def test_handle_events(hass, utcnow, calls): """Test that events are handled.""" helper = await setup_test_component(hass, create_remote) entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.testdevice_battery") device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert await async_setup_component( hass, automation.DOMAIN, { automation.DOMAIN: [ { "alias": "single_press", "trigger": { "platform": "device", "domain": DOMAIN, "device_id": device.id, "type": "button1", "subtype": "single_press", }, "action": { "service": "test.automation", "data_template": { "some": ( "{{ trigger.platform}} - " "{{ trigger.type }} - {{ trigger.subtype }} - " "{{ trigger.id }}" ) }, }, }, { "alias": "long_press", "trigger": { "platform": "device", "domain": DOMAIN, "device_id": device.id, "type": "button2", "subtype": "long_press", }, "action": { "service": "test.automation", "data_template": { "some": ( "{{ trigger.platform}} - " "{{ trigger.type }} - {{ trigger.subtype }} - " "{{ trigger.id }}" ) }, }, }, ] }, ) # Make sure first automation (only) fires for single press helper.pairing.testing.update_named_service( "Button 1", {CharacteristicsTypes.INPUT_EVENT: 0} ) await hass.async_block_till_done() assert len(calls) == 1 assert calls[0].data["some"] == "device - button1 - single_press - 0" # Make sure automation doesn't trigger for long press helper.pairing.testing.update_named_service( "Button 1", {CharacteristicsTypes.INPUT_EVENT: 1} ) await hass.async_block_till_done() assert len(calls) == 1 # Make sure automation doesn't trigger for double press helper.pairing.testing.update_named_service( "Button 1", {CharacteristicsTypes.INPUT_EVENT: 2} ) await hass.async_block_till_done() assert len(calls) == 1 # Make sure second automation fires for long press helper.pairing.testing.update_named_service( "Button 2", {CharacteristicsTypes.INPUT_EVENT: 2} ) await hass.async_block_till_done() assert len(calls) == 2 assert calls[1].data["some"] == "device - button2 - long_press - 0" # Turn the automations off await hass.services.async_call( "automation", "turn_off", {"entity_id": "automation.long_press"}, blocking=True, ) await hass.services.async_call( "automation", "turn_off", {"entity_id": "automation.single_press"}, blocking=True, ) # Make sure event no longer fires helper.pairing.testing.update_named_service( "Button 2", {CharacteristicsTypes.INPUT_EVENT: 2} ) await hass.async_block_till_done() assert len(calls) == 2
apache-2.0
[ 624, 774, 5629, 6065, 63, 5538, 1174, 2003, 18899, 1041, 199, 504, 282, 2308, 4219, 6065, 14, 1238, 14, 1560, 29867, 492, 6659, 29867, 4100, 199, 504, 282, 2308, 4219, 6065, 14, 1238, 14, 5950, 492, 21813, 4100, 199, 646, 4613, 199, 199, 646, 8846, 14, 4608, 14, 23867, 465, 25461, 199, 504, 8846, 14, 4608, 14, 4219, 6065, 63, 5538, 14, 1297, 492, 15265, 199, 504, 8846, 14, 7546, 492, 2243, 63, 5189, 465, 16642, 12, 4642, 63, 5189, 465, 9266, 199, 504, 8846, 14, 2758, 492, 5316, 63, 2758, 63, 3173, 199, 199, 504, 2295, 14, 2330, 492, 334, 272, 702, 63, 6717, 63, 7191, 12, 272, 5316, 63, 362, 63, 1782, 63, 2495, 21953, 12, 272, 5316, 63, 1805, 63, 1364, 12, 199, 9, 199, 504, 2295, 14, 4608, 14, 15918, 14, 22454, 492, 10098, 63, 15918, 63, 13817, 221, 327, 8151, 26, 481, 8854, 199, 504, 2295, 14, 4608, 14, 4219, 6065, 63, 5538, 14, 2330, 492, 3272, 63, 396, 63, 3173, 421, 199, 3, 4287, 26, 3507, 29, 27913, 13, 7837, 13, 354, 199, 32, 4462, 14, 5997, 199, 318, 4882, 8, 5387, 304, 272, 408, 7927, 4882, 370, 282, 1683, 2435, 1041, 272, 372, 5316, 63, 1805, 63, 1364, 8, 5387, 12, 298, 396, 401, 298, 23867, 531, 421, 199, 318, 1218, 63, 3846, 8, 2732, 1089, 304, 272, 408, 16213, 2735, 6236, 8323, 367, 282, 5528, 334, 9099, 365, 315, 78, 282, 1572, 10477, 272, 2435, 63, 1302, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 10486, 63, 13837, 9, 339, 1495, 275, 2435, 63, 1302, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 10486, 63, 13837, 63, 13001, 9, 272, 1495, 14, 585, 275, 413, 339, 367, 284, 315, 1425, 8, 20, 304, 267, 5528, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 6689, 30928, 63, 15605, 45, 2617, 63, 18079, 9, 267, 5528, 14, 12751, 14, 740, 8, 1364, 63, 1302, 9, 398, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 7321, 63, 8193, 9, 267, 1495, 14, 585, 275, 378, 267, 1495, 14, 12068, 275, 2097, 8796, 401, 298, 2700, 401, 298, 6857, 937, 398, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 2339, 9, 267, 1495, 14, 585, 275, 289, 2, 4259, 469, 73, 435, 413, 7063, 398, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 10486, 63, 13837, 63, 10215, 9, 267, 1495, 14, 585, 275, 284, 339, 330, 13891, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 28839, 1157, 57, 63, 10486, 9, 272, 330, 13891, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 28839, 1157, 57, 63, 11817, 9, 421, 199, 318, 1218, 63, 3887, 8, 2732, 1089, 304, 272, 408, 16213, 282, 5528, 334, 9099, 365, 440, 315, 282, 1572, 10477, 272, 5528, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 6689, 30928, 63, 15605, 45, 2617, 63, 18079, 9, 339, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 7321, 63, 8193, 9, 272, 1495, 14, 585, 275, 378, 272, 1495, 14, 12068, 275, 2097, 8796, 401, 298, 2700, 401, 298, 6857, 937, 339, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 2339, 9, 272, 1495, 14, 585, 275, 298, 4259, 413, 2, 339, 330, 13891, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 28839, 1157, 57, 63, 10486, 9, 272, 330, 13891, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 28839, 1157, 57, 63, 11817, 9, 421, 199, 318, 1218, 63, 20842, 30930, 8, 2732, 1089, 304, 272, 408, 16213, 282, 5528, 334, 9099, 365, 440, 315, 282, 1572, 10477, 272, 5528, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 1649, 726, 34, 14952, 9, 339, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 7321, 63, 8193, 9, 272, 1495, 14, 585, 275, 378, 272, 1495, 14, 12068, 275, 2097, 8796, 401, 298, 2700, 401, 298, 6857, 937, 339, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 2339, 9, 272, 1495, 14, 585, 275, 298, 2585, 269, 30930, 2, 339, 330, 13891, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 28839, 1157, 57, 63, 10486, 9, 272, 330, 13891, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 28839, 1157, 57, 63, 11817, 9, 421, 199, 4146, 347, 511, 63, 26318, 63, 3846, 8, 5387, 12, 221, 10779, 304, 272, 408, 774, 626, 3982, 365, 6657, 3720, 12601, 1041, 272, 5517, 3272, 63, 396, 63, 3173, 8, 5387, 12, 1218, 63, 3846, 9, 339, 4642, 63, 5189, 275, 9266, 14, 4146, 63, 362, 8, 5387, 9, 272, 2397, 275, 4642, 63, 5189, 14, 4146, 63, 362, 480, 8956, 14, 396, 1782, 63, 21113, 531, 339, 2243, 63, 5189, 275, 16642, 14, 4146, 63, 362, 8, 5387, 9, 272, 2243, 275, 2243, 63, 5189, 14, 4146, 63, 362, 8, 2373, 14, 1782, 63, 344, 9, 339, 1420, 275, 359, 267, 469, 288, 298, 1782, 63, 344, 582, 2243, 14, 344, 12, 288, 298, 2261, 582, 298, 8956, 401, 288, 298, 4502, 63, 344, 582, 298, 8956, 14, 396, 1782, 63, 21113, 401, 288, 298, 3246, 582, 298, 1782, 401, 288, 298, 466, 582, 298, 21113, 63, 1896, 401, 267, 789, 272, 1622, 339, 367, 5528, 315, 1689, 3887, 17, 401, 298, 3887, 18, 401, 298, 3887, 19, 401, 298, 3887, 20, 2349, 267, 367, 15686, 315, 1689, 4780, 63, 2915, 401, 298, 3157, 63, 2915, 401, 298, 2809, 63, 2915, 2349, 288, 1420, 14, 740, 8, 355, 469, 490, 298, 1782, 63, 344, 582, 2243, 14, 344, 12, 490, 298, 2261, 582, 298, 4219, 6065, 63, 5538, 401, 490, 298, 3246, 582, 298, 1782, 401, 490, 298, 466, 582, 5528, 12, 490, 298, 10512, 582, 15686, 12, 355, 789, 288, 776, 339, 18899, 275, 5517, 5316, 63, 362, 63, 1782, 63, 2495, 21953, 8, 5387, 12, 298, 7631, 401, 2243, 14, 344, 9, 272, 702, 63, 6717, 63, 7191, 8, 26328, 12, 1420, 9, 421, 199, 4146 ]
[ 774, 5629, 6065, 63, 5538, 1174, 2003, 18899, 1041, 199, 504, 282, 2308, 4219, 6065, 14, 1238, 14, 1560, 29867, 492, 6659, 29867, 4100, 199, 504, 282, 2308, 4219, 6065, 14, 1238, 14, 5950, 492, 21813, 4100, 199, 646, 4613, 199, 199, 646, 8846, 14, 4608, 14, 23867, 465, 25461, 199, 504, 8846, 14, 4608, 14, 4219, 6065, 63, 5538, 14, 1297, 492, 15265, 199, 504, 8846, 14, 7546, 492, 2243, 63, 5189, 465, 16642, 12, 4642, 63, 5189, 465, 9266, 199, 504, 8846, 14, 2758, 492, 5316, 63, 2758, 63, 3173, 199, 199, 504, 2295, 14, 2330, 492, 334, 272, 702, 63, 6717, 63, 7191, 12, 272, 5316, 63, 362, 63, 1782, 63, 2495, 21953, 12, 272, 5316, 63, 1805, 63, 1364, 12, 199, 9, 199, 504, 2295, 14, 4608, 14, 15918, 14, 22454, 492, 10098, 63, 15918, 63, 13817, 221, 327, 8151, 26, 481, 8854, 199, 504, 2295, 14, 4608, 14, 4219, 6065, 63, 5538, 14, 2330, 492, 3272, 63, 396, 63, 3173, 421, 199, 3, 4287, 26, 3507, 29, 27913, 13, 7837, 13, 354, 199, 32, 4462, 14, 5997, 199, 318, 4882, 8, 5387, 304, 272, 408, 7927, 4882, 370, 282, 1683, 2435, 1041, 272, 372, 5316, 63, 1805, 63, 1364, 8, 5387, 12, 298, 396, 401, 298, 23867, 531, 421, 199, 318, 1218, 63, 3846, 8, 2732, 1089, 304, 272, 408, 16213, 2735, 6236, 8323, 367, 282, 5528, 334, 9099, 365, 315, 78, 282, 1572, 10477, 272, 2435, 63, 1302, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 10486, 63, 13837, 9, 339, 1495, 275, 2435, 63, 1302, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 10486, 63, 13837, 63, 13001, 9, 272, 1495, 14, 585, 275, 413, 339, 367, 284, 315, 1425, 8, 20, 304, 267, 5528, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 6689, 30928, 63, 15605, 45, 2617, 63, 18079, 9, 267, 5528, 14, 12751, 14, 740, 8, 1364, 63, 1302, 9, 398, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 7321, 63, 8193, 9, 267, 1495, 14, 585, 275, 378, 267, 1495, 14, 12068, 275, 2097, 8796, 401, 298, 2700, 401, 298, 6857, 937, 398, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 2339, 9, 267, 1495, 14, 585, 275, 289, 2, 4259, 469, 73, 435, 413, 7063, 398, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 10486, 63, 13837, 63, 10215, 9, 267, 1495, 14, 585, 275, 284, 339, 330, 13891, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 28839, 1157, 57, 63, 10486, 9, 272, 330, 13891, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 28839, 1157, 57, 63, 11817, 9, 421, 199, 318, 1218, 63, 3887, 8, 2732, 1089, 304, 272, 408, 16213, 282, 5528, 334, 9099, 365, 440, 315, 282, 1572, 10477, 272, 5528, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 6689, 30928, 63, 15605, 45, 2617, 63, 18079, 9, 339, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 7321, 63, 8193, 9, 272, 1495, 14, 585, 275, 378, 272, 1495, 14, 12068, 275, 2097, 8796, 401, 298, 2700, 401, 298, 6857, 937, 339, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 2339, 9, 272, 1495, 14, 585, 275, 298, 4259, 413, 2, 339, 330, 13891, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 28839, 1157, 57, 63, 10486, 9, 272, 330, 13891, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 28839, 1157, 57, 63, 11817, 9, 421, 199, 318, 1218, 63, 20842, 30930, 8, 2732, 1089, 304, 272, 408, 16213, 282, 5528, 334, 9099, 365, 440, 315, 282, 1572, 10477, 272, 5528, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 1649, 726, 34, 14952, 9, 339, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 7321, 63, 8193, 9, 272, 1495, 14, 585, 275, 378, 272, 1495, 14, 12068, 275, 2097, 8796, 401, 298, 2700, 401, 298, 6857, 937, 339, 1495, 275, 5528, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 2339, 9, 272, 1495, 14, 585, 275, 298, 2585, 269, 30930, 2, 339, 330, 13891, 275, 2879, 1089, 14, 525, 63, 1364, 8, 15803, 4100, 14, 28839, 1157, 57, 63, 10486, 9, 272, 330, 13891, 14, 525, 63, 1560, 8, 1610, 29867, 4100, 14, 28839, 1157, 57, 63, 11817, 9, 421, 199, 4146, 347, 511, 63, 26318, 63, 3846, 8, 5387, 12, 221, 10779, 304, 272, 408, 774, 626, 3982, 365, 6657, 3720, 12601, 1041, 272, 5517, 3272, 63, 396, 63, 3173, 8, 5387, 12, 1218, 63, 3846, 9, 339, 4642, 63, 5189, 275, 9266, 14, 4146, 63, 362, 8, 5387, 9, 272, 2397, 275, 4642, 63, 5189, 14, 4146, 63, 362, 480, 8956, 14, 396, 1782, 63, 21113, 531, 339, 2243, 63, 5189, 275, 16642, 14, 4146, 63, 362, 8, 5387, 9, 272, 2243, 275, 2243, 63, 5189, 14, 4146, 63, 362, 8, 2373, 14, 1782, 63, 344, 9, 339, 1420, 275, 359, 267, 469, 288, 298, 1782, 63, 344, 582, 2243, 14, 344, 12, 288, 298, 2261, 582, 298, 8956, 401, 288, 298, 4502, 63, 344, 582, 298, 8956, 14, 396, 1782, 63, 21113, 401, 288, 298, 3246, 582, 298, 1782, 401, 288, 298, 466, 582, 298, 21113, 63, 1896, 401, 267, 789, 272, 1622, 339, 367, 5528, 315, 1689, 3887, 17, 401, 298, 3887, 18, 401, 298, 3887, 19, 401, 298, 3887, 20, 2349, 267, 367, 15686, 315, 1689, 4780, 63, 2915, 401, 298, 3157, 63, 2915, 401, 298, 2809, 63, 2915, 2349, 288, 1420, 14, 740, 8, 355, 469, 490, 298, 1782, 63, 344, 582, 2243, 14, 344, 12, 490, 298, 2261, 582, 298, 4219, 6065, 63, 5538, 401, 490, 298, 3246, 582, 298, 1782, 401, 490, 298, 466, 582, 5528, 12, 490, 298, 10512, 582, 15686, 12, 355, 789, 288, 776, 339, 18899, 275, 5517, 5316, 63, 362, 63, 1782, 63, 2495, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
jelmer/samba
python/samba/tests/samba_tool/base.py
36
4702
# Unix SMB/CIFS implementation. # Copyright (C) Sean Dague <sdague@linux.vnet.ibm.com> 2011 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # This provides a wrapper around the cmd interface so that tests can # easily be built on top of it and have minimal code to run basic tests # of the commands. A list of the environmental variables can be found in # ~/selftest/selftest.pl # # These can all be accesses via os.environ["VARIBLENAME"] when needed import random import string from samba.auth import system_session from samba.samdb import SamDB from cStringIO import StringIO from samba.netcmd.main import cmd_sambatool import samba.tests class SambaToolCmdTest(samba.tests.TestCaseInTempDir): def getSamDB(self, *argv): """a convenience function to get a samdb instance so that we can query it""" # We build a fake command to get the options created the same # way the command classes do it. It would be better if the command # classes had a way to more cleanly do this, but this lets us write # tests for now cmd = cmd_sambatool.subcommands["user"].subcommands["setexpiry"] parser, optiongroups = cmd._create_parser("user") opts, args = parser.parse_args(list(argv)) # Filter out options from option groups args = args[1:] kwargs = dict(opts.__dict__) for option_group in parser.option_groups: for option in option_group.option_list: if option.dest is not None: del kwargs[option.dest] kwargs.update(optiongroups) H = kwargs.get("H", None) sambaopts = kwargs.get("sambaopts", None) credopts = kwargs.get("credopts", None) lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True) samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) return samdb def runcmd(self, name, *args): """run a single level command""" cmd = cmd_sambatool.subcommands[name] cmd.outf = StringIO() cmd.errf = StringIO() result = cmd._run(name, *args) return (result, cmd.outf.getvalue(), cmd.errf.getvalue()) def runsubcmd(self, name, sub, *args): """run a command with sub commands""" # The reason we need this function separate from runcmd is # that the .outf StringIO assignment is overriden if we use # runcmd, so we can't capture stdout and stderr cmd = cmd_sambatool.subcommands[name].subcommands[sub] cmd.outf = StringIO() cmd.errf = StringIO() result = cmd._run(name, *args) return (result, cmd.outf.getvalue(), cmd.errf.getvalue()) def assertCmdSuccess(self, val, msg=""): self.assertIsNone(val, msg) def assertCmdFail(self, val, msg=""): self.assertIsNotNone(val, msg) def assertMatch(self, base, string, msg=""): self.assertTrue(string in base, msg) def randomName(self, count=8): """Create a random name, cap letters and numbers, and always starting with a letter""" name = random.choice(string.ascii_uppercase) name += ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase+ string.digits) for x in range(count - 1)) return name def randomPass(self, count=16): name = random.choice(string.ascii_uppercase) name += random.choice(string.digits) name += random.choice(string.ascii_lowercase) name += ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase+ string.digits) for x in range(count - 3)) return name def randomXid(self): # pick some hopefully unused, high UID/GID range to avoid interference # from the system the test runs on xid = random.randint(4711000, 4799000) return xid def assertWithin(self, val1, val2, delta, msg=""): """Assert that val1 is within delta of val2, useful for time computations""" self.assertTrue(((val1 + delta) > val2) and ((val1 - delta) < val2), msg)
gpl-3.0
[ 3, 13074, 2389, 34, 15, 3553, 7079, 4514, 14, 199, 3, 1898, 334, 35, 9, 3240, 290, 26110, 310, 665, 3893, 30904, 32, 5135, 14, 86, 846, 14, 19870, 14, 957, 30, 7760, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 961, 6571, 282, 4975, 6818, 314, 2088, 3217, 880, 626, 2295, 883, 199, 3, 16174, 506, 6137, 641, 2746, 402, 652, 436, 1172, 13460, 1233, 370, 1255, 5678, 2295, 199, 3, 402, 314, 3718, 14, 437, 769, 402, 314, 3734, 279, 2860, 883, 506, 1911, 315, 199, 3, 6146, 15, 277, 396, 15, 277, 396, 14, 1168, 199, 3, 199, 3, 5723, 883, 1006, 506, 1066, 5804, 4799, 747, 14, 2314, 905, 5568, 2100, 5304, 1991, 937, 1380, 4346, 199, 199, 646, 2196, 199, 646, 1059, 199, 504, 31710, 14, 1178, 492, 2656, 63, 1730, 199, 504, 31710, 14, 21660, 697, 492, 428, 455, 2846, 199, 504, 15073, 492, 5228, 199, 504, 31710, 14, 846, 1760, 14, 973, 492, 2088, 63, 83, 11020, 11318, 393, 199, 646, 31710, 14, 2219, 199, 199, 533, 428, 14310, 5157, 7874, 774, 8, 21693, 14, 2219, 14, 1746, 607, 29008, 304, 339, 347, 664, 51, 455, 2846, 8, 277, 12, 627, 3020, 304, 267, 408, 65, 16777, 805, 370, 664, 282, 31626, 697, 1256, 880, 626, 781, 883, 1827, 652, 624, 398, 327, 2136, 1900, 282, 4026, 1414, 370, 664, 314, 1511, 2737, 314, 2011, 267, 327, 4340, 314, 1414, 3992, 886, 652, 14, 2779, 3955, 506, 8034, 340, 314, 1414, 267, 327, 3992, 10530, 282, 4340, 370, 1655, 3633, 590, 886, 642, 12, 1325, 642, 19083, 2739, 2218, 267, 327, 2295, 367, 3063, 267, 2088, 275, 2088, 63, 83, 11020, 11318, 393, 14, 954, 4405, 905, 751, 4140, 954, 4405, 905, 261, 3858, 1038, 651, 937, 267, 1798, 12, 945, 2634, 275, 2088, 423, 981, 63, 2087, 480, 751, 531, 267, 3999, 12, 1249, 275, 1798, 14, 1122, 63, 589, 8, 513, 8, 3020, 430, 267, 327, 9388, 734, 1511, 687, 945, 4652, 267, 1249, 275, 1249, 59, 17, 2938, 267, 2074, 275, 1211, 8, 3291, 855, 807, 3368, 267, 367, 945, 63, 923, 315, 1798, 14, 1422, 63, 2634, 26, 288, 367, 945, 315, 945, 63, 923, 14, 1422, 63, 513, 26, 355, 340, 945, 14, 2614, 365, 440, 488, 26, 490, 2150, 2074, 59, 1422, 14, 2614, 61, 267, 2074, 14, 873, 8, 1422, 2634, 9, 398, 869, 275, 2074, 14, 362, 480, 40, 401, 488, 9, 267, 31710, 3291, 275, 2074, 14, 362, 480, 21693, 3291, 401, 488, 9, 267, 22314, 3291, 275, 2074, 14, 362, 480, 18639, 3291, 401, 488, 9, 398, 13204, 275, 31710, 3291, 14, 362, 63, 912, 22176, 342, 267, 20023, 275, 22314, 3291, 14, 362, 63, 6942, 8, 10343, 12, 9567, 63, 6744, 29, 549, 9, 398, 31626, 697, 275, 428, 455, 2846, 8, 633, 29, 40, 12, 2351, 63, 815, 29, 2253, 63, 1730, 1062, 1993, 6235, 29, 15226, 12, 13204, 29, 10343, 9, 267, 372, 31626, 697, 2378, 347, 519, 1097, 1064, 8, 277, 12, 536, 12, 627, 589, 304, 267, 408, 1065, 282, 2849, 2166, 1414, 624, 267, 2088, 275, 2088, 63, 83, 11020, 11318, 393, 14, 954, 4405, 59, 354, 61, 267, 2088, 14, 548, 70, 275, 5228, 342, 267, 2088, 14, 1508, 70, 275, 5228, 342, 267, 754, 275, 2088, 423, 1065, 8, 354, 12, 627, 589, 9, 267, 372, 334, 1099, 12, 2088, 14, 548, 70, 14, 7150, 1062, 2088, 14, 1508, 70, 14, 7150, 1012, 339, 347, 1255, 954, 1760, 8, 277, 12, 536, 12, 1007, 12, 627, 589, 304, 267, 408, 1065, 282, 1414, 543, 1007, 3718, 624, 267, 327, 710, 4499, 781, 1929, 642, 805, 7396, 687, 519, 1097, 1064, 365, 267, 327, 626, 314, 1275, 548, 70, 5228, 9801, 365, 1806, 25045, 340, 781, 675, 267, 327, 519, 1097, 1064, 12, 880, 781, 883, 1133, 12296, 3839, 436, 4635, 267, 2088, 275, 2088, 63, 83, 11020, 11318, 393, 14, 954, 4405, 59, 354, 1055, 954, 4405, 59, 954, 61, 267, 2088, 14, 548, 70, 275, 5228, 342, 267, 2088, 14, 1508, 70, 275, 5228, 342, 267, 754, 275, 2088, 423, 1065, 8, 354, 12, 627, 589, 9, 267, 372, 334, 1099, 12, 2088, 14, 548, 70, 14, 7150, 1062, 2088, 14, 1508, 70, 14, 7150, 1012, 339, 347, 702, 7874, 8300, 8, 277, 12, 1139, 12, 1499, 17364, 267, 291, 14, 7702, 8, 637, 12, 1499, 9, 339, 347, 702, 7874, 4874, 8, 277, 12, 1139, 12, 1499, 17364, 267, 291, 14, 10389, 8, 637, 12, 1499, 9, 339, 347, 702, 4486, 8, 277, 12, 1300, 12, 1059, 12, 1499, 17364, 267, 291, 14, 1815, 8, 875, 315, 1300, 12, 1499, 9, 339, 347, 2196, 985, 8, 277, 12, 2338, 29, 24, 304, 267, 408, 2499, 282, 2196, 536, 12, 4021, 14435, 436, 5579, 12, 436, 3544, 6617, 543, 282, 8082, 624, 267, 536, 275, 2196, 14, 5095, 8, 875, 14, 4371, 63, 26831, 9, 267, 536, 847, 6522, 904, 8, 2355, 14, 5095, 8, 875, 14, 4371, 63, 26831, 435, 1059, 14, 4371, 63, 21636, 11, 1059, 14, 7022, 9, 367, 671, 315, 1425, 8, 835, 446, 413, 430, 267, 372, 536, 339, 347, 2196, 4986, 8, 277, 12, 2338, 29, 975, 304, 267, 536, 275, 2196, 14, 5095, 8, 875 ]
[ 13074, 2389, 34, 15, 3553, 7079, 4514, 14, 199, 3, 1898, 334, 35, 9, 3240, 290, 26110, 310, 665, 3893, 30904, 32, 5135, 14, 86, 846, 14, 19870, 14, 957, 30, 7760, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 961, 6571, 282, 4975, 6818, 314, 2088, 3217, 880, 626, 2295, 883, 199, 3, 16174, 506, 6137, 641, 2746, 402, 652, 436, 1172, 13460, 1233, 370, 1255, 5678, 2295, 199, 3, 402, 314, 3718, 14, 437, 769, 402, 314, 3734, 279, 2860, 883, 506, 1911, 315, 199, 3, 6146, 15, 277, 396, 15, 277, 396, 14, 1168, 199, 3, 199, 3, 5723, 883, 1006, 506, 1066, 5804, 4799, 747, 14, 2314, 905, 5568, 2100, 5304, 1991, 937, 1380, 4346, 199, 199, 646, 2196, 199, 646, 1059, 199, 504, 31710, 14, 1178, 492, 2656, 63, 1730, 199, 504, 31710, 14, 21660, 697, 492, 428, 455, 2846, 199, 504, 15073, 492, 5228, 199, 504, 31710, 14, 846, 1760, 14, 973, 492, 2088, 63, 83, 11020, 11318, 393, 199, 646, 31710, 14, 2219, 199, 199, 533, 428, 14310, 5157, 7874, 774, 8, 21693, 14, 2219, 14, 1746, 607, 29008, 304, 339, 347, 664, 51, 455, 2846, 8, 277, 12, 627, 3020, 304, 267, 408, 65, 16777, 805, 370, 664, 282, 31626, 697, 1256, 880, 626, 781, 883, 1827, 652, 624, 398, 327, 2136, 1900, 282, 4026, 1414, 370, 664, 314, 1511, 2737, 314, 2011, 267, 327, 4340, 314, 1414, 3992, 886, 652, 14, 2779, 3955, 506, 8034, 340, 314, 1414, 267, 327, 3992, 10530, 282, 4340, 370, 1655, 3633, 590, 886, 642, 12, 1325, 642, 19083, 2739, 2218, 267, 327, 2295, 367, 3063, 267, 2088, 275, 2088, 63, 83, 11020, 11318, 393, 14, 954, 4405, 905, 751, 4140, 954, 4405, 905, 261, 3858, 1038, 651, 937, 267, 1798, 12, 945, 2634, 275, 2088, 423, 981, 63, 2087, 480, 751, 531, 267, 3999, 12, 1249, 275, 1798, 14, 1122, 63, 589, 8, 513, 8, 3020, 430, 267, 327, 9388, 734, 1511, 687, 945, 4652, 267, 1249, 275, 1249, 59, 17, 2938, 267, 2074, 275, 1211, 8, 3291, 855, 807, 3368, 267, 367, 945, 63, 923, 315, 1798, 14, 1422, 63, 2634, 26, 288, 367, 945, 315, 945, 63, 923, 14, 1422, 63, 513, 26, 355, 340, 945, 14, 2614, 365, 440, 488, 26, 490, 2150, 2074, 59, 1422, 14, 2614, 61, 267, 2074, 14, 873, 8, 1422, 2634, 9, 398, 869, 275, 2074, 14, 362, 480, 40, 401, 488, 9, 267, 31710, 3291, 275, 2074, 14, 362, 480, 21693, 3291, 401, 488, 9, 267, 22314, 3291, 275, 2074, 14, 362, 480, 18639, 3291, 401, 488, 9, 398, 13204, 275, 31710, 3291, 14, 362, 63, 912, 22176, 342, 267, 20023, 275, 22314, 3291, 14, 362, 63, 6942, 8, 10343, 12, 9567, 63, 6744, 29, 549, 9, 398, 31626, 697, 275, 428, 455, 2846, 8, 633, 29, 40, 12, 2351, 63, 815, 29, 2253, 63, 1730, 1062, 1993, 6235, 29, 15226, 12, 13204, 29, 10343, 9, 267, 372, 31626, 697, 2378, 347, 519, 1097, 1064, 8, 277, 12, 536, 12, 627, 589, 304, 267, 408, 1065, 282, 2849, 2166, 1414, 624, 267, 2088, 275, 2088, 63, 83, 11020, 11318, 393, 14, 954, 4405, 59, 354, 61, 267, 2088, 14, 548, 70, 275, 5228, 342, 267, 2088, 14, 1508, 70, 275, 5228, 342, 267, 754, 275, 2088, 423, 1065, 8, 354, 12, 627, 589, 9, 267, 372, 334, 1099, 12, 2088, 14, 548, 70, 14, 7150, 1062, 2088, 14, 1508, 70, 14, 7150, 1012, 339, 347, 1255, 954, 1760, 8, 277, 12, 536, 12, 1007, 12, 627, 589, 304, 267, 408, 1065, 282, 1414, 543, 1007, 3718, 624, 267, 327, 710, 4499, 781, 1929, 642, 805, 7396, 687, 519, 1097, 1064, 365, 267, 327, 626, 314, 1275, 548, 70, 5228, 9801, 365, 1806, 25045, 340, 781, 675, 267, 327, 519, 1097, 1064, 12, 880, 781, 883, 1133, 12296, 3839, 436, 4635, 267, 2088, 275, 2088, 63, 83, 11020, 11318, 393, 14, 954, 4405, 59, 354, 1055, 954, 4405, 59, 954, 61, 267, 2088, 14, 548, 70, 275, 5228, 342, 267, 2088, 14, 1508, 70, 275, 5228, 342, 267, 754, 275, 2088, 423, 1065, 8, 354, 12, 627, 589, 9, 267, 372, 334, 1099, 12, 2088, 14, 548, 70, 14, 7150, 1062, 2088, 14, 1508, 70, 14, 7150, 1012, 339, 347, 702, 7874, 8300, 8, 277, 12, 1139, 12, 1499, 17364, 267, 291, 14, 7702, 8, 637, 12, 1499, 9, 339, 347, 702, 7874, 4874, 8, 277, 12, 1139, 12, 1499, 17364, 267, 291, 14, 10389, 8, 637, 12, 1499, 9, 339, 347, 702, 4486, 8, 277, 12, 1300, 12, 1059, 12, 1499, 17364, 267, 291, 14, 1815, 8, 875, 315, 1300, 12, 1499, 9, 339, 347, 2196, 985, 8, 277, 12, 2338, 29, 24, 304, 267, 408, 2499, 282, 2196, 536, 12, 4021, 14435, 436, 5579, 12, 436, 3544, 6617, 543, 282, 8082, 624, 267, 536, 275, 2196, 14, 5095, 8, 875, 14, 4371, 63, 26831, 9, 267, 536, 847, 6522, 904, 8, 2355, 14, 5095, 8, 875, 14, 4371, 63, 26831, 435, 1059, 14, 4371, 63, 21636, 11, 1059, 14, 7022, 9, 367, 671, 315, 1425, 8, 835, 446, 413, 430, 267, 372, 536, 339, 347, 2196, 4986, 8, 277, 12, 2338, 29, 975, 304, 267, 536, 275, 2196, 14, 5095, 8, 875, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
ishanic/scikit-learn
sklearn/feature_extraction/hashing.py
183
6155
# Author: Lars Buitinck <L.J.Buitinck@uva.nl> # License: BSD 3 clause import numbers import numpy as np import scipy.sparse as sp from . import _hashing from ..base import BaseEstimator, TransformerMixin def _iteritems(d): """Like d.iteritems, but accepts any collections.Mapping.""" return d.iteritems() if hasattr(d, "iteritems") else d.items() class FeatureHasher(BaseEstimator, TransformerMixin): """Implements feature hashing, aka the hashing trick. This class turns sequences of symbolic feature names (strings) into scipy.sparse matrices, using a hash function to compute the matrix column corresponding to a name. The hash function employed is the signed 32-bit version of Murmurhash3. Feature names of type byte string are used as-is. Unicode strings are converted to UTF-8 first, but no Unicode normalization is done. Feature values must be (finite) numbers. This class is a low-memory alternative to DictVectorizer and CountVectorizer, intended for large-scale (online) learning and situations where memory is tight, e.g. when running prediction code on embedded devices. Read more in the :ref:`User Guide <feature_hashing>`. Parameters ---------- n_features : integer, optional The number of features (columns) in the output matrices. Small numbers of features are likely to cause hash collisions, but large numbers will cause larger coefficient dimensions in linear learners. dtype : numpy type, optional The type of feature values. Passed to scipy.sparse matrix constructors as the dtype argument. Do not set this to bool, np.boolean or any unsigned integer type. input_type : string, optional Either "dict" (the default) to accept dictionaries over (feature_name, value); "pair" to accept pairs of (feature_name, value); or "string" to accept single strings. feature_name should be a string, while value should be a number. In the case of "string", a value of 1 is implied. The feature_name is hashed to find the appropriate column for the feature. The value's sign might be flipped in the output (but see non_negative, below). non_negative : boolean, optional, default np.float64 Whether output matrices should contain non-negative values only; effectively calls abs on the matrix prior to returning it. When True, output values can be interpreted as frequencies. When False, output values will have expected value zero. Examples -------- >>> from sklearn.feature_extraction import FeatureHasher >>> h = FeatureHasher(n_features=10) >>> D = [{'dog': 1, 'cat':2, 'elephant':4},{'dog': 2, 'run': 5}] >>> f = h.transform(D) >>> f.toarray() array([[ 0., 0., -4., -1., 0., 0., 0., 0., 0., 2.], [ 0., 0., 0., -2., -5., 0., 0., 0., 0., 0.]]) See also -------- DictVectorizer : vectorizes string-valued features using a hash table. sklearn.preprocessing.OneHotEncoder : handles nominal/categorical features encoded as columns of integers. """ def __init__(self, n_features=(2 ** 20), input_type="dict", dtype=np.float64, non_negative=False): self._validate_params(n_features, input_type) self.dtype = dtype self.input_type = input_type self.n_features = n_features self.non_negative = non_negative @staticmethod def _validate_params(n_features, input_type): # strangely, np.int16 instances are not instances of Integral, # while np.int64 instances are... if not isinstance(n_features, (numbers.Integral, np.integer)): raise TypeError("n_features must be integral, got %r (%s)." % (n_features, type(n_features))) elif n_features < 1 or n_features >= 2 ** 31: raise ValueError("Invalid number of features (%d)." % n_features) if input_type not in ("dict", "pair", "string"): raise ValueError("input_type must be 'dict', 'pair' or 'string'," " got %r." % input_type) def fit(self, X=None, y=None): """No-op. This method doesn't do anything. It exists purely for compatibility with the scikit-learn transformer API. Returns ------- self : FeatureHasher """ # repeat input validation for grid search (which calls set_params) self._validate_params(self.n_features, self.input_type) return self def transform(self, raw_X, y=None): """Transform a sequence of instances to a scipy.sparse matrix. Parameters ---------- raw_X : iterable over iterable over raw features, length = n_samples Samples. Each sample must be iterable an (e.g., a list or tuple) containing/generating feature names (and optionally values, see the input_type constructor argument) which will be hashed. raw_X need not support the len function, so it can be the result of a generator; n_samples is determined on the fly. y : (ignored) Returns ------- X : scipy.sparse matrix, shape = (n_samples, self.n_features) Feature matrix, for use with estimators or further transformers. """ raw_X = iter(raw_X) if self.input_type == "dict": raw_X = (_iteritems(d) for d in raw_X) elif self.input_type == "string": raw_X = (((f, 1) for f in x) for x in raw_X) indices, indptr, values = \ _hashing.transform(raw_X, self.n_features, self.dtype) n_samples = indptr.shape[0] - 1 if n_samples == 0: raise ValueError("Cannot vectorize empty sequence.") X = sp.csr_matrix((values, indices, indptr), dtype=self.dtype, shape=(n_samples, self.n_features)) X.sum_duplicates() # also sorts the indices if self.non_negative: np.abs(X.data, X.data) return X
bsd-3-clause
[ 3, 6529, 26, 491, 4291, 4779, 390, 262, 346, 665, 44, 14, 42, 14, 1713, 390, 262, 346, 32, 85, 3042, 14, 7530, 30, 199, 3, 844, 26, 6289, 650, 8502, 199, 199, 646, 5579, 199, 199, 646, 2680, 465, 980, 199, 646, 7026, 14, 4421, 465, 2249, 199, 199, 504, 1275, 492, 485, 2227, 316, 199, 504, 2508, 1095, 492, 3523, 13183, 12, 30486, 4256, 421, 199, 318, 485, 4611, 8, 68, 304, 272, 408, 12545, 366, 14, 4611, 12, 1325, 11479, 1263, 5055, 14, 7674, 1041, 272, 372, 366, 14, 4611, 342, 340, 2688, 8, 68, 12, 298, 4611, 531, 587, 366, 14, 1744, 342, 421, 199, 533, 13407, 13415, 8, 1563, 13183, 12, 30486, 4256, 304, 272, 408, 29452, 3878, 25223, 12, 282, 7351, 314, 25223, 20907, 14, 339, 961, 1021, 25449, 8013, 402, 13673, 3878, 1561, 334, 5465, 9, 1901, 272, 7026, 14, 4421, 12627, 12, 1808, 282, 2631, 805, 370, 4526, 314, 3634, 2763, 272, 5226, 370, 282, 536, 14, 710, 2631, 805, 9052, 3374, 379, 365, 314, 10514, 4337, 13, 2075, 272, 1015, 402, 603, 16462, 2227, 19, 14, 339, 13407, 1561, 402, 730, 3696, 1059, 787, 1202, 465, 13, 374, 14, 6140, 3326, 787, 272, 6702, 370, 9094, 13, 24, 1642, 12, 1325, 949, 6140, 16973, 365, 4224, 14, 272, 13407, 1338, 1471, 506, 334, 8005, 9, 5579, 14, 339, 961, 1021, 365, 282, 6465, 13, 4844, 13943, 370, 7448, 26165, 436, 272, 14826, 26165, 12, 11619, 367, 7031, 13, 3467, 334, 15178, 9, 9328, 436, 24325, 272, 2382, 4402, 365, 3367, 913, 12, 325, 14, 71, 14, 1380, 3879, 12044, 1233, 641, 12169, 272, 7256, 14, 339, 5574, 1655, 315, 314, 520, 1121, 1705, 1899, 15423, 665, 4445, 63, 2227, 316, 14943, 339, 3897, 272, 4143, 272, 302, 63, 3179, 520, 3000, 12, 2716, 267, 710, 1329, 402, 4534, 334, 3406, 9, 315, 314, 1072, 12627, 14, 23704, 5579, 267, 402, 4534, 787, 12060, 370, 7675, 2631, 30063, 12, 1325, 7031, 5579, 267, 911, 7675, 12142, 9421, 7365, 315, 7798, 12537, 1192, 14, 272, 2152, 520, 2680, 730, 12, 2716, 267, 710, 730, 402, 3878, 1338, 14, 510, 2744, 370, 7026, 14, 4421, 3634, 31604, 267, 465, 314, 2152, 1423, 14, 4226, 440, 663, 642, 370, 2155, 12, 980, 14, 4871, 503, 1263, 267, 7381, 3000, 730, 14, 272, 1324, 63, 466, 520, 1059, 12, 2716, 267, 13083, 298, 807, 2, 334, 1589, 849, 9, 370, 4729, 11196, 1806, 267, 334, 4445, 63, 354, 12, 574, 2736, 298, 3852, 2, 370, 4729, 6342, 402, 334, 4445, 63, 354, 12, 574, 2736, 267, 503, 298, 875, 2, 370, 4729, 2849, 3326, 14, 267, 3878, 63, 354, 1077, 506, 282, 1059, 12, 1830, 574, 1077, 506, 282, 1329, 14, 267, 1010, 314, 1930, 402, 298, 875, 401, 282, 574, 402, 413, 365, 2478, 14, 267, 710, 3878, 63, 354, 365, 19871, 370, 2342, 314, 5827, 2763, 367, 314, 267, 3878, 14, 710, 574, 1159, 2070, 5594, 506, 18761, 1915, 315, 314, 1072, 334, 7911, 1937, 267, 2222, 63, 7371, 12, 5084, 680, 272, 2222, 63, 7371, 520, 5046, 12, 2716, 12, 849, 980, 14, 1609, 772, 267, 7480, 1072, 12627, 1077, 1395, 2222, 13, 7371, 1338, 1454, 27, 267, 27881, 4882, 2853, 641, 314, 3634, 6791, 370, 8152, 652, 14, 267, 3979, 715, 12, 1072, 1338, 883, 506, 11922, 465, 22411, 14, 267, 3979, 756, 12, 1072, 1338, 911, 1172, 1420, 574, 4697, 14, 339, 6058, 272, 3001, 272, 1306, 687, 6357, 14, 4445, 63, 24020, 492, 13407, 13415, 272, 1306, 394, 275, 13407, 13415, 8, 78, 63, 3179, 29, 709, 9, 272, 1306, 577, 275, 9016, 13889, 356, 413, 12, 283, 3385, 356, 18, 12, 283, 8081, 838, 867, 356, 20, 1386, 1445, 13889, 356, 499, 12, 283, 1065, 356, 959, 11049, 272, 1306, 289, 275, 394, 14, 4711, 8, 36, 9, 272, 1306, 289, 14, 18993, 342, 272, 1625, 4038, 378, 2020, 221, 378, 2020, 446, 20, 2020, 446, 17, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 2020, 221, 499, 8333, 1779, 359, 378, 2020, 221, 378, 2020, 221, 378, 2020, 446, 18, 2020, 446, 21, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 19450, 288, 272, 1666, 2597, 272, 3001, 272, 7448, 26165, 520, 5477, 6491, 1059, 13, 16611, 4534, 1808, 282, 2631, 1817, 14, 272, 6357, 14, 21402, 14, 4395, 19942, 6679, 520, 10022, 17468, 1582, 15, 16810, 4534, 489, 5737, 465, 4362, 402, 9446, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 302, 63, 3179, 2687, 18, 1011, 3388, 395, 1324, 63, 466, 628, 807, 401, 326, 2152, 29, 1590, 14, 1609, 772, 12, 2222, 63, 7371, 29, 797, 304, 267, 291, 423, 3502, 63, 1162, 8, 78, 63, 3179, 12, 1324, 63, 466, 9, 398, 291, 14, 2271, 275, 2152, 267, 291, 14, 1210, 63, 466, 275, 1324, 63, 466, 267, 291, 14, 78, 63, 3179, 275, 302, 63, 3179, 267, 291, 14, 2865, 63, 7371, 275, 2222, 63, 7371, 339, 768, 4639, 272, 347, 485, 3502, 63, 1162, 8, 78, 63, 3179, 12, 1324, 63, 466, 304, 267, 327, 620, 618, 590, 12, 980, 14, 442, 975, 4454, 787, 440, 4454, 402, 23095, 12, 267, 327, 1830, 980, 14, 442, 772, 4454, 787, 1396, 267, 340, 440, 1228, 8, 78, 63, 3179, 12, 334, 10548, 14, 18949, 12, 980, 14, 4115, 2298, 288, 746, 3146, 480, 78, 63, 3179, 1471, 506, 20583, 12, 4788, 450, 82, 4366, 83, 17617, 1169, 450, 334, 78, 63, 3179, 12, 730, 8, 78, 63, 3179, 1724, 267, 916, 302, 63, 3179, 665, 413, 503, 302, 63, 3179, 2356, 499, 1011, 7105, 26, 288, 746, 1722, 480, 3364, 1329, 402, 4534, 4366, 68, 17617, 450, 302, 63, 3179, 9, 398, 340, 1324, 63, 466, 440, 315, 1689, 807, 401, 298, 3852, 401, 298, 875, 2349, 288, 746, 1722, 480, 1210, 63, 466, 1471, 506, 283, 807, 297, 283, 3852, 7, 503, 283, 875, 297, 2, 2490, 298, 4788, 450, 82, 2122, 450, 1324, 63, 466, 9, 339, 347, 5542, 8, 277, 12, 1323, 29, 403, 12, 612, 29, 403 ]
[ 6529, 26, 491, 4291, 4779, 390, 262, 346, 665, 44, 14, 42, 14, 1713, 390, 262, 346, 32, 85, 3042, 14, 7530, 30, 199, 3, 844, 26, 6289, 650, 8502, 199, 199, 646, 5579, 199, 199, 646, 2680, 465, 980, 199, 646, 7026, 14, 4421, 465, 2249, 199, 199, 504, 1275, 492, 485, 2227, 316, 199, 504, 2508, 1095, 492, 3523, 13183, 12, 30486, 4256, 421, 199, 318, 485, 4611, 8, 68, 304, 272, 408, 12545, 366, 14, 4611, 12, 1325, 11479, 1263, 5055, 14, 7674, 1041, 272, 372, 366, 14, 4611, 342, 340, 2688, 8, 68, 12, 298, 4611, 531, 587, 366, 14, 1744, 342, 421, 199, 533, 13407, 13415, 8, 1563, 13183, 12, 30486, 4256, 304, 272, 408, 29452, 3878, 25223, 12, 282, 7351, 314, 25223, 20907, 14, 339, 961, 1021, 25449, 8013, 402, 13673, 3878, 1561, 334, 5465, 9, 1901, 272, 7026, 14, 4421, 12627, 12, 1808, 282, 2631, 805, 370, 4526, 314, 3634, 2763, 272, 5226, 370, 282, 536, 14, 710, 2631, 805, 9052, 3374, 379, 365, 314, 10514, 4337, 13, 2075, 272, 1015, 402, 603, 16462, 2227, 19, 14, 339, 13407, 1561, 402, 730, 3696, 1059, 787, 1202, 465, 13, 374, 14, 6140, 3326, 787, 272, 6702, 370, 9094, 13, 24, 1642, 12, 1325, 949, 6140, 16973, 365, 4224, 14, 272, 13407, 1338, 1471, 506, 334, 8005, 9, 5579, 14, 339, 961, 1021, 365, 282, 6465, 13, 4844, 13943, 370, 7448, 26165, 436, 272, 14826, 26165, 12, 11619, 367, 7031, 13, 3467, 334, 15178, 9, 9328, 436, 24325, 272, 2382, 4402, 365, 3367, 913, 12, 325, 14, 71, 14, 1380, 3879, 12044, 1233, 641, 12169, 272, 7256, 14, 339, 5574, 1655, 315, 314, 520, 1121, 1705, 1899, 15423, 665, 4445, 63, 2227, 316, 14943, 339, 3897, 272, 4143, 272, 302, 63, 3179, 520, 3000, 12, 2716, 267, 710, 1329, 402, 4534, 334, 3406, 9, 315, 314, 1072, 12627, 14, 23704, 5579, 267, 402, 4534, 787, 12060, 370, 7675, 2631, 30063, 12, 1325, 7031, 5579, 267, 911, 7675, 12142, 9421, 7365, 315, 7798, 12537, 1192, 14, 272, 2152, 520, 2680, 730, 12, 2716, 267, 710, 730, 402, 3878, 1338, 14, 510, 2744, 370, 7026, 14, 4421, 3634, 31604, 267, 465, 314, 2152, 1423, 14, 4226, 440, 663, 642, 370, 2155, 12, 980, 14, 4871, 503, 1263, 267, 7381, 3000, 730, 14, 272, 1324, 63, 466, 520, 1059, 12, 2716, 267, 13083, 298, 807, 2, 334, 1589, 849, 9, 370, 4729, 11196, 1806, 267, 334, 4445, 63, 354, 12, 574, 2736, 298, 3852, 2, 370, 4729, 6342, 402, 334, 4445, 63, 354, 12, 574, 2736, 267, 503, 298, 875, 2, 370, 4729, 2849, 3326, 14, 267, 3878, 63, 354, 1077, 506, 282, 1059, 12, 1830, 574, 1077, 506, 282, 1329, 14, 267, 1010, 314, 1930, 402, 298, 875, 401, 282, 574, 402, 413, 365, 2478, 14, 267, 710, 3878, 63, 354, 365, 19871, 370, 2342, 314, 5827, 2763, 367, 314, 267, 3878, 14, 710, 574, 1159, 2070, 5594, 506, 18761, 1915, 315, 314, 1072, 334, 7911, 1937, 267, 2222, 63, 7371, 12, 5084, 680, 272, 2222, 63, 7371, 520, 5046, 12, 2716, 12, 849, 980, 14, 1609, 772, 267, 7480, 1072, 12627, 1077, 1395, 2222, 13, 7371, 1338, 1454, 27, 267, 27881, 4882, 2853, 641, 314, 3634, 6791, 370, 8152, 652, 14, 267, 3979, 715, 12, 1072, 1338, 883, 506, 11922, 465, 22411, 14, 267, 3979, 756, 12, 1072, 1338, 911, 1172, 1420, 574, 4697, 14, 339, 6058, 272, 3001, 272, 1306, 687, 6357, 14, 4445, 63, 24020, 492, 13407, 13415, 272, 1306, 394, 275, 13407, 13415, 8, 78, 63, 3179, 29, 709, 9, 272, 1306, 577, 275, 9016, 13889, 356, 413, 12, 283, 3385, 356, 18, 12, 283, 8081, 838, 867, 356, 20, 1386, 1445, 13889, 356, 499, 12, 283, 1065, 356, 959, 11049, 272, 1306, 289, 275, 394, 14, 4711, 8, 36, 9, 272, 1306, 289, 14, 18993, 342, 272, 1625, 4038, 378, 2020, 221, 378, 2020, 446, 20, 2020, 446, 17, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 2020, 221, 499, 8333, 1779, 359, 378, 2020, 221, 378, 2020, 221, 378, 2020, 446, 18, 2020, 446, 21, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 2020, 221, 378, 19450, 288, 272, 1666, 2597, 272, 3001, 272, 7448, 26165, 520, 5477, 6491, 1059, 13, 16611, 4534, 1808, 282, 2631, 1817, 14, 272, 6357, 14, 21402, 14, 4395, 19942, 6679, 520, 10022, 17468, 1582, 15, 16810, 4534, 489, 5737, 465, 4362, 402, 9446, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 302, 63, 3179, 2687, 18, 1011, 3388, 395, 1324, 63, 466, 628, 807, 401, 326, 2152, 29, 1590, 14, 1609, 772, 12, 2222, 63, 7371, 29, 797, 304, 267, 291, 423, 3502, 63, 1162, 8, 78, 63, 3179, 12, 1324, 63, 466, 9, 398, 291, 14, 2271, 275, 2152, 267, 291, 14, 1210, 63, 466, 275, 1324, 63, 466, 267, 291, 14, 78, 63, 3179, 275, 302, 63, 3179, 267, 291, 14, 2865, 63, 7371, 275, 2222, 63, 7371, 339, 768, 4639, 272, 347, 485, 3502, 63, 1162, 8, 78, 63, 3179, 12, 1324, 63, 466, 304, 267, 327, 620, 618, 590, 12, 980, 14, 442, 975, 4454, 787, 440, 4454, 402, 23095, 12, 267, 327, 1830, 980, 14, 442, 772, 4454, 787, 1396, 267, 340, 440, 1228, 8, 78, 63, 3179, 12, 334, 10548, 14, 18949, 12, 980, 14, 4115, 2298, 288, 746, 3146, 480, 78, 63, 3179, 1471, 506, 20583, 12, 4788, 450, 82, 4366, 83, 17617, 1169, 450, 334, 78, 63, 3179, 12, 730, 8, 78, 63, 3179, 1724, 267, 916, 302, 63, 3179, 665, 413, 503, 302, 63, 3179, 2356, 499, 1011, 7105, 26, 288, 746, 1722, 480, 3364, 1329, 402, 4534, 4366, 68, 17617, 450, 302, 63, 3179, 9, 398, 340, 1324, 63, 466, 440, 315, 1689, 807, 401, 298, 3852, 401, 298, 875, 2349, 288, 746, 1722,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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
rlugojr/rekall
rekall-core/rekall/plugins/tools/mspdb.py
2
45023
# Rekall Memory Forensics # Copyright 2014 Google Inc. All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # pylint: disable=protected-access """These plugins are for manipulating Microsoft PDB file. References: https://code.google.com/p/pdbparse/ http://moyix.blogspot.de/2007/10/types-stream.html http://undocumented.rawol.com/win_pdbx.zip Our goal here is not to be a complete parser for PDB files. Rather, we are trying to extract only the important information we need in order to build a Rekall profile. This means that we dont necessarily care about modifiers like "const" "volatile" etc, but mostly care about struct, enums, bitfields etc. If you are comparing the code here with the code in the pdbparse project, be aware that due to the crazy way the construct library (which is used by pdbparse) splits up bits, the ordering in the pdbparse code does not follow the correct bit number (bits are defined in the order they appear in the bit stream, which for a little endian number is non intuitive). e.g. CV_property = BitStruct("prop", Flag("fwdref"), Flag("opcast"), Flag("opassign"), Flag("cnested"), Flag("isnested"), Flag("ovlops"), Flag("ctor"), Flag("packed"), BitField("reserved", 7, swapped=True), Flag("scoped"), ) Actually is this struct (i.e. above the first field is bit 7, then 6 etc until bit 0 the bit 15 down to 8): typedef struct _CV_prop_t { /*000.0*/ WORD packed : 1; /*000.1*/ WORD ctor : 1; /*000.2*/ WORD ovlops : 1; /*000.3*/ WORD isnested : 1; /*000.4*/ WORD cnested : 1; /*000.5*/ WORD opassign : 1; /*000.6*/ WORD opcast : 1; /*000.7*/ WORD fwdref : 1; /*001.0*/ WORD scoped : 1; /*001.1*/ WORD reserved : 7; /*002*/ } CV_prop_t, *PCV_prop_t, **PPCV_prop_t; Since we are lazy and do not want to hand code all the structure definitions, we simply build a profile from the C implementation, and then use it here directly using the "mspdb" profile (which is available in the profile repository). http://undocumented.rawol.com/win_pdbx.zip: ./sbs_sdk/include/pdb_info.h Other known implementations of PDB parsing: https://chromium.googlesource.com/syzygy/+/master/pdb The closest thing to official documentation can be found here: http://pierrelib.pagesperso-orange.fr/exec_formats/MS_Symbol_Type_v1.0.pdf """ __author__ = "Michael Cohen <scudette@gmail.com>" import glob import re import ntpath import os import platform import subprocess import sys import urllib2 from rekall import addrspace from rekall import plugin from rekall import obj from rekall import testlib from rekall import utils from rekall.plugins import core from rekall.plugins.addrspaces import standard from rekall.plugins.overlays import basic from rekall.plugins.overlays.windows import pe_vtypes class FetchPDB(core.DirectoryDumperMixin, plugin.TypedProfileCommand, plugin.Command): """Fetch the PDB file for an executable from the Microsoft PDB server.""" __name = "fetch_pdb" SYM_URLS = ['http://msdl.microsoft.com/download/symbols'] USER_AGENT = "Microsoft-Symbol-Server/10.0.0.0" __args = [ dict(name="pdb_filename", required=True, positional=True, help="The filename of the executable to get the PDB file for."), dict(name="guid", positional=True, help="The GUID of the pdb file. If provided, the pdb filename must" " be provided in the --pdb_filename parameter.") ] def render(self, renderer): # The filename is an executable if self.plugin_args.guid is None and self.plugin_args.pdb_filename: self.pe = pe_vtypes.PE(filename=self.plugin_args.pdb_filename, session=self.session) data_directory = self.pe.nt_header.OptionalHeader.DataDirectory[ "IMAGE_DIRECTORY_ENTRY_DEBUG"].VirtualAddress.dereference_as( "_IMAGE_DEBUG_DIRECTORY") # We only support the more recent RSDS format. debug = data_directory.AddressOfRawData.dereference_as( "CV_RSDS_HEADER") if debug.Signature != "RSDS": self.session.logging.error("PDB stream %s not supported.", debug.Signature) return self.plugin_args.pdb_filename = ntpath.basename(str(debug.Filename)) self.plugin_args.guid = self.pe.RSDS.GUID_AGE elif self.plugin_args.pdb_filename is None: raise RuntimeError( "Filename must be provided when GUID is specified.") # Write the file data to the renderer. pdb_file_data = self.FetchPDBFile() with renderer.open(filename=self.plugin_args.pdb_filename, directory=self.plugin_args.dump_dir, mode="wb") as fd: fd.write(pdb_file_data) def FetchPDBFile(self): # Ensure the pdb filename has the correct extension. pdb_filename = self.plugin_args.pdb_filename guid = self.plugin_args.guid if not pdb_filename.endswith(".pdb"): pdb_filename += ".pdb" for url in self.SYM_URLS: basename = ntpath.splitext(pdb_filename)[0] url += "/%s/%s/%s.pd_" % (pdb_filename, guid, basename) self.session.report_progress("Trying to fetch %s\n", url) request = urllib2.Request(url, None, headers={ 'User-Agent': self.USER_AGENT}) url_handler = urllib2.urlopen(request) with utils.TempDirectory() as temp_dir: compressed_output_file = os.path.join( temp_dir, "%s.pd_" % basename) output_file = os.path.join( temp_dir, "%s.pdb" % basename) # Download the compressed file to a temp file. with open(compressed_output_file, "wb") as outfd: while True: data = url_handler.read(8192) if not data: break outfd.write(data) self.session.report_progress( "%s: Downloaded %s bytes", basename, outfd.tell()) # Now try to decompress it with system tools. This might fail. try: if platform.system() == "Windows": # This should already be installed on windows systems. subprocess.check_call( ["expand", compressed_output_file, output_file], cwd=temp_dir) else: # In Linux we just hope the cabextract program was # installed. subprocess.check_call( ["cabextract", compressed_output_file], cwd=temp_dir, stdout=sys.stderr) except (subprocess.CalledProcessError, OSError): raise RuntimeError( "Failed to decompress output file %s. " "Ensure cabextract is installed.\n" % output_file) # Sometimes the CAB file contains a PDB file with a different # name or casing than we expect. We use glob to find any PDB # files in the temp directory. output_file = glob.glob("%s/*pdb" % temp_dir)[0] # We read the entire file into memory here - it should not be # larger than approximately 10mb. with open(output_file, "rb") as fd: return fd.read(50 * 1024 * 1024) class TestFetchPDB(testlib.DisabledTest): """Disable this test.""" PARAMETERS = dict(commandline="fetch_pdb") def Pages(length, page_size): """Calculate the number of pages required to store a stream.""" num_pages = length / page_size if length % page_size: num_pages += 1 return num_pages class StreamBasedAddressSpace(addrspace.CachingAddressSpaceMixIn, addrspace.RunBasedAddressSpace): """An address space which combines together the page lists. Once we parse the page list, we can build this address space which takes care of reassembling the stream for us automatically. """ def __init__(self, pages=None, page_size=None, **kwargs): super(StreamBasedAddressSpace, self).__init__(**kwargs) self.pages = pages self.PAGE_SIZE = page_size = int(page_size) i = 0 for i, page in enumerate(pages): self.add_run(i * page_size, page * page_size, page_size) # Record the total size of the file. self.size = (i + 1) * page_size #################################################################### # The following parses the TPI stream (stream 2). #################################################################### # Inside TPI stream we have a list of records. The type of the struct stored in # the record is declared by use of the _LEAF_ENUM_e enum. The following lookup # map is used to map from the _LEAF_ENUM_e to the BaseObject class to # instantiate. LEAF_ENUM_TO_TYPE = dict( LF_STRUCTURE="_lfClass", LF_ARRAY="_lfArray", LF_PROCEDURE="_lfProc", LF_POINTER="_lfPointer", LF_ARGLIST="_lfArgList", LF_MODIFIER="_lfModifier", LF_FIELDLIST="_lfFieldList", LF_ENUM="_lfEnum", LF_UNION="_lfUnion", LF_BITFIELD="_lfBitfield", LF_NESTTYPE="_lfNestType", LF_CHAR="byte", LF_SHORT="short int", LF_USHORT="unsigned short int", LF_LONG="long", LF_ULONG="unsigned long", LF_64PWCHAR="Pointer", ) # The SubRecord field is a union which depends on the _LEAF_ENUM_e. The # following maps these to the enum fields. There are other members in the union, # but we dont care about them. LEAF_ENUM_TO_SUBRECORD = dict( LF_MEMBER="Member", LF_ENUMERATE="Enumerate", LF_NESTTYPE="NestType", ) # A map between the symbol type enum and the actual record type. SYM_ENUM_TO_SYM = dict( S_PUB32="_PUBSYM32", ) mspdb_overlays = { # The file header. We only support newer versions. "_PDB_HEADER_700": [None, { "abSignature": [None, ["Signature", dict( value="Microsoft C/C++ MSF 7.00\r\n\x1ADS\0\0\0" )]], # Total number of pages in the root stream. "root_pages": lambda x: Pages(x.dRootBytes, x.dPageBytes), # This is an array of page indexes which make up the page list of # the root stream. "adIndexPages": [None, ["Array", dict( target="unsigned int", # The root page list is stored in the index stream. Each # page index is 4 bytes. count=lambda x: Pages(4 * x.root_pages, x.dPageBytes), )]], }], # The header of the root stream (This applies once we reconstruct the root # stream). It defines the page indexes of all the streams in this file. "_PDB_ROOT_700": [lambda x: (x.dStreams + 1) * 4, { "adStreamBytes": [None, ["Array", dict( count=lambda x: x.dStreams, target="unsigned int", )]], }], # A modifier adds some flags to its modified_type. "_lfModifier": [None, { "modified_type": [2, ["unsigned int"]], "modifier": [6, ["Flags", dict( bitmap=dict( unaligned=2, volatile=1, const=0 ), target="unsigned short int", )]], }], # The size of the SubRecord itself is the size of the value. (ie. depends on # the _LEAF_ENUM_e). We must calculate the exact size because SubRecords (of # variable size) are stored back to back in the lfFieldList. "_lfSubRecord": [lambda x: x.value.obj_size, { "leaf": [None, ["Enumeration", dict( enum_name="_LEAF_ENUM_e", target="unsigned short int")]], # This psuedo value automatically selects the correct member of the # union based on the leaf value. "value": lambda x: x.m( LEAF_ENUM_TO_SUBRECORD.get(str(x.leaf), "Unknown")), }], "_lfEnum": [None, { # The name of the enum element. "Name": [None, ["String"]], }], "_lfNestType": [None, { # The name of the enum element. "Name": [None, ["String"]], }], # A lfFieldList holds a back to back variable length array of SubRecords. "_lfFieldList": [None, { "SubRecord": [None, ["ListArray", dict( target="_lfSubRecord", # Total length is determined by the size of the # container. maximum_size=lambda x: x.obj_parent.length - 2, )]], }], # Arg list for a function. "_lfArgList": [None, { # This is a list of _TYPE_ENUM_e, or an index reference into the TPI # stream. "arg": [None, ["Array", dict( target="Enumeration", target_args=dict( enum_name="_TYPE_ENUM_e", target="unsigned short int", ), count=lambda x: x.count )]], }], # A helper type to select the correct implementation. "TypeContainer": [lambda x: x.length + 2, { "length": [0, ["unsigned short int"]], # Depending on the value of this enum, this field must be cast to # the correct struct. "type_enum": [2, ["Enumeration", dict( enum_name="_LEAF_ENUM_e", target="unsigned short int" )]], # Depending on the enumeration above, the type_enum field must be # cast into one of these structs. "type": lambda x: x.type_enum.cast( LEAF_ENUM_TO_TYPE.get(str(x.type_enum), "unsigned int")) }], # This is the TPI stream header. It is followed by a list of TypeContainers # for all the types in this stream. "_HDR": [None, { "types": [lambda x: x.obj_size, ["ListArray", dict( target="TypeContainer", count=lambda x: x.tiMac - x.tiMin, maximum_size=lambda x: x.cbGprec, )]], }], "_GUID": [16, { "Data1": [0, ["unsigned long", {}]], "Data2": [4, ["unsigned short", {}]], "Data3": [6, ["unsigned short", {}]], "Data4": [8, ["String", dict(length=8, term=None)]], "AsString": lambda x: ("%08x%04x%04x%s" % ( x.Data1, x.Data2, x.Data3, str(x.Data4).encode('hex'))).upper(), }], "Info": [None, { "Version": [0, ["unsigned long int"]], "TimeDateStamp": [4, ["UnixTimeStamp"]], "Age": [8, ["unsigned long int"]], "GUID": [12, ["_GUID"]], }], # The record length does not include the tag. "_ALIGNSYM": [lambda x: x.reclen + 2, { "rectyp": [None, ["Enumeration", dict( enum_name="_SYM_ENUM_e", target="unsigned short int")]], # The real record type depends on the _SYM_ENUM_e. "value": lambda x: x.cast( SYM_ENUM_TO_SYM.get(str(x.rectyp), "")) }], "_PUBSYM32": [None, { "name": [None, ["String"]], }], "DBI": [None, { "DBIHdr": [0, ["_NewDBIHdr"]], "ExHeaders": [64, ["ListArray", dict( maximum_size=lambda x: x.DBIHdr.cbGpModi, target="DBIExHeaders")]], }], "DBIExHeaders": [None, { "modName": [64, ["String"]], "objName": [lambda x: x.modName.obj_offset + x.modName.obj_size, ["String"]], }], "IMAGE_SECTION_HEADER": [None, { "Name": [None, ["String"]], }], } class lfClass(obj.Struct): """Represents a class or struct.""" _obj_end = 0 def __init__(self, **kwargs): super(lfClass, self).__init__(**kwargs) self._DecodeVariableData() @utils.safe_property def obj_size(self): """Our size is the end of the object plus any padding.""" return pe_vtypes.RoundUpToWordAlignment( self.obj_end - self.obj_offset) def _DecodeVariableData(self): """This object is followed by a variable sized data structure. This data structure contains the "value_" and "name" attributes. If the first short int less than 0x8000, it represents the value. Otherwise, it represents an _LEAF_ENUM_e enum which determines the size of the value to read next (e.g. LF_ULONG = 4 bytes, LF_SHORT = 2 bytes) and those represent the value. The name field then follows as a String. Following the name field, there is padding to 4 byte alignment. We must calculate the total size of this struct in this function, after parsing all the components. """ obj_end = self.obj_offset + super(lfClass, self).obj_size field_type = self.obj_profile.Object( "unsigned short int", offset=obj_end, vm=self.obj_vm) obj_end += field_type.obj_size if field_type < 0x8000: self.value_ = field_type self.name = self.obj_profile.String( offset=obj_end, vm=self.obj_vm) obj_end += self.name.obj_size else: # The field type is an LF_ENUM which determines which struct this # is. type_enum_name = self.obj_profile.get_enum( "_LEAF_ENUM_e").get(str(field_type)) type_name = LEAF_ENUM_TO_TYPE.get(type_enum_name) self.value_ = self.obj_profile.Object( type_name=type_name, offset=obj_end, vm=self.obj_vm) # The name follows the value. self.name = self.obj_profile.String( offset=self.value_.obj_offset + self.value_.obj_size, vm=self.obj_vm) obj_end += self.value_.obj_size + self.name.obj_size # Record the end of the object self._obj_end = obj_end # Sometimes the field is named '__unnamed' so we disambiguate it here. if self.name == "__unnamed": self.name = "__unnamed_%s" % self.field @utils.safe_property def obj_end(self): return self._obj_end def Definition(self, _): """Returns the vtype data structure defining this element. Returns: a tuple, the first element is the target name, the second is the dict of the target_args. """ # The target is just the name of this class. return [str(self.name), {}] class lfEnumerate(lfClass): """A SubRecord describing a single enumeration definition.""" class lfBitfield(obj.Struct): """A range of bits.""" def Definition(self, tpi): """BitField overlays on top of another type.""" result = tpi.DefinitionByIndex(self.type) if not result: return [str(self.name), {}] target, target_args = result return "BitField", dict( start_bit=int(self.position), end_bit=int(self.position) + int(self.length), target_args=target_args, target=target) class lfNestType(obj.Struct): UNNAMED_RE = re.compile("<unnamed-type-([^->]+)>") def __init__(self, **kwargs): super(lfNestType, self).__init__(**kwargs) self.value_ = 0 self.name = str(self.Name) m = self.UNNAMED_RE.match(self.name) if m: self.name = m.group(1) @utils.safe_property def obj_size(self): """Our size is the end of the object plus any padding.""" return pe_vtypes.RoundUpToWordAlignment( self.Name.obj_offset + self.Name.obj_size) def Definition(self, tpi): return tpi.DefinitionByIndex(self.index) class lfUnion(lfClass): """A Union is basically the same as a struct, except members may overlap.""" class lfModifier(lfClass): def Definition(self, tpi): """We dont really care about modifiers, just pass the utype through.""" return tpi.DefinitionByIndex(self.modified_type) class lfEnum(obj.Struct): """Represents an enumeration definition.""" @utils.safe_property def Name(self): enum_name = str(self.m("Name")) if enum_name == "<unnamed-tag>": enum_name = "ENUM_%X" % self.obj_offset return enum_name def AddEnumeration(self, tpi): enumeration = {} reverse_enumeration = {} for x in tpi.Resolve(self.field).SubRecord: enumeration[int(x.value.value_)] = str(x.value.name) reverse_enumeration[str(x.value.name)] = int(x.value.value_) tpi.AddEnumeration(self.Name, enumeration) tpi.AddReverseEnumeration(self.Name, reverse_enumeration) def Definition(self, tpi): """Enumerations are defined in two parts. First an enumeration dict is added to the profile constants, and then the target "Enumeration" can use it by name (having the enum_name field). This allows many fields which use the same enumeration to share the definition dict. """ result = tpi.DefinitionByIndex(self.utype) if not result: return [str(self.name), {}] target, target_args = result return "Enumeration", dict( target=target, target_args=target_args, enum_name=self.Name) class lfPointer(lfClass): """A Pointer object.""" def Definition(self, tpi): target_index = int(self.u1.utype) result = tpi.DefinitionByIndex(target_index) if not result: return [str(self.name), {}] target, target_args = result return ["Pointer", dict( target=target, target_args=target_args )] class lfProc(lfClass): """A Function object.""" def Definition(self, tpi): """We record the function arg prototype as well.""" args = [] for idx in tpi.Resolve(self.arglist).arg: definition = tpi.DefinitionByIndex(idx) if definition: args.append(definition) return "Function", dict(args=args) class lfArray(lfClass): """An array of the same object.""" def Definition(self, tpi): result = tpi.DefinitionByIndex(self.elemtype) if not result: return [str(self.name), {}] target, target_args = result if target == "<unnamed-tag>": target = "<unnamed-%s>" % self.elemtype # Note that we only specify the total size of the array. We have no idea # how many items fit at this stage because we dont know the exact size # of the elements. The post processing step will convert the size into a # count. definition = ["Array", dict( target=target, target_args=target_args, size=int(self.value_), )] tpi.RegisterFixUp(definition) return definition class lfMember(lfClass): """A member in a struct (or class).""" def Definition(self, tpi): """Returns a tuple of target, target_args for the member.""" return tpi.DefinitionByIndex(self.m("index")) class _PDB_HEADER_700(obj.Struct): """The file header of a PDB file.""" def get_page_list(self): """The full page list is a double indexed array.""" result = [] for idx in self.adIndexPages: for page_number in self.obj_profile.Array( offset=idx * self.dPageBytes, vm=self.obj_vm, target="unsigned int", count=self.dPageBytes / 4): result.append(int(page_number)) if len(result) >= self.root_pages: return result return result class _PDB_ROOT_700(obj.Struct): """The root stream contains information about all other streams.""" def _GetStreams(self): """Read all the streams in the file.""" offset_of_index_list = self.obj_offset + self.obj_size page_size = self.obj_context["page_size"] for stream_size in self.adStreamBytes: if stream_size == 0xffffffff: stream_size = 0 page_list = self.obj_profile.Array( offset=offset_of_index_list, vm=self.obj_vm, count=Pages(stream_size, page_size), target="unsigned int") offset_of_index_list += page_list.obj_size yield StreamBasedAddressSpace( base=self.obj_vm.base, page_size=page_size, session=self.obj_profile.session, pages=page_list) def GetStream(self, number): """Only return the required streams, discarding the rest.""" for i, address_space in enumerate(self._GetStreams()): if i == number: return address_space class DBIExHeaders(obj.Struct): @utils.safe_property def obj_size(self): return (pe_vtypes.RoundUpToWordAlignment( self.objName.obj_offset + self.objName.obj_size) - self.obj_offset) class DBI(obj.Struct): def DBGHeader(self): DBIHdr = self.DBIHdr # Skip over all these sections which we dont care about until we get to # the debug header at the end. header_offset = (self.obj_offset + DBIHdr.obj_size + DBIHdr.cbGpModi + DBIHdr.cbSC + DBIHdr.cbSecMap + DBIHdr.cbFileInfo + DBIHdr.cbTSMap + DBIHdr.cbECInfo) return self.obj_profile.DbgHdr(header_offset, vm=self.obj_vm) class PDBProfile(basic.Profile32Bits, basic.BasicClasses): """A profile to parse Microsoft PDB files. Note that this is built on top of the mspdb profile which exists in the profile repository, as generated from the code here: http://undocumented.rawol.com/win_pdbx.zip Do not directly instantiate this. Just do: profile = session.LoadProfile("mspdb") """ def __init__(self, **kwargs): super(PDBProfile, self).__init__(**kwargs) self.add_overlay(mspdb_overlays) self.add_classes({ "_PDB_HEADER_700": _PDB_HEADER_700, "_PDB_ROOT_700": _PDB_ROOT_700, "_lfClass": lfClass, "_lfArray": lfArray, "_lfMember": lfMember, "_lfPointer": lfPointer, "_lfProc": lfProc, "_lfEnum": lfEnum, "_lfModifier": lfModifier, "_lfUnion": lfUnion, "_lfBitfield": lfBitfield, "_lfEnumerate": lfEnumerate, "_lfNestType": lfNestType, "DBIExHeaders": DBIExHeaders, "DBI": DBI }) class PDBParser(object): """Parses a Microsoft PDB file.""" # A mapping between _TYPE_ENUM_e basic pdb types and vtype # descriptions. Keys: The _TYPE_ENUM_e enum, values a tuple of target, # target_args for instantiating the Rekall object describing this type. TYPE_ENUM_TO_VTYPE = { "T_32PINT4": ["Pointer", dict(target="long")], "T_32PLONG": ["Pointer", dict(target="long")], "T_32PQUAD": ["Pointer", dict(target="long long")], "T_32PRCHAR": ["Pointer", dict(target="unsigned char")], "T_32PREAL32": ["Pointer", dict(target="Void")], "T_32PREAL64": ["Pointer", dict(target="Void")], "T_32PSHORT": ["Pointer", dict(target="short")], "T_32PUCHAR": ["Pointer", dict(target="unsigned char")], "T_32PUINT4": ["Pointer", dict(target="unsigned int")], "T_32PULONG": ["Pointer", dict(target="unsigned long")], "T_32PUQUAD": ["Pointer", dict(target="unsigned long long")], "T_32PUSHORT": ["Pointer", dict(target="unsigned short")], "T_32PVOID": ["Pointer", dict(target="Void")], "T_32PWCHAR": ["Pointer", dict(target="UnicodeString")], "T_64PLONG": ["Pointer", dict(target="long")], "T_64PQUAD": ["Pointer", dict(target="long long")], "T_64PRCHAR": ["Pointer", dict(target="unsigned char")], "T_64PUCHAR": ["Pointer", dict(target="unsigned char")], "T_64PWCHAR": ["Pointer", dict(target="String")], "T_64PULONG": ["Pointer", dict(target="unsigned long")], "T_64PUQUAD": ["Pointer", dict(target="unsigned long long")], "T_64PUSHORT": ["Pointer", dict(target="unsigned short")], "T_64PVOID": ["Pointer", dict(target="Void")], "T_BOOL08": ["unsigned char", {}], "T_CHAR": ["char", {}], "T_INT4": ["long", {}], "T_INT8": ["long long", {}], "T_LONG": ["long", {}], "T_QUAD": ["long long", {}], "T_RCHAR": ["unsigned char", {}], "T_REAL32": ["float", {}], "T_REAL64": ["double", {}], "T_REAL80": ["long double", {}], "T_SHORT": ["short", {}], "T_UCHAR": ["unsigned char", {}], "T_UINT4": ["unsigned long", {}], "T_ULONG": ["unsigned long", {}], "T_UQUAD": ["unsigned long long", {}], "T_USHORT": ["unsigned short", {}], "T_VOID": ["Void", {}], "T_WCHAR": ["UnicodeString", {}], } def __init__(self, filename, session): self.session = session self.fixups = [] self.enums = {} self.rev_enums = {} self.constants = {} self.functions = {} self.profile = self.session.LoadProfile("mspdb") self._TYPE_ENUM_e = self.profile.get_enum("_TYPE_ENUM_e") self._TYPE_ENUM_e = dict( (int(x), y) for x, y in self._TYPE_ENUM_e.items()) self.address_space = standard.FileAddressSpace( filename=filename, session=self.session) self.header = self.profile._PDB_HEADER_700( vm=self.address_space, offset=0) if not self.header.abSignature.is_valid(): raise IOError("PDB file not supported.") root_pages = self.header.get_page_list() root_stream = StreamBasedAddressSpace( base=self.address_space, page_size=self.header.dPageBytes, pages=root_pages, session=self.profile.session) self.root_stream_header = self.profile._PDB_ROOT_700( offset=0, vm=root_stream, context=dict( page_size=self.header.dPageBytes ) ) self.ParsePDB() self.ParseDBI() self.ParseTPI() def ParsePDB(self): """Parse the PDB info stream.""" # Get the info stream. info = self.profile.Info(vm=self.root_stream_header.GetStream(1)) self.metadata = dict( Version=int(info.Version), Timestamp=str(info.TimeDateStamp), GUID_AGE="%s%X" % (info.GUID.AsString, info.Age), ) def ParseDBI(self): """Parse the DBI stream. This fires off subparsers for contained streams. """ dbi = self.profile.DBI(vm=self.root_stream_header.GetStream(3)) DBGHeader = dbi.DBGHeader() # Sometimes this stream is set to 0xFFFF so we need to use the other # stream. section_stream = DBGHeader.snSectionHdrOrig if section_stream == 0xFFFF: section_stream = DBGHeader.snSectionHdr self.ParseSectionHeaders(section_stream) self.ParseOMAP(DBGHeader.snOmapFromSrc) self.ParseGlobalSymbols(dbi.DBIHdr.u1.snSymRecs) def ParseSectionHeaders(self, stream_id): """Gather the PE sections of this executable.""" self.sections = [] stream = self.root_stream_header.GetStream(stream_id) if stream is None: return for section in self.profile.ListArray( maximum_size=stream.size, target="IMAGE_SECTION_HEADER", vm=stream): self.sections.append(section) def ParseOMAP(self, omap_stream_id): """Build an OMAP lookup table. The OMAP is a translation between the original symbol's offset to the final offset. When the linker builds the executable, it reorders the original object files in the executable section. This translation table tells us where the symbols end up. """ self.omap = utils.SortedCollection(key=lambda x: x[0]) omap_stream = self.root_stream_header.GetStream(omap_stream_id) if omap_stream is None: return omap_address_space = addrspace.BufferAddressSpace( session=self.session, data=omap_stream.read(0, omap_stream.size)) omap_array = self.profile.Array( vm=omap_address_space, count=omap_stream.size / self.profile.get_obj_size("_OMAP_DATA"), max_count=omap_stream.size, target="_OMAP_DATA") for i, omap in enumerate(omap_array): src = int(omap.rva) dest = int(omap.rvaTo) self.omap.insert((src, dest)) self.session.report_progress( " Extracting OMAP Information %s%%", lambda: i * 100 / omap_array.count) def ParseGlobalSymbols(self, stream_id): """Parse the symbol records stream.""" stream = self.root_stream_header.GetStream(stream_id) for container in self.profile.ListArray(target="_ALIGNSYM", vm=stream, maximum_size=stream.size): if container.reclen == 0: break symbol = container.value # Skip unknown records for now. if not symbol: self.session.logging.warning( "Unimplemented symbol %s" % container.rectyp) continue try: name = str(symbol.name) except AttributeError: # We do not support symbols without name (e.g. annotations). continue translated_offset = offset = int(symbol.off) # Some files do not have OMAP information or section information. In # that case we just export the symbol offsets untranslated. if self.sections: # Convert the RVA to a virtual address by referencing into the # correct section. translated_offset = virtual_address = ( offset + self.sections[symbol.seg - 1].VirtualAddress) # If there is no OMAP specified we just translate the symbol # into the right section. if self.omap: # Translate the offset according to the OMAP. try: from_offset, dest_offset = self.omap.find_le( virtual_address) translated_offset = ( virtual_address - from_offset + dest_offset) except ValueError: pass if symbol.pubsymflags.u1.fFunction: self.functions[name] = translated_offset else: self.constants[name] = translated_offset self.session.report_progress(" Parsing Symbols %s", name) def ParseTPI(self): """The TPI stream contains all the struct definitions.""" self.lookup = {} tpi = self.profile._HDR(vm=self.root_stream_header.GetStream(2)) # Build a lookup table for fast resolving of TPI indexes. for i, t in enumerate(tpi.types): self.session.report_progress(" Parsing Structs %(spinner)s") self.lookup[tpi.tiMin + i] = t if not t: break # Extract ALL enumerations, even if they are not referenced by any # structs. for value in self.lookup.values(): if value.type_enum == "LF_ENUM": value.type.AddEnumeration(self) def AddEnumeration(self, name, enumeration): self.enums[name] = enumeration def AddReverseEnumeration(self, name, enumeration): self.rev_enums[name] = enumeration def RegisterFixUp(self, definition): self.fixups.append(definition) def Structs(self): for key, value in self.lookup.iteritems(): # Ignore the forward references. if ((value.type_enum == "LF_STRUCTURE" or value.type_enum == "LF_UNION") and not value.type.property.fwdref): struct_name = value.type.name if struct_name == "<unnamed-tag>": struct_name = "<unnamed-%s>" % key struct_size = int(value.type.value_) field_list = self.lookup[int(value.type.field)].type definition = [struct_size, {}] for field in field_list.SubRecord: field_definition = field.value.Definition(self) if field_definition: if field_definition[0] == "<unnamed-tag>": field_definition[0] = ( "<unnamed-%s>" % field.value.index) definition[1][str(field.value.name)] = [ int(field.value.value_), field_definition] yield [struct_name, definition] def DefinitionByIndex(self, idx): """Return the vtype definition of the item identified by idx.""" result = None if idx < 0x700: type_name = self._TYPE_ENUM_e.get(idx) result = self.TYPE_ENUM_TO_VTYPE.get(type_name) if result is None and type_name != "T_NOTYPE": self.session.logging.error("Unrecognized type %s\n", type_name) else: try: result = self.lookup[idx].type.Definition(self) except AttributeError: pass return result def Resolve(self, idx): try: return self.lookup[idx].type except KeyError: return obj.NoneObject("Index not known") def __enter__(self): return self def __exit__(self, exc_type, exc_value, trace): self.address_space.close() class ParsePDB(core.DirectoryDumperMixin, plugin.TypedProfileCommand, plugin.Command): """Parse the PDB streams.""" __name = "parse_pdb" __args = [ dict(name="pdb_filename", required=True, positional=True, help="The filename of the PDB file."), dict(name="profile_class", help="The name of the profile implementation. " "Default name is derived from the pdb filename."), dict(name="output_filename", help="The name of the file to store this profile. "), dict(name="windows_version", help="The windows version (major.minor.revision) " "corresponding with this PDB. For example, Windows 7 " "should be given as 6.1"), dict(name="concise", type="Boolean", help="Specify this to emit less detailed information."), ] def __init__(self, *args, **kwargs): self.metadata = kwargs.pop("metadata", {}) super(ParsePDB, self).__init__(*args, **kwargs) profile_class = self.metadata.get( "ProfileClass", self.plugin_args.profile_class) # By default select the class with the same name as the pdb file. if profile_class is None: profile_class = os.path.splitext( os.path.basename(self.plugin_args.pdb_filename))[0].capitalize() if profile_class not in obj.Profile.classes: profile_class = "BasicPEProfile" self.plugin_args.profile_class = profile_class versions = [] if self.plugin_args.windows_version is not None: versions = self.plugin_args.windows_version.split(".", 2) for i, metadata in enumerate(["major", "minor", "rev"]): try: self.metadata[metadata] = versions[i] except IndexError: break self.tpi = PDBParser(self.plugin_args.pdb_filename, self.session) NATIVE_TYPE_SIZE = { "unsigned char": 1, "unsigned int": 4, "unsigned long": 4, "unsigned long long": 8, "unsigned short": 2, "char": 1, "int": 4, "long": 4, "long long": 8, "short": 2, } def PostProcessVTypes(self, vtypes): """Post process the vtypes to optimize some access members.""" arch = self.metadata.get("arch", "AMD64") for defintion in self.tpi.fixups: target, target_args = defintion if target == "Array": # The PDB symbols specify a UnicodeString as an array of wide # char but we need to fix it to be a UnicodeString with a # specified length. if target_args.get("target") == "UnicodeString": defintion[0] = "UnicodeString" defintion[1] = dict( length=target_args.get("size") / 2 ) elif target_args.has_key("size"): # Work out the array target size. array_target = target_args.get("target") target_size = self.NATIVE_TYPE_SIZE.get(array_target) if target_size is None: if array_target == "Pointer": target_size = 8 if arch == "AMD64" else 4 else: target_definition = vtypes.get(array_target) if target_definition is None: # We have no idea what size it is. Leave the # size parameter for the object system to work # out during runtime. continue target_size = target_definition[0] # Replace the size with a count. target_args["count"] = target_args.pop( "size") / target_size return vtypes def parse_pdb(self): with self.tpi: vtypes = {} for i, (struct_name, definition) in enumerate(self.tpi.Structs()): self.session.report_progress( " Exporting %s: %s", i, struct_name) struct_name = str(struct_name) existing_definition = vtypes.get(struct_name) if existing_definition: # Merge the old definition into the new definition. definition[1].update(existing_definition[1]) vtypes[struct_name] = definition self.metadata.update(dict( ProfileClass=self.plugin_args.profile_class, Type="Profile", PDBFile=os.path.basename(self.plugin_args.pdb_filename), )) self.metadata.update(self.tpi.metadata) # Demangle all constants. demangler = pe_vtypes.Demangler(self.metadata) constants = {} for name, value in self.tpi.constants.iteritems(): constants[demangler.DemangleName(name)] = value functions = {} for name, value in self.tpi.functions.iteritems(): functions[demangler.DemangleName(name)] = value vtypes = self.PostProcessVTypes(vtypes) result = { "$METADATA": self.metadata, "$STRUCTS": vtypes, "$ENUMS": self.tpi.enums, } if not self.plugin_args.concise: result["$REVENUMS"] = self.tpi.rev_enums result["$CONSTANTS"] = constants result["$FUNCTIONS"] = functions return result def render(self, renderer): result = self.parse_pdb() if self.plugin_args.output_filename: with renderer.open(filename=self.plugin_args.output_filename, directory=self.plugin_args.dump_dir, mode="wb") as fd: fd.write(utils.PPrint(result)) else: renderer.write(utils.PPrint(result))
gpl-2.0
[ 3, 799, 22360, 15825, 21684, 78, 17378, 199, 3, 1898, 6927, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 334, 292, 199, 3, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 199, 3, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 1666, 314, 1664, 199, 3, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 15673, 13, 13421, 8217, 199, 3, 199, 199, 3, 4287, 26, 3507, 29, 6798, 13, 2732, 199, 199, 624, 20676, 8963, 787, 367, 13335, 20529, 15332, 30280, 570, 14, 199, 199, 15242, 26, 199, 2859, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 10511, 1122, 15, 199, 1014, 921, 573, 89, 1148, 14, 66, 7270, 14173, 14, 271, 15, 9488, 15, 709, 15, 1313, 13, 1745, 14, 1360, 199, 1014, 921, 30107, 12546, 14, 1773, 393, 14, 957, 15, 2676, 63, 10511, 88, 14, 3065, 199, 199, 47, 300, 14850, 2348, 365, 440, 370, 506, 282, 4890, 1798, 367, 30280, 1584, 14, 3898, 728, 12, 781, 787, 199, 893, 316, 370, 5536, 1454, 314, 11012, 2556, 781, 1929, 315, 1865, 370, 1900, 282, 199, 497, 22360, 4690, 14, 961, 4910, 626, 781, 21542, 20513, 10296, 3595, 9933, 2839, 199, 2, 1297, 2, 298, 32059, 2, 5423, 12, 1325, 19762, 10296, 3595, 2702, 12, 28441, 12, 4546, 955, 5423, 14, 199, 199, 3917, 1265, 787, 20234, 314, 1233, 2348, 543, 314, 1233, 315, 314, 10543, 1122, 2199, 12, 506, 199, 14600, 626, 7037, 370, 314, 286, 30566, 4340, 314, 6982, 3555, 334, 6777, 365, 1202, 701, 199, 10511, 1122, 9, 19115, 1536, 5821, 12, 314, 7794, 315, 314, 10543, 1122, 1233, 1630, 440, 2035, 314, 199, 4525, 4546, 1329, 334, 5609, 787, 3247, 315, 314, 1865, 2985, 7468, 315, 314, 4546, 2547, 12, 199, 6777, 367, 282, 12050, 17638, 1329, 365, 2222, 1109, 1907, 857, 680, 325, 14, 71, 14, 199, 199, 12847, 63, 1829, 275, 10199, 4836, 480, 4469, 401, 272, 18241, 480, 27912, 1121, 1288, 272, 18241, 480, 411, 2931, 1288, 272, 18241, 480, 411, 5038, 1288, 272, 18241, 480, 67, 6376, 1288, 272, 18241, 480, 374, 6376, 1288, 272, 18241, 480, 8822, 320, 1190, 1288, 272, 18241, 480, 630, 1288, 272, 18241, 480, 12286, 1288, 339, 10199, 792, 480, 10421, 401, 1520, 12, 25072, 29, 549, 395, 272, 18241, 480, 23254, 1288, 199, 9, 199, 199, 19348, 3163, 365, 642, 2702, 334, 73, 14, 69, 14, 3432, 314, 1642, 901, 365, 4546, 1520, 12, 2066, 1227, 5423, 5133, 199, 2075, 378, 314, 4546, 4114, 3224, 370, 1695, 304, 199, 199, 9594, 2702, 485, 12847, 63, 4469, 63, 84, 267, 469, 199, 6331, 1493, 14, 16, 15870, 31858, 13170, 257, 520, 413, 27, 199, 6331, 1493, 14, 17, 15870, 31858, 286, 8270, 258, 520, 413, 27, 199, 6331, 1493, 14, 18, 15870, 31858, 312, 86, 320, 1190, 257, 520, 413, 27, 199, 6331, 1493, 14, 19, 15870, 31858, 5712, 3505, 520, 413, 27, 199, 6331, 1493, 14, 20, 15870, 31858, 286, 6376, 221, 520, 413, 27, 199, 6331, 1493, 14, 21, 15870, 31858, 1687, 5038, 520, 413, 27, 199, 6331, 1493, 14, 22, 15870, 31858, 1687, 2931, 257, 520, 413, 27, 199, 6331, 1493, 14, 23, 15870, 31858, 31336, 1121, 257, 520, 413, 27, 199, 6331, 4587, 14, 16, 15870, 31858, 27582, 257, 520, 413, 27, 199, 6331, 4587, 14, 17, 15870, 31858, 4644, 520, 1520, 27, 199, 6331, 7432, 15870, 789, 267, 445, 54, 63, 4469, 63, 84, 12, 627, 4222, 54, 63, 4469, 63, 84, 12, 1011, 48, 4222, 54, 63, 4469, 63, 84, 27, 199, 199, 24430, 781, 787, 9617, 436, 886, 440, 2934, 370, 4926, 1233, 1006, 314, 5523, 10269, 12, 781, 199, 11184, 590, 1900, 282, 4690, 687, 314, 445, 4514, 12, 436, 2066, 675, 652, 2348, 5370, 199, 4941, 314, 298, 77, 681, 697, 2, 4690, 334, 6777, 365, 2808, 315, 314, 4690, 7611, 680, 199, 199, 1014, 921, 30107, 12546, 14, 1773, 393, 14, 957, 15, 2676, 63, 10511, 88, 14, 3065, 26, 16605, 83, 1533, 63, 9277, 15, 2613, 15, 10511, 63, 815, 14, 72, 199, 199, 8632, 6040, 12591, 402, 30280, 6057, 26, 199, 2859, 921, 13211, 14, 3098, 1365, 14, 957, 15, 1786, 3605, 4312, 15, 19616, 4133, 15, 10511, 199, 199, 1918, 18284, 8377, 370, 25410, 3794, 883, 506, 1911, 2348, 26, 199, 1014, 921, 1038, 281, 264, 773, 14, 5856, 529, 1152, 13, 22683, 14, 4391, 15, 1628, 63, 6321, 15, 3053, 63, 8169, 63, 804, 63, 86, 17, 14, 16, 14, 5607, 199, 199, 624, 199, 199, 363, 2502, 363, 275, 298, 45, 11781, 1849, 16800, 665, 551, 3786, 14586, 32, 6799, 14, 957, 4335, 199, 199, 646, 5739, 199, 646, 295, 199, 646, 13377, 515, 199, 646, 747, 199, 646, 4298, 199, 646, 3873, 199, 646, 984, 199, 646, 4011, 18, 199, 199, 504, 295, 22360, 492, 29259, 1142, 199, 504, 295, 22360, 492, 3589, 199, 504, 295, 22360, 492, 1559, 199, 504, 295, 22360, 492, 511, 773, 199, 504, 295, 22360, 492, 3778, 199, 199, 504, 295, 22360, 14, 5265, 492, 6170, 199, 504, 295, 22360, 14, 5265, 14, 18942, 4285, 492, 4465, 199, 504, 295, 22360, 14, 5265, 14, 1883, 9316, 492, 5678, 199, 504, 295, 22360, 14, 5265, 14, 1883, 9316, 14, 8258, 492, 4837, 63, 86, 1313, 421, 199, 533, 16347, 32641, 8, 1018, 14, 6231, 28593, 4256, 12, 3589, 14, 22193, 5736, 3110, 12, 2049, 3589, 14, 3110, 304, 272, 408, 11135, 314, 30280, 570, 367, 376 ]
[ 799, 22360, 15825, 21684, 78, 17378, 199, 3, 1898, 6927, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 334, 292, 199, 3, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 199, 3, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 1666, 314, 1664, 199, 3, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 15673, 13, 13421, 8217, 199, 3, 199, 199, 3, 4287, 26, 3507, 29, 6798, 13, 2732, 199, 199, 624, 20676, 8963, 787, 367, 13335, 20529, 15332, 30280, 570, 14, 199, 199, 15242, 26, 199, 2859, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 10511, 1122, 15, 199, 1014, 921, 573, 89, 1148, 14, 66, 7270, 14173, 14, 271, 15, 9488, 15, 709, 15, 1313, 13, 1745, 14, 1360, 199, 1014, 921, 30107, 12546, 14, 1773, 393, 14, 957, 15, 2676, 63, 10511, 88, 14, 3065, 199, 199, 47, 300, 14850, 2348, 365, 440, 370, 506, 282, 4890, 1798, 367, 30280, 1584, 14, 3898, 728, 12, 781, 787, 199, 893, 316, 370, 5536, 1454, 314, 11012, 2556, 781, 1929, 315, 1865, 370, 1900, 282, 199, 497, 22360, 4690, 14, 961, 4910, 626, 781, 21542, 20513, 10296, 3595, 9933, 2839, 199, 2, 1297, 2, 298, 32059, 2, 5423, 12, 1325, 19762, 10296, 3595, 2702, 12, 28441, 12, 4546, 955, 5423, 14, 199, 199, 3917, 1265, 787, 20234, 314, 1233, 2348, 543, 314, 1233, 315, 314, 10543, 1122, 2199, 12, 506, 199, 14600, 626, 7037, 370, 314, 286, 30566, 4340, 314, 6982, 3555, 334, 6777, 365, 1202, 701, 199, 10511, 1122, 9, 19115, 1536, 5821, 12, 314, 7794, 315, 314, 10543, 1122, 1233, 1630, 440, 2035, 314, 199, 4525, 4546, 1329, 334, 5609, 787, 3247, 315, 314, 1865, 2985, 7468, 315, 314, 4546, 2547, 12, 199, 6777, 367, 282, 12050, 17638, 1329, 365, 2222, 1109, 1907, 857, 680, 325, 14, 71, 14, 199, 199, 12847, 63, 1829, 275, 10199, 4836, 480, 4469, 401, 272, 18241, 480, 27912, 1121, 1288, 272, 18241, 480, 411, 2931, 1288, 272, 18241, 480, 411, 5038, 1288, 272, 18241, 480, 67, 6376, 1288, 272, 18241, 480, 374, 6376, 1288, 272, 18241, 480, 8822, 320, 1190, 1288, 272, 18241, 480, 630, 1288, 272, 18241, 480, 12286, 1288, 339, 10199, 792, 480, 10421, 401, 1520, 12, 25072, 29, 549, 395, 272, 18241, 480, 23254, 1288, 199, 9, 199, 199, 19348, 3163, 365, 642, 2702, 334, 73, 14, 69, 14, 3432, 314, 1642, 901, 365, 4546, 1520, 12, 2066, 1227, 5423, 5133, 199, 2075, 378, 314, 4546, 4114, 3224, 370, 1695, 304, 199, 199, 9594, 2702, 485, 12847, 63, 4469, 63, 84, 267, 469, 199, 6331, 1493, 14, 16, 15870, 31858, 13170, 257, 520, 413, 27, 199, 6331, 1493, 14, 17, 15870, 31858, 286, 8270, 258, 520, 413, 27, 199, 6331, 1493, 14, 18, 15870, 31858, 312, 86, 320, 1190, 257, 520, 413, 27, 199, 6331, 1493, 14, 19, 15870, 31858, 5712, 3505, 520, 413, 27, 199, 6331, 1493, 14, 20, 15870, 31858, 286, 6376, 221, 520, 413, 27, 199, 6331, 1493, 14, 21, 15870, 31858, 1687, 5038, 520, 413, 27, 199, 6331, 1493, 14, 22, 15870, 31858, 1687, 2931, 257, 520, 413, 27, 199, 6331, 1493, 14, 23, 15870, 31858, 31336, 1121, 257, 520, 413, 27, 199, 6331, 4587, 14, 16, 15870, 31858, 27582, 257, 520, 413, 27, 199, 6331, 4587, 14, 17, 15870, 31858, 4644, 520, 1520, 27, 199, 6331, 7432, 15870, 789, 267, 445, 54, 63, 4469, 63, 84, 12, 627, 4222, 54, 63, 4469, 63, 84, 12, 1011, 48, 4222, 54, 63, 4469, 63, 84, 27, 199, 199, 24430, 781, 787, 9617, 436, 886, 440, 2934, 370, 4926, 1233, 1006, 314, 5523, 10269, 12, 781, 199, 11184, 590, 1900, 282, 4690, 687, 314, 445, 4514, 12, 436, 2066, 675, 652, 2348, 5370, 199, 4941, 314, 298, 77, 681, 697, 2, 4690, 334, 6777, 365, 2808, 315, 314, 4690, 7611, 680, 199, 199, 1014, 921, 30107, 12546, 14, 1773, 393, 14, 957, 15, 2676, 63, 10511, 88, 14, 3065, 26, 16605, 83, 1533, 63, 9277, 15, 2613, 15, 10511, 63, 815, 14, 72, 199, 199, 8632, 6040, 12591, 402, 30280, 6057, 26, 199, 2859, 921, 13211, 14, 3098, 1365, 14, 957, 15, 1786, 3605, 4312, 15, 19616, 4133, 15, 10511, 199, 199, 1918, 18284, 8377, 370, 25410, 3794, 883, 506, 1911, 2348, 26, 199, 1014, 921, 1038, 281, 264, 773, 14, 5856, 529, 1152, 13, 22683, 14, 4391, 15, 1628, 63, 6321, 15, 3053, 63, 8169, 63, 804, 63, 86, 17, 14, 16, 14, 5607, 199, 199, 624, 199, 199, 363, 2502, 363, 275, 298, 45, 11781, 1849, 16800, 665, 551, 3786, 14586, 32, 6799, 14, 957, 4335, 199, 199, 646, 5739, 199, 646, 295, 199, 646, 13377, 515, 199, 646, 747, 199, 646, 4298, 199, 646, 3873, 199, 646, 984, 199, 646, 4011, 18, 199, 199, 504, 295, 22360, 492, 29259, 1142, 199, 504, 295, 22360, 492, 3589, 199, 504, 295, 22360, 492, 1559, 199, 504, 295, 22360, 492, 511, 773, 199, 504, 295, 22360, 492, 3778, 199, 199, 504, 295, 22360, 14, 5265, 492, 6170, 199, 504, 295, 22360, 14, 5265, 14, 18942, 4285, 492, 4465, 199, 504, 295, 22360, 14, 5265, 14, 1883, 9316, 492, 5678, 199, 504, 295, 22360, 14, 5265, 14, 1883, 9316, 14, 8258, 492, 4837, 63, 86, 1313, 421, 199, 533, 16347, 32641, 8, 1018, 14, 6231, 28593, 4256, 12, 3589, 14, 22193, 5736, 3110, 12, 2049, 3589, 14, 3110, 304, 272, 408, 11135, 314, 30280, 570, 367, 376, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
AloneRoad/Inforlearn
vendor/simplejson/tests/test_pass1.py
259
1903
from unittest import TestCase import simplejson as json # from http://json.org/JSON_checker/test/pass1.json JSON = r''' [ "JSON Test Pattern pass1", {"object with 1 member":["array with 1 element"]}, {}, [], -42, true, false, null, { "integer": 1234567890, "real": -9876.543210, "e": 0.123456789e-12, "E": 1.234567890E+34, "": 23456789012E666, "zero": 0, "one": 1, "space": " ", "quote": "\"", "backslash": "\\", "controls": "\b\f\n\r\t", "slash": "/ & \/", "alpha": "abcdefghijklmnopqrstuvwyz", "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", "digit": "0123456789", "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?", "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", "true": true, "false": false, "null": null, "array":[ ], "object":{ }, "address": "50 St. James Street", "url": "http://www.JSON.org/", "comment": "// /* <!-- --", "# -- --> */": " ", " s p a c e d " :[1,2 , 3 , 4 , 5 , 6 ,7 ], "compact": [1,2,3,4,5,6,7], "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", "quotes": "&#34; \u0022 %22 0x22 034 &#x22;", "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" : "A key can be any string" }, 0.5 ,98.6 , 99.44 , 1066 ,"rosebud"] ''' class TestPass1(TestCase): def test_parse(self): # test in/out equivalence and parsing res = json.loads(JSON) out = json.dumps(res) self.assertEquals(res, json.loads(out)) try: json.dumps(res, allow_nan=False) except ValueError: pass else: self.fail("23456789012E666 should be out of range")
apache-2.0
[ 504, 2882, 492, 7640, 199, 199, 646, 13804, 465, 2022, 199, 199, 3, 687, 1455, 921, 1001, 14, 1308, 15, 6243, 63, 6743, 15, 396, 15, 1529, 17, 14, 1001, 199, 6243, 275, 519, 2344, 199, 59, 272, 298, 6243, 1379, 27019, 986, 17, 401, 272, 2420, 785, 543, 413, 3653, 582, 905, 1144, 543, 413, 1819, 19057, 272, 5479, 272, 990, 272, 446, 2260, 12, 272, 2549, 12, 272, 3055, 12, 272, 2973, 12, 272, 469, 267, 298, 4115, 582, 32695, 16, 12, 267, 298, 3093, 582, 446, 25, 14690, 14, 1477, 708, 709, 12, 267, 298, 69, 582, 378, 14, 11272, 69, 13, 713, 12, 267, 298, 37, 582, 413, 14, 5533, 6690, 16, 37, 11, 1082, 12, 267, 10812, 221, 26569, 6690, 11533, 37, 11829, 12, 267, 298, 4262, 582, 378, 12, 267, 298, 368, 582, 413, 12, 267, 298, 2638, 582, 298, 3872, 267, 298, 3513, 582, 1867, 5151, 267, 298, 21509, 582, 9926, 401, 267, 298, 13658, 582, 1867, 66, 60, 70, 60, 78, 60, 82, 60, 84, 401, 267, 298, 7001, 582, 3286, 1253, 971, 10665, 267, 298, 4468, 582, 298, 22017, 21241, 87, 19873, 401, 267, 298, 18554, 582, 298, 27108, 25407, 55, 26184, 401, 267, 298, 8573, 582, 298, 11371, 401, 267, 298, 6664, 582, 24505, 17, 94, 1, 32, 3, 22074, 62, 6, 10, 342, 63, 16341, 3126, 356, 14675, 9420, 92, 27, 9758, 30, 15583, 267, 298, 4097, 582, 1867, 85, 29555, 60, 85, 20, 5308, 60, 85, 1407, 1217, 60, 85, 35, 5638, 60, 8231, 2866, 60, 11116, 20, 33, 401, 267, 298, 2052, 582, 2549, 12, 267, 298, 3910, 582, 3055, 12, 267, 298, 2307, 582, 2973, 12, 267, 298, 1144, 19086, 221, 2156, 267, 298, 785, 582, 91, 221, 1660, 267, 298, 1562, 582, 298, 1400, 1933, 14, 1603, 14015, 14259, 401, 267, 298, 633, 582, 298, 1014, 921, 1544, 14, 6243, 14, 1308, 10665, 267, 298, 3349, 582, 23057, 13505, 28253, 1553, 401, 267, 5426, 1553, 10541, 11589, 582, 298, 3872, 267, 298, 308, 299, 282, 286, 325, 366, 298, 520, 59, 17, 12, 18, 2360, 650, 199, 199, 12, 199, 199, 20, 2360, 959, 263, 2360, 3515, 1227, 3698, 2360, 23, 263, 2156, 267, 298, 23046, 582, 359, 17, 12, 18, 12, 19, 12, 20, 12, 21, 12, 22, 12, 23, 467, 267, 298, 1001, 505, 582, 5310, 4451, 785, 543, 413, 3653, 60, 19086, 4451, 1144, 543, 413, 1819, 60, 937, 10750, 267, 298, 14005, 582, 27720, 1082, 27, 971, 85, 27846, 450, 1081, 378, 88, 1081, 378, 1082, 1253, 3, 88, 1081, 17259, 267, 1867, 15, 9780, 3212, 85, 3263, 5100, 60, 85, 34, 1217, 37, 60, 85, 1217, 2905, 60, 85, 4161, 1093, 60, 9870, 983, 60, 11116, 20, 33, 60, 66, 60, 70, 60, 78, 60, 82, 60, 84, 64, 17, 94, 1, 32, 3, 22074, 62, 6, 10, 342, 63, 16341, 9811, 2440, 92, 27, 6536, 14, 8316, 30, 13472, 199, 26, 298, 33, 790, 883, 506, 1263, 1059, 2, 272, 1660, 272, 378, 14, 21, 2360, 2905, 14, 22, 199, 12, 199, 1020, 14, 1602, 199, 12, 199, 199, 709, 1272, 421, 199, 4589, 293, 261, 464, 68, 937, 199, 2344, 199, 199, 533, 1379, 4986, 17, 8, 1746, 304, 272, 347, 511, 63, 1122, 8, 277, 304, 267, 327, 511, 315, 15, 548, 325, 22810, 436, 6057, 267, 522, 275, 2022, 14, 3640, 8, 6243, 9, 267, 734, 275, 2022, 14, 4180, 8, 470, 9, 267, 291, 14, 2947, 8, 470, 12, 2022, 14, 3640, 8, 548, 430, 267, 862, 26, 288, 2022, 14, 4180, 8, 470, 12, 2040, 63, 4304, 29, 797, 9, 267, 871, 1722, 26, 288, 986, 267, 587, 26, 288, 291, 14, 1633, 480, 5533, 6690, 11533, 37, 11829, 1077, 506, 734, 402, 1425, 531, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2882, 492, 7640, 199, 199, 646, 13804, 465, 2022, 199, 199, 3, 687, 1455, 921, 1001, 14, 1308, 15, 6243, 63, 6743, 15, 396, 15, 1529, 17, 14, 1001, 199, 6243, 275, 519, 2344, 199, 59, 272, 298, 6243, 1379, 27019, 986, 17, 401, 272, 2420, 785, 543, 413, 3653, 582, 905, 1144, 543, 413, 1819, 19057, 272, 5479, 272, 990, 272, 446, 2260, 12, 272, 2549, 12, 272, 3055, 12, 272, 2973, 12, 272, 469, 267, 298, 4115, 582, 32695, 16, 12, 267, 298, 3093, 582, 446, 25, 14690, 14, 1477, 708, 709, 12, 267, 298, 69, 582, 378, 14, 11272, 69, 13, 713, 12, 267, 298, 37, 582, 413, 14, 5533, 6690, 16, 37, 11, 1082, 12, 267, 10812, 221, 26569, 6690, 11533, 37, 11829, 12, 267, 298, 4262, 582, 378, 12, 267, 298, 368, 582, 413, 12, 267, 298, 2638, 582, 298, 3872, 267, 298, 3513, 582, 1867, 5151, 267, 298, 21509, 582, 9926, 401, 267, 298, 13658, 582, 1867, 66, 60, 70, 60, 78, 60, 82, 60, 84, 401, 267, 298, 7001, 582, 3286, 1253, 971, 10665, 267, 298, 4468, 582, 298, 22017, 21241, 87, 19873, 401, 267, 298, 18554, 582, 298, 27108, 25407, 55, 26184, 401, 267, 298, 8573, 582, 298, 11371, 401, 267, 298, 6664, 582, 24505, 17, 94, 1, 32, 3, 22074, 62, 6, 10, 342, 63, 16341, 3126, 356, 14675, 9420, 92, 27, 9758, 30, 15583, 267, 298, 4097, 582, 1867, 85, 29555, 60, 85, 20, 5308, 60, 85, 1407, 1217, 60, 85, 35, 5638, 60, 8231, 2866, 60, 11116, 20, 33, 401, 267, 298, 2052, 582, 2549, 12, 267, 298, 3910, 582, 3055, 12, 267, 298, 2307, 582, 2973, 12, 267, 298, 1144, 19086, 221, 2156, 267, 298, 785, 582, 91, 221, 1660, 267, 298, 1562, 582, 298, 1400, 1933, 14, 1603, 14015, 14259, 401, 267, 298, 633, 582, 298, 1014, 921, 1544, 14, 6243, 14, 1308, 10665, 267, 298, 3349, 582, 23057, 13505, 28253, 1553, 401, 267, 5426, 1553, 10541, 11589, 582, 298, 3872, 267, 298, 308, 299, 282, 286, 325, 366, 298, 520, 59, 17, 12, 18, 2360, 650, 199, 199, 12, 199, 199, 20, 2360, 959, 263, 2360, 3515, 1227, 3698, 2360, 23, 263, 2156, 267, 298, 23046, 582, 359, 17, 12, 18, 12, 19, 12, 20, 12, 21, 12, 22, 12, 23, 467, 267, 298, 1001, 505, 582, 5310, 4451, 785, 543, 413, 3653, 60, 19086, 4451, 1144, 543, 413, 1819, 60, 937, 10750, 267, 298, 14005, 582, 27720, 1082, 27, 971, 85, 27846, 450, 1081, 378, 88, 1081, 378, 1082, 1253, 3, 88, 1081, 17259, 267, 1867, 15, 9780, 3212, 85, 3263, 5100, 60, 85, 34, 1217, 37, 60, 85, 1217, 2905, 60, 85, 4161, 1093, 60, 9870, 983, 60, 11116, 20, 33, 60, 66, 60, 70, 60, 78, 60, 82, 60, 84, 64, 17, 94, 1, 32, 3, 22074, 62, 6, 10, 342, 63, 16341, 9811, 2440, 92, 27, 6536, 14, 8316, 30, 13472, 199, 26, 298, 33, 790, 883, 506, 1263, 1059, 2, 272, 1660, 272, 378, 14, 21, 2360, 2905, 14, 22, 199, 12, 199, 1020, 14, 1602, 199, 12, 199, 199, 709, 1272, 421, 199, 4589, 293, 261, 464, 68, 937, 199, 2344, 199, 199, 533, 1379, 4986, 17, 8, 1746, 304, 272, 347, 511, 63, 1122, 8, 277, 304, 267, 327, 511, 315, 15, 548, 325, 22810, 436, 6057, 267, 522, 275, 2022, 14, 3640, 8, 6243, 9, 267, 734, 275, 2022, 14, 4180, 8, 470, 9, 267, 291, 14, 2947, 8, 470, 12, 2022, 14, 3640, 8, 548, 430, 267, 862, 26, 288, 2022, 14, 4180, 8, 470, 12, 2040, 63, 4304, 29, 797, 9, 267, 871, 1722, 26, 288, 986, 267, 587, 26, 288, 291, 14, 1633, 480, 5533, 6690, 11533, 37, 11829, 1077, 506, 734, 402, 1425, 531, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
rupak0577/ginga
ginga/util/io_fits.py
1
11092
# # io_fits.py -- Module wrapper for loading FITS files. # # This is open-source software licensed under a BSD license. # Please see the file LICENSE.txt for details. # """ There are two possible choices for a python FITS file reading package compatible with Ginga: astropy/pyfits and fitsio. Both are based on the CFITSIO library, although it seems that astropy's version has changed quite a bit from the original, while fitsio is still tracking the current version. To force the use of one, do: from ginga.util import io_fits io_fits.use('package') (replace 'package' with one of {'astropy', 'fitsio'}) before you load any images. Otherwise Ginga will try to pick one for you. """ import numpy from ginga.util import iohelper fits_configured = False fitsLoaderClass = None have_pyfits = False have_fitsio = False class FITSError(Exception): pass def use(fitspkg, raise_err=True): global fits_configured, fitsLoaderClass, \ have_pyfits, pyfits, \ have_fitsio, fitsio if fitspkg == 'astropy': try: from astropy.io import fits as pyfits have_pyfits = True fitsLoaderClass = PyFitsFileHandler return True except ImportError: try: # maybe they have a standalone version of pyfits? import pyfits have_pyfits = True fitsLoaderClass = PyFitsFileHandler return True except ImportError as e: if raise_err: raise return False elif fitspkg == 'fitsio': try: import fitsio have_fitsio = True fitsLoaderClass = FitsioFileHandler return True except ImportError as e: if raise_err: raise return False return False class BaseFitsFileHandler(object): # Reserved for future use pass class PyFitsFileHandler(BaseFitsFileHandler): def __init__(self, logger): super(PyFitsFileHandler, self).__init__() if not have_pyfits: raise FITSError("Need astropy or pyfits module installed to use this file handler") self.logger = logger self.kind = 'pyfits' def fromHDU(self, hdu, ahdr): header = hdu.header if hasattr(header, 'cards'): # newer astropy.io.fits don't have ascardlist() for card in header.cards: if len(card.keyword) == 0: continue ahdr.set_card(card.keyword, card.value, comment=card.comment) else: for card in header.ascardlist(): if len(card.key) == 0: continue ahdr.set_card(card.key, card.value, comment=card.comment) def load_hdu(self, hdu, ahdr, fobj=None, naxispath=None): data = hdu.data if data is None: data = numpy.zeros((0, 0)) elif not isinstance(data, numpy.ndarray): data = numpy.zeros((0, 0)) elif 0 in data.shape: data = numpy.zeros((0, 0)) elif len(data.shape) < 2: # Expand 1D arrays into 1xN array data = data.reshape((1, data.shape[0])) else: if naxispath is None: naxispath = [] else: # Drill down naxispath for idx in naxispath: data = data[idx] self.fromHDU(hdu, ahdr) return (data, naxispath) def load_file(self, filespec, ahdr, numhdu=None, naxispath=None, phdr=None, memmap=None): info = iohelper.get_fileinfo(filespec) if not info.ondisk: raise FITSError("File does not appear to be on disk: %s" % ( info.url)) filepath = info.filepath self.logger.debug("Loading file '%s' ..." % (filepath)) fits_f = pyfits.open(filepath, 'readonly', memmap=memmap) # this seems to be necessary now for some fits files... try: fits_f.verify('fix') except Exception as e: raise FITSError("Error loading fits file '%s': %s" % ( filepath, str(e))) if numhdu is None: info = fits_f.info(output=False) extver_db = {} found_valid_hdu = False for i in range(len(fits_f)): hdu = fits_f[i] tup = info[i] name = tup[1] # figure out the EXTVER for this HDU extver = extver_db.setdefault(name, 0) extver += 1 extver_db[name] = extver # rule out HDUs we can't deal with if not (isinstance(hdu, pyfits.ImageHDU) or isinstance(hdu, pyfits.PrimaryHDU)): # Don't open tables, etc. continue if not isinstance(hdu.data, numpy.ndarray): # We need to open a numpy array continue if 0 in hdu.data.shape: # non-pixel or zero-length data hdu? continue #print "data type is %s" % hdu.data.dtype.kind # Looks good, let's try it found_valid_hdu = True if len(name) == 0: numhdu = i else: numhdu = (name, extver) break if not found_valid_hdu: ## raise FITSError("No data HDU found that Ginga can open in '%s'" % ( ## filepath)) # Load just the header numhdu = 0 elif isinstance(numhdu, (int, str)): hdu = fits_f[numhdu] name = hdu.name extver = hdu.ver if len(name) > 0: numhdu = (name, extver) hdu = fits_f[numhdu] data, naxispath = self.load_hdu(hdu, ahdr, fobj=fits_f, naxispath=naxispath) # Read PRIMARY header if phdr is not None: self.fromHDU(fits_f[0], phdr) fits_f.close() return (data, numhdu, naxispath) def create_fits(self, data, header): fits_f = pyfits.HDUList() hdu = pyfits.PrimaryHDU() hdu.data = data for kwd in header.keys(): card = header.get_card(kwd) hdu.header[card.key] = (card.value, card.comment) fits_f.append(hdu) return fits_f def write_fits(self, path, data, header, **kwdargs): fits_f = self.create_fits(data, header) fits_f.writeto(path, **kwdargs) fits_f.close() def save_as_file(self, filepath, data, header, **kwdargs): self.write_fits(filepath, data, header, **kwdargs) class FitsioFileHandler(BaseFitsFileHandler): def __init__(self, logger): super(FitsioFileHandler, self).__init__() if not have_fitsio: raise FITSError("Need fitsio module installed to use this file handler") self.logger = logger self.kind = 'fitsio' def fromHDU(self, hdu, ahdr): header = hdu.read_header() for d in header.records(): if len(d['name']) == 0: continue bnch = ahdr.__setitem__(d['name'], d['value']) bnch.comment = d['comment'] def load_hdu(self, hdu, ahdr, fobj=None, naxispath=None): data = hdu.read() if data is None: data = numpy.zeros((0, 0)) elif not isinstance(data, numpy.ndarray): data = numpy.zeros((0, 0)) elif 0 in data.shape: data = numpy.zeros((0, 0)) elif len(data.shape) < 2: # Expand 1D arrays into 1xN array data = data.reshape((1, data.shape[0])) else: if naxispath is None: naxispath = [] else: # Drill down naxispath for idx in naxispath: data = data[idx] self.fromHDU(hdu, ahdr) return (data, naxispath) def load_file(self, filespec, ahdr, numhdu=None, naxispath=None, phdr=None, memmap=None): info = iohelper.get_fileinfo(filespec) if not info.ondisk: raise FITSError("File does not appear to be on disk: %s" % ( info.url)) filepath = info.filepath self.logger.debug("Loading file '%s' ..." % (filepath)) fits_f = fitsio.FITS(filepath, memmap=memmap) if numhdu is None: found_valid_hdu = False for i in range(len(fits_f)): hdu = fits_f[i] info = hdu.get_info() #print(info) name = info['extname'] extver = info['extver'] if not ('ndims' in info) or (info['ndims'] == 0): # compressed FITS file or non-pixel data hdu? continue #print(dir(hdu)) # Looks good, let's try it found_valid_hdu = True if len(name) == 0: numhdu = i else: numhdu = (name, extver) break if not found_valid_hdu: ## raise FITSError("No data HDU found that Ginga can open in '%s'" % ( ## filepath)) # Just load the header numhdu = 0 elif isinstance(numhdu, (int, str)): hdu = fits_f[numhdu] info = hdu.get_info() name = info['extname'] extver = info['extver'] if len(name) > 0: numhdu = (name, extver) hdu = fits_f[numhdu] data, naxispath = self.load_hdu(hdu, ahdr, fobj=fits_f, naxispath=naxispath) # Read PRIMARY header if phdr is not None: self.fromHDU(fits_f[0], phdr) fits_f.close() return (data, numhdu, naxispath) def create_fits(self, data, header): fits_f = pyfits.HDUList() hdu = pyfits.PrimaryHDU() hdu.data = data for kwd in header.keys(): card = header.get_card(kwd) hdu.header.update(card.key, card.value, comment=card.comment) fits_f.append(hdu) return fits_f def write_fits(self, path, data, header): fits_f = fitsio.FITS(path, 'rw') fits_f = self.create_fits(data, header) fits_f.writeto(path, output_verify='fix') fits_f.close() def save_as_file(self, filepath, data, header, **kwdargs): self.write_fits(filepath, data, header, **kwdargs) if not fits_configured: # default fitsLoaderClass = PyFitsFileHandler # try to use them in this order # astropy is faster for name in ('astropy', 'fitsio'): if use(name, raise_err=False): break def get_fitsloader(kind=None, logger=None): return fitsLoaderClass(logger) #END
bsd-3-clause
[ 3, 199, 3, 5890, 63, 14948, 14, 647, 1553, 5673, 4975, 367, 8697, 481, 5930, 1584, 14, 199, 3, 199, 3, 961, 365, 1551, 13, 1365, 2032, 18233, 1334, 282, 6289, 4190, 14, 199, 3, 7754, 1937, 314, 570, 5113, 14, 2424, 367, 2436, 14, 199, 3, 199, 624, 199, 10924, 787, 2877, 3962, 3415, 367, 282, 2366, 481, 5930, 570, 7664, 2559, 199, 6490, 543, 598, 316, 65, 26, 28753, 15, 647, 14948, 436, 5542, 22961, 14, 221, 17650, 787, 4079, 641, 199, 1589, 6035, 5930, 2090, 3555, 12, 22160, 652, 12237, 626, 28753, 1159, 1015, 965, 199, 2489, 18794, 282, 4546, 687, 314, 3379, 12, 1830, 5542, 22961, 365, 5139, 15161, 199, 1589, 1453, 1015, 14, 199, 199, 1378, 3542, 314, 675, 402, 1373, 12, 886, 26, 339, 687, 486, 316, 65, 14, 1974, 492, 5890, 63, 14948, 272, 5890, 63, 14948, 14, 1180, 360, 2491, 358, 199, 199, 8, 1814, 283, 2491, 7, 543, 1373, 402, 791, 1810, 7537, 297, 283, 3269, 22961, 3071, 2544, 1265, 2248, 199, 1629, 5935, 14, 221, 6630, 598, 316, 65, 911, 862, 370, 3732, 1373, 367, 1265, 14, 199, 624, 199, 646, 2680, 199, 199, 504, 486, 316, 65, 14, 1974, 492, 5890, 3676, 199, 199, 14948, 63, 11786, 275, 756, 199, 14948, 5455, 2543, 275, 488, 199, 7804, 63, 647, 14948, 275, 756, 199, 7804, 63, 3269, 22961, 275, 756, 199, 199, 533, 481, 5930, 547, 8, 1726, 304, 272, 986, 199, 199, 318, 675, 8, 3269, 681, 9761, 12, 746, 63, 1508, 29, 549, 304, 272, 2288, 20147, 63, 11786, 12, 20147, 5455, 2543, 12, 971, 1779, 1172, 63, 647, 14948, 12, 1134, 14948, 12, 971, 1779, 1172, 63, 3269, 22961, 12, 5542, 22961, 339, 340, 5542, 681, 9761, 508, 283, 1810, 7537, 356, 267, 862, 26, 288, 687, 28753, 14, 2308, 492, 20147, 465, 1134, 14948, 288, 1172, 63, 647, 14948, 275, 715, 288, 20147, 5455, 2543, 275, 1611, 38, 1405, 21982, 288, 372, 715, 398, 871, 3545, 26, 288, 862, 26, 355, 327, 11703, 2985, 1172, 282, 18042, 1015, 402, 1134, 14948, 31, 355, 492, 1134, 14948, 355, 1172, 63, 647, 14948, 275, 715, 355, 20147, 5455, 2543, 275, 1611, 38, 1405, 21982, 355, 372, 715, 953, 871, 3545, 465, 325, 26, 355, 340, 746, 63, 1508, 26, 490, 746, 267, 372, 756, 339, 916, 5542, 681, 9761, 508, 283, 3269, 22961, 356, 267, 862, 26, 288, 492, 5542, 22961, 288, 1172, 63, 3269, 22961, 275, 715, 288, 20147, 5455, 2543, 275, 25971, 22961, 21982, 288, 372, 715, 398, 871, 3545, 465, 325, 26, 288, 340, 746, 63, 1508, 26, 355, 746, 267, 372, 756, 339, 372, 756, 421, 199, 533, 3523, 38, 1405, 21982, 8, 785, 304, 272, 327, 5702, 367, 6466, 675, 272, 986, 199, 199, 533, 1611, 38, 1405, 21982, 8, 1563, 38, 1405, 21982, 304, 339, 347, 636, 826, 721, 277, 12, 2512, 304, 267, 1613, 8, 2713, 38, 1405, 21982, 12, 291, 2843, 826, 4533, 398, 340, 440, 1172, 63, 647, 14948, 26, 288, 746, 481, 5930, 547, 480, 17809, 28753, 503, 1134, 14948, 859, 4903, 370, 675, 642, 570, 3016, 531, 267, 291, 14, 2921, 275, 2512, 267, 291, 14, 5091, 275, 283, 647, 14948, 7, 339, 347, 687, 40, 4980, 8, 277, 12, 394, 2033, 12, 282, 11244, 304, 267, 1406, 275, 394, 2033, 14, 1291, 267, 340, 2688, 8, 1291, 12, 283, 13761, 735, 288, 327, 15666, 28753, 14, 2308, 14, 14948, 2793, 1133, 1172, 465, 5841, 513, 342, 288, 367, 12564, 315, 1406, 14, 13761, 26, 355, 340, 822, 8, 5841, 14, 6691, 9, 508, 378, 26, 490, 1980, 355, 282, 11244, 14, 409, 63, 5841, 8, 5841, 14, 6691, 12, 12564, 14, 585, 12, 3721, 29, 5841, 14, 3349, 9, 267, 587, 26, 288, 367, 12564, 315, 1406, 14, 305, 5841, 513, 837, 355, 340, 822, 8, 5841, 14, 498, 9, 508, 378, 26, 490, 1980, 355, 282, 11244, 14, 409, 63, 5841, 8, 5841, 14, 498, 12, 12564, 14, 585, 12, 3721, 29, 5841, 14, 3349, 9, 339, 347, 2248, 63, 72, 2033, 8, 277, 12, 394, 2033, 12, 282, 11244, 12, 29962, 29, 403, 12, 302, 3127, 515, 29, 403, 304, 267, 666, 275, 394, 2033, 14, 576, 267, 340, 666, 365, 488, 26, 288, 666, 275, 2680, 14, 4250, 1332, 16, 12, 378, 430, 267, 916, 440, 1228, 8, 576, 12, 2680, 14, 8237, 304, 288, 666, 275, 2680, 14, 4250, 1332, 16, 12, 378, 430, 267, 916, 378, 315, 666, 14, 1392, 26, 288, 666, 275, 2680, 14, 4250, 1332, 16, 12, 378, 430, 267, 916, 822, 8, 576, 14, 1392, 9, 665, 499, 26, 288, 327, 18890, 413, 36, 6572, 1901, 413, 31985, 1625, 288, 666, 275, 666, 14, 5217, 1332, 17, 12, 666, 14, 1392, 59, 16, 2459, 267, 587, 26, 288, 340, 302, 3127, 515, 365, 488, 26, 355, 302, 3127, 515, 275, 942, 288, 587, 26, 355, 327, 577, 322, 914, 3224, 302, 3127, 515, 355, 367, 4280, 315, 302, 3127, 515, 26, 490, 666, 275, 666, 59, 2996, 61, 398, 291, 14, 504, 40, 4980, 8, 72, 2033, 12, 282, 11244, 9, 267, 372, 334, 576, 12, 302, 3127, 515, 9, 339, 347, 2248, 63, 493, 8, 277, 12, 1584, 733, 12, 282, 11244, 12, 1967, 72, 2033, 29, 403, 12, 302, 3127, 515, 29, 403, 12, 2116, 3945, 5012, 29, 403, 12, 7573, 1130, 29, 403, 304, 398, 2256, 275, 5890, 3676, 14, 362, 63, 493, 815, 8, 493, 1650, 9, 267, 340, 440, 2256, 14, 265, 4032, 26, 288, 746, 481, 5930, 547, 480, 1173, 1630, 440, 7468, 370, 506, 641, 4543, 26, 450, 83, 2, 450, 334, 355, 2256, 14, 633, 430, 267, 9911, 275, 2256, 14, 7218, 398, 291, 14, 2921, 14, 1757, 480, 19236, 570, 1543, 83, 7, 21742, 450, 334, 7218, 430, 267, 20147, 63, 70, 275, 1134, 14948, 14, 1490, 8, 7218, 12, 283, 6753, 297, 7573, 1130, 29, 5286, 1130, 9, 398, 327, 642, 12237, 370, 506, 5784, 3063, 367, 2005, 20147, 1584, 1396, 267, 862, 26, 288, 20147, 63, 70, 14, 4712, 360, 970, 358, 267, 871, 2186, 465, 325, 26, 288, 746 ]
[ 199, 3, 5890, 63, 14948, 14, 647, 1553, 5673, 4975, 367, 8697, 481, 5930, 1584, 14, 199, 3, 199, 3, 961, 365, 1551, 13, 1365, 2032, 18233, 1334, 282, 6289, 4190, 14, 199, 3, 7754, 1937, 314, 570, 5113, 14, 2424, 367, 2436, 14, 199, 3, 199, 624, 199, 10924, 787, 2877, 3962, 3415, 367, 282, 2366, 481, 5930, 570, 7664, 2559, 199, 6490, 543, 598, 316, 65, 26, 28753, 15, 647, 14948, 436, 5542, 22961, 14, 221, 17650, 787, 4079, 641, 199, 1589, 6035, 5930, 2090, 3555, 12, 22160, 652, 12237, 626, 28753, 1159, 1015, 965, 199, 2489, 18794, 282, 4546, 687, 314, 3379, 12, 1830, 5542, 22961, 365, 5139, 15161, 199, 1589, 1453, 1015, 14, 199, 199, 1378, 3542, 314, 675, 402, 1373, 12, 886, 26, 339, 687, 486, 316, 65, 14, 1974, 492, 5890, 63, 14948, 272, 5890, 63, 14948, 14, 1180, 360, 2491, 358, 199, 199, 8, 1814, 283, 2491, 7, 543, 1373, 402, 791, 1810, 7537, 297, 283, 3269, 22961, 3071, 2544, 1265, 2248, 199, 1629, 5935, 14, 221, 6630, 598, 316, 65, 911, 862, 370, 3732, 1373, 367, 1265, 14, 199, 624, 199, 646, 2680, 199, 199, 504, 486, 316, 65, 14, 1974, 492, 5890, 3676, 199, 199, 14948, 63, 11786, 275, 756, 199, 14948, 5455, 2543, 275, 488, 199, 7804, 63, 647, 14948, 275, 756, 199, 7804, 63, 3269, 22961, 275, 756, 199, 199, 533, 481, 5930, 547, 8, 1726, 304, 272, 986, 199, 199, 318, 675, 8, 3269, 681, 9761, 12, 746, 63, 1508, 29, 549, 304, 272, 2288, 20147, 63, 11786, 12, 20147, 5455, 2543, 12, 971, 1779, 1172, 63, 647, 14948, 12, 1134, 14948, 12, 971, 1779, 1172, 63, 3269, 22961, 12, 5542, 22961, 339, 340, 5542, 681, 9761, 508, 283, 1810, 7537, 356, 267, 862, 26, 288, 687, 28753, 14, 2308, 492, 20147, 465, 1134, 14948, 288, 1172, 63, 647, 14948, 275, 715, 288, 20147, 5455, 2543, 275, 1611, 38, 1405, 21982, 288, 372, 715, 398, 871, 3545, 26, 288, 862, 26, 355, 327, 11703, 2985, 1172, 282, 18042, 1015, 402, 1134, 14948, 31, 355, 492, 1134, 14948, 355, 1172, 63, 647, 14948, 275, 715, 355, 20147, 5455, 2543, 275, 1611, 38, 1405, 21982, 355, 372, 715, 953, 871, 3545, 465, 325, 26, 355, 340, 746, 63, 1508, 26, 490, 746, 267, 372, 756, 339, 916, 5542, 681, 9761, 508, 283, 3269, 22961, 356, 267, 862, 26, 288, 492, 5542, 22961, 288, 1172, 63, 3269, 22961, 275, 715, 288, 20147, 5455, 2543, 275, 25971, 22961, 21982, 288, 372, 715, 398, 871, 3545, 465, 325, 26, 288, 340, 746, 63, 1508, 26, 355, 746, 267, 372, 756, 339, 372, 756, 421, 199, 533, 3523, 38, 1405, 21982, 8, 785, 304, 272, 327, 5702, 367, 6466, 675, 272, 986, 199, 199, 533, 1611, 38, 1405, 21982, 8, 1563, 38, 1405, 21982, 304, 339, 347, 636, 826, 721, 277, 12, 2512, 304, 267, 1613, 8, 2713, 38, 1405, 21982, 12, 291, 2843, 826, 4533, 398, 340, 440, 1172, 63, 647, 14948, 26, 288, 746, 481, 5930, 547, 480, 17809, 28753, 503, 1134, 14948, 859, 4903, 370, 675, 642, 570, 3016, 531, 267, 291, 14, 2921, 275, 2512, 267, 291, 14, 5091, 275, 283, 647, 14948, 7, 339, 347, 687, 40, 4980, 8, 277, 12, 394, 2033, 12, 282, 11244, 304, 267, 1406, 275, 394, 2033, 14, 1291, 267, 340, 2688, 8, 1291, 12, 283, 13761, 735, 288, 327, 15666, 28753, 14, 2308, 14, 14948, 2793, 1133, 1172, 465, 5841, 513, 342, 288, 367, 12564, 315, 1406, 14, 13761, 26, 355, 340, 822, 8, 5841, 14, 6691, 9, 508, 378, 26, 490, 1980, 355, 282, 11244, 14, 409, 63, 5841, 8, 5841, 14, 6691, 12, 12564, 14, 585, 12, 3721, 29, 5841, 14, 3349, 9, 267, 587, 26, 288, 367, 12564, 315, 1406, 14, 305, 5841, 513, 837, 355, 340, 822, 8, 5841, 14, 498, 9, 508, 378, 26, 490, 1980, 355, 282, 11244, 14, 409, 63, 5841, 8, 5841, 14, 498, 12, 12564, 14, 585, 12, 3721, 29, 5841, 14, 3349, 9, 339, 347, 2248, 63, 72, 2033, 8, 277, 12, 394, 2033, 12, 282, 11244, 12, 29962, 29, 403, 12, 302, 3127, 515, 29, 403, 304, 267, 666, 275, 394, 2033, 14, 576, 267, 340, 666, 365, 488, 26, 288, 666, 275, 2680, 14, 4250, 1332, 16, 12, 378, 430, 267, 916, 440, 1228, 8, 576, 12, 2680, 14, 8237, 304, 288, 666, 275, 2680, 14, 4250, 1332, 16, 12, 378, 430, 267, 916, 378, 315, 666, 14, 1392, 26, 288, 666, 275, 2680, 14, 4250, 1332, 16, 12, 378, 430, 267, 916, 822, 8, 576, 14, 1392, 9, 665, 499, 26, 288, 327, 18890, 413, 36, 6572, 1901, 413, 31985, 1625, 288, 666, 275, 666, 14, 5217, 1332, 17, 12, 666, 14, 1392, 59, 16, 2459, 267, 587, 26, 288, 340, 302, 3127, 515, 365, 488, 26, 355, 302, 3127, 515, 275, 942, 288, 587, 26, 355, 327, 577, 322, 914, 3224, 302, 3127, 515, 355, 367, 4280, 315, 302, 3127, 515, 26, 490, 666, 275, 666, 59, 2996, 61, 398, 291, 14, 504, 40, 4980, 8, 72, 2033, 12, 282, 11244, 9, 267, 372, 334, 576, 12, 302, 3127, 515, 9, 339, 347, 2248, 63, 493, 8, 277, 12, 1584, 733, 12, 282, 11244, 12, 1967, 72, 2033, 29, 403, 12, 302, 3127, 515, 29, 403, 12, 2116, 3945, 5012, 29, 403, 12, 7573, 1130, 29, 403, 304, 398, 2256, 275, 5890, 3676, 14, 362, 63, 493, 815, 8, 493, 1650, 9, 267, 340, 440, 2256, 14, 265, 4032, 26, 288, 746, 481, 5930, 547, 480, 1173, 1630, 440, 7468, 370, 506, 641, 4543, 26, 450, 83, 2, 450, 334, 355, 2256, 14, 633, 430, 267, 9911, 275, 2256, 14, 7218, 398, 291, 14, 2921, 14, 1757, 480, 19236, 570, 1543, 83, 7, 21742, 450, 334, 7218, 430, 267, 20147, 63, 70, 275, 1134, 14948, 14, 1490, 8, 7218, 12, 283, 6753, 297, 7573, 1130, 29, 5286, 1130, 9, 398, 327, 642, 12237, 370, 506, 5784, 3063, 367, 2005, 20147, 1584, 1396, 267, 862, 26, 288, 20147, 63, 70, 14, 4712, 360, 970, 358, 267, 871, 2186, 465, 325, 26, 288, 746, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
mindnervestech/mnrp
addons/mail/mail_alias.py
72
15479
# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Business Applications # Copyright (C) 2012 OpenERP S.A. (<http://openerp.com>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## import logging import re import unicodedata from openerp.osv import fields, osv from openerp.tools import ustr from openerp.modules.registry import RegistryManager from openerp import SUPERUSER_ID from openerp.tools.translate import _ _logger = logging.getLogger(__name__) # Inspired by http://stackoverflow.com/questions/517923 def remove_accents(input_str): """Suboptimal-but-better-than-nothing way to replace accented latin letters by an ASCII equivalent. Will obviously change the meaning of input_str and work only for some cases""" input_str = ustr(input_str) nkfd_form = unicodedata.normalize('NFKD', input_str) return u''.join([c for c in nkfd_form if not unicodedata.combining(c)]) class mail_alias(osv.Model): """A Mail Alias is a mapping of an email address with a given OpenERP Document model. It is used by OpenERP's mail gateway when processing incoming emails sent to the system. If the recipient address (To) of the message matches a Mail Alias, the message will be either processed following the rules of that alias. If the message is a reply it will be attached to the existing discussion on the corresponding record, otherwise a new record of the corresponding model will be created. This is meant to be used in combination with a catch-all email configuration on the company's mail server, so that as soon as a new mail.alias is created, it becomes immediately usable and OpenERP will accept email for it. """ _name = 'mail.alias' _description = "Email Aliases" _rec_name = 'alias_name' _order = 'alias_model_id, alias_name' def _get_alias_domain(self, cr, uid, ids, name, args, context=None): ir_config_parameter = self.pool.get("ir.config_parameter") domain = ir_config_parameter.get_param(cr, uid, "mail.catchall.domain", context=context) return dict.fromkeys(ids, domain or "") _columns = { 'alias_name': fields.char('Alias Name', help="The name of the email alias, e.g. 'jobs' if you want to catch emails for <jobs@example.odoo.com>",), 'alias_model_id': fields.many2one('ir.model', 'Aliased Model', required=True, ondelete="cascade", help="The model (Odoo Document Kind) to which this alias " "corresponds. Any incoming email that does not reply to an " "existing record will cause the creation of a new record " "of this model (e.g. a Project Task)", # hack to only allow selecting mail_thread models (we might # (have a few false positives, though) domain="[('field_id.name', '=', 'message_ids')]"), 'alias_user_id': fields.many2one('res.users', 'Owner', help="The owner of records created upon receiving emails on this alias. " "If this field is not set the system will attempt to find the right owner " "based on the sender (From) address, or will use the Administrator account " "if no system user is found for that address."), 'alias_defaults': fields.text('Default Values', required=True, help="A Python dictionary that will be evaluated to provide " "default values when creating new records for this alias."), 'alias_force_thread_id': fields.integer('Record Thread ID', help="Optional ID of a thread (record) to which all incoming " "messages will be attached, even if they did not reply to it. " "If set, this will disable the creation of new records completely."), 'alias_domain': fields.function(_get_alias_domain, string="Alias domain", type='char'), 'alias_parent_model_id': fields.many2one('ir.model', 'Parent Model', help="Parent model holding the alias. The model holding the alias reference\n" "is not necessarily the model given by alias_model_id\n" "(example: project (parent_model) and task (model))"), 'alias_parent_thread_id': fields.integer('Parent Record Thread ID', help="ID of the parent record holding the alias (example: project holding the task creation alias)"), 'alias_contact': fields.selection([ ('everyone', 'Everyone'), ('partners', 'Authenticated Partners'), ('followers', 'Followers only'), ], string='Alias Contact Security', required=True, help="Policy to post a message on the document using the mailgateway.\n" "- everyone: everyone can post\n" "- partners: only authenticated partners\n" "- followers: only followers of the related document\n"), } _defaults = { 'alias_defaults': '{}', 'alias_user_id': lambda self, cr, uid, context: uid, # looks better when creating new aliases - even if the field is informative only 'alias_domain': lambda self, cr, uid, context: self._get_alias_domain(cr, SUPERUSER_ID, [1], None, None)[1], 'alias_contact': 'everyone', } _sql_constraints = [ ('alias_unique', 'UNIQUE(alias_name)', 'Unfortunately this email alias is already used, please choose a unique one') ] def _check_alias_defaults(self, cr, uid, ids, context=None): try: for record in self.browse(cr, uid, ids, context=context): dict(eval(record.alias_defaults)) except Exception: return False return True _constraints = [ (_check_alias_defaults, '''Invalid expression, it must be a literal python dictionary definition e.g. "{'field': 'value'}"''', ['alias_defaults']), ] def name_get(self, cr, uid, ids, context=None): """Return the mail alias display alias_name, including the implicit mail catchall domain if exists from config otherwise "New Alias". e.g. `jobs@mail.odoo.com` or `jobs` or 'New Alias' """ res = [] for record in self.browse(cr, uid, ids, context=context): if record.alias_name and record.alias_domain: res.append((record['id'], "%s@%s" % (record.alias_name, record.alias_domain))) elif record.alias_name: res.append((record['id'], "%s" % (record.alias_name))) else: res.append((record['id'], _("Inactive Alias"))) return res def _find_unique(self, cr, uid, name, alias_id=False, context=None): """Find a unique alias name similar to ``name``. If ``name`` is already taken, make a variant by adding an integer suffix until an unused alias is found. """ sequence = None while True: new_name = "%s%s" % (name, sequence) if sequence is not None else name domain = [('alias_name', '=', new_name)] if alias_id: domain += [('id', '!=', alias_id)] if not self.search(cr, uid, domain): break sequence = (sequence + 1) if sequence else 2 return new_name def _clean_and_make_unique(self, cr, uid, name, alias_id=False, context=None): # when an alias name appears to already be an email, we keep the local part only name = remove_accents(name).lower().split('@')[0] name = re.sub(r'[^\w+.]+', '-', name) return self._find_unique(cr, uid, name, alias_id=alias_id, context=context) def migrate_to_alias(self, cr, child_model_name, child_table_name, child_model_auto_init_fct, alias_model_name, alias_id_column, alias_key, alias_prefix='', alias_force_key='', alias_defaults={}, alias_generate_name=False, context=None): """ Installation hook to create aliases for all users and avoid constraint errors. :param child_model_name: model name of the child class (i.e. res.users) :param child_table_name: table name of the child class (i.e. res_users) :param child_model_auto_init_fct: pointer to the _auto_init function (i.e. super(res_users,self)._auto_init(cr, context=context)) :param alias_model_name: name of the aliased model :param alias_id_column: alias_id column (i.e. self._columns['alias_id']) :param alias_key: name of the column used for the unique name (i.e. 'login') :param alias_prefix: prefix for the unique name (i.e. 'jobs' + ...) :param alias_force_key': name of the column for force_thread_id; if empty string, not taken into account :param alias_defaults: dict, keys = mail.alias columns, values = child model column name used for default values (i.e. {'job_id': 'id'}) :param alias_generate_name: automatically generate alias name using prefix / alias key; default alias_name value is False because since 8.0 it is not required anymore """ if context is None: context = {} # disable the unique alias_id not null constraint, to avoid spurious warning during # super.auto_init. We'll reinstall it afterwards. alias_id_column.required = False # call _auto_init res = child_model_auto_init_fct(cr, context=context) registry = RegistryManager.get(cr.dbname) mail_alias = registry.get('mail.alias') child_class_model = registry[child_model_name] no_alias_ids = child_class_model.search(cr, SUPERUSER_ID, [('alias_id', '=', False)], context={'active_test': False}) # Use read() not browse(), to avoid prefetching uninitialized inherited fields for obj_data in child_class_model.read(cr, SUPERUSER_ID, no_alias_ids, [alias_key]): alias_vals = {'alias_name': False} if alias_generate_name: alias_vals['alias_name'] = '%s%s' % (alias_prefix, obj_data[alias_key]) if alias_force_key: alias_vals['alias_force_thread_id'] = obj_data[alias_force_key] alias_vals['alias_defaults'] = dict((k, obj_data[v]) for k, v in alias_defaults.iteritems()) alias_vals['alias_parent_thread_id'] = obj_data['id'] alias_create_ctx = dict(context, alias_model_name=alias_model_name, alias_parent_model_name=child_model_name) alias_id = mail_alias.create(cr, SUPERUSER_ID, alias_vals, context=alias_create_ctx) child_class_model.write(cr, SUPERUSER_ID, obj_data['id'], {'alias_id': alias_id}, context={'mail_notrack': True}) _logger.info('Mail alias created for %s %s (id %s)', child_model_name, obj_data[alias_key], obj_data['id']) # Finally attempt to reinstate the missing constraint try: cr.execute('ALTER TABLE %s ALTER COLUMN alias_id SET NOT NULL' % (child_table_name)) except Exception: _logger.warning("Table '%s': unable to set a NOT NULL constraint on column '%s' !\n"\ "If you want to have it, you should update the records and execute manually:\n"\ "ALTER TABLE %s ALTER COLUMN %s SET NOT NULL", child_table_name, 'alias_id', child_table_name, 'alias_id') # set back the unique alias_id constraint alias_id_column.required = True return res def create(self, cr, uid, vals, context=None): """ Creates an email.alias record according to the values provided in ``vals``, with 2 alterations: the ``alias_name`` value may be suffixed in order to make it unique (and certain unsafe characters replaced), and he ``alias_model_id`` value will set to the model ID of the ``model_name`` context value, if provided. """ if context is None: context = {} model_name = context.get('alias_model_name') parent_model_name = context.get('alias_parent_model_name') if vals.get('alias_name'): vals['alias_name'] = self._clean_and_make_unique(cr, uid, vals.get('alias_name'), context=context) if model_name: model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', model_name)], context=context)[0] vals['alias_model_id'] = model_id if parent_model_name: model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', parent_model_name)], context=context)[0] vals['alias_parent_model_id'] = model_id return super(mail_alias, self).create(cr, uid, vals, context=context) def write(self, cr, uid, ids, vals, context=None): """"give a unique alias name if given alias name is already assigned""" ids = ids if isinstance(ids, (tuple, list)) else [ids] if vals.get('alias_name') and ids: vals['alias_name'] = self._clean_and_make_unique(cr, uid, vals.get('alias_name'), alias_id=ids[0], context=context) return super(mail_alias, self).write(cr, uid, ids, vals, context=context) def open_document(self, cr, uid, ids, context=None): alias = self.browse(cr, uid, ids, context=context)[0] if not alias.alias_model_id or not alias.alias_force_thread_id: return False return { 'view_type': 'form', 'view_mode': 'form', 'res_model': alias.alias_model_id.model, 'res_id': alias.alias_force_thread_id, 'type': 'ir.actions.act_window', } def open_parent_document(self, cr, uid, ids, context=None): alias = self.browse(cr, uid, ids, context=context)[0] if not alias.alias_parent_model_id or not alias.alias_parent_thread_id: return False return { 'view_type': 'form', 'view_mode': 'form', 'res_model': alias.alias_parent_model_id.model, 'res_id': alias.alias_parent_thread_id, 'type': 'ir.actions.act_window', }
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 23813, 24636, 199, 3, 259, 1898, 334, 35, 9, 6029, 7653, 428, 14, 33, 14, 8642, 1014, 921, 11267, 14, 957, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 646, 2050, 199, 646, 295, 199, 646, 23128, 199, 199, 504, 5166, 14, 4795, 492, 1504, 12, 9506, 199, 504, 5166, 14, 2537, 492, 399, 495, 199, 504, 5166, 14, 3112, 14, 5189, 492, 20738, 2988, 199, 504, 5166, 492, 12824, 63, 998, 199, 504, 5166, 14, 2537, 14, 5275, 492, 485, 199, 199, 63, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 3, 12062, 1038, 581, 701, 1455, 921, 23153, 14, 957, 15, 16069, 15, 21, 10699, 1789, 199, 318, 2813, 63, 18028, 83, 8, 1210, 63, 495, 304, 272, 408, 2610, 411, 16757, 13, 7911, 13, 9549, 351, 13, 13797, 13, 16323, 4340, 370, 3350, 1066, 2497, 471, 272, 16899, 14435, 701, 376, 10485, 7353, 14, 12823, 25259, 590, 1570, 314, 272, 11150, 402, 1324, 63, 495, 436, 1736, 1454, 367, 2005, 5560, 624, 272, 1324, 63, 495, 275, 399, 495, 8, 1210, 63, 495, 9, 272, 302, 75, 2592, 63, 964, 275, 23128, 14, 7721, 360, 19749, 13368, 297, 1324, 63, 495, 9, 272, 372, 399, 17067, 904, 779, 67, 367, 286, 315, 302, 75, 2592, 63, 964, 340, 440, 23128, 14, 6560, 7969, 8, 67, 3948, 421, 199, 533, 6016, 63, 3620, 8, 4795, 14, 1685, 304, 272, 408, 33, 18027, 24777, 365, 282, 4412, 402, 376, 3031, 2287, 543, 282, 1627, 7653, 7543, 2126, 1402, 14, 2779, 365, 1202, 701, 7653, 1159, 6016, 10391, 1380, 6661, 12467, 14931, 2126, 4847, 370, 314, 2656, 14, 982, 314, 10318, 2287, 334, 1378, 9, 402, 314, 1245, 4450, 2126, 282, 18027, 24777, 12, 314, 1245, 911, 506, 1902, 7686, 2569, 314, 4713, 2126, 402, 626, 5162, 14, 982, 314, 1245, 365, 282, 9351, 652, 911, 506, 10102, 370, 314, 2126, 3411, 16582, 641, 314, 5226, 2777, 12, 4257, 282, 892, 2126, 2777, 402, 314, 5226, 1402, 911, 506, 2737, 14, 10817, 961, 365, 18329, 370, 506, 1202, 315, 14665, 543, 282, 8579, 13, 452, 3031, 2897, 2126, 641, 314, 7233, 1159, 6016, 1654, 12, 880, 626, 465, 18930, 465, 282, 892, 6016, 14, 3620, 365, 2126, 2737, 12, 652, 15410, 9939, 18025, 436, 7653, 911, 4729, 3031, 367, 652, 14, 1362, 408, 272, 485, 354, 275, 283, 1198, 14, 3620, 7, 272, 485, 1802, 275, 298, 7035, 15170, 3274, 2, 272, 485, 2761, 63, 354, 275, 283, 3620, 63, 354, 7, 272, 485, 1648, 275, 283, 3620, 63, 1238, 63, 344, 12, 5162, 63, 354, 7, 339, 347, 485, 362, 63, 3620, 63, 2261, 8, 277, 12, 2467, 12, 1747, 12, 2762, 12, 536, 12, 1249, 12, 1067, 29, 403, 304, 267, 8190, 63, 888, 63, 5329, 275, 291, 14, 2293, 14, 362, 480, 723, 14, 888, 63, 5329, 531, 267, 2881, 275, 8190, 63, 888, 63, 5329, 14, 362, 63, 635, 8, 1556, 12, 1747, 12, 298, 1198, 14, 9341, 452, 14, 2261, 401, 1067, 29, 1100, 9, 267, 372, 1211, 14, 19164, 8, 1580, 12, 2881, 503, 6899, 339, 485, 3406, 275, 469, 267, 283, 3620, 63, 354, 356, 1504, 14, 1560, 360, 14149, 2812, 297, 288, 1720, 628, 1918, 536, 402, 314, 3031, 5162, 12, 325, 14, 71, 14, 283, 6920, 7, 340, 1265, 2934, 370, 8579, 14931, 367, 665, 6920, 32, 2694, 14, 22058, 14, 957, 7166, 395, 267, 283, 3620, 63, 1238, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 723, 14, 1238, 297, 283, 6985, 11185, 5822, 297, 1415, 29, 549, 12, 16549, 628, 15377, 401, 5101, 1720, 628, 1918, 1402, 334, 47, 16766, 7543, 1804, 688, 9, 370, 1314, 642, 5162, 298, 6901, 298, 989, 3853, 795, 14, 6184, 12467, 3031, 626, 1630, 440, 9351, 370, 376, 298, 6901, 298, 5952, 2777, 911, 7675, 314, 7143, 402, 282, 892, 2777, 298, 6901, 298, 1618, 642, 1402, 334, 69, 14, 71, 14, 282, 7290, 8495, 4186, 5101, 327, 11176, 370, 1454, 2040, 30090, 6016, 63, 2671, 1709, 334, 1129, 5594, 5101, 327, 334, 7804, 282, 9284, 3055, 27609, 12, 10617, 9, 5101, 2881, 628, 19412, 698, 63, 344, 14, 354, 297, 6291, 283, 1188, 63, 1580, 5440, 1288, 267, 283, 3620, 63, 751, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 470, 14, 3707, 297, 283, 14919, 297, 5644, 1720, 628, 1918, 5771, 402, 5767, 2737, 12188, 18390, 14931, 641, 642, 5162, 14, 298, 6059, 298, 3917, 642, 901, 365, 440, 663, 314, 2656, 911, 7427, 370, 2342, 314, 2451, 5771, 298, 6059, 298, 6788, 641, 314, 8904, 334, 2532, 9, 2287, 12, 503, 911, 675, 314, 30660, 2933, 298, 6059, 298, 692, 949, 2656, 922, 365, 1911, 367, 626, 2287, 7651, 267, 283, 3620, 63, 4322, 356, 1504, 14, 505, 360, 2698, 13468, 297, 1415, 29, 549, 12, 4228, 1720, 628, 33, 2018, 2600, 626, 911, 506, 13006, 370, 5647, 298, 5644, 298, 885, 1338, 1380, 6425, 892, 5767, 367, 642, 5162, 7651, 267, 283, 3620, 63, 3990, 63, 2671, 63, 344, 356, 1504, 14, 4115, 360, 5433, 11086, 2870 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 23813, 24636, 199, 3, 259, 1898, 334, 35, 9, 6029, 7653, 428, 14, 33, 14, 8642, 1014, 921, 11267, 14, 957, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 646, 2050, 199, 646, 295, 199, 646, 23128, 199, 199, 504, 5166, 14, 4795, 492, 1504, 12, 9506, 199, 504, 5166, 14, 2537, 492, 399, 495, 199, 504, 5166, 14, 3112, 14, 5189, 492, 20738, 2988, 199, 504, 5166, 492, 12824, 63, 998, 199, 504, 5166, 14, 2537, 14, 5275, 492, 485, 199, 199, 63, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 3, 12062, 1038, 581, 701, 1455, 921, 23153, 14, 957, 15, 16069, 15, 21, 10699, 1789, 199, 318, 2813, 63, 18028, 83, 8, 1210, 63, 495, 304, 272, 408, 2610, 411, 16757, 13, 7911, 13, 9549, 351, 13, 13797, 13, 16323, 4340, 370, 3350, 1066, 2497, 471, 272, 16899, 14435, 701, 376, 10485, 7353, 14, 12823, 25259, 590, 1570, 314, 272, 11150, 402, 1324, 63, 495, 436, 1736, 1454, 367, 2005, 5560, 624, 272, 1324, 63, 495, 275, 399, 495, 8, 1210, 63, 495, 9, 272, 302, 75, 2592, 63, 964, 275, 23128, 14, 7721, 360, 19749, 13368, 297, 1324, 63, 495, 9, 272, 372, 399, 17067, 904, 779, 67, 367, 286, 315, 302, 75, 2592, 63, 964, 340, 440, 23128, 14, 6560, 7969, 8, 67, 3948, 421, 199, 533, 6016, 63, 3620, 8, 4795, 14, 1685, 304, 272, 408, 33, 18027, 24777, 365, 282, 4412, 402, 376, 3031, 2287, 543, 282, 1627, 7653, 7543, 2126, 1402, 14, 2779, 365, 1202, 701, 7653, 1159, 6016, 10391, 1380, 6661, 12467, 14931, 2126, 4847, 370, 314, 2656, 14, 982, 314, 10318, 2287, 334, 1378, 9, 402, 314, 1245, 4450, 2126, 282, 18027, 24777, 12, 314, 1245, 911, 506, 1902, 7686, 2569, 314, 4713, 2126, 402, 626, 5162, 14, 982, 314, 1245, 365, 282, 9351, 652, 911, 506, 10102, 370, 314, 2126, 3411, 16582, 641, 314, 5226, 2777, 12, 4257, 282, 892, 2126, 2777, 402, 314, 5226, 1402, 911, 506, 2737, 14, 10817, 961, 365, 18329, 370, 506, 1202, 315, 14665, 543, 282, 8579, 13, 452, 3031, 2897, 2126, 641, 314, 7233, 1159, 6016, 1654, 12, 880, 626, 465, 18930, 465, 282, 892, 6016, 14, 3620, 365, 2126, 2737, 12, 652, 15410, 9939, 18025, 436, 7653, 911, 4729, 3031, 367, 652, 14, 1362, 408, 272, 485, 354, 275, 283, 1198, 14, 3620, 7, 272, 485, 1802, 275, 298, 7035, 15170, 3274, 2, 272, 485, 2761, 63, 354, 275, 283, 3620, 63, 354, 7, 272, 485, 1648, 275, 283, 3620, 63, 1238, 63, 344, 12, 5162, 63, 354, 7, 339, 347, 485, 362, 63, 3620, 63, 2261, 8, 277, 12, 2467, 12, 1747, 12, 2762, 12, 536, 12, 1249, 12, 1067, 29, 403, 304, 267, 8190, 63, 888, 63, 5329, 275, 291, 14, 2293, 14, 362, 480, 723, 14, 888, 63, 5329, 531, 267, 2881, 275, 8190, 63, 888, 63, 5329, 14, 362, 63, 635, 8, 1556, 12, 1747, 12, 298, 1198, 14, 9341, 452, 14, 2261, 401, 1067, 29, 1100, 9, 267, 372, 1211, 14, 19164, 8, 1580, 12, 2881, 503, 6899, 339, 485, 3406, 275, 469, 267, 283, 3620, 63, 354, 356, 1504, 14, 1560, 360, 14149, 2812, 297, 288, 1720, 628, 1918, 536, 402, 314, 3031, 5162, 12, 325, 14, 71, 14, 283, 6920, 7, 340, 1265, 2934, 370, 8579, 14931, 367, 665, 6920, 32, 2694, 14, 22058, 14, 957, 7166, 395, 267, 283, 3620, 63, 1238, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 723, 14, 1238, 297, 283, 6985, 11185, 5822, 297, 1415, 29, 549, 12, 16549, 628, 15377, 401, 5101, 1720, 628, 1918, 1402, 334, 47, 16766, 7543, 1804, 688, 9, 370, 1314, 642, 5162, 298, 6901, 298, 989, 3853, 795, 14, 6184, 12467, 3031, 626, 1630, 440, 9351, 370, 376, 298, 6901, 298, 5952, 2777, 911, 7675, 314, 7143, 402, 282, 892, 2777, 298, 6901, 298, 1618, 642, 1402, 334, 69, 14, 71, 14, 282, 7290, 8495, 4186, 5101, 327, 11176, 370, 1454, 2040, 30090, 6016, 63, 2671, 1709, 334, 1129, 5594, 5101, 327, 334, 7804, 282, 9284, 3055, 27609, 12, 10617, 9, 5101, 2881, 628, 19412, 698, 63, 344, 14, 354, 297, 6291, 283, 1188, 63, 1580, 5440, 1288, 267, 283, 3620, 63, 751, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 470, 14, 3707, 297, 283, 14919, 297, 5644, 1720, 628, 1918, 5771, 402, 5767, 2737, 12188, 18390, 14931, 641, 642, 5162, 14, 298, 6059, 298, 3917, 642, 901, 365, 440, 663, 314, 2656, 911, 7427, 370, 2342, 314, 2451, 5771, 298, 6059, 298, 6788, 641, 314, 8904, 334, 2532, 9, 2287, 12, 503, 911, 675, 314, 30660, 2933, 298, 6059, 298, 692, 949, 2656, 922, 365, 1911, 367, 626, 2287, 7651, 267, 283, 3620, 63, 4322, 356, 1504, 14, 505, 360, 2698, 13468, 297, 1415, 29, 549, 12, 4228, 1720, 628, 33, 2018, 2600, 626, 911, 506, 13006, 370, 5647, 298, 5644, 298, 885, 1338, 1380, 6425, 892, 5767, 367, 642, 5162, 7651, 267, 283, 3620, 63, 3990, 63, 2671, 63, 344, 356, 1504, 14, 4115, 360, 5433, 11086, 2870, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
xaedes/canopen_301_402
src/canopen_301_402_old/utils.py
1
3131
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import can def set_timeout(timeout,callback): ''' @summary: calls a function after a specified number of seconds @param timeout: number of seconds @param callback: function be called @result: ''' pass # TODO def collect_all_leaf_subclasses(Type): ''' @summary: returns a list of classes that inherit from type and have no further inheriting subclasses @param Type: new style class type @result: list of classes ''' # current subclasses subclasses = Type.__subclasses__() # no further inheriting subclasses; Type is part of result if len(subclasses) == 0: return [Type] else: # this type is no leaf type # look for further inheriting subclasses # and collect their leaf subclasses result = list() for subclass in subclasses: result.extend(collect_all_leaf_subclasses(subclass)) return result def parseIntAutoBase(string): if string is None: return None string = string.strip() # if it is a negative number the prefix starts after the minus sign # use a variable offset where the prefix should start if string[0] == "-": offset = 1 else: offset = 0 if string[offset:][:2] == "0x": base = 16 elif string[offset:][:2] == "0o": base = 8 elif string[offset:][:2] == "0b": base = 2 else: base = 10 return int(string,base) class HistoryListener(can.Listener): def __init__(self): self.msgs = list() def on_message_received(self,msg): self.msgs.append(msg) def str_to_can_msg(string): ''' @summary: Converts string to can.Message @param string: has same format as linux tool "cansend". e.g. '601#01.01.01.01' @result: can.Message ''' # remove not allowed characters allowed = "0123456789.#RABCDEF" string = string.upper() string = ''.join([char for char in string if char in allowed]) hashidx = string.index("#") head = string[:hashidx] body = string[hashidx+1:] arb_id = int(head,16) if body == "R": data = [] req = True else: data = body.split(".") data = [int(item,16) for item in data] req = False msg = can.Message(extended_id=False,arbitration_id=arb_id,data=data,is_remote_frame=req) return msg def can_msg_to_str(msg): ''' @summary: Converts can.Message to string @param msg: can.Message @result: has same format as linux tool "cansend". e.g. '601#01.01.01.01' ''' head = hex(int(msg.arbitration_id))[2:] if len(head) < 3: head = ((3-len(head)) * "0") + head if msg.is_remote_frame: body = "R" else: body = [] for byte in list(msg.data): str_byte = hex(byte)[2:] if len(str_byte) < 2: str_byte = ((2-len(str_byte)) * "0") + str_byte body.append(str_byte) body = ".".join(body) result = (head+"#"+body).upper() return result
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 18, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 646, 883, 199, 199, 318, 663, 63, 2593, 8, 2593, 12, 3058, 304, 272, 1449, 272, 768, 4705, 26, 4882, 282, 805, 2410, 282, 2013, 1329, 402, 4696, 272, 768, 635, 2653, 26, 1329, 402, 4696, 272, 768, 635, 3233, 26, 805, 506, 2797, 5591, 768, 1099, 26, 5591, 1449, 272, 986, 327, 3254, 199, 199, 318, 8775, 63, 452, 63, 8914, 63, 19094, 8, 804, 304, 272, 1449, 272, 768, 4705, 26, 2529, 282, 769, 402, 3992, 626, 8287, 687, 730, 436, 1172, 949, 9848, 29927, 9180, 272, 768, 635, 2434, 26, 892, 3449, 1021, 730, 272, 768, 1099, 26, 769, 402, 3992, 272, 1449, 339, 327, 1453, 9180, 272, 9180, 275, 2434, 855, 19094, 4533, 339, 327, 949, 9848, 29927, 9180, 27, 2434, 365, 1777, 402, 754, 272, 340, 822, 8, 19094, 9, 508, 378, 26, 267, 372, 359, 804, 61, 272, 587, 26, 267, 327, 642, 730, 365, 949, 11747, 730, 267, 327, 3648, 367, 9848, 29927, 9180, 267, 327, 436, 8775, 3932, 11747, 9180, 267, 754, 275, 769, 342, 267, 367, 5516, 315, 9180, 26, 288, 754, 14, 2880, 8, 7112, 63, 452, 63, 8914, 63, 19094, 8, 6083, 430, 267, 372, 754, 199, 199, 318, 2198, 3241, 3358, 1563, 8, 875, 304, 272, 340, 1059, 365, 488, 26, 372, 488, 272, 1059, 275, 1059, 14, 1913, 342, 339, 327, 340, 652, 365, 282, 6946, 1329, 314, 2403, 9174, 2410, 314, 21357, 2070, 272, 327, 675, 282, 1750, 3268, 2382, 314, 2403, 1077, 1343, 272, 340, 1059, 59, 16, 61, 508, 30312, 267, 3268, 275, 413, 272, 587, 26, 267, 3268, 275, 378, 339, 340, 1059, 59, 2743, 2938, 1491, 18, 61, 508, 298, 16, 88, 582, 267, 1300, 275, 3193, 272, 916, 1059, 59, 2743, 2938, 1491, 18, 61, 508, 298, 16, 79, 582, 267, 1300, 275, 1695, 272, 916, 1059, 59, 2743, 2938, 1491, 18, 61, 508, 298, 16, 66, 582, 267, 1300, 275, 499, 272, 587, 26, 267, 1300, 275, 1616, 339, 372, 1109, 8, 875, 12, 1095, 9, 421, 199, 533, 27829, 10464, 8, 2425, 14, 10464, 304, 272, 347, 636, 826, 721, 277, 304, 267, 291, 14, 13429, 275, 769, 342, 272, 347, 641, 63, 1188, 63, 9226, 8, 277, 12, 1328, 304, 267, 291, 14, 13429, 14, 740, 8, 1328, 9, 268, 199, 318, 620, 63, 475, 63, 2425, 63, 1328, 8, 875, 304, 272, 1449, 272, 768, 4705, 26, 420, 19107, 1059, 370, 883, 14, 2209, 272, 768, 635, 1059, 26, 965, 2011, 1475, 465, 18369, 4744, 298, 2425, 2254, 1674, 325, 14, 71, 14, 283, 24539, 3, 614, 14, 614, 14, 614, 14, 614, 7, 272, 768, 1099, 26, 420, 883, 14, 2209, 272, 1449, 339, 327, 2813, 440, 4370, 4110, 272, 4370, 275, 298, 11371, 14, 3, 50, 18820, 2, 272, 1059, 275, 1059, 14, 4142, 342, 272, 1059, 275, 6522, 904, 779, 1560, 367, 1495, 315, 1059, 340, 1495, 315, 4370, 566, 339, 2631, 2996, 275, 1059, 14, 1080, 10064, 531, 272, 4854, 275, 1059, 1491, 2227, 2996, 61, 272, 2396, 275, 1059, 59, 2227, 2996, 11, 17, 2938, 2378, 601, 66, 63, 344, 275, 1109, 8, 2993, 12, 975, 9, 272, 340, 2396, 508, 298, 50, 582, 267, 666, 275, 942, 267, 2648, 275, 715, 14821, 587, 26, 267, 666, 275, 2396, 14, 1294, 15857, 267, 666, 275, 359, 442, 8, 1053, 12, 975, 9, 367, 1242, 315, 666, 61, 267, 2648, 275, 756, 339, 1499, 275, 883, 14, 2209, 8, 10525, 63, 344, 29, 797, 12, 285, 2075, 1754, 63, 344, 29, 10325, 63, 344, 12, 576, 29, 576, 12, 374, 63, 3846, 63, 1943, 29, 2103, 9, 339, 372, 1499, 4388, 199, 318, 883, 63, 1328, 63, 475, 63, 495, 8, 1328, 304, 272, 1449, 272, 768, 4705, 26, 19107, 883, 14, 2209, 370, 1059, 272, 768, 635, 1499, 26, 883, 14, 2209, 272, 768, 1099, 26, 259, 965, 2011, 1475, 465, 18369, 4744, 298, 2425, 2254, 1674, 325, 14, 71, 14, 283, 24539, 3, 614, 14, 614, 14, 614, 14, 614, 7, 272, 1449, 272, 4854, 275, 6318, 8, 442, 8, 1328, 14, 285, 2075, 1754, 63, 344, 11515, 18, 2938, 2286, 340, 822, 8, 2993, 9, 665, 650, 26, 267, 4854, 275, 3666, 19, 13, 552, 8, 2993, 430, 627, 298, 16, 531, 435, 4854, 339, 340, 1499, 14, 374, 63, 3846, 63, 1943, 26, 267, 2396, 275, 298, 50, 2, 272, 587, 26, 267, 2396, 275, 942, 267, 367, 3696, 315, 769, 8, 1328, 14, 576, 304, 288, 620, 63, 4414, 275, 6318, 8, 4414, 2788, 18, 2938, 288, 340, 822, 8, 495, 63, 4414, 9, 665, 499, 26, 355, 620, 63, 4414, 275, 3666, 18, 13, 552, 8, 495, 63, 4414, 430, 627, 298, 16, 531, 435, 620, 63, 4414, 288, 2396, 14, 740, 8, 495, 63, 4414, 9, 2728, 2396, 275, 32443, 904, 8, 2030, 9, 339, 754, 275, 334, 2993, 5207, 3, 7709, 2030, 680, 4142, 342, 272, 372, 754, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 18, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 646, 883, 199, 199, 318, 663, 63, 2593, 8, 2593, 12, 3058, 304, 272, 1449, 272, 768, 4705, 26, 4882, 282, 805, 2410, 282, 2013, 1329, 402, 4696, 272, 768, 635, 2653, 26, 1329, 402, 4696, 272, 768, 635, 3233, 26, 805, 506, 2797, 5591, 768, 1099, 26, 5591, 1449, 272, 986, 327, 3254, 199, 199, 318, 8775, 63, 452, 63, 8914, 63, 19094, 8, 804, 304, 272, 1449, 272, 768, 4705, 26, 2529, 282, 769, 402, 3992, 626, 8287, 687, 730, 436, 1172, 949, 9848, 29927, 9180, 272, 768, 635, 2434, 26, 892, 3449, 1021, 730, 272, 768, 1099, 26, 769, 402, 3992, 272, 1449, 339, 327, 1453, 9180, 272, 9180, 275, 2434, 855, 19094, 4533, 339, 327, 949, 9848, 29927, 9180, 27, 2434, 365, 1777, 402, 754, 272, 340, 822, 8, 19094, 9, 508, 378, 26, 267, 372, 359, 804, 61, 272, 587, 26, 267, 327, 642, 730, 365, 949, 11747, 730, 267, 327, 3648, 367, 9848, 29927, 9180, 267, 327, 436, 8775, 3932, 11747, 9180, 267, 754, 275, 769, 342, 267, 367, 5516, 315, 9180, 26, 288, 754, 14, 2880, 8, 7112, 63, 452, 63, 8914, 63, 19094, 8, 6083, 430, 267, 372, 754, 199, 199, 318, 2198, 3241, 3358, 1563, 8, 875, 304, 272, 340, 1059, 365, 488, 26, 372, 488, 272, 1059, 275, 1059, 14, 1913, 342, 339, 327, 340, 652, 365, 282, 6946, 1329, 314, 2403, 9174, 2410, 314, 21357, 2070, 272, 327, 675, 282, 1750, 3268, 2382, 314, 2403, 1077, 1343, 272, 340, 1059, 59, 16, 61, 508, 30312, 267, 3268, 275, 413, 272, 587, 26, 267, 3268, 275, 378, 339, 340, 1059, 59, 2743, 2938, 1491, 18, 61, 508, 298, 16, 88, 582, 267, 1300, 275, 3193, 272, 916, 1059, 59, 2743, 2938, 1491, 18, 61, 508, 298, 16, 79, 582, 267, 1300, 275, 1695, 272, 916, 1059, 59, 2743, 2938, 1491, 18, 61, 508, 298, 16, 66, 582, 267, 1300, 275, 499, 272, 587, 26, 267, 1300, 275, 1616, 339, 372, 1109, 8, 875, 12, 1095, 9, 421, 199, 533, 27829, 10464, 8, 2425, 14, 10464, 304, 272, 347, 636, 826, 721, 277, 304, 267, 291, 14, 13429, 275, 769, 342, 272, 347, 641, 63, 1188, 63, 9226, 8, 277, 12, 1328, 304, 267, 291, 14, 13429, 14, 740, 8, 1328, 9, 268, 199, 318, 620, 63, 475, 63, 2425, 63, 1328, 8, 875, 304, 272, 1449, 272, 768, 4705, 26, 420, 19107, 1059, 370, 883, 14, 2209, 272, 768, 635, 1059, 26, 965, 2011, 1475, 465, 18369, 4744, 298, 2425, 2254, 1674, 325, 14, 71, 14, 283, 24539, 3, 614, 14, 614, 14, 614, 14, 614, 7, 272, 768, 1099, 26, 420, 883, 14, 2209, 272, 1449, 339, 327, 2813, 440, 4370, 4110, 272, 4370, 275, 298, 11371, 14, 3, 50, 18820, 2, 272, 1059, 275, 1059, 14, 4142, 342, 272, 1059, 275, 6522, 904, 779, 1560, 367, 1495, 315, 1059, 340, 1495, 315, 4370, 566, 339, 2631, 2996, 275, 1059, 14, 1080, 10064, 531, 272, 4854, 275, 1059, 1491, 2227, 2996, 61, 272, 2396, 275, 1059, 59, 2227, 2996, 11, 17, 2938, 2378, 601, 66, 63, 344, 275, 1109, 8, 2993, 12, 975, 9, 272, 340, 2396, 508, 298, 50, 582, 267, 666, 275, 942, 267, 2648, 275, 715, 14821, 587, 26, 267, 666, 275, 2396, 14, 1294, 15857, 267, 666, 275, 359, 442, 8, 1053, 12, 975, 9, 367, 1242, 315, 666, 61, 267, 2648, 275, 756, 339, 1499, 275, 883, 14, 2209, 8, 10525, 63, 344, 29, 797, 12, 285, 2075, 1754, 63, 344, 29, 10325, 63, 344, 12, 576, 29, 576, 12, 374, 63, 3846, 63, 1943, 29, 2103, 9, 339, 372, 1499, 4388, 199, 318, 883, 63, 1328, 63, 475, 63, 495, 8, 1328, 304, 272, 1449, 272, 768, 4705, 26, 19107, 883, 14, 2209, 370, 1059, 272, 768, 635, 1499, 26, 883, 14, 2209, 272, 768, 1099, 26, 259, 965, 2011, 1475, 465, 18369, 4744, 298, 2425, 2254, 1674, 325, 14, 71, 14, 283, 24539, 3, 614, 14, 614, 14, 614, 14, 614, 7, 272, 1449, 272, 4854, 275, 6318, 8, 442, 8, 1328, 14, 285, 2075, 1754, 63, 344, 11515, 18, 2938, 2286, 340, 822, 8, 2993, 9, 665, 650, 26, 267, 4854, 275, 3666, 19, 13, 552, 8, 2993, 430, 627, 298, 16, 531, 435, 4854, 339, 340, 1499, 14, 374, 63, 3846, 63, 1943, 26, 267, 2396, 275, 298, 50, 2, 272, 587, 26, 267, 2396, 275, 942, 267, 367, 3696, 315, 769, 8, 1328, 14, 576, 304, 288, 620, 63, 4414, 275, 6318, 8, 4414, 2788, 18, 2938, 288, 340, 822, 8, 495, 63, 4414, 9, 665, 499, 26, 355, 620, 63, 4414, 275, 3666, 18, 13, 552, 8, 495, 63, 4414, 430, 627, 298, 16, 531, 435, 620, 63, 4414, 288, 2396, 14, 740, 8, 495, 63, 4414, 9, 2728, 2396, 275, 32443, 904, 8, 2030, 9, 339, 754, 275, 334, 2993, 5207, 3, 7709, 2030, 680, 4142, 342, 272, 372, 754, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
GaetanCambier/CouchPotatoServer
couchpotato/core/media/movie/providers/trailer/youtube_dl/extractor/mgoon.py
177
2695
# coding: utf-8 from __future__ import unicode_literals import re from .common import InfoExtractor from ..utils import ( ExtractorError, qualities, unified_strdate, ) class MgoonIE(InfoExtractor): _VALID_URL = r'''(?x)https?://(?:www\.)? (?:(:?m\.)?mgoon\.com/(?:ch/(?:.+)/v|play/view)| video\.mgoon\.com)/(?P<id>[0-9]+)''' _API_URL = 'http://mpos.mgoon.com/player/video?id={0:}' _TESTS = [ { 'url': 'http://m.mgoon.com/ch/hi6618/v/5582148', 'md5': 'dd46bb66ab35cf6d51cc812fd82da79d', 'info_dict': { 'id': '5582148', 'uploader_id': 'hi6618', 'duration': 240.419, 'upload_date': '20131220', 'ext': 'mp4', 'title': 'md5:543aa4c27a4931d371c3f433e8cebebc', 'thumbnail': 're:^https?://.*\.jpg$', } }, { 'url': 'http://www.mgoon.com/play/view/5582148', 'only_matching': True, }, { 'url': 'http://video.mgoon.com/5582148', 'only_matching': True, }, ] def _real_extract(self, url): mobj = re.match(self._VALID_URL, url) video_id = mobj.group('id') data = self._download_json(self._API_URL.format(video_id), video_id) if data.get('errorInfo', {}).get('code') != 'NONE': raise ExtractorError('%s encountered an error: %s' % ( self.IE_NAME, data['errorInfo']['message']), expected=True) v_info = data['videoInfo'] title = v_info.get('v_title') thumbnail = v_info.get('v_thumbnail') duration = v_info.get('v_duration') upload_date = unified_strdate(v_info.get('v_reg_date')) uploader_id = data.get('userInfo', {}).get('u_alias') if duration: duration /= 1000.0 age_limit = None if data.get('accessInfo', {}).get('code') == 'VIDEO_STATUS_ADULT': age_limit = 18 formats = [] get_quality = qualities(['360p', '480p', '720p', '1080p']) for fmt in data['videoFiles']: formats.append({ 'format_id': fmt['label'], 'quality': get_quality(fmt['label']), 'url': fmt['url'], 'ext': fmt['format'], }) self._sort_formats(formats) return { 'id': video_id, 'title': title, 'formats': formats, 'thumbnail': thumbnail, 'duration': duration, 'upload_date': upload_date, 'uploader_id': uploader_id, 'age_limit': age_limit, }
gpl-3.0
[ 3, 2803, 26, 2774, 13, 24, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 295, 199, 199, 504, 1275, 2330, 492, 21298, 199, 504, 2508, 1208, 492, 334, 272, 19783, 12, 272, 6420, 12107, 12, 272, 25344, 63, 495, 602, 12, 199, 9, 421, 199, 533, 603, 1939, 265, 4332, 8, 18283, 304, 272, 485, 5600, 63, 2632, 275, 519, 2344, 2229, 88, 9, 2859, 24524, 1544, 20316, 272, 16697, 8, 26, 31, 77, 20316, 77, 1939, 265, 4537, 957, 32576, 335, 32576, 6977, 2447, 86, 92, 2802, 15, 1345, 8636, 267, 3991, 4537, 77, 1939, 265, 4537, 957, 2447, 2229, 48, 28, 344, 9514, 16, 13, 25, 11896, 2344, 272, 485, 3735, 63, 2632, 275, 283, 1014, 921, 311, 736, 14, 77, 1939, 265, 14, 957, 15, 6147, 15, 3722, 31, 344, 3126, 16, 26, 6834, 272, 485, 7569, 275, 359, 267, 469, 288, 283, 633, 356, 283, 1014, 921, 77, 14, 77, 1939, 265, 14, 957, 15, 335, 15, 5812, 1272, 1085, 15, 86, 15, 1229, 2564, 10834, 297, 288, 283, 1064, 21, 356, 283, 617, 2466, 2501, 1272, 371, 1276, 2177, 22, 68, 2869, 2055, 29601, 2592, 2564, 983, 1965, 68, 297, 288, 283, 815, 63, 807, 356, 469, 355, 283, 344, 356, 283, 1229, 2564, 10834, 297, 355, 283, 13671, 63, 344, 356, 283, 5812, 1272, 1085, 297, 355, 283, 5553, 356, 21883, 14, 25230, 12, 355, 283, 5064, 63, 602, 356, 283, 6965, 713, 1165, 297, 355, 283, 832, 356, 283, 311, 20, 297, 355, 283, 1213, 356, 283, 1064, 21, 26, 20103, 2158, 20, 67, 1465, 65, 1887, 2192, 68, 16124, 67, 19, 70, 23404, 69, 24, 301, 1235, 3776, 297, 355, 283, 8311, 356, 283, 264, 23497, 2859, 32569, 8476, 4268, 288, 789, 267, 1660, 267, 469, 288, 283, 633, 356, 283, 1014, 921, 1544, 14, 77, 1939, 265, 14, 957, 15, 2802, 15, 1345, 15, 1229, 2564, 10834, 297, 288, 283, 2118, 63, 9467, 356, 715, 12, 267, 1660, 267, 469, 288, 283, 633, 356, 283, 1014, 921, 3722, 14, 77, 1939, 265, 14, 957, 15, 1229, 2564, 10834, 297, 288, 283, 2118, 63, 9467, 356, 715, 12, 267, 1660, 272, 1622, 339, 347, 485, 3093, 63, 5005, 8, 277, 12, 1166, 304, 267, 14208, 275, 295, 14, 1431, 8, 277, 423, 5600, 63, 2632, 12, 1166, 9, 267, 3991, 63, 344, 275, 14208, 14, 923, 360, 344, 358, 398, 666, 275, 291, 423, 4249, 63, 1001, 8, 277, 423, 3735, 63, 2632, 14, 908, 8, 3722, 63, 344, 395, 3991, 63, 344, 9, 398, 340, 666, 14, 362, 360, 705, 2354, 297, 13056, 362, 360, 600, 358, 1137, 283, 9185, 356, 288, 746, 19783, 3508, 83, 14556, 376, 1125, 26, 450, 83, 7, 450, 334, 355, 291, 14, 4332, 63, 2339, 12, 666, 459, 705, 2354, 2545, 1188, 3815, 1420, 29, 549, 9, 398, 373, 63, 815, 275, 666, 459, 3722, 2354, 418, 267, 2538, 275, 373, 63, 815, 14, 362, 360, 86, 63, 1213, 358, 267, 10062, 275, 373, 63, 815, 14, 362, 360, 86, 63, 8311, 358, 267, 7373, 275, 373, 63, 815, 14, 362, 360, 86, 63, 5553, 358, 267, 5802, 63, 602, 275, 25344, 63, 495, 602, 8, 86, 63, 815, 14, 362, 360, 86, 63, 1135, 63, 602, 1333, 267, 25257, 63, 344, 275, 666, 14, 362, 360, 751, 2354, 297, 13056, 362, 360, 85, 63, 3620, 358, 267, 340, 7373, 26, 288, 7373, 12257, 5198, 14, 16, 398, 11437, 63, 3097, 275, 488, 267, 340, 666, 14, 362, 360, 2732, 2354, 297, 13056, 362, 360, 600, 358, 508, 283, 20142, 63, 6305, 63, 1554, 2233, 356, 288, 11437, 63, 3097, 275, 6155, 398, 6752, 275, 942, 267, 664, 63, 9161, 275, 6420, 12107, 2941, 11197, 80, 297, 283, 21853, 80, 297, 283, 18386, 80, 297, 283, 23514, 80, 1105, 267, 367, 7104, 315, 666, 459, 3722, 5535, 2565, 288, 6752, 14, 740, 2561, 355, 283, 908, 63, 344, 356, 7104, 459, 1302, 995, 355, 283, 9161, 356, 664, 63, 9161, 8, 5045, 459, 1302, 3815, 355, 283, 633, 356, 7104, 459, 633, 995, 355, 283, 832, 356, 7104, 459, 908, 995, 953, 3828, 267, 291, 423, 3191, 63, 6321, 8, 6321, 9, 398, 372, 469, 288, 283, 344, 356, 3991, 63, 344, 12, 288, 283, 1213, 356, 2538, 12, 288, 283, 6321, 356, 6752, 12, 288, 283, 8311, 356, 10062, 12, 288, 283, 5553, 356, 7373, 12, 288, 283, 5064, 63, 602, 356, 5802, 63, 602, 12, 288, 283, 13671, 63, 344, 356, 25257, 63, 344, 12, 288, 283, 474, 63, 3097, 356, 11437, 63, 3097, 12, 267, 789, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2803, 26, 2774, 13, 24, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 295, 199, 199, 504, 1275, 2330, 492, 21298, 199, 504, 2508, 1208, 492, 334, 272, 19783, 12, 272, 6420, 12107, 12, 272, 25344, 63, 495, 602, 12, 199, 9, 421, 199, 533, 603, 1939, 265, 4332, 8, 18283, 304, 272, 485, 5600, 63, 2632, 275, 519, 2344, 2229, 88, 9, 2859, 24524, 1544, 20316, 272, 16697, 8, 26, 31, 77, 20316, 77, 1939, 265, 4537, 957, 32576, 335, 32576, 6977, 2447, 86, 92, 2802, 15, 1345, 8636, 267, 3991, 4537, 77, 1939, 265, 4537, 957, 2447, 2229, 48, 28, 344, 9514, 16, 13, 25, 11896, 2344, 272, 485, 3735, 63, 2632, 275, 283, 1014, 921, 311, 736, 14, 77, 1939, 265, 14, 957, 15, 6147, 15, 3722, 31, 344, 3126, 16, 26, 6834, 272, 485, 7569, 275, 359, 267, 469, 288, 283, 633, 356, 283, 1014, 921, 77, 14, 77, 1939, 265, 14, 957, 15, 335, 15, 5812, 1272, 1085, 15, 86, 15, 1229, 2564, 10834, 297, 288, 283, 1064, 21, 356, 283, 617, 2466, 2501, 1272, 371, 1276, 2177, 22, 68, 2869, 2055, 29601, 2592, 2564, 983, 1965, 68, 297, 288, 283, 815, 63, 807, 356, 469, 355, 283, 344, 356, 283, 1229, 2564, 10834, 297, 355, 283, 13671, 63, 344, 356, 283, 5812, 1272, 1085, 297, 355, 283, 5553, 356, 21883, 14, 25230, 12, 355, 283, 5064, 63, 602, 356, 283, 6965, 713, 1165, 297, 355, 283, 832, 356, 283, 311, 20, 297, 355, 283, 1213, 356, 283, 1064, 21, 26, 20103, 2158, 20, 67, 1465, 65, 1887, 2192, 68, 16124, 67, 19, 70, 23404, 69, 24, 301, 1235, 3776, 297, 355, 283, 8311, 356, 283, 264, 23497, 2859, 32569, 8476, 4268, 288, 789, 267, 1660, 267, 469, 288, 283, 633, 356, 283, 1014, 921, 1544, 14, 77, 1939, 265, 14, 957, 15, 2802, 15, 1345, 15, 1229, 2564, 10834, 297, 288, 283, 2118, 63, 9467, 356, 715, 12, 267, 1660, 267, 469, 288, 283, 633, 356, 283, 1014, 921, 3722, 14, 77, 1939, 265, 14, 957, 15, 1229, 2564, 10834, 297, 288, 283, 2118, 63, 9467, 356, 715, 12, 267, 1660, 272, 1622, 339, 347, 485, 3093, 63, 5005, 8, 277, 12, 1166, 304, 267, 14208, 275, 295, 14, 1431, 8, 277, 423, 5600, 63, 2632, 12, 1166, 9, 267, 3991, 63, 344, 275, 14208, 14, 923, 360, 344, 358, 398, 666, 275, 291, 423, 4249, 63, 1001, 8, 277, 423, 3735, 63, 2632, 14, 908, 8, 3722, 63, 344, 395, 3991, 63, 344, 9, 398, 340, 666, 14, 362, 360, 705, 2354, 297, 13056, 362, 360, 600, 358, 1137, 283, 9185, 356, 288, 746, 19783, 3508, 83, 14556, 376, 1125, 26, 450, 83, 7, 450, 334, 355, 291, 14, 4332, 63, 2339, 12, 666, 459, 705, 2354, 2545, 1188, 3815, 1420, 29, 549, 9, 398, 373, 63, 815, 275, 666, 459, 3722, 2354, 418, 267, 2538, 275, 373, 63, 815, 14, 362, 360, 86, 63, 1213, 358, 267, 10062, 275, 373, 63, 815, 14, 362, 360, 86, 63, 8311, 358, 267, 7373, 275, 373, 63, 815, 14, 362, 360, 86, 63, 5553, 358, 267, 5802, 63, 602, 275, 25344, 63, 495, 602, 8, 86, 63, 815, 14, 362, 360, 86, 63, 1135, 63, 602, 1333, 267, 25257, 63, 344, 275, 666, 14, 362, 360, 751, 2354, 297, 13056, 362, 360, 85, 63, 3620, 358, 267, 340, 7373, 26, 288, 7373, 12257, 5198, 14, 16, 398, 11437, 63, 3097, 275, 488, 267, 340, 666, 14, 362, 360, 2732, 2354, 297, 13056, 362, 360, 600, 358, 508, 283, 20142, 63, 6305, 63, 1554, 2233, 356, 288, 11437, 63, 3097, 275, 6155, 398, 6752, 275, 942, 267, 664, 63, 9161, 275, 6420, 12107, 2941, 11197, 80, 297, 283, 21853, 80, 297, 283, 18386, 80, 297, 283, 23514, 80, 1105, 267, 367, 7104, 315, 666, 459, 3722, 5535, 2565, 288, 6752, 14, 740, 2561, 355, 283, 908, 63, 344, 356, 7104, 459, 1302, 995, 355, 283, 9161, 356, 664, 63, 9161, 8, 5045, 459, 1302, 3815, 355, 283, 633, 356, 7104, 459, 633, 995, 355, 283, 832, 356, 7104, 459, 908, 995, 953, 3828, 267, 291, 423, 3191, 63, 6321, 8, 6321, 9, 398, 372, 469, 288, 283, 344, 356, 3991, 63, 344, 12, 288, 283, 1213, 356, 2538, 12, 288, 283, 6321, 356, 6752, 12, 288, 283, 8311, 356, 10062, 12, 288, 283, 5553, 356, 7373, 12, 288, 283, 5064, 63, 602, 356, 5802, 63, 602, 12, 288, 283, 13671, 63, 344, 356, 25257, 63, 344, 12, 288, 283, 474, 63, 3097, 356, 11437, 63, 3097, 12, 267, 789, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
mxrrow/zaicoin
src/deps/boost/libs/python/pyste/tests/test_all.py
54
4106
#!/usr/bin/python # Copyright Bruno da Silva de Oliveira 2003. Use, modification and # distribution is subject to the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) import os import glob import shutil import sys import time #============================================================================= # win32 configuration #============================================================================= if sys.platform == 'win32': includes = '-ID:/programming/libraries/boost-cvs/boost -ID:/Bin/Python/include' build_pyste_cmd = 'python ../src/Pyste/pyste.py --pyste-ns=pyste --cache-dir=cache %s ' % includes compile_single_cmd = 'cl /nologo /GR /GX -c %s -I. ' % includes link_single_cmd = 'link /nologo /DLL '\ '/libpath:D:/programming/libraries/boost-cvs/lib /libpath:D:/Bin/Python/libs '\ 'boost_python.lib python24.lib /out:_%s.dll ' obj_ext = 'obj' #============================================================================= # linux configuration #============================================================================= elif sys.platform == 'linux2': build_pyste_cmd = 'python ../src/Pyste/pyste.py -I. ' compile_single_cmd = 'g++ -shared -c -I. -I/usr/include/python2.4 ' link_single_cmd = 'g++ -shared -o _%s.so -lboost_python ' obj_ext = 'o' def build_pyste(multiple, module): rest = '%s --module=_%s %s.pyste' % (multiple, module, module) execute(build_pyste_cmd + rest) def compile_single(module): module_obj = '' if os.path.isfile(module+'.cpp'): execute(compile_single_cmd + module+'.cpp') module_obj = module + '.' + obj_ext execute(compile_single_cmd + ('_%s.cpp' % module)) link = link_single_cmd % module execute(link + ('_%s.%s ' % (module, obj_ext)) + module_obj) def compile_multiple(module): module_obj = '' if os.path.isfile(module+'.cpp'): execute(compile_single_cmd + module+'.cpp') module_obj = module + '.' + obj_ext files = glob.glob('_%s/*.cpp' % module) for f in files: execute(compile_single_cmd + f) def basename(name): return os.path.basename(os.path.splitext(name)[0]) objs = [basename(x) + '.' + obj_ext for x in files] objs.append(module_obj) execute((link_single_cmd % module) + ' '.join(objs)) def execute(cmd): os.system(cmd) def run_tests(): if os.system('python runtests.py') != 0: raise RuntimeError, 'tests failed' def cleanup(): modules = get_modules() extensions = '*.dll *.pyc *.obj *.exp *.lib *.o *.so' files = [] for module in modules: files.append('_' + module + '.cpp') for ext in extensions.split(): files += glob.glob(ext) files.append('build.log') for file in files: try: os.remove(file) except OSError: pass for module in modules: try: shutil.rmtree('_' + module) except OSError: pass def main(multiple, module=None): if module is None: modules = get_modules() else: modules = [module] start = time.clock() for module in modules: build_pyste(multiple, module) print '-'*50 print 'Building pyste files: %0.2f seconds' % (time.clock()-start) print start = time.clock() for module in modules: if multiple: compile_multiple(module) else: compile_single(module) print '-'*50 print 'Compiling files: %0.2f seconds' % (time.clock()-start) print if len(modules) == 1: os.system('python %sUT.py' % modules[0]) else: run_tests() #cleanup() def get_modules(): def getname(file): return os.path.splitext(os.path.basename(file))[0] return [getname(x) for x in glob.glob('*.pyste')] if __name__ == '__main__': if len(sys.argv) > 1: module = sys.argv[1] else: module = None try: # main('--multiple', module) main('', module) except RuntimeError, e: print e
mit
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1898, 699, 1065, 79, 12927, 428, 382, 3042, 477, 593, 6442, 20936, 13004, 14, 3645, 12, 7100, 436, 199, 3, 4084, 365, 5420, 370, 314, 30470, 2290, 844, 12, 3394, 413, 14, 16, 14, 199, 3, 334, 9295, 23073, 570, 5113, 63, 17, 63, 16, 14, 2424, 503, 1331, 737, 199, 3, 1455, 921, 1544, 14, 15589, 14, 1308, 15, 3961, 63, 17, 63, 16, 14, 2424, 9, 199, 199, 646, 747, 199, 646, 5739, 199, 646, 5145, 199, 646, 984, 199, 646, 900, 199, 199, 14813, 9152, 199, 3, 4747, 708, 2897, 199, 14813, 9152, 199, 692, 984, 14, 3246, 508, 283, 2676, 708, 356, 339, 6952, 275, 2475, 998, 11254, 496, 9258, 15, 10159, 15, 15589, 13, 28151, 15, 15589, 446, 998, 11254, 13394, 15, 4718, 15, 2613, 7, 272, 1900, 63, 15983, 266, 63, 1760, 275, 283, 1548, 24272, 2164, 15, 48, 588, 266, 15, 15983, 266, 14, 647, 1553, 15983, 266, 13, 561, 29, 15983, 266, 1553, 1637, 13, 694, 29, 1637, 450, 83, 283, 450, 6952, 272, 6555, 63, 4780, 63, 1760, 275, 283, 429, 1182, 889, 9733, 1182, 3975, 1182, 39, 56, 446, 67, 450, 83, 446, 41, 14, 283, 450, 6952, 272, 2142, 63, 4780, 63, 1760, 275, 283, 1073, 1182, 889, 9733, 1182, 15982, 1557, 267, 1994, 773, 515, 26, 36, 11254, 496, 9258, 15, 10159, 15, 15589, 13, 28151, 15, 773, 1182, 773, 515, 26, 36, 11254, 13394, 15, 4718, 15, 8450, 1557, 267, 283, 15589, 63, 1548, 14, 773, 2366, 1194, 14, 773, 1182, 548, 26, 4970, 83, 14, 9259, 283, 272, 1559, 63, 832, 275, 283, 1113, 7, 199, 199, 14813, 9152, 199, 3, 18369, 2897, 199, 14813, 9152, 199, 4164, 984, 14, 3246, 508, 283, 5135, 18, 356, 339, 1900, 63, 15983, 266, 63, 1760, 275, 283, 1548, 24272, 2164, 15, 48, 588, 266, 15, 15983, 266, 14, 647, 446, 41, 14, 283, 272, 6555, 63, 4780, 63, 1760, 275, 283, 71, 4176, 446, 5555, 446, 67, 446, 41, 14, 446, 41, 15, 2647, 15, 2613, 15, 1548, 18, 14, 20, 283, 272, 2142, 63, 4780, 63, 1760, 275, 283, 71, 4176, 446, 5555, 446, 79, 485, 5, 83, 14, 1152, 446, 76, 15589, 63, 1548, 283, 272, 1559, 63, 832, 275, 283, 79, 7, 4388, 199, 318, 1900, 63, 15983, 266, 8, 6048, 12, 859, 304, 272, 4618, 275, 1543, 83, 1553, 578, 3699, 5, 83, 450, 83, 14, 15983, 266, 7, 450, 334, 6048, 12, 859, 12, 859, 9, 272, 5341, 8, 1506, 63, 15983, 266, 63, 1760, 435, 4618, 9, 421, 199, 318, 6555, 63, 4780, 8, 578, 304, 272, 859, 63, 1113, 275, 2125, 272, 340, 747, 14, 515, 14, 6292, 8, 578, 18098, 5910, 735, 267, 5341, 8, 2014, 63, 4780, 63, 1760, 435, 859, 18098, 5910, 358, 267, 859, 63, 1113, 275, 859, 435, 7815, 435, 1559, 63, 832, 272, 5341, 8, 2014, 63, 4780, 63, 1760, 435, 661, 4970, 83, 14, 5910, 7, 450, 859, 430, 272, 2142, 275, 2142, 63, 4780, 63, 1760, 450, 859, 272, 5341, 8, 1073, 435, 661, 4970, 83, 4111, 83, 283, 450, 334, 578, 12, 1559, 63, 832, 430, 435, 859, 63, 1113, 9, 421, 199, 318, 6555, 63, 6048, 8, 578, 304, 272, 859, 63, 1113, 275, 2125, 272, 340, 747, 14, 515, 14, 6292, 8, 578, 18098, 5910, 735, 267, 5341, 8, 2014, 63, 4780, 63, 1760, 435, 859, 18098, 5910, 358, 267, 859, 63, 1113, 275, 859, 435, 7815, 435, 1559, 63, 832, 272, 1584, 275, 5739, 14, 6463, 360, 4970, 83, 20362, 5910, 7, 450, 859, 9, 272, 367, 289, 315, 1584, 26, 267, 5341, 8, 2014, 63, 4780, 63, 1760, 435, 289, 9, 272, 347, 9593, 8, 354, 304, 267, 372, 747, 14, 515, 14, 4846, 8, 736, 14, 515, 14, 7973, 8, 354, 2788, 16, 566, 272, 13474, 275, 359, 4846, 8, 88, 9, 435, 7815, 435, 1559, 63, 832, 367, 671, 315, 1584, 61, 272, 13474, 14, 740, 8, 578, 63, 1113, 9, 272, 5341, 1332, 1073, 63, 4780, 63, 1760, 450, 859, 9, 435, 283, 1987, 904, 8, 8718, 430, 421, 199, 318, 5341, 8, 1760, 304, 272, 747, 14, 2253, 8, 1760, 9, 421, 199, 318, 1255, 63, 2219, 837, 272, 340, 747, 14, 2253, 360, 1548, 1255, 2219, 14, 647, 358, 1137, 378, 26, 267, 746, 6064, 12, 283, 2219, 3405, 7, 421, 199, 318, 9058, 837, 272, 4621, 275, 664, 63, 3112, 342, 272, 5478, 275, 11937, 9259, 23588, 11357, 23588, 1113, 23588, 1474, 23588, 773, 23588, 79, 23588, 1152, 7, 272, 1584, 275, 942, 272, 367, 859, 315, 4621, 26, 267, 1584, 14, 740, 6412, 7, 435, 859, 435, 1987, 5910, 358, 272, 367, 1599, 315, 5478, 14, 1294, 837, 267, 1584, 847, 5739, 14, 6463, 8, 832, 9, 272, 1584, 14, 740, 360, 1506, 14, 793, 358, 272, 367, 570, 315, 1584, 26, 267, 862, 26, 288, 747, 14, 2168, 8, 493, 9, 267, 871, 6440, 26, 986, 339, 367, 859, 315, 4621, 26, 267, 862, 26, 288, 5145, 14, 9242, 6412, 7, 435, 859, 9, 267, 871, 6440, 26, 986, 421, 199, 318, 2446, 8, 6048, 12, 859, 29, 403, 304, 272, 340, 859, 365, 488, 26, 267, 4621, 275, 664, 63, 3112, 342, 272, 587, 26, 267, 4621, 275, 359, 578, 61, 339, 1343, 275, 900, 14, 9597, 342, 272, 367, 859, 315, 4621, 26, 267, 1900, 63, 15983, 266, 8, 6048, 12, 859, 9, 272, 870, 10791, 10, 1400, 272, 870, 283, 16461, 10382, 266, 1584, 26, 450, 16, 14, 18, 70, 4696, 7, 450, 334, 521, 14, 9597, 22251, 928, 9, 272, 870, 339, 1343, 275, 900, 14, 9597, 342, 272, 367, 859, 315, 4621, 26, 267, 340, 3663, 26, 288, 6555, 63, 6048, 8, 578, 9, 267, 587, 26, 288, 6555, 63, 4780, 8, 578, 9, 272, 870, 10791, 10, 1400, 272, 870, 283, 2404, 5662, 1584, 26, 450, 16, 14, 18, 70, 4696, 7, 450, 334, 521, 14, 9597, 22251, 928, 9, 272, 870, 272, 340, 822, 8, 3112, 9, 508, 413, 26, 267, 747, 14, 2253, 360, 1548, 450, 83, 934 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1898, 699, 1065, 79, 12927, 428, 382, 3042, 477, 593, 6442, 20936, 13004, 14, 3645, 12, 7100, 436, 199, 3, 4084, 365, 5420, 370, 314, 30470, 2290, 844, 12, 3394, 413, 14, 16, 14, 199, 3, 334, 9295, 23073, 570, 5113, 63, 17, 63, 16, 14, 2424, 503, 1331, 737, 199, 3, 1455, 921, 1544, 14, 15589, 14, 1308, 15, 3961, 63, 17, 63, 16, 14, 2424, 9, 199, 199, 646, 747, 199, 646, 5739, 199, 646, 5145, 199, 646, 984, 199, 646, 900, 199, 199, 14813, 9152, 199, 3, 4747, 708, 2897, 199, 14813, 9152, 199, 692, 984, 14, 3246, 508, 283, 2676, 708, 356, 339, 6952, 275, 2475, 998, 11254, 496, 9258, 15, 10159, 15, 15589, 13, 28151, 15, 15589, 446, 998, 11254, 13394, 15, 4718, 15, 2613, 7, 272, 1900, 63, 15983, 266, 63, 1760, 275, 283, 1548, 24272, 2164, 15, 48, 588, 266, 15, 15983, 266, 14, 647, 1553, 15983, 266, 13, 561, 29, 15983, 266, 1553, 1637, 13, 694, 29, 1637, 450, 83, 283, 450, 6952, 272, 6555, 63, 4780, 63, 1760, 275, 283, 429, 1182, 889, 9733, 1182, 3975, 1182, 39, 56, 446, 67, 450, 83, 446, 41, 14, 283, 450, 6952, 272, 2142, 63, 4780, 63, 1760, 275, 283, 1073, 1182, 889, 9733, 1182, 15982, 1557, 267, 1994, 773, 515, 26, 36, 11254, 496, 9258, 15, 10159, 15, 15589, 13, 28151, 15, 773, 1182, 773, 515, 26, 36, 11254, 13394, 15, 4718, 15, 8450, 1557, 267, 283, 15589, 63, 1548, 14, 773, 2366, 1194, 14, 773, 1182, 548, 26, 4970, 83, 14, 9259, 283, 272, 1559, 63, 832, 275, 283, 1113, 7, 199, 199, 14813, 9152, 199, 3, 18369, 2897, 199, 14813, 9152, 199, 4164, 984, 14, 3246, 508, 283, 5135, 18, 356, 339, 1900, 63, 15983, 266, 63, 1760, 275, 283, 1548, 24272, 2164, 15, 48, 588, 266, 15, 15983, 266, 14, 647, 446, 41, 14, 283, 272, 6555, 63, 4780, 63, 1760, 275, 283, 71, 4176, 446, 5555, 446, 67, 446, 41, 14, 446, 41, 15, 2647, 15, 2613, 15, 1548, 18, 14, 20, 283, 272, 2142, 63, 4780, 63, 1760, 275, 283, 71, 4176, 446, 5555, 446, 79, 485, 5, 83, 14, 1152, 446, 76, 15589, 63, 1548, 283, 272, 1559, 63, 832, 275, 283, 79, 7, 4388, 199, 318, 1900, 63, 15983, 266, 8, 6048, 12, 859, 304, 272, 4618, 275, 1543, 83, 1553, 578, 3699, 5, 83, 450, 83, 14, 15983, 266, 7, 450, 334, 6048, 12, 859, 12, 859, 9, 272, 5341, 8, 1506, 63, 15983, 266, 63, 1760, 435, 4618, 9, 421, 199, 318, 6555, 63, 4780, 8, 578, 304, 272, 859, 63, 1113, 275, 2125, 272, 340, 747, 14, 515, 14, 6292, 8, 578, 18098, 5910, 735, 267, 5341, 8, 2014, 63, 4780, 63, 1760, 435, 859, 18098, 5910, 358, 267, 859, 63, 1113, 275, 859, 435, 7815, 435, 1559, 63, 832, 272, 5341, 8, 2014, 63, 4780, 63, 1760, 435, 661, 4970, 83, 14, 5910, 7, 450, 859, 430, 272, 2142, 275, 2142, 63, 4780, 63, 1760, 450, 859, 272, 5341, 8, 1073, 435, 661, 4970, 83, 4111, 83, 283, 450, 334, 578, 12, 1559, 63, 832, 430, 435, 859, 63, 1113, 9, 421, 199, 318, 6555, 63, 6048, 8, 578, 304, 272, 859, 63, 1113, 275, 2125, 272, 340, 747, 14, 515, 14, 6292, 8, 578, 18098, 5910, 735, 267, 5341, 8, 2014, 63, 4780, 63, 1760, 435, 859, 18098, 5910, 358, 267, 859, 63, 1113, 275, 859, 435, 7815, 435, 1559, 63, 832, 272, 1584, 275, 5739, 14, 6463, 360, 4970, 83, 20362, 5910, 7, 450, 859, 9, 272, 367, 289, 315, 1584, 26, 267, 5341, 8, 2014, 63, 4780, 63, 1760, 435, 289, 9, 272, 347, 9593, 8, 354, 304, 267, 372, 747, 14, 515, 14, 4846, 8, 736, 14, 515, 14, 7973, 8, 354, 2788, 16, 566, 272, 13474, 275, 359, 4846, 8, 88, 9, 435, 7815, 435, 1559, 63, 832, 367, 671, 315, 1584, 61, 272, 13474, 14, 740, 8, 578, 63, 1113, 9, 272, 5341, 1332, 1073, 63, 4780, 63, 1760, 450, 859, 9, 435, 283, 1987, 904, 8, 8718, 430, 421, 199, 318, 5341, 8, 1760, 304, 272, 747, 14, 2253, 8, 1760, 9, 421, 199, 318, 1255, 63, 2219, 837, 272, 340, 747, 14, 2253, 360, 1548, 1255, 2219, 14, 647, 358, 1137, 378, 26, 267, 746, 6064, 12, 283, 2219, 3405, 7, 421, 199, 318, 9058, 837, 272, 4621, 275, 664, 63, 3112, 342, 272, 5478, 275, 11937, 9259, 23588, 11357, 23588, 1113, 23588, 1474, 23588, 773, 23588, 79, 23588, 1152, 7, 272, 1584, 275, 942, 272, 367, 859, 315, 4621, 26, 267, 1584, 14, 740, 6412, 7, 435, 859, 435, 1987, 5910, 358, 272, 367, 1599, 315, 5478, 14, 1294, 837, 267, 1584, 847, 5739, 14, 6463, 8, 832, 9, 272, 1584, 14, 740, 360, 1506, 14, 793, 358, 272, 367, 570, 315, 1584, 26, 267, 862, 26, 288, 747, 14, 2168, 8, 493, 9, 267, 871, 6440, 26, 986, 339, 367, 859, 315, 4621, 26, 267, 862, 26, 288, 5145, 14, 9242, 6412, 7, 435, 859, 9, 267, 871, 6440, 26, 986, 421, 199, 318, 2446, 8, 6048, 12, 859, 29, 403, 304, 272, 340, 859, 365, 488, 26, 267, 4621, 275, 664, 63, 3112, 342, 272, 587, 26, 267, 4621, 275, 359, 578, 61, 339, 1343, 275, 900, 14, 9597, 342, 272, 367, 859, 315, 4621, 26, 267, 1900, 63, 15983, 266, 8, 6048, 12, 859, 9, 272, 870, 10791, 10, 1400, 272, 870, 283, 16461, 10382, 266, 1584, 26, 450, 16, 14, 18, 70, 4696, 7, 450, 334, 521, 14, 9597, 22251, 928, 9, 272, 870, 339, 1343, 275, 900, 14, 9597, 342, 272, 367, 859, 315, 4621, 26, 267, 340, 3663, 26, 288, 6555, 63, 6048, 8, 578, 9, 267, 587, 26, 288, 6555, 63, 4780, 8, 578, 9, 272, 870, 10791, 10, 1400, 272, 870, 283, 2404, 5662, 1584, 26, 450, 16, 14, 18, 70, 4696, 7, 450, 334, 521, 14, 9597, 22251, 928, 9, 272, 870, 272, 340, 822, 8, 3112, 9, 508, 413, 26, 267, 747, 14, 2253, 360, 1548, 450, 83, 934, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
mtanski/samba
python/samba/netcmd/spn.py
46
7603
# spn management # # Copyright Matthieu Patou mat@samba.org 2010 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # import samba.getopt as options import ldb from samba import provision from samba.samdb import SamDB from samba.auth import system_session from samba.netcmd.common import _get_user_realm_domain from samba.netcmd import ( Command, CommandError, SuperCommand, Option ) class cmd_spn_list(Command): """List spns of a given user.""" synopsis = "%prog <user> [options]" takes_optiongroups = { "sambaopts": options.SambaOptions, "credopts": options.CredentialsOptions, "versionopts": options.VersionOptions, } takes_args = ["user"] def run(self, user, credopts=None, sambaopts=None, versionopts=None): lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp) paths = provision.provision_paths_from_lp(lp, lp.get("realm")) sam = SamDB(paths.samdb, session_info=system_session(), credentials=creds, lp=lp) # TODO once I understand how, use the domain info to naildown # to the correct domain (cleaneduser, realm, domain) = _get_user_realm_domain(user) self.outf.write(cleaneduser+"\n") res = sam.search( expression="samaccountname=%s" % ldb.binary_encode(cleaneduser), scope=ldb.SCOPE_SUBTREE, attrs=["servicePrincipalName"]) if len(res) >0: spns = res[0].get("servicePrincipalName") found = False flag = ldb.FLAG_MOD_ADD if spns is not None: self.outf.write( "User %s has the following servicePrincipalName: \n" % res[0].dn) for e in spns: self.outf.write("\t %s\n" % e) else: self.outf.write("User %s has no servicePrincipalName" % res[0].dn) else: raise CommandError("User %s not found" % user) class cmd_spn_add(Command): """Create a new spn.""" synopsis = "%prog <name> <user> [options]" takes_optiongroups = { "sambaopts": options.SambaOptions, "credopts": options.CredentialsOptions, "versionopts": options.VersionOptions, } takes_options = [ Option("--force", help="Force the addition of the spn" " even it exists already", action="store_true"), ] takes_args = ["name", "user"] def run(self, name, user, force=False, credopts=None, sambaopts=None, versionopts=None): lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp) paths = provision.provision_paths_from_lp(lp, lp.get("realm")) sam = SamDB(paths.samdb, session_info=system_session(), credentials=creds, lp=lp) res = sam.search( expression="servicePrincipalName=%s" % ldb.binary_encode(name), scope=ldb.SCOPE_SUBTREE) if len(res) != 0 and not force: raise CommandError("Service principal %s already" " affected to another user" % name) (cleaneduser, realm, domain) = _get_user_realm_domain(user) res = sam.search( expression="samaccountname=%s" % ldb.binary_encode(cleaneduser), scope=ldb.SCOPE_SUBTREE, attrs=["servicePrincipalName"]) if len(res) >0: res[0].dn msg = ldb.Message() spns = res[0].get("servicePrincipalName") tab = [] found = False flag = ldb.FLAG_MOD_ADD if spns is not None: for e in spns: if str(e) == name: found = True tab.append(str(e)) flag = ldb.FLAG_MOD_REPLACE tab.append(name) msg.dn = res[0].dn msg["servicePrincipalName"] = ldb.MessageElement(tab, flag, "servicePrincipalName") if not found: sam.modify(msg) else: raise CommandError("Service principal %s already" " affected to %s" % (name, user)) else: raise CommandError("User %s not found" % user) class cmd_spn_delete(Command): """Delete a spn.""" synopsis = "%prog <name> [user] [options]" takes_optiongroups = { "sambaopts": options.SambaOptions, "credopts": options.CredentialsOptions, "versionopts": options.VersionOptions, } takes_args = ["name", "user?"] def run(self, name, user=None, credopts=None, sambaopts=None, versionopts=None): lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp) paths = provision.provision_paths_from_lp(lp, lp.get("realm")) sam = SamDB(paths.samdb, session_info=system_session(), credentials=creds, lp=lp) res = sam.search( expression="servicePrincipalName=%s" % ldb.binary_encode(name), scope=ldb.SCOPE_SUBTREE, attrs=["servicePrincipalName", "samAccountName"]) if len(res) >0: result = None if user is not None: (cleaneduser, realm, domain) = _get_user_realm_domain(user) for elem in res: if str(elem["samAccountName"]).lower() == cleaneduser: result = elem if result is None: raise CommandError("Unable to find user %s with" " spn %s" % (user, name)) else: if len(res) != 1: listUser = "" for r in res: listUser = "%s\n%s" % (listUser, str(r.dn)) raise CommandError("More than one user has the spn %s " "and no specific user was specified, list of users" " with this spn:%s" % (name, listUser)) else: result=res[0] msg = ldb.Message() spns = result.get("servicePrincipalName") tab = [] if spns is not None: for e in spns: if str(e) != name: tab.append(str(e)) flag = ldb.FLAG_MOD_REPLACE msg.dn = result.dn msg["servicePrincipalName"] = ldb.MessageElement(tab, flag, "servicePrincipalName") sam.modify(msg) else: raise CommandError("Service principal %s not affected" % name) class cmd_spn(SuperCommand): """Service Principal Name (SPN) management.""" subcommands = {} subcommands["add"] = cmd_spn_add() subcommands["list"] = cmd_spn_list() subcommands["delete"] = cmd_spn_delete()
gpl-3.0
[ 3, 2249, 78, 10041, 199, 3, 199, 3, 1898, 18619, 273, 29364, 510, 292, 810, 2530, 32, 21693, 14, 1308, 7129, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 199, 646, 31710, 14, 18907, 465, 1511, 199, 646, 634, 697, 199, 504, 31710, 492, 15408, 199, 504, 31710, 14, 21660, 697, 492, 428, 455, 2846, 199, 504, 31710, 14, 1178, 492, 2656, 63, 1730, 199, 504, 31710, 14, 846, 1760, 14, 2330, 492, 485, 362, 63, 751, 63, 7728, 63, 2261, 199, 504, 31710, 14, 846, 1760, 492, 334, 272, 5817, 12, 272, 14393, 12, 272, 17897, 3110, 12, 272, 3207, 272, 776, 421, 199, 533, 2088, 63, 681, 78, 63, 513, 8, 3110, 304, 272, 408, 1296, 2249, 561, 402, 282, 1627, 922, 1041, 339, 9560, 27573, 275, 2071, 6595, 665, 751, 30, 359, 1419, 8480, 339, 6181, 63, 1422, 2634, 275, 469, 267, 298, 21693, 3291, 582, 1511, 14, 51, 14310, 4558, 12, 267, 298, 18639, 3291, 582, 1511, 14, 13428, 4558, 12, 267, 298, 1023, 3291, 582, 1511, 14, 3353, 4558, 12, 267, 789, 339, 6181, 63, 589, 275, 2097, 751, 937, 339, 347, 1255, 8, 277, 12, 922, 12, 22314, 3291, 29, 403, 12, 31710, 3291, 29, 403, 12, 1015, 3291, 29, 403, 304, 267, 13204, 275, 31710, 3291, 14, 362, 63, 912, 22176, 342, 267, 20023, 275, 22314, 3291, 14, 362, 63, 6942, 8, 10343, 9, 267, 3792, 275, 15408, 14, 13717, 63, 3771, 63, 504, 63, 10343, 8, 10343, 12, 13204, 14, 362, 480, 7728, 2237, 267, 31626, 275, 428, 455, 2846, 8, 3771, 14, 21660, 697, 12, 2351, 63, 815, 29, 2253, 63, 1730, 1062, 490, 6235, 29, 15226, 12, 13204, 29, 10343, 9, 267, 327, 3254, 5403, 473, 20647, 4212, 12, 675, 314, 2881, 2256, 370, 11802, 668, 944, 267, 327, 370, 314, 3211, 2881, 267, 334, 8275, 751, 12, 10482, 12, 2881, 9, 275, 485, 362, 63, 751, 63, 7728, 63, 2261, 8, 751, 9, 267, 291, 14, 548, 70, 14, 952, 8, 8275, 751, 25789, 78, 531, 267, 522, 275, 31626, 14, 1733, 8, 288, 3965, 628, 2231, 3088, 835, 354, 2458, 83, 2, 450, 634, 697, 14, 3008, 63, 2143, 8, 8275, 751, 395, 288, 4194, 29, 15793, 14, 17998, 63, 6348, 22841, 12, 3290, 6270, 1364, 31729, 985, 3135, 267, 340, 822, 8, 470, 9, 690, 16, 26, 288, 2249, 561, 275, 522, 59, 16, 1055, 362, 480, 1364, 31729, 985, 531, 288, 1911, 275, 756, 288, 3305, 275, 634, 697, 14, 3719, 63, 8816, 63, 9732, 288, 340, 2249, 561, 365, 440, 488, 26, 355, 291, 14, 548, 70, 14, 952, 8, 490, 298, 1899, 450, 83, 965, 314, 2569, 2435, 31729, 985, 26, 971, 78, 2, 450, 490, 522, 59, 16, 1055, 4272, 9, 355, 367, 325, 315, 2249, 561, 26, 490, 291, 14, 548, 70, 14, 952, 4582, 84, 450, 83, 60, 78, 2, 450, 325, 9, 288, 587, 26, 355, 291, 14, 548, 70, 14, 952, 480, 1899, 450, 83, 965, 949, 2435, 31729, 985, 2, 450, 490, 522, 59, 16, 1055, 4272, 9, 267, 587, 26, 288, 746, 14393, 480, 1899, 450, 83, 440, 1911, 2, 450, 922, 9, 421, 199, 533, 2088, 63, 681, 78, 63, 525, 8, 3110, 304, 272, 408, 2499, 282, 892, 2249, 78, 1041, 339, 9560, 27573, 275, 2071, 6595, 665, 354, 30, 665, 751, 30, 359, 1419, 8480, 339, 6181, 63, 1422, 2634, 275, 469, 267, 298, 21693, 3291, 582, 1511, 14, 51, 14310, 4558, 12, 267, 298, 18639, 3291, 582, 1511, 14, 13428, 4558, 12, 267, 298, 1023, 3291, 582, 1511, 14, 3353, 4558, 12, 267, 789, 272, 6181, 63, 1419, 275, 359, 267, 3207, 6739, 3990, 401, 1720, 628, 13606, 314, 10234, 402, 314, 2249, 78, 2, 3044, 298, 2755, 652, 3495, 2575, 401, 1595, 628, 1617, 63, 2052, 1288, 288, 1622, 272, 6181, 63, 589, 275, 2097, 354, 401, 298, 751, 937, 339, 347, 1255, 8, 277, 12, 536, 12, 922, 12, 221, 3542, 29, 797, 12, 22314, 3291, 29, 403, 12, 31710, 3291, 29, 403, 12, 288, 1015, 3291, 29, 403, 304, 267, 13204, 275, 31710, 3291, 14, 362, 63, 912, 22176, 342, 267, 20023, 275, 22314, 3291, 14, 362, 63, 6942, 8, 10343, 9, 267, 3792, 275, 15408, 14, 13717, 63, 3771, 63, 504, 63, 10343, 8, 10343, 12, 13204, 14, 362, 480, 7728, 2237, 267, 31626, 275, 428, 455, 2846, 8, 3771, 14, 21660, 697, 12, 2351, 63, 815, 29, 2253, 63, 1730, 1062, 490, 6235, 29, 15226, 12, 13204, 29, 10343, 9, 267, 522, 275, 31626, 14, 1733, 8, 288, 3965, 628, 1364, 31729, 985, 2458, 83, 2, 450, 634, 697, 14, 3008, 63, 2143, 8, 354, 395, 288, 4194, 29, 15793, 14, 17998, 63, 6348, 22841, 9, 267, 340, 822, 8, 470, 9, 1137, 378, 436, 440, 3542, 26, 288, 746, 14393, 480, 3167, 21646, 450, 83, 2575, 2, 3521, 298, 16955, 370, 4573, 922, 2, 450, 536, 9, 398, 334, 8275, 751, 12, 10482, 12, 2881, 9, 275, 485, 362, 63, 751, 63, 7728, 63, 2261, 8, 751, 9, 267, 522, 275, 31626, 14, 1733, 8, 288, 3965, 628, 2231, 3088, 835, 354, 2458, 83, 2, 450, 634, 697, 14, 3008, 63, 2143, 8, 8275, 751, 395, 288, 4194, 29, 15793, 14, 17998, 63, 6348, 22841 ]
[ 2249, 78, 10041, 199, 3, 199, 3, 1898, 18619, 273, 29364, 510, 292, 810, 2530, 32, 21693, 14, 1308, 7129, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 199, 646, 31710, 14, 18907, 465, 1511, 199, 646, 634, 697, 199, 504, 31710, 492, 15408, 199, 504, 31710, 14, 21660, 697, 492, 428, 455, 2846, 199, 504, 31710, 14, 1178, 492, 2656, 63, 1730, 199, 504, 31710, 14, 846, 1760, 14, 2330, 492, 485, 362, 63, 751, 63, 7728, 63, 2261, 199, 504, 31710, 14, 846, 1760, 492, 334, 272, 5817, 12, 272, 14393, 12, 272, 17897, 3110, 12, 272, 3207, 272, 776, 421, 199, 533, 2088, 63, 681, 78, 63, 513, 8, 3110, 304, 272, 408, 1296, 2249, 561, 402, 282, 1627, 922, 1041, 339, 9560, 27573, 275, 2071, 6595, 665, 751, 30, 359, 1419, 8480, 339, 6181, 63, 1422, 2634, 275, 469, 267, 298, 21693, 3291, 582, 1511, 14, 51, 14310, 4558, 12, 267, 298, 18639, 3291, 582, 1511, 14, 13428, 4558, 12, 267, 298, 1023, 3291, 582, 1511, 14, 3353, 4558, 12, 267, 789, 339, 6181, 63, 589, 275, 2097, 751, 937, 339, 347, 1255, 8, 277, 12, 922, 12, 22314, 3291, 29, 403, 12, 31710, 3291, 29, 403, 12, 1015, 3291, 29, 403, 304, 267, 13204, 275, 31710, 3291, 14, 362, 63, 912, 22176, 342, 267, 20023, 275, 22314, 3291, 14, 362, 63, 6942, 8, 10343, 9, 267, 3792, 275, 15408, 14, 13717, 63, 3771, 63, 504, 63, 10343, 8, 10343, 12, 13204, 14, 362, 480, 7728, 2237, 267, 31626, 275, 428, 455, 2846, 8, 3771, 14, 21660, 697, 12, 2351, 63, 815, 29, 2253, 63, 1730, 1062, 490, 6235, 29, 15226, 12, 13204, 29, 10343, 9, 267, 327, 3254, 5403, 473, 20647, 4212, 12, 675, 314, 2881, 2256, 370, 11802, 668, 944, 267, 327, 370, 314, 3211, 2881, 267, 334, 8275, 751, 12, 10482, 12, 2881, 9, 275, 485, 362, 63, 751, 63, 7728, 63, 2261, 8, 751, 9, 267, 291, 14, 548, 70, 14, 952, 8, 8275, 751, 25789, 78, 531, 267, 522, 275, 31626, 14, 1733, 8, 288, 3965, 628, 2231, 3088, 835, 354, 2458, 83, 2, 450, 634, 697, 14, 3008, 63, 2143, 8, 8275, 751, 395, 288, 4194, 29, 15793, 14, 17998, 63, 6348, 22841, 12, 3290, 6270, 1364, 31729, 985, 3135, 267, 340, 822, 8, 470, 9, 690, 16, 26, 288, 2249, 561, 275, 522, 59, 16, 1055, 362, 480, 1364, 31729, 985, 531, 288, 1911, 275, 756, 288, 3305, 275, 634, 697, 14, 3719, 63, 8816, 63, 9732, 288, 340, 2249, 561, 365, 440, 488, 26, 355, 291, 14, 548, 70, 14, 952, 8, 490, 298, 1899, 450, 83, 965, 314, 2569, 2435, 31729, 985, 26, 971, 78, 2, 450, 490, 522, 59, 16, 1055, 4272, 9, 355, 367, 325, 315, 2249, 561, 26, 490, 291, 14, 548, 70, 14, 952, 4582, 84, 450, 83, 60, 78, 2, 450, 325, 9, 288, 587, 26, 355, 291, 14, 548, 70, 14, 952, 480, 1899, 450, 83, 965, 949, 2435, 31729, 985, 2, 450, 490, 522, 59, 16, 1055, 4272, 9, 267, 587, 26, 288, 746, 14393, 480, 1899, 450, 83, 440, 1911, 2, 450, 922, 9, 421, 199, 533, 2088, 63, 681, 78, 63, 525, 8, 3110, 304, 272, 408, 2499, 282, 892, 2249, 78, 1041, 339, 9560, 27573, 275, 2071, 6595, 665, 354, 30, 665, 751, 30, 359, 1419, 8480, 339, 6181, 63, 1422, 2634, 275, 469, 267, 298, 21693, 3291, 582, 1511, 14, 51, 14310, 4558, 12, 267, 298, 18639, 3291, 582, 1511, 14, 13428, 4558, 12, 267, 298, 1023, 3291, 582, 1511, 14, 3353, 4558, 12, 267, 789, 272, 6181, 63, 1419, 275, 359, 267, 3207, 6739, 3990, 401, 1720, 628, 13606, 314, 10234, 402, 314, 2249, 78, 2, 3044, 298, 2755, 652, 3495, 2575, 401, 1595, 628, 1617, 63, 2052, 1288, 288, 1622, 272, 6181, 63, 589, 275, 2097, 354, 401, 298, 751, 937, 339, 347, 1255, 8, 277, 12, 536, 12, 922, 12, 221, 3542, 29, 797, 12, 22314, 3291, 29, 403, 12, 31710, 3291, 29, 403, 12, 288, 1015, 3291, 29, 403, 304, 267, 13204, 275, 31710, 3291, 14, 362, 63, 912, 22176, 342, 267, 20023, 275, 22314, 3291, 14, 362, 63, 6942, 8, 10343, 9, 267, 3792, 275, 15408, 14, 13717, 63, 3771, 63, 504, 63, 10343, 8, 10343, 12, 13204, 14, 362, 480, 7728, 2237, 267, 31626, 275, 428, 455, 2846, 8, 3771, 14, 21660, 697, 12, 2351, 63, 815, 29, 2253, 63, 1730, 1062, 490, 6235, 29, 15226, 12, 13204, 29, 10343, 9, 267, 522, 275, 31626, 14, 1733, 8, 288, 3965, 628, 1364, 31729, 985, 2458, 83, 2, 450, 634, 697, 14, 3008, 63, 2143, 8, 354, 395, 288, 4194, 29, 15793, 14, 17998, 63, 6348, 22841, 9, 267, 340, 822, 8, 470, 9, 1137, 378, 436, 440, 3542, 26, 288, 746, 14393, 480, 3167, 21646, 450, 83, 2575, 2, 3521, 298, 16955, 370, 4573, 922, 2, 450, 536, 9, 398, 334, 8275, 751, 12, 10482, 12, 2881, 9, 275, 485, 362, 63, 751, 63, 7728, 63, 2261, 8, 751, 9, 267, 522, 275, 31626, 14, 1733, 8, 288, 3965, 628, 2231, 3088, 835, 354, 2458, 83, 2, 450, 634, 697, 14, 3008, 63, 2143, 8, 8275, 751, 395, 288, 4194, 29, 15793, 14, 17998, 63, 6348, 22841, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
dirk-dhu/freetz
make/hplip/hplip-config-update.py
4
3297
#!/usr/bin/env python # -*- coding: utf-8 -*- from sys import argv, stdout, stderr, exit import re from collections import defaultdict # To ease search in menuconfig, the printers are split into these classes # mind the order (e.g. color_laserjet before laserjet) # format: (substring of section name in models.dat, string for "Printer Class" in menuconfig) classes = [ ("deskjet", "Deskjet"), ("photosmart", "Photosmart"), ("officejet", "Officejet"), ("psc", "PSC"), ("color_laserjet", "Color LaserJet"), ("laserjet", "LaserJet"), ("designjet", "Designjet"), ("", "Other") # default, "" matches every section name ] def parse(models_dat): # format: # >>> allprinters["officejet"]["officejet_pro_8000_a809"] # ['HP Officejet Pro 8000 Printer - A809a', 'HP Officejet Pro 8000 Wireless Printer - A809n'] allprinters = defaultdict(dict) with open(models_dat) as fp: for line in fp: match = re.match(r"\[(.*[^~])\]", line) if match: pr = match.group(1) # don't touch this string; used by awk to strip down models.dat for cl, name in classes: if cl in line: break allprinters[cl][pr] = [] else: match = re.match(r"model\d*=(.*)", line) if match: allprinters[cl][pr].append(match.group(1)) return allprinters def tovar(s): """Transform s into a valid identifier for Kconfig by making it uppercase and replacing everything that is not a letter, digit or underscore with an underscore""" return re.sub(r"[^A-Z\d_]", "_", s.upper()) def print_class(cl, printers): stdout.write("""\ choice prompt "Printer Type" depends on FREETZ_PACKAGE_HPLIP && FREETZ_PACKAGE_HPLIP_%s help Select your printer type here. """ % tovar(cl)) for typ in sorted(printers.keys()): stdout.write("""\ config FREETZ_PACKAGE_HPLIP_PRINTER_TYPE_%s bool "%s" help Supported models: %s """ % (tovar(typ), typ, "\n\t\t\t".join(printers[typ]))) stdout.write("""\ endchoice """) if __name__ == "__main__": if len(argv) != 3: stderr.write("Usage: %s <hplip version> <model.dat>\n" % argv[0]) exit(1) version = argv[1] allprinters = parse(argv[2]) stdout.write("""\ config FREETZ_PACKAGE_HPLIP bool "HPLIP %s (binary only)" select FREETZ_PACKAGE_SANE_BACKENDS select FREETZ_LIB_libpthread select FREETZ_LIB_libusb_1 default n help HPLIP - HP Linux Imaging and Printing choice prompt "Printer Class" depends on FREETZ_PACKAGE_HPLIP help Select your printer class here. """ % version) #classes[4],classes[5]=classes[5],classes[4] for cl, name in classes: stdout.write("""\ config FREETZ_PACKAGE_HPLIP_%s bool "%s" """ % (tovar(name), name)) stdout.write("""\ endchoice """) for cl, name in classes: print_class(name, allprinters[cl]) stdout.write("""\ config FREETZ_PACKAGE_HPLIP_PRINTER_TYPE string """) for cl, name in classes: for pr in allprinters[cl].keys(): stdout.write("""\ default "%s" if FREETZ_PACKAGE_HPLIP_PRINTER_TYPE_%s """ % (pr, tovar(pr)))
gpl-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 984, 492, 9238, 12, 3839, 12, 4635, 12, 4458, 199, 646, 295, 199, 504, 5055, 492, 10018, 199, 199, 3, 4005, 325, 482, 2754, 315, 6269, 888, 12, 314, 5448, 11005, 787, 3715, 1901, 3520, 3992, 199, 3, 25169, 314, 1865, 334, 69, 14, 71, 14, 3164, 63, 416, 332, 74, 386, 2544, 1127, 332, 74, 386, 9, 199, 3, 1475, 26, 334, 954, 875, 402, 3420, 536, 315, 221, 1709, 14, 4616, 12, 1059, 367, 298, 14131, 8089, 2, 315, 6269, 888, 9, 199, 2888, 275, 359, 272, 1689, 10368, 74, 386, 401, 260, 298, 2586, 25775, 386, 1288, 272, 1689, 25211, 77, 580, 401, 420, 298, 5663, 17278, 77, 580, 1288, 272, 1689, 18812, 74, 386, 401, 755, 298, 31166, 74, 386, 1288, 272, 1689, 80, 551, 401, 3777, 298, 5067, 35, 1288, 272, 1689, 2326, 63, 416, 332, 74, 386, 401, 221, 298, 4117, 7964, 332, 42, 386, 1288, 272, 1689, 416, 332, 74, 386, 401, 263, 298, 7833, 332, 42, 386, 1288, 272, 1689, 14748, 74, 386, 401, 755, 298, 20924, 74, 386, 1288, 272, 24727, 4483, 298, 8632, 531, 327, 849, 12, 3087, 4450, 4036, 3420, 536, 199, 61, 199, 199, 318, 2198, 8, 992, 63, 4616, 304, 272, 327, 1475, 26, 272, 327, 1306, 1006, 24858, 905, 18812, 74, 386, 6611, 18812, 74, 386, 63, 496, 63, 15214, 63, 65, 11782, 937, 272, 327, 788, 18635, 593, 11286, 301, 74, 386, 2165, 29855, 25716, 1058, 446, 437, 11782, 65, 297, 283, 18635, 593, 11286, 301, 74, 386, 2165, 29855, 644, 3621, 2003, 25716, 1058, 446, 437, 11782, 78, 418, 272, 1006, 24858, 275, 10018, 8, 807, 9, 272, 543, 1551, 8, 992, 63, 4616, 9, 465, 4090, 26, 267, 367, 1004, 315, 4090, 26, 288, 1336, 275, 295, 14, 1431, 8, 82, 3212, 7528, 2795, 4735, 94, 27147, 11472, 1004, 9, 288, 340, 1336, 26, 355, 5448, 275, 1336, 14, 923, 8, 17, 9, 327, 2793, 1133, 12943, 642, 1059, 27, 1202, 701, 282, 14947, 370, 6202, 3224, 1709, 14, 4616, 355, 367, 824, 12, 536, 315, 3992, 26, 490, 340, 824, 315, 1004, 26, 717, 2059, 355, 1006, 24858, 59, 429, 1527, 2700, 61, 275, 942, 288, 587, 26, 355, 1336, 275, 295, 14, 1431, 8, 82, 2, 1238, 60, 68, 10, 2687, 2795, 4186, 1004, 9, 355, 340, 1336, 26, 490, 1006, 24858, 59, 429, 1527, 2700, 1055, 740, 8, 1431, 14, 923, 8, 17, 430, 272, 372, 1006, 24858, 199, 199, 318, 370, 1391, 8, 83, 304, 272, 408, 6939, 308, 1901, 282, 1686, 5148, 367, 28637, 701, 10663, 652, 22681, 436, 272, 15810, 8137, 626, 365, 440, 282, 8082, 12, 10964, 503, 18888, 543, 376, 18888, 624, 272, 372, 295, 14, 954, 8, 82, 2, 4735, 33, 13, 58, 60, 68, 63, 11472, 2668, 401, 308, 14, 4142, 1012, 199, 199, 318, 870, 63, 533, 8, 429, 12, 5448, 11005, 304, 272, 3839, 14, 952, 21723, 199, 199, 5095, 199, 198, 7650, 298, 14131, 2434, 2, 199, 198, 8912, 641, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 10883, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 4970, 83, 199, 198, 3437, 507, 198, 5446, 2195, 16639, 730, 2348, 14, 199, 199, 624, 450, 370, 1391, 8, 429, 430, 339, 367, 6211, 315, 3355, 8, 24858, 14, 1612, 5109, 267, 3839, 14, 952, 21723, 199, 198, 888, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 63, 3311, 3843, 63, 2711, 4970, 83, 507, 198, 2245, 2071, 83, 2, 507, 198, 3437, 686, 198, 10682, 1709, 26, 686, 198, 5, 83, 199, 199, 624, 450, 334, 475, 1391, 8, 9749, 395, 6211, 12, 1867, 78, 60, 84, 60, 84, 60, 84, 1674, 904, 8, 24858, 59, 9749, 11845, 339, 3839, 14, 952, 21723, 199, 500, 5095, 199, 6141, 421, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 340, 822, 8, 3020, 9, 1137, 650, 26, 267, 4635, 14, 952, 480, 7692, 26, 450, 83, 665, 12025, 3587, 1015, 30, 665, 1238, 14, 4616, 3072, 78, 2, 450, 9238, 59, 16, 566, 267, 4458, 8, 17, 9, 339, 1015, 275, 9238, 59, 17, 61, 272, 1006, 24858, 275, 2198, 8, 3020, 59, 18, 566, 339, 3839, 14, 952, 21723, 199, 888, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 199, 198, 2245, 298, 40, 2749, 1772, 450, 83, 334, 3008, 1454, 2924, 199, 198, 2416, 481, 907, 775, 58, 63, 19265, 63, 51, 879, 37, 63, 28988, 199, 198, 2416, 481, 907, 775, 58, 63, 5617, 63, 773, 27869, 199, 198, 2416, 481, 907, 775, 58, 63, 5617, 63, 317, 5610, 66, 63, 17, 199, 198, 885, 302, 199, 198, 3437, 507, 198, 40, 2749, 1772, 446, 869, 48, 10130, 473, 391, 1540, 436, 9101, 316, 199, 199, 5095, 199, 198, 7650, 298, 14131, 8089, 2, 199, 198, 8912, 641, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 199, 198, 3437, 507, 198, 5446, 2195, 16639, 1021, 2348, 14, 199, 624, 450, 1015, 9, 339, 327, 2888, 59, 20, 467, 2888, 59, 21, 10404, 2888, 59, 21, 467, 2888, 59, 20, 61, 272, 367, 824, 12, 536, 315, 3992, 26, 267, 3839, 14, 952, 21723, 421, 198, 888, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 4970, 83, 199, 198, 2245, 2071, 83, 2, 199, 624, 450, 334, 475, 1391, 8, 354, 395, 536, 430, 339, 3839, 14, 952, 21723, 199, 500, 5095, 199, 6141, 339, 367, 824, 12, 536, 315, 3992, 26, 267, 870, 63, 533, 8, 354, 12, 1006, 24858, 59, 429, 566, 2378, 3839, 14, 952, 21723, 199, 199, 888, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 63, 3311, 3843, 63, 2711, 199, 198, 875, 199, 6141, 339, 367, 824, 12, 536, 315, 3992, 26, 267, 367, 5448, 315, 1006, 24858, 59, 429, 1055, 1612, 837, 288, 3839, 14, 952, 21723, 199, 198, 885, 2071, 83, 2, 340, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 63, 3311, 3843, 63, 2711, 4970, 83, 199, 624, 450 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 984, 492, 9238, 12, 3839, 12, 4635, 12, 4458, 199, 646, 295, 199, 504, 5055, 492, 10018, 199, 199, 3, 4005, 325, 482, 2754, 315, 6269, 888, 12, 314, 5448, 11005, 787, 3715, 1901, 3520, 3992, 199, 3, 25169, 314, 1865, 334, 69, 14, 71, 14, 3164, 63, 416, 332, 74, 386, 2544, 1127, 332, 74, 386, 9, 199, 3, 1475, 26, 334, 954, 875, 402, 3420, 536, 315, 221, 1709, 14, 4616, 12, 1059, 367, 298, 14131, 8089, 2, 315, 6269, 888, 9, 199, 2888, 275, 359, 272, 1689, 10368, 74, 386, 401, 260, 298, 2586, 25775, 386, 1288, 272, 1689, 25211, 77, 580, 401, 420, 298, 5663, 17278, 77, 580, 1288, 272, 1689, 18812, 74, 386, 401, 755, 298, 31166, 74, 386, 1288, 272, 1689, 80, 551, 401, 3777, 298, 5067, 35, 1288, 272, 1689, 2326, 63, 416, 332, 74, 386, 401, 221, 298, 4117, 7964, 332, 42, 386, 1288, 272, 1689, 416, 332, 74, 386, 401, 263, 298, 7833, 332, 42, 386, 1288, 272, 1689, 14748, 74, 386, 401, 755, 298, 20924, 74, 386, 1288, 272, 24727, 4483, 298, 8632, 531, 327, 849, 12, 3087, 4450, 4036, 3420, 536, 199, 61, 199, 199, 318, 2198, 8, 992, 63, 4616, 304, 272, 327, 1475, 26, 272, 327, 1306, 1006, 24858, 905, 18812, 74, 386, 6611, 18812, 74, 386, 63, 496, 63, 15214, 63, 65, 11782, 937, 272, 327, 788, 18635, 593, 11286, 301, 74, 386, 2165, 29855, 25716, 1058, 446, 437, 11782, 65, 297, 283, 18635, 593, 11286, 301, 74, 386, 2165, 29855, 644, 3621, 2003, 25716, 1058, 446, 437, 11782, 78, 418, 272, 1006, 24858, 275, 10018, 8, 807, 9, 272, 543, 1551, 8, 992, 63, 4616, 9, 465, 4090, 26, 267, 367, 1004, 315, 4090, 26, 288, 1336, 275, 295, 14, 1431, 8, 82, 3212, 7528, 2795, 4735, 94, 27147, 11472, 1004, 9, 288, 340, 1336, 26, 355, 5448, 275, 1336, 14, 923, 8, 17, 9, 327, 2793, 1133, 12943, 642, 1059, 27, 1202, 701, 282, 14947, 370, 6202, 3224, 1709, 14, 4616, 355, 367, 824, 12, 536, 315, 3992, 26, 490, 340, 824, 315, 1004, 26, 717, 2059, 355, 1006, 24858, 59, 429, 1527, 2700, 61, 275, 942, 288, 587, 26, 355, 1336, 275, 295, 14, 1431, 8, 82, 2, 1238, 60, 68, 10, 2687, 2795, 4186, 1004, 9, 355, 340, 1336, 26, 490, 1006, 24858, 59, 429, 1527, 2700, 1055, 740, 8, 1431, 14, 923, 8, 17, 430, 272, 372, 1006, 24858, 199, 199, 318, 370, 1391, 8, 83, 304, 272, 408, 6939, 308, 1901, 282, 1686, 5148, 367, 28637, 701, 10663, 652, 22681, 436, 272, 15810, 8137, 626, 365, 440, 282, 8082, 12, 10964, 503, 18888, 543, 376, 18888, 624, 272, 372, 295, 14, 954, 8, 82, 2, 4735, 33, 13, 58, 60, 68, 63, 11472, 2668, 401, 308, 14, 4142, 1012, 199, 199, 318, 870, 63, 533, 8, 429, 12, 5448, 11005, 304, 272, 3839, 14, 952, 21723, 199, 199, 5095, 199, 198, 7650, 298, 14131, 2434, 2, 199, 198, 8912, 641, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 10883, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 4970, 83, 199, 198, 3437, 507, 198, 5446, 2195, 16639, 730, 2348, 14, 199, 199, 624, 450, 370, 1391, 8, 429, 430, 339, 367, 6211, 315, 3355, 8, 24858, 14, 1612, 5109, 267, 3839, 14, 952, 21723, 199, 198, 888, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 63, 3311, 3843, 63, 2711, 4970, 83, 507, 198, 2245, 2071, 83, 2, 507, 198, 3437, 686, 198, 10682, 1709, 26, 686, 198, 5, 83, 199, 199, 624, 450, 334, 475, 1391, 8, 9749, 395, 6211, 12, 1867, 78, 60, 84, 60, 84, 60, 84, 1674, 904, 8, 24858, 59, 9749, 11845, 339, 3839, 14, 952, 21723, 199, 500, 5095, 199, 6141, 421, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 340, 822, 8, 3020, 9, 1137, 650, 26, 267, 4635, 14, 952, 480, 7692, 26, 450, 83, 665, 12025, 3587, 1015, 30, 665, 1238, 14, 4616, 3072, 78, 2, 450, 9238, 59, 16, 566, 267, 4458, 8, 17, 9, 339, 1015, 275, 9238, 59, 17, 61, 272, 1006, 24858, 275, 2198, 8, 3020, 59, 18, 566, 339, 3839, 14, 952, 21723, 199, 888, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 199, 198, 2245, 298, 40, 2749, 1772, 450, 83, 334, 3008, 1454, 2924, 199, 198, 2416, 481, 907, 775, 58, 63, 19265, 63, 51, 879, 37, 63, 28988, 199, 198, 2416, 481, 907, 775, 58, 63, 5617, 63, 773, 27869, 199, 198, 2416, 481, 907, 775, 58, 63, 5617, 63, 317, 5610, 66, 63, 17, 199, 198, 885, 302, 199, 198, 3437, 507, 198, 40, 2749, 1772, 446, 869, 48, 10130, 473, 391, 1540, 436, 9101, 316, 199, 199, 5095, 199, 198, 7650, 298, 14131, 8089, 2, 199, 198, 8912, 641, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 199, 198, 3437, 507, 198, 5446, 2195, 16639, 1021, 2348, 14, 199, 624, 450, 1015, 9, 339, 327, 2888, 59, 20, 467, 2888, 59, 21, 10404, 2888, 59, 21, 467, 2888, 59, 20, 61, 272, 367, 824, 12, 536, 315, 3992, 26, 267, 3839, 14, 952, 21723, 421, 198, 888, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 4970, 83, 199, 198, 2245, 2071, 83, 2, 199, 624, 450, 334, 475, 1391, 8, 354, 395, 536, 430, 339, 3839, 14, 952, 21723, 199, 500, 5095, 199, 6141, 339, 367, 824, 12, 536, 315, 3992, 26, 267, 870, 63, 533, 8, 354, 12, 1006, 24858, 59, 429, 566, 2378, 3839, 14, 952, 21723, 199, 199, 888, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 63, 3311, 3843, 63, 2711, 199, 198, 875, 199, 6141, 339, 367, 824, 12, 536, 315, 3992, 26, 267, 367, 5448, 315, 1006, 24858, 59, 429, 1055, 1612, 837, 288, 3839, 14, 952, 21723, 199, 198, 885, 2071, 83, 2, 340, 481, 907, 775, 58, 63, 19265, 63, 40, 2749, 1772, 63, 3311, 3843, 63, 2711, 4970, 83, 199, 624, 450, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
akhilaananthram/nupic.fluent
fluent/utils/text_preprocess.py
1
10244
# ---------------------------------------------------------------------- # Numenta Platform for Intelligent Computing (NuPIC) # Copyright (C) 2015, Numenta, Inc. Unless you have purchased from # Numenta, Inc. a separate commercial license for this software code, the # following terms and conditions apply: # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero Public License version 3 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU Affero Public License for more details. # # You should have received a copy of the GNU Affero Public License # along with this program. If not, see http://www.gnu.org/licenses. # # http://numenta.org/licenses/ # ---------------------------------------------------------------------- """ This file contains text pre-processing functions for NLP experiments. """ import os import pandas import re import string from collections import Counter from functools import partial class TextPreprocess(object): """Class for text pre-processing""" alphabet = string.ascii_lowercase def __init__(self, corpusTxt="compilation.txt", abbrCSV="abbreviations.csv", contrCSV="contractions.csv"): """ @param corpusTxt (str) A compilation of most frequent words. The default file 'compilation.txt' is the most frequent words from both British National Corpus, Wiktionary, and books from Project Guttenberg. @param abbrCSV (str) A compilation of domain specific abbreviations. The file is a csv with the header "Abbr,Expansion". The default file 'abbreviations.csv' contains basic abbreviations. @param contrCSV (str) A compilation of common contractions. The file is a csv with the header "Contr,Expansion". The default file 'contractions.csv' contains a short list of common contractions. """ self.abbrCSV = abbrCSV self.contrCSV = contrCSV self.corpusTxt = corpusTxt self.abbrs = None self.bagOfWords = None self.contrs = None self.corpus = None def _setupCorpus(self, corpusSource): """Create member vars for English language corpus and bag of words.""" corpusPath = os.path.abspath(os.path.join( os.path.dirname(__file__), '../..', 'data/etc', corpusSource)) try: self.corpus = file(corpusPath).read() except IOError: raise self.bagOfWords = Counter(self.tokenize(self.corpus)) def _setupAbbrs(self, abbrsSource): """ Read in abbreviations, and combine all into one regex that will only match exact matches and not words containing them. E.g. if "WFH" is an abbreviation, it will match "WFH", but not "XWFH". """ self.abbrs = self.readExpansionFile(abbrsSource, ["", "s", "'s"]) self.abbrRegex = re.compile(r"\b%s\b" % r"\b|\b".join(self.abbrs.keys())) def _setupContr(self, contrSource): """ Read in contractions, and combine all into one regex that will match any word ending in the contraction. E.g. if "'ll" is a contraction, it will match "he'll". """ self.contrs = self.readExpansionFile(contrSource) self.contrRegex = re.compile(r"%s\b" % r"\b|".join(self.contrs.keys())) @staticmethod def readExpansionFile(filename, suffixes=None): """ Read the csv file to get the original/expansion pairs and add suffixes if necessary. @param filename (str) Name of csv file to read. Expected format is original text in col 0, and expansion in col 1. @param suffixes (list) Strings that are added to the end of the original and expanded form if provided @return expansionPairs (dict) The keys are the original form with the suffixes added and the values are the expanded form with the suffixes added """ if suffixes is None: suffixes = [""] expansionPairs = {} try: # Allow absolute paths if os.path.exists(filename): path = filename # Allow relative paths else: path = os.path.abspath(os.path.join( os.path.dirname(__file__), '../..', 'data/etc', filename)) dataFrame = pandas.read_csv(path) for i in xrange(dataFrame.shape[0]): original = dataFrame.iloc[i][0].lower() expansion = dataFrame.iloc[i][1].lower() for suffix in suffixes: originalSuffix = "{}{}".format(original, suffix) expSuffix = "{}{}".format(expansion, suffix) expansionPairs[originalSuffix] = expSuffix except IOError: raise # Add an empty string if empty so the regex compiles if not expansionPairs: expansionPairs[""] = "" return expansionPairs def tokenize(self, text, ignoreCommon=None, removeStrings=None, correctSpell=False, expandAbbr=False, expandContr=False): """ Tokenize, returning only lower-case letters and "$". @param text (str) Single string to tokenize. @param ignoreCommon (int) This many most frequent words will be filtered out from the returned tokens. @param removeStrings (list) List of strings to delete from the text. @param correctSpell (bool) Run tokens through spelling correction. @param expandAbbr (bool) Run text through abbreviation expander @param expandContr (bool) Run text through contraction expander """ if not isinstance(text, str): raise ValueError("Must input a single string object to tokenize.") text = text.lower() if expandAbbr: if not self.abbrs: self._setupAbbrs(self.abbrCSV) getAbbrExpansion = partial(self.getExpansion, table=self.abbrs) text = self.abbrRegex.sub(getAbbrExpansion, text) if expandContr: if not self.contrs: self._setupContr(self.contrCSV) getContrExpansion = partial(self.getExpansion, table=self.contrs) text = self.contrRegex.sub(getContrExpansion, text) if removeStrings: for removal in removeStrings: text = text.replace(removal, "") tokens = re.findall('[a-z$]+', text) if correctSpell: tokens = [self.correct(t) for t in tokens] if ignoreCommon: tokens = self.removeMostCommon(tokens, n=ignoreCommon) return tokens def removeMostCommon(self, tokenList, n=100): """ Remove the n most common tokens as counted in the bag-of-words corpus. @param tokenList (list) List of token strings. @param n (int) Will filter out the n-most frequent terms. """ if not self.bagOfWords: self._setupCorpus(self.corpusTxt) ignoreList = [word[0] for word in self.bagOfWords.most_common(n)] return [token for token in tokenList if token not in ignoreList] @staticmethod def getExpansion(match, table): """ Gets the expanded version of the regular expression @param match (_sre.SRE_Match) Regex match to expand @param table (dict) Maps the string version of the regular expression to the string expansion @return (string) Expansion """ return table[match.string[match.start(): match.end()]] def correct(self, word): """ Find the best spelling correction for this word. Prefer edit distance of 0, then one, then two; otherwise default to the word itself. """ if not self.bagOfWords: self._setupCorpus(self.corpusTxt) candidates = (self._known({word}) or self._known(self._editDistance1(word)) or self._known(self._editDistance2(word)) or [word]) return max(candidates, key=self.bagOfWords.get) def _known(self, words): """Return the subset of words that are in the corpus.""" return {w for w in words if w in self.bagOfWords} @staticmethod def _editDistance1(word): """ Return all strings that are edit distance =1 from the input word. Damerau-Levenshtein edit distance: - deletion(x,y) is the count(xy typed as x) - insertion(x,y) is the count(x typed as xy) - substitution(x,y) is the count(x typed as y) - transposition(x,y) is the count(xy typed as yx) """ # First split the word into tuples of all possible pairs. # Note: need +1 so we can perform edits at front and back end of the word. splits = [(word[:i], word[i:]) for i in range(len(word)+1)] # Now perform the edits at every possible split location. # Substitution is essentially a deletion and insertion. delete = [a+b[1:] for a,b in splits if b] insert = [a+b+c for a,b in splits for c in TextPreprocess.alphabet] subs = [a+c+b[1:] for a,b in splits for c in TextPreprocess.alphabet if b] trans = [a+b[1]+b[0]+b[2:] for a,b in splits if len(b)>1] return set(delete + insert + subs + trans) def _editDistance2(self, word): """ Return all strings that are edit distance =2 from the input word; i.e. call the _editDistance1() method twice for edits with distances of two. """ return {edits2 for edits1 in self._editDistance1(word) for edits2 in self._editDistance1(edits1)}
agpl-3.0
[ 3, 20359, 199, 3, 22783, 16078, 367, 8883, 24024, 27799, 334, 21988, 26769, 9, 199, 3, 1898, 334, 35, 9, 6900, 12, 22783, 12, 3277, 14, 221, 4158, 1265, 1172, 15932, 68, 687, 199, 3, 22783, 12, 3277, 14, 282, 7396, 2414, 23012, 4190, 367, 642, 2032, 1233, 12, 314, 199, 3, 2569, 2895, 436, 3704, 4838, 26, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1684, 844, 1015, 650, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 199, 3, 1666, 314, 1664, 4265, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 14, 199, 3, 199, 3, 1455, 921, 78, 18952, 14, 1308, 15, 2383, 15, 199, 3, 20359, 199, 624, 199, 2765, 570, 3509, 1318, 876, 13, 6338, 3423, 367, 653, 9257, 444, 22263, 14, 199, 624, 199, 199, 646, 747, 199, 646, 10634, 199, 646, 295, 199, 646, 1059, 199, 199, 504, 5055, 492, 14427, 199, 504, 9143, 492, 7417, 4388, 199, 533, 4516, 26539, 8, 785, 304, 523, 408, 2543, 367, 1318, 876, 13, 6338, 624, 819, 27230, 275, 1059, 14, 4371, 63, 21636, 819, 347, 636, 826, 721, 277, 12, 2049, 16831, 32199, 628, 863, 13696, 14, 2424, 401, 2049, 2236, 3289, 19018, 628, 371, 23988, 1298, 14, 4737, 401, 2049, 406, 454, 19018, 628, 17926, 2452, 14, 4737, 2349, 272, 408, 272, 768, 635, 16831, 32199, 420, 334, 495, 9, 755, 437, 18653, 402, 4750, 28914, 5932, 14, 710, 267, 849, 570, 283, 863, 13696, 14, 2424, 7, 365, 314, 4750, 28914, 5932, 687, 3865, 267, 699, 322, 23184, 20548, 7499, 8843, 12, 644, 3258, 296, 695, 12, 436, 19040, 687, 7290, 598, 337, 724, 14630, 14, 339, 768, 635, 2236, 3289, 19018, 263, 334, 495, 9, 755, 437, 18653, 402, 2881, 2488, 267, 2236, 23988, 1298, 14, 710, 570, 365, 282, 7392, 543, 314, 1406, 298, 33, 2501, 82, 12, 26048, 1674, 710, 267, 849, 570, 283, 371, 23988, 1298, 14, 4737, 7, 3509, 5678, 2236, 23988, 1298, 14, 339, 768, 635, 406, 454, 19018, 755, 334, 495, 9, 755, 437, 18653, 402, 2863, 18782, 2452, 14, 710, 267, 570, 365, 282, 7392, 543, 314, 1406, 298, 714, 454, 12, 26048, 1674, 710, 849, 570, 267, 283, 17926, 2452, 14, 4737, 7, 3509, 282, 3974, 769, 402, 2863, 18782, 2452, 14, 272, 408, 272, 291, 14, 20787, 19018, 275, 2236, 3289, 19018, 272, 291, 14, 388, 454, 19018, 275, 406, 454, 19018, 272, 291, 14, 16780, 32199, 275, 16831, 32199, 339, 291, 14, 12198, 2393, 275, 488, 272, 291, 14, 19430, 3466, 23759, 275, 488, 272, 291, 14, 388, 454, 83, 275, 488, 272, 291, 14, 16780, 275, 488, 8330, 347, 485, 2758, 26424, 8, 277, 12, 16831, 2980, 304, 272, 408, 2499, 3653, 6802, 367, 20144, 2637, 16831, 436, 330, 643, 402, 5932, 1041, 272, 16831, 2042, 275, 747, 14, 515, 14, 4832, 8, 736, 14, 515, 14, 904, 8, 267, 747, 14, 515, 14, 3475, 3460, 493, 10139, 20644, 703, 297, 283, 576, 15, 6839, 297, 16831, 2980, 430, 272, 862, 26, 489, 291, 14, 16780, 275, 570, 8, 16780, 2042, 680, 739, 342, 272, 871, 5925, 26, 489, 746, 339, 291, 14, 19430, 3466, 23759, 275, 14427, 8, 277, 14, 15246, 8, 277, 14, 16780, 430, 8330, 347, 485, 2758, 33, 2501, 2393, 8, 277, 12, 2236, 66, 2393, 2980, 304, 272, 408, 272, 5574, 315, 2236, 23988, 1298, 12, 436, 13323, 1006, 1901, 1373, 5163, 626, 911, 1454, 1336, 272, 5835, 4450, 436, 440, 5932, 3035, 3062, 14, 272, 662, 14, 71, 14, 340, 298, 29046, 40, 2, 365, 376, 2236, 30369, 12, 652, 911, 1336, 298, 29046, 40, 401, 1325, 440, 298, 56, 29046, 40, 1674, 272, 408, 272, 291, 14, 12198, 2393, 275, 291, 14, 739, 26048, 1173, 8, 12198, 2393, 2980, 12, 359, 5151, 298, 83, 401, 3546, 83, 3135, 272, 291, 14, 20787, 5103, 275, 295, 14, 2014, 8, 82, 3212, 66, 5, 83, 60, 66, 2, 450, 519, 3212, 66, 6113, 66, 1674, 904, 8, 277, 14, 12198, 2393, 14, 1612, 4059, 8330, 347, 485, 2758, 714, 454, 8, 277, 12, 406, 454, 2980, 304, 272, 408, 272, 5574, 315, 18782, 2452, 12, 436, 13323, 1006, 1901, 1373, 5163, 626, 911, 1336, 1263, 272, 4349, 13401, 315, 314, 18782, 414, 14, 272, 662, 14, 71, 14, 340, 3546, 914, 2, 365, 282, 18782, 414, 12, 652, 911, 1336, 298, 426, 7171, 1674, 272, 408, 272, 291, 14, 388, 454, 83, 275, 291, 14, 739, 26048, 1173, 8, 388, 454, 2980, 9, 272, 291, 14, 388, 454, 5103, 275, 295, 14, 2014, 8, 82, 6808, 83, 60, 66, 2, 450, 519, 3212, 66, 92, 1674, 904, 8, 277, 14, 388, 454, 83, 14, 1612, 4059, 8330, 768, 4639, 523, 347, 1586, 26048, 1173, 8, 1501, 12, 19475, 29, 403, 304, 272, 408, 272, 5574, 314, 7392, 570, 370, 664, 314, 3379, 15, 24651, 6342, 436, 1050, 19475, 340, 272, 5784, 14, 272, 768, 635, 1788, 260, 334, 495, 9, 258, 2812, 402, 7392, 570, 370, 1586, 14, 13796, 1475, 4228, 365, 3379, 1318, 315, 1048, 378, 12, 436, 14819, 4228, 315, 1048, 413, 14, 272, 768, 635, 19475, 260, 334, 513, 9, 259, 24361, 626, 787, 3483, 370, 314, 1284, 402, 4228, 314, 3379, 436, 11507, 1824, 340, 4228, 2741, 272, 768, 1107, 14819, 12882, 83, 221, 334, 807, 9, 259, 710, 2883, 787, 314, 3379, 1824, 543, 4228, 314, 19475, 3483, 436, 314, 1338, 787, 4228, 314, 11507, 1824, 543, 314, 19475, 4228, 3483, 272, 408, 272, 340, 19475, 365, 488, 26, 489, 19475, 275, 359, 341, 61, 339, 14819, 12882, 83 ]
[ 20359, 199, 3, 22783, 16078, 367, 8883, 24024, 27799, 334, 21988, 26769, 9, 199, 3, 1898, 334, 35, 9, 6900, 12, 22783, 12, 3277, 14, 221, 4158, 1265, 1172, 15932, 68, 687, 199, 3, 22783, 12, 3277, 14, 282, 7396, 2414, 23012, 4190, 367, 642, 2032, 1233, 12, 314, 199, 3, 2569, 2895, 436, 3704, 4838, 26, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1684, 844, 1015, 650, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 199, 3, 1666, 314, 1664, 4265, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 14, 199, 3, 199, 3, 1455, 921, 78, 18952, 14, 1308, 15, 2383, 15, 199, 3, 20359, 199, 624, 199, 2765, 570, 3509, 1318, 876, 13, 6338, 3423, 367, 653, 9257, 444, 22263, 14, 199, 624, 199, 199, 646, 747, 199, 646, 10634, 199, 646, 295, 199, 646, 1059, 199, 199, 504, 5055, 492, 14427, 199, 504, 9143, 492, 7417, 4388, 199, 533, 4516, 26539, 8, 785, 304, 523, 408, 2543, 367, 1318, 876, 13, 6338, 624, 819, 27230, 275, 1059, 14, 4371, 63, 21636, 819, 347, 636, 826, 721, 277, 12, 2049, 16831, 32199, 628, 863, 13696, 14, 2424, 401, 2049, 2236, 3289, 19018, 628, 371, 23988, 1298, 14, 4737, 401, 2049, 406, 454, 19018, 628, 17926, 2452, 14, 4737, 2349, 272, 408, 272, 768, 635, 16831, 32199, 420, 334, 495, 9, 755, 437, 18653, 402, 4750, 28914, 5932, 14, 710, 267, 849, 570, 283, 863, 13696, 14, 2424, 7, 365, 314, 4750, 28914, 5932, 687, 3865, 267, 699, 322, 23184, 20548, 7499, 8843, 12, 644, 3258, 296, 695, 12, 436, 19040, 687, 7290, 598, 337, 724, 14630, 14, 339, 768, 635, 2236, 3289, 19018, 263, 334, 495, 9, 755, 437, 18653, 402, 2881, 2488, 267, 2236, 23988, 1298, 14, 710, 570, 365, 282, 7392, 543, 314, 1406, 298, 33, 2501, 82, 12, 26048, 1674, 710, 267, 849, 570, 283, 371, 23988, 1298, 14, 4737, 7, 3509, 5678, 2236, 23988, 1298, 14, 339, 768, 635, 406, 454, 19018, 755, 334, 495, 9, 755, 437, 18653, 402, 2863, 18782, 2452, 14, 710, 267, 570, 365, 282, 7392, 543, 314, 1406, 298, 714, 454, 12, 26048, 1674, 710, 849, 570, 267, 283, 17926, 2452, 14, 4737, 7, 3509, 282, 3974, 769, 402, 2863, 18782, 2452, 14, 272, 408, 272, 291, 14, 20787, 19018, 275, 2236, 3289, 19018, 272, 291, 14, 388, 454, 19018, 275, 406, 454, 19018, 272, 291, 14, 16780, 32199, 275, 16831, 32199, 339, 291, 14, 12198, 2393, 275, 488, 272, 291, 14, 19430, 3466, 23759, 275, 488, 272, 291, 14, 388, 454, 83, 275, 488, 272, 291, 14, 16780, 275, 488, 8330, 347, 485, 2758, 26424, 8, 277, 12, 16831, 2980, 304, 272, 408, 2499, 3653, 6802, 367, 20144, 2637, 16831, 436, 330, 643, 402, 5932, 1041, 272, 16831, 2042, 275, 747, 14, 515, 14, 4832, 8, 736, 14, 515, 14, 904, 8, 267, 747, 14, 515, 14, 3475, 3460, 493, 10139, 20644, 703, 297, 283, 576, 15, 6839, 297, 16831, 2980, 430, 272, 862, 26, 489, 291, 14, 16780, 275, 570, 8, 16780, 2042, 680, 739, 342, 272, 871, 5925, 26, 489, 746, 339, 291, 14, 19430, 3466, 23759, 275, 14427, 8, 277, 14, 15246, 8, 277, 14, 16780, 430, 8330, 347, 485, 2758, 33, 2501, 2393, 8, 277, 12, 2236, 66, 2393, 2980, 304, 272, 408, 272, 5574, 315, 2236, 23988, 1298, 12, 436, 13323, 1006, 1901, 1373, 5163, 626, 911, 1454, 1336, 272, 5835, 4450, 436, 440, 5932, 3035, 3062, 14, 272, 662, 14, 71, 14, 340, 298, 29046, 40, 2, 365, 376, 2236, 30369, 12, 652, 911, 1336, 298, 29046, 40, 401, 1325, 440, 298, 56, 29046, 40, 1674, 272, 408, 272, 291, 14, 12198, 2393, 275, 291, 14, 739, 26048, 1173, 8, 12198, 2393, 2980, 12, 359, 5151, 298, 83, 401, 3546, 83, 3135, 272, 291, 14, 20787, 5103, 275, 295, 14, 2014, 8, 82, 3212, 66, 5, 83, 60, 66, 2, 450, 519, 3212, 66, 6113, 66, 1674, 904, 8, 277, 14, 12198, 2393, 14, 1612, 4059, 8330, 347, 485, 2758, 714, 454, 8, 277, 12, 406, 454, 2980, 304, 272, 408, 272, 5574, 315, 18782, 2452, 12, 436, 13323, 1006, 1901, 1373, 5163, 626, 911, 1336, 1263, 272, 4349, 13401, 315, 314, 18782, 414, 14, 272, 662, 14, 71, 14, 340, 3546, 914, 2, 365, 282, 18782, 414, 12, 652, 911, 1336, 298, 426, 7171, 1674, 272, 408, 272, 291, 14, 388, 454, 83, 275, 291, 14, 739, 26048, 1173, 8, 388, 454, 2980, 9, 272, 291, 14, 388, 454, 5103, 275, 295, 14, 2014, 8, 82, 6808, 83, 60, 66, 2, 450, 519, 3212, 66, 92, 1674, 904, 8, 277, 14, 388, 454, 83, 14, 1612, 4059, 8330, 768, 4639, 523, 347, 1586, 26048, 1173, 8, 1501, 12, 19475, 29, 403, 304, 272, 408, 272, 5574, 314, 7392, 570, 370, 664, 314, 3379, 15, 24651, 6342, 436, 1050, 19475, 340, 272, 5784, 14, 272, 768, 635, 1788, 260, 334, 495, 9, 258, 2812, 402, 7392, 570, 370, 1586, 14, 13796, 1475, 4228, 365, 3379, 1318, 315, 1048, 378, 12, 436, 14819, 4228, 315, 1048, 413, 14, 272, 768, 635, 19475, 260, 334, 513, 9, 259, 24361, 626, 787, 3483, 370, 314, 1284, 402, 4228, 314, 3379, 436, 11507, 1824, 340, 4228, 2741, 272, 768, 1107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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
rjcorrig/FreeRDP
resources/conv_to_ewm_prop.py
80
1430
#!/usr/bin/python # Copyright 2011 Anthony Tong <atong@trustedcs.com> # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ tool to preconvert an icon file to a x11 property as expected by ewm hints spec: width, length, [argb pixels] """ import PIL import PIL.Image import os import sys def usage(): print "convert_to_ewm_prop <infile> <outfile>" return 1 def main(argv): if len(argv) != 3: return usage() im = PIL.Image.open(argv[1]) fp = open(argv[2], 'w') var_name = os.path.basename(argv[2]) if var_name.endswith('.h'): var_name = var_name[:-2] fp.write("static unsigned long %s_prop [] = {\n" % var_name) fp.write(" %d, %d\n" % im.size) i = 0 for pixel in im.getdata(): r,g,b,a = pixel pixel = b pixel |= g << 8 pixel |= r << 16 pixel |= a << 24 fp.write(" , %du" % pixel) i += 1 if i % 8 == 0: fp.write("\n") fp.write("};\n") if __name__ == '__main__': sys.exit(main(sys.argv))
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 199, 3, 1898, 7760, 1626, 898, 89, 377, 951, 665, 292, 951, 32, 17549, 1259, 14, 957, 30, 199, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 624, 199, 3557, 370, 876, 3916, 376, 7016, 570, 370, 282, 671, 845, 3324, 465, 1420, 199, 991, 325, 16240, 18069, 3158, 26, 199, 2063, 12, 2582, 12, 359, 1273, 66, 11094, 61, 199, 624, 199, 199, 646, 14937, 199, 646, 14937, 14, 3491, 199, 199, 646, 747, 199, 646, 984, 199, 199, 318, 4503, 837, 199, 198, 1361, 298, 3916, 63, 475, 63, 546, 77, 63, 4469, 665, 13880, 30, 665, 4984, 4335, 199, 198, 1107, 413, 199, 199, 318, 2446, 8, 3020, 304, 199, 198, 692, 822, 8, 3020, 9, 1137, 650, 26, 507, 198, 1107, 4503, 342, 421, 198, 1017, 275, 14937, 14, 3491, 14, 1490, 8, 3020, 59, 17, 566, 199, 198, 3997, 275, 1551, 8, 3020, 59, 18, 467, 283, 87, 358, 421, 198, 1391, 63, 354, 275, 747, 14, 515, 14, 4846, 8, 3020, 59, 18, 566, 199, 198, 692, 2729, 63, 354, 14, 4130, 5175, 72, 735, 507, 198, 1391, 63, 354, 275, 2729, 63, 354, 4439, 18, 61, 421, 198, 3997, 14, 952, 480, 1986, 7381, 1846, 450, 83, 63, 4469, 942, 275, 9459, 78, 2, 450, 2729, 63, 354, 9, 199, 198, 3997, 14, 952, 480, 450, 68, 12, 450, 68, 60, 78, 2, 450, 3416, 14, 890, 9, 421, 198, 73, 275, 378, 199, 198, 509, 7148, 315, 3416, 14, 29160, 837, 507, 198, 82, 12, 71, 12, 66, 12, 65, 275, 7148, 507, 198, 8435, 275, 330, 11083, 198, 8435, 8901, 486, 5213, 1695, 507, 198, 8435, 8901, 519, 5213, 3193, 507, 198, 8435, 8901, 282, 5213, 5504, 507, 198, 3997, 14, 952, 480, 2360, 450, 2033, 2, 450, 7148, 9, 2742, 198, 73, 847, 413, 507, 198, 692, 284, 450, 1695, 508, 378, 26, 686, 198, 3997, 14, 952, 4582, 78, 531, 421, 198, 3997, 14, 952, 480, 16055, 78, 531, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 199, 198, 1274, 14, 2224, 8, 973, 8, 1274, 14, 3020, 430, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 199, 199, 3, 1898, 7760, 1626, 898, 89, 377, 951, 665, 292, 951, 32, 17549, 1259, 14, 957, 30, 199, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 624, 199, 3557, 370, 876, 3916, 376, 7016, 570, 370, 282, 671, 845, 3324, 465, 1420, 199, 991, 325, 16240, 18069, 3158, 26, 199, 2063, 12, 2582, 12, 359, 1273, 66, 11094, 61, 199, 624, 199, 199, 646, 14937, 199, 646, 14937, 14, 3491, 199, 199, 646, 747, 199, 646, 984, 199, 199, 318, 4503, 837, 199, 198, 1361, 298, 3916, 63, 475, 63, 546, 77, 63, 4469, 665, 13880, 30, 665, 4984, 4335, 199, 198, 1107, 413, 199, 199, 318, 2446, 8, 3020, 304, 199, 198, 692, 822, 8, 3020, 9, 1137, 650, 26, 507, 198, 1107, 4503, 342, 421, 198, 1017, 275, 14937, 14, 3491, 14, 1490, 8, 3020, 59, 17, 566, 199, 198, 3997, 275, 1551, 8, 3020, 59, 18, 467, 283, 87, 358, 421, 198, 1391, 63, 354, 275, 747, 14, 515, 14, 4846, 8, 3020, 59, 18, 566, 199, 198, 692, 2729, 63, 354, 14, 4130, 5175, 72, 735, 507, 198, 1391, 63, 354, 275, 2729, 63, 354, 4439, 18, 61, 421, 198, 3997, 14, 952, 480, 1986, 7381, 1846, 450, 83, 63, 4469, 942, 275, 9459, 78, 2, 450, 2729, 63, 354, 9, 199, 198, 3997, 14, 952, 480, 450, 68, 12, 450, 68, 60, 78, 2, 450, 3416, 14, 890, 9, 421, 198, 73, 275, 378, 199, 198, 509, 7148, 315, 3416, 14, 29160, 837, 507, 198, 82, 12, 71, 12, 66, 12, 65, 275, 7148, 507, 198, 8435, 275, 330, 11083, 198, 8435, 8901, 486, 5213, 1695, 507, 198, 8435, 8901, 519, 5213, 3193, 507, 198, 8435, 8901, 282, 5213, 5504, 507, 198, 3997, 14, 952, 480, 2360, 450, 2033, 2, 450, 7148, 9, 2742, 198, 73, 847, 413, 507, 198, 692, 284, 450, 1695, 508, 378, 26, 686, 198, 3997, 14, 952, 4582, 78, 531, 421, 198, 3997, 14, 952, 480, 16055, 78, 531, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 199, 198, 1274, 14, 2224, 8, 973, 8, 1274, 14, 3020, 430, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
sbalde/edx-platform
lms/djangoapps/instructor/tests/test_api.py
12
201659
# -*- coding: utf-8 -*- """ Unit tests for instructor.api methods. """ import datetime import ddt import random import pytz import io import json import requests import shutil import tempfile from urllib import quote from django.conf import settings from django.contrib.auth.models import User from django.core import mail from django.core.files.uploadedfile import SimpleUploadedFile from django.core.urlresolvers import reverse from django.http import HttpRequest, HttpResponse from django.test import RequestFactory, TestCase from django.test.utils import override_settings from django.utils.timezone import utc from django.utils.translation import ugettext as _ from mock import Mock, patch from nose.tools import raises from nose.plugins.attrib import attr from opaque_keys.edx.locations import SlashSeparatedCourseKey from course_modes.models import CourseMode from courseware.models import StudentModule from courseware.tests.factories import StaffFactory, InstructorFactory, BetaTesterFactory, UserProfileFactory from courseware.tests.helpers import LoginEnrollmentTestCase from django_comment_common.models import FORUM_ROLE_COMMUNITY_TA from django_comment_common.utils import seed_permissions_roles from microsite_configuration import microsite from shoppingcart.models import ( RegistrationCodeRedemption, Order, CouponRedemption, PaidCourseRegistration, Coupon, Invoice, CourseRegistrationCode, CourseRegistrationCodeInvoiceItem, InvoiceTransaction) from shoppingcart.pdf import PDFInvoice from student.models import ( CourseEnrollment, CourseEnrollmentAllowed, NonExistentCourseError, ManualEnrollmentAudit, UNENROLLED_TO_ENROLLED, ENROLLED_TO_UNENROLLED, ALLOWEDTOENROLL_TO_UNENROLLED, ENROLLED_TO_ENROLLED, UNENROLLED_TO_ALLOWEDTOENROLL, UNENROLLED_TO_UNENROLLED, ALLOWEDTOENROLL_TO_ENROLLED ) from student.tests.factories import UserFactory, CourseModeFactory, AdminFactory from student.roles import CourseBetaTesterRole, CourseSalesAdminRole, CourseFinanceAdminRole, CourseInstructorRole from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.fields import Date from courseware.models import StudentFieldOverride import instructor_task.api import instructor.views.api from instructor.views.api import require_finance_admin from instructor.tests.utils import FakeContentTask, FakeEmail, FakeEmailInfo from instructor.views.api import generate_unique_password from instructor.views.api import _split_input_list, common_exceptions_400 from instructor_task.api_helper import AlreadyRunningError from openedx.core.djangoapps.course_groups.cohorts import set_course_cohort_settings from .test_tools import msk_from_problem_urlname DATE_FIELD = Date() EXPECTED_CSV_HEADER = ( '"code","redeem_code_url","course_id","company_name","created_by","redeemed_by","invoice_id","purchaser",' '"customer_reference_number","internal_reference"' ) EXPECTED_COUPON_CSV_HEADER = '"Coupon Code","Course Id","% Discount","Description","Expiration Date",' \ '"Is Active","Code Redeemed Count","Total Discounted Seats","Total Discounted Amount"' # ddt data for test cases involving reports REPORTS_DATA = ( { 'report_type': 'grade', 'instructor_api_endpoint': 'calculate_grades_csv', 'task_api_endpoint': 'instructor_task.api.submit_calculate_grades_csv', 'extra_instructor_api_kwargs': {} }, { 'report_type': 'enrolled student profile', 'instructor_api_endpoint': 'get_students_features', 'task_api_endpoint': 'instructor_task.api.submit_calculate_students_features_csv', 'extra_instructor_api_kwargs': {'csv': '/csv'} }, { 'report_type': 'detailed enrollment', 'instructor_api_endpoint': 'get_enrollment_report', 'task_api_endpoint': 'instructor_task.api.submit_detailed_enrollment_features_csv', 'extra_instructor_api_kwargs': {} }, { 'report_type': 'students who may enroll', 'instructor_api_endpoint': 'get_students_who_may_enroll', 'task_api_endpoint': 'instructor_task.api.submit_calculate_may_enroll_csv', 'extra_instructor_api_kwargs': {}, } ) # ddt data for test cases involving executive summary report EXECUTIVE_SUMMARY_DATA = ( { 'report_type': 'executive summary', 'instructor_api_endpoint': 'get_exec_summary_report', 'task_api_endpoint': 'instructor_task.api.submit_executive_summary_report', 'extra_instructor_api_kwargs': {} }, ) @common_exceptions_400 def view_success(request): # pylint: disable=unused-argument "A dummy view for testing that returns a simple HTTP response" return HttpResponse('success') @common_exceptions_400 def view_user_doesnotexist(request): # pylint: disable=unused-argument "A dummy view that raises a User.DoesNotExist exception" raise User.DoesNotExist() @common_exceptions_400 def view_alreadyrunningerror(request): # pylint: disable=unused-argument "A dummy view that raises an AlreadyRunningError exception" raise AlreadyRunningError() @attr('shard_1') class TestCommonExceptions400(TestCase): """ Testing the common_exceptions_400 decorator. """ def setUp(self): super(TestCommonExceptions400, self).setUp() self.request = Mock(spec=HttpRequest) self.request.META = {} def test_happy_path(self): resp = view_success(self.request) self.assertEqual(resp.status_code, 200) def test_user_doesnotexist(self): self.request.is_ajax.return_value = False resp = view_user_doesnotexist(self.request) # pylint: disable=assignment-from-no-return self.assertEqual(resp.status_code, 400) self.assertIn("User does not exist", resp.content) def test_user_doesnotexist_ajax(self): self.request.is_ajax.return_value = True resp = view_user_doesnotexist(self.request) # pylint: disable=assignment-from-no-return self.assertEqual(resp.status_code, 400) result = json.loads(resp.content) self.assertIn("User does not exist", result["error"]) def test_alreadyrunningerror(self): self.request.is_ajax.return_value = False resp = view_alreadyrunningerror(self.request) # pylint: disable=assignment-from-no-return self.assertEqual(resp.status_code, 400) self.assertIn("Task is already running", resp.content) def test_alreadyrunningerror_ajax(self): self.request.is_ajax.return_value = True resp = view_alreadyrunningerror(self.request) # pylint: disable=assignment-from-no-return self.assertEqual(resp.status_code, 400) result = json.loads(resp.content) self.assertIn("Task is already running", result["error"]) @attr('shard_1') @patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message')) @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False}) class TestInstructorAPIDenyLevels(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Ensure that users cannot access endpoints they shouldn't be able to. """ def setUp(self): super(TestInstructorAPIDenyLevels, self).setUp() self.course = CourseFactory.create() self.user = UserFactory.create() CourseEnrollment.enroll(self.user, self.course.id) self.problem_location = msk_from_problem_urlname( self.course.id, 'robot-some-problem-urlname' ) self.problem_urlname = self.problem_location.to_deprecated_string() _module = StudentModule.objects.create( student=self.user, course_id=self.course.id, module_state_key=self.problem_location, state=json.dumps({'attempts': 10}), ) # Endpoints that only Staff or Instructors can access self.staff_level_endpoints = [ ('students_update_enrollment', {'identifiers': 'foo@example.org', 'action': 'enroll'}), ('get_grading_config', {}), ('get_students_features', {}), ('get_distribution', {}), ('get_student_progress_url', {'unique_student_identifier': self.user.username}), ('reset_student_attempts', {'problem_to_reset': self.problem_urlname, 'unique_student_identifier': self.user.email}), ('update_forum_role_membership', {'unique_student_identifier': self.user.email, 'rolename': 'Moderator', 'action': 'allow'}), ('list_forum_members', {'rolename': FORUM_ROLE_COMMUNITY_TA}), ('proxy_legacy_analytics', {'aname': 'ProblemGradeDistribution'}), ('send_email', {'send_to': 'staff', 'subject': 'test', 'message': 'asdf'}), ('list_instructor_tasks', {}), ('list_background_email_tasks', {}), ('list_report_downloads', {}), ('list_financial_report_downloads', {}), ('calculate_grades_csv', {}), ('get_students_features', {}), ('get_enrollment_report', {}), ('get_students_who_may_enroll', {}), ('get_exec_summary_report', {}), ] # Endpoints that only Instructors can access self.instructor_level_endpoints = [ ('bulk_beta_modify_access', {'identifiers': 'foo@example.org', 'action': 'add'}), ('modify_access', {'unique_student_identifier': self.user.email, 'rolename': 'beta', 'action': 'allow'}), ('list_course_role_members', {'rolename': 'beta'}), ('rescore_problem', {'problem_to_reset': self.problem_urlname, 'unique_student_identifier': self.user.email}), ] def _access_endpoint(self, endpoint, args, status_code, msg): """ Asserts that accessing the given `endpoint` gets a response of `status_code`. endpoint: string, endpoint for instructor dash API args: dict, kwargs for `reverse` call status_code: expected HTTP status code response msg: message to display if assertion fails. """ url = reverse(endpoint, kwargs={'course_id': self.course.id.to_deprecated_string()}) if endpoint in ['send_email', 'students_update_enrollment', 'bulk_beta_modify_access']: response = self.client.post(url, args) else: response = self.client.get(url, args) self.assertEqual( response.status_code, status_code, msg=msg ) def test_student_level(self): """ Ensure that an enrolled student can't access staff or instructor endpoints. """ self.client.login(username=self.user.username, password='test') for endpoint, args in self.staff_level_endpoints: self._access_endpoint( endpoint, args, 403, "Student should not be allowed to access endpoint " + endpoint ) for endpoint, args in self.instructor_level_endpoints: self._access_endpoint( endpoint, args, 403, "Student should not be allowed to access endpoint " + endpoint ) def test_staff_level(self): """ Ensure that a staff member can't access instructor endpoints. """ staff_member = StaffFactory(course_key=self.course.id) CourseEnrollment.enroll(staff_member, self.course.id) CourseFinanceAdminRole(self.course.id).add_users(staff_member) self.client.login(username=staff_member.username, password='test') # Try to promote to forums admin - not working # update_forum_role(self.course.id, staff_member, FORUM_ROLE_ADMINISTRATOR, 'allow') for endpoint, args in self.staff_level_endpoints: # TODO: make these work if endpoint in ['update_forum_role_membership', 'proxy_legacy_analytics', 'list_forum_members']: continue self._access_endpoint( endpoint, args, 200, "Staff member should be allowed to access endpoint " + endpoint ) for endpoint, args in self.instructor_level_endpoints: self._access_endpoint( endpoint, args, 403, "Staff member should not be allowed to access endpoint " + endpoint ) def test_instructor_level(self): """ Ensure that an instructor member can access all endpoints. """ inst = InstructorFactory(course_key=self.course.id) CourseEnrollment.enroll(inst, self.course.id) CourseFinanceAdminRole(self.course.id).add_users(inst) self.client.login(username=inst.username, password='test') for endpoint, args in self.staff_level_endpoints: # TODO: make these work if endpoint in ['update_forum_role_membership', 'proxy_legacy_analytics']: continue self._access_endpoint( endpoint, args, 200, "Instructor should be allowed to access endpoint " + endpoint ) for endpoint, args in self.instructor_level_endpoints: # TODO: make this work if endpoint in ['rescore_problem']: continue self._access_endpoint( endpoint, args, 200, "Instructor should be allowed to access endpoint " + endpoint ) @attr('shard_1') @patch.dict(settings.FEATURES, {'ALLOW_AUTOMATED_SIGNUPS': True}) class TestInstructorAPIBulkAccountCreationAndEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test Bulk account creation and enrollment from csv file """ def setUp(self): super(TestInstructorAPIBulkAccountCreationAndEnrollment, self).setUp() self.request = RequestFactory().request() self.course = CourseFactory.create() self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') self.url = reverse('register_and_enroll_students', kwargs={'course_id': self.course.id.to_deprecated_string()}) self.not_enrolled_student = UserFactory( username='NotEnrolledStudent', email='nonenrolled@test.com', first_name='NotEnrolled', last_name='Student' ) @patch('instructor.views.api.log.info') def test_account_creation_and_enrollment_with_csv(self, info_log): """ Happy path test to create a single new user """ csv_content = "test_student@example.com,test_student_1,tester1,USA" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEquals(len(data['row_errors']), 0) self.assertEquals(len(data['warnings']), 0) self.assertEquals(len(data['general_errors']), 0) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_ENROLLED) # test the log for email that's send to new created user. info_log.assert_called_with('email sent to new created user at %s', 'test_student@example.com') @patch('instructor.views.api.log.info') def test_account_creation_and_enrollment_with_csv_with_blank_lines(self, info_log): """ Happy path test to create a single new user """ csv_content = "\ntest_student@example.com,test_student_1,tester1,USA\n\n" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEquals(len(data['row_errors']), 0) self.assertEquals(len(data['warnings']), 0) self.assertEquals(len(data['general_errors']), 0) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_ENROLLED) # test the log for email that's send to new created user. info_log.assert_called_with('email sent to new created user at %s', 'test_student@example.com') @patch('instructor.views.api.log.info') def test_email_and_username_already_exist(self, info_log): """ If the email address and username already exists and the user is enrolled in the course, do nothing (including no email gets sent out) """ csv_content = "test_student@example.com,test_student_1,tester1,USA\n" \ "test_student@example.com,test_student_1,tester2,US" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEquals(len(data['row_errors']), 0) self.assertEquals(len(data['warnings']), 0) self.assertEquals(len(data['general_errors']), 0) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_ENROLLED) # test the log for email that's send to new created user. info_log.assert_called_with( u"user already exists with username '%s' and email '%s'", 'test_student_1', 'test_student@example.com' ) def test_file_upload_type_not_csv(self): """ Try uploading some non-CSV file and verify that it is rejected """ uploaded_file = SimpleUploadedFile("temp.jpg", io.BytesIO(b"some initial binary data: \x00\x01").read()) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertNotEquals(len(data['general_errors']), 0) self.assertEquals(data['general_errors'][0]['response'], 'Make sure that the file you upload is in CSV format with no extraneous characters or rows.') manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 0) def test_bad_file_upload_type(self): """ Try uploading some non-CSV file and verify that it is rejected """ uploaded_file = SimpleUploadedFile("temp.csv", io.BytesIO(b"some initial binary data: \x00\x01").read()) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertNotEquals(len(data['general_errors']), 0) self.assertEquals(data['general_errors'][0]['response'], 'Could not read uploaded file.') manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 0) def test_insufficient_data(self): """ Try uploading a CSV file which does not have the exact four columns of data """ csv_content = "test_student@example.com,test_student_1\n" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEquals(len(data['row_errors']), 0) self.assertEquals(len(data['warnings']), 0) self.assertEquals(len(data['general_errors']), 1) self.assertEquals(data['general_errors'][0]['response'], 'Data in row #1 must have exactly four columns: email, username, full name, and country') manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 0) def test_invalid_email_in_csv(self): """ Test failure case of a poorly formatted email field """ csv_content = "test_student.example.com,test_student_1,tester1,USA" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'students_list': uploaded_file}) data = json.loads(response.content) self.assertEqual(response.status_code, 200) self.assertNotEquals(len(data['row_errors']), 0) self.assertEquals(len(data['warnings']), 0) self.assertEquals(len(data['general_errors']), 0) self.assertEquals(data['row_errors'][0]['response'], 'Invalid email {0}.'.format('test_student.example.com')) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 0) @patch('instructor.views.api.log.info') def test_csv_user_exist_and_not_enrolled(self, info_log): """ If the email address and username already exists and the user is not enrolled in the course, enrolled him/her and iterate to next one. """ csv_content = "nonenrolled@test.com,NotEnrolledStudent,tester1,USA" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) info_log.assert_called_with( u'user %s enrolled in the course %s', u'NotEnrolledStudent', self.course.id ) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertTrue(manual_enrollments[0].state_transition, UNENROLLED_TO_ENROLLED) def test_user_with_already_existing_email_in_csv(self): """ If the email address already exists, but the username is different, assume it is the correct user and just register the user in the course. """ csv_content = "test_student@example.com,test_student_1,tester1,USA\n" \ "test_student@example.com,test_student_2,tester2,US" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) warning_message = 'An account with email {email} exists but the provided username {username} ' \ 'is different. Enrolling anyway with {email}.'.format(email='test_student@example.com', username='test_student_2') self.assertNotEquals(len(data['warnings']), 0) self.assertEquals(data['warnings'][0]['response'], warning_message) user = User.objects.get(email='test_student@example.com') self.assertTrue(CourseEnrollment.is_enrolled(user, self.course.id)) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertTrue(manual_enrollments[0].state_transition, UNENROLLED_TO_ENROLLED) def test_user_with_already_existing_username_in_csv(self): """ If the username already exists (but not the email), assume it is a different user and fail to create the new account. """ csv_content = "test_student1@example.com,test_student_1,tester1,USA\n" \ "test_student2@example.com,test_student_1,tester2,US" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertNotEquals(len(data['row_errors']), 0) self.assertEquals(data['row_errors'][0]['response'], 'Username {user} already exists.'.format(user='test_student_1')) def test_csv_file_not_attached(self): """ Test when the user does not attach a file """ csv_content = "test_student1@example.com,test_student_1,tester1,USA\n" \ "test_student2@example.com,test_student_1,tester2,US" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'file_not_found': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertNotEquals(len(data['general_errors']), 0) self.assertEquals(data['general_errors'][0]['response'], 'File is not attached.') manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 0) def test_raising_exception_in_auto_registration_and_enrollment_case(self): """ Test that exceptions are handled well """ csv_content = "test_student1@example.com,test_student_1,tester1,USA\n" \ "test_student2@example.com,test_student_1,tester2,US" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) with patch('instructor.views.api.create_and_enroll_user') as mock: mock.side_effect = NonExistentCourseError() response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertNotEquals(len(data['row_errors']), 0) self.assertEquals(data['row_errors'][0]['response'], 'NonExistentCourseError') manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 0) def test_generate_unique_password(self): """ generate_unique_password should generate a unique password string that excludes certain characters. """ password = generate_unique_password([], 12) self.assertEquals(len(password), 12) for letter in password: self.assertNotIn(letter, 'aAeEiIoOuU1l') def test_users_created_and_enrolled_successfully_if_others_fail(self): csv_content = "test_student1@example.com,test_student_1,tester1,USA\n" \ "test_student3@example.com,test_student_1,tester3,CA\n" \ "test_student2@example.com,test_student_2,tester2,USA" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertNotEquals(len(data['row_errors']), 0) self.assertEquals(data['row_errors'][0]['response'], 'Username {user} already exists.'.format(user='test_student_1')) self.assertTrue(User.objects.filter(username='test_student_1', email='test_student1@example.com').exists()) self.assertTrue(User.objects.filter(username='test_student_2', email='test_student2@example.com').exists()) self.assertFalse(User.objects.filter(email='test_student3@example.com').exists()) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 2) @patch.object(instructor.views.api, 'generate_random_string', Mock(side_effect=['first', 'first', 'second'])) def test_generate_unique_password_no_reuse(self): """ generate_unique_password should generate a unique password string that hasn't been generated before. """ generated_password = ['first'] password = generate_unique_password(generated_password, 12) self.assertNotEquals(password, 'first') @patch.dict(settings.FEATURES, {'ALLOW_AUTOMATED_SIGNUPS': False}) def test_allow_automated_signups_flag_not_set(self): csv_content = "test_student1@example.com,test_student_1,tester1,USA" uploaded_file = SimpleUploadedFile("temp.csv", csv_content) response = self.client.post(self.url, {'students_list': uploaded_file}) self.assertEquals(response.status_code, 403) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 0) @attr('shard_1') @ddt.ddt class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test enrollment modification endpoint. This test does NOT exhaustively test state changes, that is the job of test_enrollment. This tests the response and action switch. """ def setUp(self): super(TestInstructorAPIEnrollment, self).setUp() self.request = RequestFactory().request() self.course = CourseFactory.create() self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') self.enrolled_student = UserFactory(username='EnrolledStudent', first_name='Enrolled', last_name='Student') CourseEnrollment.enroll( self.enrolled_student, self.course.id ) self.notenrolled_student = UserFactory(username='NotEnrolledStudent', first_name='NotEnrolled', last_name='Student') # Create invited, but not registered, user cea = CourseEnrollmentAllowed(email='robot-allowed@robot.org', course_id=self.course.id) cea.save() self.allowed_email = 'robot-allowed@robot.org' self.notregistered_email = 'robot-not-an-email-yet@robot.org' self.assertEqual(User.objects.filter(email=self.notregistered_email).count(), 0) # Email URL values self.site_name = microsite.get_value( 'SITE_NAME', settings.SITE_NAME ) self.about_path = '/courses/{}/about'.format(self.course.id) self.course_path = '/courses/{}/'.format(self.course.id) # uncomment to enable enable printing of large diffs # from failed assertions in the event of a test failure. # (comment because pylint C0103(invalid-name)) # self.maxDiff = None def test_missing_params(self): """ Test missing all query parameters. """ url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url) self.assertEqual(response.status_code, 400) def test_bad_action(self): """ Test with an invalid action. """ action = 'robot-not-an-action' url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.enrolled_student.email, 'action': action}) self.assertEqual(response.status_code, 400) def test_invalid_email(self): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': 'percivaloctavius@', 'action': 'enroll', 'email_students': False}) self.assertEqual(response.status_code, 200) # test the response data expected = { "action": "enroll", 'auto_enroll': False, "results": [ { "identifier": 'percivaloctavius@', "invalidIdentifier": True, } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_invalid_username(self): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': 'percivaloctavius', 'action': 'enroll', 'email_students': False}) self.assertEqual(response.status_code, 200) # test the response data expected = { "action": "enroll", 'auto_enroll': False, "results": [ { "identifier": 'percivaloctavius', "invalidIdentifier": True, } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_enroll_with_username(self): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.notenrolled_student.username, 'action': 'enroll', 'email_students': False}) self.assertEqual(response.status_code, 200) # test the response data expected = { "action": "enroll", 'auto_enroll': False, "results": [ { "identifier": self.notenrolled_student.username, "before": { "enrollment": False, "auto_enroll": False, "user": True, "allowed": False, }, "after": { "enrollment": True, "auto_enroll": False, "user": True, "allowed": False, } } ] } manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_ENROLLED) res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_enroll_without_email(self): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.notenrolled_student.email, 'action': 'enroll', 'email_students': False}) print "type(self.notenrolled_student.email): {}".format(type(self.notenrolled_student.email)) self.assertEqual(response.status_code, 200) # test that the user is now enrolled user = User.objects.get(email=self.notenrolled_student.email) self.assertTrue(CourseEnrollment.is_enrolled(user, self.course.id)) # test the response data expected = { "action": "enroll", "auto_enroll": False, "results": [ { "identifier": self.notenrolled_student.email, "before": { "enrollment": False, "auto_enroll": False, "user": True, "allowed": False, }, "after": { "enrollment": True, "auto_enroll": False, "user": True, "allowed": False, } } ] } manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_ENROLLED) res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 0) @ddt.data('http', 'https') def test_enroll_with_email(self, protocol): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) params = {'identifiers': self.notenrolled_student.email, 'action': 'enroll', 'email_students': True} environ = {'wsgi.url_scheme': protocol} response = self.client.post(url, params, **environ) print "type(self.notenrolled_student.email): {}".format(type(self.notenrolled_student.email)) self.assertEqual(response.status_code, 200) # test that the user is now enrolled user = User.objects.get(email=self.notenrolled_student.email) self.assertTrue(CourseEnrollment.is_enrolled(user, self.course.id)) # test the response data expected = { "action": "enroll", "auto_enroll": False, "results": [ { "identifier": self.notenrolled_student.email, "before": { "enrollment": False, "auto_enroll": False, "user": True, "allowed": False, }, "after": { "enrollment": True, "auto_enroll": False, "user": True, "allowed": False, } } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, u'You have been enrolled in {}'.format(self.course.display_name) ) self.assertEqual( mail.outbox[0].body, "Dear NotEnrolled Student\n\nYou have been enrolled in {} " "at edx.org by a member of the course staff. " "The course should now appear on your edx.org dashboard.\n\n" "To start accessing course materials, please visit " "{proto}://{site}{course_path}\n\n----\n" "This email was automatically sent from edx.org to NotEnrolled Student".format( self.course.display_name, proto=protocol, site=self.site_name, course_path=self.course_path ) ) @ddt.data('http', 'https') def test_enroll_with_email_not_registered(self, protocol): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) params = {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': True} environ = {'wsgi.url_scheme': protocol} response = self.client.post(url, params, **environ) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_ALLOWEDTOENROLL) self.assertEqual(response.status_code, 200) # Check the outbox self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, u'You have been invited to register for {}'.format(self.course.display_name) ) self.assertEqual( mail.outbox[0].body, "Dear student,\n\nYou have been invited to join {} at edx.org by a member of the course staff.\n\n" "To finish your registration, please visit {proto}://{site}/register and fill out the " "registration form making sure to use robot-not-an-email-yet@robot.org in the E-mail field.\n" "Once you have registered and activated your account, " "visit {proto}://{site}{about_path} to join the course.\n\n----\n" "This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org".format( self.course.display_name, proto=protocol, site=self.site_name, about_path=self.about_path ) ) @ddt.data('http', 'https') @patch.dict(settings.FEATURES, {'ENABLE_MKTG_SITE': True}) def test_enroll_email_not_registered_mktgsite(self, protocol): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) params = {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': True} environ = {'wsgi.url_scheme': protocol} response = self.client.post(url, params, **environ) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_ALLOWEDTOENROLL) self.assertEqual(response.status_code, 200) self.assertEqual( mail.outbox[0].body, "Dear student,\n\nYou have been invited to join {display_name}" " at edx.org by a member of the course staff.\n\n" "To finish your registration, please visit {proto}://{site}/register and fill out the registration form " "making sure to use robot-not-an-email-yet@robot.org in the E-mail field.\n" "You can then enroll in {display_name}.\n\n----\n" "This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org".format( display_name=self.course.display_name, proto=protocol, site=self.site_name ) ) @ddt.data('http', 'https') def test_enroll_with_email_not_registered_autoenroll(self, protocol): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) params = {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': True, 'auto_enroll': True} environ = {'wsgi.url_scheme': protocol} response = self.client.post(url, params, **environ) print "type(self.notregistered_email): {}".format(type(self.notregistered_email)) self.assertEqual(response.status_code, 200) # Check the outbox self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, u'You have been invited to register for {}'.format(self.course.display_name) ) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_ALLOWEDTOENROLL) self.assertEqual( mail.outbox[0].body, "Dear student,\n\nYou have been invited to join {display_name}" " at edx.org by a member of the course staff.\n\n" "To finish your registration, please visit {proto}://{site}/register and fill out the registration form " "making sure to use robot-not-an-email-yet@robot.org in the E-mail field.\n" "Once you have registered and activated your account," " you will see {display_name} listed on your dashboard.\n\n----\n" "This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org".format( proto=protocol, site=self.site_name, display_name=self.course.display_name ) ) def test_unenroll_without_email(self): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.enrolled_student.email, 'action': 'unenroll', 'email_students': False}) print "type(self.enrolled_student.email): {}".format(type(self.enrolled_student.email)) self.assertEqual(response.status_code, 200) # test that the user is now unenrolled user = User.objects.get(email=self.enrolled_student.email) self.assertFalse(CourseEnrollment.is_enrolled(user, self.course.id)) # test the response data expected = { "action": "unenroll", "auto_enroll": False, "results": [ { "identifier": self.enrolled_student.email, "before": { "enrollment": True, "auto_enroll": False, "user": True, "allowed": False, }, "after": { "enrollment": False, "auto_enroll": False, "user": True, "allowed": False, } } ] } manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, ENROLLED_TO_UNENROLLED) res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 0) def test_unenroll_with_email(self): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.enrolled_student.email, 'action': 'unenroll', 'email_students': True}) print "type(self.enrolled_student.email): {}".format(type(self.enrolled_student.email)) self.assertEqual(response.status_code, 200) # test that the user is now unenrolled user = User.objects.get(email=self.enrolled_student.email) self.assertFalse(CourseEnrollment.is_enrolled(user, self.course.id)) # test the response data expected = { "action": "unenroll", "auto_enroll": False, "results": [ { "identifier": self.enrolled_student.email, "before": { "enrollment": True, "auto_enroll": False, "user": True, "allowed": False, }, "after": { "enrollment": False, "auto_enroll": False, "user": True, "allowed": False, } } ] } manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, ENROLLED_TO_UNENROLLED) res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, 'You have been un-enrolled from {display_name}'.format(display_name=self.course.display_name,) ) self.assertEqual( mail.outbox[0].body, "Dear Enrolled Student\n\nYou have been un-enrolled in {display_name} " "at edx.org by a member of the course staff. " "The course will no longer appear on your edx.org dashboard.\n\n" "Your other courses have not been affected.\n\n----\n" "This email was automatically sent from edx.org to Enrolled Student".format( display_name=self.course.display_name, ) ) def test_unenroll_with_email_allowed_student(self): url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.allowed_email, 'action': 'unenroll', 'email_students': True}) print "type(self.allowed_email): {}".format(type(self.allowed_email)) self.assertEqual(response.status_code, 200) # test the response data expected = { "action": "unenroll", "auto_enroll": False, "results": [ { "identifier": self.allowed_email, "before": { "enrollment": False, "auto_enroll": False, "user": False, "allowed": True, }, "after": { "enrollment": False, "auto_enroll": False, "user": False, "allowed": False, } } ] } manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, ALLOWEDTOENROLL_TO_UNENROLLED) res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, 'You have been un-enrolled from {display_name}'.format(display_name=self.course.display_name,) ) self.assertEqual( mail.outbox[0].body, "Dear Student,\n\nYou have been un-enrolled from course {display_name} by a member of the course staff. " "Please disregard the invitation previously sent.\n\n----\n" "This email was automatically sent from edx.org to robot-allowed@robot.org".format( display_name=self.course.display_name, ) ) @ddt.data('http', 'https') @patch('instructor.enrollment.uses_shib') def test_enroll_with_email_not_registered_with_shib(self, protocol, mock_uses_shib): mock_uses_shib.return_value = True url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) params = {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': True} environ = {'wsgi.url_scheme': protocol} response = self.client.post(url, params, **environ) self.assertEqual(response.status_code, 200) # Check the outbox self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, 'You have been invited to register for {display_name}'.format(display_name=self.course.display_name,) ) self.assertEqual( mail.outbox[0].body, "Dear student,\n\nYou have been invited to join {display_name} at edx.org by a member of the course staff.\n\n" "To access the course visit {proto}://{site}{about_path} and register for the course.\n\n----\n" "This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org".format( proto=protocol, site=self.site_name, about_path=self.about_path, display_name=self.course.display_name, ) ) @patch('instructor.enrollment.uses_shib') @patch.dict(settings.FEATURES, {'ENABLE_MKTG_SITE': True}) def test_enroll_email_not_registered_shib_mktgsite(self, mock_uses_shib): # Try with marketing site enabled and shib on mock_uses_shib.return_value = True url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) # Try with marketing site enabled with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}): response = self.client.post(url, {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': True}) self.assertEqual(response.status_code, 200) self.assertEqual( mail.outbox[0].body, "Dear student,\n\nYou have been invited to join {} at edx.org by a member of the course staff.\n\n----\n" "This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org".format( self.course.display_name, ) ) @ddt.data('http', 'https') @patch('instructor.enrollment.uses_shib') def test_enroll_with_email_not_registered_with_shib_autoenroll(self, protocol, mock_uses_shib): mock_uses_shib.return_value = True url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id.to_deprecated_string()}) params = {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': True, 'auto_enroll': True} environ = {'wsgi.url_scheme': protocol} response = self.client.post(url, params, **environ) print "type(self.notregistered_email): {}".format(type(self.notregistered_email)) self.assertEqual(response.status_code, 200) # Check the outbox self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, 'You have been invited to register for {display_name}'.format(display_name=self.course.display_name,) ) self.assertEqual( mail.outbox[0].body, "Dear student,\n\nYou have been invited to join {display_name}" " at edx.org by a member of the course staff.\n\n" "To access the course visit {proto}://{site}{course_path} and login.\n\n----\n" "This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org".format( display_name=self.course.display_name, proto=protocol, site=self.site_name, course_path=self.course_path ) ) def test_enroll_already_enrolled_student(self): """ Ensure that already enrolled "verified" students cannot be downgraded to "honor" """ course_enrollment = CourseEnrollment.objects.get( user=self.enrolled_student, course_id=self.course.id ) # make this enrollment "verified" course_enrollment.mode = u'verified' course_enrollment.save() self.assertEqual(course_enrollment.mode, u'verified') # now re-enroll the student through the instructor dash self._change_student_enrollment(self.enrolled_student, self.course, 'enroll') # affirm that the student is still in "verified" mode course_enrollment = CourseEnrollment.objects.get( user=self.enrolled_student, course_id=self.course.id ) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, ENROLLED_TO_ENROLLED) self.assertEqual(course_enrollment.mode, u"verified") def create_paid_course(self): """ create paid course mode. """ paid_course = CourseFactory.create() CourseModeFactory.create(course_id=paid_course.id, min_price=50) CourseInstructorRole(paid_course.id).add_users(self.instructor) return paid_course def test_reason_field_should_not_be_empty(self): """ test to check that reason field should not be empty when manually enrolling the students for the paid courses. """ paid_course = self.create_paid_course() url = reverse('students_update_enrollment', kwargs={'course_id': paid_course.id.to_deprecated_string()}) params = {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': False, 'auto_enroll': False} response = self.client.post(url, params) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 0) # test the response data expected = { "action": "enroll", "auto_enroll": False, "results": [ { "error": True } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_unenrolled_allowed_to_enroll_user(self): """ test to unenroll allow to enroll user. """ paid_course = self.create_paid_course() url = reverse('students_update_enrollment', kwargs={'course_id': paid_course.id.to_deprecated_string()}) params = {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': False, 'auto_enroll': False, 'reason': 'testing..'} response = self.client.post(url, params) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_ALLOWEDTOENROLL) self.assertEqual(response.status_code, 200) # now registered the user UserFactory(email=self.notregistered_email) url = reverse('students_update_enrollment', kwargs={'course_id': paid_course.id.to_deprecated_string()}) params = {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': False, 'auto_enroll': False, 'reason': 'testing'} response = self.client.post(url, params) manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 2) self.assertEqual(manual_enrollments[1].state_transition, ALLOWEDTOENROLL_TO_ENROLLED) self.assertEqual(response.status_code, 200) # test the response data expected = { "action": "enroll", "auto_enroll": False, "results": [ { "identifier": self.notregistered_email, "before": { "enrollment": False, "auto_enroll": False, "user": True, "allowed": True, }, "after": { "enrollment": True, "auto_enroll": False, "user": True, "allowed": True, } } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_unenrolled_already_not_enrolled_user(self): """ test unenrolled user already not enrolled in a course. """ paid_course = self.create_paid_course() course_enrollment = CourseEnrollment.objects.filter( user__email=self.notregistered_email, course_id=paid_course.id ) self.assertEqual(course_enrollment.count(), 0) url = reverse('students_update_enrollment', kwargs={'course_id': paid_course.id.to_deprecated_string()}) params = {'identifiers': self.notregistered_email, 'action': 'unenroll', 'email_students': False, 'auto_enroll': False, 'reason': 'testing'} response = self.client.post(url, params) self.assertEqual(response.status_code, 200) # test the response data expected = { "action": "unenroll", "auto_enroll": False, "results": [ { "identifier": self.notregistered_email, "before": { "enrollment": False, "auto_enroll": False, "user": False, "allowed": False, }, "after": { "enrollment": False, "auto_enroll": False, "user": False, "allowed": False, } } ] } manual_enrollments = ManualEnrollmentAudit.objects.all() self.assertEqual(manual_enrollments.count(), 1) self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_UNENROLLED) res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_unenroll_and_enroll_verified(self): """ Test that unenrolling and enrolling a student from a verified track results in that student being in an honor track """ course_enrollment = CourseEnrollment.objects.get( user=self.enrolled_student, course_id=self.course.id ) # upgrade enrollment course_enrollment.mode = u'verified' course_enrollment.save() self.assertEqual(course_enrollment.mode, u'verified') self._change_student_enrollment(self.enrolled_student, self.course, 'unenroll') self._change_student_enrollment(self.enrolled_student, self.course, 'enroll') course_enrollment = CourseEnrollment.objects.get( user=self.enrolled_student, course_id=self.course.id ) self.assertEqual(course_enrollment.mode, u'honor') def _change_student_enrollment(self, user, course, action): """ Helper function that posts to 'students_update_enrollment' to change a student's enrollment """ url = reverse( 'students_update_enrollment', kwargs={'course_id': course.id.to_deprecated_string()}, ) params = { 'identifiers': user.email, 'action': action, 'email_students': True, 'reason': 'change user enrollment' } response = self.client.post(url, params) self.assertEqual(response.status_code, 200) return response @attr('shard_1') @ddt.ddt class TestInstructorAPIBulkBetaEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test bulk beta modify access endpoint. """ def setUp(self): super(TestInstructorAPIBulkBetaEnrollment, self).setUp() self.course = CourseFactory.create() self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') self.beta_tester = BetaTesterFactory(course_key=self.course.id) CourseEnrollment.enroll( self.beta_tester, self.course.id ) self.assertTrue(CourseBetaTesterRole(self.course.id).has_user(self.beta_tester)) self.notenrolled_student = UserFactory(username='NotEnrolledStudent') self.notregistered_email = 'robot-not-an-email-yet@robot.org' self.assertEqual(User.objects.filter(email=self.notregistered_email).count(), 0) self.request = RequestFactory().request() # Email URL values self.site_name = microsite.get_value( 'SITE_NAME', settings.SITE_NAME ) self.about_path = '/courses/{}/about'.format(self.course.id) self.course_path = '/courses/{}/'.format(self.course.id) # uncomment to enable enable printing of large diffs # from failed assertions in the event of a test failure. # (comment because pylint C0103(invalid-name)) # self.maxDiff = None def test_missing_params(self): """ Test missing all query parameters. """ url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url) self.assertEqual(response.status_code, 400) def test_bad_action(self): """ Test with an invalid action. """ action = 'robot-not-an-action' url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.beta_tester.email, 'action': action}) self.assertEqual(response.status_code, 400) def add_notenrolled(self, response, identifier): """ Test Helper Method (not a test, called by other tests) Takes a client response from a call to bulk_beta_modify_access with 'email_students': False, and the student identifier (email or username) given as 'identifiers' in the request. Asserts the reponse returns cleanly, that the student was added as a beta tester, and the response properly contains their identifier, 'error': False, and 'userDoesNotExist': False. Additionally asserts no email was sent. """ self.assertEqual(response.status_code, 200) self.assertTrue(CourseBetaTesterRole(self.course.id).has_user(self.notenrolled_student)) # test the response data expected = { "action": "add", "results": [ { "identifier": identifier, "error": False, "userDoesNotExist": False } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 0) def test_add_notenrolled_email(self): url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.notenrolled_student.email, 'action': 'add', 'email_students': False}) self.add_notenrolled(response, self.notenrolled_student.email) self.assertFalse(CourseEnrollment.is_enrolled(self.notenrolled_student, self.course.id)) def test_add_notenrolled_email_autoenroll(self): url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.notenrolled_student.email, 'action': 'add', 'email_students': False, 'auto_enroll': True}) self.add_notenrolled(response, self.notenrolled_student.email) self.assertTrue(CourseEnrollment.is_enrolled(self.notenrolled_student, self.course.id)) def test_add_notenrolled_username(self): url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.notenrolled_student.username, 'action': 'add', 'email_students': False}) self.add_notenrolled(response, self.notenrolled_student.username) self.assertFalse(CourseEnrollment.is_enrolled(self.notenrolled_student, self.course.id)) def test_add_notenrolled_username_autoenroll(self): url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.notenrolled_student.username, 'action': 'add', 'email_students': False, 'auto_enroll': True}) self.add_notenrolled(response, self.notenrolled_student.username) self.assertTrue(CourseEnrollment.is_enrolled(self.notenrolled_student, self.course.id)) @ddt.data('http', 'https') def test_add_notenrolled_with_email(self, protocol): url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) params = {'identifiers': self.notenrolled_student.email, 'action': 'add', 'email_students': True} environ = {'wsgi.url_scheme': protocol} response = self.client.post(url, params, **environ) self.assertEqual(response.status_code, 200) self.assertTrue(CourseBetaTesterRole(self.course.id).has_user(self.notenrolled_student)) # test the response data expected = { "action": "add", "results": [ { "identifier": self.notenrolled_student.email, "error": False, "userDoesNotExist": False } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, 'You have been invited to a beta test for {display_name}'.format(display_name=self.course.display_name,) ) self.assertEqual( mail.outbox[0].body, u"Dear {student_name}\n\nYou have been invited to be a beta tester " "for {display_name} at edx.org by a member of the course staff.\n\n" "Visit {proto}://{site}{about_path} to join " "the course and begin the beta test.\n\n----\n" "This email was automatically sent from edx.org to {student_email}".format( display_name=self.course.display_name, student_name=self.notenrolled_student.profile.name, student_email=self.notenrolled_student.email, proto=protocol, site=self.site_name, about_path=self.about_path ) ) @ddt.data('http', 'https') def test_add_notenrolled_with_email_autoenroll(self, protocol): url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) params = {'identifiers': self.notenrolled_student.email, 'action': 'add', 'email_students': True, 'auto_enroll': True} environ = {'wsgi.url_scheme': protocol} response = self.client.post(url, params, **environ) self.assertEqual(response.status_code, 200) self.assertTrue(CourseBetaTesterRole(self.course.id).has_user(self.notenrolled_student)) # test the response data expected = { "action": "add", "results": [ { "identifier": self.notenrolled_student.email, "error": False, "userDoesNotExist": False } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, 'You have been invited to a beta test for {display_name}'.format(display_name=self.course.display_name) ) self.assertEqual( mail.outbox[0].body, u"Dear {student_name}\n\nYou have been invited to be a beta tester " "for {display_name} at edx.org by a member of the course staff.\n\n" "To start accessing course materials, please visit " "{proto}://{site}{course_path}\n\n----\n" "This email was automatically sent from edx.org to {student_email}".format( display_name=self.course.display_name, student_name=self.notenrolled_student.profile.name, student_email=self.notenrolled_student.email, proto=protocol, site=self.site_name, course_path=self.course_path ) ) @patch.dict(settings.FEATURES, {'ENABLE_MKTG_SITE': True}) def test_add_notenrolled_email_mktgsite(self): # Try with marketing site enabled url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.notenrolled_student.email, 'action': 'add', 'email_students': True}) self.assertEqual(response.status_code, 200) self.assertEqual( mail.outbox[0].body, u"Dear {}\n\nYou have been invited to be a beta tester " "for {} at edx.org by a member of the course staff.\n\n" "Visit edx.org to enroll in the course and begin the beta test.\n\n----\n" "This email was automatically sent from edx.org to {}".format( self.notenrolled_student.profile.name, self.course.display_name, self.notenrolled_student.email, ) ) def test_enroll_with_email_not_registered(self): # User doesn't exist url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.notregistered_email, 'action': 'add', 'email_students': True, 'reason': 'testing'}) self.assertEqual(response.status_code, 200) # test the response data expected = { "action": "add", "results": [ { "identifier": self.notregistered_email, "error": True, "userDoesNotExist": True } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 0) def test_remove_without_email(self): url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.beta_tester.email, 'action': 'remove', 'email_students': False, 'reason': 'testing'}) self.assertEqual(response.status_code, 200) # Works around a caching bug which supposedly can't happen in prod. The instance here is not == # the instance fetched from the email above which had its cache cleared if hasattr(self.beta_tester, '_roles'): del self.beta_tester._roles self.assertFalse(CourseBetaTesterRole(self.course.id).has_user(self.beta_tester)) # test the response data expected = { "action": "remove", "results": [ { "identifier": self.beta_tester.email, "error": False, "userDoesNotExist": False } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 0) def test_remove_with_email(self): url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, {'identifiers': self.beta_tester.email, 'action': 'remove', 'email_students': True, 'reason': 'testing'}) self.assertEqual(response.status_code, 200) # Works around a caching bug which supposedly can't happen in prod. The instance here is not == # the instance fetched from the email above which had its cache cleared if hasattr(self.beta_tester, '_roles'): del self.beta_tester._roles self.assertFalse(CourseBetaTesterRole(self.course.id).has_user(self.beta_tester)) # test the response data expected = { "action": "remove", "results": [ { "identifier": self.beta_tester.email, "error": False, "userDoesNotExist": False } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) # Check the outbox self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, u'You have been removed from a beta test for {display_name}'.format(display_name=self.course.display_name,) ) self.assertEqual( mail.outbox[0].body, "Dear {full_name}\n\nYou have been removed as a beta tester for " "{display_name} at edx.org by a member of the course staff. " "The course will remain on your dashboard, but you will no longer " "be part of the beta testing group.\n\n" "Your other courses have not been affected.\n\n----\n" "This email was automatically sent from edx.org to {email_address}".format( display_name=self.course.display_name, full_name=self.beta_tester.profile.name, email_address=self.beta_tester.email ) ) @attr('shard_1') class TestInstructorAPILevelsAccess(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test endpoints whereby instructors can change permissions of other users. This test does NOT test whether the actions had an effect on the database, that is the job of test_access. This tests the response and action switch. Actually, modify_access does not have a very meaningful response yet, so only the status code is tested. """ def setUp(self): super(TestInstructorAPILevelsAccess, self).setUp() self.course = CourseFactory.create() self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') self.other_instructor = InstructorFactory(course_key=self.course.id) self.other_staff = StaffFactory(course_key=self.course.id) self.other_user = UserFactory() def test_modify_access_noparams(self): """ Test missing all query parameters. """ url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url) self.assertEqual(response.status_code, 400) def test_modify_access_bad_action(self): """ Test with an invalid action parameter. """ url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'unique_student_identifier': self.other_staff.email, 'rolename': 'staff', 'action': 'robot-not-an-action', }) self.assertEqual(response.status_code, 400) def test_modify_access_bad_role(self): """ Test with an invalid action parameter. """ url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'unique_student_identifier': self.other_staff.email, 'rolename': 'robot-not-a-roll', 'action': 'revoke', }) self.assertEqual(response.status_code, 400) def test_modify_access_allow(self): url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'unique_student_identifier': self.other_user.email, 'rolename': 'staff', 'action': 'allow', }) self.assertEqual(response.status_code, 200) def test_modify_access_allow_with_uname(self): url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'unique_student_identifier': self.other_instructor.username, 'rolename': 'staff', 'action': 'allow', }) self.assertEqual(response.status_code, 200) def test_modify_access_revoke(self): url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'unique_student_identifier': self.other_staff.email, 'rolename': 'staff', 'action': 'revoke', }) self.assertEqual(response.status_code, 200) def test_modify_access_revoke_with_username(self): url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'unique_student_identifier': self.other_staff.username, 'rolename': 'staff', 'action': 'revoke', }) self.assertEqual(response.status_code, 200) def test_modify_access_with_fake_user(self): url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'unique_student_identifier': 'GandalfTheGrey', 'rolename': 'staff', 'action': 'revoke', }) self.assertEqual(response.status_code, 200) expected = { 'unique_student_identifier': 'GandalfTheGrey', 'userDoesNotExist': True, } res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_modify_access_with_inactive_user(self): self.other_user.is_active = False self.other_user.save() # pylint: disable=no-member url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'unique_student_identifier': self.other_user.username, 'rolename': 'beta', 'action': 'allow', }) self.assertEqual(response.status_code, 200) expected = { 'unique_student_identifier': self.other_user.username, 'inactiveUser': True, } res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_modify_access_revoke_not_allowed(self): """ Test revoking access that a user does not have. """ url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'unique_student_identifier': self.other_staff.email, 'rolename': 'instructor', 'action': 'revoke', }) self.assertEqual(response.status_code, 200) def test_modify_access_revoke_self(self): """ Test that an instructor cannot remove instructor privelages from themself. """ url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'unique_student_identifier': self.instructor.email, 'rolename': 'instructor', 'action': 'revoke', }) self.assertEqual(response.status_code, 200) # check response content expected = { 'unique_student_identifier': self.instructor.username, 'rolename': 'instructor', 'action': 'revoke', 'removingSelfAsInstructor': True, } res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_list_course_role_members_noparams(self): """ Test missing all query parameters. """ url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url) self.assertEqual(response.status_code, 400) def test_list_course_role_members_bad_rolename(self): """ Test with an invalid rolename parameter. """ url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'rolename': 'robot-not-a-rolename', }) self.assertEqual(response.status_code, 400) def test_list_course_role_members_staff(self): url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'rolename': 'staff', }) self.assertEqual(response.status_code, 200) # check response content expected = { 'course_id': self.course.id.to_deprecated_string(), 'staff': [ { 'username': self.other_staff.username, 'email': self.other_staff.email, 'first_name': self.other_staff.first_name, 'last_name': self.other_staff.last_name, } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_list_course_role_members_beta(self): url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'rolename': 'beta', }) self.assertEqual(response.status_code, 200) # check response content expected = { 'course_id': self.course.id.to_deprecated_string(), 'beta': [] } res_json = json.loads(response.content) self.assertEqual(res_json, expected) def test_update_forum_role_membership(self): """ Test update forum role membership with user's email and username. """ # Seed forum roles for course. seed_permissions_roles(self.course.id) for user in [self.instructor, self.other_user]: for identifier_attr in [user.email, user.username]: for rolename in ["Administrator", "Moderator", "Community TA"]: for action in ["allow", "revoke"]: self.assert_update_forum_role_membership(user, identifier_attr, rolename, action) def assert_update_forum_role_membership(self, current_user, identifier, rolename, action): """ Test update forum role membership. Get unique_student_identifier, rolename and action and update forum role. """ url = reverse('update_forum_role_membership', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get( url, { 'unique_student_identifier': identifier, 'rolename': rolename, 'action': action, } ) # Status code should be 200. self.assertEqual(response.status_code, 200) user_roles = current_user.roles.filter(course_id=self.course.id).values_list("name", flat=True) if action == 'allow': self.assertIn(rolename, user_roles) elif action == 'revoke': self.assertNotIn(rolename, user_roles) @attr('shard_1') @ddt.ddt @patch.dict('django.conf.settings.FEATURES', {'ENABLE_PAID_COURSE_REGISTRATION': True}) class TestInstructorAPILevelsDataDump(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test endpoints that show data without side effects. """ def setUp(self): super(TestInstructorAPILevelsDataDump, self).setUp() self.course = CourseFactory.create() self.course_mode = CourseMode(course_id=self.course.id, mode_slug="honor", mode_display_name="honor cert", min_price=40) self.course_mode.save() self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') self.cart = Order.get_cart_for_user(self.instructor) self.coupon_code = 'abcde' self.coupon = Coupon(code=self.coupon_code, description='testing code', course_id=self.course.id, percentage_discount=10, created_by=self.instructor, is_active=True) self.coupon.save() #create testing invoice 1 self.sale_invoice_1 = Invoice.objects.create( total_amount=1234.32, company_name='Test1', company_contact_name='TestName', company_contact_email='Test@company.com', recipient_name='Testw', recipient_email='test1@test.com', customer_reference_number='2Fwe23S', internal_reference="A", course_id=self.course.id, is_valid=True ) self.invoice_item = CourseRegistrationCodeInvoiceItem.objects.create( invoice=self.sale_invoice_1, qty=1, unit_price=1234.32, course_id=self.course.id ) self.students = [UserFactory() for _ in xrange(6)] for student in self.students: CourseEnrollment.enroll(student, self.course.id) self.students_who_may_enroll = self.students + [UserFactory() for _ in range(5)] for student in self.students_who_may_enroll: CourseEnrollmentAllowed.objects.create( email=student.email, course_id=self.course.id ) def register_with_redemption_code(self, user, code): """ enroll user using a registration code """ redeem_url = reverse('register_code_redemption', args=[code]) self.client.login(username=user.username, password='test') response = self.client.get(redeem_url) self.assertEquals(response.status_code, 200) # check button text self.assertTrue('Activate Course Enrollment' in response.content) response = self.client.post(redeem_url) self.assertEquals(response.status_code, 200) def test_invalidate_sale_record(self): """ Testing the sale invalidating scenario. """ for i in range(2): course_registration_code = CourseRegistrationCode( code='sale_invoice{}'.format(i), course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, invoice=self.sale_invoice_1, invoice_item=self.invoice_item, mode_slug='honor' ) course_registration_code.save() data = {'invoice_number': self.sale_invoice_1.id, 'event_type': "invalidate"} url = reverse('sale_validation', kwargs={'course_id': self.course.id.to_deprecated_string()}) self.assert_request_status_code(200, url, method="POST", data=data) #Now try to fetch data against not existing invoice number test_data_1 = {'invoice_number': 100, 'event_type': "invalidate"} self.assert_request_status_code(404, url, method="POST", data=test_data_1) # Now invalidate the same invoice number and expect an Bad request response = self.assert_request_status_code(400, url, method="POST", data=data) self.assertIn("The sale associated with this invoice has already been invalidated.", response.content) # now re_validate the invoice number data['event_type'] = "re_validate" self.assert_request_status_code(200, url, method="POST", data=data) # Now re_validate the same active invoice number and expect an Bad request response = self.assert_request_status_code(400, url, method="POST", data=data) self.assertIn("This invoice is already active.", response.content) test_data_2 = {'invoice_number': self.sale_invoice_1.id} response = self.assert_request_status_code(400, url, method="POST", data=test_data_2) self.assertIn("Missing required event_type parameter", response.content) test_data_3 = {'event_type': "re_validate"} response = self.assert_request_status_code(400, url, method="POST", data=test_data_3) self.assertIn("Missing required invoice_number parameter", response.content) # submitting invalid invoice number data['invoice_number'] = 'testing' response = self.assert_request_status_code(400, url, method="POST", data=data) self.assertIn("invoice_number must be an integer, {value} provided".format(value=data['invoice_number']), response.content) def test_get_sale_order_records_features_csv(self): """ Test that the response from get_sale_order_records is in csv format. """ # add the coupon code for the course coupon = Coupon( code='test_code', description='test_description', course_id=self.course.id, percentage_discount='10', created_by=self.instructor, is_active=True ) coupon.save() self.cart.order_type = 'business' self.cart.save() self.cart.add_billing_details(company_name='Test Company', company_contact_name='Test', company_contact_email='test@123', recipient_name='R1', recipient_email='', customer_reference_number='PO#23') paid_course_reg_item = PaidCourseRegistration.add_to_order(self.cart, self.course.id) # update the quantity of the cart item paid_course_reg_item resp = self.client.post(reverse('shoppingcart.views.update_user_cart'), {'ItemId': paid_course_reg_item.id, 'qty': '4'}) self.assertEqual(resp.status_code, 200) # apply the coupon code to the item in the cart resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': coupon.code}) self.assertEqual(resp.status_code, 200) self.cart.purchase() # get the updated item item = self.cart.orderitem_set.all().select_subclasses()[0] # get the redeemed coupon information coupon_redemption = CouponRedemption.objects.select_related('coupon').filter(order=self.cart) sale_order_url = reverse('get_sale_order_records', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(sale_order_url) self.assertEqual(response['Content-Type'], 'text/csv') self.assertIn('36', response.content.split('\r\n')[1]) self.assertIn(str(item.unit_cost), response.content.split('\r\n')[1],) self.assertIn(str(item.list_price), response.content.split('\r\n')[1],) self.assertIn(item.status, response.content.split('\r\n')[1],) self.assertIn(coupon_redemption[0].coupon.code, response.content.split('\r\n')[1],) def test_coupon_redeem_count_in_ecommerce_section(self): """ Test that checks the redeem count in the instructor_dashboard coupon section """ # add the coupon code for the course coupon = Coupon( code='test_code', description='test_description', course_id=self.course.id, percentage_discount='10', created_by=self.instructor, is_active=True ) coupon.save() # Coupon Redeem Count only visible for Financial Admins. CourseFinanceAdminRole(self.course.id).add_users(self.instructor) PaidCourseRegistration.add_to_order(self.cart, self.course.id) # apply the coupon code to the item in the cart resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': coupon.code}) self.assertEqual(resp.status_code, 200) # URL for instructor dashboard instructor_dashboard = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()}) # visit the instructor dashboard page and # check that the coupon redeem count should be 0 resp = self.client.get(instructor_dashboard) self.assertEqual(resp.status_code, 200) self.assertIn('Number Redeemed', resp.content) self.assertIn('<td>0</td>', resp.content) # now make the payment of your cart items self.cart.purchase() # visit the instructor dashboard page and # check that the coupon redeem count should be 1 resp = self.client.get(instructor_dashboard) self.assertEqual(resp.status_code, 200) self.assertIn('Number Redeemed', resp.content) self.assertIn('<td>1</td>', resp.content) def test_get_sale_records_features_csv(self): """ Test that the response from get_sale_records is in csv format. """ for i in range(2): course_registration_code = CourseRegistrationCode( code='sale_invoice{}'.format(i), course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, invoice=self.sale_invoice_1, invoice_item=self.invoice_item, mode_slug='honor' ) course_registration_code.save() url = reverse( 'get_sale_records', kwargs={'course_id': self.course.id.to_deprecated_string()} ) response = self.client.get(url + '/csv', {}) self.assertEqual(response['Content-Type'], 'text/csv') def test_get_sale_records_features_json(self): """ Test that the response from get_sale_records is in json format. """ for i in range(5): course_registration_code = CourseRegistrationCode( code='sale_invoice{}'.format(i), course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, invoice=self.sale_invoice_1, invoice_item=self.invoice_item, mode_slug='honor' ) course_registration_code.save() url = reverse('get_sale_records', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {}) res_json = json.loads(response.content) self.assertIn('sale', res_json) for res in res_json['sale']: self.validate_sale_records_response( res, course_registration_code, self.sale_invoice_1, 0, invoice_item=self.invoice_item ) def test_get_sale_records_features_with_multiple_invoices(self): """ Test that the response from get_sale_records is in json format for multiple invoices """ for i in range(5): course_registration_code = CourseRegistrationCode( code='qwerty{}'.format(i), course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, invoice=self.sale_invoice_1, invoice_item=self.invoice_item, mode_slug='honor' ) course_registration_code.save() #create test invoice 2 sale_invoice_2 = Invoice.objects.create( total_amount=1234.32, company_name='Test1', company_contact_name='TestName', company_contact_email='Test@company.com', recipient_name='Testw_2', recipient_email='test2@test.com', customer_reference_number='2Fwe23S', internal_reference="B", course_id=self.course.id ) invoice_item_2 = CourseRegistrationCodeInvoiceItem.objects.create( invoice=sale_invoice_2, qty=1, unit_price=1234.32, course_id=self.course.id ) for i in range(5): course_registration_code = CourseRegistrationCode( code='xyzmn{}'.format(i), course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, invoice=sale_invoice_2, invoice_item=invoice_item_2, mode_slug='honor' ) course_registration_code.save() url = reverse('get_sale_records', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {}) res_json = json.loads(response.content) self.assertIn('sale', res_json) self.validate_sale_records_response( res_json['sale'][0], course_registration_code, self.sale_invoice_1, 0, invoice_item=self.invoice_item ) self.validate_sale_records_response( res_json['sale'][1], course_registration_code, sale_invoice_2, 0, invoice_item=invoice_item_2 ) def validate_sale_records_response(self, res, course_registration_code, invoice, used_codes, invoice_item): """ validate sale records attribute values with the response object """ self.assertEqual(res['total_amount'], invoice.total_amount) self.assertEqual(res['recipient_email'], invoice.recipient_email) self.assertEqual(res['recipient_name'], invoice.recipient_name) self.assertEqual(res['company_name'], invoice.company_name) self.assertEqual(res['company_contact_name'], invoice.company_contact_name) self.assertEqual(res['company_contact_email'], invoice.company_contact_email) self.assertEqual(res['internal_reference'], invoice.internal_reference) self.assertEqual(res['customer_reference_number'], invoice.customer_reference_number) self.assertEqual(res['invoice_number'], invoice.id) self.assertEqual(res['created_by'], course_registration_code.created_by.username) self.assertEqual(res['course_id'], invoice_item.course_id.to_deprecated_string()) self.assertEqual(res['total_used_codes'], used_codes) self.assertEqual(res['total_codes'], 5) def test_get_students_features(self): """ Test that some minimum of information is formatted correctly in the response to get_students_features. """ url = reverse('get_students_features', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {}) res_json = json.loads(response.content) self.assertIn('students', res_json) for student in self.students: student_json = [ x for x in res_json['students'] if x['username'] == student.username ][0] self.assertEqual(student_json['username'], student.username) self.assertEqual(student_json['email'], student.email) @ddt.data(True, False) def test_get_students_features_cohorted(self, is_cohorted): """ Test that get_students_features includes cohort info when the course is cohorted, and does not when the course is not cohorted. """ url = reverse('get_students_features', kwargs={'course_id': unicode(self.course.id)}) set_course_cohort_settings(self.course.id, is_cohorted=is_cohorted) response = self.client.get(url, {}) res_json = json.loads(response.content) self.assertEqual('cohort' in res_json['feature_names'], is_cohorted) def test_get_students_who_may_enroll(self): """ Test whether get_students_who_may_enroll returns an appropriate status message when users request a CSV file of students who may enroll in a course. """ url = reverse( 'get_students_who_may_enroll', kwargs={'course_id': unicode(self.course.id)} ) # Successful case: response = self.client.get(url, {}) res_json = json.loads(response.content) self.assertIn('status', res_json) self.assertNotIn('already in progress', res_json['status']) # CSV generation already in progress: with patch('instructor_task.api.submit_calculate_may_enroll_csv') as submit_task_function: error = AlreadyRunningError() submit_task_function.side_effect = error response = self.client.get(url, {}) res_json = json.loads(response.content) self.assertIn('status', res_json) self.assertIn('already in progress', res_json['status']) def test_access_course_finance_admin_with_invalid_course_key(self): """ Test assert require_course fiance_admin before generating a detailed enrollment report """ func = Mock() decorated_func = require_finance_admin(func) request = self.mock_request() response = decorated_func(request, 'invalid_course_key') self.assertEqual(response.status_code, 404) self.assertFalse(func.called) def mock_request(self): """ mock request """ request = Mock() request.user = self.instructor return request def test_access_course_finance_admin_with_valid_course_key(self): """ Test to check the course_finance_admin role with valid key but doesn't have access to the function """ func = Mock() decorated_func = require_finance_admin(func) request = self.mock_request() response = decorated_func(request, 'valid/course/key') self.assertEqual(response.status_code, 403) self.assertFalse(func.called) def test_add_user_to_fiance_admin_role_with_valid_course(self): """ test to check that a function is called using a fiance_admin rights. """ func = Mock() decorated_func = require_finance_admin(func) request = self.mock_request() CourseFinanceAdminRole(self.course.id).add_users(self.instructor) decorated_func(request, self.course.id.to_deprecated_string()) self.assertTrue(func.called) def test_enrollment_report_features_csv(self): """ test to generate enrollment report. enroll users, admin staff using registration codes. """ InvoiceTransaction.objects.create( invoice=self.sale_invoice_1, amount=self.sale_invoice_1.total_amount, status='completed', created_by=self.instructor, last_modified_by=self.instructor ) course_registration_code = CourseRegistrationCode.objects.create( code='abcde', course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, invoice=self.sale_invoice_1, invoice_item=self.invoice_item, mode_slug='honor' ) admin_user = AdminFactory() admin_cart = Order.get_cart_for_user(admin_user) PaidCourseRegistration.add_to_order(admin_cart, self.course.id) admin_cart.purchase() # create a new user/student and enroll # in the course using a registration code # and then validates the generated detailed enrollment report test_user = UserFactory() self.register_with_redemption_code(test_user, course_registration_code.code) CourseFinanceAdminRole(self.course.id).add_users(self.instructor) UserProfileFactory.create(user=self.students[0], meta='{"company": "asdasda"}') self.client.login(username=self.instructor.username, password='test') url = reverse('get_enrollment_report', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {}) self.assertIn('Your detailed enrollment report is being generated!', response.content) def test_bulk_purchase_detailed_report(self): """ test to generate detailed enrollment report. 1 Purchase registration codes. 2 Enroll users via registration code. 3 Validate generated enrollment report. """ paid_course_reg_item = PaidCourseRegistration.add_to_order(self.cart, self.course.id) # update the quantity of the cart item paid_course_reg_item resp = self.client.post(reverse('shoppingcart.views.update_user_cart'), {'ItemId': paid_course_reg_item.id, 'qty': '4'}) self.assertEqual(resp.status_code, 200) # apply the coupon code to the item in the cart resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': self.coupon_code}) self.assertEqual(resp.status_code, 200) self.cart.purchase() course_reg_codes = CourseRegistrationCode.objects.filter(order=self.cart) self.register_with_redemption_code(self.instructor, course_reg_codes[0].code) test_user = UserFactory() test_user_cart = Order.get_cart_for_user(test_user) PaidCourseRegistration.add_to_order(test_user_cart, self.course.id) test_user_cart.purchase() InvoiceTransaction.objects.create( invoice=self.sale_invoice_1, amount=-self.sale_invoice_1.total_amount, status='refunded', created_by=self.instructor, last_modified_by=self.instructor ) course_registration_code = CourseRegistrationCode.objects.create( code='abcde', course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, invoice=self.sale_invoice_1, invoice_item=self.invoice_item, mode_slug='honor' ) test_user1 = UserFactory() self.register_with_redemption_code(test_user1, course_registration_code.code) CourseFinanceAdminRole(self.course.id).add_users(self.instructor) self.client.login(username=self.instructor.username, password='test') url = reverse('get_enrollment_report', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {}) self.assertIn('Your detailed enrollment report is being generated!', response.content) def test_create_registration_code_without_invoice_and_order(self): """ test generate detailed enrollment report, used a registration codes which has been created via invoice or bulk purchase scenario. """ course_registration_code = CourseRegistrationCode.objects.create( code='abcde', course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, mode_slug='honor' ) test_user1 = UserFactory() self.register_with_redemption_code(test_user1, course_registration_code.code) CourseFinanceAdminRole(self.course.id).add_users(self.instructor) self.client.login(username=self.instructor.username, password='test') url = reverse('get_enrollment_report', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {}) self.assertIn('Your detailed enrollment report is being generated!', response.content) def test_invoice_payment_is_still_pending_for_registration_codes(self): """ test generate enrollment report enroll a user in a course using registration code whose invoice has not been paid yet """ course_registration_code = CourseRegistrationCode.objects.create( code='abcde', course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, invoice=self.sale_invoice_1, invoice_item=self.invoice_item, mode_slug='honor' ) test_user1 = UserFactory() self.register_with_redemption_code(test_user1, course_registration_code.code) CourseFinanceAdminRole(self.course.id).add_users(self.instructor) self.client.login(username=self.instructor.username, password='test') url = reverse('get_enrollment_report', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {}) self.assertIn('Your detailed enrollment report is being generated!', response.content) @patch.object(instructor.views.api, 'anonymous_id_for_user', Mock(return_value='42')) @patch.object(instructor.views.api, 'unique_id_for_user', Mock(return_value='41')) def test_get_anon_ids(self): """ Test the CSV output for the anonymized user ids. """ url = reverse('get_anon_ids', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {}) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith( '"User ID","Anonymized User ID","Course Specific Anonymized User ID"' '\n"3","41","42"\n' )) self.assertTrue(body.endswith('"8","41","42"\n')) def test_list_report_downloads(self): url = reverse('list_report_downloads', kwargs={'course_id': self.course.id.to_deprecated_string()}) with patch('instructor_task.models.LocalFSReportStore.links_for') as mock_links_for: mock_links_for.return_value = [ ('mock_file_name_1', 'https://1.mock.url'), ('mock_file_name_2', 'https://2.mock.url'), ] response = self.client.get(url, {}) expected_response = { "downloads": [ { "url": "https://1.mock.url", "link": "<a href=\"https://1.mock.url\">mock_file_name_1</a>", "name": "mock_file_name_1" }, { "url": "https://2.mock.url", "link": "<a href=\"https://2.mock.url\">mock_file_name_2</a>", "name": "mock_file_name_2" } ] } res_json = json.loads(response.content) self.assertEqual(res_json, expected_response) @ddt.data(*REPORTS_DATA) @ddt.unpack def test_calculate_report_csv_success(self, report_type, instructor_api_endpoint, task_api_endpoint, extra_instructor_api_kwargs): kwargs = {'course_id': unicode(self.course.id)} kwargs.update(extra_instructor_api_kwargs) url = reverse(instructor_api_endpoint, kwargs=kwargs) CourseFinanceAdminRole(self.course.id).add_users(self.instructor) with patch(task_api_endpoint): response = self.client.get(url, {}) success_status = "Your {report_type} report is being generated! You can view the status of the generation task in the 'Pending Instructor Tasks' section.".format(report_type=report_type) self.assertIn(success_status, response.content) @ddt.data(*EXECUTIVE_SUMMARY_DATA) @ddt.unpack def test_executive_summary_report_success( self, report_type, instructor_api_endpoint, task_api_endpoint, extra_instructor_api_kwargs ): kwargs = {'course_id': unicode(self.course.id)} kwargs.update(extra_instructor_api_kwargs) url = reverse(instructor_api_endpoint, kwargs=kwargs) CourseFinanceAdminRole(self.course.id).add_users(self.instructor) with patch(task_api_endpoint): response = self.client.get(url, {}) success_status = "Your {report_type} report is being created." \ " To view the status of the report, see the 'Pending Instructor Tasks'" \ " section.".format(report_type=report_type) self.assertIn(success_status, response.content) @ddt.data(*EXECUTIVE_SUMMARY_DATA) @ddt.unpack def test_executive_summary_report_already_running( self, report_type, instructor_api_endpoint, task_api_endpoint, extra_instructor_api_kwargs ): kwargs = {'course_id': unicode(self.course.id)} kwargs.update(extra_instructor_api_kwargs) url = reverse(instructor_api_endpoint, kwargs=kwargs) CourseFinanceAdminRole(self.course.id).add_users(self.instructor) with patch(task_api_endpoint) as mock: mock.side_effect = AlreadyRunningError() response = self.client.get(url, {}) already_running_status = "An {report_type} report is currently in progress." \ " To view the status of the report, see the 'Pending Instructor Tasks' section." \ " When completed, the report will be available for download in the table below." \ " You will be able to download the" \ " report when it is complete.".format(report_type=report_type) self.assertIn(already_running_status, response.content) def test_get_distribution_no_feature(self): """ Test that get_distribution lists available features when supplied no feature parameter. """ url = reverse('get_distribution', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = json.loads(response.content) self.assertEqual(type(res_json['available_features']), list) url = reverse('get_distribution', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url + u'?feature=') self.assertEqual(response.status_code, 200) res_json = json.loads(response.content) self.assertEqual(type(res_json['available_features']), list) def test_get_distribution_unavailable_feature(self): """ Test that get_distribution fails gracefully with an unavailable feature. """ url = reverse('get_distribution', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {'feature': 'robot-not-a-real-feature'}) self.assertEqual(response.status_code, 400) def test_get_distribution_gender(self): """ Test that get_distribution fails gracefully with an unavailable feature. """ url = reverse('get_distribution', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {'feature': 'gender'}) self.assertEqual(response.status_code, 200) res_json = json.loads(response.content) self.assertEqual(res_json['feature_results']['data']['m'], 6) self.assertEqual(res_json['feature_results']['choices_display_names']['m'], 'Male') self.assertEqual(res_json['feature_results']['data']['no_data'], 0) self.assertEqual(res_json['feature_results']['choices_display_names']['no_data'], 'No Data') def test_get_student_progress_url(self): """ Test that progress_url is in the successful response. """ url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()}) url += "?unique_student_identifier={}".format( quote(self.students[0].email.encode("utf-8")) ) response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = json.loads(response.content) self.assertIn('progress_url', res_json) def test_get_student_progress_url_from_uname(self): """ Test that progress_url is in the successful response. """ url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()}) url += "?unique_student_identifier={}".format( quote(self.students[0].username.encode("utf-8")) ) response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = json.loads(response.content) self.assertIn('progress_url', res_json) def test_get_student_progress_url_noparams(self): """ Test that the endpoint 404's without the required query params. """ url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url) self.assertEqual(response.status_code, 400) def test_get_student_progress_url_nostudent(self): """ Test that the endpoint 400's when requesting an unknown email. """ url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url) self.assertEqual(response.status_code, 400) @attr('shard_1') class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test endpoints whereby instructors can change student grades. This includes resetting attempts and starting rescore tasks. This test does NOT test whether the actions had an effect on the database, that is the job of task tests and test_enrollment. """ def setUp(self): super(TestInstructorAPIRegradeTask, self).setUp() self.course = CourseFactory.create() self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') self.student = UserFactory() CourseEnrollment.enroll(self.student, self.course.id) self.problem_location = msk_from_problem_urlname( self.course.id, 'robot-some-problem-urlname' ) self.problem_urlname = self.problem_location.to_deprecated_string() self.module_to_reset = StudentModule.objects.create( student=self.student, course_id=self.course.id, module_state_key=self.problem_location, state=json.dumps({'attempts': 10}), ) def test_reset_student_attempts_deletall(self): """ Make sure no one can delete all students state on a problem. """ url = reverse('reset_student_attempts', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'problem_to_reset': self.problem_urlname, 'all_students': True, 'delete_module': True, }) self.assertEqual(response.status_code, 400) def test_reset_student_attempts_single(self): """ Test reset single student attempts. """ url = reverse('reset_student_attempts', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'problem_to_reset': self.problem_urlname, 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 200) # make sure problem attempts have been reset. changed_module = StudentModule.objects.get(pk=self.module_to_reset.pk) self.assertEqual( json.loads(changed_module.state)['attempts'], 0 ) # mock out the function which should be called to execute the action. @patch.object(instructor_task.api, 'submit_reset_problem_attempts_for_all_students') def test_reset_student_attempts_all(self, act): """ Test reset all student attempts. """ url = reverse('reset_student_attempts', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'problem_to_reset': self.problem_urlname, 'all_students': True, }) self.assertEqual(response.status_code, 200) self.assertTrue(act.called) def test_reset_student_attempts_missingmodule(self): """ Test reset for non-existant problem. """ url = reverse('reset_student_attempts', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'problem_to_reset': 'robot-not-a-real-module', 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 400) def test_reset_student_attempts_delete(self): """ Test delete single student state. """ url = reverse('reset_student_attempts', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'problem_to_reset': self.problem_urlname, 'unique_student_identifier': self.student.email, 'delete_module': True, }) self.assertEqual(response.status_code, 200) # make sure the module has been deleted self.assertEqual( StudentModule.objects.filter( student=self.module_to_reset.student, course_id=self.module_to_reset.course_id, # module_id=self.module_to_reset.module_id, ).count(), 0 ) def test_reset_student_attempts_nonsense(self): """ Test failure with both unique_student_identifier and all_students. """ url = reverse('reset_student_attempts', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'problem_to_reset': self.problem_urlname, 'unique_student_identifier': self.student.email, 'all_students': True, }) self.assertEqual(response.status_code, 400) @patch.object(instructor_task.api, 'submit_rescore_problem_for_student') def test_rescore_problem_single(self, act): """ Test rescoring of a single student. """ url = reverse('rescore_problem', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'problem_to_reset': self.problem_urlname, 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 200) self.assertTrue(act.called) @patch.object(instructor_task.api, 'submit_rescore_problem_for_student') def test_rescore_problem_single_from_uname(self, act): """ Test rescoring of a single student. """ url = reverse('rescore_problem', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'problem_to_reset': self.problem_urlname, 'unique_student_identifier': self.student.username, }) self.assertEqual(response.status_code, 200) self.assertTrue(act.called) @patch.object(instructor_task.api, 'submit_rescore_problem_for_all_students') def test_rescore_problem_all(self, act): """ Test rescoring for all students. """ url = reverse('rescore_problem', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'problem_to_reset': self.problem_urlname, 'all_students': True, }) self.assertEqual(response.status_code, 200) self.assertTrue(act.called) @patch.dict(settings.FEATURES, {'ENTRANCE_EXAMS': True}) def test_course_has_entrance_exam_in_student_attempts_reset(self): """ Test course has entrance exam id set while resetting attempts""" url = reverse('reset_student_attempts_for_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'all_students': True, 'delete_module': False, }) self.assertEqual(response.status_code, 400) @patch.dict(settings.FEATURES, {'ENTRANCE_EXAMS': True}) def test_rescore_entrance_exam_with_invalid_exam(self): """ Test course has entrance exam id set while re-scoring. """ url = reverse('rescore_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 400) @attr('shard_1') @patch.dict(settings.FEATURES, {'ENTRANCE_EXAMS': True}) class TestEntranceExamInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test endpoints whereby instructors can rescore student grades, reset student attempts and delete state for entrance exam. """ def setUp(self): super(TestEntranceExamInstructorAPIRegradeTask, self).setUp() self.course = CourseFactory.create( org='test_org', course='test_course', run='test_run', entrance_exam_id='i4x://{}/{}/chapter/Entrance_exam'.format('test_org', 'test_course') ) self.course_with_invalid_ee = CourseFactory.create(entrance_exam_id='invalid_exam') self.instructor = InstructorFactory(course_key=self.course.id) # Add instructor to invalid ee course CourseInstructorRole(self.course_with_invalid_ee.id).add_users(self.instructor) self.client.login(username=self.instructor.username, password='test') self.student = UserFactory() CourseEnrollment.enroll(self.student, self.course.id) self.entrance_exam = ItemFactory.create( parent=self.course, category='chapter', display_name='Entrance exam' ) subsection = ItemFactory.create( parent=self.entrance_exam, category='sequential', display_name='Subsection 1' ) vertical = ItemFactory.create( parent=subsection, category='vertical', display_name='Vertical 1' ) self.ee_problem_1 = ItemFactory.create( parent=vertical, category="problem", display_name="Exam Problem - Problem 1" ) self.ee_problem_2 = ItemFactory.create( parent=vertical, category="problem", display_name="Exam Problem - Problem 2" ) ee_module_to_reset1 = StudentModule.objects.create( student=self.student, course_id=self.course.id, module_state_key=self.ee_problem_1.location, state=json.dumps({'attempts': 10, 'done': True}), ) ee_module_to_reset2 = StudentModule.objects.create( student=self.student, course_id=self.course.id, module_state_key=self.ee_problem_2.location, state=json.dumps({'attempts': 10, 'done': True}), ) self.ee_modules = [ee_module_to_reset1.module_state_key, ee_module_to_reset2.module_state_key] def test_reset_entrance_exam_student_attempts_deletall(self): """ Make sure no one can delete all students state on entrance exam. """ url = reverse('reset_student_attempts_for_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'all_students': True, 'delete_module': True, }) self.assertEqual(response.status_code, 400) def test_reset_entrance_exam_student_attempts_single(self): """ Test reset single student attempts for entrance exam. """ url = reverse('reset_student_attempts_for_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 200) # make sure problem attempts have been reset. changed_modules = StudentModule.objects.filter(module_state_key__in=self.ee_modules) for changed_module in changed_modules: self.assertEqual( json.loads(changed_module.state)['attempts'], 0 ) # mock out the function which should be called to execute the action. @patch.object(instructor_task.api, 'submit_reset_problem_attempts_in_entrance_exam') def test_reset_entrance_exam_all_student_attempts(self, act): """ Test reset all student attempts for entrance exam. """ url = reverse('reset_student_attempts_for_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'all_students': True, }) self.assertEqual(response.status_code, 200) self.assertTrue(act.called) def test_reset_student_attempts_invalid_entrance_exam(self): """ Test reset for invalid entrance exam. """ url = reverse('reset_student_attempts_for_entrance_exam', kwargs={'course_id': unicode(self.course_with_invalid_ee.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 400) def test_entrance_exam_sttudent_delete_state(self): """ Test delete single student entrance exam state. """ url = reverse('reset_student_attempts_for_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, 'delete_module': True, }) self.assertEqual(response.status_code, 200) # make sure the module has been deleted changed_modules = StudentModule.objects.filter(module_state_key__in=self.ee_modules) self.assertEqual(changed_modules.count(), 0) def test_entrance_exam_delete_state_with_staff(self): """ Test entrance exam delete state failure with staff access. """ self.client.logout() staff_user = StaffFactory(course_key=self.course.id) self.client.login(username=staff_user.username, password='test') url = reverse('reset_student_attempts_for_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, 'delete_module': True, }) self.assertEqual(response.status_code, 403) def test_entrance_exam_reset_student_attempts_nonsense(self): """ Test failure with both unique_student_identifier and all_students. """ url = reverse('reset_student_attempts_for_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, 'all_students': True, }) self.assertEqual(response.status_code, 400) @patch.object(instructor_task.api, 'submit_rescore_entrance_exam_for_student') def test_rescore_entrance_exam_single_student(self, act): """ Test re-scoring of entrance exam for single student. """ url = reverse('rescore_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 200) self.assertTrue(act.called) def test_rescore_entrance_exam_all_student(self): """ Test rescoring for all students. """ url = reverse('rescore_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'all_students': True, }) self.assertEqual(response.status_code, 200) def test_rescore_entrance_exam_all_student_and_single(self): """ Test re-scoring with both all students and single student parameters. """ url = reverse('rescore_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, 'all_students': True, }) self.assertEqual(response.status_code, 400) def test_rescore_entrance_exam_with_invalid_exam(self): """ Test re-scoring of entrance exam with invalid exam. """ url = reverse('rescore_entrance_exam', kwargs={'course_id': unicode(self.course_with_invalid_ee.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 400) def test_list_entrance_exam_instructor_tasks_student(self): """ Test list task history for entrance exam AND student. """ # create a re-score entrance exam task url = reverse('rescore_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 200) url = reverse('list_entrance_exam_instructor_tasks', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 200) # check response tasks = json.loads(response.content)['tasks'] self.assertEqual(len(tasks), 1) self.assertEqual(tasks[0]['status'], _('Complete')) def test_list_entrance_exam_instructor_tasks_all_student(self): """ Test list task history for entrance exam AND all student. """ url = reverse('list_entrance_exam_instructor_tasks', kwargs={'course_id': unicode(self.course.id)}) response = self.client.get(url, {}) self.assertEqual(response.status_code, 200) # check response tasks = json.loads(response.content)['tasks'] self.assertEqual(len(tasks), 0) def test_list_entrance_exam_instructor_with_invalid_exam_key(self): """ Test list task history for entrance exam failure if course has invalid exam. """ url = reverse('list_entrance_exam_instructor_tasks', kwargs={'course_id': unicode(self.course_with_invalid_ee.id)}) response = self.client.get(url, { 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 400) def test_skip_entrance_exam_student(self): """ Test skip entrance exam api for student. """ # create a re-score entrance exam task url = reverse('mark_student_can_skip_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.post(url, { 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 200) # check response message = _('This student (%s) will skip the entrance exam.') % self.student.email self.assertContains(response, message) # post again with same student response = self.client.post(url, { 'unique_student_identifier': self.student.email, }) # This time response message should be different message = _('This student (%s) is already allowed to skip the entrance exam.') % self.student.email self.assertContains(response, message) @attr('shard_1') @patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message')) @patch.dict(settings.FEATURES, {'ENABLE_INSTRUCTOR_EMAIL': True, 'REQUIRE_COURSE_EMAIL_AUTH': False}) class TestInstructorSendEmail(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Checks that only instructors have access to email endpoints, and that these endpoints are only accessible with courses that actually exist, only with valid email messages. """ def setUp(self): super(TestInstructorSendEmail, self).setUp() self.course = CourseFactory.create() self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') test_subject = u'\u1234 test subject' test_message = u'\u6824 test message' self.full_test_message = { 'send_to': 'staff', 'subject': test_subject, 'message': test_message, } def test_send_email_as_logged_in_instructor(self): url = reverse('send_email', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, self.full_test_message) self.assertEqual(response.status_code, 200) def test_send_email_but_not_logged_in(self): self.client.logout() url = reverse('send_email', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, self.full_test_message) self.assertEqual(response.status_code, 403) def test_send_email_but_not_staff(self): self.client.logout() student = UserFactory() self.client.login(username=student.username, password='test') url = reverse('send_email', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, self.full_test_message) self.assertEqual(response.status_code, 403) def test_send_email_but_course_not_exist(self): url = reverse('send_email', kwargs={'course_id': 'GarbageCourse/DNE/NoTerm'}) response = self.client.post(url, self.full_test_message) self.assertNotEqual(response.status_code, 200) def test_send_email_no_sendto(self): url = reverse('send_email', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, { 'subject': 'test subject', 'message': 'test message', }) self.assertEqual(response.status_code, 400) def test_send_email_no_subject(self): url = reverse('send_email', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, { 'send_to': 'staff', 'message': 'test message', }) self.assertEqual(response.status_code, 400) def test_send_email_no_message(self): url = reverse('send_email', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url, { 'send_to': 'staff', 'subject': 'test subject', }) self.assertEqual(response.status_code, 400) class MockCompletionInfo(object): """Mock for get_task_completion_info""" times_called = 0 def mock_get_task_completion_info(self, *args): # pylint: disable=unused-argument """Mock for get_task_completion_info""" self.times_called += 1 if self.times_called % 2 == 0: return True, 'Task Completed' return False, 'Task Errored In Some Way' @attr('shard_1') class TestInstructorAPITaskLists(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test instructor task list endpoint. """ class FakeTask(object): """ Fake task object """ FEATURES = [ 'task_type', 'task_input', 'task_id', 'requester', 'task_state', 'created', 'status', 'task_message', 'duration_sec' ] def __init__(self, completion): for feature in self.FEATURES: setattr(self, feature, 'expected') # created needs to be a datetime self.created = datetime.datetime(2013, 10, 25, 11, 42, 35) # set 'status' and 'task_message' attrs success, task_message = completion() if success: self.status = "Complete" else: self.status = "Incomplete" self.task_message = task_message # Set 'task_output' attr, which will be parsed to the 'duration_sec' attr. self.task_output = '{"duration_ms": 1035000}' self.duration_sec = 1035000 / 1000.0 def make_invalid_output(self): """Munge task_output to be invalid json""" self.task_output = 'HI MY NAME IS INVALID JSON' # This should be given the value of 'unknown' if the task output # can't be properly parsed self.duration_sec = 'unknown' def to_dict(self): """ Convert fake task to dictionary representation. """ attr_dict = {key: getattr(self, key) for key in self.FEATURES} attr_dict['created'] = attr_dict['created'].isoformat() return attr_dict def setUp(self): super(TestInstructorAPITaskLists, self).setUp() self.course = CourseFactory.create( entrance_exam_id='i4x://{}/{}/chapter/Entrance_exam'.format('test_org', 'test_course') ) self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') self.student = UserFactory() CourseEnrollment.enroll(self.student, self.course.id) self.problem_location = msk_from_problem_urlname( self.course.id, 'robot-some-problem-urlname' ) self.problem_urlname = self.problem_location.to_deprecated_string() self.module = StudentModule.objects.create( student=self.student, course_id=self.course.id, module_state_key=self.problem_location, state=json.dumps({'attempts': 10}), ) mock_factory = MockCompletionInfo() self.tasks = [self.FakeTask(mock_factory.mock_get_task_completion_info) for _ in xrange(7)] self.tasks[-1].make_invalid_output() @patch.object(instructor_task.api, 'get_running_instructor_tasks') def test_list_instructor_tasks_running(self, act): """ Test list of all running tasks. """ act.return_value = self.tasks url = reverse('list_instructor_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()}) mock_factory = MockCompletionInfo() with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info: mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info response = self.client.get(url, {}) self.assertEqual(response.status_code, 200) # check response self.assertTrue(act.called) expected_tasks = [ftask.to_dict() for ftask in self.tasks] actual_tasks = json.loads(response.content)['tasks'] for exp_task, act_task in zip(expected_tasks, actual_tasks): self.assertDictEqual(exp_task, act_task) self.assertEqual(actual_tasks, expected_tasks) @patch.object(instructor_task.api, 'get_instructor_task_history') def test_list_background_email_tasks(self, act): """Test list of background email tasks.""" act.return_value = self.tasks url = reverse('list_background_email_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()}) mock_factory = MockCompletionInfo() with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info: mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info response = self.client.get(url, {}) self.assertEqual(response.status_code, 200) # check response self.assertTrue(act.called) expected_tasks = [ftask.to_dict() for ftask in self.tasks] actual_tasks = json.loads(response.content)['tasks'] for exp_task, act_task in zip(expected_tasks, actual_tasks): self.assertDictEqual(exp_task, act_task) self.assertEqual(actual_tasks, expected_tasks) @patch.object(instructor_task.api, 'get_instructor_task_history') def test_list_instructor_tasks_problem(self, act): """ Test list task history for problem. """ act.return_value = self.tasks url = reverse('list_instructor_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()}) mock_factory = MockCompletionInfo() with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info: mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info response = self.client.get(url, { 'problem_location_str': self.problem_urlname, }) self.assertEqual(response.status_code, 200) # check response self.assertTrue(act.called) expected_tasks = [ftask.to_dict() for ftask in self.tasks] actual_tasks = json.loads(response.content)['tasks'] for exp_task, act_task in zip(expected_tasks, actual_tasks): self.assertDictEqual(exp_task, act_task) self.assertEqual(actual_tasks, expected_tasks) @patch.object(instructor_task.api, 'get_instructor_task_history') def test_list_instructor_tasks_problem_student(self, act): """ Test list task history for problem AND student. """ act.return_value = self.tasks url = reverse('list_instructor_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()}) mock_factory = MockCompletionInfo() with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info: mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info response = self.client.get(url, { 'problem_location_str': self.problem_urlname, 'unique_student_identifier': self.student.email, }) self.assertEqual(response.status_code, 200) # check response self.assertTrue(act.called) expected_tasks = [ftask.to_dict() for ftask in self.tasks] actual_tasks = json.loads(response.content)['tasks'] for exp_task, act_task in zip(expected_tasks, actual_tasks): self.assertDictEqual(exp_task, act_task) self.assertEqual(actual_tasks, expected_tasks) @attr('shard_1') @patch.object(instructor_task.api, 'get_instructor_task_history') class TestInstructorEmailContentList(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test the instructor email content history endpoint. """ def setUp(self): super(TestInstructorEmailContentList, self).setUp() self.course = CourseFactory.create() self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') self.tasks = {} self.emails = {} self.emails_info = {} def setup_fake_email_info(self, num_emails, with_failures=False): """ Initialize the specified number of fake emails """ for email_id in range(num_emails): num_sent = random.randint(1, 15401) if with_failures: failed = random.randint(1, 15401) else: failed = 0 self.tasks[email_id] = FakeContentTask(email_id, num_sent, failed, 'expected') self.emails[email_id] = FakeEmail(email_id) self.emails_info[email_id] = FakeEmailInfo(self.emails[email_id], num_sent, failed) def get_matching_mock_email(self, **kwargs): """ Returns the matching mock emails for the given id """ email_id = kwargs.get('id', 0) return self.emails[email_id] def get_email_content_response(self, num_emails, task_history_request, with_failures=False): """ Calls the list_email_content endpoint and returns the repsonse """ self.setup_fake_email_info(num_emails, with_failures) task_history_request.return_value = self.tasks.values() url = reverse('list_email_content', kwargs={'course_id': self.course.id.to_deprecated_string()}) with patch('instructor.views.api.CourseEmail.objects.get') as mock_email_info: mock_email_info.side_effect = self.get_matching_mock_email response = self.client.get(url, {}) self.assertEqual(response.status_code, 200) return response def check_emails_sent(self, num_emails, task_history_request, with_failures=False): """ Tests sending emails with or without failures """ response = self.get_email_content_response(num_emails, task_history_request, with_failures) self.assertTrue(task_history_request.called) expected_email_info = [email_info.to_dict() for email_info in self.emails_info.values()] actual_email_info = json.loads(response.content)['emails'] self.assertEqual(len(actual_email_info), num_emails) for exp_email, act_email in zip(expected_email_info, actual_email_info): self.assertDictEqual(exp_email, act_email) self.assertEqual(expected_email_info, actual_email_info) def test_content_list_one_email(self, task_history_request): """ Test listing of bulk emails when email list has one email """ response = self.get_email_content_response(1, task_history_request) self.assertTrue(task_history_request.called) email_info = json.loads(response.content)['emails'] # Emails list should have one email self.assertEqual(len(email_info), 1) # Email content should be what's expected expected_message = self.emails[0].html_message returned_email_info = email_info[0] received_message = returned_email_info[u'email'][u'html_message'] self.assertEqual(expected_message, received_message) def test_content_list_no_emails(self, task_history_request): """ Test listing of bulk emails when email list empty """ response = self.get_email_content_response(0, task_history_request) self.assertTrue(task_history_request.called) email_info = json.loads(response.content)['emails'] # Emails list should be empty self.assertEqual(len(email_info), 0) def test_content_list_email_content_many(self, task_history_request): """ Test listing of bulk emails sent large amount of emails """ self.check_emails_sent(50, task_history_request) def test_list_email_content_error(self, task_history_request): """ Test handling of error retrieving email """ invalid_task = FakeContentTask(0, 0, 0, 'test') invalid_task.make_invalid_input() task_history_request.return_value = [invalid_task] url = reverse('list_email_content', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {}) self.assertEqual(response.status_code, 200) self.assertTrue(task_history_request.called) returned_email_info = json.loads(response.content)['emails'] self.assertEqual(len(returned_email_info), 1) returned_info = returned_email_info[0] for info in ['created', 'sent_to', 'email', 'number_sent', 'requester']: self.assertEqual(returned_info[info], None) def test_list_email_with_failure(self, task_history_request): """ Test the handling of email task that had failures """ self.check_emails_sent(1, task_history_request, True) def test_list_many_emails_with_failures(self, task_history_request): """ Test the handling of many emails with failures """ self.check_emails_sent(50, task_history_request, True) def test_list_email_with_no_successes(self, task_history_request): task_info = FakeContentTask(0, 0, 10, 'expected') email = FakeEmail(0) email_info = FakeEmailInfo(email, 0, 10) task_history_request.return_value = [task_info] url = reverse('list_email_content', kwargs={'course_id': self.course.id.to_deprecated_string()}) with patch('instructor.views.api.CourseEmail.objects.get') as mock_email_info: mock_email_info.return_value = email response = self.client.get(url, {}) self.assertEqual(response.status_code, 200) self.assertTrue(task_history_request.called) returned_info_list = json.loads(response.content)['emails'] self.assertEqual(len(returned_info_list), 1) returned_info = returned_info_list[0] expected_info = email_info.to_dict() self.assertDictEqual(expected_info, returned_info) @attr('shard_1') @ddt.ddt @override_settings(ANALYTICS_SERVER_URL="http://robotanalyticsserver.netbot:900/") @override_settings(ANALYTICS_API_KEY="robot_api_key") class TestInstructorAPIAnalyticsProxy(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test instructor analytics proxy endpoint. """ class FakeProxyResponse(object): """ Fake successful requests response object. """ def __init__(self): self.status_code = requests.status_codes.codes.OK self.content = '{"test_content": "robot test content"}' class FakeBadProxyResponse(object): """ Fake strange-failed requests response object. """ def __init__(self): self.status_code = 'notok.' self.content = '{"test_content": "robot test content"}' def setUp(self): super(TestInstructorAPIAnalyticsProxy, self).setUp() self.course = CourseFactory.create() self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') @ddt.data((ModuleStoreEnum.Type.mongo, False), (ModuleStoreEnum.Type.split, True)) @ddt.unpack @patch.object(instructor.views.api.requests, 'get') def test_analytics_proxy_url(self, store_type, assert_wo_encoding, act): """ Test legacy analytics proxy url generation. """ with modulestore().default_store(store_type): course = CourseFactory.create() instructor_local = InstructorFactory(course_key=course.id) self.client.login(username=instructor_local.username, password='test') act.return_value = self.FakeProxyResponse() url = reverse('proxy_legacy_analytics', kwargs={'course_id': course.id.to_deprecated_string()}) response = self.client.get(url, { 'aname': 'ProblemGradeDistribution' }) self.assertEqual(response.status_code, 200) # Make request URL pattern - everything but course id. url_pattern = "{url}get?aname={aname}&course_id={course_id}&apikey={api_key}".format( url="http://robotanalyticsserver.netbot:900/", aname="ProblemGradeDistribution", course_id="{course_id!s}", api_key="robot_api_key", ) if assert_wo_encoding: # Format url with no URL-encoding of parameters. assert_url = url_pattern.format(course_id=course.id.to_deprecated_string()) with self.assertRaises(AssertionError): act.assert_called_once_with(assert_url) # Format url *with* URL-encoding of parameters. expected_url = url_pattern.format(course_id=quote(course.id.to_deprecated_string())) act.assert_called_once_with(expected_url) @override_settings(ANALYTICS_SERVER_URL="") @patch.object(instructor.views.api.requests, 'get') def test_analytics_proxy_server_url(self, act): """ Test legacy analytics when empty server url. """ act.return_value = self.FakeProxyResponse() url = reverse('proxy_legacy_analytics', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'aname': 'ProblemGradeDistribution' }) self.assertEqual(response.status_code, 501) @override_settings(ANALYTICS_API_KEY="") @patch.object(instructor.views.api.requests, 'get') def test_analytics_proxy_api_key(self, act): """ Test legacy analytics when empty server API key. """ act.return_value = self.FakeProxyResponse() url = reverse('proxy_legacy_analytics', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'aname': 'ProblemGradeDistribution' }) self.assertEqual(response.status_code, 501) @override_settings(ANALYTICS_SERVER_URL="") @override_settings(ANALYTICS_API_KEY="") @patch.object(instructor.views.api.requests, 'get') def test_analytics_proxy_empty_url_and_api_key(self, act): """ Test legacy analytics when empty server url & API key. """ act.return_value = self.FakeProxyResponse() url = reverse('proxy_legacy_analytics', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'aname': 'ProblemGradeDistribution' }) self.assertEqual(response.status_code, 501) @patch.object(instructor.views.api.requests, 'get') def test_analytics_proxy(self, act): """ Test legacy analytics content proxyin, actg. """ act.return_value = self.FakeProxyResponse() url = reverse('proxy_legacy_analytics', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'aname': 'ProblemGradeDistribution' }) self.assertEqual(response.status_code, 200) # check response self.assertTrue(act.called) expected_res = {'test_content': "robot test content"} self.assertEqual(json.loads(response.content), expected_res) @patch.object(instructor.views.api.requests, 'get') def test_analytics_proxy_reqfailed(self, act): """ Test proxy when server reponds with failure. """ act.return_value = self.FakeBadProxyResponse() url = reverse('proxy_legacy_analytics', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'aname': 'ProblemGradeDistribution' }) self.assertEqual(response.status_code, 500) @patch.object(instructor.views.api.requests, 'get') def test_analytics_proxy_missing_param(self, act): """ Test proxy when missing the aname query parameter. """ act.return_value = self.FakeProxyResponse() url = reverse('proxy_legacy_analytics', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {}) self.assertEqual(response.status_code, 400) self.assertFalse(act.called) @attr('shard_1') class TestInstructorAPIHelpers(TestCase): """ Test helpers for instructor.api """ def test_split_input_list(self): strings = [] lists = [] strings.append( "Lorem@ipsum.dolor, sit@amet.consectetur\nadipiscing@elit.Aenean\r convallis@at.lacus\r, ut@lacinia.Sed") lists.append(['Lorem@ipsum.dolor', 'sit@amet.consectetur', 'adipiscing@elit.Aenean', 'convallis@at.lacus', 'ut@lacinia.Sed']) for (stng, lst) in zip(strings, lists): self.assertEqual(_split_input_list(stng), lst) def test_split_input_list_unicode(self): self.assertEqual(_split_input_list('robot@robot.edu, robot2@robot.edu'), ['robot@robot.edu', 'robot2@robot.edu']) self.assertEqual(_split_input_list(u'robot@robot.edu, robot2@robot.edu'), ['robot@robot.edu', 'robot2@robot.edu']) self.assertEqual(_split_input_list(u'robot@robot.edu, robot2@robot.edu'), [u'robot@robot.edu', 'robot2@robot.edu']) scary_unistuff = unichr(40960) + u'abcd' + unichr(1972) self.assertEqual(_split_input_list(scary_unistuff), [scary_unistuff]) def test_msk_from_problem_urlname(self): course_id = SlashSeparatedCourseKey('MITx', '6.002x', '2013_Spring') name = 'L2Node1' output = 'i4x://MITx/6.002x/problem/L2Node1' self.assertEqual(msk_from_problem_urlname(course_id, name).to_deprecated_string(), output) @raises(ValueError) def test_msk_from_problem_urlname_error(self): args = ('notagoodcourse', 'L2Node1') msk_from_problem_urlname(*args) def get_extended_due(course, unit, user): """ Gets the overridden due date for the given user on the given unit. Returns `None` if there is no override set. """ try: override = StudentFieldOverride.objects.get( course_id=course.id, student=user, location=unit.location, field='due' ) return DATE_FIELD.from_json(json.loads(override.value)) except StudentFieldOverride.DoesNotExist: return None @attr('shard_1') class TestDueDateExtensions(ModuleStoreTestCase, LoginEnrollmentTestCase): """ Test data dumps for reporting. """ def setUp(self): """ Fixtures. """ super(TestDueDateExtensions, self).setUp() due = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=utc) course = CourseFactory.create() week1 = ItemFactory.create(due=due) week2 = ItemFactory.create(due=due) week3 = ItemFactory.create() # No due date course.children = [week1.location.to_deprecated_string(), week2.location.to_deprecated_string(), week3.location.to_deprecated_string()] homework = ItemFactory.create( parent_location=week1.location, due=due ) week1.children = [homework.location.to_deprecated_string()] user1 = UserFactory.create() StudentModule( state='{}', student_id=user1.id, course_id=course.id, module_state_key=week1.location).save() StudentModule( state='{}', student_id=user1.id, course_id=course.id, module_state_key=week2.location).save() StudentModule( state='{}', student_id=user1.id, course_id=course.id, module_state_key=week3.location).save() StudentModule( state='{}', student_id=user1.id, course_id=course.id, module_state_key=homework.location).save() user2 = UserFactory.create() StudentModule( state='{}', student_id=user2.id, course_id=course.id, module_state_key=week1.location).save() StudentModule( state='{}', student_id=user2.id, course_id=course.id, module_state_key=homework.location).save() user3 = UserFactory.create() StudentModule( state='{}', student_id=user3.id, course_id=course.id, module_state_key=week1.location).save() StudentModule( state='{}', student_id=user3.id, course_id=course.id, module_state_key=homework.location).save() self.course = course self.week1 = week1 self.homework = homework self.week2 = week2 self.week3 = week3 self.user1 = user1 self.user2 = user2 self.instructor = InstructorFactory(course_key=course.id) self.client.login(username=self.instructor.username, password='test') def test_change_due_date(self): url = reverse('change_due_date', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'student': self.user1.username, 'url': self.week1.location.to_deprecated_string(), 'due_datetime': '12/30/2013 00:00' }) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(datetime.datetime(2013, 12, 30, 0, 0, tzinfo=utc), get_extended_due(self.course, self.week1, self.user1)) def test_change_to_invalid_due_date(self): url = reverse('change_due_date', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'student': self.user1.username, 'url': self.week1.location.to_deprecated_string(), 'due_datetime': '01/01/2009 00:00' }) self.assertEqual(response.status_code, 400, response.content) self.assertEqual( None, get_extended_due(self.course, self.week1, self.user1) ) def test_change_nonexistent_due_date(self): url = reverse('change_due_date', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'student': self.user1.username, 'url': self.week3.location.to_deprecated_string(), 'due_datetime': '12/30/2013 00:00' }) self.assertEqual(response.status_code, 400, response.content) self.assertEqual( None, get_extended_due(self.course, self.week3, self.user1) ) def test_reset_date(self): self.test_change_due_date() url = reverse('reset_due_date', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'student': self.user1.username, 'url': self.week1.location.to_deprecated_string(), }) self.assertEqual(response.status_code, 200, response.content) self.assertEqual( None, get_extended_due(self.course, self.week1, self.user1) ) def test_reset_nonexistent_extension(self): url = reverse('reset_due_date', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'student': self.user1.username, 'url': self.week1.location.to_deprecated_string(), }) self.assertEqual(response.status_code, 400, response.content) def test_reset_extension_to_deleted_date(self): """ Test that we can delete a due date extension after deleting the normal due date, without causing an error. """ self.test_change_due_date() self.week1.due = None self.week1 = self.store.update_item(self.week1, self.user1.id) # Now, week1's normal due date is deleted but the extension still exists. url = reverse('reset_due_date', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, { 'student': self.user1.username, 'url': self.week1.location.to_deprecated_string(), }) self.assertEqual(response.status_code, 200, response.content) self.assertEqual( None, get_extended_due(self.course, self.week1, self.user1) ) def test_show_unit_extensions(self): self.test_change_due_date() url = reverse('show_unit_extensions', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {'url': self.week1.location.to_deprecated_string()}) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(json.loads(response.content), { u'data': [{u'Extended Due Date': u'2013-12-30 00:00', u'Full Name': self.user1.profile.name, u'Username': self.user1.username}], u'header': [u'Username', u'Full Name', u'Extended Due Date'], u'title': u'Users with due date extensions for %s' % self.week1.display_name}) def test_show_student_extensions(self): self.test_change_due_date() url = reverse('show_student_extensions', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.get(url, {'student': self.user1.username}) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(json.loads(response.content), { u'data': [{u'Extended Due Date': u'2013-12-30 00:00', u'Unit': self.week1.display_name}], u'header': [u'Unit', u'Extended Due Date'], u'title': u'Due date extensions for %s (%s)' % ( self.user1.profile.name, self.user1.username)}) @attr('shard_1') @override_settings(REGISTRATION_CODE_LENGTH=8) class TestCourseRegistrationCodes(ModuleStoreTestCase): """ Test data dumps for E-commerce Course Registration Codes. """ def setUp(self): """ Fixtures. """ super(TestCourseRegistrationCodes, self).setUp() self.course = CourseFactory.create() CourseModeFactory.create(course_id=self.course.id, min_price=50) self.instructor = InstructorFactory(course_key=self.course.id) self.client.login(username=self.instructor.username, password='test') CourseSalesAdminRole(self.course.id).add_users(self.instructor) url = reverse('generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()}) data = { 'total_registration_codes': 12, 'company_name': 'Test Group', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 122.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': '' } response = self.client.post(url, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) for i in range(5): order = Order(user=self.instructor, status='purchased') order.save() # Spent(used) Registration Codes for i in range(5): i += 1 registration_code_redemption = RegistrationCodeRedemption( registration_code_id=i, redeemed_by=self.instructor ) registration_code_redemption.save() @override_settings(FINANCE_EMAIL='finance@example.com') def test_finance_email_in_recipient_list_when_generating_registration_codes(self): """ Test to verify that the invoice will also be sent to the FINANCE_EMAIL when generating registration codes """ url_reg_code = reverse('generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()}) data = { 'total_registration_codes': 5, 'company_name': 'Group Alpha', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 121.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': 'True' } response = self.client.post(url_reg_code, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') # check for the last mail.outbox, The FINANCE_EMAIL has been appended at the # very end, when generating registration codes self.assertEqual(mail.outbox[-1].to[0], 'finance@example.com') def test_user_invoice_copy_preference(self): """ Test to remember user invoice copy preference """ url_reg_code = reverse('generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()}) data = { 'total_registration_codes': 5, 'company_name': 'Group Alpha', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 121.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': 'True' } # user invoice copy preference will be saved in api user preference; model response = self.client.post(url_reg_code, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') # get user invoice copy preference. url_user_invoice_preference = reverse('get_user_invoice_preference', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url_user_invoice_preference, data) result = json.loads(response.content) self.assertEqual(result['invoice_copy'], True) # updating the user invoice copy preference during code generation flow data['invoice'] = '' response = self.client.post(url_reg_code, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') # get user invoice copy preference. url_user_invoice_preference = reverse('get_user_invoice_preference', kwargs={'course_id': self.course.id.to_deprecated_string()}) response = self.client.post(url_user_invoice_preference, data) result = json.loads(response.content) self.assertEqual(result['invoice_copy'], False) def test_generate_course_registration_codes_csv(self): """ Test to generate a response of all the generated course registration codes """ url = reverse('generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()}) data = { 'total_registration_codes': 15, 'company_name': 'Group Alpha', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 122.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': '' } response = self.client.post(url, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) self.assertEqual(len(body.split('\n')), 17) def test_generate_course_registration_with_redeem_url_codes_csv(self): """ Test to generate a response of all the generated course registration codes """ url = reverse('generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()}) data = { 'total_registration_codes': 15, 'company_name': 'Group Alpha', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 122.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': '' } response = self.client.post(url, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) self.assertEqual(len(body.split('\n')), 17) rows = body.split('\n') index = 1 while index < len(rows): if rows[index]: row_data = rows[index].split(',') code = row_data[0].replace('"', '') self.assertTrue(row_data[1].startswith('"http') and row_data[1].endswith('/shoppingcart/register/redeem/{0}/"'.format(code))) index += 1 @patch.object(instructor.views.api, 'random_code_generator', Mock(side_effect=['first', 'second', 'third', 'fourth'])) def test_generate_course_registration_codes_matching_existing_coupon_code(self): """ Test the generated course registration code is already in the Coupon Table """ url = reverse('generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()}) coupon = Coupon(code='first', course_id=self.course.id.to_deprecated_string(), created_by=self.instructor) coupon.save() data = { 'total_registration_codes': 3, 'company_name': 'Group Alpha', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 122.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': '' } response = self.client.post(url, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) self.assertEqual(len(body.split('\n')), 5) # 1 for headers, 1 for new line at the end and 3 for the actual data @patch.object(instructor.views.api, 'random_code_generator', Mock(side_effect=['first', 'first', 'second', 'third'])) def test_generate_course_registration_codes_integrity_error(self): """ Test for the Integrity error against the generated code """ url = reverse('generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()}) data = { 'total_registration_codes': 2, 'company_name': 'Test Group', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 122.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': '' } response = self.client.post(url, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) self.assertEqual(len(body.split('\n')), 4) def test_spent_course_registration_codes_csv(self): """ Test to generate a response of all the spent course registration codes """ url = reverse('spent_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()}) data = {'spent_company_name': ''} response = self.client.post(url, data) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) self.assertEqual(len(body.split('\n')), 7) generate_code_url = reverse( 'generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()} ) data = { 'total_registration_codes': 9, 'company_name': 'Group Alpha', 'company_contact_name': 'Test@company.com', 'unit_price': 122.45, 'company_contact_email': 'Test@company.com', 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': '' } response = self.client.post(generate_code_url, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) for i in range(9): order = Order(user=self.instructor, status='purchased') order.save() # Spent(used) Registration Codes for i in range(9): i += 13 registration_code_redemption = RegistrationCodeRedemption( registration_code_id=i, redeemed_by=self.instructor ) registration_code_redemption.save() data = {'spent_company_name': 'Group Alpha'} response = self.client.post(url, data) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) self.assertEqual(len(body.split('\n')), 11) def test_active_course_registration_codes_csv(self): """ Test to generate a response of all the active course registration codes """ url = reverse('active_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()}) data = {'active_company_name': ''} response = self.client.post(url, data) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) self.assertEqual(len(body.split('\n')), 9) generate_code_url = reverse( 'generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()} ) data = { 'total_registration_codes': 9, 'company_name': 'Group Alpha', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 122.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': '' } response = self.client.post(generate_code_url, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) data = {'active_company_name': 'Group Alpha'} response = self.client.post(url, data) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) self.assertEqual(len(body.split('\n')), 11) def test_get_all_course_registration_codes_csv(self): """ Test to generate a response of all the course registration codes """ url = reverse( 'get_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()} ) data = {'download_company_name': ''} response = self.client.post(url, data) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) self.assertEqual(len(body.split('\n')), 14) generate_code_url = reverse( 'generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()} ) data = { 'total_registration_codes': 9, 'company_name': 'Group Alpha', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 122.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': '' } response = self.client.post(generate_code_url, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) data = {'download_company_name': 'Group Alpha'} response = self.client.post(url, data) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) self.assertEqual(len(body.split('\n')), 11) def test_pdf_file_throws_exception(self): """ test to mock the pdf file generation throws an exception when generating registration codes. """ generate_code_url = reverse( 'generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()} ) data = { 'total_registration_codes': 9, 'company_name': 'Group Alpha', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 122.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': '' } with patch.object(PDFInvoice, 'generate_pdf', side_effect=Exception): response = self.client.post(generate_code_url, data) self.assertEqual(response.status_code, 200, response.content) def test_get_codes_with_sale_invoice(self): """ Test to generate a response of all the course registration codes """ generate_code_url = reverse( 'generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()} ) data = { 'total_registration_codes': 5.5, 'company_name': 'Group Invoice', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 122.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': True } response = self.client.post(generate_code_url, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 200, response.content) url = reverse('get_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()}) data = {'download_company_name': 'Group Invoice'} response = self.client.post(url, data) self.assertEqual(response.status_code, 200, response.content) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_CSV_HEADER)) def test_with_invalid_unit_price(self): """ Test to generate a response of all the course registration codes """ generate_code_url = reverse( 'generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()} ) data = { 'total_registration_codes': 10, 'company_name': 'Group Invoice', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 'invalid', 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': True } response = self.client.post(generate_code_url, data, **{'HTTP_HOST': 'localhost'}) self.assertEqual(response.status_code, 400, response.content) self.assertIn('Could not parse amount as', response.content) def test_get_historical_coupon_codes(self): """ Test to download a response of all the active coupon codes """ get_coupon_code_url = reverse( 'get_coupon_codes', kwargs={'course_id': self.course.id.to_deprecated_string()} ) for i in range(10): coupon = Coupon( code='test_code{0}'.format(i), description='test_description', course_id=self.course.id, percentage_discount='{0}'.format(i), created_by=self.instructor, is_active=True ) coupon.save() #now create coupons with the expiration dates for i in range(5): coupon = Coupon( code='coupon{0}'.format(i), description='test_description', course_id=self.course.id, percentage_discount='{0}'.format(i), created_by=self.instructor, is_active=True, expiration_date=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=2) ) coupon.save() response = self.client.get(get_coupon_code_url) self.assertEqual(response.status_code, 200, response.content) # filter all the coupons for coupon in Coupon.objects.all(): self.assertIn( '"{coupon_code}","{course_id}","{discount}","{description}","{expiration_date}","{is_active}",' '"{code_redeemed_count}","{total_discounted_seats}","{total_discounted_amount}"'.format( coupon_code=coupon.code, course_id=coupon.course_id, discount=coupon.percentage_discount, description=coupon.description, expiration_date=coupon.display_expiry_date, is_active=coupon.is_active, code_redeemed_count="0", total_discounted_seats="0", total_discounted_amount="0", ), response.content ) self.assertEqual(response['Content-Type'], 'text/csv') body = response.content.replace('\r', '') self.assertTrue(body.startswith(EXPECTED_COUPON_CSV_HEADER)) @attr('shard_1') class TestBulkCohorting(ModuleStoreTestCase): """ Test adding users to cohorts in bulk via CSV upload. """ def setUp(self): super(TestBulkCohorting, self).setUp() self.course = CourseFactory.create() self.staff_user = StaffFactory(course_key=self.course.id) self.non_staff_user = UserFactory.create() self.tempdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.tempdir) def call_add_users_to_cohorts(self, csv_data, suffix='.csv', method='POST'): """ Call `add_users_to_cohorts` with a file generated from `csv_data`. """ # this temporary file will be removed in `self.tearDown()` __, file_name = tempfile.mkstemp(suffix=suffix, dir=self.tempdir) with open(file_name, 'w') as file_pointer: file_pointer.write(csv_data.encode('utf-8')) with open(file_name, 'r') as file_pointer: url = reverse('add_users_to_cohorts', kwargs={'course_id': unicode(self.course.id)}) if method == 'POST': return self.client.post(url, {'uploaded-file': file_pointer}) elif method == 'GET': return self.client.get(url, {'uploaded-file': file_pointer}) def expect_error_on_file_content(self, file_content, error, file_suffix='.csv'): """ Verify that we get the error we expect for a given file input. """ self.client.login(username=self.staff_user.username, password='test') response = self.call_add_users_to_cohorts(file_content, suffix=file_suffix) self.assertEqual(response.status_code, 400) result = json.loads(response.content) self.assertEqual(result['error'], error) def verify_success_on_file_content(self, file_content, mock_store_upload, mock_cohort_task): """ Verify that `addd_users_to_cohorts` successfully validates the file content, uploads the input file, and triggers the background task. """ mock_store_upload.return_value = (None, 'fake_file_name.csv') self.client.login(username=self.staff_user.username, password='test') response = self.call_add_users_to_cohorts(file_content) self.assertEqual(response.status_code, 204) self.assertTrue(mock_store_upload.called) self.assertTrue(mock_cohort_task.called) def test_no_cohort_field(self): """ Verify that we get a descriptive verification error when we haven't included a cohort field in the uploaded CSV. """ self.expect_error_on_file_content( 'username,email\n', "The file must contain a 'cohort' column containing cohort names." ) def test_no_username_or_email_field(self): """ Verify that we get a descriptive verification error when we haven't included a username or email field in the uploaded CSV. """ self.expect_error_on_file_content( 'cohort\n', "The file must contain a 'username' column, an 'email' column, or both." ) def test_empty_csv(self): """ Verify that we get a descriptive verification error when we haven't included any data in the uploaded CSV. """ self.expect_error_on_file_content( '', "The file must contain a 'cohort' column containing cohort names." ) def test_wrong_extension(self): """ Verify that we get a descriptive verification error when we haven't uploaded a file with a '.csv' extension. """ self.expect_error_on_file_content( '', "The file must end with the extension '.csv'.", file_suffix='.notcsv' ) def test_non_staff_no_access(self): """ Verify that we can't access the view when we aren't a staff user. """ self.client.login(username=self.non_staff_user.username, password='test') response = self.call_add_users_to_cohorts('') self.assertEqual(response.status_code, 403) def test_post_only(self): """ Verify that we can't call the view when we aren't using POST. """ self.client.login(username=self.staff_user.username, password='test') response = self.call_add_users_to_cohorts('', method='GET') self.assertEqual(response.status_code, 405) @patch('instructor.views.api.instructor_task.api.submit_cohort_students') @patch('instructor.views.api.store_uploaded_file') def test_success_username(self, mock_store_upload, mock_cohort_task): """ Verify that we store the input CSV and call a background task when the CSV has username and cohort columns. """ self.verify_success_on_file_content( 'username,cohort\nfoo_username,bar_cohort', mock_store_upload, mock_cohort_task ) @patch('instructor.views.api.instructor_task.api.submit_cohort_students') @patch('instructor.views.api.store_uploaded_file') def test_success_email(self, mock_store_upload, mock_cohort_task): """ Verify that we store the input CSV and call the cohorting background task when the CSV has email and cohort columns. """ self.verify_success_on_file_content( 'email,cohort\nfoo_email,bar_cohort', mock_store_upload, mock_cohort_task ) @patch('instructor.views.api.instructor_task.api.submit_cohort_students') @patch('instructor.views.api.store_uploaded_file') def test_success_username_and_email(self, mock_store_upload, mock_cohort_task): """ Verify that we store the input CSV and call the cohorting background task when the CSV has username, email and cohort columns. """ self.verify_success_on_file_content( 'username,email,cohort\nfoo_username,bar_email,baz_cohort', mock_store_upload, mock_cohort_task ) @patch('instructor.views.api.instructor_task.api.submit_cohort_students') @patch('instructor.views.api.store_uploaded_file') def test_success_carriage_return(self, mock_store_upload, mock_cohort_task): """ Verify that we store the input CSV and call the cohorting background task when lines in the CSV are delimited by carriage returns. """ self.verify_success_on_file_content( 'username,email,cohort\rfoo_username,bar_email,baz_cohort', mock_store_upload, mock_cohort_task ) @patch('instructor.views.api.instructor_task.api.submit_cohort_students') @patch('instructor.views.api.store_uploaded_file') def test_success_carriage_return_line_feed(self, mock_store_upload, mock_cohort_task): """ Verify that we store the input CSV and call the cohorting background task when lines in the CSV are delimited by carriage returns and line feeds. """ self.verify_success_on_file_content( 'username,email,cohort\r\nfoo_username,bar_email,baz_cohort', mock_store_upload, mock_cohort_task )
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 199, 5072, 2295, 367, 17724, 14, 1246, 3102, 14, 199, 624, 199, 646, 2197, 199, 646, 366, 3583, 199, 646, 2196, 199, 646, 15444, 199, 646, 5890, 199, 646, 2022, 199, 646, 4145, 199, 646, 5145, 199, 646, 5549, 199, 504, 4011, 492, 6313, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 2828, 14, 1178, 14, 992, 492, 2876, 199, 504, 1639, 14, 1018, 492, 6016, 199, 504, 1639, 14, 1018, 14, 1725, 14, 19044, 493, 492, 5870, 24665, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 14, 1014, 492, 20730, 12, 6183, 199, 504, 1639, 14, 396, 492, 18638, 12, 7640, 199, 504, 1639, 14, 396, 14, 1208, 492, 4278, 63, 1751, 199, 504, 1639, 14, 1208, 14, 7145, 492, 19314, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 465, 485, 199, 199, 504, 1683, 492, 4420, 12, 3371, 199, 504, 11354, 14, 2537, 492, 6534, 199, 504, 11354, 14, 5265, 14, 6640, 492, 1921, 199, 504, 15058, 63, 1612, 14, 8268, 14, 8022, 492, 30687, 199, 199, 504, 2518, 63, 10433, 14, 992, 492, 27312, 199, 504, 20736, 14, 992, 492, 17246, 2377, 199, 504, 20736, 14, 2219, 14, 15406, 492, 25910, 2927, 12, 26150, 2927, 12, 29521, 22403, 2927, 12, 19037, 2927, 199, 504, 20736, 14, 2219, 14, 7546, 492, 16430, 13842, 1746, 199, 504, 1639, 63, 3349, 63, 2330, 14, 992, 492, 2381, 2639, 63, 15468, 63, 5378, 1734, 1922, 63, 6166, 199, 504, 1639, 63, 3349, 63, 2330, 14, 1208, 492, 6347, 63, 6060, 63, 8050, 199, 504, 30489, 63, 4758, 492, 30489, 199, 504, 25630, 4073, 8153, 14, 992, 492, 334, 272, 20764, 3034, 497, 271, 25424, 12, 9240, 12, 1849, 13527, 497, 271, 25424, 12, 272, 10164, 344, 6979, 11757, 12, 1849, 13527, 12, 19868, 12, 5531, 11757, 3034, 12, 5531, 11757, 3034, 21092, 2081, 12, 272, 19868, 10161, 9, 199, 504, 25630, 4073, 8153, 14, 5607, 492, 15537, 21092, 199, 504, 6474, 14, 992, 492, 334, 272, 18946, 12, 18946, 16070, 12, 10172, 920, 13298, 6979, 547, 12, 272, 30247, 13842, 23601, 12, 6778, 742, 6245, 5290, 63, 2566, 63, 742, 6245, 5290, 12, 5070, 6245, 5290, 63, 2566, 63, 1734, 742, 6245, 5290, 12, 272, 27805, 1149, 2566, 742, 14881, 63, 2566, 63, 1734, 742, 6245, 5290, 12, 5070, 6245, 5290, 63, 2566, 63, 742, 6245, 5290, 12, 6778, 742, 6245, 5290, 63, 2566, 63, 17350, 2566, 742, 14881, 12, 272, 6778, 742, 6245, 5290, 63, 2566, 63, 1734, 742, 6245, 5290, 12, 27805, 1149, 2566, 742, 14881, 63, 2566, 63, 742, 6245, 5290, 199, 9, 199, 504, 6474, 14, 2219, 14, 15406, 492, 16047, 12, 27312, 2927, 12, 9516, 2927, 199, 504, 6474, 14, 8050, 492, 5531, 21732, 22403, 7422, 12, 5531, 18220, 4880, 7422, 12, 5531, 8694, 554, 4880, 7422, 12, 5531, 30742, 7422, 199, 504, 9872, 14, 10012, 492, 23431, 199, 504, 9872, 14, 10012, 14, 1176, 492, 10996, 199, 504, 9872, 14, 10012, 14, 2219, 14, 1176, 63, 1208, 492, 17996, 1746, 199, 504, 9872, 14, 10012, 14, 2219, 14, 15406, 492, 17862, 12, 19319, 199, 504, 9872, 14, 955, 492, 6148, 199, 199, 504, 20736, 14, 992, 492, 17246, 792, 11954, 199, 199, 646, 17724, 63, 1765, 14, 1246, 199, 646, 17724, 14, 4196, 14, 1246, 199, 504, 17724, 14, 4196, 14, 1246, 492, 4409, 63, 2408, 554, 63, 2113, 199, 504, 17724, 14, 2219, 14, 1208, 492, 7777, 2714, 4476, 12, 7777, 7035, 12, 7777, 7035, 2354, 199, 504, 17724, 14, 4196, 14, 1246, 492, 3550, 63, 3235, 63, 2060, 199, 504, 17724, 14, 4196, 14, 1246, 492, 485, 1294, 63, 1210, 63, 513, 12, 2863, 63, 3924, 63, 5303, 199, 504, 17724, 63, 1765, 14, 1246, 63, 3676, 492, 21086, 9602, 547, 199, 199, 504, 22709, 14, 1018, 14, 16432, 14, 1972, 63, 2634, 14, 10403, 83, 492, 663, 63, 1972, 63, 10403, 63, 1751, 199, 199, 504, 1275, 396, 63, 2537, 492, 333, 1339, 63, 504, 63, 6462, 63, 633, 354, 199, 199, 5390, 63, 8609, 275, 6148, 342, 199, 22358, 63, 19018, 63, 7311, 275, 334, 272, 5522, 600, 2266, 21919, 5633, 63, 600, 63, 633, 2266, 1972, 63, 344, 2266, 4627, 63, 354, 2266, 3966, 63, 991, 2266, 264, 11192, 3594, 63, 991, 2266, 5404, 63, 344, 2266, 6653, 9518, 332, 21891, 272, 5522, 10178, 63, 4443, 63, 1955, 2266, 4672, 63, 4443, 4507, 199, 9, 199, 22358, 63, 1439, 2160, 615, 63, 19018, 63, 7311, 275, 5522, 967, 13527, 5495, 2266, 6979, 15418, 11890, 5289, 835, 2266, 5831, 2266, 14000, 1754, 6148, 21891, 971, 2490, 5522, 1831, 23241, 2266, 3034, 799, 11192, 3594, 14826, 2266, 7316, 5289, 3094, 471, 3240, 1956, 2266, 7316, 5289, 3094, 471, 26701, 4507, 199, 199, 3, 366, 3583, 666, 367, 511, 5560, 25613, 4007, 13924, 199, 17356, 51, 63, 3998, 275, 334, 272, 469, 267, 283, 3070, 63, 466, 356, 283, 4523, 297, 267, 283, 14891, 63, 1246, 63, 6520, 356, 283, 12063, 63, 18050, 63, 4737, 297, 267, 283, 1765, 63, 1246, 63, 6520, 356, 283, 14891, 63, 1765, 14, 1246, 14, 7275, 63, 12063, 63, 18050, 63, 4737, 297, 267, 283, 2911, 63, 14891, 63, 1246, 63, 958, 356, 1052, 272, 1660, 272, 469, 267, 283, 3070, 63, 466, 356, 283, 22428, 6474, 4690, 297, 267, 283, 14891, 63, 1246, 63, 6520, 356, 283, 362, 63, 17921, 63, 3179, 297, 267, 283, 1765, 63, 1246, 63, 6520, 356, 283, 14891, 63, 1765, 14, 1246, 14, 7275, 63, 12063, 63, 17921, 63, 3179, 63, 4737, 297, 267, 283, 2911, 63, 14891, 63, 1246, 63, 958, 356, 791, 4737, 356, 1994, 4737, 936, 272, 1660, 272, 469, 267, 283, 3070, 63, 466, 356, 283, 19170, 14869, 297, 267, 283, 14891, 63, 1246, 63, 6520, 356, 283, 362, 63, 12214, 63, 3070, 297, 267, 283, 1765, 63, 1246, 63, 6520, 356, 283, 14891, 63, 1765, 14, 1246, 14, 7275, 63, 19170, 63, 12214, 63, 3179, 63, 4737, 297, 267, 283, 2911, 63, 14891, 63, 1246, 63, 958, 356, 1052, 272, 1660, 272, 469, 267, 283, 3070, 63, 466, 356, 283, 17921 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 199, 5072, 2295, 367, 17724, 14, 1246, 3102, 14, 199, 624, 199, 646, 2197, 199, 646, 366, 3583, 199, 646, 2196, 199, 646, 15444, 199, 646, 5890, 199, 646, 2022, 199, 646, 4145, 199, 646, 5145, 199, 646, 5549, 199, 504, 4011, 492, 6313, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 2828, 14, 1178, 14, 992, 492, 2876, 199, 504, 1639, 14, 1018, 492, 6016, 199, 504, 1639, 14, 1018, 14, 1725, 14, 19044, 493, 492, 5870, 24665, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 14, 1014, 492, 20730, 12, 6183, 199, 504, 1639, 14, 396, 492, 18638, 12, 7640, 199, 504, 1639, 14, 396, 14, 1208, 492, 4278, 63, 1751, 199, 504, 1639, 14, 1208, 14, 7145, 492, 19314, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 465, 485, 199, 199, 504, 1683, 492, 4420, 12, 3371, 199, 504, 11354, 14, 2537, 492, 6534, 199, 504, 11354, 14, 5265, 14, 6640, 492, 1921, 199, 504, 15058, 63, 1612, 14, 8268, 14, 8022, 492, 30687, 199, 199, 504, 2518, 63, 10433, 14, 992, 492, 27312, 199, 504, 20736, 14, 992, 492, 17246, 2377, 199, 504, 20736, 14, 2219, 14, 15406, 492, 25910, 2927, 12, 26150, 2927, 12, 29521, 22403, 2927, 12, 19037, 2927, 199, 504, 20736, 14, 2219, 14, 7546, 492, 16430, 13842, 1746, 199, 504, 1639, 63, 3349, 63, 2330, 14, 992, 492, 2381, 2639, 63, 15468, 63, 5378, 1734, 1922, 63, 6166, 199, 504, 1639, 63, 3349, 63, 2330, 14, 1208, 492, 6347, 63, 6060, 63, 8050, 199, 504, 30489, 63, 4758, 492, 30489, 199, 504, 25630, 4073, 8153, 14, 992, 492, 334, 272, 20764, 3034, 497, 271, 25424, 12, 9240, 12, 1849, 13527, 497, 271, 25424, 12, 272, 10164, 344, 6979, 11757, 12, 1849, 13527, 12, 19868, 12, 5531, 11757, 3034, 12, 5531, 11757, 3034, 21092, 2081, 12, 272, 19868, 10161, 9, 199, 504, 25630, 4073, 8153, 14, 5607, 492, 15537, 21092, 199, 504, 6474, 14, 992, 492, 334, 272, 18946, 12, 18946, 16070, 12, 10172, 920, 13298, 6979, 547, 12, 272, 30247, 13842, 23601, 12, 6778, 742, 6245, 5290, 63, 2566, 63, 742, 6245, 5290, 12, 5070, 6245, 5290, 63, 2566, 63, 1734, 742, 6245, 5290, 12, 272, 27805, 1149, 2566, 742, 14881, 63, 2566, 63, 1734, 742, 6245, 5290, 12, 5070, 6245, 5290, 63, 2566, 63, 742, 6245, 5290, 12, 6778, 742, 6245, 5290, 63, 2566, 63, 17350, 2566, 742, 14881, 12, 272, 6778, 742, 6245, 5290, 63, 2566, 63, 1734, 742, 6245, 5290, 12, 27805, 1149, 2566, 742, 14881, 63, 2566, 63, 742, 6245, 5290, 199, 9, 199, 504, 6474, 14, 2219, 14, 15406, 492, 16047, 12, 27312, 2927, 12, 9516, 2927, 199, 504, 6474, 14, 8050, 492, 5531, 21732, 22403, 7422, 12, 5531, 18220, 4880, 7422, 12, 5531, 8694, 554, 4880, 7422, 12, 5531, 30742, 7422, 199, 504, 9872, 14, 10012, 492, 23431, 199, 504, 9872, 14, 10012, 14, 1176, 492, 10996, 199, 504, 9872, 14, 10012, 14, 2219, 14, 1176, 63, 1208, 492, 17996, 1746, 199, 504, 9872, 14, 10012, 14, 2219, 14, 15406, 492, 17862, 12, 19319, 199, 504, 9872, 14, 955, 492, 6148, 199, 199, 504, 20736, 14, 992, 492, 17246, 792, 11954, 199, 199, 646, 17724, 63, 1765, 14, 1246, 199, 646, 17724, 14, 4196, 14, 1246, 199, 504, 17724, 14, 4196, 14, 1246, 492, 4409, 63, 2408, 554, 63, 2113, 199, 504, 17724, 14, 2219, 14, 1208, 492, 7777, 2714, 4476, 12, 7777, 7035, 12, 7777, 7035, 2354, 199, 504, 17724, 14, 4196, 14, 1246, 492, 3550, 63, 3235, 63, 2060, 199, 504, 17724, 14, 4196, 14, 1246, 492, 485, 1294, 63, 1210, 63, 513, 12, 2863, 63, 3924, 63, 5303, 199, 504, 17724, 63, 1765, 14, 1246, 63, 3676, 492, 21086, 9602, 547, 199, 199, 504, 22709, 14, 1018, 14, 16432, 14, 1972, 63, 2634, 14, 10403, 83, 492, 663, 63, 1972, 63, 10403, 63, 1751, 199, 199, 504, 1275, 396, 63, 2537, 492, 333, 1339, 63, 504, 63, 6462, 63, 633, 354, 199, 199, 5390, 63, 8609, 275, 6148, 342, 199, 22358, 63, 19018, 63, 7311, 275, 334, 272, 5522, 600, 2266, 21919, 5633, 63, 600, 63, 633, 2266, 1972, 63, 344, 2266, 4627, 63, 354, 2266, 3966, 63, 991, 2266, 264, 11192, 3594, 63, 991, 2266, 5404, 63, 344, 2266, 6653, 9518, 332, 21891, 272, 5522, 10178, 63, 4443, 63, 1955, 2266, 4672, 63, 4443, 4507, 199, 9, 199, 22358, 63, 1439, 2160, 615, 63, 19018, 63, 7311, 275, 5522, 967, 13527, 5495, 2266, 6979, 15418, 11890, 5289, 835, 2266, 5831, 2266, 14000, 1754, 6148, 21891, 971, 2490, 5522, 1831, 23241, 2266, 3034, 799, 11192, 3594, 14826, 2266, 7316, 5289, 3094, 471, 3240, 1956, 2266, 7316, 5289, 3094, 471, 26701, 4507, 199, 199, 3, 366, 3583, 666, 367, 511, 5560, 25613, 4007, 13924, 199, 17356, 51, 63, 3998, 275, 334, 272, 469, 267, 283, 3070, 63, 466, 356, 283, 4523, 297, 267, 283, 14891, 63, 1246, 63, 6520, 356, 283, 12063, 63, 18050, 63, 4737, 297, 267, 283, 1765, 63, 1246, 63, 6520, 356, 283, 14891, 63, 1765, 14, 1246, 14, 7275, 63, 12063, 63, 18050, 63, 4737, 297, 267, 283, 2911, 63, 14891, 63, 1246, 63, 958, 356, 1052, 272, 1660, 272, 469, 267, 283, 3070, 63, 466, 356, 283, 22428, 6474, 4690, 297, 267, 283, 14891, 63, 1246, 63, 6520, 356, 283, 362, 63, 17921, 63, 3179, 297, 267, 283, 1765, 63, 1246, 63, 6520, 356, 283, 14891, 63, 1765, 14, 1246, 14, 7275, 63, 12063, 63, 17921, 63, 3179, 63, 4737, 297, 267, 283, 2911, 63, 14891, 63, 1246, 63, 958, 356, 791, 4737, 356, 1994, 4737, 936, 272, 1660, 272, 469, 267, 283, 3070, 63, 466, 356, 283, 19170, 14869, 297, 267, 283, 14891, 63, 1246, 63, 6520, 356, 283, 362, 63, 12214, 63, 3070, 297, 267, 283, 1765, 63, 1246, 63, 6520, 356, 283, 14891, 63, 1765, 14, 1246, 14, 7275, 63, 19170, 63, 12214, 63, 3179, 63, 4737, 297, 267, 283, 2911, 63, 14891, 63, 1246, 63, 958, 356, 1052, 272, 1660, 272, 469, 267, 283, 3070, 63, 466, 356, 283, 17921, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
TerraFERMA/TerraFERMA
buckettools/python/buckettools/diagnostics/filehandling.py
1
6629
# This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # (originally part of fluidity, modified for buckettools by Cian Wilson) # Copyright (C) 2013 Columbia University in the City of New York and others. # # Please see the AUTHORS file in the main source directory for a full list # of contributors. # # This file is part of TerraFERMA. # # TerraFERMA is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # TerraFERMA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with TerraFERMA. If not, see <http://www.gnu.org/licenses/>. """ File handling routines """ import glob import os import shutil import subprocess import stat import tempfile import unittest import buckettools.diagnostics.debug as debug import buckettools.diagnostics.utils as utils def FileExtension(filename): """ Return the file extension of the supplied filename (including the ".") """ split = os.path.basename(filename).split(".") if len(split) == 1: return "" else: return "." + split[-1] def StripFileExtension(filename): """ Strip the file extension from the supplied filename """ split = os.path.basename(filename).split(".") if len(split) == 1: return filename else: return os.path.join(os.path.dirname(filename), utils.FormLine(split[:-1], delimiter = ".", newline = False)) def Touch(filename): """ Update timestamp for given file (or create it if it doesn't exist) """ if FileExists(filename): os.utime(filename, None) else: fileHandle = open(filename, "w") fileHandle.flush() fileHandle.close() return def Mkdir(path, parents = False): """ Create a directory at the specified path. Make all parents if parents is True. """ if parents: parentPath = "" for dir in path.split(os.path.sep): parentPath = os.path.join(parentPath, dir) Mkdir(parentPath, parents = False) else: if not FileExists(path) or not Isdir(path): os.mkdir(path) return def Cp(donor, target): """ Copy a file """ shutil.copy(donor, target) return def Move(donor, target): """ Move a file """ shutil.move(donor, target) return def FileExists(filename): """ Return whether the supplied file exists """ try: os.stat(filename) return True except OSError: return False def IsExecutable(filename): """ Return whether the supplied file exists and is executable """ if not FileExists(filename): return False else: return os.access(filename, os.X_OK) def Isdir(path): """ Return whether the supplied path represents a directory """ return stat.S_ISDIR(os.stat(path)[0]) def Rm(path): """ Delete the file at the specified path """ os.remove(path) return def Rmdir(path, force = False): """ Delete the directory at the specified path. Include all of its contents if force is True. """ if force: for file in glob.glob(os.path.join(path, "*")): if Isdir(file): Rmdir(file) else: Rm(file) os.rmdir(path) return def FindAndReplace(filename, find, replace): """ Find and replace text in the supplied file """ # Could do this out-of-core inputHandle = open(filename, "r") inputString = inputHandle.read() inputHandle.close() inputString = inputString.replace(find, replace) outputHandle = open(filename, "w") outputHandle.write(inputString) outputHandle.close() return class filehandlingUnittests(unittest.TestCase): def testFileExtension(self): self.assertEquals(FileExtension("a.b"), ".b") self.assertEquals(FileExtension("/one/two.three.four"), ".four") self.assertEquals(FileExtension("a"), "") self.assertEquals(FileExtension("../one.two"), ".two") return def testStripFileExtension(self): self.assertEquals(StripFileExtension("a.b"), "a") self.assertEquals(StripFileExtension("/one/two.three.four"), "/one/two.three") self.assertEquals(StripFileExtension("a"), "a") self.assertEquals(StripFileExtension("../one.two"), "../one") return def testTouch(self): tempDir = tempfile.mkdtemp() tempFile = os.path.join(tempDir, "test") self.assertFalse(FileExists(tempFile)) Touch(tempFile) self.assertTrue(FileExists(tempFile)) Rmdir(tempDir, force = True) return def testIsExecutable(self): self.assertTrue(FileExists(__file__)) self.assertFalse(IsExecutable(__file__)) tempDir = tempfile.mkdtemp() tempFile = os.path.join(tempDir, "test") Touch(tempFile) self.assertTrue(FileExists(tempFile)) self.assertFalse(IsExecutable(tempFile)) os.chmod(tempFile, stat.S_IXUSR) self.assertTrue(FileExists(tempFile)) self.assertTrue(IsExecutable(tempFile)) Rmdir(tempDir, force = True) return def testFileExists(self): self.assertTrue(FileExists(__file__)) return def testIsdir(self): tempDir = tempfile.mkdtemp() self.assertTrue(Isdir(tempDir)) Rmdir(tempDir, force = True) fileOsHandle, tempFile = tempfile.mkstemp() self.assertFalse(Isdir(tempFile)) os.close(fileOsHandle) Rm(tempFile) return def testRmdir(self): tempDir = tempfile.mkdtemp() fileHandle = open(os.path.join(tempDir, "tempfile"), "w") fileHandle.close() os.mkdir(os.path.join(tempDir, "tempdir")) Rmdir(tempDir, force = True) self.assertFalse(FileExists(tempDir)) return
lgpl-3.0
[ 3, 961, 3555, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 199, 3, 1015, 499, 14, 17, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 221, 199, 3, 961, 3555, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 221, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 3180, 543, 642, 3555, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 221, 11315, 13, 10067, 221, 8217, 199, 199, 3, 334, 6493, 1183, 1777, 402, 2717, 1907, 328, 369, 12, 6042, 367, 5315, 2537, 701, 445, 5653, 644, 382, 834, 9, 199, 199, 3, 1898, 334, 35, 9, 6171, 3626, 4295, 4674, 15904, 315, 314, 14753, 402, 7053, 1488, 4708, 436, 11789, 14, 199, 3, 199, 3, 7754, 1937, 314, 10610, 570, 315, 314, 2446, 1350, 2082, 367, 282, 2615, 769, 199, 3, 402, 8417, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 13861, 345, 15849, 2054, 14, 199, 3, 199, 3, 13861, 345, 15849, 2054, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 13861, 345, 15849, 2054, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 1666, 314, 199, 3, 1664, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 844, 199, 3, 3180, 543, 13861, 345, 15849, 2054, 14, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 421, 199, 624, 199, 1173, 7252, 14975, 199, 624, 199, 199, 646, 5739, 199, 646, 747, 199, 646, 5145, 199, 646, 3873, 199, 646, 5672, 199, 646, 5549, 199, 646, 2882, 199, 199, 646, 5315, 2537, 14, 6706, 21204, 14, 1757, 465, 3105, 199, 646, 5315, 2537, 14, 6706, 21204, 14, 1208, 465, 3778, 199, 199, 318, 3814, 6382, 8, 1501, 304, 523, 408, 523, 1432, 314, 570, 3329, 402, 314, 6841, 1788, 334, 15768, 314, 298, 2685, 523, 408, 819, 3715, 275, 747, 14, 515, 14, 4846, 8, 1501, 680, 1294, 15857, 12244, 340, 822, 8, 1294, 9, 508, 413, 26, 272, 372, 3087, 523, 587, 26, 272, 372, 14530, 435, 3715, 1988, 17, 61, 199, 199, 318, 19828, 1173, 6382, 8, 1501, 304, 523, 408, 523, 19828, 314, 570, 3329, 687, 314, 6841, 1788, 523, 408, 819, 3715, 275, 747, 14, 515, 14, 4846, 8, 1501, 680, 1294, 15857, 12244, 340, 822, 8, 1294, 9, 508, 413, 26, 272, 372, 1788, 523, 587, 26, 272, 372, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 8, 1501, 395, 3778, 14, 2821, 3049, 8, 1294, 4439, 17, 467, 11172, 275, 3680, 401, 8057, 275, 756, 430, 199, 199, 318, 377, 13087, 8, 1501, 304, 523, 408, 523, 6162, 4913, 367, 1627, 570, 334, 269, 1218, 652, 340, 652, 3181, 1133, 2187, 9, 523, 408, 12244, 340, 3814, 7965, 8, 1501, 304, 272, 747, 14, 24043, 8, 1501, 12, 488, 9, 523, 587, 26, 272, 570, 5940, 275, 1551, 8, 1501, 12, 298, 87, 531, 272, 570, 5940, 14, 4939, 342, 272, 570, 5940, 14, 1600, 342, 27404, 372, 523, 199, 318, 603, 75, 694, 8, 515, 12, 8623, 275, 756, 304, 523, 408, 523, 2790, 282, 2082, 737, 314, 2013, 931, 14, 4155, 1006, 8623, 340, 8623, 365, 715, 14, 523, 408, 12244, 340, 8623, 26, 272, 1676, 2042, 275, 3087, 272, 367, 2935, 315, 931, 14, 1294, 8, 736, 14, 515, 14, 4127, 304, 489, 1676, 2042, 275, 747, 14, 515, 14, 904, 8, 1708, 2042, 12, 2935, 9, 489, 603, 75, 694, 8, 1708, 2042, 12, 8623, 275, 756, 9, 523, 587, 26, 272, 340, 440, 3814, 7965, 8, 515, 9, 503, 440, 6596, 694, 8, 515, 304, 489, 747, 14, 8215, 8, 515, 9, 12244, 372, 199, 199, 318, 445, 80, 8, 13196, 269, 12, 1347, 304, 523, 408, 523, 11247, 282, 570, 523, 408, 12244, 5145, 14, 1574, 8, 13196, 269, 12, 1347, 9, 12244, 372, 2043, 199, 318, 14171, 8, 13196, 269, 12, 1347, 304, 523, 408, 523, 14171, 282, 570, 523, 408, 12244, 5145, 14, 1185, 8, 13196, 269, 12, 1347, 9, 12244, 372, 199, 199, 318, 3814, 7965, 8, 1501, 304, 523, 408, 523, 1432, 3775, 314, 6841, 570, 3495, 523, 408, 819, 862, 26, 272, 747, 14, 3736, 8, 1501, 9, 272, 372, 715, 523, 871, 6440, 26, 272, 372, 756, 523, 199, 318, 6596, 18039, 8, 1501, 304, 523, 408, 523, 1432, 3775, 314, 6841, 570, 3495, 436, 365, 7286, 523, 408, 819, 340, 440, 3814, 7965, 8, 1501, 304, 272, 372, 756, 523, 587, 26, 272, 372, 747, 14, 2732, 8, 1501, 12, 747, 14, 56, 63, 3593, 9, 1362, 199, 318, 6596, 694, 8, 515, 304, 523, 408, 523, 1432, 3775, 314, 6841, 931, 8469, 282, 2082, 523, 408, 27404, 372, 5672, 14, 51, 63, 1311, 3022, 8, 736, 14, 3736, 8, 515, 2788, 16, 566, 1362, 199, 318, 820, 77, 8, 515, 304, 523, 408, 523, 8496, 314, 570, 737, 314, 2013, 931, 523, 408, 12244, 747, 14, 2168, 8, 515, 9, 12244, 372, 523, 199, 318, 820, 77, 694, 8, 515, 12, 3542, 275, 756, 304, 523, 408 ]
[ 961, 3555, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 199, 3, 1015, 499, 14, 17, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 221, 199, 3, 961, 3555, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 221, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 3180, 543, 642, 3555, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 221, 11315, 13, 10067, 221, 8217, 199, 199, 3, 334, 6493, 1183, 1777, 402, 2717, 1907, 328, 369, 12, 6042, 367, 5315, 2537, 701, 445, 5653, 644, 382, 834, 9, 199, 199, 3, 1898, 334, 35, 9, 6171, 3626, 4295, 4674, 15904, 315, 314, 14753, 402, 7053, 1488, 4708, 436, 11789, 14, 199, 3, 199, 3, 7754, 1937, 314, 10610, 570, 315, 314, 2446, 1350, 2082, 367, 282, 2615, 769, 199, 3, 402, 8417, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 13861, 345, 15849, 2054, 14, 199, 3, 199, 3, 13861, 345, 15849, 2054, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 13861, 345, 15849, 2054, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 1666, 314, 199, 3, 1664, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 844, 199, 3, 3180, 543, 13861, 345, 15849, 2054, 14, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 421, 199, 624, 199, 1173, 7252, 14975, 199, 624, 199, 199, 646, 5739, 199, 646, 747, 199, 646, 5145, 199, 646, 3873, 199, 646, 5672, 199, 646, 5549, 199, 646, 2882, 199, 199, 646, 5315, 2537, 14, 6706, 21204, 14, 1757, 465, 3105, 199, 646, 5315, 2537, 14, 6706, 21204, 14, 1208, 465, 3778, 199, 199, 318, 3814, 6382, 8, 1501, 304, 523, 408, 523, 1432, 314, 570, 3329, 402, 314, 6841, 1788, 334, 15768, 314, 298, 2685, 523, 408, 819, 3715, 275, 747, 14, 515, 14, 4846, 8, 1501, 680, 1294, 15857, 12244, 340, 822, 8, 1294, 9, 508, 413, 26, 272, 372, 3087, 523, 587, 26, 272, 372, 14530, 435, 3715, 1988, 17, 61, 199, 199, 318, 19828, 1173, 6382, 8, 1501, 304, 523, 408, 523, 19828, 314, 570, 3329, 687, 314, 6841, 1788, 523, 408, 819, 3715, 275, 747, 14, 515, 14, 4846, 8, 1501, 680, 1294, 15857, 12244, 340, 822, 8, 1294, 9, 508, 413, 26, 272, 372, 1788, 523, 587, 26, 272, 372, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 8, 1501, 395, 3778, 14, 2821, 3049, 8, 1294, 4439, 17, 467, 11172, 275, 3680, 401, 8057, 275, 756, 430, 199, 199, 318, 377, 13087, 8, 1501, 304, 523, 408, 523, 6162, 4913, 367, 1627, 570, 334, 269, 1218, 652, 340, 652, 3181, 1133, 2187, 9, 523, 408, 12244, 340, 3814, 7965, 8, 1501, 304, 272, 747, 14, 24043, 8, 1501, 12, 488, 9, 523, 587, 26, 272, 570, 5940, 275, 1551, 8, 1501, 12, 298, 87, 531, 272, 570, 5940, 14, 4939, 342, 272, 570, 5940, 14, 1600, 342, 27404, 372, 523, 199, 318, 603, 75, 694, 8, 515, 12, 8623, 275, 756, 304, 523, 408, 523, 2790, 282, 2082, 737, 314, 2013, 931, 14, 4155, 1006, 8623, 340, 8623, 365, 715, 14, 523, 408, 12244, 340, 8623, 26, 272, 1676, 2042, 275, 3087, 272, 367, 2935, 315, 931, 14, 1294, 8, 736, 14, 515, 14, 4127, 304, 489, 1676, 2042, 275, 747, 14, 515, 14, 904, 8, 1708, 2042, 12, 2935, 9, 489, 603, 75, 694, 8, 1708, 2042, 12, 8623, 275, 756, 9, 523, 587, 26, 272, 340, 440, 3814, 7965, 8, 515, 9, 503, 440, 6596, 694, 8, 515, 304, 489, 747, 14, 8215, 8, 515, 9, 12244, 372, 199, 199, 318, 445, 80, 8, 13196, 269, 12, 1347, 304, 523, 408, 523, 11247, 282, 570, 523, 408, 12244, 5145, 14, 1574, 8, 13196, 269, 12, 1347, 9, 12244, 372, 2043, 199, 318, 14171, 8, 13196, 269, 12, 1347, 304, 523, 408, 523, 14171, 282, 570, 523, 408, 12244, 5145, 14, 1185, 8, 13196, 269, 12, 1347, 9, 12244, 372, 199, 199, 318, 3814, 7965, 8, 1501, 304, 523, 408, 523, 1432, 3775, 314, 6841, 570, 3495, 523, 408, 819, 862, 26, 272, 747, 14, 3736, 8, 1501, 9, 272, 372, 715, 523, 871, 6440, 26, 272, 372, 756, 523, 199, 318, 6596, 18039, 8, 1501, 304, 523, 408, 523, 1432, 3775, 314, 6841, 570, 3495, 436, 365, 7286, 523, 408, 819, 340, 440, 3814, 7965, 8, 1501, 304, 272, 372, 756, 523, 587, 26, 272, 372, 747, 14, 2732, 8, 1501, 12, 747, 14, 56, 63, 3593, 9, 1362, 199, 318, 6596, 694, 8, 515, 304, 523, 408, 523, 1432, 3775, 314, 6841, 931, 8469, 282, 2082, 523, 408, 27404, 372, 5672, 14, 51, 63, 1311, 3022, 8, 736, 14, 3736, 8, 515, 2788, 16, 566, 1362, 199, 318, 820, 77, 8, 515, 304, 523, 408, 523, 8496, 314, 570, 737, 314, 2013, 931, 523, 408, 12244, 747, 14, 2168, 8, 515, 9, 12244, 372, 523, 199, 318, 820, 77, 694, 8, 515, 12, 3542, 275, 756, 304, 523, 408, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
cuboxi/android_external_chromium_org
tools/telemetry/telemetry/core/platform/profiler/android_prebuilt_profiler_helper.py
23
1228
# Copyright 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Android-specific, downloads and installs pre-built profilers. These pre-built binaries are stored in Cloud Storage, and they were built from AOSP source. Specific profilers using this helper class contain more detailed information. """ import os from telemetry.core import util from telemetry.page import cloud_storage _DEVICE_PROFILER_DIR = '/data/local/tmp/profilers/' def GetDevicePath(profiler_binary): return os.path.join(_DEVICE_PROFILER_DIR, os.path.basename(profiler_binary)) def GetHostPath(profiler_binary): return os.path.join(util.GetTelemetryDir(), 'bin', 'prebuilt', 'android', profiler_binary) def GetIfChanged(profiler_binary): cloud_storage.GetIfChanged(cloud_storage.PUBLIC_BUCKET, GetHostPath(profiler_binary)) def InstallOnDevice(adb, profiler_binary): GetIfChanged(profiler_binary) adb.Adb().PushIfNeeded(GetHostPath(profiler_binary), GetDevicePath(profiler_binary)) adb.Adb().RunShellCommand('chmod 777 ' + GetDevicePath(profiler_binary))
bsd-3-clause
[ 3, 1898, 6171, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 20762, 13, 6100, 12, 28242, 436, 25801, 876, 13, 11730, 4690, 2393, 14, 199, 199, 20676, 876, 13, 11730, 21984, 787, 5489, 315, 8142, 10533, 12, 436, 2985, 4898, 199, 11730, 687, 437, 3100, 48, 1350, 14, 20411, 4690, 2393, 1808, 642, 5922, 1021, 1395, 199, 6878, 16212, 2556, 14, 199, 624, 199, 199, 646, 747, 199, 199, 504, 17298, 14, 1018, 492, 4884, 199, 504, 17298, 14, 1606, 492, 8002, 63, 3494, 421, 199, 63, 10555, 63, 2514, 5110, 540, 63, 3022, 275, 1994, 576, 15, 1832, 15, 2791, 15, 2913, 2393, 4805, 421, 199, 318, 2372, 2510, 2042, 8, 20132, 63, 3008, 304, 523, 372, 747, 14, 515, 14, 904, 1547, 10555, 63, 2514, 5110, 540, 63, 3022, 12, 747, 14, 515, 14, 4846, 8, 20132, 63, 3008, 430, 421, 199, 318, 2372, 4965, 2042, 8, 20132, 63, 3008, 304, 523, 372, 747, 14, 515, 14, 904, 8, 1974, 14, 1002, 24944, 10987, 3567, 1062, 1993, 283, 1393, 297, 283, 657, 11730, 297, 283, 6238, 297, 23173, 63, 3008, 9, 421, 199, 318, 2372, 3917, 6970, 8, 20132, 63, 3008, 304, 523, 8002, 63, 3494, 14, 1002, 3917, 6970, 8, 4091, 63, 3494, 14, 19476, 63, 20156, 12, 2490, 2372, 4965, 2042, 8, 20132, 63, 3008, 430, 421, 199, 318, 13276, 3314, 2510, 8, 13741, 12, 23173, 63, 3008, 304, 523, 2372, 3917, 6970, 8, 20132, 63, 3008, 9, 523, 28173, 14, 33, 697, 1252, 10731, 3917, 21549, 8, 1002, 4965, 2042, 8, 20132, 63, 3008, 395, 586, 2372, 2510, 2042, 8, 20132, 63, 3008, 430, 523, 28173, 14, 33, 697, 1252, 2540, 8529, 3110, 360, 11693, 8375, 23, 283, 435, 2372, 2510, 2042, 8, 20132, 63, 3008, 430, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1898, 6171, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 20762, 13, 6100, 12, 28242, 436, 25801, 876, 13, 11730, 4690, 2393, 14, 199, 199, 20676, 876, 13, 11730, 21984, 787, 5489, 315, 8142, 10533, 12, 436, 2985, 4898, 199, 11730, 687, 437, 3100, 48, 1350, 14, 20411, 4690, 2393, 1808, 642, 5922, 1021, 1395, 199, 6878, 16212, 2556, 14, 199, 624, 199, 199, 646, 747, 199, 199, 504, 17298, 14, 1018, 492, 4884, 199, 504, 17298, 14, 1606, 492, 8002, 63, 3494, 421, 199, 63, 10555, 63, 2514, 5110, 540, 63, 3022, 275, 1994, 576, 15, 1832, 15, 2791, 15, 2913, 2393, 4805, 421, 199, 318, 2372, 2510, 2042, 8, 20132, 63, 3008, 304, 523, 372, 747, 14, 515, 14, 904, 1547, 10555, 63, 2514, 5110, 540, 63, 3022, 12, 747, 14, 515, 14, 4846, 8, 20132, 63, 3008, 430, 421, 199, 318, 2372, 4965, 2042, 8, 20132, 63, 3008, 304, 523, 372, 747, 14, 515, 14, 904, 8, 1974, 14, 1002, 24944, 10987, 3567, 1062, 1993, 283, 1393, 297, 283, 657, 11730, 297, 283, 6238, 297, 23173, 63, 3008, 9, 421, 199, 318, 2372, 3917, 6970, 8, 20132, 63, 3008, 304, 523, 8002, 63, 3494, 14, 1002, 3917, 6970, 8, 4091, 63, 3494, 14, 19476, 63, 20156, 12, 2490, 2372, 4965, 2042, 8, 20132, 63, 3008, 430, 421, 199, 318, 13276, 3314, 2510, 8, 13741, 12, 23173, 63, 3008, 304, 523, 2372, 3917, 6970, 8, 20132, 63, 3008, 9, 523, 28173, 14, 33, 697, 1252, 10731, 3917, 21549, 8, 1002, 4965, 2042, 8, 20132, 63, 3008, 395, 586, 2372, 2510, 2042, 8, 20132, 63, 3008, 430, 523, 28173, 14, 33, 697, 1252, 2540, 8529, 3110, 360, 11693, 8375, 23, 283, 435, 2372, 2510, 2042, 8, 20132, 63, 3008, 430, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
bulax41/Commands
scripts/telegram_bot.py
1
8020
#!/usr/bin/env python import subprocess import select import sys import datetime import time import re import json import socket import logging import telegram from contextlib import closing from telegram.ext import Updater, CommandHandler, MessageHandler, Filters savefile = "chatlist.json" user_token = "8c6d20cee7837fa7e6a55a254aa3ac53" admin_token = "79e36a012213b96a2248cefe01225f71" # Enable logging logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) def _messageUsers(message): global userList,updater for user in userList.keys(): chat_id = userList[user]["chat_id"] try: logger.info("Sending Message to user %s" % user) updater.bot.sendMessage(chat_id=chat_id,text=message) except Unauthorized: # remove update.message.chat_id from conversation list chatList.remove(chat_id) logger.warning("Unauthorized, remove update.message.chat_id from conversation list") continue except BadRequest: # remove update.message.chat_id from conversation list logger.warning("BadRequest, sending message") continue except TimedOut: # handle slow connection problems logger.warning("TimedOut, sending message") continue except NetworkError: # handle other connection problems logger.warning("NetworkError, sending message") continue except ChatMigrated as e: logger.warning("Chat Migrated ID, sending message") continue except TelegramError: # handle all other telegram related errors logger.warning("TelegramError, sending message") continue return def _messageAdmins(message): global userList,updater for user in userList.keys(): if userList[user]["admin"] == False: continue chat_id = userList[user]["chat_id"] try: logger.info("Sending Message to user %s" % user) updater.bot.sendMessage(chat_id=chat_id,text=message) except Unauthorized: # remove update.message.chat_id from conversation list chatList.remove(chat_id) logger.warning("Unauthorized, remove update.message.chat_id from conversation list") continue except BadRequest: # remove update.message.chat_id from conversation list logger.warning("BadRequest, sending message") continue except TimedOut: # handle slow connection problems logger.warning("TimedOut, sending message") continue except NetworkError: # handle other connection problems logger.warning("NetworkError, sending message") continue except ChatMigrated as e: logger.warning("Chat Migrated ID, sending message") continue except TelegramError: # handle all other telegram related errors logger.warning("TelegramError, sending message") continue return def tokens(bot,update): if _auth(update,admin=True) == False: return update.message.reply_text( """ User registration token: %s Admin registration token: %s """ % (user_token,admin_token) ) return def who(bot,update): global userList if _auth(update) == False: return for user in userList.keys(): admin = "" if userList[user]["admin"]: admin = ", Admin" msg = "%s %s, %s %s" % (userList[user]["first_name"],userList[user]["last_name"],userList[user]["username"],admin) update.message.reply_text(msg) return def _auth(update,admin=False): global userList user = update.message.from_user if update.message.chat.type != "private": update.message.reply_text("Sorry %s, I prefer only private chats." % user.first_name) return(False) if userList.has_key(str(user.id)): if admin: return(userList[str(user.id)]["admin"]) return(True) update.message.reply_text("I'm sorry %s. I am not sure chatting with you is a good idea right now." % user.first_name) return(False) def _add_user(update,admin=False): global userList userList[str(update.message.from_user.id)] = { "admin":admin, "chat_id":update.message.chat.id, "first_name": update.message.from_user.first_name, "last_name": update.message.from_user.last_name, "username": update.message.from_user.username } with open(savefile, 'w') as f: json.dump(userList,f) return def register(bot, update, args): global userList user = update.message.from_user token = " ".join(args) if token == user_token: if userList.has_key(str(user.id)): update.message.reply_text("%s, you have already registered." % user.first_name) return _add_user(update) elif token == admin_token: if userList.has_key(str(user.id)): if userList[str(user.id)]["admin"]: update.message.reply_text("%s, you are already and admin." % user.first_name) return else: _add_user(update,admin=True) update.message.reply_text("%s, you are now an admin. Wield the power with care. Check out the /help menu to see the new commands." % user.first_name) return else: update.message.reply_text("Hi %s, I can't register you. " % user.first_name ) return update.message.reply_text("Welcome %s! If you need help just ask. /help" % user.first_name) _messageAdmins(user.first_name) return def help(bot, update): global userList if _auth(update) == False: return user = update.message.from_user if _auth(update,admin=True): m = """ *Admin Commands* /tokens : Replies with the registration tokens """ update.message.reply_text(m) update.message.reply_text( """ *User menu* /who : List the registered users. /register {token} : This is to register with the Bot or upgrade an account to an admin. """ ) def echo(bot, update): if _auth(update) == False: return update.message.reply_text(update.message.text) def error(bot, update, error): logger.warn('Update "%s" caused error "%s"' % (update, error)) def unknownCmd(bot, update): if _auth(update) == False: return update.message.reply_text("Hi %s, not sure I understand, please ask for /help if needed." % update.message.from_user.first_name) return def load_users(): global userList # open up previous authenticated chat users try: with open(savefile, 'r') as f: try: userList = json.load(f) except ValueError: print "No users to load" pass except: pass def main(): global userList,updater userList = {} load_users() # Create the EventHandler and pass it your bot's token. updater = Updater("319507063:AAFI9Ca2x50NKTxBuxOn5TSHvdEI-bng0N4") # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram dp.add_handler(CommandHandler("register", register,pass_args=True)) dp.add_handler(CommandHandler("help", help)) dp.add_handler(CommandHandler("who", who)) dp.add_handler(CommandHandler("tokens", tokens)) dp.add_handler(MessageHandler(Filters.command,help)) dp.add_handler(MessageHandler(Filters.text, help)) # log all errors dp.add_error_handler(error) # Start the Bot updater.start_polling() updater.idle() if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 646, 3873, 199, 646, 3504, 199, 646, 984, 199, 646, 2197, 199, 646, 900, 199, 646, 295, 199, 646, 2022, 199, 646, 2838, 199, 646, 2050, 199, 646, 14001, 1679, 199, 504, 15502, 492, 11261, 199, 504, 14001, 1679, 14, 832, 492, 6162, 82, 12, 5817, 2461, 12, 6430, 2461, 12, 21240, 199, 199, 2117, 493, 275, 298, 10289, 513, 14, 1001, 2, 199, 751, 63, 1418, 275, 298, 24, 67, 22, 68, 1165, 29377, 2277, 1401, 667, 23, 69, 22, 65, 1229, 65, 8306, 2158, 19, 645, 2481, 2, 199, 2113, 63, 1418, 275, 298, 1965, 69, 1344, 65, 614, 1081, 969, 66, 2534, 65, 29899, 301, 771, 614, 10932, 70, 3172, 2, 199, 199, 3, 12030, 2050, 199, 4806, 14, 19602, 8, 908, 29342, 18331, 9, 83, 446, 2818, 354, 9, 83, 446, 2818, 20056, 9, 83, 446, 2818, 1188, 9, 83, 297, 490, 2166, 29, 4806, 14, 4531, 9, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 318, 485, 1188, 12117, 8, 1188, 304, 272, 2288, 922, 1296, 12, 29645, 272, 367, 922, 315, 922, 1296, 14, 1612, 837, 267, 21472, 63, 344, 275, 922, 1296, 59, 751, 7541, 10289, 63, 344, 937, 267, 862, 26, 288, 2512, 14, 815, 480, 27219, 6430, 370, 922, 450, 83, 2, 450, 922, 9, 288, 1678, 82, 14, 3018, 14, 2254, 2209, 8, 10289, 63, 344, 29, 10289, 63, 344, 12, 505, 29, 1188, 9, 398, 871, 1910, 11497, 26, 288, 327, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 288, 21472, 1296, 14, 2168, 8, 10289, 63, 344, 9, 288, 2512, 14, 3764, 480, 28290, 12, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 531, 288, 1980, 267, 871, 8857, 2017, 26, 288, 327, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 288, 2512, 14, 3764, 480, 12380, 12, 10209, 1245, 531, 288, 1980, 267, 871, 4703, 68, 2204, 26, 288, 327, 2429, 11999, 1950, 8826, 288, 2512, 14, 3764, 480, 28682, 2204, 12, 10209, 1245, 531, 288, 1980, 267, 871, 7220, 547, 26, 288, 327, 2429, 1163, 1950, 8826, 288, 2512, 14, 3764, 480, 4491, 547, 12, 10209, 1245, 531, 288, 1980, 267, 871, 2799, 292, 19322, 12601, 465, 325, 26, 288, 2512, 14, 3764, 480, 21954, 28195, 12601, 2870, 12, 10209, 1245, 531, 288, 1980, 267, 871, 23884, 1679, 547, 26, 288, 327, 2429, 1006, 1163, 14001, 1679, 4048, 2552, 288, 2512, 14, 3764, 480, 24944, 1679, 547, 12, 10209, 1245, 531, 288, 1980, 272, 372, 199, 199, 318, 485, 1188, 4880, 83, 8, 1188, 304, 272, 2288, 922, 1296, 12, 29645, 272, 367, 922, 315, 922, 1296, 14, 1612, 837, 267, 340, 922, 1296, 59, 751, 7541, 2113, 937, 508, 756, 26, 288, 1980, 267, 21472, 63, 344, 275, 922, 1296, 59, 751, 7541, 10289, 63, 344, 937, 267, 862, 26, 288, 2512, 14, 815, 480, 27219, 6430, 370, 922, 450, 83, 2, 450, 922, 9, 288, 1678, 82, 14, 3018, 14, 2254, 2209, 8, 10289, 63, 344, 29, 10289, 63, 344, 12, 505, 29, 1188, 9, 398, 871, 1910, 11497, 26, 288, 327, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 288, 21472, 1296, 14, 2168, 8, 10289, 63, 344, 9, 288, 2512, 14, 3764, 480, 28290, 12, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 531, 288, 1980, 267, 871, 8857, 2017, 26, 288, 327, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 288, 2512, 14, 3764, 480, 12380, 12, 10209, 1245, 531, 288, 1980, 267, 871, 4703, 68, 2204, 26, 288, 327, 2429, 11999, 1950, 8826, 288, 2512, 14, 3764, 480, 28682, 2204, 12, 10209, 1245, 531, 288, 1980, 267, 871, 7220, 547, 26, 288, 327, 2429, 1163, 1950, 8826, 288, 2512, 14, 3764, 480, 4491, 547, 12, 10209, 1245, 531, 288, 1980, 267, 871, 2799, 292, 19322, 12601, 465, 325, 26, 288, 2512, 14, 3764, 480, 21954, 28195, 12601, 2870, 12, 10209, 1245, 531, 288, 1980, 267, 871, 23884, 1679, 547, 26, 288, 327, 2429, 1006, 1163, 14001, 1679, 4048, 2552, 288, 2512, 14, 3764, 480, 24944, 1679, 547, 12, 10209, 1245, 531, 288, 1980, 272, 372, 199, 199, 318, 4645, 8, 3018, 12, 873, 304, 272, 340, 485, 1178, 8, 873, 12, 2113, 29, 549, 9, 508, 756, 26, 267, 372, 339, 1678, 14, 1188, 14, 8102, 63, 505, 8, 267, 408, 267, 2876, 10991, 1526, 26, 450, 83, 267, 9516, 10991, 1526, 26, 450, 83, 267, 408, 450, 334, 751, 63, 1418, 12, 2113, 63, 1418, 9, 267, 776, 272, 372, 421, 199, 318, 3963, 8, 3018, 12, 873, 304, 272, 2288, 922, 1296, 272, 340, 485, 1178, 8, 873, 9, 508, 756, 26, 267, 372, 339, 367, 922, 315, 922, 1296, 14, 1612, 837, 267, 4628, 275, 3087, 267, 340, 922, 1296, 59, 751, 7541, 2113, 6229, 288, 4628, 275, 3872, 9516, 2, 267, 1499, 275, 2071, 83, 450, 83, 12, 450, 83, 450, 83, 2, 450, 334, 751, 1296, 59, 751, 7541, 2246, 63, 354, 2255, 751, 1296, 59, 751, 7541, 2019, 63, 354, 2255, 751, 1296, 59, 751, 7541, 2473, 2255, 2113, 9, 267, 1678, 14, 1188, 14, 8102, 63, 505, 8, 1328, 9, 272, 372, 199, 199, 318, 485, 1178, 8, 873, 12, 2113, 29, 797, 304, 272, 2288, 922, 1296, 272, 922, 275, 1678, 14, 1188, 14, 504, 63, 751, 339, 340, 1678, 14, 1188, 14, 10289, 14, 466, 1137, 298, 4239, 582, 267, 1678, 14, 1188, 14, 8102, 63, 505, 480, 27143, 450, 83, 12, 473, 16602, 1454, 5726, 682, 1956, 2122, 450, 922, 14, 2246, 63, 354, 9, 267, 372, 8, 797, 9, 339, 340, 922, 1296, 14, 1989, 63, 498, 8, 495, 8, 751, 14, 344, 2298, 267, 340, 4628, 26, 288, 372, 8, 751, 1296, 59, 495, 8, 751, 14, 344, 1874, 905, 2113, 3135, 267, 372, 8, 549, 9, 339, 1678, 14, 1188, 14, 8102, 63, 505, 480, 41, 6704, 308, 21342, 450, 83, 14, 221, 473, 8140, 440, 3238, 21472, 1337, 543, 1265, 365, 282, 6954, 16819 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 646, 3873, 199, 646, 3504, 199, 646, 984, 199, 646, 2197, 199, 646, 900, 199, 646, 295, 199, 646, 2022, 199, 646, 2838, 199, 646, 2050, 199, 646, 14001, 1679, 199, 504, 15502, 492, 11261, 199, 504, 14001, 1679, 14, 832, 492, 6162, 82, 12, 5817, 2461, 12, 6430, 2461, 12, 21240, 199, 199, 2117, 493, 275, 298, 10289, 513, 14, 1001, 2, 199, 751, 63, 1418, 275, 298, 24, 67, 22, 68, 1165, 29377, 2277, 1401, 667, 23, 69, 22, 65, 1229, 65, 8306, 2158, 19, 645, 2481, 2, 199, 2113, 63, 1418, 275, 298, 1965, 69, 1344, 65, 614, 1081, 969, 66, 2534, 65, 29899, 301, 771, 614, 10932, 70, 3172, 2, 199, 199, 3, 12030, 2050, 199, 4806, 14, 19602, 8, 908, 29342, 18331, 9, 83, 446, 2818, 354, 9, 83, 446, 2818, 20056, 9, 83, 446, 2818, 1188, 9, 83, 297, 490, 2166, 29, 4806, 14, 4531, 9, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 318, 485, 1188, 12117, 8, 1188, 304, 272, 2288, 922, 1296, 12, 29645, 272, 367, 922, 315, 922, 1296, 14, 1612, 837, 267, 21472, 63, 344, 275, 922, 1296, 59, 751, 7541, 10289, 63, 344, 937, 267, 862, 26, 288, 2512, 14, 815, 480, 27219, 6430, 370, 922, 450, 83, 2, 450, 922, 9, 288, 1678, 82, 14, 3018, 14, 2254, 2209, 8, 10289, 63, 344, 29, 10289, 63, 344, 12, 505, 29, 1188, 9, 398, 871, 1910, 11497, 26, 288, 327, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 288, 21472, 1296, 14, 2168, 8, 10289, 63, 344, 9, 288, 2512, 14, 3764, 480, 28290, 12, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 531, 288, 1980, 267, 871, 8857, 2017, 26, 288, 327, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 288, 2512, 14, 3764, 480, 12380, 12, 10209, 1245, 531, 288, 1980, 267, 871, 4703, 68, 2204, 26, 288, 327, 2429, 11999, 1950, 8826, 288, 2512, 14, 3764, 480, 28682, 2204, 12, 10209, 1245, 531, 288, 1980, 267, 871, 7220, 547, 26, 288, 327, 2429, 1163, 1950, 8826, 288, 2512, 14, 3764, 480, 4491, 547, 12, 10209, 1245, 531, 288, 1980, 267, 871, 2799, 292, 19322, 12601, 465, 325, 26, 288, 2512, 14, 3764, 480, 21954, 28195, 12601, 2870, 12, 10209, 1245, 531, 288, 1980, 267, 871, 23884, 1679, 547, 26, 288, 327, 2429, 1006, 1163, 14001, 1679, 4048, 2552, 288, 2512, 14, 3764, 480, 24944, 1679, 547, 12, 10209, 1245, 531, 288, 1980, 272, 372, 199, 199, 318, 485, 1188, 4880, 83, 8, 1188, 304, 272, 2288, 922, 1296, 12, 29645, 272, 367, 922, 315, 922, 1296, 14, 1612, 837, 267, 340, 922, 1296, 59, 751, 7541, 2113, 937, 508, 756, 26, 288, 1980, 267, 21472, 63, 344, 275, 922, 1296, 59, 751, 7541, 10289, 63, 344, 937, 267, 862, 26, 288, 2512, 14, 815, 480, 27219, 6430, 370, 922, 450, 83, 2, 450, 922, 9, 288, 1678, 82, 14, 3018, 14, 2254, 2209, 8, 10289, 63, 344, 29, 10289, 63, 344, 12, 505, 29, 1188, 9, 398, 871, 1910, 11497, 26, 288, 327, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 288, 21472, 1296, 14, 2168, 8, 10289, 63, 344, 9, 288, 2512, 14, 3764, 480, 28290, 12, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 531, 288, 1980, 267, 871, 8857, 2017, 26, 288, 327, 2813, 1678, 14, 1188, 14, 10289, 63, 344, 687, 3818, 20592, 769, 288, 2512, 14, 3764, 480, 12380, 12, 10209, 1245, 531, 288, 1980, 267, 871, 4703, 68, 2204, 26, 288, 327, 2429, 11999, 1950, 8826, 288, 2512, 14, 3764, 480, 28682, 2204, 12, 10209, 1245, 531, 288, 1980, 267, 871, 7220, 547, 26, 288, 327, 2429, 1163, 1950, 8826, 288, 2512, 14, 3764, 480, 4491, 547, 12, 10209, 1245, 531, 288, 1980, 267, 871, 2799, 292, 19322, 12601, 465, 325, 26, 288, 2512, 14, 3764, 480, 21954, 28195, 12601, 2870, 12, 10209, 1245, 531, 288, 1980, 267, 871, 23884, 1679, 547, 26, 288, 327, 2429, 1006, 1163, 14001, 1679, 4048, 2552, 288, 2512, 14, 3764, 480, 24944, 1679, 547, 12, 10209, 1245, 531, 288, 1980, 272, 372, 199, 199, 318, 4645, 8, 3018, 12, 873, 304, 272, 340, 485, 1178, 8, 873, 12, 2113, 29, 549, 9, 508, 756, 26, 267, 372, 339, 1678, 14, 1188, 14, 8102, 63, 505, 8, 267, 408, 267, 2876, 10991, 1526, 26, 450, 83, 267, 9516, 10991, 1526, 26, 450, 83, 267, 408, 450, 334, 751, 63, 1418, 12, 2113, 63, 1418, 9, 267, 776, 272, 372, 421, 199, 318, 3963, 8, 3018, 12, 873, 304, 272, 2288, 922, 1296, 272, 340, 485, 1178, 8, 873, 9, 508, 756, 26, 267, 372, 339, 367, 922, 315, 922, 1296, 14, 1612, 837, 267, 4628, 275, 3087, 267, 340, 922, 1296, 59, 751, 7541, 2113, 6229, 288, 4628, 275, 3872, 9516, 2, 267, 1499, 275, 2071, 83, 450, 83, 12, 450, 83, 450, 83, 2, 450, 334, 751, 1296, 59, 751, 7541, 2246, 63, 354, 2255, 751, 1296, 59, 751, 7541, 2019, 63, 354, 2255, 751, 1296, 59, 751, 7541, 2473, 2255, 2113, 9, 267, 1678, 14, 1188, 14, 8102, 63, 505, 8, 1328, 9, 272, 372, 199, 199, 318, 485, 1178, 8, 873, 12, 2113, 29, 797, 304, 272, 2288, 922, 1296, 272, 922, 275, 1678, 14, 1188, 14, 504, 63, 751, 339, 340, 1678, 14, 1188, 14, 10289, 14, 466, 1137, 298, 4239, 582, 267, 1678, 14, 1188, 14, 8102, 63, 505, 480, 27143, 450, 83, 12, 473, 16602, 1454, 5726, 682, 1956, 2122, 450, 922, 14, 2246, 63, 354, 9, 267, 372, 8, 797, 9, 339, 340, 922, 1296, 14, 1989, 63, 498, 8, 495, 8, 751, 14, 344, 2298, 267, 340, 4628, 26, 288, 372, 8, 751, 1296, 59, 495, 8, 751, 14, 344, 1874, 905, 2113, 3135, 267, 372, 8, 549, 9, 339, 1678, 14, 1188, 14, 8102, 63, 505, 480, 41, 6704, 308, 21342, 450, 83, 14, 221, 473, 8140, 440, 3238, 21472, 1337, 543, 1265, 365, 282, 6954, 16819, 0 ]
[ 1, 1, 1, 1, 1, 1, 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ensorflow/tensorflow/python/profiler/internal/run_metadata_test.py
3
6803
# Copyright 2016 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """test the RunMetadata proto.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function from collections import defaultdict import six from tensorflow.core.protobuf import config_pb2 from tensorflow.python.client import session from tensorflow.python.framework import ops from tensorflow.python.ops import math_ops from tensorflow.python.ops import random_ops from tensorflow.python.ops import variables from tensorflow.python.platform import test from tensorflow.python.profiler import option_builder # pylint: disable=g-bad-import-order # XXX: this depends on pywrap_tensorflow and must come later from tensorflow.python.profiler import model_analyzer from tensorflow.python.profiler.internal import model_analyzer_testlib as lib SIZE = 1300 builder = option_builder.ProfileOptionBuilder def _extract_node(run_meta, node_names): if not isinstance(node_names, list): node_names = [node_names] ret = defaultdict(list) for dev_stat in run_meta.step_stats.dev_stats: dev = dev_stat.device for node_stat in dev_stat.node_stats: if node_stat.node_name in node_names: ret[dev].append(node_stat) return ret def _run_model(): x = random_ops.random_normal(shape=[1, SIZE]) w = random_ops.random_normal(shape=[SIZE, 2 * SIZE]) y = math_ops.matmul(x, w) with session.Session() as sess: run_metadata = config_pb2.RunMetadata() opts = builder.time_and_memory() opts['min_micros'] = 0 opts['min_bytes'] = 0 _ = sess.run(y, options=config_pb2.RunOptions( trace_level=config_pb2.RunOptions.FULL_TRACE), run_metadata=run_metadata) tfprof_node = model_analyzer.profile( sess.graph, run_meta=run_metadata, options=opts) return tfprof_node, run_metadata def _run_loop_model(): with session.Session() as sess: x = lib.BuildFullModel() sess.run(variables.global_variables_initializer()) run_meta = config_pb2.RunMetadata() _ = sess.run(x, options=config_pb2.RunOptions( trace_level=config_pb2.RunOptions.FULL_TRACE), run_metadata=run_meta) tfprof_node = model_analyzer.profile( sess.graph, run_meta, options=builder.time_and_memory()) return tfprof_node, run_meta class RunMetadataTest(test.TestCase): def testGPU(self): if not test.is_gpu_available(cuda_only=True): return gpu_dev = test.gpu_device_name() ops.reset_default_graph() with ops.device(gpu_dev): tfprof_node, run_meta = _run_model() self.assertEqual(tfprof_node.children[0].name, 'MatMul') self.assertGreater(tfprof_node.children[0].exec_micros, 10) ret = _extract_node(run_meta, ['MatMul', 'MatMul:MatMul']) self.assertEqual(len(ret), 3) self.assertTrue('/job:localhost/replica:0/task:0' + gpu_dev in ret) del ret['/job:localhost/replica:0/task:0' + gpu_dev] has_all_stream = False for k, _ in six.iteritems(ret): self.assertTrue(gpu_dev + '/stream' in k) if gpu_dev + '/stream:all' in k: has_all_stream = True self.assertTrue(has_all_stream) def testCPU(self): ops.reset_default_graph() with ops.device('/cpu:0'): tfprof_node, run_meta = _run_model() self.assertEqual(tfprof_node.children[0].name, 'MatMul') self.assertGreater(tfprof_node.children[0].exec_micros, 0) ret = _extract_node(run_meta, 'MatMul') self.assertEqual(len(ret), 1) self.assertTrue('/job:localhost/replica:0/task:0/cpu:0' in ret) ret = _extract_node(run_meta, 'MatMul:MatMul') self.assertEqual(len(ret), 0) def testLoopCPU(self): ops.reset_default_graph() with ops.device('/cpu:0'): tfprof_node, run_meta = _run_loop_model() # The while-loop caused a node to appear 4 times in scheduling. ret = _extract_node(run_meta, 'rnn/while/rnn/basic_rnn_cell/basic_rnn_cell/MatMul') self.assertEqual(len(ret['/job:localhost/replica:0/task:0/cpu:0']), 4) total_cpu_execs = 0 for node in ret['/job:localhost/replica:0/task:0/cpu:0']: total_cpu_execs += node.op_end_rel_micros mm_node = lib.SearchTFProfNode( tfprof_node, 'rnn/while/rnn/basic_rnn_cell/basic_rnn_cell/MatMul') self.assertEqual(mm_node.run_count, 4) self.assertEqual(mm_node.cpu_exec_micros, total_cpu_execs) self.assertEqual(mm_node.exec_micros, total_cpu_execs) # pylint: disable=pointless-string-statement """ TODO(xpan): This test is flaky because RunMetadata returned from TensorFlow is random. Still being investigated. def testLoopGPU(self): if not test.is_gpu_available(): return ops.reset_default_graph() with ops.device('/device:GPU:0'): tfprof_node, run_meta = _run_loop_model() # The while-loop caused a node to appear 4 times in scheduling. ret = _extract_node(run_meta, 'rnn/while/rnn/basic_rnn_cell/basic_rnn_cell/MatMul') self.assertEqual(len(ret['/job:localhost/replica:0/task:0/device:GPU:0']), 4) total_cpu_execs = 0 for node in ret['/job:localhost/replica:0/task:0/device:GPU:0']: total_cpu_execs += node.op_end_rel_micros ret = _extract_node( run_meta, 'rnn/while/rnn/basic_rnn_cell/basic_rnn_cell/MatMul:MatMul') self.assertGreaterEqual(len(ret['/device:GPU:0/stream:all']), 4) total_accelerator_execs = 0 for node in ret['/device:GPU:0/stream:all']: total_accelerator_execs += node.op_end_rel_micros mm_node = lib.SearchTFProfNode( tfprof_node, 'rnn/while/rnn/basic_rnn_cell/basic_rnn_cell/MatMul') self.assertEqual(mm_node.run_count, 4) self.assertEqual(mm_node.accelerator_exec_micros, total_accelerator_execs) self.assertEqual(mm_node.cpu_exec_micros, total_cpu_execs) self.assertEqual(mm_node.exec_micros, total_cpu_execs + total_accelerator_execs) """ if __name__ == '__main__': test.main()
mit
[ 3, 1898, 7800, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 396, 314, 3378, 5142, 4104, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 5055, 492, 10018, 199, 199, 646, 3816, 199, 199, 504, 3228, 14, 1018, 14, 7204, 492, 1101, 63, 3317, 18, 199, 504, 3228, 14, 1548, 14, 1258, 492, 2351, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4156, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2196, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2860, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 504, 3228, 14, 1548, 14, 20132, 492, 945, 63, 5649, 199, 199, 3, 4287, 26, 3507, 29, 71, 13, 4087, 13, 646, 13, 1648, 199, 3, 5787, 26, 642, 8350, 641, 1134, 3823, 63, 16008, 436, 1471, 11492, 2945, 199, 504, 3228, 14, 1548, 14, 20132, 492, 1402, 63, 17965, 199, 504, 3228, 14, 1548, 14, 20132, 14, 4672, 492, 1402, 63, 17965, 63, 396, 773, 465, 1973, 199, 199, 4305, 275, 4944, 383, 199, 5649, 275, 945, 63, 5649, 14, 5736, 2602, 6437, 421, 199, 318, 485, 5005, 63, 932, 8, 1065, 63, 2024, 12, 1031, 63, 1247, 304, 523, 340, 440, 1228, 8, 932, 63, 1247, 12, 769, 304, 272, 1031, 63, 1247, 275, 359, 932, 63, 1247, 61, 523, 2203, 275, 10018, 8, 513, 9, 523, 367, 4866, 63, 3736, 315, 1255, 63, 2024, 14, 2926, 63, 3200, 14, 2374, 63, 3200, 26, 272, 4866, 275, 4866, 63, 3736, 14, 1782, 272, 367, 1031, 63, 3736, 315, 4866, 63, 3736, 14, 932, 63, 3200, 26, 489, 340, 1031, 63, 3736, 14, 932, 63, 354, 315, 1031, 63, 1247, 26, 267, 2203, 59, 2374, 1055, 740, 8, 932, 63, 3736, 9, 523, 372, 2203, 421, 199, 318, 485, 1065, 63, 1238, 837, 523, 671, 275, 2196, 63, 1483, 14, 2355, 63, 3302, 8, 1392, 1524, 17, 12, 32289, 566, 523, 336, 275, 2196, 63, 1483, 14, 2355, 63, 3302, 8, 1392, 1524, 4305, 12, 499, 627, 32289, 566, 523, 612, 275, 3473, 63, 1483, 14, 14465, 8, 88, 12, 336, 9, 819, 543, 2351, 14, 4434, 342, 465, 4043, 26, 272, 1255, 63, 2343, 275, 1101, 63, 3317, 18, 14, 2540, 5142, 342, 272, 3999, 275, 6545, 14, 521, 63, 460, 63, 4844, 342, 272, 3999, 459, 827, 63, 6453, 83, 418, 275, 378, 272, 3999, 459, 827, 63, 2394, 418, 275, 378, 272, 485, 275, 4043, 14, 1065, 8, 89, 12, 326, 1511, 29, 888, 63, 3317, 18, 14, 2540, 4558, 8, 2151, 3307, 63, 1896, 29, 888, 63, 3317, 18, 14, 2540, 4558, 14, 14742, 63, 20112, 395, 326, 1255, 63, 2343, 29, 1065, 63, 2343, 9, 272, 2833, 14979, 63, 932, 275, 1402, 63, 17965, 14, 2913, 8, 267, 4043, 14, 2180, 12, 267, 1255, 63, 2024, 29, 1065, 63, 2343, 12, 267, 1511, 29, 3291, 9, 339, 372, 2833, 14979, 63, 932, 12, 1255, 63, 2343, 421, 199, 318, 485, 1065, 63, 3813, 63, 1238, 837, 523, 543, 2351, 14, 4434, 342, 465, 4043, 26, 272, 671, 275, 1973, 14, 3425, 9042, 1685, 342, 339, 4043, 14, 1065, 8, 3669, 14, 2966, 63, 3669, 63, 6498, 1012, 272, 1255, 63, 2024, 275, 1101, 63, 3317, 18, 14, 2540, 5142, 342, 272, 485, 275, 4043, 14, 1065, 8, 88, 12, 326, 1511, 29, 888, 63, 3317, 18, 14, 2540, 4558, 8, 2151, 3307, 63, 1896, 29, 888, 63, 3317, 18, 14, 2540, 4558, 14, 14742, 63, 20112, 395, 326, 1255, 63, 2343, 29, 1065, 63, 2024, 9, 339, 2833, 14979, 63, 932, 275, 1402, 63, 17965, 14, 2913, 8, 267, 4043, 14, 2180, 12, 1255, 63, 2024, 12, 267, 1511, 29, 5649, 14, 521, 63, 460, 63, 4844, 1012, 272, 372, 2833, 14979, 63, 932, 12, 1255, 63, 2024, 421, 199, 533, 3378, 5142, 774, 8, 396, 14, 1746, 304, 819, 347, 511, 20769, 8, 277, 304, 272, 340, 440, 511, 14, 374, 63, 6477, 63, 4561, 8, 16309, 63, 2118, 29, 549, 304, 489, 372, 339, 21758, 63, 2374, 275, 511, 14, 6477, 63, 1782, 63, 354, 342, 272, 4156, 14, 3958, 63, 885, 63, 2180, 342, 272, 543, 4156, 14, 1782, 8, 6477, 63, 2374, 304, 489, 2833, 14979, 63, 932, 12, 1255, 63, 2024, 275, 485, 1065, 63, 1238, 342, 489, 291, 14, 629, 8, 3249, 14979, 63, 932, 14, 3223, 59, 16, 1055, 354, 12, 283, 14817, 16867, 358, 489, 291, 14, 15070, 8, 3249, 14979, 63, 932, 14, 3223, 59, 16, 1055, 1628, 63, 6453, 83, 12, 1616, 9, 339, 2203, 275, 485, 5005, 63, 932, 8, 1065, 63, 2024, 12, 788, 14817, 16867, 297, 283, 14817, 16867, 26, 14817, 16867, 1105, 272, 291, 14, 629, 8, 552, 8, 3292, 395, 650, 9, 272, 291, 14, 1815, 2336, 2423, 26, 5967, 15, 12317, 26, 16, 15, 1765, 26, 16, 7, 435, 21758, 63, 2374, 315, 2203, 9, 272, 2150, 2203, 459, 15, 2423, 26, 5967, 15, 12317, 26, 16, 15, 1765, 26, 16, 7, 435, 21758, 63, 2374, 61, 339, 965, 63, 452, 63, 1745, 275, 756, 272, 367, 1022, 12, 485, 315, 3816, 14, 4611, 8, 3292, 304, 489, 291, 14, 1815 ]
[ 1898, 7800, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 396, 314, 3378, 5142, 4104, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 5055, 492, 10018, 199, 199, 646, 3816, 199, 199, 504, 3228, 14, 1018, 14, 7204, 492, 1101, 63, 3317, 18, 199, 504, 3228, 14, 1548, 14, 1258, 492, 2351, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4156, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2196, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2860, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 504, 3228, 14, 1548, 14, 20132, 492, 945, 63, 5649, 199, 199, 3, 4287, 26, 3507, 29, 71, 13, 4087, 13, 646, 13, 1648, 199, 3, 5787, 26, 642, 8350, 641, 1134, 3823, 63, 16008, 436, 1471, 11492, 2945, 199, 504, 3228, 14, 1548, 14, 20132, 492, 1402, 63, 17965, 199, 504, 3228, 14, 1548, 14, 20132, 14, 4672, 492, 1402, 63, 17965, 63, 396, 773, 465, 1973, 199, 199, 4305, 275, 4944, 383, 199, 5649, 275, 945, 63, 5649, 14, 5736, 2602, 6437, 421, 199, 318, 485, 5005, 63, 932, 8, 1065, 63, 2024, 12, 1031, 63, 1247, 304, 523, 340, 440, 1228, 8, 932, 63, 1247, 12, 769, 304, 272, 1031, 63, 1247, 275, 359, 932, 63, 1247, 61, 523, 2203, 275, 10018, 8, 513, 9, 523, 367, 4866, 63, 3736, 315, 1255, 63, 2024, 14, 2926, 63, 3200, 14, 2374, 63, 3200, 26, 272, 4866, 275, 4866, 63, 3736, 14, 1782, 272, 367, 1031, 63, 3736, 315, 4866, 63, 3736, 14, 932, 63, 3200, 26, 489, 340, 1031, 63, 3736, 14, 932, 63, 354, 315, 1031, 63, 1247, 26, 267, 2203, 59, 2374, 1055, 740, 8, 932, 63, 3736, 9, 523, 372, 2203, 421, 199, 318, 485, 1065, 63, 1238, 837, 523, 671, 275, 2196, 63, 1483, 14, 2355, 63, 3302, 8, 1392, 1524, 17, 12, 32289, 566, 523, 336, 275, 2196, 63, 1483, 14, 2355, 63, 3302, 8, 1392, 1524, 4305, 12, 499, 627, 32289, 566, 523, 612, 275, 3473, 63, 1483, 14, 14465, 8, 88, 12, 336, 9, 819, 543, 2351, 14, 4434, 342, 465, 4043, 26, 272, 1255, 63, 2343, 275, 1101, 63, 3317, 18, 14, 2540, 5142, 342, 272, 3999, 275, 6545, 14, 521, 63, 460, 63, 4844, 342, 272, 3999, 459, 827, 63, 6453, 83, 418, 275, 378, 272, 3999, 459, 827, 63, 2394, 418, 275, 378, 272, 485, 275, 4043, 14, 1065, 8, 89, 12, 326, 1511, 29, 888, 63, 3317, 18, 14, 2540, 4558, 8, 2151, 3307, 63, 1896, 29, 888, 63, 3317, 18, 14, 2540, 4558, 14, 14742, 63, 20112, 395, 326, 1255, 63, 2343, 29, 1065, 63, 2343, 9, 272, 2833, 14979, 63, 932, 275, 1402, 63, 17965, 14, 2913, 8, 267, 4043, 14, 2180, 12, 267, 1255, 63, 2024, 29, 1065, 63, 2343, 12, 267, 1511, 29, 3291, 9, 339, 372, 2833, 14979, 63, 932, 12, 1255, 63, 2343, 421, 199, 318, 485, 1065, 63, 3813, 63, 1238, 837, 523, 543, 2351, 14, 4434, 342, 465, 4043, 26, 272, 671, 275, 1973, 14, 3425, 9042, 1685, 342, 339, 4043, 14, 1065, 8, 3669, 14, 2966, 63, 3669, 63, 6498, 1012, 272, 1255, 63, 2024, 275, 1101, 63, 3317, 18, 14, 2540, 5142, 342, 272, 485, 275, 4043, 14, 1065, 8, 88, 12, 326, 1511, 29, 888, 63, 3317, 18, 14, 2540, 4558, 8, 2151, 3307, 63, 1896, 29, 888, 63, 3317, 18, 14, 2540, 4558, 14, 14742, 63, 20112, 395, 326, 1255, 63, 2343, 29, 1065, 63, 2024, 9, 339, 2833, 14979, 63, 932, 275, 1402, 63, 17965, 14, 2913, 8, 267, 4043, 14, 2180, 12, 1255, 63, 2024, 12, 267, 1511, 29, 5649, 14, 521, 63, 460, 63, 4844, 1012, 272, 372, 2833, 14979, 63, 932, 12, 1255, 63, 2024, 421, 199, 533, 3378, 5142, 774, 8, 396, 14, 1746, 304, 819, 347, 511, 20769, 8, 277, 304, 272, 340, 440, 511, 14, 374, 63, 6477, 63, 4561, 8, 16309, 63, 2118, 29, 549, 304, 489, 372, 339, 21758, 63, 2374, 275, 511, 14, 6477, 63, 1782, 63, 354, 342, 272, 4156, 14, 3958, 63, 885, 63, 2180, 342, 272, 543, 4156, 14, 1782, 8, 6477, 63, 2374, 304, 489, 2833, 14979, 63, 932, 12, 1255, 63, 2024, 275, 485, 1065, 63, 1238, 342, 489, 291, 14, 629, 8, 3249, 14979, 63, 932, 14, 3223, 59, 16, 1055, 354, 12, 283, 14817, 16867, 358, 489, 291, 14, 15070, 8, 3249, 14979, 63, 932, 14, 3223, 59, 16, 1055, 1628, 63, 6453, 83, 12, 1616, 9, 339, 2203, 275, 485, 5005, 63, 932, 8, 1065, 63, 2024, 12, 788, 14817, 16867, 297, 283, 14817, 16867, 26, 14817, 16867, 1105, 272, 291, 14, 629, 8, 552, 8, 3292, 395, 650, 9, 272, 291, 14, 1815, 2336, 2423, 26, 5967, 15, 12317, 26, 16, 15, 1765, 26, 16, 7, 435, 21758, 63, 2374, 315, 2203, 9, 272, 2150, 2203, 459, 15, 2423, 26, 5967, 15, 12317, 26, 16, 15, 1765, 26, 16, 7, 435, 21758, 63, 2374, 61, 339, 965, 63, 452, 63, 1745, 275, 756, 272, 367, 1022, 12, 485, 315, 3816, 14, 4611, 8, 3292, 304, 489, 291, 14, 1815, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
Fat-Zer/FreeCAD_sf_master
src/Mod/Web/InitGui.py
13
2410
#*************************************************************************** #* Copyright (c) 2002,2003 Jürgen Riegel <juergen.riegel@web.de> * #* * #* This file is part of the FreeCAD CAx development system. * #* * #* This program is free software; you can redistribute it and/or modify * #* it under the terms of the GNU Lesser General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. * #* * #* FreeCAD is distributed in the hope that it will be useful, * #* but WITHOUT ANY WARRANTY; without even the implied warranty of * #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * #* GNU Lesser General Public License for more details. * #* * #* You should have received a copy of the GNU Library General Public * #* License along with FreeCAD; if not, write to the Free Software * #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * #* USA * #***************************************************************************/ # Web gui init module # # Gathering all the information to start FreeCAD # This is the second one of three init scripts, the third one # runs when the gui is up class WebWorkbench ( Workbench ): "Web workbench object" def __init__(self): self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Web/Resources/icons/WebWorkbench.svg" self.__class__.MenuText = "Web" self.__class__.ToolTip = "Web workbench" def Initialize(self): # load the module import WebGui def GetClassName(self): return "WebGui::Workbench" Gui.addWorkbench(WebWorkbench()) # Append the open handler FreeCAD.addImportType("Web Page (*.html *.xhtml)", "WebGui") FreeCAD.__unit_test__ += [ "TestWebGui" ]
lgpl-2.1
[ 3, 17623, 202, 199, 15002, 257, 1898, 334, 67, 9, 14790, 12, 17919, 1603, 17709, 82, 2268, 820, 1873, 24920, 665, 74, 14262, 2268, 14, 11317, 24920, 32, 2520, 14, 271, 30, 260, 627, 202, 199, 15002, 17997, 627, 202, 199, 15002, 257, 961, 570, 365, 1777, 402, 314, 20914, 7240, 88, 16367, 2656, 14, 4519, 627, 202, 199, 15002, 17997, 627, 202, 199, 15002, 257, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 221, 627, 202, 199, 15002, 257, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 844, 334, 44, 12006, 9, 259, 627, 202, 199, 15002, 257, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 258, 627, 202, 199, 15002, 257, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 7861, 627, 202, 199, 15002, 257, 367, 10093, 1937, 314, 5059, 6013, 1318, 570, 14, 2476, 627, 202, 199, 15002, 17997, 627, 202, 199, 15002, 257, 20914, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 3322, 627, 202, 199, 15002, 257, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 263, 627, 202, 199, 15002, 257, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 260, 627, 202, 199, 15002, 257, 1664, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 7861, 627, 202, 199, 15002, 17997, 627, 202, 199, 15002, 257, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 11243, 1696, 1684, 258, 627, 202, 199, 15002, 257, 844, 3180, 543, 20914, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 263, 627, 202, 199, 15002, 257, 2752, 12, 3277, 2020, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 221, 15673, 13, 13421, 221, 627, 202, 199, 15002, 257, 8217, 6208, 257, 627, 202, 199, 3, 17623, 15, 2999, 199, 3, 6001, 11621, 4205, 859, 202, 199, 3, 202, 199, 3, 19634, 316, 1006, 314, 2556, 370, 1343, 20914, 202, 199, 3, 961, 365, 314, 3499, 1373, 402, 7795, 4205, 10554, 12, 314, 10919, 1373, 202, 199, 3, 7858, 1380, 314, 11621, 365, 1536, 8065, 199, 533, 6001, 6517, 16571, 334, 9361, 16571, 3461, 1128, 298, 5926, 1736, 16571, 909, 2, 1128, 347, 636, 826, 721, 277, 304, 1039, 291, 855, 533, 4343, 8954, 275, 20914, 14, 362, 4031, 3567, 342, 435, 298, 9871, 15, 5926, 15, 13745, 15, 16471, 15, 5926, 6517, 16571, 14, 10273, 2, 1039, 291, 855, 533, 4343, 5977, 1872, 275, 298, 5926, 2, 1039, 291, 855, 533, 4343, 21784, 275, 298, 5926, 1736, 16571, 2, 2958, 347, 11578, 8, 277, 304, 1039, 327, 2248, 314, 859, 1039, 492, 6001, 4324, 2958, 347, 2372, 23200, 8, 277, 304, 1039, 372, 298, 5926, 4324, 447, 6517, 16571, 2, 2999, 199, 4324, 14, 525, 6517, 16571, 8, 5926, 6517, 16571, 1012, 2999, 199, 3, 18726, 314, 1551, 3016, 202, 199, 10146, 17238, 14, 525, 6295, 804, 480, 5926, 10331, 334, 4856, 1360, 23588, 12909, 4186, 298, 5926, 4324, 531, 2999, 199, 10146, 17238, 855, 3248, 63, 396, 363, 847, 359, 298, 774, 5926, 4324, 2, 1622, 1223, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 17623, 202, 199, 15002, 257, 1898, 334, 67, 9, 14790, 12, 17919, 1603, 17709, 82, 2268, 820, 1873, 24920, 665, 74, 14262, 2268, 14, 11317, 24920, 32, 2520, 14, 271, 30, 260, 627, 202, 199, 15002, 17997, 627, 202, 199, 15002, 257, 961, 570, 365, 1777, 402, 314, 20914, 7240, 88, 16367, 2656, 14, 4519, 627, 202, 199, 15002, 17997, 627, 202, 199, 15002, 257, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 221, 627, 202, 199, 15002, 257, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 844, 334, 44, 12006, 9, 259, 627, 202, 199, 15002, 257, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 258, 627, 202, 199, 15002, 257, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 7861, 627, 202, 199, 15002, 257, 367, 10093, 1937, 314, 5059, 6013, 1318, 570, 14, 2476, 627, 202, 199, 15002, 17997, 627, 202, 199, 15002, 257, 20914, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 3322, 627, 202, 199, 15002, 257, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 263, 627, 202, 199, 15002, 257, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 260, 627, 202, 199, 15002, 257, 1664, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 7861, 627, 202, 199, 15002, 17997, 627, 202, 199, 15002, 257, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 11243, 1696, 1684, 258, 627, 202, 199, 15002, 257, 844, 3180, 543, 20914, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 263, 627, 202, 199, 15002, 257, 2752, 12, 3277, 2020, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 221, 15673, 13, 13421, 221, 627, 202, 199, 15002, 257, 8217, 6208, 257, 627, 202, 199, 3, 17623, 15, 2999, 199, 3, 6001, 11621, 4205, 859, 202, 199, 3, 202, 199, 3, 19634, 316, 1006, 314, 2556, 370, 1343, 20914, 202, 199, 3, 961, 365, 314, 3499, 1373, 402, 7795, 4205, 10554, 12, 314, 10919, 1373, 202, 199, 3, 7858, 1380, 314, 11621, 365, 1536, 8065, 199, 533, 6001, 6517, 16571, 334, 9361, 16571, 3461, 1128, 298, 5926, 1736, 16571, 909, 2, 1128, 347, 636, 826, 721, 277, 304, 1039, 291, 855, 533, 4343, 8954, 275, 20914, 14, 362, 4031, 3567, 342, 435, 298, 9871, 15, 5926, 15, 13745, 15, 16471, 15, 5926, 6517, 16571, 14, 10273, 2, 1039, 291, 855, 533, 4343, 5977, 1872, 275, 298, 5926, 2, 1039, 291, 855, 533, 4343, 21784, 275, 298, 5926, 1736, 16571, 2, 2958, 347, 11578, 8, 277, 304, 1039, 327, 2248, 314, 859, 1039, 492, 6001, 4324, 2958, 347, 2372, 23200, 8, 277, 304, 1039, 372, 298, 5926, 4324, 447, 6517, 16571, 2, 2999, 199, 4324, 14, 525, 6517, 16571, 8, 5926, 6517, 16571, 1012, 2999, 199, 3, 18726, 314, 1551, 3016, 202, 199, 10146, 17238, 14, 525, 6295, 804, 480, 5926, 10331, 334, 4856, 1360, 23588, 12909, 4186, 298, 5926, 4324, 531, 2999, 199, 10146, 17238, 855, 3248, 63, 396, 363, 847, 359, 298, 774, 5926, 4324, 2, 1622, 1223, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
foxwill/ol-api-tester
env/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/timeout.py
1004
9544
# The default socket timeout, used by httplib to indicate that no timeout was # specified by the user from socket import _GLOBAL_DEFAULT_TIMEOUT import time from ..exceptions import TimeoutStateError # A sentinel value to indicate that no timeout was specified by the user in # urllib3 _Default = object() def current_time(): """ Retrieve the current time. This function is mocked out in unit testing. """ return time.time() class Timeout(object): """ Timeout configuration. Timeouts can be defined as a default for a pool:: timeout = Timeout(connect=2.0, read=7.0) http = PoolManager(timeout=timeout) response = http.request('GET', 'http://example.com/') Or per-request (which overrides the default for the pool):: response = http.request('GET', 'http://example.com/', timeout=Timeout(10)) Timeouts can be disabled by setting all the parameters to ``None``:: no_timeout = Timeout(connect=None, read=None) response = http.request('GET', 'http://example.com/, timeout=no_timeout) :param total: This combines the connect and read timeouts into one; the read timeout will be set to the time leftover from the connect attempt. In the event that both a connect timeout and a total are specified, or a read timeout and a total are specified, the shorter timeout will be applied. Defaults to None. :type total: integer, float, or None :param connect: The maximum amount of time to wait for a connection attempt to a server to succeed. Omitting the parameter will default the connect timeout to the system default, probably `the global default timeout in socket.py <http://hg.python.org/cpython/file/603b4d593758/Lib/socket.py#l535>`_. None will set an infinite timeout for connection attempts. :type connect: integer, float, or None :param read: The maximum amount of time to wait between consecutive read operations for a response from the server. Omitting the parameter will default the read timeout to the system default, probably `the global default timeout in socket.py <http://hg.python.org/cpython/file/603b4d593758/Lib/socket.py#l535>`_. None will set an infinite timeout. :type read: integer, float, or None .. note:: Many factors can affect the total amount of time for urllib3 to return an HTTP response. For example, Python's DNS resolver does not obey the timeout specified on the socket. Other factors that can affect total request time include high CPU load, high swap, the program running at a low priority level, or other behaviors. In addition, the read and total timeouts only measure the time between read operations on the socket connecting the client and the server, not the total amount of time for the request to return a complete response. For most requests, the timeout is raised because the server has not sent the first byte in the specified time. This is not always the case; if a server streams one byte every fifteen seconds, a timeout of 20 seconds will not trigger, even though the request will take several minutes to complete. If your goal is to cut off any request after a set amount of wall clock time, consider having a second "watcher" thread to cut off a slow request. """ #: A sentinel object representing the default timeout value DEFAULT_TIMEOUT = _GLOBAL_DEFAULT_TIMEOUT def __init__(self, total=None, connect=_Default, read=_Default): self._connect = self._validate_timeout(connect, 'connect') self._read = self._validate_timeout(read, 'read') self.total = self._validate_timeout(total, 'total') self._start_connect = None def __str__(self): return '%s(connect=%r, read=%r, total=%r)' % ( type(self).__name__, self._connect, self._read, self.total) @classmethod def _validate_timeout(cls, value, name): """ Check that a timeout attribute is valid. :param value: The timeout value to validate :param name: The name of the timeout attribute to validate. This is used to specify in error messages. :return: The validated and casted version of the given value. :raises ValueError: If the type is not an integer or a float, or if it is a numeric value less than zero. """ if value is _Default: return cls.DEFAULT_TIMEOUT if value is None or value is cls.DEFAULT_TIMEOUT: return value try: float(value) except (TypeError, ValueError): raise ValueError("Timeout value %s was %s, but it must be an " "int or float." % (name, value)) try: if value < 0: raise ValueError("Attempted to set %s timeout to %s, but the " "timeout cannot be set to a value less " "than 0." % (name, value)) except TypeError: # Python 3 raise ValueError("Timeout value %s was %s, but it must be an " "int or float." % (name, value)) return value @classmethod def from_float(cls, timeout): """ Create a new Timeout from a legacy timeout value. The timeout value used by httplib.py sets the same timeout on the connect(), and recv() socket requests. This creates a :class:`Timeout` object that sets the individual timeouts to the ``timeout`` value passed to this function. :param timeout: The legacy timeout value. :type timeout: integer, float, sentinel default object, or None :return: Timeout object :rtype: :class:`Timeout` """ return Timeout(read=timeout, connect=timeout) def clone(self): """ Create a copy of the timeout object Timeout properties are stored per-pool but each request needs a fresh Timeout object to ensure each one has its own start/stop configured. :return: a copy of the timeout object :rtype: :class:`Timeout` """ # We can't use copy.deepcopy because that will also create a new object # for _GLOBAL_DEFAULT_TIMEOUT, which socket.py uses as a sentinel to # detect the user default. return Timeout(connect=self._connect, read=self._read, total=self.total) def start_connect(self): """ Start the timeout clock, used during a connect() attempt :raises urllib3.exceptions.TimeoutStateError: if you attempt to start a timer that has been started already. """ if self._start_connect is not None: raise TimeoutStateError("Timeout timer has already been started.") self._start_connect = current_time() return self._start_connect def get_connect_duration(self): """ Gets the time elapsed since the call to :meth:`start_connect`. :return: Elapsed time. :rtype: float :raises urllib3.exceptions.TimeoutStateError: if you attempt to get duration for a timer that hasn't been started. """ if self._start_connect is None: raise TimeoutStateError("Can't get connect duration for timer " "that has not started.") return current_time() - self._start_connect @property def connect_timeout(self): """ Get the value to use when setting a connection timeout. This will be a positive float or integer, the value None (never timeout), or the default system timeout. :return: Connect timeout. :rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None """ if self.total is None: return self._connect if self._connect is None or self._connect is self.DEFAULT_TIMEOUT: return self.total return min(self._connect, self.total) @property def read_timeout(self): """ Get the value for the read timeout. This assumes some time has elapsed in the connection timeout and computes the read timeout appropriately. If self.total is set, the read timeout is dependent on the amount of time taken by the connect timeout. If the connection time has not been established, a :exc:`~urllib3.exceptions.TimeoutStateError` will be raised. :return: Value to use for the read timeout. :rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None :raises urllib3.exceptions.TimeoutStateError: If :meth:`start_connect` has not yet been called on this object. """ if (self.total is not None and self.total is not self.DEFAULT_TIMEOUT and self._read is not None and self._read is not self.DEFAULT_TIMEOUT): # In case the connect timeout has not yet been established. if self._start_connect is None: return self._read return max(0, min(self.total - self.get_connect_duration(), self._read)) elif self.total is not None and self.total is not self.DEFAULT_TIMEOUT: return max(0, self.total - self.get_connect_duration()) else: return self._read
gpl-2.0
[ 3, 710, 849, 2838, 2653, 12, 1202, 701, 8809, 370, 6623, 626, 949, 2653, 1990, 199, 3, 2013, 701, 314, 922, 199, 504, 2838, 492, 485, 13808, 63, 3472, 63, 8899, 199, 646, 900, 199, 199, 504, 2508, 3924, 492, 12878, 2223, 547, 199, 199, 3, 437, 13792, 574, 370, 6623, 626, 949, 2653, 1990, 2013, 701, 314, 922, 315, 199, 3, 4011, 19, 199, 63, 2698, 275, 909, 342, 199, 199, 318, 1453, 63, 521, 837, 272, 408, 272, 13939, 314, 1453, 900, 14, 961, 805, 365, 16991, 734, 315, 4137, 5343, 14, 272, 408, 272, 372, 900, 14, 521, 342, 421, 199, 533, 12878, 8, 785, 304, 272, 408, 12878, 2897, 14, 339, 12878, 83, 883, 506, 3247, 465, 282, 849, 367, 282, 4203, 447, 398, 2653, 275, 12878, 8, 2242, 29, 18, 14, 16, 12, 1586, 29, 23, 14, 16, 9, 267, 1455, 275, 15553, 2988, 8, 2593, 29, 2593, 9, 267, 1177, 275, 1455, 14, 1069, 360, 2970, 297, 283, 1014, 921, 2694, 14, 957, 6217, 339, 4236, 1126, 13, 1069, 334, 6777, 10580, 314, 849, 367, 314, 4203, 304, 26, 398, 1177, 275, 1455, 14, 1069, 360, 2970, 297, 283, 1014, 921, 2694, 14, 957, 3678, 2653, 29, 6372, 8, 709, 430, 339, 12878, 83, 883, 506, 6980, 701, 4260, 1006, 314, 2633, 370, 1124, 403, 1040, 447, 398, 949, 63, 2593, 275, 12878, 8, 2242, 29, 403, 12, 1586, 29, 403, 9, 267, 1177, 275, 1455, 14, 1069, 360, 2970, 297, 283, 1014, 921, 2694, 14, 957, 15, 12, 2653, 29, 889, 63, 2593, 9, 2378, 520, 635, 3141, 26, 267, 961, 5300, 3746, 314, 4907, 436, 1586, 25870, 1901, 1373, 27, 314, 1586, 2653, 267, 911, 506, 663, 370, 314, 900, 32196, 687, 314, 4907, 7427, 14, 1010, 314, 267, 1566, 626, 3865, 282, 4907, 2653, 436, 282, 3141, 787, 2013, 12, 503, 282, 1586, 267, 2653, 436, 282, 3141, 787, 2013, 12, 314, 18299, 2653, 911, 506, 6781, 14, 398, 7827, 370, 488, 14, 339, 520, 466, 3141, 26, 3000, 12, 2069, 12, 503, 488, 339, 520, 635, 4907, 26, 267, 710, 5696, 5982, 402, 900, 370, 3618, 367, 282, 1950, 7427, 370, 282, 1654, 267, 370, 17961, 14, 593, 1147, 1337, 314, 2725, 911, 849, 314, 4907, 2653, 370, 267, 314, 2656, 849, 12, 8646, 658, 1589, 2288, 849, 2653, 315, 2838, 14, 647, 267, 665, 1014, 921, 9208, 14, 1548, 14, 1308, 15, 67, 1548, 15, 493, 15, 30877, 66, 20, 68, 1427, 1401, 2010, 15, 4728, 15, 3450, 14, 647, 3, 76, 7920, 8637, 3754, 267, 488, 911, 663, 376, 15258, 2653, 367, 1950, 12454, 14, 339, 520, 466, 4907, 26, 3000, 12, 2069, 12, 503, 488, 339, 520, 635, 1586, 26, 267, 710, 5696, 5982, 402, 900, 370, 3618, 3382, 23376, 267, 1586, 5331, 367, 282, 1177, 687, 314, 1654, 14, 593, 1147, 1337, 267, 314, 2725, 911, 849, 314, 1586, 2653, 370, 314, 2656, 267, 849, 12, 8646, 658, 1589, 2288, 849, 2653, 315, 2838, 14, 647, 267, 665, 1014, 921, 9208, 14, 1548, 14, 1308, 15, 67, 1548, 15, 493, 15, 30877, 66, 20, 68, 1427, 1401, 2010, 15, 4728, 15, 3450, 14, 647, 3, 76, 7920, 8637, 3754, 267, 488, 911, 663, 376, 15258, 2653, 14, 339, 520, 466, 1586, 26, 3000, 12, 2069, 12, 503, 488, 339, 2508, 5317, 447, 398, 15517, 17704, 883, 12787, 314, 3141, 5982, 402, 900, 367, 4011, 19, 370, 372, 267, 376, 3101, 1177, 14, 398, 2104, 2893, 12, 2018, 1159, 10237, 15611, 1630, 440, 312, 32236, 314, 2653, 2013, 267, 641, 314, 2838, 14, 5439, 17704, 626, 883, 12787, 3141, 1056, 900, 2387, 267, 4721, 11952, 2248, 12, 4721, 11413, 12, 314, 2240, 3879, 737, 282, 6465, 7464, 2166, 12, 267, 503, 1163, 5112, 1384, 14, 398, 1010, 10234, 12, 314, 1586, 436, 3141, 25870, 1454, 9775, 314, 900, 3382, 267, 1586, 5331, 641, 314, 2838, 18170, 314, 1890, 436, 314, 1654, 12, 267, 440, 314, 3141, 5982, 402, 900, 367, 314, 1056, 370, 372, 282, 4890, 267, 1177, 14, 2104, 4750, 4145, 12, 314, 2653, 365, 4915, 2952, 314, 1654, 267, 965, 440, 4847, 314, 1642, 3696, 315, 314, 2013, 900, 14, 961, 365, 440, 3544, 267, 314, 1930, 27, 340, 282, 1654, 13788, 1373, 3696, 4036, 289, 692, 25076, 4696, 12, 282, 2653, 267, 402, 3388, 4696, 911, 440, 6804, 12, 2755, 10617, 314, 1056, 911, 5452, 267, 9978, 9395, 370, 4890, 14, 398, 982, 2195, 14850, 365, 370, 10415, 2331, 1263, 1056, 2410, 282, 663, 5982, 402, 19882, 12516, 267, 900, 12, 11201, 9445, 282, 3499, 298, 22226, 2, 2462, 370, 10415, 2331, 282, 11999, 267, 1056, 14, 272, 408, 339, 6079, 437, 13792, 909, 6144, 314, 849, 2653, 574, 272, 6186, 63, 8899, 275, 485, 13808, 63, 3472, 63, 8899, 339, 347, 636, 826, 721, 277, 12, 3141, 29, 403, 12, 4907, 3699, 2698, 12, 1586, 3699, 2698, 304, 267, 291, 423, 2242, 275, 291, 423, 3502, 63, 2593, 8, 2242, 12, 283, 2242, 358, 267, 291, 423, 739, 275, 291, 423, 3502, 63, 2593, 8, 739, 12, 283, 739, 358, 267, 291, 14, 2923, 275, 291, 423, 3502, 63, 2593, 8, 2923, 12, 283, 2923, 358, 267, 291, 423, 928, 63, 2242, 275, 488, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 8, 2242, 2458, 82, 12, 1586, 2458, 82, 12, 3141, 2458, 82, 3171, 450, 334, 288, 730, 8, 277, 2843, 354, 3108, 291, 423, 2242, 12, 291, 423, 739, 12, 291, 14, 2923, 9, 339, 768, 3744, 272, 347, 485, 3502, 63, 2593, 8, 1886, 12, 574, 12, 536, 304, 267, 408, 2670, 626, 282, 2653, 2225, 365, 1686, 14, 398, 520, 635, 574, 26, 710, 2653, 574, 370, 4107, 267, 520, 635, 536, 26, 710, 536, 402, 314, 2653, 2225, 370, 4107, 14, 961, 365, 288, 1202, 370, 4165, 315, 1125, 3788, 14, 267, 520, 1107, 26, 710, 16468, 436, 14984, 471, 1015, 402, 314, 1627, 574, 14, 267, 520, 3536, 1722, 26, 982, 314, 730, 365, 440, 376, 3000, 503, 282, 2069, 12, 503, 340, 652, 288, 365, 282, 8950, 574, 6656, 2419, 4697, 14, 267, 408, 267, 340, 574 ]
[ 710, 849, 2838, 2653, 12, 1202, 701, 8809, 370, 6623, 626, 949, 2653, 1990, 199, 3, 2013, 701, 314, 922, 199, 504, 2838, 492, 485, 13808, 63, 3472, 63, 8899, 199, 646, 900, 199, 199, 504, 2508, 3924, 492, 12878, 2223, 547, 199, 199, 3, 437, 13792, 574, 370, 6623, 626, 949, 2653, 1990, 2013, 701, 314, 922, 315, 199, 3, 4011, 19, 199, 63, 2698, 275, 909, 342, 199, 199, 318, 1453, 63, 521, 837, 272, 408, 272, 13939, 314, 1453, 900, 14, 961, 805, 365, 16991, 734, 315, 4137, 5343, 14, 272, 408, 272, 372, 900, 14, 521, 342, 421, 199, 533, 12878, 8, 785, 304, 272, 408, 12878, 2897, 14, 339, 12878, 83, 883, 506, 3247, 465, 282, 849, 367, 282, 4203, 447, 398, 2653, 275, 12878, 8, 2242, 29, 18, 14, 16, 12, 1586, 29, 23, 14, 16, 9, 267, 1455, 275, 15553, 2988, 8, 2593, 29, 2593, 9, 267, 1177, 275, 1455, 14, 1069, 360, 2970, 297, 283, 1014, 921, 2694, 14, 957, 6217, 339, 4236, 1126, 13, 1069, 334, 6777, 10580, 314, 849, 367, 314, 4203, 304, 26, 398, 1177, 275, 1455, 14, 1069, 360, 2970, 297, 283, 1014, 921, 2694, 14, 957, 3678, 2653, 29, 6372, 8, 709, 430, 339, 12878, 83, 883, 506, 6980, 701, 4260, 1006, 314, 2633, 370, 1124, 403, 1040, 447, 398, 949, 63, 2593, 275, 12878, 8, 2242, 29, 403, 12, 1586, 29, 403, 9, 267, 1177, 275, 1455, 14, 1069, 360, 2970, 297, 283, 1014, 921, 2694, 14, 957, 15, 12, 2653, 29, 889, 63, 2593, 9, 2378, 520, 635, 3141, 26, 267, 961, 5300, 3746, 314, 4907, 436, 1586, 25870, 1901, 1373, 27, 314, 1586, 2653, 267, 911, 506, 663, 370, 314, 900, 32196, 687, 314, 4907, 7427, 14, 1010, 314, 267, 1566, 626, 3865, 282, 4907, 2653, 436, 282, 3141, 787, 2013, 12, 503, 282, 1586, 267, 2653, 436, 282, 3141, 787, 2013, 12, 314, 18299, 2653, 911, 506, 6781, 14, 398, 7827, 370, 488, 14, 339, 520, 466, 3141, 26, 3000, 12, 2069, 12, 503, 488, 339, 520, 635, 4907, 26, 267, 710, 5696, 5982, 402, 900, 370, 3618, 367, 282, 1950, 7427, 370, 282, 1654, 267, 370, 17961, 14, 593, 1147, 1337, 314, 2725, 911, 849, 314, 4907, 2653, 370, 267, 314, 2656, 849, 12, 8646, 658, 1589, 2288, 849, 2653, 315, 2838, 14, 647, 267, 665, 1014, 921, 9208, 14, 1548, 14, 1308, 15, 67, 1548, 15, 493, 15, 30877, 66, 20, 68, 1427, 1401, 2010, 15, 4728, 15, 3450, 14, 647, 3, 76, 7920, 8637, 3754, 267, 488, 911, 663, 376, 15258, 2653, 367, 1950, 12454, 14, 339, 520, 466, 4907, 26, 3000, 12, 2069, 12, 503, 488, 339, 520, 635, 1586, 26, 267, 710, 5696, 5982, 402, 900, 370, 3618, 3382, 23376, 267, 1586, 5331, 367, 282, 1177, 687, 314, 1654, 14, 593, 1147, 1337, 267, 314, 2725, 911, 849, 314, 1586, 2653, 370, 314, 2656, 267, 849, 12, 8646, 658, 1589, 2288, 849, 2653, 315, 2838, 14, 647, 267, 665, 1014, 921, 9208, 14, 1548, 14, 1308, 15, 67, 1548, 15, 493, 15, 30877, 66, 20, 68, 1427, 1401, 2010, 15, 4728, 15, 3450, 14, 647, 3, 76, 7920, 8637, 3754, 267, 488, 911, 663, 376, 15258, 2653, 14, 339, 520, 466, 1586, 26, 3000, 12, 2069, 12, 503, 488, 339, 2508, 5317, 447, 398, 15517, 17704, 883, 12787, 314, 3141, 5982, 402, 900, 367, 4011, 19, 370, 372, 267, 376, 3101, 1177, 14, 398, 2104, 2893, 12, 2018, 1159, 10237, 15611, 1630, 440, 312, 32236, 314, 2653, 2013, 267, 641, 314, 2838, 14, 5439, 17704, 626, 883, 12787, 3141, 1056, 900, 2387, 267, 4721, 11952, 2248, 12, 4721, 11413, 12, 314, 2240, 3879, 737, 282, 6465, 7464, 2166, 12, 267, 503, 1163, 5112, 1384, 14, 398, 1010, 10234, 12, 314, 1586, 436, 3141, 25870, 1454, 9775, 314, 900, 3382, 267, 1586, 5331, 641, 314, 2838, 18170, 314, 1890, 436, 314, 1654, 12, 267, 440, 314, 3141, 5982, 402, 900, 367, 314, 1056, 370, 372, 282, 4890, 267, 1177, 14, 2104, 4750, 4145, 12, 314, 2653, 365, 4915, 2952, 314, 1654, 267, 965, 440, 4847, 314, 1642, 3696, 315, 314, 2013, 900, 14, 961, 365, 440, 3544, 267, 314, 1930, 27, 340, 282, 1654, 13788, 1373, 3696, 4036, 289, 692, 25076, 4696, 12, 282, 2653, 267, 402, 3388, 4696, 911, 440, 6804, 12, 2755, 10617, 314, 1056, 911, 5452, 267, 9978, 9395, 370, 4890, 14, 398, 982, 2195, 14850, 365, 370, 10415, 2331, 1263, 1056, 2410, 282, 663, 5982, 402, 19882, 12516, 267, 900, 12, 11201, 9445, 282, 3499, 298, 22226, 2, 2462, 370, 10415, 2331, 282, 11999, 267, 1056, 14, 272, 408, 339, 6079, 437, 13792, 909, 6144, 314, 849, 2653, 574, 272, 6186, 63, 8899, 275, 485, 13808, 63, 3472, 63, 8899, 339, 347, 636, 826, 721, 277, 12, 3141, 29, 403, 12, 4907, 3699, 2698, 12, 1586, 3699, 2698, 304, 267, 291, 423, 2242, 275, 291, 423, 3502, 63, 2593, 8, 2242, 12, 283, 2242, 358, 267, 291, 423, 739, 275, 291, 423, 3502, 63, 2593, 8, 739, 12, 283, 739, 358, 267, 291, 14, 2923, 275, 291, 423, 3502, 63, 2593, 8, 2923, 12, 283, 2923, 358, 267, 291, 423, 928, 63, 2242, 275, 488, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 8, 2242, 2458, 82, 12, 1586, 2458, 82, 12, 3141, 2458, 82, 3171, 450, 334, 288, 730, 8, 277, 2843, 354, 3108, 291, 423, 2242, 12, 291, 423, 739, 12, 291, 14, 2923, 9, 339, 768, 3744, 272, 347, 485, 3502, 63, 2593, 8, 1886, 12, 574, 12, 536, 304, 267, 408, 2670, 626, 282, 2653, 2225, 365, 1686, 14, 398, 520, 635, 574, 26, 710, 2653, 574, 370, 4107, 267, 520, 635, 536, 26, 710, 536, 402, 314, 2653, 2225, 370, 4107, 14, 961, 365, 288, 1202, 370, 4165, 315, 1125, 3788, 14, 267, 520, 1107, 26, 710, 16468, 436, 14984, 471, 1015, 402, 314, 1627, 574, 14, 267, 520, 3536, 1722, 26, 982, 314, 730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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SectorLabs/django-postgres-extra
psqlextra/models/view.py
1
4455
from typing import Callable, Optional, Union from django.core.exceptions import ImproperlyConfigured from django.db import connections from django.db.models import Model from django.db.models.base import ModelBase from django.db.models.query import QuerySet from psqlextra.type_assertions import is_query_set, is_sql, is_sql_with_params from psqlextra.types import SQL, SQLWithParams from .base import PostgresModel from .options import PostgresViewOptions ViewQueryValue = Union[QuerySet, SQLWithParams, SQL] ViewQuery = Optional[Union[ViewQueryValue, Callable[[], ViewQueryValue]]] class PostgresViewModelMeta(ModelBase): """Custom meta class for :see:PostgresView and :see:PostgresMaterializedView. This meta class extracts attributes from the inner `ViewMeta` class and copies it onto a `_vew_meta` attribute. This is similar to how Django's `_meta` works. """ def __new__(cls, name, bases, attrs, **kwargs): new_class = super().__new__(cls, name, bases, attrs, **kwargs) meta_class = attrs.pop("ViewMeta", None) view_query = getattr(meta_class, "query", None) sql_with_params = cls._view_query_as_sql_with_params( new_class, view_query ) view_meta = PostgresViewOptions(query=sql_with_params) new_class.add_to_class("_view_meta", view_meta) return new_class @staticmethod def _view_query_as_sql_with_params( model: Model, view_query: ViewQuery ) -> Optional[SQLWithParams]: """Gets the query associated with the view as a raw SQL query with bind parameters. The query can be specified as a query set, raw SQL with params or without params. The query can also be specified as a callable which returns any of the above. When copying the meta options from the model, we convert any from the above to a raw SQL query with bind parameters. We do this is because it is what the SQL driver understands and we can easily serialize it into a migration. """ # might be a callable to support delayed imports view_query = view_query() if callable(view_query) else view_query # make sure we don't do a boolean check on query sets, # because that might evaluate the query set if not is_query_set(view_query) and not view_query: return None is_valid_view_query = ( is_query_set(view_query) or is_sql_with_params(view_query) or is_sql(view_query) ) if not is_valid_view_query: raise ImproperlyConfigured( ( "Model '%s' is not properly configured to be a view." " Set the `query` attribute on the `ViewMeta` class" " to be a valid `django.db.models.query.QuerySet`" " SQL string, or tuple of SQL string and params." ) % (model.__name__) ) # querysets can easily be converted into sql, params if is_query_set(view_query): return view_query.query.sql_with_params() # query was already specified in the target format if is_sql_with_params(view_query): return view_query return view_query, tuple() class PostgresViewModel(PostgresModel, metaclass=PostgresViewModelMeta): """Base class for creating a model that is a view.""" class Meta: abstract = True base_manager_name = "objects" class PostgresMaterializedViewModel( PostgresViewModel, metaclass=PostgresViewModelMeta ): """Base class for creating a model that is a materialized view.""" class Meta: abstract = True base_manager_name = "objects" @classmethod def refresh( cls, concurrently: bool = False, using: Optional[str] = None ) -> None: """Refreshes this materialized view. Arguments: concurrently: Whether to tell PostgreSQL to refresh this materialized view concurrently. using: Optionally, the name of the database connection to use for refreshing the materialized view. """ conn_name = using or "default" with connections[conn_name].schema_editor() as schema_editor: schema_editor.refresh_materialized_view_model(cls, concurrently)
mit
[ 504, 14090, 492, 16975, 12, 4879, 12, 15961, 199, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 697, 492, 6947, 199, 504, 1639, 14, 697, 14, 992, 492, 5822, 199, 504, 1639, 14, 697, 14, 992, 14, 1095, 492, 5822, 1563, 199, 504, 1639, 14, 697, 14, 992, 14, 1131, 492, 18397, 199, 199, 504, 299, 3526, 274, 400, 345, 14, 466, 63, 305, 13049, 492, 365, 63, 1131, 63, 409, 12, 365, 63, 3009, 12, 365, 63, 3009, 63, 1045, 63, 1162, 199, 504, 299, 3526, 274, 400, 345, 14, 1313, 492, 5385, 12, 5385, 3007, 6007, 199, 199, 504, 1275, 1095, 492, 7711, 7266, 1685, 199, 504, 1275, 1419, 492, 7711, 7266, 2768, 4558, 199, 199, 2768, 3227, 1110, 275, 15961, 59, 13689, 12, 5385, 3007, 6007, 12, 5385, 61, 199, 2768, 3227, 275, 4879, 59, 15540, 59, 2768, 3227, 1110, 12, 16975, 9046, 467, 10935, 3227, 1110, 20737, 421, 199, 533, 7711, 7266, 2768, 1685, 3396, 8, 1685, 1563, 304, 272, 408, 7223, 3404, 1021, 367, 520, 3239, 26, 6564, 7266, 2768, 436, 272, 520, 3239, 26, 6564, 7266, 15787, 1759, 2768, 14, 339, 961, 3404, 1021, 5536, 83, 3004, 687, 314, 6506, 272, 658, 2768, 3396, 64, 1021, 436, 6866, 652, 14602, 282, 18494, 432, 87, 63, 2024, 64, 272, 2225, 14, 961, 365, 8545, 370, 4212, 5634, 1159, 18494, 2024, 64, 5419, 14, 272, 408, 339, 347, 636, 1222, 721, 1886, 12, 536, 12, 9768, 12, 3290, 12, 1011, 958, 304, 267, 892, 63, 533, 275, 1613, 11027, 1222, 721, 1886, 12, 536, 12, 9768, 12, 3290, 12, 1011, 958, 9, 267, 3404, 63, 533, 275, 3290, 14, 1935, 480, 2768, 3396, 401, 488, 9, 398, 2455, 63, 1131, 275, 2519, 8, 2024, 63, 533, 12, 298, 1131, 401, 488, 9, 267, 3875, 63, 1045, 63, 1162, 275, 843, 423, 1345, 63, 1131, 63, 305, 63, 3009, 63, 1045, 63, 1162, 8, 288, 892, 63, 533, 12, 2455, 63, 1131, 267, 776, 398, 2455, 63, 2024, 275, 7711, 7266, 2768, 4558, 8, 1131, 29, 3009, 63, 1045, 63, 1162, 9, 267, 892, 63, 533, 14, 525, 63, 475, 63, 533, 11008, 1345, 63, 2024, 401, 2455, 63, 2024, 9, 267, 372, 892, 63, 533, 339, 768, 4639, 272, 347, 485, 1345, 63, 1131, 63, 305, 63, 3009, 63, 1045, 63, 1162, 8, 267, 1402, 26, 5822, 12, 2455, 63, 1131, 26, 10935, 3227, 272, 776, 1035, 4879, 59, 4657, 3007, 6007, 2189, 267, 408, 14426, 314, 1827, 4568, 543, 314, 2455, 465, 282, 3066, 5385, 1827, 543, 5398, 267, 2633, 14, 398, 710, 1827, 883, 506, 2013, 465, 282, 1827, 663, 12, 3066, 5385, 543, 1862, 267, 503, 1928, 1862, 14, 710, 1827, 883, 2597, 506, 2013, 465, 282, 4550, 267, 1314, 2529, 1263, 402, 314, 3432, 14, 398, 3979, 16743, 314, 3404, 1511, 687, 314, 1402, 12, 781, 3957, 1263, 267, 687, 314, 3432, 370, 282, 3066, 5385, 1827, 543, 5398, 2633, 14, 2136, 886, 267, 642, 365, 2952, 652, 365, 4052, 314, 5385, 5253, 1334, 26580, 436, 267, 781, 883, 16174, 8437, 652, 1901, 282, 8367, 14, 267, 408, 398, 327, 5594, 506, 282, 4550, 370, 2291, 24725, 8925, 267, 2455, 63, 1131, 275, 2455, 63, 1131, 342, 340, 4550, 8, 1345, 63, 1131, 9, 587, 2455, 63, 1131, 398, 327, 1852, 3238, 781, 2793, 1133, 886, 282, 5046, 1104, 641, 1827, 5951, 12, 267, 327, 2952, 626, 5594, 9352, 314, 1827, 663, 267, 340, 440, 365, 63, 1131, 63, 409, 8, 1345, 63, 1131, 9, 436, 440, 2455, 63, 1131, 26, 288, 372, 488, 398, 365, 63, 1078, 63, 1345, 63, 1131, 275, 334, 288, 365, 63, 1131, 63, 409, 8, 1345, 63, 1131, 9, 288, 503, 365, 63, 3009, 63, 1045, 63, 1162, 8, 1345, 63, 1131, 9, 288, 503, 365, 63, 3009, 8, 1345, 63, 1131, 9, 267, 776, 398, 340, 440, 365, 63, 1078, 63, 1345, 63, 1131, 26, 288, 746, 11897, 8, 355, 334, 490, 298, 1685, 1543, 83, 7, 365, 440, 7684, 7526, 370, 506, 282, 2455, 2122, 490, 298, 2494, 314, 658, 1131, 64, 2225, 641, 314, 658, 2768, 3396, 64, 1021, 2, 490, 298, 370, 506, 282, 1686, 658, 1176, 14, 697, 14, 992, 14, 1131, 14, 13689, 64, 2, 490, 298, 5385, 1059, 12, 503, 2008, 402, 5385, 1059, 436, 1862, 2122, 355, 776, 355, 450, 334, 1238, 855, 354, 3368, 288, 776, 398, 327, 1827, 2193, 883, 16174, 506, 6702, 1901, 3875, 12, 1862, 267, 340, 365, 63, 1131, 63, 409, 8, 1345, 63, 1131, 304, 288, 372, 2455, 63, 1131, 14, 1131, 14, 3009, 63, 1045, 63, 1162, 342, 398, 327, 1827, 1990, 2575, 2013, 315, 314, 1347, 1475, 267, 340, 365, 63, 3009, 63, 1045, 63, 1162, 8, 1345, 63, 1131, 304, 288, 372, 2455, 63, 1131, 398, 372, 2455, 63, 1131, 12, 2008, 342, 421, 199, 533, 7711, 7266, 2768, 1685, 8, 6564, 7266, 1685, 12, 17074, 29, 6564, 7266, 2768, 1685, 3396, 304, 272, 408, 1563, 1021, 367, 6425, 282, 1402, 626, 365, 282, 2455, 1041, 339, 1021, 6288, 26, 267, 9006, 275, 715, 267, 1300, 63, 2609, 63, 354, 275, 298, 1462, 2, 421, 199, 533, 7711, 7266, 15787, 1759, 2768, 1685, 8, 272, 7711, 7266, 2768, 1685, 12, 17074, 29, 6564, 7266, 2768, 1685, 3396, 199, 304, 272, 408, 1563, 1021, 367, 6425, 282, 1402, 626, 365, 282, 6285, 1759, 2455, 1041, 339, 1021, 6288, 26, 267, 9006, 275, 715, 267, 1300, 63, 2609, 63, 354, 275, 298, 1462, 2, 339, 768, 3744, 272, 347, 9236, 8, 267, 843, 12, 406, 19767, 26, 2155, 275, 756, 12, 1808, 26, 4879, 59, 495, 61, 275, 488, 272, 776, 1035, 488, 26, 267, 408, 18730, 397, 642, 6285, 1759, 2455, 14, 398, 7628, 26, 288, 406, 19767, 26, 355, 7480, 370, 11480, 20175, 370, 9236, 642, 355, 6285, 1759, 2455, 406, 19767, 14, 953, 1808, 26, 355, 22383, 12, 314, 536, 402, 314, 3050, 1950, 355, 370, 675, 367, 9236, 316, 314, 6285, 1759, 2455, 14, 267, 408, 398, 2557, 63, 354, 275, 1808, 503, 298, 885, 2, 398, 543, 6947, 59, 1631, 63, 354, 1055, 3629, 63 ]
[ 14090, 492, 16975, 12, 4879, 12, 15961, 199, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 697, 492, 6947, 199, 504, 1639, 14, 697, 14, 992, 492, 5822, 199, 504, 1639, 14, 697, 14, 992, 14, 1095, 492, 5822, 1563, 199, 504, 1639, 14, 697, 14, 992, 14, 1131, 492, 18397, 199, 199, 504, 299, 3526, 274, 400, 345, 14, 466, 63, 305, 13049, 492, 365, 63, 1131, 63, 409, 12, 365, 63, 3009, 12, 365, 63, 3009, 63, 1045, 63, 1162, 199, 504, 299, 3526, 274, 400, 345, 14, 1313, 492, 5385, 12, 5385, 3007, 6007, 199, 199, 504, 1275, 1095, 492, 7711, 7266, 1685, 199, 504, 1275, 1419, 492, 7711, 7266, 2768, 4558, 199, 199, 2768, 3227, 1110, 275, 15961, 59, 13689, 12, 5385, 3007, 6007, 12, 5385, 61, 199, 2768, 3227, 275, 4879, 59, 15540, 59, 2768, 3227, 1110, 12, 16975, 9046, 467, 10935, 3227, 1110, 20737, 421, 199, 533, 7711, 7266, 2768, 1685, 3396, 8, 1685, 1563, 304, 272, 408, 7223, 3404, 1021, 367, 520, 3239, 26, 6564, 7266, 2768, 436, 272, 520, 3239, 26, 6564, 7266, 15787, 1759, 2768, 14, 339, 961, 3404, 1021, 5536, 83, 3004, 687, 314, 6506, 272, 658, 2768, 3396, 64, 1021, 436, 6866, 652, 14602, 282, 18494, 432, 87, 63, 2024, 64, 272, 2225, 14, 961, 365, 8545, 370, 4212, 5634, 1159, 18494, 2024, 64, 5419, 14, 272, 408, 339, 347, 636, 1222, 721, 1886, 12, 536, 12, 9768, 12, 3290, 12, 1011, 958, 304, 267, 892, 63, 533, 275, 1613, 11027, 1222, 721, 1886, 12, 536, 12, 9768, 12, 3290, 12, 1011, 958, 9, 267, 3404, 63, 533, 275, 3290, 14, 1935, 480, 2768, 3396, 401, 488, 9, 398, 2455, 63, 1131, 275, 2519, 8, 2024, 63, 533, 12, 298, 1131, 401, 488, 9, 267, 3875, 63, 1045, 63, 1162, 275, 843, 423, 1345, 63, 1131, 63, 305, 63, 3009, 63, 1045, 63, 1162, 8, 288, 892, 63, 533, 12, 2455, 63, 1131, 267, 776, 398, 2455, 63, 2024, 275, 7711, 7266, 2768, 4558, 8, 1131, 29, 3009, 63, 1045, 63, 1162, 9, 267, 892, 63, 533, 14, 525, 63, 475, 63, 533, 11008, 1345, 63, 2024, 401, 2455, 63, 2024, 9, 267, 372, 892, 63, 533, 339, 768, 4639, 272, 347, 485, 1345, 63, 1131, 63, 305, 63, 3009, 63, 1045, 63, 1162, 8, 267, 1402, 26, 5822, 12, 2455, 63, 1131, 26, 10935, 3227, 272, 776, 1035, 4879, 59, 4657, 3007, 6007, 2189, 267, 408, 14426, 314, 1827, 4568, 543, 314, 2455, 465, 282, 3066, 5385, 1827, 543, 5398, 267, 2633, 14, 398, 710, 1827, 883, 506, 2013, 465, 282, 1827, 663, 12, 3066, 5385, 543, 1862, 267, 503, 1928, 1862, 14, 710, 1827, 883, 2597, 506, 2013, 465, 282, 4550, 267, 1314, 2529, 1263, 402, 314, 3432, 14, 398, 3979, 16743, 314, 3404, 1511, 687, 314, 1402, 12, 781, 3957, 1263, 267, 687, 314, 3432, 370, 282, 3066, 5385, 1827, 543, 5398, 2633, 14, 2136, 886, 267, 642, 365, 2952, 652, 365, 4052, 314, 5385, 5253, 1334, 26580, 436, 267, 781, 883, 16174, 8437, 652, 1901, 282, 8367, 14, 267, 408, 398, 327, 5594, 506, 282, 4550, 370, 2291, 24725, 8925, 267, 2455, 63, 1131, 275, 2455, 63, 1131, 342, 340, 4550, 8, 1345, 63, 1131, 9, 587, 2455, 63, 1131, 398, 327, 1852, 3238, 781, 2793, 1133, 886, 282, 5046, 1104, 641, 1827, 5951, 12, 267, 327, 2952, 626, 5594, 9352, 314, 1827, 663, 267, 340, 440, 365, 63, 1131, 63, 409, 8, 1345, 63, 1131, 9, 436, 440, 2455, 63, 1131, 26, 288, 372, 488, 398, 365, 63, 1078, 63, 1345, 63, 1131, 275, 334, 288, 365, 63, 1131, 63, 409, 8, 1345, 63, 1131, 9, 288, 503, 365, 63, 3009, 63, 1045, 63, 1162, 8, 1345, 63, 1131, 9, 288, 503, 365, 63, 3009, 8, 1345, 63, 1131, 9, 267, 776, 398, 340, 440, 365, 63, 1078, 63, 1345, 63, 1131, 26, 288, 746, 11897, 8, 355, 334, 490, 298, 1685, 1543, 83, 7, 365, 440, 7684, 7526, 370, 506, 282, 2455, 2122, 490, 298, 2494, 314, 658, 1131, 64, 2225, 641, 314, 658, 2768, 3396, 64, 1021, 2, 490, 298, 370, 506, 282, 1686, 658, 1176, 14, 697, 14, 992, 14, 1131, 14, 13689, 64, 2, 490, 298, 5385, 1059, 12, 503, 2008, 402, 5385, 1059, 436, 1862, 2122, 355, 776, 355, 450, 334, 1238, 855, 354, 3368, 288, 776, 398, 327, 1827, 2193, 883, 16174, 506, 6702, 1901, 3875, 12, 1862, 267, 340, 365, 63, 1131, 63, 409, 8, 1345, 63, 1131, 304, 288, 372, 2455, 63, 1131, 14, 1131, 14, 3009, 63, 1045, 63, 1162, 342, 398, 327, 1827, 1990, 2575, 2013, 315, 314, 1347, 1475, 267, 340, 365, 63, 3009, 63, 1045, 63, 1162, 8, 1345, 63, 1131, 304, 288, 372, 2455, 63, 1131, 398, 372, 2455, 63, 1131, 12, 2008, 342, 421, 199, 533, 7711, 7266, 2768, 1685, 8, 6564, 7266, 1685, 12, 17074, 29, 6564, 7266, 2768, 1685, 3396, 304, 272, 408, 1563, 1021, 367, 6425, 282, 1402, 626, 365, 282, 2455, 1041, 339, 1021, 6288, 26, 267, 9006, 275, 715, 267, 1300, 63, 2609, 63, 354, 275, 298, 1462, 2, 421, 199, 533, 7711, 7266, 15787, 1759, 2768, 1685, 8, 272, 7711, 7266, 2768, 1685, 12, 17074, 29, 6564, 7266, 2768, 1685, 3396, 199, 304, 272, 408, 1563, 1021, 367, 6425, 282, 1402, 626, 365, 282, 6285, 1759, 2455, 1041, 339, 1021, 6288, 26, 267, 9006, 275, 715, 267, 1300, 63, 2609, 63, 354, 275, 298, 1462, 2, 339, 768, 3744, 272, 347, 9236, 8, 267, 843, 12, 406, 19767, 26, 2155, 275, 756, 12, 1808, 26, 4879, 59, 495, 61, 275, 488, 272, 776, 1035, 488, 26, 267, 408, 18730, 397, 642, 6285, 1759, 2455, 14, 398, 7628, 26, 288, 406, 19767, 26, 355, 7480, 370, 11480, 20175, 370, 9236, 642, 355, 6285, 1759, 2455, 406, 19767, 14, 953, 1808, 26, 355, 22383, 12, 314, 536, 402, 314, 3050, 1950, 355, 370, 675, 367, 9236, 316, 314, 6285, 1759, 2455, 14, 267, 408, 398, 2557, 63, 354, 275, 1808, 503, 298, 885, 2, 398, 543, 6947, 59, 1631, 63, 354, 1055, 3629, 63, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
Titulacion-Sistemas/PythonTitulacion-EV
Lib/site-packages/pywin32-219-py2.7-win32.egg/mmsystem.py
24
30521
# Generated by h2py from d:/msdev/include/mmsystem.h MAXPNAMELEN = 32 MAXERRORLENGTH = 256 MAX_JOYSTICKOEMVXDNAME = 260 MM_MICROSOFT = 1 MM_MIDI_MAPPER = 1 MM_WAVE_MAPPER = 2 MM_SNDBLST_MIDIOUT = 3 MM_SNDBLST_MIDIIN = 4 MM_SNDBLST_SYNTH = 5 MM_SNDBLST_WAVEOUT = 6 MM_SNDBLST_WAVEIN = 7 MM_ADLIB = 9 MM_MPU401_MIDIOUT = 10 MM_MPU401_MIDIIN = 11 MM_PC_JOYSTICK = 12 TIME_MS = 0x0001 TIME_SAMPLES = 0x0002 TIME_BYTES = 0x0004 TIME_SMPTE = 0x0008 TIME_MIDI = 0x0010 TIME_TICKS = 0x0020 MM_JOY1MOVE = 0x3A0 MM_JOY2MOVE = 0x3A1 MM_JOY1ZMOVE = 0x3A2 MM_JOY2ZMOVE = 0x3A3 MM_JOY1BUTTONDOWN = 0x3B5 MM_JOY2BUTTONDOWN = 0x3B6 MM_JOY1BUTTONUP = 0x3B7 MM_JOY2BUTTONUP = 0x3B8 MM_MCINOTIFY = 0x3B9 MM_WOM_OPEN = 0x3BB MM_WOM_CLOSE = 0x3BC MM_WOM_DONE = 0x3BD MM_WIM_OPEN = 0x3BE MM_WIM_CLOSE = 0x3BF MM_WIM_DATA = 0x3C0 MM_MIM_OPEN = 0x3C1 MM_MIM_CLOSE = 0x3C2 MM_MIM_DATA = 0x3C3 MM_MIM_LONGDATA = 0x3C4 MM_MIM_ERROR = 0x3C5 MM_MIM_LONGERROR = 0x3C6 MM_MOM_OPEN = 0x3C7 MM_MOM_CLOSE = 0x3C8 MM_MOM_DONE = 0x3C9 MM_STREAM_OPEN = 0x3D4 MM_STREAM_CLOSE = 0x3D5 MM_STREAM_DONE = 0x3D6 MM_STREAM_ERROR = 0x3D7 MM_MOM_POSITIONCB = 0x3CA MM_MIM_MOREDATA = 0x3CC MM_MIXM_LINE_CHANGE = 0x3D0 MM_MIXM_CONTROL_CHANGE = 0x3D1 MMSYSERR_BASE = 0 WAVERR_BASE = 32 MIDIERR_BASE = 64 TIMERR_BASE = 96 JOYERR_BASE = 160 MCIERR_BASE = 256 MIXERR_BASE = 1024 MCI_STRING_OFFSET = 512 MCI_VD_OFFSET = 1024 MCI_CD_OFFSET = 1088 MCI_WAVE_OFFSET = 1152 MCI_SEQ_OFFSET = 1216 MMSYSERR_NOERROR = 0 MMSYSERR_ERROR = (MMSYSERR_BASE + 1) MMSYSERR_BADDEVICEID = (MMSYSERR_BASE + 2) MMSYSERR_NOTENABLED = (MMSYSERR_BASE + 3) MMSYSERR_ALLOCATED = (MMSYSERR_BASE + 4) MMSYSERR_INVALHANDLE = (MMSYSERR_BASE + 5) MMSYSERR_NODRIVER = (MMSYSERR_BASE + 6) MMSYSERR_NOMEM = (MMSYSERR_BASE + 7) MMSYSERR_NOTSUPPORTED = (MMSYSERR_BASE + 8) MMSYSERR_BADERRNUM = (MMSYSERR_BASE + 9) MMSYSERR_INVALFLAG = (MMSYSERR_BASE + 10) MMSYSERR_INVALPARAM = (MMSYSERR_BASE + 11) MMSYSERR_HANDLEBUSY = (MMSYSERR_BASE + 12) MMSYSERR_INVALIDALIAS = (MMSYSERR_BASE + 13) MMSYSERR_BADDB = (MMSYSERR_BASE + 14) MMSYSERR_KEYNOTFOUND = (MMSYSERR_BASE + 15) MMSYSERR_READERROR = (MMSYSERR_BASE + 16) MMSYSERR_WRITEERROR = (MMSYSERR_BASE + 17) MMSYSERR_DELETEERROR = (MMSYSERR_BASE + 18) MMSYSERR_VALNOTFOUND = (MMSYSERR_BASE + 19) MMSYSERR_NODRIVERCB = (MMSYSERR_BASE + 20) MMSYSERR_LASTERROR = (MMSYSERR_BASE + 20) DRV_LOAD = 0x0001 DRV_ENABLE = 0x0002 DRV_OPEN = 0x0003 DRV_CLOSE = 0x0004 DRV_DISABLE = 0x0005 DRV_FREE = 0x0006 DRV_CONFIGURE = 0x0007 DRV_QUERYCONFIGURE = 0x0008 DRV_INSTALL = 0x0009 DRV_REMOVE = 0x000A DRV_EXITSESSION = 0x000B DRV_POWER = 0x000F DRV_RESERVED = 0x0800 DRV_USER = 0x4000 DRVCNF_CANCEL = 0x0000 DRVCNF_OK = 0x0001 DRVCNF_RESTART = 0x0002 DRV_CANCEL = DRVCNF_CANCEL DRV_OK = DRVCNF_OK DRV_RESTART = DRVCNF_RESTART DRV_MCI_FIRST = DRV_RESERVED DRV_MCI_LAST = (DRV_RESERVED + 0xFFF) CALLBACK_TYPEMASK = 0x00070000 CALLBACK_NULL = 0x00000000 CALLBACK_WINDOW = 0x00010000 CALLBACK_TASK = 0x00020000 CALLBACK_FUNCTION = 0x00030000 CALLBACK_THREAD = (CALLBACK_TASK) CALLBACK_EVENT = 0x00050000 SND_SYNC = 0x0000 SND_ASYNC = 0x0001 SND_NODEFAULT = 0x0002 SND_MEMORY = 0x0004 SND_LOOP = 0x0008 SND_NOSTOP = 0x0010 SND_NOWAIT = 0x00002000 SND_ALIAS = 0x00010000 SND_ALIAS_ID = 0x00110000 SND_FILENAME = 0x00020000 SND_RESOURCE = 0x00040004 SND_PURGE = 0x0040 SND_APPLICATION = 0x0080 SND_ALIAS_START = 0 WAVERR_BADFORMAT = (WAVERR_BASE + 0) WAVERR_STILLPLAYING = (WAVERR_BASE + 1) WAVERR_UNPREPARED = (WAVERR_BASE + 2) WAVERR_SYNC = (WAVERR_BASE + 3) WAVERR_LASTERROR = (WAVERR_BASE + 3) WOM_OPEN = MM_WOM_OPEN WOM_CLOSE = MM_WOM_CLOSE WOM_DONE = MM_WOM_DONE WIM_OPEN = MM_WIM_OPEN WIM_CLOSE = MM_WIM_CLOSE WIM_DATA = MM_WIM_DATA WAVE_MAPPER = -1 # 0xFFFFFFFF WAVE_FORMAT_QUERY = 0x0001 WAVE_ALLOWSYNC = 0x0002 WAVE_MAPPED = 0x0004 WAVE_FORMAT_DIRECT = 0x0008 WAVE_FORMAT_DIRECT_QUERY = (WAVE_FORMAT_QUERY | WAVE_FORMAT_DIRECT) WHDR_DONE = 0x00000001 WHDR_PREPARED = 0x00000002 WHDR_BEGINLOOP = 0x00000004 WHDR_ENDLOOP = 0x00000008 WHDR_INQUEUE = 0x00000010 WAVECAPS_PITCH = 0x0001 WAVECAPS_PLAYBACKRATE = 0x0002 WAVECAPS_VOLUME = 0x0004 WAVECAPS_LRVOLUME = 0x0008 WAVECAPS_SYNC = 0x0010 WAVECAPS_SAMPLEACCURATE = 0x0020 WAVECAPS_DIRECTSOUND = 0x0040 WAVE_INVALIDFORMAT = 0x00000000 WAVE_FORMAT_1M08 = 0x00000001 WAVE_FORMAT_1S08 = 0x00000002 WAVE_FORMAT_1M16 = 0x00000004 WAVE_FORMAT_1S16 = 0x00000008 WAVE_FORMAT_2M08 = 0x00000010 WAVE_FORMAT_2S08 = 0x00000020 WAVE_FORMAT_2M16 = 0x00000040 WAVE_FORMAT_2S16 = 0x00000080 WAVE_FORMAT_4M08 = 0x00000100 WAVE_FORMAT_4S08 = 0x00000200 WAVE_FORMAT_4M16 = 0x00000400 WAVE_FORMAT_4S16 = 0x00000800 WAVE_FORMAT_PCM = 1 WAVE_FORMAT_IEEE_FLOAT = 3 MIDIERR_UNPREPARED = (MIDIERR_BASE + 0) MIDIERR_STILLPLAYING = (MIDIERR_BASE + 1) MIDIERR_NOMAP = (MIDIERR_BASE + 2) MIDIERR_NOTREADY = (MIDIERR_BASE + 3) MIDIERR_NODEVICE = (MIDIERR_BASE + 4) MIDIERR_INVALIDSETUP = (MIDIERR_BASE + 5) MIDIERR_BADOPENMODE = (MIDIERR_BASE + 6) MIDIERR_DONT_CONTINUE = (MIDIERR_BASE + 7) MIDIERR_LASTERROR = (MIDIERR_BASE + 7) MIDIPATCHSIZE = 128 MIM_OPEN = MM_MIM_OPEN MIM_CLOSE = MM_MIM_CLOSE MIM_DATA = MM_MIM_DATA MIM_LONGDATA = MM_MIM_LONGDATA MIM_ERROR = MM_MIM_ERROR MIM_LONGERROR = MM_MIM_LONGERROR MOM_OPEN = MM_MOM_OPEN MOM_CLOSE = MM_MOM_CLOSE MOM_DONE = MM_MOM_DONE MIM_MOREDATA = MM_MIM_MOREDATA MOM_POSITIONCB = MM_MOM_POSITIONCB MIDI_IO_STATUS = 0x00000020 MIDI_CACHE_ALL = 1 MIDI_CACHE_BESTFIT = 2 MIDI_CACHE_QUERY = 3 MIDI_UNCACHE = 4 MOD_MIDIPORT = 1 MOD_SYNTH = 2 MOD_SQSYNTH = 3 MOD_FMSYNTH = 4 MOD_MAPPER = 5 MIDICAPS_VOLUME = 0x0001 MIDICAPS_LRVOLUME = 0x0002 MIDICAPS_CACHE = 0x0004 MIDICAPS_STREAM = 0x0008 MHDR_DONE = 0x00000001 MHDR_PREPARED = 0x00000002 MHDR_INQUEUE = 0x00000004 MHDR_ISSTRM = 0x00000008 MEVT_F_SHORT = 0x00000000 MEVT_F_LONG = -2147483648 # 0x80000000 MEVT_F_CALLBACK = 0x40000000 def MEVT_EVENTTYPE(x): return ((BYTE)(((x)>>24)&0xFF)) def MEVT_EVENTPARM(x): return ((DWORD)((x)&0x00FFFFFF)) MIDISTRM_ERROR = (-2) MIDIPROP_SET = -2147483648 # 0x80000000 MIDIPROP_GET = 0x40000000 MIDIPROP_TIMEDIV = 0x00000001 MIDIPROP_TEMPO = 0x00000002 AUXCAPS_CDAUDIO = 1 AUXCAPS_AUXIN = 2 AUXCAPS_VOLUME = 0x0001 AUXCAPS_LRVOLUME = 0x0002 MIXER_SHORT_NAME_CHARS = 16 MIXER_LONG_NAME_CHARS = 64 MIXERR_INVALLINE = (MIXERR_BASE + 0) MIXERR_INVALCONTROL = (MIXERR_BASE + 1) MIXERR_INVALVALUE = (MIXERR_BASE + 2) MIXERR_LASTERROR = (MIXERR_BASE + 2) MIXER_OBJECTF_HANDLE = -2147483648 # 0x80000000 MIXER_OBJECTF_MIXER = 0x00000000 MIXER_OBJECTF_HMIXER = (MIXER_OBJECTF_HANDLE|MIXER_OBJECTF_MIXER) MIXER_OBJECTF_WAVEOUT = 0x10000000 MIXER_OBJECTF_HWAVEOUT = (MIXER_OBJECTF_HANDLE|MIXER_OBJECTF_WAVEOUT) MIXER_OBJECTF_WAVEIN = 0x20000000 MIXER_OBJECTF_HWAVEIN = (MIXER_OBJECTF_HANDLE|MIXER_OBJECTF_WAVEIN) MIXER_OBJECTF_MIDIOUT = 0x30000000 MIXER_OBJECTF_HMIDIOUT = (MIXER_OBJECTF_HANDLE|MIXER_OBJECTF_MIDIOUT) MIXER_OBJECTF_MIDIIN = 0x40000000 MIXER_OBJECTF_HMIDIIN = (MIXER_OBJECTF_HANDLE|MIXER_OBJECTF_MIDIIN) MIXER_OBJECTF_AUX = 0x50000000 MIXERLINE_LINEF_ACTIVE = 0x00000001 MIXERLINE_LINEF_DISCONNECTED = 0x00008000 MIXERLINE_LINEF_SOURCE = -2147483648 # 0x80000000 MIXERLINE_COMPONENTTYPE_DST_FIRST = 0x00000000 MIXERLINE_COMPONENTTYPE_DST_UNDEFINED = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 0) MIXERLINE_COMPONENTTYPE_DST_DIGITAL = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 1) MIXERLINE_COMPONENTTYPE_DST_LINE = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 2) MIXERLINE_COMPONENTTYPE_DST_MONITOR = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 3) MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4) MIXERLINE_COMPONENTTYPE_DST_HEADPHONES = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 5) MIXERLINE_COMPONENTTYPE_DST_TELEPHONE = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 6) MIXERLINE_COMPONENTTYPE_DST_WAVEIN = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 7) MIXERLINE_COMPONENTTYPE_DST_VOICEIN = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 8) MIXERLINE_COMPONENTTYPE_DST_LAST = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 8) MIXERLINE_COMPONENTTYPE_SRC_FIRST = 0x00001000 MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 0) MIXERLINE_COMPONENTTYPE_SRC_DIGITAL = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 1) MIXERLINE_COMPONENTTYPE_SRC_LINE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2) MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3) MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 4) MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 5) MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 6) MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 7) MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 8) MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 9) MIXERLINE_COMPONENTTYPE_SRC_ANALOG = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 10) MIXERLINE_COMPONENTTYPE_SRC_LAST = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 10) MIXERLINE_TARGETTYPE_UNDEFINED = 0 MIXERLINE_TARGETTYPE_WAVEOUT = 1 MIXERLINE_TARGETTYPE_WAVEIN = 2 MIXERLINE_TARGETTYPE_MIDIOUT = 3 MIXERLINE_TARGETTYPE_MIDIIN = 4 MIXERLINE_TARGETTYPE_AUX = 5 MIXER_GETLINEINFOF_DESTINATION = 0x00000000 MIXER_GETLINEINFOF_SOURCE = 0x00000001 MIXER_GETLINEINFOF_LINEID = 0x00000002 MIXER_GETLINEINFOF_COMPONENTTYPE = 0x00000003 MIXER_GETLINEINFOF_TARGETTYPE = 0x00000004 MIXER_GETLINEINFOF_QUERYMASK = 0x0000000F MIXERCONTROL_CONTROLF_UNIFORM = 0x00000001 MIXERCONTROL_CONTROLF_MULTIPLE = 0x00000002 MIXERCONTROL_CONTROLF_DISABLED = -2147483648 # 0x80000000 MIXERCONTROL_CT_CLASS_MASK = -268435456 # 0xF0000000 MIXERCONTROL_CT_CLASS_CUSTOM = 0x00000000 MIXERCONTROL_CT_CLASS_METER = 0x10000000 MIXERCONTROL_CT_CLASS_SWITCH = 0x20000000 MIXERCONTROL_CT_CLASS_NUMBER = 0x30000000 MIXERCONTROL_CT_CLASS_SLIDER = 0x40000000 MIXERCONTROL_CT_CLASS_FADER = 0x50000000 MIXERCONTROL_CT_CLASS_TIME = 0x60000000 MIXERCONTROL_CT_CLASS_LIST = 0x70000000 MIXERCONTROL_CT_SUBCLASS_MASK = 0x0F000000 MIXERCONTROL_CT_SC_SWITCH_BOOLEAN = 0x00000000 MIXERCONTROL_CT_SC_SWITCH_BUTTON = 0x01000000 MIXERCONTROL_CT_SC_METER_POLLED = 0x00000000 MIXERCONTROL_CT_SC_TIME_MICROSECS = 0x00000000 MIXERCONTROL_CT_SC_TIME_MILLISECS = 0x01000000 MIXERCONTROL_CT_SC_LIST_SINGLE = 0x00000000 MIXERCONTROL_CT_SC_LIST_MULTIPLE = 0x01000000 MIXERCONTROL_CT_UNITS_MASK = 0x00FF0000 MIXERCONTROL_CT_UNITS_CUSTOM = 0x00000000 MIXERCONTROL_CT_UNITS_BOOLEAN = 0x00010000 MIXERCONTROL_CT_UNITS_SIGNED = 0x00020000 MIXERCONTROL_CT_UNITS_UNSIGNED = 0x00030000 MIXERCONTROL_CT_UNITS_DECIBELS = 0x00040000 MIXERCONTROL_CT_UNITS_PERCENT = 0x00050000 MIXERCONTROL_CONTROLTYPE_CUSTOM = (MIXERCONTROL_CT_CLASS_CUSTOM | MIXERCONTROL_CT_UNITS_CUSTOM) MIXERCONTROL_CONTROLTYPE_BOOLEANMETER = (MIXERCONTROL_CT_CLASS_METER | MIXERCONTROL_CT_SC_METER_POLLED | MIXERCONTROL_CT_UNITS_BOOLEAN) MIXERCONTROL_CONTROLTYPE_SIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER | MIXERCONTROL_CT_SC_METER_POLLED | MIXERCONTROL_CT_UNITS_SIGNED) MIXERCONTROL_CONTROLTYPE_PEAKMETER = (MIXERCONTROL_CONTROLTYPE_SIGNEDMETER + 1) MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER | MIXERCONTROL_CT_SC_METER_POLLED | MIXERCONTROL_CT_UNITS_UNSIGNED) MIXERCONTROL_CONTROLTYPE_BOOLEAN = (MIXERCONTROL_CT_CLASS_SWITCH | MIXERCONTROL_CT_SC_SWITCH_BOOLEAN | MIXERCONTROL_CT_UNITS_BOOLEAN) MIXERCONTROL_CONTROLTYPE_ONOFF = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 1) MIXERCONTROL_CONTROLTYPE_MUTE = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 2) MIXERCONTROL_CONTROLTYPE_MONO = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 3) MIXERCONTROL_CONTROLTYPE_LOUDNESS = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 4) MIXERCONTROL_CONTROLTYPE_STEREOENH = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 5) MIXERCONTROL_CONTROLTYPE_BUTTON = (MIXERCONTROL_CT_CLASS_SWITCH | MIXERCONTROL_CT_SC_SWITCH_BUTTON | MIXERCONTROL_CT_UNITS_BOOLEAN) MIXERCONTROL_CONTROLTYPE_DECIBELS = (MIXERCONTROL_CT_CLASS_NUMBER | MIXERCONTROL_CT_UNITS_DECIBELS) MIXERCONTROL_CONTROLTYPE_SIGNED = (MIXERCONTROL_CT_CLASS_NUMBER | MIXERCONTROL_CT_UNITS_SIGNED) MIXERCONTROL_CONTROLTYPE_UNSIGNED = (MIXERCONTROL_CT_CLASS_NUMBER | MIXERCONTROL_CT_UNITS_UNSIGNED) MIXERCONTROL_CONTROLTYPE_PERCENT = (MIXERCONTROL_CT_CLASS_NUMBER | MIXERCONTROL_CT_UNITS_PERCENT) MIXERCONTROL_CONTROLTYPE_SLIDER = (MIXERCONTROL_CT_CLASS_SLIDER | MIXERCONTROL_CT_UNITS_SIGNED) MIXERCONTROL_CONTROLTYPE_PAN = (MIXERCONTROL_CONTROLTYPE_SLIDER + 1) MIXERCONTROL_CONTROLTYPE_QSOUNDPAN = (MIXERCONTROL_CONTROLTYPE_SLIDER + 2) MIXERCONTROL_CONTROLTYPE_FADER = (MIXERCONTROL_CT_CLASS_FADER | MIXERCONTROL_CT_UNITS_UNSIGNED) MIXERCONTROL_CONTROLTYPE_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1) MIXERCONTROL_CONTROLTYPE_BASS = (MIXERCONTROL_CONTROLTYPE_FADER + 2) MIXERCONTROL_CONTROLTYPE_TREBLE = (MIXERCONTROL_CONTROLTYPE_FADER + 3) MIXERCONTROL_CONTROLTYPE_EQUALIZER = (MIXERCONTROL_CONTROLTYPE_FADER + 4) MIXERCONTROL_CONTROLTYPE_SINGLESELECT = (MIXERCONTROL_CT_CLASS_LIST | MIXERCONTROL_CT_SC_LIST_SINGLE | MIXERCONTROL_CT_UNITS_BOOLEAN) MIXERCONTROL_CONTROLTYPE_MUX = (MIXERCONTROL_CONTROLTYPE_SINGLESELECT + 1) MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT = (MIXERCONTROL_CT_CLASS_LIST | MIXERCONTROL_CT_SC_LIST_MULTIPLE | MIXERCONTROL_CT_UNITS_BOOLEAN) MIXERCONTROL_CONTROLTYPE_MIXER = (MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT + 1) MIXERCONTROL_CONTROLTYPE_MICROTIME = (MIXERCONTROL_CT_CLASS_TIME | MIXERCONTROL_CT_SC_TIME_MICROSECS | MIXERCONTROL_CT_UNITS_UNSIGNED) MIXERCONTROL_CONTROLTYPE_MILLITIME = (MIXERCONTROL_CT_CLASS_TIME | MIXERCONTROL_CT_SC_TIME_MILLISECS | MIXERCONTROL_CT_UNITS_UNSIGNED) MIXER_GETLINECONTROLSF_ALL = 0x00000000 MIXER_GETLINECONTROLSF_ONEBYID = 0x00000001 MIXER_GETLINECONTROLSF_ONEBYTYPE = 0x00000002 MIXER_GETLINECONTROLSF_QUERYMASK = 0x0000000F MIXER_GETCONTROLDETAILSF_VALUE = 0x00000000 MIXER_GETCONTROLDETAILSF_LISTTEXT = 0x00000001 MIXER_GETCONTROLDETAILSF_QUERYMASK = 0x0000000F MIXER_SETCONTROLDETAILSF_VALUE = 0x00000000 MIXER_SETCONTROLDETAILSF_CUSTOM = 0x00000001 MIXER_SETCONTROLDETAILSF_QUERYMASK = 0x0000000F TIMERR_NOERROR = (0) TIMERR_NOCANDO = (TIMERR_BASE+1) TIMERR_STRUCT = (TIMERR_BASE+33) TIME_ONESHOT = 0x0000 TIME_PERIODIC = 0x0001 TIME_CALLBACK_FUNCTION = 0x0000 TIME_CALLBACK_EVENT_SET = 0x0010 TIME_CALLBACK_EVENT_PULSE = 0x0020 JOYERR_NOERROR = (0) JOYERR_PARMS = (JOYERR_BASE+5) JOYERR_NOCANDO = (JOYERR_BASE+6) JOYERR_UNPLUGGED = (JOYERR_BASE+7) JOY_BUTTON1 = 0x0001 JOY_BUTTON2 = 0x0002 JOY_BUTTON3 = 0x0004 JOY_BUTTON4 = 0x0008 JOY_BUTTON1CHG = 0x0100 JOY_BUTTON2CHG = 0x0200 JOY_BUTTON3CHG = 0x0400 JOY_BUTTON4CHG = 0x0800 JOY_BUTTON5 = 0x00000010 JOY_BUTTON6 = 0x00000020 JOY_BUTTON7 = 0x00000040 JOY_BUTTON8 = 0x00000080 JOY_BUTTON9 = 0x00000100 JOY_BUTTON10 = 0x00000200 JOY_BUTTON11 = 0x00000400 JOY_BUTTON12 = 0x00000800 JOY_BUTTON13 = 0x00001000 JOY_BUTTON14 = 0x00002000 JOY_BUTTON15 = 0x00004000 JOY_BUTTON16 = 0x00008000 JOY_BUTTON17 = 0x00010000 JOY_BUTTON18 = 0x00020000 JOY_BUTTON19 = 0x00040000 JOY_BUTTON20 = 0x00080000 JOY_BUTTON21 = 0x00100000 JOY_BUTTON22 = 0x00200000 JOY_BUTTON23 = 0x00400000 JOY_BUTTON24 = 0x00800000 JOY_BUTTON25 = 0x01000000 JOY_BUTTON26 = 0x02000000 JOY_BUTTON27 = 0x04000000 JOY_BUTTON28 = 0x08000000 JOY_BUTTON29 = 0x10000000 JOY_BUTTON30 = 0x20000000 JOY_BUTTON31 = 0x40000000 JOY_BUTTON32 = -2147483648 # 0x80000000 JOY_POVFORWARD = 0 JOY_POVRIGHT = 9000 JOY_POVBACKWARD = 18000 JOY_POVLEFT = 27000 JOY_RETURNX = 0x00000001 JOY_RETURNY = 0x00000002 JOY_RETURNZ = 0x00000004 JOY_RETURNR = 0x00000008 JOY_RETURNU = 0x00000010 JOY_RETURNV = 0x00000020 JOY_RETURNPOV = 0x00000040 JOY_RETURNBUTTONS = 0x00000080 JOY_RETURNRAWDATA = 0x00000100 JOY_RETURNPOVCTS = 0x00000200 JOY_RETURNCENTERED = 0x00000400 JOY_USEDEADZONE = 0x00000800 JOY_RETURNALL = (JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | \ JOY_RETURNR | JOY_RETURNU | JOY_RETURNV | \ JOY_RETURNPOV | JOY_RETURNBUTTONS) JOY_CAL_READALWAYS = 0x00010000 JOY_CAL_READXYONLY = 0x00020000 JOY_CAL_READ3 = 0x00040000 JOY_CAL_READ4 = 0x00080000 JOY_CAL_READXONLY = 0x00100000 JOY_CAL_READYONLY = 0x00200000 JOY_CAL_READ5 = 0x00400000 JOY_CAL_READ6 = 0x00800000 JOY_CAL_READZONLY = 0x01000000 JOY_CAL_READRONLY = 0x02000000 JOY_CAL_READUONLY = 0x04000000 JOY_CAL_READVONLY = 0x08000000 JOYSTICKID1 = 0 JOYSTICKID2 = 1 JOYCAPS_HASZ = 0x0001 JOYCAPS_HASR = 0x0002 JOYCAPS_HASU = 0x0004 JOYCAPS_HASV = 0x0008 JOYCAPS_HASPOV = 0x0010 JOYCAPS_POV4DIR = 0x0020 JOYCAPS_POVCTS = 0x0040 MMIOERR_BASE = 256 MMIOERR_FILENOTFOUND = (MMIOERR_BASE + 1) MMIOERR_OUTOFMEMORY = (MMIOERR_BASE + 2) MMIOERR_CANNOTOPEN = (MMIOERR_BASE + 3) MMIOERR_CANNOTCLOSE = (MMIOERR_BASE + 4) MMIOERR_CANNOTREAD = (MMIOERR_BASE + 5) MMIOERR_CANNOTWRITE = (MMIOERR_BASE + 6) MMIOERR_CANNOTSEEK = (MMIOERR_BASE + 7) MMIOERR_CANNOTEXPAND = (MMIOERR_BASE + 8) MMIOERR_CHUNKNOTFOUND = (MMIOERR_BASE + 9) MMIOERR_UNBUFFERED = (MMIOERR_BASE + 10) MMIOERR_PATHNOTFOUND = (MMIOERR_BASE + 11) MMIOERR_ACCESSDENIED = (MMIOERR_BASE + 12) MMIOERR_SHARINGVIOLATION = (MMIOERR_BASE + 13) MMIOERR_NETWORKERROR = (MMIOERR_BASE + 14) MMIOERR_TOOMANYOPENFILES = (MMIOERR_BASE + 15) MMIOERR_INVALIDFILE = (MMIOERR_BASE + 16) CFSEPCHAR = ord('+') MMIO_RWMODE = 0x00000003 MMIO_SHAREMODE = 0x00000070 MMIO_CREATE = 0x00001000 MMIO_PARSE = 0x00000100 MMIO_DELETE = 0x00000200 MMIO_EXIST = 0x00004000 MMIO_ALLOCBUF = 0x00010000 MMIO_GETTEMP = 0x00020000 MMIO_DIRTY = 0x10000000 MMIO_READ = 0x00000000 MMIO_WRITE = 0x00000001 MMIO_READWRITE = 0x00000002 MMIO_COMPAT = 0x00000000 MMIO_EXCLUSIVE = 0x00000010 MMIO_DENYWRITE = 0x00000020 MMIO_DENYREAD = 0x00000030 MMIO_DENYNONE = 0x00000040 MMIO_FHOPEN = 0x0010 MMIO_EMPTYBUF = 0x0010 MMIO_TOUPPER = 0x0010 MMIO_INSTALLPROC = 0x00010000 MMIO_GLOBALPROC = 0x10000000 MMIO_REMOVEPROC = 0x00020000 MMIO_UNICODEPROC = 0x01000000 MMIO_FINDPROC = 0x00040000 MMIO_FINDCHUNK = 0x0010 MMIO_FINDRIFF = 0x0020 MMIO_FINDLIST = 0x0040 MMIO_CREATERIFF = 0x0020 MMIO_CREATELIST = 0x0040 MMIOM_READ = MMIO_READ MMIOM_WRITE = MMIO_WRITE MMIOM_SEEK = 2 MMIOM_OPEN = 3 MMIOM_CLOSE = 4 MMIOM_WRITEFLUSH = 5 MMIOM_RENAME = 6 MMIOM_USER = 0x8000 SEEK_SET = 0 SEEK_CUR = 1 SEEK_END = 2 MMIO_DEFAULTBUFFER = 8192 MCIERR_INVALID_DEVICE_ID = (MCIERR_BASE + 1) MCIERR_UNRECOGNIZED_KEYWORD = (MCIERR_BASE + 3) MCIERR_UNRECOGNIZED_COMMAND = (MCIERR_BASE + 5) MCIERR_HARDWARE = (MCIERR_BASE + 6) MCIERR_INVALID_DEVICE_NAME = (MCIERR_BASE + 7) MCIERR_OUT_OF_MEMORY = (MCIERR_BASE + 8) MCIERR_DEVICE_OPEN = (MCIERR_BASE + 9) MCIERR_CANNOT_LOAD_DRIVER = (MCIERR_BASE + 10) MCIERR_MISSING_COMMAND_STRING = (MCIERR_BASE + 11) MCIERR_PARAM_OVERFLOW = (MCIERR_BASE + 12) MCIERR_MISSING_STRING_ARGUMENT = (MCIERR_BASE + 13) MCIERR_BAD_INTEGER = (MCIERR_BASE + 14) MCIERR_PARSER_INTERNAL = (MCIERR_BASE + 15) MCIERR_DRIVER_INTERNAL = (MCIERR_BASE + 16) MCIERR_MISSING_PARAMETER = (MCIERR_BASE + 17) MCIERR_UNSUPPORTED_FUNCTION = (MCIERR_BASE + 18) MCIERR_FILE_NOT_FOUND = (MCIERR_BASE + 19) MCIERR_DEVICE_NOT_READY = (MCIERR_BASE + 20) MCIERR_INTERNAL = (MCIERR_BASE + 21) MCIERR_DRIVER = (MCIERR_BASE + 22) MCIERR_CANNOT_USE_ALL = (MCIERR_BASE + 23) MCIERR_MULTIPLE = (MCIERR_BASE + 24) MCIERR_EXTENSION_NOT_FOUND = (MCIERR_BASE + 25) MCIERR_OUTOFRANGE = (MCIERR_BASE + 26) MCIERR_FLAGS_NOT_COMPATIBLE = (MCIERR_BASE + 28) MCIERR_FILE_NOT_SAVED = (MCIERR_BASE + 30) MCIERR_DEVICE_TYPE_REQUIRED = (MCIERR_BASE + 31) MCIERR_DEVICE_LOCKED = (MCIERR_BASE + 32) MCIERR_DUPLICATE_ALIAS = (MCIERR_BASE + 33) MCIERR_BAD_CONSTANT = (MCIERR_BASE + 34) MCIERR_MUST_USE_SHAREABLE = (MCIERR_BASE + 35) MCIERR_MISSING_DEVICE_NAME = (MCIERR_BASE + 36) MCIERR_BAD_TIME_FORMAT = (MCIERR_BASE + 37) MCIERR_NO_CLOSING_QUOTE = (MCIERR_BASE + 38) MCIERR_DUPLICATE_FLAGS = (MCIERR_BASE + 39) MCIERR_INVALID_FILE = (MCIERR_BASE + 40) MCIERR_NULL_PARAMETER_BLOCK = (MCIERR_BASE + 41) MCIERR_UNNAMED_RESOURCE = (MCIERR_BASE + 42) MCIERR_NEW_REQUIRES_ALIAS = (MCIERR_BASE + 43) MCIERR_NOTIFY_ON_AUTO_OPEN = (MCIERR_BASE + 44) MCIERR_NO_ELEMENT_ALLOWED = (MCIERR_BASE + 45) MCIERR_NONAPPLICABLE_FUNCTION = (MCIERR_BASE + 46) MCIERR_ILLEGAL_FOR_AUTO_OPEN = (MCIERR_BASE + 47) MCIERR_FILENAME_REQUIRED = (MCIERR_BASE + 48) MCIERR_EXTRA_CHARACTERS = (MCIERR_BASE + 49) MCIERR_DEVICE_NOT_INSTALLED = (MCIERR_BASE + 50) MCIERR_GET_CD = (MCIERR_BASE + 51) MCIERR_SET_CD = (MCIERR_BASE + 52) MCIERR_SET_DRIVE = (MCIERR_BASE + 53) MCIERR_DEVICE_LENGTH = (MCIERR_BASE + 54) MCIERR_DEVICE_ORD_LENGTH = (MCIERR_BASE + 55) MCIERR_NO_INTEGER = (MCIERR_BASE + 56) MCIERR_WAVE_OUTPUTSINUSE = (MCIERR_BASE + 64) MCIERR_WAVE_SETOUTPUTINUSE = (MCIERR_BASE + 65) MCIERR_WAVE_INPUTSINUSE = (MCIERR_BASE + 66) MCIERR_WAVE_SETINPUTINUSE = (MCIERR_BASE + 67) MCIERR_WAVE_OUTPUTUNSPECIFIED = (MCIERR_BASE + 68) MCIERR_WAVE_INPUTUNSPECIFIED = (MCIERR_BASE + 69) MCIERR_WAVE_OUTPUTSUNSUITABLE = (MCIERR_BASE + 70) MCIERR_WAVE_SETOUTPUTUNSUITABLE = (MCIERR_BASE + 71) MCIERR_WAVE_INPUTSUNSUITABLE = (MCIERR_BASE + 72) MCIERR_WAVE_SETINPUTUNSUITABLE = (MCIERR_BASE + 73) MCIERR_SEQ_DIV_INCOMPATIBLE = (MCIERR_BASE + 80) MCIERR_SEQ_PORT_INUSE = (MCIERR_BASE + 81) MCIERR_SEQ_PORT_NONEXISTENT = (MCIERR_BASE + 82) MCIERR_SEQ_PORT_MAPNODEVICE = (MCIERR_BASE + 83) MCIERR_SEQ_PORT_MISCERROR = (MCIERR_BASE + 84) MCIERR_SEQ_TIMER = (MCIERR_BASE + 85) MCIERR_SEQ_PORTUNSPECIFIED = (MCIERR_BASE + 86) MCIERR_SEQ_NOMIDIPRESENT = (MCIERR_BASE + 87) MCIERR_NO_WINDOW = (MCIERR_BASE + 90) MCIERR_CREATEWINDOW = (MCIERR_BASE + 91) MCIERR_FILE_READ = (MCIERR_BASE + 92) MCIERR_FILE_WRITE = (MCIERR_BASE + 93) MCIERR_NO_IDENTITY = (MCIERR_BASE + 94) MCIERR_CUSTOM_DRIVER_BASE = (MCIERR_BASE + 256) MCI_FIRST = DRV_MCI_FIRST MCI_OPEN = 0x0803 MCI_CLOSE = 0x0804 MCI_ESCAPE = 0x0805 MCI_PLAY = 0x0806 MCI_SEEK = 0x0807 MCI_STOP = 0x0808 MCI_PAUSE = 0x0809 MCI_INFO = 0x080A MCI_GETDEVCAPS = 0x080B MCI_SPIN = 0x080C MCI_SET = 0x080D MCI_STEP = 0x080E MCI_RECORD = 0x080F MCI_SYSINFO = 0x0810 MCI_BREAK = 0x0811 MCI_SAVE = 0x0813 MCI_STATUS = 0x0814 MCI_CUE = 0x0830 MCI_REALIZE = 0x0840 MCI_WINDOW = 0x0841 MCI_PUT = 0x0842 MCI_WHERE = 0x0843 MCI_FREEZE = 0x0844 MCI_UNFREEZE = 0x0845 MCI_LOAD = 0x0850 MCI_CUT = 0x0851 MCI_COPY = 0x0852 MCI_PASTE = 0x0853 MCI_UPDATE = 0x0854 MCI_RESUME = 0x0855 MCI_DELETE = 0x0856 MCI_USER_MESSAGES = (DRV_MCI_FIRST + 0x400) MCI_LAST = 0x0FFF MCI_DEVTYPE_VCR = 513 MCI_DEVTYPE_VIDEODISC = 514 MCI_DEVTYPE_OVERLAY = 515 MCI_DEVTYPE_CD_AUDIO = 516 MCI_DEVTYPE_DAT = 517 MCI_DEVTYPE_SCANNER = 518 MCI_DEVTYPE_ANIMATION = 519 MCI_DEVTYPE_DIGITAL_VIDEO = 520 MCI_DEVTYPE_OTHER = 521 MCI_DEVTYPE_WAVEFORM_AUDIO = 522 MCI_DEVTYPE_SEQUENCER = 523 MCI_DEVTYPE_FIRST = MCI_DEVTYPE_VCR MCI_DEVTYPE_LAST = MCI_DEVTYPE_SEQUENCER MCI_DEVTYPE_FIRST_USER = 0x1000 MCI_MODE_NOT_READY = (MCI_STRING_OFFSET + 12) MCI_MODE_STOP = (MCI_STRING_OFFSET + 13) MCI_MODE_PLAY = (MCI_STRING_OFFSET + 14) MCI_MODE_RECORD = (MCI_STRING_OFFSET + 15) MCI_MODE_SEEK = (MCI_STRING_OFFSET + 16) MCI_MODE_PAUSE = (MCI_STRING_OFFSET + 17) MCI_MODE_OPEN = (MCI_STRING_OFFSET + 18) MCI_FORMAT_MILLISECONDS = 0 MCI_FORMAT_HMS = 1 MCI_FORMAT_MSF = 2 MCI_FORMAT_FRAMES = 3 MCI_FORMAT_SMPTE_24 = 4 MCI_FORMAT_SMPTE_25 = 5 MCI_FORMAT_SMPTE_30 = 6 MCI_FORMAT_SMPTE_30DROP = 7 MCI_FORMAT_BYTES = 8 MCI_FORMAT_SAMPLES = 9 MCI_FORMAT_TMSF = 10 def MCI_MSF_MINUTE(msf): return ((BYTE)(msf)) def MCI_MSF_SECOND(msf): return ((BYTE)(((WORD)(msf)) >> 8)) def MCI_MSF_FRAME(msf): return ((BYTE)((msf)>>16)) def MCI_TMSF_TRACK(tmsf): return ((BYTE)(tmsf)) def MCI_TMSF_MINUTE(tmsf): return ((BYTE)(((WORD)(tmsf)) >> 8)) def MCI_TMSF_SECOND(tmsf): return ((BYTE)((tmsf)>>16)) def MCI_TMSF_FRAME(tmsf): return ((BYTE)((tmsf)>>24)) def MCI_HMS_HOUR(hms): return ((BYTE)(hms)) def MCI_HMS_MINUTE(hms): return ((BYTE)(((WORD)(hms)) >> 8)) def MCI_HMS_SECOND(hms): return ((BYTE)((hms)>>16)) MCI_NOTIFY_SUCCESSFUL = 0x0001 MCI_NOTIFY_SUPERSEDED = 0x0002 MCI_NOTIFY_ABORTED = 0x0004 MCI_NOTIFY_FAILURE = 0x0008 MCI_NOTIFY = 0x00000001 MCI_WAIT = 0x00000002 MCI_FROM = 0x00000004 MCI_TO = 0x00000008 MCI_TRACK = 0x00000010 MCI_OPEN_SHAREABLE = 0x00000100 MCI_OPEN_ELEMENT = 0x00000200 MCI_OPEN_ALIAS = 0x00000400 MCI_OPEN_ELEMENT_ID = 0x00000800 MCI_OPEN_TYPE_ID = 0x00001000 MCI_OPEN_TYPE = 0x00002000 MCI_SEEK_TO_START = 0x00000100 MCI_SEEK_TO_END = 0x00000200 MCI_STATUS_ITEM = 0x00000100 MCI_STATUS_START = 0x00000200 MCI_STATUS_LENGTH = 0x00000001 MCI_STATUS_POSITION = 0x00000002 MCI_STATUS_NUMBER_OF_TRACKS = 0x00000003 MCI_STATUS_MODE = 0x00000004 MCI_STATUS_MEDIA_PRESENT = 0x00000005 MCI_STATUS_TIME_FORMAT = 0x00000006 MCI_STATUS_READY = 0x00000007 MCI_STATUS_CURRENT_TRACK = 0x00000008 MCI_INFO_PRODUCT = 0x00000100 MCI_INFO_FILE = 0x00000200 MCI_INFO_MEDIA_UPC = 0x00000400 MCI_INFO_MEDIA_IDENTITY = 0x00000800 MCI_INFO_NAME = 0x00001000 MCI_INFO_COPYRIGHT = 0x00002000 MCI_GETDEVCAPS_ITEM = 0x00000100 MCI_GETDEVCAPS_CAN_RECORD = 0x00000001 MCI_GETDEVCAPS_HAS_AUDIO = 0x00000002 MCI_GETDEVCAPS_HAS_VIDEO = 0x00000003 MCI_GETDEVCAPS_DEVICE_TYPE = 0x00000004 MCI_GETDEVCAPS_USES_FILES = 0x00000005 MCI_GETDEVCAPS_COMPOUND_DEVICE = 0x00000006 MCI_GETDEVCAPS_CAN_EJECT = 0x00000007 MCI_GETDEVCAPS_CAN_PLAY = 0x00000008 MCI_GETDEVCAPS_CAN_SAVE = 0x00000009 MCI_SYSINFO_QUANTITY = 0x00000100 MCI_SYSINFO_OPEN = 0x00000200 MCI_SYSINFO_NAME = 0x00000400 MCI_SYSINFO_INSTALLNAME = 0x00000800 MCI_SET_DOOR_OPEN = 0x00000100 MCI_SET_DOOR_CLOSED = 0x00000200 MCI_SET_TIME_FORMAT = 0x00000400 MCI_SET_AUDIO = 0x00000800 MCI_SET_VIDEO = 0x00001000 MCI_SET_ON = 0x00002000 MCI_SET_OFF = 0x00004000 MCI_SET_AUDIO_ALL = 0x00000000 MCI_SET_AUDIO_LEFT = 0x00000001 MCI_SET_AUDIO_RIGHT = 0x00000002 MCI_BREAK_KEY = 0x00000100 MCI_BREAK_HWND = 0x00000200 MCI_BREAK_OFF = 0x00000400 MCI_RECORD_INSERT = 0x00000100 MCI_RECORD_OVERWRITE = 0x00000200 MCI_SAVE_FILE = 0x00000100 MCI_LOAD_FILE = 0x00000100 MCI_VD_MODE_PARK = (MCI_VD_OFFSET + 1) MCI_VD_MEDIA_CLV = (MCI_VD_OFFSET + 2) MCI_VD_MEDIA_CAV = (MCI_VD_OFFSET + 3) MCI_VD_MEDIA_OTHER = (MCI_VD_OFFSET + 4) MCI_VD_FORMAT_TRACK = 0x4001 MCI_VD_PLAY_REVERSE = 0x00010000 MCI_VD_PLAY_FAST = 0x00020000 MCI_VD_PLAY_SPEED = 0x00040000 MCI_VD_PLAY_SCAN = 0x00080000 MCI_VD_PLAY_SLOW = 0x00100000 MCI_VD_SEEK_REVERSE = 0x00010000 MCI_VD_STATUS_SPEED = 0x00004002 MCI_VD_STATUS_FORWARD = 0x00004003 MCI_VD_STATUS_MEDIA_TYPE = 0x00004004 MCI_VD_STATUS_SIDE = 0x00004005 MCI_VD_STATUS_DISC_SIZE = 0x00004006 MCI_VD_GETDEVCAPS_CLV = 0x00010000 MCI_VD_GETDEVCAPS_CAV = 0x00020000 MCI_VD_SPIN_UP = 0x00010000 MCI_VD_SPIN_DOWN = 0x00020000 MCI_VD_GETDEVCAPS_CAN_REVERSE = 0x00004002 MCI_VD_GETDEVCAPS_FAST_RATE = 0x00004003 MCI_VD_GETDEVCAPS_SLOW_RATE = 0x00004004 MCI_VD_GETDEVCAPS_NORMAL_RATE = 0x00004005 MCI_VD_STEP_FRAMES = 0x00010000 MCI_VD_STEP_REVERSE = 0x00020000 MCI_VD_ESCAPE_STRING = 0x00000100 MCI_CDA_STATUS_TYPE_TRACK = 0x00004001 MCI_CDA_TRACK_AUDIO = (MCI_CD_OFFSET + 0) MCI_CDA_TRACK_OTHER = (MCI_CD_OFFSET + 1) MCI_WAVE_PCM = (MCI_WAVE_OFFSET + 0) MCI_WAVE_MAPPER = (MCI_WAVE_OFFSET + 1) MCI_WAVE_OPEN_BUFFER = 0x00010000 MCI_WAVE_SET_FORMATTAG = 0x00010000 MCI_WAVE_SET_CHANNELS = 0x00020000 MCI_WAVE_SET_SAMPLESPERSEC = 0x00040000 MCI_WAVE_SET_AVGBYTESPERSEC = 0x00080000 MCI_WAVE_SET_BLOCKALIGN = 0x00100000 MCI_WAVE_SET_BITSPERSAMPLE = 0x00200000 MCI_WAVE_INPUT = 0x00400000 MCI_WAVE_OUTPUT = 0x00800000 MCI_WAVE_STATUS_FORMATTAG = 0x00004001 MCI_WAVE_STATUS_CHANNELS = 0x00004002 MCI_WAVE_STATUS_SAMPLESPERSEC = 0x00004003 MCI_WAVE_STATUS_AVGBYTESPERSEC = 0x00004004 MCI_WAVE_STATUS_BLOCKALIGN = 0x00004005 MCI_WAVE_STATUS_BITSPERSAMPLE = 0x00004006 MCI_WAVE_STATUS_LEVEL = 0x00004007 MCI_WAVE_SET_ANYINPUT = 0x04000000 MCI_WAVE_SET_ANYOUTPUT = 0x08000000 MCI_WAVE_GETDEVCAPS_INPUTS = 0x00004001 MCI_WAVE_GETDEVCAPS_OUTPUTS = 0x00004002 MCI_SEQ_DIV_PPQN = (0 + MCI_SEQ_OFFSET) MCI_SEQ_DIV_SMPTE_24 = (1 + MCI_SEQ_OFFSET) MCI_SEQ_DIV_SMPTE_25 = (2 + MCI_SEQ_OFFSET) MCI_SEQ_DIV_SMPTE_30DROP = (3 + MCI_SEQ_OFFSET) MCI_SEQ_DIV_SMPTE_30 = (4 + MCI_SEQ_OFFSET) MCI_SEQ_FORMAT_SONGPTR = 0x4001 MCI_SEQ_FILE = 0x4002 MCI_SEQ_MIDI = 0x4003 MCI_SEQ_SMPTE = 0x4004 MCI_SEQ_NONE = 65533 MCI_SEQ_MAPPER = 65535 MCI_SEQ_STATUS_TEMPO = 0x00004002 MCI_SEQ_STATUS_PORT = 0x00004003 MCI_SEQ_STATUS_SLAVE = 0x00004007 MCI_SEQ_STATUS_MASTER = 0x00004008 MCI_SEQ_STATUS_OFFSET = 0x00004009 MCI_SEQ_STATUS_DIVTYPE = 0x0000400A MCI_SEQ_STATUS_NAME = 0x0000400B MCI_SEQ_STATUS_COPYRIGHT = 0x0000400C MCI_SEQ_SET_TEMPO = 0x00010000 MCI_SEQ_SET_PORT = 0x00020000 MCI_SEQ_SET_SLAVE = 0x00040000 MCI_SEQ_SET_MASTER = 0x00080000 MCI_SEQ_SET_OFFSET = 0x01000000 MCI_ANIM_OPEN_WS = 0x00010000 MCI_ANIM_OPEN_PARENT = 0x00020000 MCI_ANIM_OPEN_NOSTATIC = 0x00040000 MCI_ANIM_PLAY_SPEED = 0x00010000 MCI_ANIM_PLAY_REVERSE = 0x00020000 MCI_ANIM_PLAY_FAST = 0x00040000 MCI_ANIM_PLAY_SLOW = 0x00080000 MCI_ANIM_PLAY_SCAN = 0x00100000 MCI_ANIM_STEP_REVERSE = 0x00010000 MCI_ANIM_STEP_FRAMES = 0x00020000 MCI_ANIM_STATUS_SPEED = 0x00004001 MCI_ANIM_STATUS_FORWARD = 0x00004002 MCI_ANIM_STATUS_HWND = 0x00004003 MCI_ANIM_STATUS_HPAL = 0x00004004 MCI_ANIM_STATUS_STRETCH = 0x00004005 MCI_ANIM_INFO_TEXT = 0x00010000 MCI_ANIM_GETDEVCAPS_CAN_REVERSE = 0x00004001 MCI_ANIM_GETDEVCAPS_FAST_RATE = 0x00004002 MCI_ANIM_GETDEVCAPS_SLOW_RATE = 0x00004003 MCI_ANIM_GETDEVCAPS_NORMAL_RATE = 0x00004004 MCI_ANIM_GETDEVCAPS_PALETTES = 0x00004006 MCI_ANIM_GETDEVCAPS_CAN_STRETCH = 0x00004007 MCI_ANIM_GETDEVCAPS_MAX_WINDOWS = 0x00004008 MCI_ANIM_REALIZE_NORM = 0x00010000 MCI_ANIM_REALIZE_BKGD = 0x00020000 MCI_ANIM_WINDOW_HWND = 0x00010000 MCI_ANIM_WINDOW_STATE = 0x00040000 MCI_ANIM_WINDOW_TEXT = 0x00080000 MCI_ANIM_WINDOW_ENABLE_STRETCH = 0x00100000 MCI_ANIM_WINDOW_DISABLE_STRETCH = 0x00200000 MCI_ANIM_WINDOW_DEFAULT = 0x00000000 MCI_ANIM_RECT = 0x00010000 MCI_ANIM_PUT_SOURCE = 0x00020000 MCI_ANIM_PUT_DESTINATION = 0x00040000 MCI_ANIM_WHERE_SOURCE = 0x00020000 MCI_ANIM_WHERE_DESTINATION = 0x00040000 MCI_ANIM_UPDATE_HDC = 0x00020000 MCI_OVLY_OPEN_WS = 0x00010000 MCI_OVLY_OPEN_PARENT = 0x00020000 MCI_OVLY_STATUS_HWND = 0x00004001 MCI_OVLY_STATUS_STRETCH = 0x00004002 MCI_OVLY_INFO_TEXT = 0x00010000 MCI_OVLY_GETDEVCAPS_CAN_STRETCH = 0x00004001 MCI_OVLY_GETDEVCAPS_CAN_FREEZE = 0x00004002 MCI_OVLY_GETDEVCAPS_MAX_WINDOWS = 0x00004003 MCI_OVLY_WINDOW_HWND = 0x00010000 MCI_OVLY_WINDOW_STATE = 0x00040000 MCI_OVLY_WINDOW_TEXT = 0x00080000 MCI_OVLY_WINDOW_ENABLE_STRETCH = 0x00100000 MCI_OVLY_WINDOW_DISABLE_STRETCH = 0x00200000 MCI_OVLY_WINDOW_DEFAULT = 0x00000000 MCI_OVLY_RECT = 0x00010000 MCI_OVLY_PUT_SOURCE = 0x00020000 MCI_OVLY_PUT_DESTINATION = 0x00040000 MCI_OVLY_PUT_FRAME = 0x00080000 MCI_OVLY_PUT_VIDEO = 0x00100000 MCI_OVLY_WHERE_SOURCE = 0x00020000 MCI_OVLY_WHERE_DESTINATION = 0x00040000 MCI_OVLY_WHERE_FRAME = 0x00080000 MCI_OVLY_WHERE_VIDEO = 0x00100000 SELECTDIB = 41 def DIBINDEX(n): return MAKELONG((n),0x10FF)
mit
[ 3, 17065, 701, 394, 18, 647, 687, 366, 11254, 706, 2374, 15, 2613, 15, 596, 2253, 14, 72, 199, 4283, 48, 22168, 275, 4337, 199, 4283, 3170, 9127, 275, 7633, 199, 4283, 63, 15465, 57, 840, 13884, 47, 2769, 54, 18184, 2339, 275, 499, 2259, 199, 3218, 63, 29112, 26999, 275, 413, 199, 3218, 63, 45, 28904, 63, 5443, 4227, 275, 413, 199, 3218, 63, 32482, 63, 5443, 4227, 275, 499, 199, 3218, 63, 8199, 2846, 29805, 63, 45, 28904, 1877, 275, 650, 199, 3218, 63, 8199, 2846, 29805, 63, 45, 28904, 568, 275, 841, 199, 3218, 63, 8199, 2846, 29805, 63, 31802, 2080, 275, 959, 199, 3218, 63, 8199, 2846, 29805, 63, 32482, 1877, 275, 1227, 199, 3218, 63, 8199, 2846, 29805, 63, 32482, 568, 275, 1520, 199, 3218, 63, 1554, 5617, 275, 1749, 199, 3218, 63, 1658, 53, 8854, 63, 45, 28904, 1877, 275, 1616, 199, 3218, 63, 1658, 53, 8854, 63, 45, 28904, 568, 275, 4119, 199, 3218, 63, 4222, 63, 15465, 57, 840, 13884, 275, 3144, 199, 4961, 63, 3053, 275, 378, 88, 4183, 199, 4961, 63, 51, 8236, 275, 378, 88, 9425, 199, 4961, 63, 20352, 275, 378, 88, 16643, 199, 4961, 63, 51, 1658, 3727, 275, 378, 88, 19141, 199, 4961, 63, 45, 28904, 275, 378, 88, 17657, 199, 4961, 63, 52, 13884, 51, 275, 378, 88, 20734, 199, 3218, 63, 15465, 57, 17, 16207, 275, 378, 88, 19, 33, 16, 199, 3218, 63, 15465, 57, 18, 16207, 275, 378, 88, 19, 33, 17, 199, 3218, 63, 15465, 57, 17, 58, 16207, 275, 378, 88, 19, 33, 18, 199, 3218, 63, 15465, 57, 18, 58, 16207, 275, 378, 88, 19, 33, 19, 199, 3218, 63, 15465, 57, 17, 13272, 8819, 275, 378, 88, 19, 34, 21, 199, 3218, 63, 15465, 57, 18, 13272, 8819, 275, 378, 88, 19, 34, 22, 199, 3218, 63, 15465, 57, 17, 13272, 2160, 275, 378, 88, 19, 34, 23, 199, 3218, 63, 15465, 57, 18, 13272, 2160, 275, 378, 88, 19, 34, 24, 199, 3218, 63, 7608, 568, 1387, 13367, 275, 378, 88, 19, 34, 25, 199, 3218, 63, 55, 7474, 63, 9935, 275, 378, 88, 19, 5342, 199, 3218, 63, 55, 7474, 63, 18219, 275, 378, 88, 19, 6265, 199, 3218, 63, 55, 7474, 63, 22162, 275, 378, 88, 19, 11156, 199, 3218, 63, 55, 1469, 63, 9935, 275, 378, 88, 19, 6773, 199, 3218, 63, 55, 1469, 63, 18219, 275, 378, 88, 19, 12659, 199, 3218, 63, 55, 1469, 63, 3998, 275, 378, 88, 19, 35, 16, 199, 3218, 63, 45, 1469, 63, 9935, 275, 378, 88, 19, 35, 17, 199, 3218, 63, 45, 1469, 63, 18219, 275, 378, 88, 19, 35, 18, 199, 3218, 63, 45, 1469, 63, 3998, 275, 378, 88, 19, 35, 19, 199, 3218, 63, 45, 1469, 63, 12375, 3998, 275, 378, 88, 19, 35, 20, 199, 3218, 63, 45, 1469, 63, 3170, 275, 378, 88, 19, 35, 21, 199, 3218, 63, 45, 1469, 63, 12375, 3170, 275, 378, 88, 19, 35, 22, 199, 3218, 63, 2679, 45, 63, 9935, 275, 378, 88, 19, 35, 23, 199, 3218, 63, 2679, 45, 63, 18219, 275, 378, 88, 19, 35, 24, 199, 3218, 63, 2679, 45, 63, 22162, 275, 378, 88, 19, 35, 25, 199, 3218, 63, 9484, 63, 9935, 275, 378, 88, 19, 36, 20, 199, 3218, 63, 9484, 63, 18219, 275, 378, 88, 19, 36, 21, 199, 3218, 63, 9484, 63, 22162, 275, 378, 88, 19, 36, 22, 199, 3218, 63, 9484, 63, 3170, 275, 378, 88, 19, 36, 23, 199, 3218, 63, 2679, 45, 63, 15717, 9956, 275, 378, 88, 19, 3263, 199, 3218, 63, 45, 1469, 63, 45, 25517, 2751, 275, 378, 88, 19, 2571, 199, 3218, 63, 25543, 45, 63, 6174, 63, 16062, 275, 378, 88, 19, 36, 16, 199, 3218, 63, 25543, 45, 63, 13060, 63, 16062, 275, 378, 88, 19, 36, 17, 199, 45, 3053, 20238, 2666, 63, 5825, 275, 378, 199, 9004, 2111, 50, 63, 5825, 275, 4337, 199, 45, 28904, 2666, 63, 5825, 275, 5049, 199, 11342, 2666, 63, 5825, 275, 15580, 199, 15465, 57, 2666, 63, 5825, 275, 21235, 199, 28840, 2666, 63, 5825, 275, 7633, 199, 25543, 2666, 63, 5825, 275, 6619, 199, 28840, 63, 5353, 63, 14839, 275, 10574, 199, 28840, 63, 26197, 63, 14839, 275, 6619, 199, 28840, 63, 7695, 63, 14839, 275, 1616, 1299, 199, 28840, 63, 32482, 63, 14839, 275, 413, 11024, 199, 28840, 63, 28674, 63, 14839, 275, 3144, 975, 199, 45, 3053, 20238, 2666, 63, 2826, 3170, 275, 378, 199, 45, 3053, 20238, 2666, 63, 3170, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 413, 9, 199, 45, 3053, 20238, 2666, 63, 9439, 10555, 998, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 499, 9, 199, 45, 3053, 20238, 2666, 63, 4609, 15704, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 650, 9, 199, 45, 3053, 20238, 2666, 63, 28605, 6989, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 841, 9, 199, 45, 3053, 20238, 2666, 63, 568, 3204, 15885, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 959, 9, 199, 45, 3053, 20238, 2666, 63, 2826, 23401, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 1227, 9, 199, 45, 3053, 20238, 2666, 63, 2826, 10293, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 1520, 9, 199, 45, 3053, 20238, 2666, 63, 4609, 15925, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 1695, 9, 199, 45, 3053, 20238, 2666, 63, 9439, 2666, 7125, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 1749, 9, 199, 45, 3053, 20238, 2666, 63, 568, 3204, 3719, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 1616, 9, 199, 45, 3053, 20238, 2666, 63, 568, 3204, 7258, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 4119, 9, 199, 45, 3053, 20238, 2666, 63, 15885, 24753, 57, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 3144, 9, 199, 45, 3053, 20238, 2666, 63, 9692, 12644, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 4944, 9, 199, 45, 3053, 20238, 2666, 63, 9439, 2846, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 4329, 9, 199, 45 ]
[ 17065, 701, 394, 18, 647, 687, 366, 11254, 706, 2374, 15, 2613, 15, 596, 2253, 14, 72, 199, 4283, 48, 22168, 275, 4337, 199, 4283, 3170, 9127, 275, 7633, 199, 4283, 63, 15465, 57, 840, 13884, 47, 2769, 54, 18184, 2339, 275, 499, 2259, 199, 3218, 63, 29112, 26999, 275, 413, 199, 3218, 63, 45, 28904, 63, 5443, 4227, 275, 413, 199, 3218, 63, 32482, 63, 5443, 4227, 275, 499, 199, 3218, 63, 8199, 2846, 29805, 63, 45, 28904, 1877, 275, 650, 199, 3218, 63, 8199, 2846, 29805, 63, 45, 28904, 568, 275, 841, 199, 3218, 63, 8199, 2846, 29805, 63, 31802, 2080, 275, 959, 199, 3218, 63, 8199, 2846, 29805, 63, 32482, 1877, 275, 1227, 199, 3218, 63, 8199, 2846, 29805, 63, 32482, 568, 275, 1520, 199, 3218, 63, 1554, 5617, 275, 1749, 199, 3218, 63, 1658, 53, 8854, 63, 45, 28904, 1877, 275, 1616, 199, 3218, 63, 1658, 53, 8854, 63, 45, 28904, 568, 275, 4119, 199, 3218, 63, 4222, 63, 15465, 57, 840, 13884, 275, 3144, 199, 4961, 63, 3053, 275, 378, 88, 4183, 199, 4961, 63, 51, 8236, 275, 378, 88, 9425, 199, 4961, 63, 20352, 275, 378, 88, 16643, 199, 4961, 63, 51, 1658, 3727, 275, 378, 88, 19141, 199, 4961, 63, 45, 28904, 275, 378, 88, 17657, 199, 4961, 63, 52, 13884, 51, 275, 378, 88, 20734, 199, 3218, 63, 15465, 57, 17, 16207, 275, 378, 88, 19, 33, 16, 199, 3218, 63, 15465, 57, 18, 16207, 275, 378, 88, 19, 33, 17, 199, 3218, 63, 15465, 57, 17, 58, 16207, 275, 378, 88, 19, 33, 18, 199, 3218, 63, 15465, 57, 18, 58, 16207, 275, 378, 88, 19, 33, 19, 199, 3218, 63, 15465, 57, 17, 13272, 8819, 275, 378, 88, 19, 34, 21, 199, 3218, 63, 15465, 57, 18, 13272, 8819, 275, 378, 88, 19, 34, 22, 199, 3218, 63, 15465, 57, 17, 13272, 2160, 275, 378, 88, 19, 34, 23, 199, 3218, 63, 15465, 57, 18, 13272, 2160, 275, 378, 88, 19, 34, 24, 199, 3218, 63, 7608, 568, 1387, 13367, 275, 378, 88, 19, 34, 25, 199, 3218, 63, 55, 7474, 63, 9935, 275, 378, 88, 19, 5342, 199, 3218, 63, 55, 7474, 63, 18219, 275, 378, 88, 19, 6265, 199, 3218, 63, 55, 7474, 63, 22162, 275, 378, 88, 19, 11156, 199, 3218, 63, 55, 1469, 63, 9935, 275, 378, 88, 19, 6773, 199, 3218, 63, 55, 1469, 63, 18219, 275, 378, 88, 19, 12659, 199, 3218, 63, 55, 1469, 63, 3998, 275, 378, 88, 19, 35, 16, 199, 3218, 63, 45, 1469, 63, 9935, 275, 378, 88, 19, 35, 17, 199, 3218, 63, 45, 1469, 63, 18219, 275, 378, 88, 19, 35, 18, 199, 3218, 63, 45, 1469, 63, 3998, 275, 378, 88, 19, 35, 19, 199, 3218, 63, 45, 1469, 63, 12375, 3998, 275, 378, 88, 19, 35, 20, 199, 3218, 63, 45, 1469, 63, 3170, 275, 378, 88, 19, 35, 21, 199, 3218, 63, 45, 1469, 63, 12375, 3170, 275, 378, 88, 19, 35, 22, 199, 3218, 63, 2679, 45, 63, 9935, 275, 378, 88, 19, 35, 23, 199, 3218, 63, 2679, 45, 63, 18219, 275, 378, 88, 19, 35, 24, 199, 3218, 63, 2679, 45, 63, 22162, 275, 378, 88, 19, 35, 25, 199, 3218, 63, 9484, 63, 9935, 275, 378, 88, 19, 36, 20, 199, 3218, 63, 9484, 63, 18219, 275, 378, 88, 19, 36, 21, 199, 3218, 63, 9484, 63, 22162, 275, 378, 88, 19, 36, 22, 199, 3218, 63, 9484, 63, 3170, 275, 378, 88, 19, 36, 23, 199, 3218, 63, 2679, 45, 63, 15717, 9956, 275, 378, 88, 19, 3263, 199, 3218, 63, 45, 1469, 63, 45, 25517, 2751, 275, 378, 88, 19, 2571, 199, 3218, 63, 25543, 45, 63, 6174, 63, 16062, 275, 378, 88, 19, 36, 16, 199, 3218, 63, 25543, 45, 63, 13060, 63, 16062, 275, 378, 88, 19, 36, 17, 199, 45, 3053, 20238, 2666, 63, 5825, 275, 378, 199, 9004, 2111, 50, 63, 5825, 275, 4337, 199, 45, 28904, 2666, 63, 5825, 275, 5049, 199, 11342, 2666, 63, 5825, 275, 15580, 199, 15465, 57, 2666, 63, 5825, 275, 21235, 199, 28840, 2666, 63, 5825, 275, 7633, 199, 25543, 2666, 63, 5825, 275, 6619, 199, 28840, 63, 5353, 63, 14839, 275, 10574, 199, 28840, 63, 26197, 63, 14839, 275, 6619, 199, 28840, 63, 7695, 63, 14839, 275, 1616, 1299, 199, 28840, 63, 32482, 63, 14839, 275, 413, 11024, 199, 28840, 63, 28674, 63, 14839, 275, 3144, 975, 199, 45, 3053, 20238, 2666, 63, 2826, 3170, 275, 378, 199, 45, 3053, 20238, 2666, 63, 3170, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 413, 9, 199, 45, 3053, 20238, 2666, 63, 9439, 10555, 998, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 499, 9, 199, 45, 3053, 20238, 2666, 63, 4609, 15704, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 650, 9, 199, 45, 3053, 20238, 2666, 63, 28605, 6989, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 841, 9, 199, 45, 3053, 20238, 2666, 63, 568, 3204, 15885, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 959, 9, 199, 45, 3053, 20238, 2666, 63, 2826, 23401, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 1227, 9, 199, 45, 3053, 20238, 2666, 63, 2826, 10293, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 1520, 9, 199, 45, 3053, 20238, 2666, 63, 4609, 15925, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 1695, 9, 199, 45, 3053, 20238, 2666, 63, 9439, 2666, 7125, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 1749, 9, 199, 45, 3053, 20238, 2666, 63, 568, 3204, 3719, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 1616, 9, 199, 45, 3053, 20238, 2666, 63, 568, 3204, 7258, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 4119, 9, 199, 45, 3053, 20238, 2666, 63, 15885, 24753, 57, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 435, 3144, 9, 199, 45, 3053, 20238, 2666, 63, 9692, 12644, 275, 334, 45, 3053, 20238, 2666, 63, 5825, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
filippog/pysnmp
examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py
1
3156
""" Serve SNMP Community names defined by regexp ++++++++++++++++++++++++++++++++++++++++++++ Receive SNMP TRAP/INFORM messages with the following options: * SNMPv1/SNMPv2c * with any SNMP community matching regexp '.*love.*' * over IPv4/UDP, listening at 127.0.0.1:162 * print received data on stdout Either of the following Net-SNMP commands will send notifications to this receiver: | $ snmptrap -v1 -c rollover 127.0.0.1 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 1 1 123 1.3.6.1.2.1.1.1.0 s test | $ snmpinform -v2c -c glove 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 The Notification Receiver below taps on v1/v2c SNMP security module to deliver certains values, normally internal to SNMP Engine, up to the context of user application. This script examines the value of CommunityName, as it came from peer SNMP Engine, and may modify it to match the only locally configured CommunityName 'public'. This effectively makes NotificationReceiver accepting messages with CommunityName's, not explicitly configured to local SNMP Engine. """# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntfrcv from pysnmp.proto.api import v2c import re # Create SNMP engine with autogenernated engineID and pre-bound # to socket transport dispatcher snmpEngine = engine.SnmpEngine() # Register a callback to be invoked at specified execution point of # SNMP Engine and passed local variables at execution point's local scope. # If at this execution point passed variables are modified, their new # values will be propagated back and used by SNMP Engine for securityName # selection. def requestObserver(snmpEngine, execpoint, variables, cbCtx): if re.match('.*love.*', str(variables['communityName'])): print('Rewriting communityName \'%s\' from %s into \'public\'' % (variables['communityName'], ':'.join([str(x) for x in variables['transportInformation'][1]]))) variables['communityName'] = variables['communityName'].clone('public') snmpEngine.observer.registerObserver( requestObserver, 'rfc2576.processIncomingMsg:writable' ) # Transport setup # UDP over IPv4 config.addTransport( snmpEngine, udp.domainName, udp.UdpTransport().openServerMode(('127.0.0.1', 162)) ) # SNMPv1/2c setup # SecurityName <-> CommunityName mapping config.addV1System(snmpEngine, 'my-area', 'public') # Callback function for receiving notifications def cbFun(snmpEngine, stateReference, contextEngineId, contextName, varBinds, cbCtx): print('Notification from ContextEngineId "%s", ContextName "%s"' % ( contextEngineId.prettyPrint(), contextName.prettyPrint() ) ) for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) # Register SNMP Application at the SNMP engine ntfrcv.NotificationReceiver(snmpEngine, cbFun) snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send confirmations try: snmpEngine.transportDispatcher.runDispatcher() except: snmpEngine.transportDispatcher.closeDispatcher() raise
bsd-3-clause
[ 624, 199, 1505, 432, 26549, 7046, 6639, 1561, 3247, 701, 13156, 199, 20421, 20421, 20421, 20421, 20421, 12437, 199, 199, 14235, 26549, 9074, 1282, 15, 568, 3516, 3788, 543, 314, 2569, 1511, 26, 199, 199, 10, 26549, 86, 17, 15, 30919, 86, 18, 67, 199, 10, 543, 1263, 26549, 23633, 4877, 13156, 1987, 10, 320, 432, 25737, 199, 10, 1806, 6509, 20, 15, 17457, 12, 22721, 737, 12792, 14, 16, 14, 16, 14, 17, 26, 12438, 199, 10, 870, 3086, 666, 641, 3839, 199, 199, 37, 1711, 402, 314, 2569, 5365, 13, 30919, 3718, 911, 3222, 13116, 370, 642, 199, 10244, 26, 199, 199, 92, 2672, 20143, 19510, 446, 86, 17, 446, 67, 20182, 21960, 12792, 14, 16, 14, 16, 14, 17, 413, 14, 19, 14, 22, 14, 17, 14, 20, 14, 17, 14, 6686, 2036, 14, 20, 14, 17, 14, 17, 14, 18, 12792, 14, 16, 14, 16, 14, 17, 413, 413, 11869, 413, 14, 19, 14, 22, 14, 17, 14, 18, 14, 17, 14, 17, 14, 17, 14, 16, 308, 511, 199, 92, 2672, 20143, 262, 964, 446, 86, 18, 67, 446, 67, 486, 320, 432, 12792, 14, 16, 14, 16, 14, 17, 11869, 413, 14, 19, 14, 22, 14, 17, 14, 22, 14, 19, 14, 17, 14, 17, 14, 21, 14, 17, 199, 199, 1918, 23362, 799, 6594, 5084, 307, 7461, 641, 373, 17, 15, 86, 18, 67, 26549, 6391, 859, 199, 475, 28503, 3361, 3953, 1338, 12, 12252, 5007, 370, 26549, 12580, 12, 1536, 370, 199, 1589, 1067, 402, 922, 4223, 14, 199, 199, 2765, 2884, 15735, 3746, 314, 574, 402, 7046, 6639, 985, 12, 465, 652, 20382, 687, 9104, 26549, 199, 8524, 12, 436, 1443, 2811, 652, 370, 1336, 314, 1454, 17738, 7526, 7046, 6639, 985, 199, 7, 3455, 1370, 961, 27881, 7704, 23362, 21800, 32163, 3788, 543, 199, 29799, 985, 1159, 12, 440, 7662, 7526, 370, 2257, 26549, 12580, 14, 199, 199, 624, 3, 199, 504, 10382, 78, 311, 14, 4502, 492, 6869, 12, 1101, 199, 504, 10382, 78, 311, 14, 24499, 14, 305, 25400, 14, 68, 1679, 492, 18419, 199, 504, 10382, 78, 311, 14, 4502, 14, 8973, 1082, 969, 492, 302, 3249, 1195, 86, 199, 504, 10382, 78, 311, 14, 2625, 14, 1246, 492, 373, 18, 67, 199, 646, 295, 199, 199, 3, 2790, 26549, 6869, 543, 6384, 974, 727, 78, 972, 6869, 998, 436, 876, 13, 3556, 199, 3, 370, 2838, 7773, 17475, 199, 15523, 8524, 275, 6869, 14, 20821, 311, 8524, 342, 199, 199, 3, 11828, 282, 3233, 370, 506, 10302, 737, 2013, 6451, 2376, 402, 221, 199, 3, 26549, 12580, 436, 3032, 2257, 2860, 737, 6451, 2376, 1159, 2257, 4194, 14, 199, 3, 982, 737, 642, 6451, 2376, 3032, 2860, 787, 6042, 12, 3932, 892, 199, 3, 1338, 911, 506, 25350, 1771, 436, 1202, 701, 26549, 12580, 367, 6391, 985, 199, 3, 7267, 14, 199, 318, 1056, 22715, 8, 15523, 8524, 12, 2146, 1403, 12, 2860, 12, 7434, 35, 2347, 304, 272, 340, 295, 14, 1431, 360, 2795, 320, 432, 16110, 620, 8, 3669, 459, 9387, 985, 26536, 267, 870, 360, 497, 14827, 23633, 985, 19095, 83, 3985, 687, 450, 83, 1901, 8891, 3455, 60, 891, 450, 334, 3669, 459, 9387, 985, 995, 29010, 904, 779, 495, 8, 88, 9, 367, 671, 315, 2860, 459, 5545, 4935, 3488, 17, 2677, 1724, 267, 2860, 459, 9387, 985, 418, 275, 2860, 459, 9387, 985, 2278, 6311, 360, 3455, 358, 199, 199, 15523, 8524, 14, 23968, 14, 2683, 22715, 8, 272, 1056, 22715, 12, 272, 283, 8973, 821, 2114, 14, 1412, 607, 7909, 6173, 26, 15053, 7, 199, 9, 199, 199, 3, 27018, 3272, 199, 199, 3, 21802, 1806, 6509, 20, 199, 888, 14, 525, 7836, 8, 272, 20143, 8524, 12, 272, 18419, 14, 2261, 985, 12, 272, 18419, 14, 22086, 7836, 1252, 1490, 3120, 1385, 4725, 4195, 14, 16, 14, 16, 14, 17, 297, 32729, 430, 199, 9, 199, 199, 3, 26549, 86, 17, 15, 18, 67, 3272, 199, 199, 3, 13863, 985, 665, 5118, 7046, 6639, 985, 4412, 199, 888, 14, 525, 54, 17, 3989, 8, 15523, 8524, 12, 283, 1662, 13, 6789, 297, 283, 3455, 358, 199, 199, 3, 17555, 805, 367, 18390, 13116, 199, 318, 7434, 19941, 8, 15523, 8524, 12, 1174, 5083, 12, 1067, 8524, 1304, 12, 1067, 985, 12, 881, 2729, 8198, 83, 12, 7434, 35, 2347, 304, 272, 870, 360, 11598, 687, 9470, 8524, 1304, 2071, 83, 401, 9470, 985, 2071, 83, 4507, 450, 334, 267, 1067, 8524, 1304, 14, 9118, 5375, 1062, 267, 1067, 985, 14, 9118, 5375, 342, 267, 776, 272, 776, 272, 367, 536, 12, 1139, 315, 2729, 8198, 83, 26, 267, 870, 3508, 83, 275, 450, 83, 7, 450, 334, 354, 14, 9118, 5375, 1062, 1139, 14, 9118, 5375, 4059, 199, 199, 3, 11828, 26549, 13515, 737, 314, 26549, 6869, 199, 343, 32309, 86, 14, 11598, 21800, 8, 15523, 8524, 12, 7434, 19941, 9, 199, 199, 15523, 8524, 14, 5545, 15461, 14, 2423, 21031, 8, 17, 9, 327, 642, 3906, 3955, 7078, 9578, 199, 199, 3, 3378, 473, 15, 47, 17475, 1314, 3955, 9128, 9212, 436, 3222, 406, 27389, 199, 893, 26, 272, 20143, 8524, 14, 5545, 15461, 14, 1065, 15461, 342, 199, 2590, 26, 272, 20143, 8524, 14, 5545, 15461, 14, 1600, 15461, 342, 272, 746, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 1505, 432, 26549, 7046, 6639, 1561, 3247, 701, 13156, 199, 20421, 20421, 20421, 20421, 20421, 12437, 199, 199, 14235, 26549, 9074, 1282, 15, 568, 3516, 3788, 543, 314, 2569, 1511, 26, 199, 199, 10, 26549, 86, 17, 15, 30919, 86, 18, 67, 199, 10, 543, 1263, 26549, 23633, 4877, 13156, 1987, 10, 320, 432, 25737, 199, 10, 1806, 6509, 20, 15, 17457, 12, 22721, 737, 12792, 14, 16, 14, 16, 14, 17, 26, 12438, 199, 10, 870, 3086, 666, 641, 3839, 199, 199, 37, 1711, 402, 314, 2569, 5365, 13, 30919, 3718, 911, 3222, 13116, 370, 642, 199, 10244, 26, 199, 199, 92, 2672, 20143, 19510, 446, 86, 17, 446, 67, 20182, 21960, 12792, 14, 16, 14, 16, 14, 17, 413, 14, 19, 14, 22, 14, 17, 14, 20, 14, 17, 14, 6686, 2036, 14, 20, 14, 17, 14, 17, 14, 18, 12792, 14, 16, 14, 16, 14, 17, 413, 413, 11869, 413, 14, 19, 14, 22, 14, 17, 14, 18, 14, 17, 14, 17, 14, 17, 14, 16, 308, 511, 199, 92, 2672, 20143, 262, 964, 446, 86, 18, 67, 446, 67, 486, 320, 432, 12792, 14, 16, 14, 16, 14, 17, 11869, 413, 14, 19, 14, 22, 14, 17, 14, 22, 14, 19, 14, 17, 14, 17, 14, 21, 14, 17, 199, 199, 1918, 23362, 799, 6594, 5084, 307, 7461, 641, 373, 17, 15, 86, 18, 67, 26549, 6391, 859, 199, 475, 28503, 3361, 3953, 1338, 12, 12252, 5007, 370, 26549, 12580, 12, 1536, 370, 199, 1589, 1067, 402, 922, 4223, 14, 199, 199, 2765, 2884, 15735, 3746, 314, 574, 402, 7046, 6639, 985, 12, 465, 652, 20382, 687, 9104, 26549, 199, 8524, 12, 436, 1443, 2811, 652, 370, 1336, 314, 1454, 17738, 7526, 7046, 6639, 985, 199, 7, 3455, 1370, 961, 27881, 7704, 23362, 21800, 32163, 3788, 543, 199, 29799, 985, 1159, 12, 440, 7662, 7526, 370, 2257, 26549, 12580, 14, 199, 199, 624, 3, 199, 504, 10382, 78, 311, 14, 4502, 492, 6869, 12, 1101, 199, 504, 10382, 78, 311, 14, 24499, 14, 305, 25400, 14, 68, 1679, 492, 18419, 199, 504, 10382, 78, 311, 14, 4502, 14, 8973, 1082, 969, 492, 302, 3249, 1195, 86, 199, 504, 10382, 78, 311, 14, 2625, 14, 1246, 492, 373, 18, 67, 199, 646, 295, 199, 199, 3, 2790, 26549, 6869, 543, 6384, 974, 727, 78, 972, 6869, 998, 436, 876, 13, 3556, 199, 3, 370, 2838, 7773, 17475, 199, 15523, 8524, 275, 6869, 14, 20821, 311, 8524, 342, 199, 199, 3, 11828, 282, 3233, 370, 506, 10302, 737, 2013, 6451, 2376, 402, 221, 199, 3, 26549, 12580, 436, 3032, 2257, 2860, 737, 6451, 2376, 1159, 2257, 4194, 14, 199, 3, 982, 737, 642, 6451, 2376, 3032, 2860, 787, 6042, 12, 3932, 892, 199, 3, 1338, 911, 506, 25350, 1771, 436, 1202, 701, 26549, 12580, 367, 6391, 985, 199, 3, 7267, 14, 199, 318, 1056, 22715, 8, 15523, 8524, 12, 2146, 1403, 12, 2860, 12, 7434, 35, 2347, 304, 272, 340, 295, 14, 1431, 360, 2795, 320, 432, 16110, 620, 8, 3669, 459, 9387, 985, 26536, 267, 870, 360, 497, 14827, 23633, 985, 19095, 83, 3985, 687, 450, 83, 1901, 8891, 3455, 60, 891, 450, 334, 3669, 459, 9387, 985, 995, 29010, 904, 779, 495, 8, 88, 9, 367, 671, 315, 2860, 459, 5545, 4935, 3488, 17, 2677, 1724, 267, 2860, 459, 9387, 985, 418, 275, 2860, 459, 9387, 985, 2278, 6311, 360, 3455, 358, 199, 199, 15523, 8524, 14, 23968, 14, 2683, 22715, 8, 272, 1056, 22715, 12, 272, 283, 8973, 821, 2114, 14, 1412, 607, 7909, 6173, 26, 15053, 7, 199, 9, 199, 199, 3, 27018, 3272, 199, 199, 3, 21802, 1806, 6509, 20, 199, 888, 14, 525, 7836, 8, 272, 20143, 8524, 12, 272, 18419, 14, 2261, 985, 12, 272, 18419, 14, 22086, 7836, 1252, 1490, 3120, 1385, 4725, 4195, 14, 16, 14, 16, 14, 17, 297, 32729, 430, 199, 9, 199, 199, 3, 26549, 86, 17, 15, 18, 67, 3272, 199, 199, 3, 13863, 985, 665, 5118, 7046, 6639, 985, 4412, 199, 888, 14, 525, 54, 17, 3989, 8, 15523, 8524, 12, 283, 1662, 13, 6789, 297, 283, 3455, 358, 199, 199, 3, 17555, 805, 367, 18390, 13116, 199, 318, 7434, 19941, 8, 15523, 8524, 12, 1174, 5083, 12, 1067, 8524, 1304, 12, 1067, 985, 12, 881, 2729, 8198, 83, 12, 7434, 35, 2347, 304, 272, 870, 360, 11598, 687, 9470, 8524, 1304, 2071, 83, 401, 9470, 985, 2071, 83, 4507, 450, 334, 267, 1067, 8524, 1304, 14, 9118, 5375, 1062, 267, 1067, 985, 14, 9118, 5375, 342, 267, 776, 272, 776, 272, 367, 536, 12, 1139, 315, 2729, 8198, 83, 26, 267, 870, 3508, 83, 275, 450, 83, 7, 450, 334, 354, 14, 9118, 5375, 1062, 1139, 14, 9118, 5375, 4059, 199, 199, 3, 11828, 26549, 13515, 737, 314, 26549, 6869, 199, 343, 32309, 86, 14, 11598, 21800, 8, 15523, 8524, 12, 7434, 19941, 9, 199, 199, 15523, 8524, 14, 5545, 15461, 14, 2423, 21031, 8, 17, 9, 327, 642, 3906, 3955, 7078, 9578, 199, 199, 3, 3378, 473, 15, 47, 17475, 1314, 3955, 9128, 9212, 436, 3222, 406, 27389, 199, 893, 26, 272, 20143, 8524, 14, 5545, 15461, 14, 1065, 15461, 342, 199, 2590, 26, 272, 20143, 8524, 14, 5545, 15461, 14, 1600, 15461, 342, 272, 746, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
yangrongwei/gyp
test/generator-output/gyptest-actions.py
198
2019
#!/usr/bin/env python # Copyright (c) 2012 Google Inc. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """ Verifies --generator-output= behavior when using actions. """ import TestGyp # Android doesn't support --generator-output. test = TestGyp.TestGyp(formats=['!android']) # All the generated files should go under 'gypfiles'. The source directory # ('actions') should be untouched. test.writable(test.workpath('actions'), False) test.run_gyp('actions.gyp', '--generator-output=' + test.workpath('gypfiles'), chdir='actions') test.writable(test.workpath('actions'), True) test.relocate('actions', 'relocate/actions') test.relocate('gypfiles', 'relocate/gypfiles') test.writable(test.workpath('relocate/actions'), False) # Some of the action outputs use "pure" relative paths (i.e. without prefixes # like <(INTERMEDIATE_DIR) or <(PROGRAM_DIR)). Even though we are building under # 'gypfiles', such outputs will still be created relative to the original .gyp # sources. Projects probably wouldn't normally do this, since it kind of defeats # the purpose of '--generator-output', but it is supported behaviour. test.writable(test.workpath('relocate/actions/build'), True) test.writable(test.workpath('relocate/actions/subdir1/build'), True) test.writable(test.workpath('relocate/actions/subdir1/actions-out'), True) test.writable(test.workpath('relocate/actions/subdir2/build'), True) test.writable(test.workpath('relocate/actions/subdir2/actions-out'), True) test.build('actions.gyp', test.ALL, chdir='relocate/gypfiles') expect = """\ Hello from program.c Hello from make-prog1.py Hello from make-prog2.py """ if test.format == 'xcode': chdir = 'relocate/actions/subdir1' else: chdir = 'relocate/gypfiles' test.run_built_executable('program', chdir=chdir, stdout=expect) test.must_match('relocate/actions/subdir2/actions-out/file.out', "Hello from make-file.py\n") test.pass_test()
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 1898, 334, 67, 9, 6029, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 199, 21168, 1553, 4679, 13, 1199, 29, 5953, 1380, 1808, 5445, 14, 199, 624, 199, 199, 646, 25688, 199, 199, 3, 14694, 3181, 1133, 2291, 1553, 4679, 13, 1199, 14, 199, 396, 275, 25688, 14, 774, 13899, 8, 6321, 2968, 1, 6238, 1105, 199, 199, 3, 2900, 314, 4046, 1584, 1077, 2621, 1334, 283, 6179, 1725, 1370, 710, 1350, 2082, 199, 3, 661, 3723, 358, 1077, 506, 625, 31854, 14, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 3723, 659, 756, 9, 199, 396, 14, 1065, 63, 6179, 360, 3723, 14, 6179, 297, 1467, 2850, 4679, 13, 1199, 534, 435, 511, 14, 800, 515, 360, 6179, 1725, 659, 1467, 13097, 534, 3723, 358, 199, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 3723, 659, 715, 9, 199, 199, 396, 14, 18919, 360, 3723, 297, 283, 18919, 15, 3723, 358, 199, 396, 14, 18919, 360, 6179, 1725, 297, 283, 18919, 15, 6179, 1725, 358, 199, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 659, 756, 9, 199, 199, 3, 6601, 402, 314, 1595, 4704, 675, 298, 5115, 2, 3847, 3792, 334, 73, 14, 69, 14, 1928, 13158, 199, 3, 2839, 665, 8, 23227, 63, 3022, 9, 503, 665, 8, 15605, 63, 3022, 4992, 22207, 10617, 781, 787, 10015, 1334, 199, 3, 283, 6179, 1725, 297, 4066, 4704, 911, 5139, 506, 2737, 3847, 370, 314, 3379, 1275, 6179, 199, 3, 5274, 14, 7290, 83, 8646, 3955, 78, 1133, 12252, 886, 642, 12, 3967, 652, 4928, 402, 347, 69, 1956, 199, 3, 314, 12016, 402, 2850, 4679, 13, 1199, 297, 1325, 652, 365, 3748, 13942, 14, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 15, 1506, 659, 715, 9, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 15, 10622, 17, 15, 1506, 659, 715, 9, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 15, 10622, 17, 15, 3723, 13, 548, 659, 715, 9, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 15, 10622, 18, 15, 1506, 659, 715, 9, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 15, 10622, 18, 15, 3723, 13, 548, 659, 715, 9, 199, 199, 396, 14, 1506, 360, 3723, 14, 6179, 297, 511, 14, 1761, 12, 13097, 534, 18919, 15, 6179, 1725, 358, 199, 199, 4921, 275, 9638, 199, 6257, 687, 2240, 14, 67, 199, 6257, 687, 1852, 13, 6595, 17, 14, 647, 199, 6257, 687, 1852, 13, 6595, 18, 14, 647, 199, 624, 199, 199, 692, 511, 14, 908, 508, 283, 8701, 356, 523, 13097, 275, 283, 18919, 15, 3723, 15, 10622, 17, 7, 199, 2836, 26, 523, 13097, 275, 283, 18919, 15, 6179, 1725, 7, 199, 396, 14, 1065, 63, 11730, 63, 5904, 360, 6815, 297, 13097, 29, 8563, 12, 3839, 29, 4921, 9, 199, 199, 396, 14, 7790, 63, 1431, 360, 18919, 15, 3723, 15, 10622, 18, 15, 3723, 13, 548, 15, 493, 14, 548, 297, 355, 298, 6257, 687, 1852, 13, 493, 14, 647, 60, 78, 531, 199, 199, 396, 14, 1529, 63, 396, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 1898, 334, 67, 9, 6029, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 199, 21168, 1553, 4679, 13, 1199, 29, 5953, 1380, 1808, 5445, 14, 199, 624, 199, 199, 646, 25688, 199, 199, 3, 14694, 3181, 1133, 2291, 1553, 4679, 13, 1199, 14, 199, 396, 275, 25688, 14, 774, 13899, 8, 6321, 2968, 1, 6238, 1105, 199, 199, 3, 2900, 314, 4046, 1584, 1077, 2621, 1334, 283, 6179, 1725, 1370, 710, 1350, 2082, 199, 3, 661, 3723, 358, 1077, 506, 625, 31854, 14, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 3723, 659, 756, 9, 199, 396, 14, 1065, 63, 6179, 360, 3723, 14, 6179, 297, 1467, 2850, 4679, 13, 1199, 534, 435, 511, 14, 800, 515, 360, 6179, 1725, 659, 1467, 13097, 534, 3723, 358, 199, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 3723, 659, 715, 9, 199, 199, 396, 14, 18919, 360, 3723, 297, 283, 18919, 15, 3723, 358, 199, 396, 14, 18919, 360, 6179, 1725, 297, 283, 18919, 15, 6179, 1725, 358, 199, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 659, 756, 9, 199, 199, 3, 6601, 402, 314, 1595, 4704, 675, 298, 5115, 2, 3847, 3792, 334, 73, 14, 69, 14, 1928, 13158, 199, 3, 2839, 665, 8, 23227, 63, 3022, 9, 503, 665, 8, 15605, 63, 3022, 4992, 22207, 10617, 781, 787, 10015, 1334, 199, 3, 283, 6179, 1725, 297, 4066, 4704, 911, 5139, 506, 2737, 3847, 370, 314, 3379, 1275, 6179, 199, 3, 5274, 14, 7290, 83, 8646, 3955, 78, 1133, 12252, 886, 642, 12, 3967, 652, 4928, 402, 347, 69, 1956, 199, 3, 314, 12016, 402, 2850, 4679, 13, 1199, 297, 1325, 652, 365, 3748, 13942, 14, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 15, 1506, 659, 715, 9, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 15, 10622, 17, 15, 1506, 659, 715, 9, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 15, 10622, 17, 15, 3723, 13, 548, 659, 715, 9, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 15, 10622, 18, 15, 1506, 659, 715, 9, 199, 396, 14, 15053, 8, 396, 14, 800, 515, 360, 18919, 15, 3723, 15, 10622, 18, 15, 3723, 13, 548, 659, 715, 9, 199, 199, 396, 14, 1506, 360, 3723, 14, 6179, 297, 511, 14, 1761, 12, 13097, 534, 18919, 15, 6179, 1725, 358, 199, 199, 4921, 275, 9638, 199, 6257, 687, 2240, 14, 67, 199, 6257, 687, 1852, 13, 6595, 17, 14, 647, 199, 6257, 687, 1852, 13, 6595, 18, 14, 647, 199, 624, 199, 199, 692, 511, 14, 908, 508, 283, 8701, 356, 523, 13097, 275, 283, 18919, 15, 3723, 15, 10622, 17, 7, 199, 2836, 26, 523, 13097, 275, 283, 18919, 15, 6179, 1725, 7, 199, 396, 14, 1065, 63, 11730, 63, 5904, 360, 6815, 297, 13097, 29, 8563, 12, 3839, 29, 4921, 9, 199, 199, 396, 14, 7790, 63, 1431, 360, 18919, 15, 3723, 15, 10622, 18, 15, 3723, 13, 548, 15, 493, 14, 548, 297, 355, 298, 6257, 687, 1852, 13, 493, 14, 647, 60, 78, 531, 199, 199, 396, 14, 1529, 63, 396, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
mahak/cinder
cinder/tests/unit/volume/drivers/dell_emc/powerstore/test_volume_group_create_from_source.py
2
4981
# Copyright (c) 2021 Dell Inc. or its subsidiaries. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from unittest import mock from cinder.tests.unit import fake_group from cinder.tests.unit import fake_group_snapshot from cinder.tests.unit import fake_snapshot from cinder.tests.unit import fake_volume from cinder.tests.unit.volume.drivers.dell_emc import powerstore class TestVolumeGroupCreateFromSource(powerstore.TestPowerStoreDriver): @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client." "PowerStoreClient.get_chap_config") def setUp(self, mock_chap): super(TestVolumeGroupCreateFromSource, self).setUp() self.driver.check_for_setup_error() self.volume = fake_volume.fake_volume_obj( self.context, host="host@backend", provider_id="fake_id", size=8 ) self.source_volume = fake_volume.fake_volume_obj( self.context, host="host@backend", provider_id="fake_id", size=8 ) self.source_volume_snap = fake_snapshot.fake_snapshot_obj( self.context, volume=self.source_volume, volume_size=8 ) self.group = fake_group.fake_group_obj( self.context, ) self.source_group = fake_group.fake_group_obj( self.context, ) self.source_group_snap = fake_group_snapshot.fake_group_snapshot_obj( self.context ) self.source_group_snap.group = self.source_group @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client." "PowerStoreClient.rename_volume") @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client." "PowerStoreClient.get_volume_id_by_name") @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client." "PowerStoreClient.clone_vg_or_vg_snapshot") @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client." "PowerStoreClient.get_vg_id_by_name") @mock.patch("cinder.volume.volume_utils.is_group_a_cg_snapshot_type") def test_create_volume_group_clone(self, mock_is_cg, mock_get_group_id, mock_clone, mock_get_volume_id, mock_rename): mock_get_volume_id.return_value = "fake_id" group_updates, volume_updates = self.driver.create_group_from_src( self.context, self.group, volumes=[self.volume], source_group=self.source_group, source_vols=[self.source_volume] ) self.assertEqual(1, len(volume_updates)) self.assertEqual("fake_id", volume_updates[0]["provider_id"]) @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client." "PowerStoreClient.rename_volume") @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client." "PowerStoreClient.get_volume_id_by_name") @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client." "PowerStoreClient.clone_vg_or_vg_snapshot") @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client." "PowerStoreClient.get_vg_snapshot_id_by_name") @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client." "PowerStoreClient.get_vg_id_by_name") @mock.patch("cinder.volume.volume_utils.is_group_a_cg_snapshot_type") def test_create_volume_group_from_snapshot(self, mock_is_cg, mock_get_group_id, mock_get_snapshot_id, mock_clone, mock_get_volume_id, mock_rename): mock_get_volume_id.return_value = "fake_id" group_updates, volume_updates = self.driver.create_group_from_src( self.context, self.group, volumes=[self.volume], snapshots=[self.source_volume_snap], group_snapshot=self.source_group_snap ) self.assertEqual(1, len(volume_updates)) self.assertEqual("fake_id", volume_updates[0]["provider_id"])
apache-2.0
[ 3, 1898, 334, 67, 9, 499, 15385, 577, 1697, 3277, 14, 503, 2399, 1007, 338, 328, 3433, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 1334, 314, 844, 14, 199, 199, 504, 2882, 492, 1683, 199, 199, 504, 13069, 14, 2219, 14, 3248, 492, 4026, 63, 923, 199, 504, 13069, 14, 2219, 14, 3248, 492, 4026, 63, 923, 63, 4753, 199, 504, 13069, 14, 2219, 14, 3248, 492, 4026, 63, 4753, 199, 504, 13069, 14, 2219, 14, 3248, 492, 4026, 63, 2405, 199, 504, 13069, 14, 2219, 14, 3248, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 492, 7074, 1617, 421, 199, 533, 1379, 6464, 2448, 2499, 2532, 2980, 8, 5652, 1617, 14, 774, 6921, 5502, 6158, 304, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 362, 63, 28765, 63, 888, 531, 272, 347, 3613, 8, 277, 12, 1683, 63, 28765, 304, 267, 1613, 8, 774, 6464, 2448, 2499, 2532, 2980, 12, 291, 680, 5996, 342, 267, 291, 14, 3090, 14, 1074, 63, 509, 63, 2758, 63, 705, 342, 267, 291, 14, 2405, 275, 4026, 63, 2405, 14, 3183, 63, 2405, 63, 1113, 8, 288, 291, 14, 1100, 12, 288, 1591, 628, 1102, 32, 4620, 401, 288, 5022, 63, 344, 628, 3183, 63, 344, 401, 288, 1568, 29, 24, 267, 776, 267, 291, 14, 1365, 63, 2405, 275, 4026, 63, 2405, 14, 3183, 63, 2405, 63, 1113, 8, 288, 291, 14, 1100, 12, 288, 1591, 628, 1102, 32, 4620, 401, 288, 5022, 63, 344, 628, 3183, 63, 344, 401, 288, 1568, 29, 24, 267, 776, 267, 291, 14, 1365, 63, 2405, 63, 10002, 275, 4026, 63, 4753, 14, 3183, 63, 4753, 63, 1113, 8, 288, 291, 14, 1100, 12, 288, 3301, 29, 277, 14, 1365, 63, 2405, 12, 288, 3301, 63, 890, 29, 24, 267, 776, 267, 291, 14, 923, 275, 4026, 63, 923, 14, 3183, 63, 923, 63, 1113, 8, 288, 291, 14, 1100, 12, 267, 776, 267, 291, 14, 1365, 63, 923, 275, 4026, 63, 923, 14, 3183, 63, 923, 63, 1113, 8, 288, 291, 14, 1100, 12, 267, 776, 267, 291, 14, 1365, 63, 923, 63, 10002, 275, 4026, 63, 923, 63, 4753, 14, 3183, 63, 923, 63, 4753, 63, 1113, 8, 288, 291, 14, 1100, 267, 776, 267, 291, 14, 1365, 63, 923, 63, 10002, 14, 923, 275, 291, 14, 1365, 63, 923, 339, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 8165, 63, 2405, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 362, 63, 2405, 63, 344, 63, 991, 63, 354, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 6311, 63, 10929, 63, 269, 63, 10929, 63, 4753, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 362, 63, 10929, 63, 344, 63, 991, 63, 354, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 2405, 63, 1208, 14, 374, 63, 923, 63, 65, 63, 12595, 63, 4753, 63, 466, 531, 272, 347, 511, 63, 981, 63, 2405, 63, 923, 63, 6311, 8, 277, 12, 4318, 1683, 63, 374, 63, 12595, 12, 4318, 1683, 63, 362, 63, 923, 63, 344, 12, 4318, 1683, 63, 6311, 12, 4318, 1683, 63, 362, 63, 2405, 63, 344, 12, 4318, 1683, 63, 8165, 304, 267, 1683, 63, 362, 63, 2405, 63, 344, 14, 1107, 63, 585, 275, 298, 3183, 63, 344, 2, 267, 1572, 63, 7618, 12, 3301, 63, 7618, 275, 291, 14, 3090, 14, 981, 63, 923, 63, 504, 63, 2164, 8, 288, 291, 14, 1100, 12, 288, 291, 14, 923, 12, 288, 12158, 1524, 277, 14, 2405, 467, 288, 1350, 63, 923, 29, 277, 14, 1365, 63, 923, 12, 288, 1350, 63, 86, 1446, 1524, 277, 14, 1365, 63, 2405, 61, 267, 776, 267, 291, 14, 629, 8, 17, 12, 822, 8, 2405, 63, 7618, 430, 267, 291, 14, 629, 480, 3183, 63, 344, 401, 3301, 63, 7618, 59, 16, 7541, 3780, 63, 344, 3135, 339, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 8165, 63, 2405, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 362, 63, 2405, 63, 344, 63, 991, 63, 354, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 6311, 63, 10929, 63, 269, 63, 10929, 63, 4753, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 362, 63, 10929, 63, 4753, 63, 344, 63, 991, 63 ]
[ 1898, 334, 67, 9, 499, 15385, 577, 1697, 3277, 14, 503, 2399, 1007, 338, 328, 3433, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 1334, 314, 844, 14, 199, 199, 504, 2882, 492, 1683, 199, 199, 504, 13069, 14, 2219, 14, 3248, 492, 4026, 63, 923, 199, 504, 13069, 14, 2219, 14, 3248, 492, 4026, 63, 923, 63, 4753, 199, 504, 13069, 14, 2219, 14, 3248, 492, 4026, 63, 4753, 199, 504, 13069, 14, 2219, 14, 3248, 492, 4026, 63, 2405, 199, 504, 13069, 14, 2219, 14, 3248, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 492, 7074, 1617, 421, 199, 533, 1379, 6464, 2448, 2499, 2532, 2980, 8, 5652, 1617, 14, 774, 6921, 5502, 6158, 304, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 362, 63, 28765, 63, 888, 531, 272, 347, 3613, 8, 277, 12, 1683, 63, 28765, 304, 267, 1613, 8, 774, 6464, 2448, 2499, 2532, 2980, 12, 291, 680, 5996, 342, 267, 291, 14, 3090, 14, 1074, 63, 509, 63, 2758, 63, 705, 342, 267, 291, 14, 2405, 275, 4026, 63, 2405, 14, 3183, 63, 2405, 63, 1113, 8, 288, 291, 14, 1100, 12, 288, 1591, 628, 1102, 32, 4620, 401, 288, 5022, 63, 344, 628, 3183, 63, 344, 401, 288, 1568, 29, 24, 267, 776, 267, 291, 14, 1365, 63, 2405, 275, 4026, 63, 2405, 14, 3183, 63, 2405, 63, 1113, 8, 288, 291, 14, 1100, 12, 288, 1591, 628, 1102, 32, 4620, 401, 288, 5022, 63, 344, 628, 3183, 63, 344, 401, 288, 1568, 29, 24, 267, 776, 267, 291, 14, 1365, 63, 2405, 63, 10002, 275, 4026, 63, 4753, 14, 3183, 63, 4753, 63, 1113, 8, 288, 291, 14, 1100, 12, 288, 3301, 29, 277, 14, 1365, 63, 2405, 12, 288, 3301, 63, 890, 29, 24, 267, 776, 267, 291, 14, 923, 275, 4026, 63, 923, 14, 3183, 63, 923, 63, 1113, 8, 288, 291, 14, 1100, 12, 267, 776, 267, 291, 14, 1365, 63, 923, 275, 4026, 63, 923, 14, 3183, 63, 923, 63, 1113, 8, 288, 291, 14, 1100, 12, 267, 776, 267, 291, 14, 1365, 63, 923, 63, 10002, 275, 4026, 63, 923, 63, 4753, 14, 3183, 63, 923, 63, 4753, 63, 1113, 8, 288, 291, 14, 1100, 267, 776, 267, 291, 14, 1365, 63, 923, 63, 10002, 14, 923, 275, 291, 14, 1365, 63, 923, 339, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 8165, 63, 2405, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 362, 63, 2405, 63, 344, 63, 991, 63, 354, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 6311, 63, 10929, 63, 269, 63, 10929, 63, 4753, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 362, 63, 10929, 63, 344, 63, 991, 63, 354, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 2405, 63, 1208, 14, 374, 63, 923, 63, 65, 63, 12595, 63, 4753, 63, 466, 531, 272, 347, 511, 63, 981, 63, 2405, 63, 923, 63, 6311, 8, 277, 12, 4318, 1683, 63, 374, 63, 12595, 12, 4318, 1683, 63, 362, 63, 923, 63, 344, 12, 4318, 1683, 63, 6311, 12, 4318, 1683, 63, 362, 63, 2405, 63, 344, 12, 4318, 1683, 63, 8165, 304, 267, 1683, 63, 362, 63, 2405, 63, 344, 14, 1107, 63, 585, 275, 298, 3183, 63, 344, 2, 267, 1572, 63, 7618, 12, 3301, 63, 7618, 275, 291, 14, 3090, 14, 981, 63, 923, 63, 504, 63, 2164, 8, 288, 291, 14, 1100, 12, 288, 291, 14, 923, 12, 288, 12158, 1524, 277, 14, 2405, 467, 288, 1350, 63, 923, 29, 277, 14, 1365, 63, 923, 12, 288, 1350, 63, 86, 1446, 1524, 277, 14, 1365, 63, 2405, 61, 267, 776, 267, 291, 14, 629, 8, 17, 12, 822, 8, 2405, 63, 7618, 430, 267, 291, 14, 629, 480, 3183, 63, 344, 401, 3301, 63, 7618, 59, 16, 7541, 3780, 63, 344, 3135, 339, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 8165, 63, 2405, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 362, 63, 2405, 63, 344, 63, 991, 63, 354, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 6311, 63, 10929, 63, 269, 63, 10929, 63, 4753, 531, 272, 768, 1805, 14, 2068, 480, 12372, 14, 2405, 14, 13337, 14, 271, 914, 63, 69, 5466, 14, 5652, 1617, 14, 1258, 2122, 355, 298, 6921, 5502, 3041, 14, 362, 63, 10929, 63, 4753, 63, 344, 63, 991, 63, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
romankagan/DDBWorkbench
plugins/hg4idea/testData/bin/mercurial/lsprofcalltree.py
100
2760
""" lsprofcalltree.py - lsprof output which is readable by kcachegrind Authors: * David Allouche <david <at> allouche.net> * Jp Calderone & Itamar Shtull-Trauring * Johan Dahlin This software may be used and distributed according to the terms of the GNU General Public License, incorporated herein by reference. """ def label(code): if isinstance(code, str): return '~' + code # built-in functions ('~' sorts at the end) else: return '%s %s:%d' % (code.co_name, code.co_filename, code.co_firstlineno) class KCacheGrind(object): def __init__(self, profiler): self.data = profiler.getstats() self.out_file = None def output(self, out_file): self.out_file = out_file print >> out_file, 'events: Ticks' self._print_summary() for entry in self.data: self._entry(entry) def _print_summary(self): max_cost = 0 for entry in self.data: totaltime = int(entry.totaltime * 1000) max_cost = max(max_cost, totaltime) print >> self.out_file, 'summary: %d' % (max_cost,) def _entry(self, entry): out_file = self.out_file code = entry.code #print >> out_file, 'ob=%s' % (code.co_filename,) if isinstance(code, str): print >> out_file, 'fi=~' else: print >> out_file, 'fi=%s' % (code.co_filename,) print >> out_file, 'fn=%s' % (label(code),) inlinetime = int(entry.inlinetime * 1000) if isinstance(code, str): print >> out_file, '0 ', inlinetime else: print >> out_file, '%d %d' % (code.co_firstlineno, inlinetime) # recursive calls are counted in entry.calls if entry.calls: calls = entry.calls else: calls = [] if isinstance(code, str): lineno = 0 else: lineno = code.co_firstlineno for subentry in calls: self._subentry(lineno, subentry) print >> out_file def _subentry(self, lineno, subentry): out_file = self.out_file code = subentry.code #print >> out_file, 'cob=%s' % (code.co_filename,) print >> out_file, 'cfn=%s' % (label(code),) if isinstance(code, str): print >> out_file, 'cfi=~' print >> out_file, 'calls=%d 0' % (subentry.callcount,) else: print >> out_file, 'cfi=%s' % (code.co_filename,) print >> out_file, 'calls=%d %d' % ( subentry.callcount, code.co_firstlineno) totaltime = int(subentry.totaltime * 1000) print >> out_file, '%d %d' % (lineno, totaltime)
apache-2.0
[ 624, 199, 478, 14979, 1250, 2350, 14, 647, 446, 9100, 14979, 1072, 1314, 365, 12701, 701, 1022, 1637, 21510, 199, 199, 2817, 1384, 26, 272, 627, 20232, 4580, 320, 85, 595, 665, 983, 5017, 665, 292, 30, 741, 320, 85, 595, 14, 846, 30, 272, 627, 1603, 80, 8256, 424, 368, 1253, 2779, 455, 285, 428, 517, 979, 13, 2437, 4039, 272, 627, 7135, 19262, 577, 11326, 472, 199, 199, 2765, 2032, 1443, 506, 1202, 436, 1854, 7182, 370, 314, 2895, 199, 1618, 314, 1664, 1696, 1684, 844, 12, 30147, 972, 2348, 262, 701, 3659, 14, 199, 624, 199, 199, 318, 1768, 8, 600, 304, 272, 340, 1228, 8, 600, 12, 620, 304, 267, 372, 17352, 7, 435, 1233, 259, 327, 6137, 13, 262, 3423, 661, 94, 7, 30313, 737, 314, 1284, 9, 272, 587, 26, 267, 372, 1543, 83, 450, 83, 2689, 68, 7, 450, 334, 600, 14, 331, 63, 354, 12, 2490, 1233, 14, 331, 63, 1501, 12, 2490, 1233, 14, 331, 63, 30114, 9, 199, 199, 533, 1804, 4437, 23765, 688, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 23173, 304, 267, 291, 14, 576, 275, 23173, 14, 362, 3200, 342, 267, 291, 14, 548, 63, 493, 275, 488, 339, 347, 1072, 8, 277, 12, 734, 63, 493, 304, 267, 291, 14, 548, 63, 493, 275, 734, 63, 493, 267, 870, 4331, 734, 63, 493, 12, 283, 4368, 26, 18742, 83, 7, 267, 291, 423, 1361, 63, 4705, 342, 267, 367, 2397, 315, 291, 14, 576, 26, 288, 291, 423, 2373, 8, 2373, 9, 339, 347, 485, 1361, 63, 4705, 8, 277, 304, 267, 1390, 63, 6336, 275, 378, 267, 367, 2397, 315, 291, 14, 576, 26, 288, 3141, 521, 275, 1109, 8, 2373, 14, 2923, 521, 627, 5198, 9, 288, 1390, 63, 6336, 275, 1390, 8, 988, 63, 6336, 12, 3141, 521, 9, 267, 870, 4331, 291, 14, 548, 63, 493, 12, 283, 4705, 26, 450, 68, 7, 450, 334, 988, 63, 6336, 4258, 339, 347, 485, 2373, 8, 277, 12, 2397, 304, 267, 734, 63, 493, 275, 291, 14, 548, 63, 493, 398, 1233, 275, 2397, 14, 600, 267, 327, 1361, 4331, 734, 63, 493, 12, 283, 2873, 2458, 83, 7, 450, 334, 600, 14, 331, 63, 1501, 4258, 267, 340, 1228, 8, 600, 12, 620, 304, 288, 870, 4331, 734, 63, 493, 12, 283, 329, 29, 94, 7, 267, 587, 26, 288, 870, 4331, 734, 63, 493, 12, 283, 329, 2458, 83, 7, 450, 334, 600, 14, 331, 63, 1501, 4258, 267, 870, 4331, 734, 63, 493, 12, 283, 2324, 2458, 83, 7, 450, 334, 1302, 8, 600, 16945, 398, 8308, 521, 275, 1109, 8, 2373, 14, 6460, 521, 627, 5198, 9, 267, 340, 1228, 8, 600, 12, 620, 304, 288, 870, 4331, 734, 63, 493, 12, 283, 16, 1656, 8308, 521, 267, 587, 26, 288, 870, 4331, 734, 63, 493, 12, 1543, 68, 450, 68, 7, 450, 334, 600, 14, 331, 63, 30114, 12, 8308, 521, 9, 398, 327, 9133, 4882, 787, 31662, 315, 2397, 14, 5352, 267, 340, 2397, 14, 5352, 26, 288, 4882, 275, 2397, 14, 5352, 267, 587, 26, 288, 4882, 275, 942, 398, 340, 1228, 8, 600, 12, 620, 304, 288, 5874, 275, 378, 267, 587, 26, 288, 5874, 275, 1233, 14, 331, 63, 30114, 398, 367, 1007, 2373, 315, 4882, 26, 288, 291, 423, 954, 2373, 8, 3469, 12, 1007, 2373, 9, 267, 870, 4331, 734, 63, 493, 339, 347, 485, 954, 2373, 8, 277, 12, 5874, 12, 1007, 2373, 304, 267, 734, 63, 493, 275, 291, 14, 548, 63, 493, 267, 1233, 275, 1007, 2373, 14, 600, 267, 327, 1361, 4331, 734, 63, 493, 12, 283, 331, 66, 2458, 83, 7, 450, 334, 600, 14, 331, 63, 1501, 4258, 267, 870, 4331, 734, 63, 493, 12, 283, 2177, 78, 2458, 83, 7, 450, 334, 1302, 8, 600, 16945, 267, 340, 1228, 8, 600, 12, 620, 304, 288, 870, 4331, 734, 63, 493, 12, 283, 67, 329, 29, 94, 7, 288, 870, 4331, 734, 63, 493, 12, 283, 5352, 2458, 68, 378, 7, 450, 334, 954, 2373, 14, 1250, 835, 4258, 267, 587, 26, 288, 870, 4331, 734, 63, 493, 12, 283, 67, 329, 2458, 83, 7, 450, 334, 600, 14, 331, 63, 1501, 4258, 288, 870, 4331, 734, 63, 493, 12, 283, 5352, 2458, 68, 450, 68, 7, 450, 334, 355, 1007, 2373, 14, 1250, 835, 12, 1233, 14, 331, 63, 30114, 9, 398, 3141, 521, 275, 1109, 8, 954, 2373, 14, 2923, 521, 627, 5198, 9, 267, 870, 4331, 734, 63, 493, 12, 1543, 68, 450, 68, 7, 450, 334, 3469, 12, 3141, 521, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 478, 14979, 1250, 2350, 14, 647, 446, 9100, 14979, 1072, 1314, 365, 12701, 701, 1022, 1637, 21510, 199, 199, 2817, 1384, 26, 272, 627, 20232, 4580, 320, 85, 595, 665, 983, 5017, 665, 292, 30, 741, 320, 85, 595, 14, 846, 30, 272, 627, 1603, 80, 8256, 424, 368, 1253, 2779, 455, 285, 428, 517, 979, 13, 2437, 4039, 272, 627, 7135, 19262, 577, 11326, 472, 199, 199, 2765, 2032, 1443, 506, 1202, 436, 1854, 7182, 370, 314, 2895, 199, 1618, 314, 1664, 1696, 1684, 844, 12, 30147, 972, 2348, 262, 701, 3659, 14, 199, 624, 199, 199, 318, 1768, 8, 600, 304, 272, 340, 1228, 8, 600, 12, 620, 304, 267, 372, 17352, 7, 435, 1233, 259, 327, 6137, 13, 262, 3423, 661, 94, 7, 30313, 737, 314, 1284, 9, 272, 587, 26, 267, 372, 1543, 83, 450, 83, 2689, 68, 7, 450, 334, 600, 14, 331, 63, 354, 12, 2490, 1233, 14, 331, 63, 1501, 12, 2490, 1233, 14, 331, 63, 30114, 9, 199, 199, 533, 1804, 4437, 23765, 688, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 23173, 304, 267, 291, 14, 576, 275, 23173, 14, 362, 3200, 342, 267, 291, 14, 548, 63, 493, 275, 488, 339, 347, 1072, 8, 277, 12, 734, 63, 493, 304, 267, 291, 14, 548, 63, 493, 275, 734, 63, 493, 267, 870, 4331, 734, 63, 493, 12, 283, 4368, 26, 18742, 83, 7, 267, 291, 423, 1361, 63, 4705, 342, 267, 367, 2397, 315, 291, 14, 576, 26, 288, 291, 423, 2373, 8, 2373, 9, 339, 347, 485, 1361, 63, 4705, 8, 277, 304, 267, 1390, 63, 6336, 275, 378, 267, 367, 2397, 315, 291, 14, 576, 26, 288, 3141, 521, 275, 1109, 8, 2373, 14, 2923, 521, 627, 5198, 9, 288, 1390, 63, 6336, 275, 1390, 8, 988, 63, 6336, 12, 3141, 521, 9, 267, 870, 4331, 291, 14, 548, 63, 493, 12, 283, 4705, 26, 450, 68, 7, 450, 334, 988, 63, 6336, 4258, 339, 347, 485, 2373, 8, 277, 12, 2397, 304, 267, 734, 63, 493, 275, 291, 14, 548, 63, 493, 398, 1233, 275, 2397, 14, 600, 267, 327, 1361, 4331, 734, 63, 493, 12, 283, 2873, 2458, 83, 7, 450, 334, 600, 14, 331, 63, 1501, 4258, 267, 340, 1228, 8, 600, 12, 620, 304, 288, 870, 4331, 734, 63, 493, 12, 283, 329, 29, 94, 7, 267, 587, 26, 288, 870, 4331, 734, 63, 493, 12, 283, 329, 2458, 83, 7, 450, 334, 600, 14, 331, 63, 1501, 4258, 267, 870, 4331, 734, 63, 493, 12, 283, 2324, 2458, 83, 7, 450, 334, 1302, 8, 600, 16945, 398, 8308, 521, 275, 1109, 8, 2373, 14, 6460, 521, 627, 5198, 9, 267, 340, 1228, 8, 600, 12, 620, 304, 288, 870, 4331, 734, 63, 493, 12, 283, 16, 1656, 8308, 521, 267, 587, 26, 288, 870, 4331, 734, 63, 493, 12, 1543, 68, 450, 68, 7, 450, 334, 600, 14, 331, 63, 30114, 12, 8308, 521, 9, 398, 327, 9133, 4882, 787, 31662, 315, 2397, 14, 5352, 267, 340, 2397, 14, 5352, 26, 288, 4882, 275, 2397, 14, 5352, 267, 587, 26, 288, 4882, 275, 942, 398, 340, 1228, 8, 600, 12, 620, 304, 288, 5874, 275, 378, 267, 587, 26, 288, 5874, 275, 1233, 14, 331, 63, 30114, 398, 367, 1007, 2373, 315, 4882, 26, 288, 291, 423, 954, 2373, 8, 3469, 12, 1007, 2373, 9, 267, 870, 4331, 734, 63, 493, 339, 347, 485, 954, 2373, 8, 277, 12, 5874, 12, 1007, 2373, 304, 267, 734, 63, 493, 275, 291, 14, 548, 63, 493, 267, 1233, 275, 1007, 2373, 14, 600, 267, 327, 1361, 4331, 734, 63, 493, 12, 283, 331, 66, 2458, 83, 7, 450, 334, 600, 14, 331, 63, 1501, 4258, 267, 870, 4331, 734, 63, 493, 12, 283, 2177, 78, 2458, 83, 7, 450, 334, 1302, 8, 600, 16945, 267, 340, 1228, 8, 600, 12, 620, 304, 288, 870, 4331, 734, 63, 493, 12, 283, 67, 329, 29, 94, 7, 288, 870, 4331, 734, 63, 493, 12, 283, 5352, 2458, 68, 378, 7, 450, 334, 954, 2373, 14, 1250, 835, 4258, 267, 587, 26, 288, 870, 4331, 734, 63, 493, 12, 283, 67, 329, 2458, 83, 7, 450, 334, 600, 14, 331, 63, 1501, 4258, 288, 870, 4331, 734, 63, 493, 12, 283, 5352, 2458, 68, 450, 68, 7, 450, 334, 355, 1007, 2373, 14, 1250, 835, 12, 1233, 14, 331, 63, 30114, 9, 398, 3141, 521, 275, 1109, 8, 954, 2373, 14, 2923, 521, 627, 5198, 9, 267, 870, 4331, 734, 63, 493, 12, 1543, 68, 450, 68, 7, 450, 334, 3469, 12, 3141, 521, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
vivekananda/fbeats
django/db/backends/sqlite3/introspection.py
84
7764
import re from django.db.backends import BaseDatabaseIntrospection # This light wrapper "fakes" a dictionary interface, because some SQLite data # types include variables in them -- e.g. "varchar(30)" -- and can't be matched # as a simple dictionary lookup. class FlexibleFieldLookupDict(object): # Maps SQL types to Django Field types. Some of the SQL types have multiple # entries here because SQLite allows for anything and doesn't normalize the # field type; it uses whatever was given. base_data_types_reverse = { 'bool': 'BooleanField', 'boolean': 'BooleanField', 'smallint': 'SmallIntegerField', 'smallint unsigned': 'PositiveSmallIntegerField', 'smallinteger': 'SmallIntegerField', 'int': 'IntegerField', 'integer': 'IntegerField', 'bigint': 'BigIntegerField', 'integer unsigned': 'PositiveIntegerField', 'decimal': 'DecimalField', 'real': 'FloatField', 'text': 'TextField', 'char': 'CharField', 'date': 'DateField', 'datetime': 'DateTimeField', 'time': 'TimeField', } def __getitem__(self, key): key = key.lower() try: return self.base_data_types_reverse[key] except KeyError: import re m = re.search(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$', key) if m: return ('CharField', {'max_length': int(m.group(1))}) raise KeyError class DatabaseIntrospection(BaseDatabaseIntrospection): data_types_reverse = FlexibleFieldLookupDict() def get_table_list(self, cursor): "Returns a list of table names in the current database." # Skip the sqlite_sequence system table used for autoincrement key # generation. cursor.execute(""" SELECT name FROM sqlite_master WHERE type='table' AND NOT name='sqlite_sequence' ORDER BY name""") return [row[0] for row in cursor.fetchall()] def get_table_description(self, cursor, table_name): "Returns a description of the table, with the DB-API cursor.description interface." return [(info['name'], info['type'], None, None, None, None, info['null_ok']) for info in self._table_info(cursor, table_name)] def get_relations(self, cursor, table_name): """ Returns a dictionary of {field_index: (field_index_other_table, other_table)} representing all relationships to the given table. Indexes are 0-based. """ # Dictionary of relations to return relations = {} # Schema for this table cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s AND type = %s", [table_name, "table"]) results = cursor.fetchone()[0].strip() results = results[results.index('(')+1:results.rindex(')')] # Walk through and look for references to other tables. SQLite doesn't # really have enforced references, but since it echoes out the SQL used # to create the table we can look for REFERENCES statements used there. for field_index, field_desc in enumerate(results.split(',')): field_desc = field_desc.strip() if field_desc.startswith("UNIQUE"): continue m = re.search('references (.*) \(["|](.*)["|]\)', field_desc, re.I) if not m: continue table, column = [s.strip('"') for s in m.groups()] cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s", [table]) result = cursor.fetchall()[0] other_table_results = result[0].strip() li, ri = other_table_results.index('('), other_table_results.rindex(')') other_table_results = other_table_results[li+1:ri] for other_index, other_desc in enumerate(other_table_results.split(',')): other_desc = other_desc.strip() if other_desc.startswith('UNIQUE'): continue name = other_desc.split(' ', 1)[0].strip('"') if name == column: relations[field_index] = (other_index, table) break return relations def get_key_columns(self, cursor, table_name): """ Returns a list of (column_name, referenced_table_name, referenced_column_name) for all key columns in given table. """ key_columns = [] # Schema for this table cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s AND type = %s", [table_name, "table"]) results = cursor.fetchone()[0].strip() results = results[results.index('(')+1:results.rindex(')')] # Walk through and look for references to other tables. SQLite doesn't # really have enforced references, but since it echoes out the SQL used # to create the table we can look for REFERENCES statements used there. for field_index, field_desc in enumerate(results.split(',')): field_desc = field_desc.strip() if field_desc.startswith("UNIQUE"): continue m = re.search('"(.*)".*references (.*) \(["|](.*)["|]\)', field_desc, re.I) if not m: continue # This will append (column_name, referenced_table_name, referenced_column_name) to key_columns key_columns.append(tuple([s.strip('"') for s in m.groups()])) return key_columns def get_indexes(self, cursor, table_name): """ Returns a dictionary of fieldname -> infodict for the given table, where each infodict is in the format: {'primary_key': boolean representing whether it's the primary key, 'unique': boolean representing whether it's a unique index} """ indexes = {} for info in self._table_info(cursor, table_name): indexes[info['name']] = {'primary_key': info['pk'] != 0, 'unique': False} cursor.execute('PRAGMA index_list(%s)' % self.connection.ops.quote_name(table_name)) # seq, name, unique for index, unique in [(field[1], field[2]) for field in cursor.fetchall()]: if not unique: continue cursor.execute('PRAGMA index_info(%s)' % self.connection.ops.quote_name(index)) info = cursor.fetchall() # Skip indexes across multiple fields if len(info) != 1: continue name = info[0][2] # seqno, cid, name indexes[name]['unique'] = True return indexes def get_primary_key_column(self, cursor, table_name): """ Get the column name of the primary key for the given table. """ # Don't use PRAGMA because that causes issues with some transactions cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s AND type = %s", [table_name, "table"]) results = cursor.fetchone()[0].strip() results = results[results.index('(')+1:results.rindex(')')] for field_desc in results.split(','): field_desc = field_desc.strip() m = re.search('"(.*)".*PRIMARY KEY$', field_desc) if m: return m.groups()[0] return None def _table_info(self, cursor, name): cursor.execute('PRAGMA table_info(%s)' % self.connection.ops.quote_name(name)) # cid, name, type, notnull, dflt_value, pk return [{'name': field[1], 'type': field[2], 'null_ok': not field[3], 'pk': field[5] # undocumented } for field in cursor.fetchall()]
bsd-3-clause
[ 646, 295, 199, 504, 1639, 14, 697, 14, 7765, 492, 29103, 30516, 199, 199, 3, 961, 10540, 4975, 298, 27443, 2, 282, 2600, 3217, 12, 2952, 2005, 19245, 666, 199, 3, 2943, 2387, 2860, 315, 3062, 1553, 325, 14, 71, 14, 298, 25545, 8, 1216, 2924, 1553, 436, 883, 1133, 506, 7838, 199, 3, 465, 282, 3486, 2600, 4237, 14, 199, 533, 481, 8196, 792, 7521, 2141, 8, 785, 304, 272, 327, 23673, 5385, 2943, 370, 5634, 5024, 2943, 14, 6601, 402, 314, 5385, 2943, 1172, 3663, 272, 327, 4811, 2348, 2952, 19245, 6127, 367, 7003, 436, 3181, 1133, 7666, 314, 272, 327, 901, 730, 27, 652, 4440, 15685, 1990, 1627, 14, 272, 1300, 63, 576, 63, 1313, 63, 4471, 275, 469, 267, 283, 2245, 356, 283, 5036, 297, 267, 283, 4871, 356, 283, 5036, 297, 267, 283, 7241, 442, 356, 283, 14640, 297, 267, 283, 7241, 442, 7381, 356, 283, 25197, 297, 267, 283, 7241, 4115, 356, 283, 14640, 297, 267, 283, 442, 356, 283, 3901, 297, 267, 283, 4115, 356, 283, 3901, 297, 267, 283, 24884, 356, 283, 25175, 297, 267, 283, 4115, 7381, 356, 283, 8591, 297, 267, 283, 6355, 356, 283, 15975, 297, 267, 283, 3093, 356, 283, 13019, 297, 267, 283, 505, 356, 283, 6254, 297, 267, 283, 1560, 356, 283, 2183, 297, 267, 283, 602, 356, 283, 14071, 297, 267, 283, 2083, 356, 283, 4626, 297, 267, 283, 521, 356, 283, 27115, 297, 272, 789, 339, 347, 636, 6095, 721, 277, 12, 790, 304, 267, 790, 275, 790, 14, 2325, 342, 267, 862, 26, 288, 372, 291, 14, 1095, 63, 576, 63, 1313, 63, 4471, 59, 498, 61, 267, 871, 4067, 26, 288, 492, 295, 288, 333, 275, 295, 14, 1733, 8, 82, 15542, 83, 10, 5169, 1391, 5547, 1560, 60, 83, 7590, 2961, 83, 22588, 68, 13439, 83, 7590, 2862, 83, 32125, 790, 9, 288, 340, 333, 26, 355, 372, 661, 2183, 297, 791, 988, 63, 1267, 356, 1109, 8, 77, 14, 923, 8, 17, 430, 1552, 288, 746, 4067, 199, 199, 533, 8692, 30516, 8, 1563, 7243, 30516, 304, 272, 666, 63, 1313, 63, 4471, 275, 481, 8196, 792, 7521, 2141, 342, 339, 347, 664, 63, 1224, 63, 513, 8, 277, 12, 3920, 304, 267, 298, 3407, 282, 769, 402, 1817, 1561, 315, 314, 1453, 3050, 2122, 267, 327, 8232, 314, 11723, 63, 4041, 2656, 1817, 1202, 367, 32497, 790, 267, 327, 10152, 14, 267, 3920, 14, 2526, 4852, 288, 10468, 536, 4442, 11723, 63, 4133, 288, 6038, 730, 534, 1224, 7, 2401, 2845, 536, 534, 10659, 63, 4041, 7, 288, 16044, 6515, 536, 6141, 267, 372, 359, 1143, 59, 16, 61, 367, 1962, 315, 3920, 14, 10174, 5106, 339, 347, 664, 63, 1224, 63, 1802, 8, 277, 12, 3920, 12, 1817, 63, 354, 304, 267, 298, 3407, 282, 1369, 402, 314, 1817, 12, 543, 314, 6249, 13, 3735, 3920, 14, 1802, 3217, 2122, 267, 372, 3842, 815, 459, 354, 995, 2256, 459, 466, 995, 488, 12, 488, 12, 488, 12, 488, 12, 326, 2256, 459, 2307, 63, 745, 1105, 367, 2256, 315, 291, 423, 1224, 63, 815, 8, 3937, 12, 1817, 63, 354, 1874, 339, 347, 664, 63, 15741, 8, 277, 12, 3920, 12, 1817, 63, 354, 304, 267, 408, 267, 1803, 282, 2600, 402, 469, 698, 63, 1080, 26, 334, 698, 63, 1080, 63, 1848, 63, 1224, 12, 1163, 63, 1224, 6769, 267, 6144, 1006, 20045, 370, 314, 1627, 1817, 14, 5499, 397, 787, 378, 13, 6788, 14, 267, 408, 398, 327, 11932, 402, 16109, 370, 372, 267, 16109, 275, 1052, 398, 327, 13268, 367, 642, 1817, 267, 3920, 14, 2526, 480, 4859, 3875, 4442, 11723, 63, 4133, 6038, 19049, 63, 354, 275, 450, 83, 2401, 730, 275, 450, 83, 401, 359, 1224, 63, 354, 12, 298, 1224, 3135, 267, 2058, 275, 3920, 14, 11591, 3430, 16, 1055, 1913, 342, 267, 2058, 275, 2058, 59, 2604, 14, 1080, 14097, 358, 11, 17, 26, 2604, 14, 26187, 15938, 5440, 398, 327, 644, 4878, 4012, 436, 3648, 367, 6941, 370, 1163, 6716, 14, 19245, 3181, 1133, 267, 327, 7710, 1172, 30163, 6941, 12, 1325, 3967, 652, 11343, 397, 734, 314, 5385, 1202, 267, 327, 370, 1218, 314, 1817, 781, 883, 3648, 367, 26901, 22243, 9834, 1202, 2337, 14, 267, 367, 901, 63, 1080, 12, 901, 63, 3257, 315, 3874, 8, 2604, 14, 1294, 5102, 8109, 288, 901, 63, 3257, 275, 901, 63, 3257, 14, 1913, 342, 288, 340, 901, 63, 3257, 14, 2460, 480, 28060, 2349, 355, 1980, 953, 333, 275, 295, 14, 1733, 360, 12635, 334, 12432, 971, 5234, 92, 8738, 12432, 905, 92, 7272, 3196, 901, 63, 3257, 12, 295, 14, 41, 9, 288, 340, 440, 333, 26, 355, 1980, 953, 1817, 12, 2763, 275, 359, 83, 14, 1913, 25441, 367, 308, 315, 333, 14, 2634, 5106, 953, 3920, 14, 2526, 480, 4859, 3875, 4442, 11723, 63, 4133, 6038, 19049, 63, 354, 275, 450, 83, 401, 359, 1224, 566, 288, 754, 275, 3920, 14, 10174, 3430, 16, 61, 288, 1163, 63, 1224, 63, 2604, 275, 754, 59, 16, 1055, 1913, 342, 288, 1212, 12, 8012, 275, 1163, 63, 1224, 63, 2604, 14, 1080, 14097, 659, 1163, 63, 1224, 63, 2604, 14, 26187, 15938, 358, 288, 1163, 63, 1224, 63, 2604, 275, 1163, 63, 1224, 63, 2604, 59, 317, 11, 17, 26, 322, 61, 22919, 367, 1163, 63, 1080, 12, 1163, 63, 3257, 315, 3874, 8, 1848, 63, 1224, 63, 2604, 14, 1294, 5102, 8109, 355, 1163, 63, 3257, 275, 1163, 63, 3257, 14, 1913, 342, 355, 340, 1163, 63, 3257, 14, 2460, 360, 28060, 735, 490, 1980, 2234, 536, 275, 1163, 63, 3257, 14, 1294, 360, 1656, 413, 2788, 16, 1055, 1913, 25441, 355, 340, 536, 508, 2763, 26, 490, 16109, 59, 698, 63, 1080, 61, 275, 334, 1848, 63, 1080, 12, 1817, 9, 490, 2059, 398, 372, 16109, 339, 347, 664, 63, 498, 63, 3406, 8, 277, 12, 3920, 12, 1817, 63, 354, 304, 267, 408, 267, 1803, 282, 769, 402, 334, 2301, 63, 354, 12, 11812, 63, 1224, 63, 354, 12, 11812, 63, 2301, 63, 354, 9, 367, 1006, 267, 790, 4362, 315, 1627, 1817, 14, 267, 408, 267, 790, 63, 3406 ]
[ 295, 199, 504, 1639, 14, 697, 14, 7765, 492, 29103, 30516, 199, 199, 3, 961, 10540, 4975, 298, 27443, 2, 282, 2600, 3217, 12, 2952, 2005, 19245, 666, 199, 3, 2943, 2387, 2860, 315, 3062, 1553, 325, 14, 71, 14, 298, 25545, 8, 1216, 2924, 1553, 436, 883, 1133, 506, 7838, 199, 3, 465, 282, 3486, 2600, 4237, 14, 199, 533, 481, 8196, 792, 7521, 2141, 8, 785, 304, 272, 327, 23673, 5385, 2943, 370, 5634, 5024, 2943, 14, 6601, 402, 314, 5385, 2943, 1172, 3663, 272, 327, 4811, 2348, 2952, 19245, 6127, 367, 7003, 436, 3181, 1133, 7666, 314, 272, 327, 901, 730, 27, 652, 4440, 15685, 1990, 1627, 14, 272, 1300, 63, 576, 63, 1313, 63, 4471, 275, 469, 267, 283, 2245, 356, 283, 5036, 297, 267, 283, 4871, 356, 283, 5036, 297, 267, 283, 7241, 442, 356, 283, 14640, 297, 267, 283, 7241, 442, 7381, 356, 283, 25197, 297, 267, 283, 7241, 4115, 356, 283, 14640, 297, 267, 283, 442, 356, 283, 3901, 297, 267, 283, 4115, 356, 283, 3901, 297, 267, 283, 24884, 356, 283, 25175, 297, 267, 283, 4115, 7381, 356, 283, 8591, 297, 267, 283, 6355, 356, 283, 15975, 297, 267, 283, 3093, 356, 283, 13019, 297, 267, 283, 505, 356, 283, 6254, 297, 267, 283, 1560, 356, 283, 2183, 297, 267, 283, 602, 356, 283, 14071, 297, 267, 283, 2083, 356, 283, 4626, 297, 267, 283, 521, 356, 283, 27115, 297, 272, 789, 339, 347, 636, 6095, 721, 277, 12, 790, 304, 267, 790, 275, 790, 14, 2325, 342, 267, 862, 26, 288, 372, 291, 14, 1095, 63, 576, 63, 1313, 63, 4471, 59, 498, 61, 267, 871, 4067, 26, 288, 492, 295, 288, 333, 275, 295, 14, 1733, 8, 82, 15542, 83, 10, 5169, 1391, 5547, 1560, 60, 83, 7590, 2961, 83, 22588, 68, 13439, 83, 7590, 2862, 83, 32125, 790, 9, 288, 340, 333, 26, 355, 372, 661, 2183, 297, 791, 988, 63, 1267, 356, 1109, 8, 77, 14, 923, 8, 17, 430, 1552, 288, 746, 4067, 199, 199, 533, 8692, 30516, 8, 1563, 7243, 30516, 304, 272, 666, 63, 1313, 63, 4471, 275, 481, 8196, 792, 7521, 2141, 342, 339, 347, 664, 63, 1224, 63, 513, 8, 277, 12, 3920, 304, 267, 298, 3407, 282, 769, 402, 1817, 1561, 315, 314, 1453, 3050, 2122, 267, 327, 8232, 314, 11723, 63, 4041, 2656, 1817, 1202, 367, 32497, 790, 267, 327, 10152, 14, 267, 3920, 14, 2526, 4852, 288, 10468, 536, 4442, 11723, 63, 4133, 288, 6038, 730, 534, 1224, 7, 2401, 2845, 536, 534, 10659, 63, 4041, 7, 288, 16044, 6515, 536, 6141, 267, 372, 359, 1143, 59, 16, 61, 367, 1962, 315, 3920, 14, 10174, 5106, 339, 347, 664, 63, 1224, 63, 1802, 8, 277, 12, 3920, 12, 1817, 63, 354, 304, 267, 298, 3407, 282, 1369, 402, 314, 1817, 12, 543, 314, 6249, 13, 3735, 3920, 14, 1802, 3217, 2122, 267, 372, 3842, 815, 459, 354, 995, 2256, 459, 466, 995, 488, 12, 488, 12, 488, 12, 488, 12, 326, 2256, 459, 2307, 63, 745, 1105, 367, 2256, 315, 291, 423, 1224, 63, 815, 8, 3937, 12, 1817, 63, 354, 1874, 339, 347, 664, 63, 15741, 8, 277, 12, 3920, 12, 1817, 63, 354, 304, 267, 408, 267, 1803, 282, 2600, 402, 469, 698, 63, 1080, 26, 334, 698, 63, 1080, 63, 1848, 63, 1224, 12, 1163, 63, 1224, 6769, 267, 6144, 1006, 20045, 370, 314, 1627, 1817, 14, 5499, 397, 787, 378, 13, 6788, 14, 267, 408, 398, 327, 11932, 402, 16109, 370, 372, 267, 16109, 275, 1052, 398, 327, 13268, 367, 642, 1817, 267, 3920, 14, 2526, 480, 4859, 3875, 4442, 11723, 63, 4133, 6038, 19049, 63, 354, 275, 450, 83, 2401, 730, 275, 450, 83, 401, 359, 1224, 63, 354, 12, 298, 1224, 3135, 267, 2058, 275, 3920, 14, 11591, 3430, 16, 1055, 1913, 342, 267, 2058, 275, 2058, 59, 2604, 14, 1080, 14097, 358, 11, 17, 26, 2604, 14, 26187, 15938, 5440, 398, 327, 644, 4878, 4012, 436, 3648, 367, 6941, 370, 1163, 6716, 14, 19245, 3181, 1133, 267, 327, 7710, 1172, 30163, 6941, 12, 1325, 3967, 652, 11343, 397, 734, 314, 5385, 1202, 267, 327, 370, 1218, 314, 1817, 781, 883, 3648, 367, 26901, 22243, 9834, 1202, 2337, 14, 267, 367, 901, 63, 1080, 12, 901, 63, 3257, 315, 3874, 8, 2604, 14, 1294, 5102, 8109, 288, 901, 63, 3257, 275, 901, 63, 3257, 14, 1913, 342, 288, 340, 901, 63, 3257, 14, 2460, 480, 28060, 2349, 355, 1980, 953, 333, 275, 295, 14, 1733, 360, 12635, 334, 12432, 971, 5234, 92, 8738, 12432, 905, 92, 7272, 3196, 901, 63, 3257, 12, 295, 14, 41, 9, 288, 340, 440, 333, 26, 355, 1980, 953, 1817, 12, 2763, 275, 359, 83, 14, 1913, 25441, 367, 308, 315, 333, 14, 2634, 5106, 953, 3920, 14, 2526, 480, 4859, 3875, 4442, 11723, 63, 4133, 6038, 19049, 63, 354, 275, 450, 83, 401, 359, 1224, 566, 288, 754, 275, 3920, 14, 10174, 3430, 16, 61, 288, 1163, 63, 1224, 63, 2604, 275, 754, 59, 16, 1055, 1913, 342, 288, 1212, 12, 8012, 275, 1163, 63, 1224, 63, 2604, 14, 1080, 14097, 659, 1163, 63, 1224, 63, 2604, 14, 26187, 15938, 358, 288, 1163, 63, 1224, 63, 2604, 275, 1163, 63, 1224, 63, 2604, 59, 317, 11, 17, 26, 322, 61, 22919, 367, 1163, 63, 1080, 12, 1163, 63, 3257, 315, 3874, 8, 1848, 63, 1224, 63, 2604, 14, 1294, 5102, 8109, 355, 1163, 63, 3257, 275, 1163, 63, 3257, 14, 1913, 342, 355, 340, 1163, 63, 3257, 14, 2460, 360, 28060, 735, 490, 1980, 2234, 536, 275, 1163, 63, 3257, 14, 1294, 360, 1656, 413, 2788, 16, 1055, 1913, 25441, 355, 340, 536, 508, 2763, 26, 490, 16109, 59, 698, 63, 1080, 61, 275, 334, 1848, 63, 1080, 12, 1817, 9, 490, 2059, 398, 372, 16109, 339, 347, 664, 63, 498, 63, 3406, 8, 277, 12, 3920, 12, 1817, 63, 354, 304, 267, 408, 267, 1803, 282, 769, 402, 334, 2301, 63, 354, 12, 11812, 63, 1224, 63, 354, 12, 11812, 63, 2301, 63, 354, 9, 367, 1006, 267, 790, 4362, 315, 1627, 1817, 14, 267, 408, 267, 790, 63, 3406, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
simontakite/sysadmin
pythonscripts/learningPython/setsubclass.py
1
1331
from __future__ import print_function # 2.X compatibility class Set(list): def __init__(self, value = []): # Constructor list.__init__([]) # Customizes list self.concat(value) # Copies mutable defaults def intersect(self, other): # other is any sequence res = [] # self is the subject for x in self: if x in other: # Pick common items res.append(x) return Set(res) # Return a new Set def union(self, other): # other is any sequence res = Set(self) # Copy me and my list res.concat(other) return res def concat(self, value): # value: list, Set, etc. for x in value: # Removes duplicates if not x in self: self.append(x) def __and__(self, other): return self.intersect(other) def __or__(self, other): return self.union(other) def __repr__(self): return 'Set:' + list.__repr__(self) if __name__ == '__main__': x = Set([1,3,5,7]) y = Set([2,1,4,5,6]) print(x, y, len(x)) print(x.intersect(y), y.union(x)) print(x & y, x | y) x.reverse(); print(x)
gpl-2.0
[ 504, 636, 2443, 363, 492, 870, 63, 1593, 259, 327, 499, 14, 56, 7163, 2999, 199, 533, 2494, 8, 513, 304, 1128, 347, 636, 826, 721, 277, 12, 574, 275, 12319, 420, 327, 20297, 1039, 769, 855, 826, 721, 59, 566, 4483, 327, 8388, 6491, 769, 1039, 291, 14, 9419, 8, 585, 9, 5185, 327, 29622, 1500, 17194, 4243, 2958, 347, 26066, 8, 277, 12, 1163, 304, 3515, 327, 1163, 365, 1263, 3414, 1039, 522, 275, 942, 12793, 327, 291, 365, 314, 5420, 1039, 367, 671, 315, 291, 26, 1675, 340, 671, 315, 1163, 26, 5185, 327, 16568, 2863, 2974, 2628, 522, 14, 740, 8, 88, 9, 1039, 372, 2494, 8, 470, 9, 8295, 327, 1432, 282, 892, 2494, 2958, 347, 13629, 8, 277, 12, 1163, 304, 4519, 327, 1163, 365, 1263, 3414, 1039, 522, 275, 2494, 8, 277, 9, 8295, 327, 11247, 562, 436, 3002, 769, 1039, 522, 14, 9419, 8, 1848, 9, 1039, 372, 522, 2958, 347, 17159, 8, 277, 12, 574, 304, 3777, 327, 574, 26, 769, 12, 2494, 12, 5423, 14, 1039, 367, 671, 315, 574, 26, 8295, 327, 23169, 15755, 1675, 340, 440, 671, 315, 291, 26, 2628, 291, 14, 740, 8, 88, 9, 2958, 347, 636, 460, 721, 277, 12, 1163, 304, 372, 291, 14, 23149, 8, 1848, 9, 1128, 347, 636, 269, 721, 277, 12, 1163, 304, 221, 372, 291, 14, 8888, 8, 1848, 9, 1128, 347, 636, 2722, 721, 277, 304, 755, 372, 283, 1084, 4881, 435, 769, 855, 2722, 721, 277, 9, 2999, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 1128, 671, 275, 2494, 779, 17, 12, 19, 12, 21, 12, 23, 566, 1128, 612, 275, 2494, 779, 18, 12, 17, 12, 20, 12, 21, 12, 22, 566, 1128, 870, 8, 88, 12, 612, 12, 822, 8, 88, 430, 1128, 870, 8, 88, 14, 23149, 8, 89, 395, 612, 14, 8888, 8, 88, 430, 1128, 870, 8, 88, 1253, 612, 12, 671, 1204, 612, 9, 1128, 671, 14, 4471, 7303, 870, 8, 88, 9, 1223, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 636, 2443, 363, 492, 870, 63, 1593, 259, 327, 499, 14, 56, 7163, 2999, 199, 533, 2494, 8, 513, 304, 1128, 347, 636, 826, 721, 277, 12, 574, 275, 12319, 420, 327, 20297, 1039, 769, 855, 826, 721, 59, 566, 4483, 327, 8388, 6491, 769, 1039, 291, 14, 9419, 8, 585, 9, 5185, 327, 29622, 1500, 17194, 4243, 2958, 347, 26066, 8, 277, 12, 1163, 304, 3515, 327, 1163, 365, 1263, 3414, 1039, 522, 275, 942, 12793, 327, 291, 365, 314, 5420, 1039, 367, 671, 315, 291, 26, 1675, 340, 671, 315, 1163, 26, 5185, 327, 16568, 2863, 2974, 2628, 522, 14, 740, 8, 88, 9, 1039, 372, 2494, 8, 470, 9, 8295, 327, 1432, 282, 892, 2494, 2958, 347, 13629, 8, 277, 12, 1163, 304, 4519, 327, 1163, 365, 1263, 3414, 1039, 522, 275, 2494, 8, 277, 9, 8295, 327, 11247, 562, 436, 3002, 769, 1039, 522, 14, 9419, 8, 1848, 9, 1039, 372, 522, 2958, 347, 17159, 8, 277, 12, 574, 304, 3777, 327, 574, 26, 769, 12, 2494, 12, 5423, 14, 1039, 367, 671, 315, 574, 26, 8295, 327, 23169, 15755, 1675, 340, 440, 671, 315, 291, 26, 2628, 291, 14, 740, 8, 88, 9, 2958, 347, 636, 460, 721, 277, 12, 1163, 304, 372, 291, 14, 23149, 8, 1848, 9, 1128, 347, 636, 269, 721, 277, 12, 1163, 304, 221, 372, 291, 14, 8888, 8, 1848, 9, 1128, 347, 636, 2722, 721, 277, 304, 755, 372, 283, 1084, 4881, 435, 769, 855, 2722, 721, 277, 9, 2999, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 1128, 671, 275, 2494, 779, 17, 12, 19, 12, 21, 12, 23, 566, 1128, 612, 275, 2494, 779, 18, 12, 17, 12, 20, 12, 21, 12, 22, 566, 1128, 870, 8, 88, 12, 612, 12, 822, 8, 88, 430, 1128, 870, 8, 88, 14, 23149, 8, 89, 395, 612, 14, 8888, 8, 88, 430, 1128, 870, 8, 88, 1253, 612, 12, 671, 1204, 612, 9, 1128, 671, 14, 4471, 7303, 870, 8, 88, 9, 1223, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
richrd/nxt-python
nxt/locator.py
17
8272
# nxt.locator module -- Locate LEGO Minstorms NXT bricks via USB or Bluetooth # Copyright (C) 2006, 2007 Douglas P Lau # Copyright (C) 2009 Marcus Wanner # Copyright (C) 2013 Dave Churchill, Marcus Wanner # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. import traceback, ConfigParser, os class BrickNotFoundError(Exception): pass class NoBackendError(Exception): pass class Method(): """Used to indicate which comm backends should be tried by find_bricks/ find_one_brick. Any or all can be selected.""" def __init__(self, usb=True, bluetooth=True, fantomusb=False, fantombt=False, device=False): #new method options MUST default to False! self.usb = usb self.bluetooth = bluetooth self.fantom = fantomusb or fantombt self.fantomusb = fantomusb self.fantombt = fantombt self.device = device def find_bricks(host=None, name=None, silent=False, method=Method()): """Used by find_one_brick to look for bricks ***ADVANCED USERS ONLY***""" methods_available = 0 if method.usb: try: import usbsock methods_available += 1 socks = usbsock.find_bricks(host, name) for s in socks: yield s except ImportError: import sys if not silent: print >>sys.stderr, "USB module unavailable, not searching there" if method.bluetooth: try: import bluesock methods_available += 1 try: socks = bluesock.find_bricks(host, name) for s in socks: yield s except (bluesock.bluetooth.BluetoothError, IOError): #for cases such as no adapter, bluetooth throws IOError, not BluetoothError pass except ImportError: import sys if not silent: print >>sys.stderr, "Bluetooth module unavailable, not searching there" if method.device: try: import devsock methods_available += 1 socks = devsock.find_bricks(name=name) for s in socks: yield s except IOError: pass if method.fantom: try: import fantomsock methods_available += 1 if method.fantomusb: usbsocks = fantomsock.find_bricks(host, name, False) for s in usbsocks: yield s if method.fantombt: btsocks = fantomsock.find_bricks(host, name, True) for s in btsocks: yield s except ImportError: import sys if not silent: print >>sys.stderr, "Fantom module unavailable, not searching there" if methods_available == 0: raise NoBackendError("No selected backends are available! Did you install the comm modules?") def find_one_brick(host=None, name=None, silent=False, strict=None, debug=False, method=None, confpath=None): """Use to find one brick. The host and name args limit the search to a given MAC or brick name. Set silent to True to stop nxt-python from printing anything during the search. This function by default automatically checks to see if the brick found has the correct host/name (if either are provided) and will not return a brick which doesn't match. This can be disabled (so the function returns any brick which can be connected to and provides a valid reply to get_device_info()) by passing strict=False. This will, however, still tell the comm backends to only look for devices which match the args provided. The confpath arg specifies the location of the configuration file which brick location information will be read from if no brick location directives (host, name, strict, or method) are provided.""" if debug and silent: silent=False print "silent and debug can't both be set; giving debug priority" conf = read_config(confpath, debug) if not (host or name or strict or method): host = conf.get('Brick', 'host') name = conf.get('Brick', 'name') strict = bool(int(conf.get('Brick', 'strict'))) method = eval('Method(%s)' % conf.get('Brick', 'method')) if not strict: strict = True if not method: method = Method() if debug: print "Host: %s Name: %s Strict: %s" % (host, name, str(strict)) print "USB: %s BT: %s Fantom: %s FUSB: %s FBT: %s" % (method.usb, method.bluetooth, method.fantom, method.fantombt, method.fantomusb) for s in find_bricks(host, name, silent, method): try: if host and 'host' in dir(s) and s.host != host: if debug: print "Warning: the brick found does not match the host provided (s.host)." if strict: continue b = s.connect() info = b.get_device_info() if host and info[1] != host: if debug: print "Warning: the brick found does not match the host provided (get_device_info)." if strict: s.close() continue if name and info[0].strip('\0') != name: if debug: print "Warning; the brick found does not match the name provided." if strict: s.close() continue return b except: if debug: traceback.print_exc() print "Failed to connect to possible brick" raise BrickNotFoundError def server_brick(host, port = 2727): import ipsock sock = ipsock.IpSock(host, port) return sock.connect() def device_brick(filename): import devsock sock = devsock.find_bricks(filename=filename) return sock.connect() def read_config(confpath=None, debug=False): conf = ConfigParser.RawConfigParser({'host': None, 'name': None, 'strict': True, 'method': ''}) if not confpath: confpath = os.path.expanduser('~/.nxt-python') if conf.read([confpath]) == [] and debug: print "Warning: Config file (should be at %s) was not read. Use nxt.locator.make_config() to create a config file." % confpath if conf.has_section('Brick') == False: conf.add_section('Brick') return conf def make_config(confpath=None): conf = ConfigParser.RawConfigParser() if not confpath: confpath = os.path.expanduser('~/.nxt-python') print "Welcome to the nxt-python config file generator!" print "This function creates an example file which find_one_brick uses to find a brick." try: if os.path.exists(confpath): raw_input("File already exists at %s. Press Enter to overwrite or Ctrl+C to abort." % confpath) except KeyboardInterrupt: print "Not writing file." return conf.add_section('Brick') conf.set('Brick', 'name', 'MyNXT') conf.set('Brick', 'host', '54:32:59:92:F9:39') conf.set('Brick', 'strict', 0) conf.set('Brick', 'method', 'usb=True, bluetooth=False, fantomusb=True') conf.write(open(confpath, 'w')) print "The file has been written at %s" % confpath print "The file contains less-than-sane default values to get you started." print "You must now edit the file with a text editor and change the values to match what you would pass to find_one_brick" print "The fields for name, host, and strict correspond to the similar args accepted by find_one_brick" print "The method field contains the string which would be passed to Method()" print "Any field whose corresponding option does not need to be passed to find_one_brick should be commented out (using a # at the start of the line) or simply removed." print "If you have questions, check the wiki and then ask on the mailing list."
gpl-3.0
[ 3, 302, 400, 14, 6354, 859, 1553, 6263, 323, 491, 4680, 47, 603, 3615, 269, 706, 653, 18926, 20611, 5618, 4799, 28655, 503, 22447, 16453, 199, 3, 1898, 334, 35, 9, 8315, 12, 10219, 221, 577, 810, 3528, 305, 510, 491, 3844, 199, 3, 1898, 334, 35, 9, 8937, 221, 603, 9912, 527, 644, 5161, 199, 3, 1898, 334, 35, 9, 6171, 221, 577, 811, 2799, 300, 335, 778, 12, 603, 9912, 527, 644, 5161, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 199, 646, 5190, 12, 14196, 12, 747, 199, 199, 533, 699, 27091, 10870, 8, 1726, 304, 272, 986, 199, 199, 533, 3091, 8447, 547, 8, 1726, 304, 272, 986, 199, 199, 533, 9075, 837, 272, 408, 9167, 370, 6623, 1314, 1923, 14745, 1077, 506, 16416, 701, 2342, 63, 30855, 15, 199, 1623, 63, 368, 63, 29541, 14, 6184, 503, 1006, 883, 506, 4895, 1041, 272, 347, 636, 826, 721, 277, 12, 27923, 29, 549, 12, 10030, 16453, 29, 549, 12, 13758, 3151, 17411, 29, 797, 12, 13758, 475, 887, 84, 29, 797, 12, 2243, 29, 797, 304, 267, 327, 1222, 1083, 1511, 18095, 849, 370, 756, 1, 267, 291, 14, 17411, 275, 27923, 267, 291, 14, 27172, 275, 10030, 16453, 267, 291, 14, 12269, 3151, 275, 13758, 3151, 17411, 503, 13758, 475, 887, 84, 267, 291, 14, 12269, 3151, 17411, 275, 13758, 3151, 17411, 267, 291, 14, 12269, 475, 887, 84, 275, 13758, 475, 887, 84, 267, 291, 14, 1782, 275, 2243, 199, 199, 318, 2342, 63, 30855, 8, 1102, 29, 403, 12, 536, 29, 403, 12, 10866, 29, 797, 12, 1083, 29, 3767, 5109, 272, 408, 9167, 701, 2342, 63, 368, 63, 29541, 370, 3648, 367, 20611, 5618, 19688, 1554, 54, 879, 25927, 13044, 51, 5258, 6084, 9153, 624, 272, 3102, 63, 4561, 275, 378, 339, 340, 1083, 14, 17411, 26, 267, 862, 26, 288, 492, 2739, 1533, 766, 288, 3102, 63, 4561, 847, 413, 288, 6771, 83, 275, 2739, 1533, 766, 14, 1623, 63, 30855, 8, 1102, 12, 536, 9, 288, 367, 308, 315, 6771, 83, 26, 355, 1995, 308, 267, 871, 3545, 26, 288, 492, 984, 288, 340, 440, 10866, 26, 870, 4331, 1274, 14, 3083, 12, 298, 19919, 859, 18735, 12, 440, 18112, 2337, 2, 2286, 340, 1083, 14, 27172, 26, 267, 862, 26, 288, 492, 10030, 5096, 288, 3102, 63, 4561, 847, 413, 288, 862, 26, 355, 6771, 83, 275, 10030, 5096, 14, 1623, 63, 30855, 8, 1102, 12, 536, 9, 355, 367, 308, 315, 6771, 83, 26, 490, 1995, 308, 288, 871, 334, 6304, 5096, 14, 27172, 14, 15617, 16453, 547, 12, 5925, 304, 327, 509, 5560, 4066, 465, 949, 12146, 12, 10030, 16453, 24266, 5925, 12, 440, 22447, 16453, 547, 355, 986, 267, 871, 3545, 26, 288, 492, 984, 288, 340, 440, 10866, 26, 870, 4331, 1274, 14, 3083, 12, 298, 15617, 16453, 859, 18735, 12, 440, 18112, 2337, 2, 2286, 340, 1083, 14, 1782, 26, 267, 862, 26, 288, 492, 477, 3122, 766, 288, 3102, 63, 4561, 847, 413, 288, 6771, 83, 275, 477, 3122, 766, 14, 1623, 63, 30855, 8, 354, 29, 354, 9, 288, 367, 308, 315, 6771, 83, 26, 355, 1995, 308, 267, 871, 5925, 26, 288, 986, 339, 340, 1083, 14, 12269, 3151, 26, 267, 862, 26, 288, 492, 13758, 12606, 766, 288, 3102, 63, 4561, 847, 413, 288, 340, 1083, 14, 12269, 3151, 17411, 26, 355, 2739, 1533, 27416, 275, 13758, 12606, 766, 14, 1623, 63, 30855, 8, 1102, 12, 536, 12, 756, 9, 355, 367, 308, 315, 2739, 1533, 27416, 26, 490, 1995, 308, 288, 340, 1083, 14, 12269, 475, 887, 84, 26, 355, 330, 1086, 27416, 275, 13758, 12606, 766, 14, 1623, 63, 30855, 8, 1102, 12, 536, 12, 715, 9, 355, 367, 308, 315, 330, 1086, 27416, 26, 490, 1995, 308, 267, 871, 3545, 26, 288, 492, 984, 288, 340, 440, 10866, 26, 870, 4331, 1274, 14, 3083, 12, 298, 29745, 3151, 859, 18735, 12, 440, 18112, 2337, 2, 2286, 340, 3102, 63, 4561, 508, 378, 26, 267, 746, 3091, 8447, 547, 480, 1944, 4895, 14745, 787, 2808, 1, 29503, 1265, 3907, 314, 1923, 4621, 18582, 421, 199, 318, 2342, 63, 368, 63, 29541, 8, 1102, 29, 403, 12, 536, 29, 403, 12, 10866, 29, 797, 12, 7478, 29, 403, 12, 3105, 29, 797, 12, 1083, 29, 403, 12, 3743, 515, 29, 403, 304, 272, 408, 6119, 370, 2342, 1373, 20611, 346, 14, 710, 1591, 436, 536, 1249, 2304, 314, 2754, 370, 221, 199, 65, 1627, 13347, 503, 20611, 346, 536, 14, 2494, 10866, 370, 715, 370, 3631, 302, 400, 13, 1548, 687, 221, 199, 26514, 7003, 5309, 314, 2754, 14, 961, 805, 701, 849, 221, 199, 2495, 17174, 5920, 370, 1937, 340, 314, 20611, 346, 1911, 965, 314, 3211, 1591, 15, 354, 221, 199, 8, 692, 1902, 787, 2741, 9, 436, 911, 440, 372, 282, 20611, 346, 1314, 3181, 1133, 221, 199, 1431, 14, 961, 883, 506, 6980, 334, 1152, 314, 805, 2529, 1263, 20611, 346, 1314, 883, 221, 199, 1235, 8539, 370, 436, 6571, 282, 1686, 9351, 370, 664, 63, 1782, 63, 815, 1012, 701, 221, 199, 29436, 7478, 29, 797, 14, 961, 911, 12, 13432, 12, 5139, 11480, 314, 1923, 14745, 221, 199, 475, 1454, 3648, 367, 7256, 1314, 1336, 314, 1249, 2741, 14, 710, 3743, 515, 1680, 221, 199, 3017, 5604, 314, 2909, 402, 314, 2897, 570, 1314, 20611, 346, 2909, 221, 199, 11697, 911, 506, 1586, 687, 340, 949, 20611, 346, 2909, 13502, 334, 1102, 12, 221, 199, 354, 12, 7478, 12, 503, 1083, 9 ]
[ 302, 400, 14, 6354, 859, 1553, 6263, 323, 491, 4680, 47, 603, 3615, 269, 706, 653, 18926, 20611, 5618, 4799, 28655, 503, 22447, 16453, 199, 3, 1898, 334, 35, 9, 8315, 12, 10219, 221, 577, 810, 3528, 305, 510, 491, 3844, 199, 3, 1898, 334, 35, 9, 8937, 221, 603, 9912, 527, 644, 5161, 199, 3, 1898, 334, 35, 9, 6171, 221, 577, 811, 2799, 300, 335, 778, 12, 603, 9912, 527, 644, 5161, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 199, 646, 5190, 12, 14196, 12, 747, 199, 199, 533, 699, 27091, 10870, 8, 1726, 304, 272, 986, 199, 199, 533, 3091, 8447, 547, 8, 1726, 304, 272, 986, 199, 199, 533, 9075, 837, 272, 408, 9167, 370, 6623, 1314, 1923, 14745, 1077, 506, 16416, 701, 2342, 63, 30855, 15, 199, 1623, 63, 368, 63, 29541, 14, 6184, 503, 1006, 883, 506, 4895, 1041, 272, 347, 636, 826, 721, 277, 12, 27923, 29, 549, 12, 10030, 16453, 29, 549, 12, 13758, 3151, 17411, 29, 797, 12, 13758, 475, 887, 84, 29, 797, 12, 2243, 29, 797, 304, 267, 327, 1222, 1083, 1511, 18095, 849, 370, 756, 1, 267, 291, 14, 17411, 275, 27923, 267, 291, 14, 27172, 275, 10030, 16453, 267, 291, 14, 12269, 3151, 275, 13758, 3151, 17411, 503, 13758, 475, 887, 84, 267, 291, 14, 12269, 3151, 17411, 275, 13758, 3151, 17411, 267, 291, 14, 12269, 475, 887, 84, 275, 13758, 475, 887, 84, 267, 291, 14, 1782, 275, 2243, 199, 199, 318, 2342, 63, 30855, 8, 1102, 29, 403, 12, 536, 29, 403, 12, 10866, 29, 797, 12, 1083, 29, 3767, 5109, 272, 408, 9167, 701, 2342, 63, 368, 63, 29541, 370, 3648, 367, 20611, 5618, 19688, 1554, 54, 879, 25927, 13044, 51, 5258, 6084, 9153, 624, 272, 3102, 63, 4561, 275, 378, 339, 340, 1083, 14, 17411, 26, 267, 862, 26, 288, 492, 2739, 1533, 766, 288, 3102, 63, 4561, 847, 413, 288, 6771, 83, 275, 2739, 1533, 766, 14, 1623, 63, 30855, 8, 1102, 12, 536, 9, 288, 367, 308, 315, 6771, 83, 26, 355, 1995, 308, 267, 871, 3545, 26, 288, 492, 984, 288, 340, 440, 10866, 26, 870, 4331, 1274, 14, 3083, 12, 298, 19919, 859, 18735, 12, 440, 18112, 2337, 2, 2286, 340, 1083, 14, 27172, 26, 267, 862, 26, 288, 492, 10030, 5096, 288, 3102, 63, 4561, 847, 413, 288, 862, 26, 355, 6771, 83, 275, 10030, 5096, 14, 1623, 63, 30855, 8, 1102, 12, 536, 9, 355, 367, 308, 315, 6771, 83, 26, 490, 1995, 308, 288, 871, 334, 6304, 5096, 14, 27172, 14, 15617, 16453, 547, 12, 5925, 304, 327, 509, 5560, 4066, 465, 949, 12146, 12, 10030, 16453, 24266, 5925, 12, 440, 22447, 16453, 547, 355, 986, 267, 871, 3545, 26, 288, 492, 984, 288, 340, 440, 10866, 26, 870, 4331, 1274, 14, 3083, 12, 298, 15617, 16453, 859, 18735, 12, 440, 18112, 2337, 2, 2286, 340, 1083, 14, 1782, 26, 267, 862, 26, 288, 492, 477, 3122, 766, 288, 3102, 63, 4561, 847, 413, 288, 6771, 83, 275, 477, 3122, 766, 14, 1623, 63, 30855, 8, 354, 29, 354, 9, 288, 367, 308, 315, 6771, 83, 26, 355, 1995, 308, 267, 871, 5925, 26, 288, 986, 339, 340, 1083, 14, 12269, 3151, 26, 267, 862, 26, 288, 492, 13758, 12606, 766, 288, 3102, 63, 4561, 847, 413, 288, 340, 1083, 14, 12269, 3151, 17411, 26, 355, 2739, 1533, 27416, 275, 13758, 12606, 766, 14, 1623, 63, 30855, 8, 1102, 12, 536, 12, 756, 9, 355, 367, 308, 315, 2739, 1533, 27416, 26, 490, 1995, 308, 288, 340, 1083, 14, 12269, 475, 887, 84, 26, 355, 330, 1086, 27416, 275, 13758, 12606, 766, 14, 1623, 63, 30855, 8, 1102, 12, 536, 12, 715, 9, 355, 367, 308, 315, 330, 1086, 27416, 26, 490, 1995, 308, 267, 871, 3545, 26, 288, 492, 984, 288, 340, 440, 10866, 26, 870, 4331, 1274, 14, 3083, 12, 298, 29745, 3151, 859, 18735, 12, 440, 18112, 2337, 2, 2286, 340, 3102, 63, 4561, 508, 378, 26, 267, 746, 3091, 8447, 547, 480, 1944, 4895, 14745, 787, 2808, 1, 29503, 1265, 3907, 314, 1923, 4621, 18582, 421, 199, 318, 2342, 63, 368, 63, 29541, 8, 1102, 29, 403, 12, 536, 29, 403, 12, 10866, 29, 797, 12, 7478, 29, 403, 12, 3105, 29, 797, 12, 1083, 29, 403, 12, 3743, 515, 29, 403, 304, 272, 408, 6119, 370, 2342, 1373, 20611, 346, 14, 710, 1591, 436, 536, 1249, 2304, 314, 2754, 370, 221, 199, 65, 1627, 13347, 503, 20611, 346, 536, 14, 2494, 10866, 370, 715, 370, 3631, 302, 400, 13, 1548, 687, 221, 199, 26514, 7003, 5309, 314, 2754, 14, 961, 805, 701, 849, 221, 199, 2495, 17174, 5920, 370, 1937, 340, 314, 20611, 346, 1911, 965, 314, 3211, 1591, 15, 354, 221, 199, 8, 692, 1902, 787, 2741, 9, 436, 911, 440, 372, 282, 20611, 346, 1314, 3181, 1133, 221, 199, 1431, 14, 961, 883, 506, 6980, 334, 1152, 314, 805, 2529, 1263, 20611, 346, 1314, 883, 221, 199, 1235, 8539, 370, 436, 6571, 282, 1686, 9351, 370, 664, 63, 1782, 63, 815, 1012, 701, 221, 199, 29436, 7478, 29, 797, 14, 961, 911, 12, 13432, 12, 5139, 11480, 314, 1923, 14745, 221, 199, 475, 1454, 3648, 367, 7256, 1314, 1336, 314, 1249, 2741, 14, 710, 3743, 515, 1680, 221, 199, 3017, 5604, 314, 2909, 402, 314, 2897, 570, 1314, 20611, 346, 2909, 221, 199, 11697, 911, 506, 1586, 687, 340, 949, 20611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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
rwarren14/robotframework
src/robot/jarrunner.py
23
2370
# Copyright 2008-2015 Nokia Solutions and Networks # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from org.robotframework import RobotRunner from robot import run_cli, rebot_cli from robot.libdoc import libdoc_cli from robot.tidy import tidy_cli from robot.testdoc import testdoc_cli USAGE = """robotframework.jar - Robot Framework runner. Usage: java -jar robotframework.jar [command] [options] [input(s)] Available commands: run - Run Robot Framework tests. The default, if no command is given. rebot - Post process Robot Framework output files. libdoc - Create test library or resource file documentation. tidy - Clean-up and changed format of test data files. testdoc - Create documentation from Robot Framework test data files. Run `java -jar robotframework.jar command --help` for more information about an individual command. Examples: java -jar robotframework.jar mytests.txt java -jar robotframework.jar run mytests.txt java -jar robotframework.jar rebot --log mylog.html out.xml java -jar robotframework.jar tidy --format txt mytests.html """ class JarRunner(RobotRunner): """Used for Java-Jython interop when RF is executed from .jar file""" _commands = {'run': run_cli, 'rebot': rebot_cli, 'tidy': tidy_cli, 'libdoc': libdoc_cli, 'testdoc': testdoc_cli} def run(self, args): try: self._run(args) except SystemExit as err: return err.code def _run(self, args): if not args or args[0] in ('-h', '--help'): print USAGE raise SystemExit(0) command, args = self._parse_command_line(args) command(args) # Always calls sys.exit() def _parse_command_line(self, args): try: return self._commands[args[0]], args[1:] except KeyError: return run_cli, args
apache-2.0
[ 3, 221, 1898, 9079, 13, 7806, 653, 745, 4674, 17991, 8653, 436, 17138, 199, 3, 199, 3, 221, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 221, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 221, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 221, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 221, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 221, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 221, 4204, 1334, 314, 844, 14, 199, 199, 504, 5981, 14, 9751, 4857, 492, 820, 17800, 7446, 199, 504, 14544, 492, 1255, 63, 2764, 12, 295, 3018, 63, 2764, 199, 504, 14544, 14, 773, 1301, 492, 1973, 1301, 63, 2764, 199, 504, 14544, 14, 5700, 89, 492, 3367, 8161, 63, 2764, 199, 504, 14544, 14, 396, 1301, 492, 511, 1301, 63, 2764, 421, 199, 20274, 275, 408, 9751, 4857, 14, 7338, 446, 820, 17800, 22545, 7876, 14, 199, 199, 7692, 26, 12120, 446, 7338, 14544, 4857, 14, 7338, 359, 1531, 61, 359, 1419, 61, 359, 1210, 8, 83, 1874, 199, 199, 11464, 3718, 26, 523, 1255, 258, 446, 3378, 820, 17800, 22545, 2295, 14, 710, 849, 12, 340, 949, 1414, 365, 1627, 14, 523, 295, 3018, 257, 446, 7711, 2112, 820, 17800, 22545, 1072, 1584, 14, 523, 1973, 1301, 221, 446, 2790, 511, 3555, 503, 2073, 570, 3794, 14, 523, 3367, 8161, 259, 446, 12762, 13, 384, 436, 2896, 1475, 402, 511, 666, 1584, 14, 523, 511, 1301, 446, 2790, 3794, 687, 820, 17800, 22545, 511, 666, 1584, 14, 199, 199, 2540, 658, 6138, 446, 7338, 14544, 4857, 14, 7338, 1414, 1553, 3437, 64, 367, 1655, 2556, 3595, 199, 290, 8212, 1414, 14, 199, 199, 22787, 26, 523, 12120, 446, 7338, 14544, 4857, 14, 7338, 3002, 2219, 14, 2424, 523, 12120, 446, 7338, 14544, 4857, 14, 7338, 1255, 3002, 2219, 14, 2424, 523, 12120, 446, 7338, 14544, 4857, 14, 7338, 295, 3018, 1553, 793, 3002, 793, 14, 1360, 734, 14, 1652, 523, 12120, 446, 7338, 14544, 4857, 14, 7338, 3367, 8161, 1553, 908, 9444, 3002, 2219, 14, 1360, 199, 624, 421, 199, 533, 1603, 285, 7446, 8, 21823, 7446, 304, 272, 408, 9167, 367, 9586, 13, 42, 11361, 4661, 2675, 1380, 820, 38, 365, 7934, 687, 1275, 7338, 570, 624, 272, 485, 4405, 275, 791, 1065, 356, 1255, 63, 2764, 12, 283, 264, 3018, 356, 295, 3018, 63, 2764, 12, 283, 5700, 89, 356, 3367, 8161, 63, 2764, 12, 326, 283, 773, 1301, 356, 1973, 1301, 63, 2764, 12, 283, 396, 1301, 356, 511, 1301, 63, 2764, 93, 339, 347, 1255, 8, 277, 12, 1249, 304, 267, 862, 26, 288, 291, 423, 1065, 8, 589, 9, 267, 871, 14838, 465, 2329, 26, 288, 372, 2329, 14, 600, 339, 347, 485, 1065, 8, 277, 12, 1249, 304, 267, 340, 440, 1249, 503, 1249, 59, 16, 61, 315, 12291, 72, 297, 2850, 3437, 735, 288, 870, 19635, 2962, 288, 746, 14838, 8, 16, 9, 267, 1414, 12, 1249, 275, 291, 423, 1122, 63, 1531, 63, 604, 8, 589, 9, 267, 1414, 8, 589, 9, 327, 16763, 4882, 984, 14, 2224, 342, 339, 347, 485, 1122, 63, 1531, 63, 604, 8, 277, 12, 1249, 304, 267, 862, 26, 288, 372, 291, 423, 4405, 59, 589, 59, 16, 2365, 1249, 59, 17, 2938, 267, 871, 4067, 26, 288, 372, 1255, 63, 2764, 12, 1249, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 221, 1898, 9079, 13, 7806, 653, 745, 4674, 17991, 8653, 436, 17138, 199, 3, 199, 3, 221, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 221, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 221, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 221, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 221, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 221, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 221, 4204, 1334, 314, 844, 14, 199, 199, 504, 5981, 14, 9751, 4857, 492, 820, 17800, 7446, 199, 504, 14544, 492, 1255, 63, 2764, 12, 295, 3018, 63, 2764, 199, 504, 14544, 14, 773, 1301, 492, 1973, 1301, 63, 2764, 199, 504, 14544, 14, 5700, 89, 492, 3367, 8161, 63, 2764, 199, 504, 14544, 14, 396, 1301, 492, 511, 1301, 63, 2764, 421, 199, 20274, 275, 408, 9751, 4857, 14, 7338, 446, 820, 17800, 22545, 7876, 14, 199, 199, 7692, 26, 12120, 446, 7338, 14544, 4857, 14, 7338, 359, 1531, 61, 359, 1419, 61, 359, 1210, 8, 83, 1874, 199, 199, 11464, 3718, 26, 523, 1255, 258, 446, 3378, 820, 17800, 22545, 2295, 14, 710, 849, 12, 340, 949, 1414, 365, 1627, 14, 523, 295, 3018, 257, 446, 7711, 2112, 820, 17800, 22545, 1072, 1584, 14, 523, 1973, 1301, 221, 446, 2790, 511, 3555, 503, 2073, 570, 3794, 14, 523, 3367, 8161, 259, 446, 12762, 13, 384, 436, 2896, 1475, 402, 511, 666, 1584, 14, 523, 511, 1301, 446, 2790, 3794, 687, 820, 17800, 22545, 511, 666, 1584, 14, 199, 199, 2540, 658, 6138, 446, 7338, 14544, 4857, 14, 7338, 1414, 1553, 3437, 64, 367, 1655, 2556, 3595, 199, 290, 8212, 1414, 14, 199, 199, 22787, 26, 523, 12120, 446, 7338, 14544, 4857, 14, 7338, 3002, 2219, 14, 2424, 523, 12120, 446, 7338, 14544, 4857, 14, 7338, 1255, 3002, 2219, 14, 2424, 523, 12120, 446, 7338, 14544, 4857, 14, 7338, 295, 3018, 1553, 793, 3002, 793, 14, 1360, 734, 14, 1652, 523, 12120, 446, 7338, 14544, 4857, 14, 7338, 3367, 8161, 1553, 908, 9444, 3002, 2219, 14, 1360, 199, 624, 421, 199, 533, 1603, 285, 7446, 8, 21823, 7446, 304, 272, 408, 9167, 367, 9586, 13, 42, 11361, 4661, 2675, 1380, 820, 38, 365, 7934, 687, 1275, 7338, 570, 624, 272, 485, 4405, 275, 791, 1065, 356, 1255, 63, 2764, 12, 283, 264, 3018, 356, 295, 3018, 63, 2764, 12, 283, 5700, 89, 356, 3367, 8161, 63, 2764, 12, 326, 283, 773, 1301, 356, 1973, 1301, 63, 2764, 12, 283, 396, 1301, 356, 511, 1301, 63, 2764, 93, 339, 347, 1255, 8, 277, 12, 1249, 304, 267, 862, 26, 288, 291, 423, 1065, 8, 589, 9, 267, 871, 14838, 465, 2329, 26, 288, 372, 2329, 14, 600, 339, 347, 485, 1065, 8, 277, 12, 1249, 304, 267, 340, 440, 1249, 503, 1249, 59, 16, 61, 315, 12291, 72, 297, 2850, 3437, 735, 288, 870, 19635, 2962, 288, 746, 14838, 8, 16, 9, 267, 1414, 12, 1249, 275, 291, 423, 1122, 63, 1531, 63, 604, 8, 589, 9, 267, 1414, 8, 589, 9, 327, 16763, 4882, 984, 14, 2224, 342, 339, 347, 485, 1122, 63, 1531, 63, 604, 8, 277, 12, 1249, 304, 267, 862, 26, 288, 372, 291, 423, 4405, 59, 589, 59, 16, 2365, 1249, 59, 17, 2938, 267, 871, 4067, 26, 288, 372, 1255, 63, 2764, 12, 1249, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
40223240/2015cdb_g3_40223240
static/Brython3.1.1-20150328-091302/Lib/platform.py
620
51006
#!/usr/bin/env python3 """ This module tries to retrieve as much platform-identifying data as possible. It makes this information available via function APIs. If called from the command line, it prints the platform information concatenated as single string to stdout. The output format is useable as part of a filename. """ # This module is maintained by Marc-Andre Lemburg <mal@egenix.com>. # If you find problems, please submit bug reports/patches via the # Python bug tracker (http://bugs.python.org) and assign them to "lemburg". # # Still needed: # * more support for WinCE # * support for MS-DOS (PythonDX ?) # * support for Amiga and other still unsupported platforms running Python # * support for additional Linux distributions # # Many thanks to all those who helped adding platform-specific # checks (in no particular order): # # Charles G Waldman, David Arnold, Gordon McMillan, Ben Darnell, # Jeff Bauer, Cliff Crawford, Ivan Van Laningham, Josef # Betancourt, Randall Hopper, Karl Putland, John Farrell, Greg # Andruk, Just van Rossum, Thomas Heller, Mark R. Levinson, Mark # Hammond, Bill Tutt, Hans Nowak, Uwe Zessin (OpenVMS support), # Colin Kong, Trent Mick, Guido van Rossum, Anthony Baxter # # History: # # <see CVS and SVN checkin messages for history> # # 1.0.7 - added DEV_NULL # 1.0.6 - added linux_distribution() # 1.0.5 - fixed Java support to allow running the module on Jython # 1.0.4 - added IronPython support # 1.0.3 - added normalization of Windows system name # 1.0.2 - added more Windows support # 1.0.1 - reformatted to make doc.py happy # 1.0.0 - reformatted a bit and checked into Python CVS # 0.8.0 - added sys.version parser and various new access # APIs (python_version(), python_compiler(), etc.) # 0.7.2 - fixed architecture() to use sizeof(pointer) where available # 0.7.1 - added support for Caldera OpenLinux # 0.7.0 - some fixes for WinCE; untabified the source file # 0.6.2 - support for OpenVMS - requires version 1.5.2-V006 or higher and # vms_lib.getsyi() configured # 0.6.1 - added code to prevent 'uname -p' on platforms which are # known not to support it # 0.6.0 - fixed win32_ver() to hopefully work on Win95,98,NT and Win2k; # did some cleanup of the interfaces - some APIs have changed # 0.5.5 - fixed another type in the MacOS code... should have # used more coffee today ;-) # 0.5.4 - fixed a few typos in the MacOS code # 0.5.3 - added experimental MacOS support; added better popen() # workarounds in _syscmd_ver() -- still not 100% elegant # though # 0.5.2 - fixed uname() to return '' instead of 'unknown' in all # return values (the system uname command tends to return # 'unknown' instead of just leaving the field emtpy) # 0.5.1 - included code for slackware dist; added exception handlers # to cover up situations where platforms don't have os.popen # (e.g. Mac) or fail on socket.gethostname(); fixed libc # detection RE # 0.5.0 - changed the API names referring to system commands to *syscmd*; # added java_ver(); made syscmd_ver() a private # API (was system_ver() in previous versions) -- use uname() # instead; extended the win32_ver() to also return processor # type information # 0.4.0 - added win32_ver() and modified the platform() output for WinXX # 0.3.4 - fixed a bug in _follow_symlinks() # 0.3.3 - fixed popen() and "file" command invokation bugs # 0.3.2 - added architecture() API and support for it in platform() # 0.3.1 - fixed syscmd_ver() RE to support Windows NT # 0.3.0 - added system alias support # 0.2.3 - removed 'wince' again... oh well. # 0.2.2 - added 'wince' to syscmd_ver() supported platforms # 0.2.1 - added cache logic and changed the platform string format # 0.2.0 - changed the API to use functions instead of module globals # since some action take too long to be run on module import # 0.1.0 - first release # # You can always get the latest version of this module at: # # http://www.egenix.com/files/python/platform.py # # If that URL should fail, try contacting the author. __copyright__ = """ Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com Copyright (c) 2000-2010, eGenix.com Software GmbH; mailto:info@egenix.com Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee or royalty is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation or portions thereof, including modifications, that you make. EGENIX.COM SOFTWARE GMBH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE ! """ __version__ = '1.0.7' import collections import sys, os, re, subprocess ### Globals & Constants # Determine the platform's /dev/null device try: DEV_NULL = os.devnull except AttributeError: # os.devnull was added in Python 2.4, so emulate it for earlier # Python versions if sys.platform in ('dos','win32','win16','os2'): # Use the old CP/M NUL as device name DEV_NULL = 'NUL' else: # Standard Unix uses /dev/null DEV_NULL = '/dev/null' ### Platform specific APIs _libc_search = re.compile(b'(__libc_init)' b'|' b'(GLIBC_([0-9.]+))' b'|' br'(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)', re.ASCII) def libc_ver(executable=sys.executable,lib='',version='', chunksize=16384): """ Tries to determine the libc version that the file executable (which defaults to the Python interpreter) is linked against. Returns a tuple of strings (lib,version) which default to the given parameters in case the lookup fails. Note that the function has intimate knowledge of how different libc versions add symbols to the executable and thus is probably only useable for executables compiled using gcc. The file is read and scanned in chunks of chunksize bytes. """ if hasattr(os.path, 'realpath'): # Python 2.2 introduced os.path.realpath(); it is used # here to work around problems with Cygwin not being # able to open symlinks for reading executable = os.path.realpath(executable) f = open(executable,'rb') binary = f.read(chunksize) pos = 0 while 1: if b'libc' in binary or b'GLIBC' in binary: m = _libc_search.search(binary,pos) else: m = None if not m: binary = f.read(chunksize) if not binary: break pos = 0 continue libcinit,glibc,glibcversion,so,threads,soversion = [ s.decode('latin1') if s is not None else s for s in m.groups()] if libcinit and not lib: lib = 'libc' elif glibc: if lib != 'glibc': lib = 'glibc' version = glibcversion elif glibcversion > version: version = glibcversion elif so: if lib != 'glibc': lib = 'libc' if soversion and soversion > version: version = soversion if threads and version[-len(threads):] != threads: version = version + threads pos = m.end() f.close() return lib,version def _dist_try_harder(distname,version,id): """ Tries some special tricks to get the distribution information in case the default method fails. Currently supports older SuSE Linux, Caldera OpenLinux and Slackware Linux distributions. """ if os.path.exists('/var/adm/inst-log/info'): # SuSE Linux stores distribution information in that file distname = 'SuSE' for line in open('/var/adm/inst-log/info'): tv = line.split() if len(tv) == 2: tag,value = tv else: continue if tag == 'MIN_DIST_VERSION': version = value.strip() elif tag == 'DIST_IDENT': values = value.split('-') id = values[2] return distname,version,id if os.path.exists('/etc/.installed'): # Caldera OpenLinux has some infos in that file (thanks to Colin Kong) for line in open('/etc/.installed'): pkg = line.split('-') if len(pkg) >= 2 and pkg[0] == 'OpenLinux': # XXX does Caldera support non Intel platforms ? If yes, # where can we find the needed id ? return 'OpenLinux',pkg[1],id if os.path.isdir('/usr/lib/setup'): # Check for slackware version tag file (thanks to Greg Andruk) verfiles = os.listdir('/usr/lib/setup') for n in range(len(verfiles)-1, -1, -1): if verfiles[n][:14] != 'slack-version-': del verfiles[n] if verfiles: verfiles.sort() distname = 'slackware' version = verfiles[-1][14:] return distname,version,id return distname,version,id _release_filename = re.compile(r'(\w+)[-_](release|version)', re.ASCII) _lsb_release_version = re.compile(r'(.+)' ' release ' '([\d.]+)' '[^(]*(?:\((.+)\))?', re.ASCII) _release_version = re.compile(r'([^0-9]+)' '(?: release )?' '([\d.]+)' '[^(]*(?:\((.+)\))?', re.ASCII) # See also http://www.novell.com/coolsolutions/feature/11251.html # and http://linuxmafia.com/faq/Admin/release-files.html # and http://data.linux-ntfs.org/rpm/whichrpm # and http://www.die.net/doc/linux/man/man1/lsb_release.1.html _supported_dists = ( 'SuSE', 'debian', 'fedora', 'redhat', 'centos', 'mandrake', 'mandriva', 'rocks', 'slackware', 'yellowdog', 'gentoo', 'UnitedLinux', 'turbolinux', 'arch', 'mageia') def _parse_release_file(firstline): # Default to empty 'version' and 'id' strings. Both defaults are used # when 'firstline' is empty. 'id' defaults to empty when an id can not # be deduced. version = '' id = '' # Parse the first line m = _lsb_release_version.match(firstline) if m is not None: # LSB format: "distro release x.x (codename)" return tuple(m.groups()) # Pre-LSB format: "distro x.x (codename)" m = _release_version.match(firstline) if m is not None: return tuple(m.groups()) # Unknown format... take the first two words l = firstline.strip().split() if l: version = l[0] if len(l) > 1: id = l[1] return '', version, id def linux_distribution(distname='', version='', id='', supported_dists=_supported_dists, full_distribution_name=1): """ Tries to determine the name of the Linux OS distribution name. The function first looks for a distribution release file in /etc and then reverts to _dist_try_harder() in case no suitable files are found. supported_dists may be given to define the set of Linux distributions to look for. It defaults to a list of currently supported Linux distributions identified by their release file name. If full_distribution_name is true (default), the full distribution read from the OS is returned. Otherwise the short name taken from supported_dists is used. Returns a tuple (distname,version,id) which default to the args given as parameters. """ try: etc = os.listdir('/etc') except os.error: # Probably not a Unix system return distname,version,id etc.sort() for file in etc: m = _release_filename.match(file) if m is not None: _distname,dummy = m.groups() if _distname in supported_dists: distname = _distname break else: return _dist_try_harder(distname,version,id) # Read the first line with open('/etc/'+file, 'r') as f: firstline = f.readline() _distname, _version, _id = _parse_release_file(firstline) if _distname and full_distribution_name: distname = _distname if _version: version = _version if _id: id = _id return distname, version, id # To maintain backwards compatibility: def dist(distname='',version='',id='', supported_dists=_supported_dists): """ Tries to determine the name of the Linux OS distribution name. The function first looks for a distribution release file in /etc and then reverts to _dist_try_harder() in case no suitable files are found. Returns a tuple (distname,version,id) which default to the args given as parameters. """ return linux_distribution(distname, version, id, supported_dists=supported_dists, full_distribution_name=0) def popen(cmd, mode='r', bufsize=-1): """ Portable popen() interface. """ import warnings warnings.warn('use os.popen instead', DeprecationWarning, stacklevel=2) return os.popen(cmd, mode, bufsize) def _norm_version(version, build=''): """ Normalize the version and build strings and return a single version string using the format major.minor.build (or patchlevel). """ l = version.split('.') if build: l.append(build) try: ints = map(int,l) except ValueError: strings = l else: strings = list(map(str,ints)) version = '.'.join(strings[:3]) return version _ver_output = re.compile(r'(?:([\w ]+) ([\w.]+) ' '.*' '\[.* ([\d.]+)\])') # Examples of VER command output: # # Windows 2000: Microsoft Windows 2000 [Version 5.00.2195] # Windows XP: Microsoft Windows XP [Version 5.1.2600] # Windows Vista: Microsoft Windows [Version 6.0.6002] # # Note that the "Version" string gets localized on different # Windows versions. def _syscmd_ver(system='', release='', version='', supported_platforms=('win32','win16','dos','os2')): """ Tries to figure out the OS version used and returns a tuple (system,release,version). It uses the "ver" shell command for this which is known to exists on Windows, DOS and OS/2. XXX Others too ? In case this fails, the given parameters are used as defaults. """ if sys.platform not in supported_platforms: return system,release,version # Try some common cmd strings for cmd in ('ver','command /c ver','cmd /c ver'): try: pipe = popen(cmd) info = pipe.read() if pipe.close(): raise os.error('command failed') # XXX How can I suppress shell errors from being written # to stderr ? except os.error as why: #print 'Command %s failed: %s' % (cmd,why) continue except IOError as why: #print 'Command %s failed: %s' % (cmd,why) continue else: break else: return system,release,version # Parse the output info = info.strip() m = _ver_output.match(info) if m is not None: system,release,version = m.groups() # Strip trailing dots from version and release if release[-1] == '.': release = release[:-1] if version[-1] == '.': version = version[:-1] # Normalize the version and build strings (eliminating additional # zeros) version = _norm_version(version) return system,release,version def _win32_getvalue(key,name,default=''): """ Read a value for name from the registry key. In case this fails, default is returned. """ try: # Use win32api if available from win32api import RegQueryValueEx except ImportError: # On Python 2.0 and later, emulate using winreg import winreg RegQueryValueEx = winreg.QueryValueEx try: return RegQueryValueEx(key,name) except: return default def win32_ver(release='',version='',csd='',ptype=''): """ Get additional version information from the Windows Registry and return a tuple (version,csd,ptype) referring to version number, CSD level (service pack), and OS type (multi/single processor). As a hint: ptype returns 'Uniprocessor Free' on single processor NT machines and 'Multiprocessor Free' on multi processor machines. The 'Free' refers to the OS version being free of debugging code. It could also state 'Checked' which means the OS version uses debugging code, i.e. code that checks arguments, ranges, etc. (Thomas Heller). Note: this function works best with Mark Hammond's win32 package installed, but also on Python 2.3 and later. It obviously only runs on Win32 compatible platforms. """ # XXX Is there any way to find out the processor type on WinXX ? # XXX Is win32 available on Windows CE ? # # Adapted from code posted by Karl Putland to comp.lang.python. # # The mappings between reg. values and release names can be found # here: http://msdn.microsoft.com/library/en-us/sysinfo/base/osversioninfo_str.asp # Import the needed APIs try: import win32api from win32api import RegQueryValueEx, RegOpenKeyEx, \ RegCloseKey, GetVersionEx from win32con import HKEY_LOCAL_MACHINE, VER_PLATFORM_WIN32_NT, \ VER_PLATFORM_WIN32_WINDOWS, VER_NT_WORKSTATION except ImportError: # Emulate the win32api module using Python APIs try: sys.getwindowsversion except AttributeError: # No emulation possible, so return the defaults... return release,version,csd,ptype else: # Emulation using winreg (added in Python 2.0) and # sys.getwindowsversion() (added in Python 2.3) import winreg GetVersionEx = sys.getwindowsversion RegQueryValueEx = winreg.QueryValueEx RegOpenKeyEx = winreg.OpenKeyEx RegCloseKey = winreg.CloseKey HKEY_LOCAL_MACHINE = winreg.HKEY_LOCAL_MACHINE VER_PLATFORM_WIN32_WINDOWS = 1 VER_PLATFORM_WIN32_NT = 2 VER_NT_WORKSTATION = 1 VER_NT_SERVER = 3 REG_SZ = 1 # Find out the registry key and some general version infos winver = GetVersionEx() maj,min,buildno,plat,csd = winver version = '%i.%i.%i' % (maj,min,buildno & 0xFFFF) if hasattr(winver, "service_pack"): if winver.service_pack != "": csd = 'SP%s' % winver.service_pack_major else: if csd[:13] == 'Service Pack ': csd = 'SP' + csd[13:] if plat == VER_PLATFORM_WIN32_WINDOWS: regkey = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion' # Try to guess the release name if maj == 4: if min == 0: release = '95' elif min == 10: release = '98' elif min == 90: release = 'Me' else: release = 'postMe' elif maj == 5: release = '2000' elif plat == VER_PLATFORM_WIN32_NT: regkey = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion' if maj <= 4: release = 'NT' elif maj == 5: if min == 0: release = '2000' elif min == 1: release = 'XP' elif min == 2: release = '2003Server' else: release = 'post2003' elif maj == 6: if hasattr(winver, "product_type"): product_type = winver.product_type else: product_type = VER_NT_WORKSTATION # Without an OSVERSIONINFOEX capable sys.getwindowsversion(), # or help from the registry, we cannot properly identify # non-workstation versions. try: key = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey) name, type = RegQueryValueEx(key, "ProductName") # Discard any type that isn't REG_SZ if type == REG_SZ and name.find("Server") != -1: product_type = VER_NT_SERVER except WindowsError: # Use default of VER_NT_WORKSTATION pass if min == 0: if product_type == VER_NT_WORKSTATION: release = 'Vista' else: release = '2008Server' elif min == 1: if product_type == VER_NT_WORKSTATION: release = '7' else: release = '2008ServerR2' elif min == 2: if product_type == VER_NT_WORKSTATION: release = '8' else: release = '2012Server' else: release = 'post2012Server' else: if not release: # E.g. Win3.1 with win32s release = '%i.%i' % (maj,min) return release,version,csd,ptype # Open the registry key try: keyCurVer = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey) # Get a value to make sure the key exists... RegQueryValueEx(keyCurVer, 'SystemRoot') except: return release,version,csd,ptype # Parse values #subversion = _win32_getvalue(keyCurVer, # 'SubVersionNumber', # ('',1))[0] #if subversion: # release = release + subversion # 95a, 95b, etc. build = _win32_getvalue(keyCurVer, 'CurrentBuildNumber', ('',1))[0] ptype = _win32_getvalue(keyCurVer, 'CurrentType', (ptype,1))[0] # Normalize version version = _norm_version(version,build) # Close key RegCloseKey(keyCurVer) return release,version,csd,ptype def _mac_ver_lookup(selectors,default=None): from _gestalt import gestalt l = [] append = l.append for selector in selectors: try: append(gestalt(selector)) except (RuntimeError, OSError): append(default) return l def _bcd2str(bcd): return hex(bcd)[2:] def _mac_ver_gestalt(): """ Thanks to Mark R. Levinson for mailing documentation links and code examples for this function. Documentation for the gestalt() API is available online at: http://www.rgaros.nl/gestalt/ """ # Check whether the version info module is available try: import _gestalt except ImportError: return None # Get the infos sysv, sysa = _mac_ver_lookup(('sysv','sysa')) # Decode the infos if sysv: major = (sysv & 0xFF00) >> 8 minor = (sysv & 0x00F0) >> 4 patch = (sysv & 0x000F) if (major, minor) >= (10, 4): # the 'sysv' gestald cannot return patchlevels # higher than 9. Apple introduced 3 new # gestalt codes in 10.4 to deal with this # issue (needed because patch levels can # run higher than 9, such as 10.4.11) major,minor,patch = _mac_ver_lookup(('sys1','sys2','sys3')) release = '%i.%i.%i' %(major, minor, patch) else: release = '%s.%i.%i' % (_bcd2str(major),minor,patch) if sysa: machine = {0x1: '68k', 0x2: 'PowerPC', 0xa: 'i386'}.get(sysa,'') versioninfo=('', '', '') return release,versioninfo,machine def _mac_ver_xml(): fn = '/System/Library/CoreServices/SystemVersion.plist' if not os.path.exists(fn): return None try: import plistlib except ImportError: return None pl = plistlib.readPlist(fn) release = pl['ProductVersion'] versioninfo=('', '', '') machine = os.uname().machine if machine in ('ppc', 'Power Macintosh'): # for compatibility with the gestalt based code machine = 'PowerPC' return release,versioninfo,machine def mac_ver(release='',versioninfo=('','',''),machine=''): """ Get MacOS version information and return it as tuple (release, versioninfo, machine) with versioninfo being a tuple (version, dev_stage, non_release_version). Entries which cannot be determined are set to the parameter values which default to ''. All tuple entries are strings. """ # First try reading the information from an XML file which should # always be present info = _mac_ver_xml() if info is not None: return info # If that doesn't work for some reason fall back to reading the # information using gestalt calls. info = _mac_ver_gestalt() if info is not None: return info # If that also doesn't work return the default values return release,versioninfo,machine def _java_getprop(name,default): from java.lang import System try: value = System.getProperty(name) if value is None: return default return value except AttributeError: return default def java_ver(release='',vendor='',vminfo=('','',''),osinfo=('','','')): """ Version interface for Jython. Returns a tuple (release,vendor,vminfo,osinfo) with vminfo being a tuple (vm_name,vm_release,vm_vendor) and osinfo being a tuple (os_name,os_version,os_arch). Values which cannot be determined are set to the defaults given as parameters (which all default to ''). """ # Import the needed APIs try: import java.lang except ImportError: return release,vendor,vminfo,osinfo vendor = _java_getprop('java.vendor', vendor) release = _java_getprop('java.version', release) vm_name, vm_release, vm_vendor = vminfo vm_name = _java_getprop('java.vm.name', vm_name) vm_vendor = _java_getprop('java.vm.vendor', vm_vendor) vm_release = _java_getprop('java.vm.version', vm_release) vminfo = vm_name, vm_release, vm_vendor os_name, os_version, os_arch = osinfo os_arch = _java_getprop('java.os.arch', os_arch) os_name = _java_getprop('java.os.name', os_name) os_version = _java_getprop('java.os.version', os_version) osinfo = os_name, os_version, os_arch return release, vendor, vminfo, osinfo ### System name aliasing def system_alias(system,release,version): """ Returns (system,release,version) aliased to common marketing names used for some systems. It also does some reordering of the information in some cases where it would otherwise cause confusion. """ if system == 'Rhapsody': # Apple's BSD derivative # XXX How can we determine the marketing release number ? return 'MacOS X Server',system+release,version elif system == 'SunOS': # Sun's OS if release < '5': # These releases use the old name SunOS return system,release,version # Modify release (marketing release = SunOS release - 3) l = release.split('.') if l: try: major = int(l[0]) except ValueError: pass else: major = major - 3 l[0] = str(major) release = '.'.join(l) if release < '6': system = 'Solaris' else: # XXX Whatever the new SunOS marketing name is... system = 'Solaris' elif system == 'IRIX64': # IRIX reports IRIX64 on platforms with 64-bit support; yet it # is really a version and not a different platform, since 32-bit # apps are also supported.. system = 'IRIX' if version: version = version + ' (64bit)' else: version = '64bit' elif system in ('win32','win16'): # In case one of the other tricks system = 'Windows' return system,release,version ### Various internal helpers def _platform(*args): """ Helper to format the platform string in a filename compatible format e.g. "system-version-machine". """ # Format the platform string platform = '-'.join(x.strip() for x in filter(len, args)) # Cleanup some possible filename obstacles... platform = platform.replace(' ','_') platform = platform.replace('/','-') platform = platform.replace('\\','-') platform = platform.replace(':','-') platform = platform.replace(';','-') platform = platform.replace('"','-') platform = platform.replace('(','-') platform = platform.replace(')','-') # No need to report 'unknown' information... platform = platform.replace('unknown','') # Fold '--'s and remove trailing '-' while 1: cleaned = platform.replace('--','-') if cleaned == platform: break platform = cleaned while platform[-1] == '-': platform = platform[:-1] return platform def _node(default=''): """ Helper to determine the node name of this machine. """ try: import socket except ImportError: # No sockets... return default try: return socket.gethostname() except socket.error: # Still not working... return default def _follow_symlinks(filepath): """ In case filepath is a symlink, follow it until a real file is reached. """ filepath = os.path.abspath(filepath) while os.path.islink(filepath): filepath = os.path.normpath( os.path.join(os.path.dirname(filepath),os.readlink(filepath))) return filepath def _syscmd_uname(option,default=''): """ Interface to the system's uname command. """ if sys.platform in ('dos','win32','win16','os2'): # XXX Others too ? return default try: f = os.popen('uname %s 2> %s' % (option, DEV_NULL)) except (AttributeError,os.error): return default output = f.read().strip() rc = f.close() if not output or rc: return default else: return output def _syscmd_file(target,default=''): """ Interface to the system's file command. The function uses the -b option of the file command to have it omit the filename in its output. Follow the symlinks. It returns default in case the command should fail. """ if sys.platform in ('dos','win32','win16','os2'): # XXX Others too ? return default target = _follow_symlinks(target) try: proc = subprocess.Popen(['file', target], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) except (AttributeError,os.error): return default output = proc.communicate()[0].decode('latin-1') rc = proc.wait() if not output or rc: return default else: return output ### Information about the used architecture # Default values for architecture; non-empty strings override the # defaults given as parameters _default_architecture = { 'win32': ('','WindowsPE'), 'win16': ('','Windows'), 'dos': ('','MSDOS'), } def architecture(executable=sys.executable,bits='',linkage=''): """ Queries the given executable (defaults to the Python interpreter binary) for various architecture information. Returns a tuple (bits,linkage) which contains information about the bit architecture and the linkage format used for the executable. Both values are returned as strings. Values that cannot be determined are returned as given by the parameter presets. If bits is given as '', the sizeof(pointer) (or sizeof(long) on Python version < 1.5.2) is used as indicator for the supported pointer size. The function relies on the system's "file" command to do the actual work. This is available on most if not all Unix platforms. On some non-Unix platforms where the "file" command does not exist and the executable is set to the Python interpreter binary defaults from _default_architecture are used. """ # Use the sizeof(pointer) as default number of bits if nothing # else is given as default. if not bits: import struct try: size = struct.calcsize('P') except struct.error: # Older installations can only query longs size = struct.calcsize('l') bits = str(size*8) + 'bit' # Get data from the 'file' system command if executable: fileout = _syscmd_file(executable, '') else: fileout = '' if not fileout and \ executable == sys.executable: # "file" command did not return anything; we'll try to provide # some sensible defaults then... if sys.platform in _default_architecture: b,l = _default_architecture[sys.platform] if b: bits = b if l: linkage = l return bits,linkage if 'executable' not in fileout: # Format not supported return bits,linkage # Bits if '32-bit' in fileout: bits = '32bit' elif 'N32' in fileout: # On Irix only bits = 'n32bit' elif '64-bit' in fileout: bits = '64bit' # Linkage if 'ELF' in fileout: linkage = 'ELF' elif 'PE' in fileout: # E.g. Windows uses this format if 'Windows' in fileout: linkage = 'WindowsPE' else: linkage = 'PE' elif 'COFF' in fileout: linkage = 'COFF' elif 'MS-DOS' in fileout: linkage = 'MSDOS' else: # XXX the A.OUT format also falls under this class... pass return bits,linkage ### Portable uname() interface uname_result = collections.namedtuple("uname_result", "system node release version machine processor") _uname_cache = None def uname(): """ Fairly portable uname interface. Returns a tuple of strings (system,node,release,version,machine,processor) identifying the underlying platform. Note that unlike the os.uname function this also returns possible processor information as an additional tuple entry. Entries which cannot be determined are set to ''. """ global _uname_cache no_os_uname = 0 if _uname_cache is not None: return _uname_cache processor = '' # Get some infos from the builtin os.uname API... try: system,node,release,version,machine = os.uname() except AttributeError: no_os_uname = 1 if no_os_uname or not list(filter(None, (system, node, release, version, machine))): # Hmm, no there is either no uname or uname has returned #'unknowns'... we'll have to poke around the system then. if no_os_uname: system = sys.platform release = '' version = '' node = _node() machine = '' use_syscmd_ver = 1 # Try win32_ver() on win32 platforms if system == 'win32': release,version,csd,ptype = win32_ver() if release and version: use_syscmd_ver = 0 # Try to use the PROCESSOR_* environment variables # available on Win XP and later; see # http://support.microsoft.com/kb/888731 and # http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM if not machine: # WOW64 processes mask the native architecture if "PROCESSOR_ARCHITEW6432" in os.environ: machine = os.environ.get("PROCESSOR_ARCHITEW6432", '') else: machine = os.environ.get('PROCESSOR_ARCHITECTURE', '') if not processor: processor = os.environ.get('PROCESSOR_IDENTIFIER', machine) # Try the 'ver' system command available on some # platforms if use_syscmd_ver: system,release,version = _syscmd_ver(system) # Normalize system to what win32_ver() normally returns # (_syscmd_ver() tends to return the vendor name as well) if system == 'Microsoft Windows': system = 'Windows' elif system == 'Microsoft' and release == 'Windows': # Under Windows Vista and Windows Server 2008, # Microsoft changed the output of the ver command. The # release is no longer printed. This causes the # system and release to be misidentified. system = 'Windows' if '6.0' == version[:3]: release = 'Vista' else: release = '' # In case we still don't know anything useful, we'll try to # help ourselves if system in ('win32','win16'): if not version: if system == 'win32': version = '32bit' else: version = '16bit' system = 'Windows' elif system[:4] == 'java': release,vendor,vminfo,osinfo = java_ver() system = 'Java' version = ', '.join(vminfo) if not version: version = vendor # System specific extensions if system == 'OpenVMS': # OpenVMS seems to have release and version mixed up if not release or release == '0': release = version version = '' # Get processor information try: import vms_lib except ImportError: pass else: csid, cpu_number = vms_lib.getsyi('SYI$_CPU',0) if (cpu_number >= 128): processor = 'Alpha' else: processor = 'VAX' if not processor: # Get processor information from the uname system command processor = _syscmd_uname('-p','') #If any unknowns still exist, replace them with ''s, which are more portable if system == 'unknown': system = '' if node == 'unknown': node = '' if release == 'unknown': release = '' if version == 'unknown': version = '' if machine == 'unknown': machine = '' if processor == 'unknown': processor = '' # normalize name if system == 'Microsoft' and release == 'Windows': system = 'Windows' release = 'Vista' _uname_cache = uname_result(system,node,release,version,machine,processor) return _uname_cache ### Direct interfaces to some of the uname() return values def system(): """ Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'. An empty string is returned if the value cannot be determined. """ return uname().system def node(): """ Returns the computer's network name (which may not be fully qualified) An empty string is returned if the value cannot be determined. """ return uname().node def release(): """ Returns the system's release, e.g. '2.2.0' or 'NT' An empty string is returned if the value cannot be determined. """ return uname().release def version(): """ Returns the system's release version, e.g. '#3 on degas' An empty string is returned if the value cannot be determined. """ return uname().version def machine(): """ Returns the machine type, e.g. 'i386' An empty string is returned if the value cannot be determined. """ return uname().machine def processor(): """ Returns the (true) processor name, e.g. 'amdk6' An empty string is returned if the value cannot be determined. Note that many platforms do not provide this information or simply return the same value as for machine(), e.g. NetBSD does this. """ return uname().processor ### Various APIs for extracting information from sys.version _sys_version_parser = re.compile( r'([\w.+]+)\s*' '\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*' '\[([^\]]+)\]?', re.ASCII) _ironpython_sys_version_parser = re.compile( r'IronPython\s*' '([\d\.]+)' '(?: \(([\d\.]+)\))?' ' on (.NET [\d\.]+)', re.ASCII) # IronPython covering 2.6 and 2.7 _ironpython26_sys_version_parser = re.compile( r'([\d.]+)\s*' '\(IronPython\s*' '[\d.]+\s*' '\(([\d.]+)\) on ([\w.]+ [\d.]+(?: \(\d+-bit\))?)\)' ) _pypy_sys_version_parser = re.compile( r'([\w.+]+)\s*' '\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*' '\[PyPy [^\]]+\]?') _sys_version_cache = {} def _sys_version(sys_version=None): """ Returns a parsed version of Python's sys.version as tuple (name, version, branch, revision, buildno, builddate, compiler) referring to the Python implementation name, version, branch, revision, build number, build date/time as string and the compiler identification string. Note that unlike the Python sys.version, the returned value for the Python version will always include the patchlevel (it defaults to '.0'). The function returns empty strings for tuple entries that cannot be determined. sys_version may be given to parse an alternative version string, e.g. if the version was read from a different Python interpreter. """ # Get the Python version if sys_version is None: sys_version = sys.version # Try the cache first result = _sys_version_cache.get(sys_version, None) if result is not None: return result # Parse it if 'Brython' in sys_version: # IronPython name = 'Brython' _parser=re.compile("^(\d+\.\d+\.\d+)[^[]+\[(.*)\]") match=_parser.match(sys_version) if match is None: raise ValueError( 'failed to parse Brython sys.version: %s' % repr(sys_version)) #version, alt_version, compiler = match.groups() version, compiler = match.groups() alt_version = '' buildno = '' builddate = '' elif 'IronPython' in sys_version: # IronPython name = 'IronPython' if sys_version.startswith('IronPython'): match = _ironpython_sys_version_parser.match(sys_version) else: match = _ironpython26_sys_version_parser.match(sys_version) if match is None: raise ValueError( 'failed to parse IronPython sys.version: %s' % repr(sys_version)) version, alt_version, compiler = match.groups() buildno = '' builddate = '' elif sys.platform.startswith('java'): # Jython name = 'Jython' match = _sys_version_parser.match(sys_version) if match is None: raise ValueError( 'failed to parse Jython sys.version: %s' % repr(sys_version)) version, buildno, builddate, buildtime, _ = match.groups() compiler = sys.platform elif "PyPy" in sys_version: # PyPy name = "PyPy" match = _pypy_sys_version_parser.match(sys_version) if match is None: raise ValueError("failed to parse PyPy sys.version: %s" % repr(sys_version)) version, buildno, builddate, buildtime = match.groups() compiler = "" else: # CPython match = _sys_version_parser.match(sys_version) if match is None: raise ValueError( 'failed to parse CPython sys.version: %s' % repr(sys_version)) version, buildno, builddate, buildtime, compiler = \ match.groups() name = 'CPython' builddate = builddate + ' ' + buildtime if hasattr(sys, '_mercurial'): _, branch, revision = sys._mercurial elif hasattr(sys, 'subversion'): # sys.subversion was added in Python 2.5 _, branch, revision = sys.subversion else: branch = '' revision = '' # Add the patchlevel version if missing l = version.split('.') if len(l) == 2: l.append('0') version = '.'.join(l) # Build and cache the result result = (name, version, branch, revision, buildno, builddate, compiler) _sys_version_cache[sys_version] = result return result def python_implementation(): """ Returns a string identifying the Python implementation. Currently, the following implementations are identified: 'CPython' (C implementation of Python), 'IronPython' (.NET implementation of Python), 'Jython' (Java implementation of Python), 'PyPy' (Python implementation of Python). """ return _sys_version()[0] def python_version(): """ Returns the Python version as string 'major.minor.patchlevel' Note that unlike the Python sys.version, the returned value will always include the patchlevel (it defaults to 0). """ return _sys_version()[1] def python_version_tuple(): """ Returns the Python version as tuple (major, minor, patchlevel) of strings. Note that unlike the Python sys.version, the returned value will always include the patchlevel (it defaults to 0). """ return tuple(_sys_version()[1].split('.')) def python_branch(): """ Returns a string identifying the Python implementation branch. For CPython this is the Subversion branch from which the Python binary was built. If not available, an empty string is returned. """ return _sys_version()[2] def python_revision(): """ Returns a string identifying the Python implementation revision. For CPython this is the Subversion revision from which the Python binary was built. If not available, an empty string is returned. """ return _sys_version()[3] def python_build(): """ Returns a tuple (buildno, builddate) stating the Python build number and date as strings. """ return _sys_version()[4:6] def python_compiler(): """ Returns a string identifying the compiler used for compiling Python. """ return _sys_version()[6] ### The Opus Magnum of platform strings :-) _platform_cache = {} def platform(aliased=0, terse=0): """ Returns a single string identifying the underlying platform with as much useful information as possible (but no more :). The output is intended to be human readable rather than machine parseable. It may look different on different platforms and this is intended. If "aliased" is true, the function will use aliases for various platforms that report system names which differ from their common names, e.g. SunOS will be reported as Solaris. The system_alias() function is used to implement this. Setting terse to true causes the function to return only the absolute minimum information needed to identify the platform. """ result = _platform_cache.get((aliased, terse), None) if result is not None: return result # Get uname information and then apply platform specific cosmetics # to it... system,node,release,version,machine,processor = uname() if machine == processor: processor = '' if aliased: system,release,version = system_alias(system,release,version) if system == 'Windows': # MS platforms rel,vers,csd,ptype = win32_ver(version) if terse: platform = _platform(system,release) else: platform = _platform(system,release,version,csd) elif system in ('Linux',): # Linux based systems distname,distversion,distid = dist('') if distname and not terse: platform = _platform(system,release,machine,processor, 'with', distname,distversion,distid) else: # If the distribution name is unknown check for libc vs. glibc libcname,libcversion = libc_ver(sys.executable) platform = _platform(system,release,machine,processor, 'with', libcname+libcversion) elif system == 'Java': # Java platforms r,v,vminfo,(os_name,os_version,os_arch) = java_ver() if terse or not os_name: platform = _platform(system,release,version) else: platform = _platform(system,release,version, 'on', os_name,os_version,os_arch) elif system == 'MacOS': # MacOS platforms if terse: platform = _platform(system,release) else: platform = _platform(system,release,machine) else: # Generic handler if terse: platform = _platform(system,release) else: bits,linkage = architecture(sys.executable) platform = _platform(system,release,machine,processor,bits,linkage) _platform_cache[(aliased, terse)] = platform return platform ### Command line interface if __name__ == '__main__': # Default is to print the aliased verbose platform string terse = ('terse' in sys.argv or '--terse' in sys.argv) aliased = (not 'nonaliased' in sys.argv and not '--nonaliased' in sys.argv) print(platform(aliased,terse)) sys.exit(0)
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 199, 624, 961, 859, 11275, 370, 8044, 465, 8298, 4298, 13, 22232, 316, 666, 465, 272, 3962, 14, 2779, 7704, 642, 2556, 2808, 4799, 805, 15913, 14, 339, 982, 2797, 687, 314, 1414, 1004, 12, 652, 14767, 314, 4298, 272, 2556, 26271, 465, 2849, 1059, 370, 3839, 14, 710, 1072, 272, 1475, 365, 675, 461, 465, 1777, 402, 282, 1788, 14, 199, 199, 624, 199, 3, 259, 961, 859, 365, 26391, 701, 603, 9912, 13, 3325, 264, 7005, 32649, 665, 2174, 32, 69, 2268, 1148, 14, 957, 10827, 199, 3, 259, 982, 1265, 2342, 8826, 12, 8749, 11482, 6519, 13924, 15, 11350, 4799, 314, 199, 3, 259, 2018, 6519, 15271, 334, 1014, 921, 13017, 14, 1548, 14, 1308, 9, 436, 5090, 3062, 370, 298, 274, 32649, 1674, 199, 3, 199, 3, 259, 428, 12587, 4346, 26, 199, 3, 259, 627, 1655, 2291, 367, 13036, 2089, 199, 3, 259, 627, 2291, 367, 14282, 13, 32735, 334, 4718, 19596, 5805, 9, 199, 3, 259, 627, 2291, 367, 437, 4071, 65, 436, 1163, 5139, 16313, 10677, 3879, 2018, 199, 3, 259, 627, 2291, 367, 4722, 10130, 10208, 199, 3, 199, 3, 259, 15517, 2419, 6080, 370, 1006, 5204, 3963, 20181, 1915, 7791, 4298, 13, 6100, 199, 3, 259, 5920, 334, 262, 949, 6770, 1865, 304, 199, 3, 199, 3, 420, 6659, 2978, 598, 644, 27075, 1237, 12, 20232, 1952, 78, 1753, 12, 598, 2181, 265, 22895, 45, 778, 290, 12, 26844, 577, 1060, 1697, 12, 199, 3, 420, 1603, 3609, 699, 3844, 281, 12, 445, 317, 556, 445, 1773, 18090, 12, 473, 20662, 812, 290, 491, 290, 316, 10670, 12, 1603, 3362, 70, 199, 3, 420, 31535, 290, 331, 20471, 12, 820, 460, 452, 869, 411, 529, 12, 1804, 285, 76, 16280, 9688, 12, 17815, 481, 285, 264, 914, 12, 29096, 199, 3, 420, 6061, 82, 3210, 12, 13870, 20744, 6848, 385, 453, 12, 27864, 869, 352, 1435, 12, 7173, 820, 14, 491, 6857, 262, 834, 12, 7173, 199, 3, 420, 869, 455, 2106, 68, 12, 699, 778, 377, 337, 84, 12, 869, 796, 7356, 1151, 12, 738, 1129, 3107, 16709, 262, 334, 4299, 54, 3053, 2291, 395, 199, 3, 420, 3626, 262, 1804, 951, 12, 377, 640, 603, 2000, 12, 598, 1535, 79, 20744, 6848, 385, 453, 12, 1626, 898, 89, 699, 1219, 351, 199, 3, 199, 3, 259, 27829, 26, 199, 3, 199, 3, 259, 665, 3239, 445, 7428, 436, 24639, 1104, 262, 3788, 367, 7994, 30, 199, 3, 199, 3, 259, 413, 14, 16, 14, 23, 446, 3483, 3265, 54, 63, 8084, 199, 3, 259, 413, 14, 16, 14, 22, 446, 3483, 18369, 63, 4972, 342, 199, 3, 259, 413, 14, 16, 14, 21, 446, 6317, 9586, 2291, 370, 2040, 3879, 314, 859, 641, 25333, 199, 3, 259, 413, 14, 16, 14, 20, 446, 3483, 473, 2641, 4718, 2291, 199, 3, 259, 413, 14, 16, 14, 19, 446, 3483, 16973, 402, 5417, 2656, 536, 199, 3, 259, 413, 14, 16, 14, 18, 446, 3483, 1655, 5417, 2291, 199, 3, 259, 413, 14, 16, 14, 17, 446, 295, 15317, 370, 1852, 1382, 14, 647, 394, 18869, 199, 3, 259, 413, 14, 16, 14, 16, 446, 295, 15317, 282, 4546, 436, 7923, 1901, 2018, 445, 7428, 199, 3, 259, 378, 14, 24, 14, 16, 446, 3483, 984, 14, 1023, 1798, 436, 7750, 892, 2879, 199, 3, 3322, 15913, 334, 1548, 63, 1023, 1062, 2366, 63, 5772, 1062, 5423, 4959, 199, 3, 259, 378, 14, 23, 14, 18, 446, 6317, 15931, 342, 370, 675, 13855, 8, 3929, 9, 2382, 2808, 199, 3, 259, 378, 14, 23, 14, 17, 446, 3483, 2291, 367, 8256, 271, 345, 3232, 14091, 199, 3, 259, 378, 14, 23, 14, 16, 446, 2005, 25079, 367, 13036, 2089, 27, 625, 2902, 4541, 314, 1350, 570, 199, 3, 259, 378, 14, 22, 14, 18, 446, 2291, 367, 3232, 54, 3053, 446, 5074, 1015, 413, 14, 21, 14, 18, 13, 54, 8010, 503, 10948, 436, 199, 3, 3322, 22505, 63, 773, 14, 362, 1786, 73, 342, 7526, 199, 3, 259, 378, 14, 22, 14, 17, 446, 3483, 1233, 370, 7981, 283, 16040, 446, 80, 7, 641, 10677, 1314, 787, 199, 3, 3322, 6040, 440, 370, 2291, 652, 199, 3, 259, 378, 14, 22, 14, 16, 446, 6317, 4747, 708, 63, 422, 342, 370, 3661, 5836, 1736, 641, 13036, 2720, 12, 2905, 12, 12460, 436, 13036, 18, 75, 27, 199, 3, 3322, 8103, 2005, 9058, 402, 314, 8386, 446, 2005, 15913, 1172, 2896, 199, 3, 259, 378, 14, 21, 14, 21, 446, 6317, 4573, 730, 315, 314, 10444, 3100, 1233, 1396, 1077, 1172, 199, 3, 3322, 1202, 1655, 512, 24715, 11168, 8700, 13, 9, 199, 3, 259, 378, 14, 21, 14, 20, 446, 6317, 282, 9284, 10284, 1712, 315, 314, 10444, 3100, 1233, 199, 3, 259, 378, 14, 21, 14, 19, 446, 3483, 22820, 10444, 3100, 2291, 27, 3483, 8034, 17758, 342, 199, 3, 3322, 18092, 83, 315, 485, 1786, 551, 1064, 63, 422, 342, 1553, 5139, 440, 2948, 5, 325, 4170, 867, 199, 3, 3322, 10617, 199, 3, 259, 378, 14, 21, 14, 18, 446, 6317, 28179, 342, 370, 372, 2125, 3140, 402, 283, 5187, 7, 315, 1006, 199, 3, 3322, 372, 1338, 334, 1589, 2656, 28179, 1414, 16685, 795, 370, 372, 199, 3, 3322, 283, 5187, 7, 3140, 402, 2951, 23188, 314, 901, 325, 2037, 647, 9, 199, 3, 259, 378, 14, 21, 14, 17, 446, 5120, 1233, 367, 29877, 1068, 2917, 27, 3483, 1919, 8297, 199, 3, 3322, 370, 8486, 1536, 24325, 2382, 10677, 2793, 1133, 1172, 747, 14, 12207, 199, 3, 3322, 334, 69, 14, 71, 14, 10444, 9, 503, 2449, 641, 2838, 14, 29789, 7303, 6317, 1973, 67, 199, 3, 3322, 15212, 5363, 199, 3, 259, 378, 14, 21, 14, 16, 446, 2896, 314, 3261, 1561, 21864, 370, 2656, 3718, 370, 627, 1786, 551, 1064, 10, 27, 199, 3, 3322, 3483, 12120, 63, 422, 7303, 6326, 1847, 551, 1064, 63, 422, 342, 282, 5726, 199, 3, 3322, 3261, 334, 10274, 2656, 63, 422, 342, 315, 4136, 5459, 9, 1553, 675, 28179, 342, 199, 3, 3322, 3140, 27, 9243, 314, 4747, 708, 63, 422 ]
[ 2647, 15, 1393, 15, 1813, 2366, 19, 199, 199, 624, 961, 859, 11275, 370, 8044, 465, 8298, 4298, 13, 22232, 316, 666, 465, 272, 3962, 14, 2779, 7704, 642, 2556, 2808, 4799, 805, 15913, 14, 339, 982, 2797, 687, 314, 1414, 1004, 12, 652, 14767, 314, 4298, 272, 2556, 26271, 465, 2849, 1059, 370, 3839, 14, 710, 1072, 272, 1475, 365, 675, 461, 465, 1777, 402, 282, 1788, 14, 199, 199, 624, 199, 3, 259, 961, 859, 365, 26391, 701, 603, 9912, 13, 3325, 264, 7005, 32649, 665, 2174, 32, 69, 2268, 1148, 14, 957, 10827, 199, 3, 259, 982, 1265, 2342, 8826, 12, 8749, 11482, 6519, 13924, 15, 11350, 4799, 314, 199, 3, 259, 2018, 6519, 15271, 334, 1014, 921, 13017, 14, 1548, 14, 1308, 9, 436, 5090, 3062, 370, 298, 274, 32649, 1674, 199, 3, 199, 3, 259, 428, 12587, 4346, 26, 199, 3, 259, 627, 1655, 2291, 367, 13036, 2089, 199, 3, 259, 627, 2291, 367, 14282, 13, 32735, 334, 4718, 19596, 5805, 9, 199, 3, 259, 627, 2291, 367, 437, 4071, 65, 436, 1163, 5139, 16313, 10677, 3879, 2018, 199, 3, 259, 627, 2291, 367, 4722, 10130, 10208, 199, 3, 199, 3, 259, 15517, 2419, 6080, 370, 1006, 5204, 3963, 20181, 1915, 7791, 4298, 13, 6100, 199, 3, 259, 5920, 334, 262, 949, 6770, 1865, 304, 199, 3, 199, 3, 420, 6659, 2978, 598, 644, 27075, 1237, 12, 20232, 1952, 78, 1753, 12, 598, 2181, 265, 22895, 45, 778, 290, 12, 26844, 577, 1060, 1697, 12, 199, 3, 420, 1603, 3609, 699, 3844, 281, 12, 445, 317, 556, 445, 1773, 18090, 12, 473, 20662, 812, 290, 491, 290, 316, 10670, 12, 1603, 3362, 70, 199, 3, 420, 31535, 290, 331, 20471, 12, 820, 460, 452, 869, 411, 529, 12, 1804, 285, 76, 16280, 9688, 12, 17815, 481, 285, 264, 914, 12, 29096, 199, 3, 420, 6061, 82, 3210, 12, 13870, 20744, 6848, 385, 453, 12, 27864, 869, 352, 1435, 12, 7173, 820, 14, 491, 6857, 262, 834, 12, 7173, 199, 3, 420, 869, 455, 2106, 68, 12, 699, 778, 377, 337, 84, 12, 869, 796, 7356, 1151, 12, 738, 1129, 3107, 16709, 262, 334, 4299, 54, 3053, 2291, 395, 199, 3, 420, 3626, 262, 1804, 951, 12, 377, 640, 603, 2000, 12, 598, 1535, 79, 20744, 6848, 385, 453, 12, 1626, 898, 89, 699, 1219, 351, 199, 3, 199, 3, 259, 27829, 26, 199, 3, 199, 3, 259, 665, 3239, 445, 7428, 436, 24639, 1104, 262, 3788, 367, 7994, 30, 199, 3, 199, 3, 259, 413, 14, 16, 14, 23, 446, 3483, 3265, 54, 63, 8084, 199, 3, 259, 413, 14, 16, 14, 22, 446, 3483, 18369, 63, 4972, 342, 199, 3, 259, 413, 14, 16, 14, 21, 446, 6317, 9586, 2291, 370, 2040, 3879, 314, 859, 641, 25333, 199, 3, 259, 413, 14, 16, 14, 20, 446, 3483, 473, 2641, 4718, 2291, 199, 3, 259, 413, 14, 16, 14, 19, 446, 3483, 16973, 402, 5417, 2656, 536, 199, 3, 259, 413, 14, 16, 14, 18, 446, 3483, 1655, 5417, 2291, 199, 3, 259, 413, 14, 16, 14, 17, 446, 295, 15317, 370, 1852, 1382, 14, 647, 394, 18869, 199, 3, 259, 413, 14, 16, 14, 16, 446, 295, 15317, 282, 4546, 436, 7923, 1901, 2018, 445, 7428, 199, 3, 259, 378, 14, 24, 14, 16, 446, 3483, 984, 14, 1023, 1798, 436, 7750, 892, 2879, 199, 3, 3322, 15913, 334, 1548, 63, 1023, 1062, 2366, 63, 5772, 1062, 5423, 4959, 199, 3, 259, 378, 14, 23, 14, 18, 446, 6317, 15931, 342, 370, 675, 13855, 8, 3929, 9, 2382, 2808, 199, 3, 259, 378, 14, 23, 14, 17, 446, 3483, 2291, 367, 8256, 271, 345, 3232, 14091, 199, 3, 259, 378, 14, 23, 14, 16, 446, 2005, 25079, 367, 13036, 2089, 27, 625, 2902, 4541, 314, 1350, 570, 199, 3, 259, 378, 14, 22, 14, 18, 446, 2291, 367, 3232, 54, 3053, 446, 5074, 1015, 413, 14, 21, 14, 18, 13, 54, 8010, 503, 10948, 436, 199, 3, 3322, 22505, 63, 773, 14, 362, 1786, 73, 342, 7526, 199, 3, 259, 378, 14, 22, 14, 17, 446, 3483, 1233, 370, 7981, 283, 16040, 446, 80, 7, 641, 10677, 1314, 787, 199, 3, 3322, 6040, 440, 370, 2291, 652, 199, 3, 259, 378, 14, 22, 14, 16, 446, 6317, 4747, 708, 63, 422, 342, 370, 3661, 5836, 1736, 641, 13036, 2720, 12, 2905, 12, 12460, 436, 13036, 18, 75, 27, 199, 3, 3322, 8103, 2005, 9058, 402, 314, 8386, 446, 2005, 15913, 1172, 2896, 199, 3, 259, 378, 14, 21, 14, 21, 446, 6317, 4573, 730, 315, 314, 10444, 3100, 1233, 1396, 1077, 1172, 199, 3, 3322, 1202, 1655, 512, 24715, 11168, 8700, 13, 9, 199, 3, 259, 378, 14, 21, 14, 20, 446, 6317, 282, 9284, 10284, 1712, 315, 314, 10444, 3100, 1233, 199, 3, 259, 378, 14, 21, 14, 19, 446, 3483, 22820, 10444, 3100, 2291, 27, 3483, 8034, 17758, 342, 199, 3, 3322, 18092, 83, 315, 485, 1786, 551, 1064, 63, 422, 342, 1553, 5139, 440, 2948, 5, 325, 4170, 867, 199, 3, 3322, 10617, 199, 3, 259, 378, 14, 21, 14, 18, 446, 6317, 28179, 342, 370, 372, 2125, 3140, 402, 283, 5187, 7, 315, 1006, 199, 3, 3322, 372, 1338, 334, 1589, 2656, 28179, 1414, 16685, 795, 370, 372, 199, 3, 3322, 283, 5187, 7, 3140, 402, 2951, 23188, 314, 901, 325, 2037, 647, 9, 199, 3, 259, 378, 14, 21, 14, 17, 446, 5120, 1233, 367, 29877, 1068, 2917, 27, 3483, 1919, 8297, 199, 3, 3322, 370, 8486, 1536, 24325, 2382, 10677, 2793, 1133, 1172, 747, 14, 12207, 199, 3, 3322, 334, 69, 14, 71, 14, 10444, 9, 503, 2449, 641, 2838, 14, 29789, 7303, 6317, 1973, 67, 199, 3, 3322, 15212, 5363, 199, 3, 259, 378, 14, 21, 14, 16, 446, 2896, 314, 3261, 1561, 21864, 370, 2656, 3718, 370, 627, 1786, 551, 1064, 10, 27, 199, 3, 3322, 3483, 12120, 63, 422, 7303, 6326, 1847, 551, 1064, 63, 422, 342, 282, 5726, 199, 3, 3322, 3261, 334, 10274, 2656, 63, 422, 342, 315, 4136, 5459, 9, 1553, 675, 28179, 342, 199, 3, 3322, 3140, 27, 9243, 314, 4747, 708, 63, 422, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
anjuncc/portia
slyd/slyd/splash/css_utils.py
9
1730
import re import urllib from scrapy.utils.url import urljoin_rfc from six.moves.urllib_parse import urlparse CSS_IMPORT = re.compile(r'''@import\s*["']([^"']+)["']''') CSS_URL = re.compile(r'''\burl\(("[^"]+"|'[^']+'|[^"')][^)]+)\)''') BAD_CSS = re.compile(r'''(-moz-binding|expression\s*\(|javascript\s*:)''', re.I) def wrap_url(url, tabid, base=None): url = url.strip() referer = None if base: referer = urlparse(base.strip()).netloc url = urljoin_rfc(base, url) parsed = urlparse(url) referer = referer or parsed.netloc if parsed.scheme == 'data': return url # TODO: process CSS inside data: urls if parsed.scheme not in ('http', 'https', 'ftp'): return 'data:text/plain,invalid_scheme' return "/proxy?" + urllib.urlencode({ "url": url, "referer": referer, "tabid": tabid }) def process_css(css_source, tabid, base_uri): """ Wraps urls in css source. >>> url = 'http://scrapinghub.com/style.css' >>> process_css('@import "{}"'.format(url), 0, url) # doctest: +ELLIPSIS '@import "/proxy?..."' """ def _absolutize_css_import(match): return '@import "{}"'.format(wrap_url(match.group(1), tabid, base_uri).replace('"', '%22')) def _absolutize_css_url(match): url = match.group(1).strip("\"'") return 'url("{}")'.format(wrap_url(url, tabid, base_uri).replace('"', '%22')) css_source = CSS_IMPORT.sub(_absolutize_css_import, css_source) css_source = CSS_URL.sub(_absolutize_css_url, css_source) css_source = BAD_CSS.sub('portia-blocked', css_source) return css_source
bsd-3-clause
[ 646, 295, 199, 646, 4011, 199, 504, 18918, 14, 1208, 14, 633, 492, 20818, 63, 8973, 199, 504, 3816, 14, 4912, 14, 4078, 63, 1122, 492, 7097, 421, 199, 14391, 63, 17576, 275, 295, 14, 2014, 8, 82, 2344, 32, 646, 60, 83, 10, 905, 418, 7059, 2, 418, 8771, 905, 418, 12310, 199, 14391, 63, 2632, 275, 295, 14, 2014, 8, 82, 891, 1154, 66, 633, 60, 9313, 25153, 5207, 92, 16122, 418, 4786, 23629, 9008, 1527, 62, 1874, 13439, 9, 12310, 199, 9439, 63, 14391, 275, 295, 14, 2014, 8, 82, 2344, 2801, 23120, 13, 9140, 92, 5599, 60, 83, 7590, 8, 92, 9554, 60, 83, 19429, 9, 18108, 295, 14, 41, 9, 421, 199, 318, 4816, 63, 633, 8, 633, 12, 5174, 344, 12, 1300, 29, 403, 304, 272, 1166, 275, 1166, 14, 1913, 342, 272, 25104, 275, 488, 272, 340, 1300, 26, 267, 25104, 275, 7097, 8, 1095, 14, 1913, 8801, 12652, 267, 1166, 275, 20818, 63, 8973, 8, 1095, 12, 1166, 9, 272, 4565, 275, 7097, 8, 633, 9, 272, 25104, 275, 25104, 503, 4565, 14, 12652, 339, 340, 4565, 14, 5512, 508, 283, 576, 356, 267, 372, 1166, 221, 327, 3254, 26, 2112, 15750, 6272, 666, 26, 8187, 272, 340, 4565, 14, 5512, 440, 315, 661, 1014, 297, 283, 2859, 297, 283, 8915, 735, 267, 372, 283, 576, 26, 505, 15, 6104, 12, 3197, 63, 5512, 7, 339, 372, 3286, 3280, 13472, 435, 4011, 14, 10738, 2561, 267, 298, 633, 582, 1166, 12, 267, 298, 20996, 582, 25104, 12, 267, 298, 2902, 344, 582, 5174, 344, 272, 3828, 421, 199, 318, 2112, 63, 3919, 8, 3919, 63, 1365, 12, 5174, 344, 12, 1300, 63, 2302, 304, 272, 408, 272, 644, 8146, 8187, 315, 11431, 1350, 14, 339, 1306, 1166, 275, 283, 1014, 921, 551, 1330, 316, 16560, 14, 957, 15, 2487, 14, 3919, 7, 272, 1306, 2112, 63, 3919, 16591, 646, 28168, 1370, 908, 8, 633, 395, 378, 12, 1166, 9, 327, 8868, 26, 435, 21677, 272, 10267, 646, 3286, 3280, 31, 1396, 4507, 272, 408, 272, 347, 485, 2101, 393, 935, 806, 63, 3919, 63, 646, 8, 1431, 304, 267, 372, 10267, 646, 28168, 1370, 908, 8, 3823, 63, 633, 8, 1431, 14, 923, 8, 17, 395, 5174, 344, 12, 6343, 1300, 63, 2302, 680, 1814, 20630, 1543, 1081, 1333, 339, 347, 485, 2101, 393, 935, 806, 63, 3919, 63, 633, 8, 1431, 304, 267, 1166, 275, 1336, 14, 923, 8, 17, 680, 1913, 480, 4451, 9859, 267, 372, 283, 633, 20794, 531, 1370, 908, 8, 3823, 63, 633, 8, 633, 12, 5174, 344, 12, 5644, 1300, 63, 2302, 680, 1814, 20630, 1543, 1081, 1333, 339, 11431, 63, 1365, 275, 15750, 63, 17576, 14, 954, 1547, 2101, 393, 935, 806, 63, 3919, 63, 646, 12, 11431, 63, 1365, 9, 272, 11431, 63, 1365, 275, 15750, 63, 2632, 14, 954, 1547, 2101, 393, 935, 806, 63, 3919, 63, 633, 12, 11431, 63, 1365, 9, 272, 11431, 63, 1365, 275, 699, 1554, 63, 14391, 14, 954, 360, 7314, 14037, 13, 17726, 297, 11431, 63, 1365, 9, 272, 372, 11431, 63, 1365, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 295, 199, 646, 4011, 199, 504, 18918, 14, 1208, 14, 633, 492, 20818, 63, 8973, 199, 504, 3816, 14, 4912, 14, 4078, 63, 1122, 492, 7097, 421, 199, 14391, 63, 17576, 275, 295, 14, 2014, 8, 82, 2344, 32, 646, 60, 83, 10, 905, 418, 7059, 2, 418, 8771, 905, 418, 12310, 199, 14391, 63, 2632, 275, 295, 14, 2014, 8, 82, 891, 1154, 66, 633, 60, 9313, 25153, 5207, 92, 16122, 418, 4786, 23629, 9008, 1527, 62, 1874, 13439, 9, 12310, 199, 9439, 63, 14391, 275, 295, 14, 2014, 8, 82, 2344, 2801, 23120, 13, 9140, 92, 5599, 60, 83, 7590, 8, 92, 9554, 60, 83, 19429, 9, 18108, 295, 14, 41, 9, 421, 199, 318, 4816, 63, 633, 8, 633, 12, 5174, 344, 12, 1300, 29, 403, 304, 272, 1166, 275, 1166, 14, 1913, 342, 272, 25104, 275, 488, 272, 340, 1300, 26, 267, 25104, 275, 7097, 8, 1095, 14, 1913, 8801, 12652, 267, 1166, 275, 20818, 63, 8973, 8, 1095, 12, 1166, 9, 272, 4565, 275, 7097, 8, 633, 9, 272, 25104, 275, 25104, 503, 4565, 14, 12652, 339, 340, 4565, 14, 5512, 508, 283, 576, 356, 267, 372, 1166, 221, 327, 3254, 26, 2112, 15750, 6272, 666, 26, 8187, 272, 340, 4565, 14, 5512, 440, 315, 661, 1014, 297, 283, 2859, 297, 283, 8915, 735, 267, 372, 283, 576, 26, 505, 15, 6104, 12, 3197, 63, 5512, 7, 339, 372, 3286, 3280, 13472, 435, 4011, 14, 10738, 2561, 267, 298, 633, 582, 1166, 12, 267, 298, 20996, 582, 25104, 12, 267, 298, 2902, 344, 582, 5174, 344, 272, 3828, 421, 199, 318, 2112, 63, 3919, 8, 3919, 63, 1365, 12, 5174, 344, 12, 1300, 63, 2302, 304, 272, 408, 272, 644, 8146, 8187, 315, 11431, 1350, 14, 339, 1306, 1166, 275, 283, 1014, 921, 551, 1330, 316, 16560, 14, 957, 15, 2487, 14, 3919, 7, 272, 1306, 2112, 63, 3919, 16591, 646, 28168, 1370, 908, 8, 633, 395, 378, 12, 1166, 9, 327, 8868, 26, 435, 21677, 272, 10267, 646, 3286, 3280, 31, 1396, 4507, 272, 408, 272, 347, 485, 2101, 393, 935, 806, 63, 3919, 63, 646, 8, 1431, 304, 267, 372, 10267, 646, 28168, 1370, 908, 8, 3823, 63, 633, 8, 1431, 14, 923, 8, 17, 395, 5174, 344, 12, 6343, 1300, 63, 2302, 680, 1814, 20630, 1543, 1081, 1333, 339, 347, 485, 2101, 393, 935, 806, 63, 3919, 63, 633, 8, 1431, 304, 267, 1166, 275, 1336, 14, 923, 8, 17, 680, 1913, 480, 4451, 9859, 267, 372, 283, 633, 20794, 531, 1370, 908, 8, 3823, 63, 633, 8, 633, 12, 5174, 344, 12, 5644, 1300, 63, 2302, 680, 1814, 20630, 1543, 1081, 1333, 339, 11431, 63, 1365, 275, 15750, 63, 17576, 14, 954, 1547, 2101, 393, 935, 806, 63, 3919, 63, 646, 12, 11431, 63, 1365, 9, 272, 11431, 63, 1365, 275, 15750, 63, 2632, 14, 954, 1547, 2101, 393, 935, 806, 63, 3919, 63, 633, 12, 11431, 63, 1365, 9, 272, 11431, 63, 1365, 275, 699, 1554, 63, 14391, 14, 954, 360, 7314, 14037, 13, 17726, 297, 11431, 63, 1365, 9, 272, 372, 11431, 63, 1365, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
segwitcoin/SegwitCoin
test/functional/test_framework/mininode.py
7
57589
#!/usr/bin/env python3 # Copyright (c) 2010 ArtForz -- public domain half-a-node # Copyright (c) 2012 Jeff Garzik # Copyright (c) 2010-2016 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Bitcoin P2P network half-a-node. This python code was modified from ArtForz' public domain half-a-node, as found in the mini-node branch of http://github.com/jgarzik/pynode. NodeConn: an object which manages p2p connectivity to a bitcoin node NodeConnCB: a base class that describes the interface for receiving callbacks with network messages from a NodeConn CBlock, CTransaction, CBlockHeader, CTxIn, CTxOut, etc....: data structures that should map to corresponding structures in bitcoin/primitives msg_block, msg_tx, msg_headers, etc.: data structures that represent network messages ser_*, deser_*: functions that handle serialization/deserialization """ import asyncore from codecs import encode from collections import defaultdict import copy import hashlib from io import BytesIO import logging import random import socket import struct import sys import time from threading import RLock, Thread from test_framework.siphash import siphash256 from test_framework.util import hex_str_to_bytes, bytes_to_hex_str BIP0031_VERSION = 60000 MY_VERSION = 70014 # past bip-31 for ping/pong MY_SUBVERSION = b"/python-mininode-tester:0.0.3/" MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37) MAX_INV_SZ = 50000 MAX_BLOCK_BASE_SIZE = 1000000 COIN = 100000000 # 1 btc in satoshis NODE_NETWORK = (1 << 0) NODE_GETUTXO = (1 << 1) NODE_BLOOM = (1 << 2) NODE_WITNESS = (1 << 3) logger = logging.getLogger("TestFramework.mininode") # Keep our own socket map for asyncore, so that we can track disconnects # ourselves (to workaround an issue with closing an asyncore socket when # using select) mininode_socket_map = dict() # One lock for synchronizing all data access between the networking thread (see # NetworkThread below) and the thread running the test logic. For simplicity, # NodeConn acquires this lock whenever delivering a message to a NodeConnCB, # and whenever adding anything to the send buffer (in send_message()). This # lock should be acquired in the thread running the test logic to synchronize # access to any data shared with the NodeConnCB or NodeConn. mininode_lock = RLock() # Serialization/deserialization tools def sha256(s): return hashlib.new('sha256', s).digest() def ripemd160(s): return hashlib.new('ripemd160', s).digest() def hash256(s): return sha256(sha256(s)) def ser_compact_size(l): r = b"" if l < 253: r = struct.pack("B", l) elif l < 0x10000: r = struct.pack("<BH", 253, l) elif l < 0x100000000: r = struct.pack("<BI", 254, l) else: r = struct.pack("<BQ", 255, l) return r def deser_compact_size(f): nit = struct.unpack("<B", f.read(1))[0] if nit == 253: nit = struct.unpack("<H", f.read(2))[0] elif nit == 254: nit = struct.unpack("<I", f.read(4))[0] elif nit == 255: nit = struct.unpack("<Q", f.read(8))[0] return nit def deser_string(f): nit = deser_compact_size(f) return f.read(nit) def ser_string(s): return ser_compact_size(len(s)) + s def deser_uint256(f): r = 0 for i in range(8): t = struct.unpack("<I", f.read(4))[0] r += t << (i * 32) return r def ser_uint256(u): rs = b"" for i in range(8): rs += struct.pack("<I", u & 0xFFFFFFFF) u >>= 32 return rs def uint256_from_str(s): r = 0 t = struct.unpack("<IIIIIIII", s[:32]) for i in range(8): r += t[i] << (i * 32) return r def uint256_from_compact(c): nbytes = (c >> 24) & 0xFF v = (c & 0xFFFFFF) << (8 * (nbytes - 3)) return v def deser_vector(f, c): nit = deser_compact_size(f) r = [] for i in range(nit): t = c() t.deserialize(f) r.append(t) return r # ser_function_name: Allow for an alternate serialization function on the # entries in the vector (we use this for serializing the vector of transactions # for a witness block). def ser_vector(l, ser_function_name=None): r = ser_compact_size(len(l)) for i in l: if ser_function_name: r += getattr(i, ser_function_name)() else: r += i.serialize() return r def deser_uint256_vector(f): nit = deser_compact_size(f) r = [] for i in range(nit): t = deser_uint256(f) r.append(t) return r def ser_uint256_vector(l): r = ser_compact_size(len(l)) for i in l: r += ser_uint256(i) return r def deser_string_vector(f): nit = deser_compact_size(f) r = [] for i in range(nit): t = deser_string(f) r.append(t) return r def ser_string_vector(l): r = ser_compact_size(len(l)) for sv in l: r += ser_string(sv) return r def deser_int_vector(f): nit = deser_compact_size(f) r = [] for i in range(nit): t = struct.unpack("<i", f.read(4))[0] r.append(t) return r def ser_int_vector(l): r = ser_compact_size(len(l)) for i in l: r += struct.pack("<i", i) return r # Deserialize from a hex string representation (eg from RPC) def FromHex(obj, hex_string): obj.deserialize(BytesIO(hex_str_to_bytes(hex_string))) return obj # Convert a binary-serializable object to hex (eg for submission via RPC) def ToHex(obj): return bytes_to_hex_str(obj.serialize()) # Objects that map to bitcoind objects, which can be serialized/deserialized class CAddress(object): def __init__(self): self.nServices = 1 self.pchReserved = b"\x00" * 10 + b"\xff" * 2 self.ip = "0.0.0.0" self.port = 0 def deserialize(self, f): self.nServices = struct.unpack("<Q", f.read(8))[0] self.pchReserved = f.read(12) self.ip = socket.inet_ntoa(f.read(4)) self.port = struct.unpack(">H", f.read(2))[0] def serialize(self): r = b"" r += struct.pack("<Q", self.nServices) r += self.pchReserved r += socket.inet_aton(self.ip) r += struct.pack(">H", self.port) return r def __repr__(self): return "CAddress(nServices=%i ip=%s port=%i)" % (self.nServices, self.ip, self.port) MSG_WITNESS_FLAG = 1<<30 class CInv(object): typemap = { 0: "Error", 1: "TX", 2: "Block", 1|MSG_WITNESS_FLAG: "WitnessTx", 2|MSG_WITNESS_FLAG : "WitnessBlock", 4: "CompactBlock" } def __init__(self, t=0, h=0): self.type = t self.hash = h def deserialize(self, f): self.type = struct.unpack("<i", f.read(4))[0] self.hash = deser_uint256(f) def serialize(self): r = b"" r += struct.pack("<i", self.type) r += ser_uint256(self.hash) return r def __repr__(self): return "CInv(type=%s hash=%064x)" \ % (self.typemap[self.type], self.hash) class CBlockLocator(object): def __init__(self): self.nVersion = MY_VERSION self.vHave = [] def deserialize(self, f): self.nVersion = struct.unpack("<i", f.read(4))[0] self.vHave = deser_uint256_vector(f) def serialize(self): r = b"" r += struct.pack("<i", self.nVersion) r += ser_uint256_vector(self.vHave) return r def __repr__(self): return "CBlockLocator(nVersion=%i vHave=%s)" \ % (self.nVersion, repr(self.vHave)) class COutPoint(object): def __init__(self, hash=0, n=0): self.hash = hash self.n = n def deserialize(self, f): self.hash = deser_uint256(f) self.n = struct.unpack("<I", f.read(4))[0] def serialize(self): r = b"" r += ser_uint256(self.hash) r += struct.pack("<I", self.n) return r def __repr__(self): return "COutPoint(hash=%064x n=%i)" % (self.hash, self.n) class CTxIn(object): def __init__(self, outpoint=None, scriptSig=b"", nSequence=0): if outpoint is None: self.prevout = COutPoint() else: self.prevout = outpoint self.scriptSig = scriptSig self.nSequence = nSequence def deserialize(self, f): self.prevout = COutPoint() self.prevout.deserialize(f) self.scriptSig = deser_string(f) self.nSequence = struct.unpack("<I", f.read(4))[0] def serialize(self): r = b"" r += self.prevout.serialize() r += ser_string(self.scriptSig) r += struct.pack("<I", self.nSequence) return r def __repr__(self): return "CTxIn(prevout=%s scriptSig=%s nSequence=%i)" \ % (repr(self.prevout), bytes_to_hex_str(self.scriptSig), self.nSequence) class CTxOut(object): def __init__(self, nValue=0, scriptPubKey=b""): self.nValue = nValue self.scriptPubKey = scriptPubKey def deserialize(self, f): self.nValue = struct.unpack("<q", f.read(8))[0] self.scriptPubKey = deser_string(f) def serialize(self): r = b"" r += struct.pack("<q", self.nValue) r += ser_string(self.scriptPubKey) return r def __repr__(self): return "CTxOut(nValue=%i.%08i scriptPubKey=%s)" \ % (self.nValue // COIN, self.nValue % COIN, bytes_to_hex_str(self.scriptPubKey)) class CScriptWitness(object): def __init__(self): # stack is a vector of strings self.stack = [] def __repr__(self): return "CScriptWitness(%s)" % \ (",".join([bytes_to_hex_str(x) for x in self.stack])) def is_null(self): if self.stack: return False return True class CTxInWitness(object): def __init__(self): self.scriptWitness = CScriptWitness() def deserialize(self, f): self.scriptWitness.stack = deser_string_vector(f) def serialize(self): return ser_string_vector(self.scriptWitness.stack) def __repr__(self): return repr(self.scriptWitness) def is_null(self): return self.scriptWitness.is_null() class CTxWitness(object): def __init__(self): self.vtxinwit = [] def deserialize(self, f): for i in range(len(self.vtxinwit)): self.vtxinwit[i].deserialize(f) def serialize(self): r = b"" # This is different than the usual vector serialization -- # we omit the length of the vector, which is required to be # the same length as the transaction's vin vector. for x in self.vtxinwit: r += x.serialize() return r def __repr__(self): return "CTxWitness(%s)" % \ (';'.join([repr(x) for x in self.vtxinwit])) def is_null(self): for x in self.vtxinwit: if not x.is_null(): return False return True class CTransaction(object): def __init__(self, tx=None): if tx is None: self.nVersion = 1 self.vin = [] self.vout = [] self.wit = CTxWitness() self.nLockTime = 0 self.sha256 = None self.hash = None else: self.nVersion = tx.nVersion self.vin = copy.deepcopy(tx.vin) self.vout = copy.deepcopy(tx.vout) self.nLockTime = tx.nLockTime self.sha256 = tx.sha256 self.hash = tx.hash self.wit = copy.deepcopy(tx.wit) def deserialize(self, f): self.nVersion = struct.unpack("<i", f.read(4))[0] self.vin = deser_vector(f, CTxIn) flags = 0 if len(self.vin) == 0: flags = struct.unpack("<B", f.read(1))[0] # Not sure why flags can't be zero, but this # matches the implementation in bitcoind if (flags != 0): self.vin = deser_vector(f, CTxIn) self.vout = deser_vector(f, CTxOut) else: self.vout = deser_vector(f, CTxOut) if flags != 0: self.wit.vtxinwit = [CTxInWitness() for i in range(len(self.vin))] self.wit.deserialize(f) self.nLockTime = struct.unpack("<I", f.read(4))[0] self.sha256 = None self.hash = None def serialize_without_witness(self): r = b"" r += struct.pack("<i", self.nVersion) r += ser_vector(self.vin) r += ser_vector(self.vout) r += struct.pack("<I", self.nLockTime) return r # Only serialize with witness when explicitly called for def serialize_with_witness(self): flags = 0 if not self.wit.is_null(): flags |= 1 r = b"" r += struct.pack("<i", self.nVersion) if flags: dummy = [] r += ser_vector(dummy) r += struct.pack("<B", flags) r += ser_vector(self.vin) r += ser_vector(self.vout) if flags & 1: if (len(self.wit.vtxinwit) != len(self.vin)): # vtxinwit must have the same length as vin self.wit.vtxinwit = self.wit.vtxinwit[:len(self.vin)] for i in range(len(self.wit.vtxinwit), len(self.vin)): self.wit.vtxinwit.append(CTxInWitness()) r += self.wit.serialize() r += struct.pack("<I", self.nLockTime) return r # Regular serialization is without witness -- must explicitly # call serialize_with_witness to include witness data. def serialize(self): return self.serialize_without_witness() # Recalculate the txid (transaction hash without witness) def rehash(self): self.sha256 = None self.calc_sha256() # We will only cache the serialization without witness in # self.sha256 and self.hash -- those are expected to be the txid. def calc_sha256(self, with_witness=False): if with_witness: # Don't cache the result, just return it return uint256_from_str(hash256(self.serialize_with_witness())) if self.sha256 is None: self.sha256 = uint256_from_str(hash256(self.serialize_without_witness())) self.hash = encode(hash256(self.serialize())[::-1], 'hex_codec').decode('ascii') def is_valid(self): self.calc_sha256() for tout in self.vout: if tout.nValue < 0 or tout.nValue > 21000000 * COIN: return False return True def __repr__(self): return "CTransaction(nVersion=%i vin=%s vout=%s wit=%s nLockTime=%i)" \ % (self.nVersion, repr(self.vin), repr(self.vout), repr(self.wit), self.nLockTime) class CBlockHeader(object): def __init__(self, header=None): if header is None: self.set_null() else: self.nVersion = header.nVersion self.hashPrevBlock = header.hashPrevBlock self.hashMerkleRoot = header.hashMerkleRoot self.nTime = header.nTime self.nBits = header.nBits self.nNonce = header.nNonce self.sha256 = header.sha256 self.hash = header.hash self.calc_sha256() def set_null(self): self.nVersion = 1 self.hashPrevBlock = 0 self.hashMerkleRoot = 0 self.nTime = 0 self.nBits = 0 self.nNonce = 0 self.sha256 = None self.hash = None def deserialize(self, f): self.nVersion = struct.unpack("<i", f.read(4))[0] self.hashPrevBlock = deser_uint256(f) self.hashMerkleRoot = deser_uint256(f) self.nTime = struct.unpack("<I", f.read(4))[0] self.nBits = struct.unpack("<I", f.read(4))[0] self.nNonce = struct.unpack("<I", f.read(4))[0] self.sha256 = None self.hash = None def serialize(self): r = b"" r += struct.pack("<i", self.nVersion) r += ser_uint256(self.hashPrevBlock) r += ser_uint256(self.hashMerkleRoot) r += struct.pack("<I", self.nTime) r += struct.pack("<I", self.nBits) r += struct.pack("<I", self.nNonce) return r def calc_sha256(self): if self.sha256 is None: r = b"" r += struct.pack("<i", self.nVersion) r += ser_uint256(self.hashPrevBlock) r += ser_uint256(self.hashMerkleRoot) r += struct.pack("<I", self.nTime) r += struct.pack("<I", self.nBits) r += struct.pack("<I", self.nNonce) self.sha256 = uint256_from_str(hash256(r)) self.hash = encode(hash256(r)[::-1], 'hex_codec').decode('ascii') def rehash(self): self.sha256 = None self.calc_sha256() return self.sha256 def __repr__(self): return "CBlockHeader(nVersion=%i hashPrevBlock=%064x hashMerkleRoot=%064x nTime=%s nBits=%08x nNonce=%08x)" \ % (self.nVersion, self.hashPrevBlock, self.hashMerkleRoot, time.ctime(self.nTime), self.nBits, self.nNonce) class CBlock(CBlockHeader): def __init__(self, header=None): super(CBlock, self).__init__(header) self.vtx = [] def deserialize(self, f): super(CBlock, self).deserialize(f) self.vtx = deser_vector(f, CTransaction) def serialize(self, with_witness=False): r = b"" r += super(CBlock, self).serialize() if with_witness: r += ser_vector(self.vtx, "serialize_with_witness") else: r += ser_vector(self.vtx) return r # Calculate the merkle root given a vector of transaction hashes @classmethod def get_merkle_root(cls, hashes): while len(hashes) > 1: newhashes = [] for i in range(0, len(hashes), 2): i2 = min(i+1, len(hashes)-1) newhashes.append(hash256(hashes[i] + hashes[i2])) hashes = newhashes return uint256_from_str(hashes[0]) def calc_merkle_root(self): hashes = [] for tx in self.vtx: tx.calc_sha256() hashes.append(ser_uint256(tx.sha256)) return self.get_merkle_root(hashes) def calc_witness_merkle_root(self): # For witness root purposes, the hash of the # coinbase, with witness, is defined to be 0...0 hashes = [ser_uint256(0)] for tx in self.vtx[1:]: # Calculate the hashes with witness data hashes.append(ser_uint256(tx.calc_sha256(True))) return self.get_merkle_root(hashes) def is_valid(self): self.calc_sha256() target = uint256_from_compact(self.nBits) if self.sha256 > target: return False for tx in self.vtx: if not tx.is_valid(): return False if self.calc_merkle_root() != self.hashMerkleRoot: return False return True def solve(self): self.rehash() target = uint256_from_compact(self.nBits) while self.sha256 > target: self.nNonce += 1 self.rehash() def __repr__(self): return "CBlock(nVersion=%i hashPrevBlock=%064x hashMerkleRoot=%064x nTime=%s nBits=%08x nNonce=%08x vtx=%s)" \ % (self.nVersion, self.hashPrevBlock, self.hashMerkleRoot, time.ctime(self.nTime), self.nBits, self.nNonce, repr(self.vtx)) class CUnsignedAlert(object): def __init__(self): self.nVersion = 1 self.nRelayUntil = 0 self.nExpiration = 0 self.nID = 0 self.nCancel = 0 self.setCancel = [] self.nMinVer = 0 self.nMaxVer = 0 self.setSubVer = [] self.nPriority = 0 self.strComment = b"" self.strStatusBar = b"" self.strReserved = b"" def deserialize(self, f): self.nVersion = struct.unpack("<i", f.read(4))[0] self.nRelayUntil = struct.unpack("<q", f.read(8))[0] self.nExpiration = struct.unpack("<q", f.read(8))[0] self.nID = struct.unpack("<i", f.read(4))[0] self.nCancel = struct.unpack("<i", f.read(4))[0] self.setCancel = deser_int_vector(f) self.nMinVer = struct.unpack("<i", f.read(4))[0] self.nMaxVer = struct.unpack("<i", f.read(4))[0] self.setSubVer = deser_string_vector(f) self.nPriority = struct.unpack("<i", f.read(4))[0] self.strComment = deser_string(f) self.strStatusBar = deser_string(f) self.strReserved = deser_string(f) def serialize(self): r = b"" r += struct.pack("<i", self.nVersion) r += struct.pack("<q", self.nRelayUntil) r += struct.pack("<q", self.nExpiration) r += struct.pack("<i", self.nID) r += struct.pack("<i", self.nCancel) r += ser_int_vector(self.setCancel) r += struct.pack("<i", self.nMinVer) r += struct.pack("<i", self.nMaxVer) r += ser_string_vector(self.setSubVer) r += struct.pack("<i", self.nPriority) r += ser_string(self.strComment) r += ser_string(self.strStatusBar) r += ser_string(self.strReserved) return r def __repr__(self): return "CUnsignedAlert(nVersion %d, nRelayUntil %d, nExpiration %d, nID %d, nCancel %d, nMinVer %d, nMaxVer %d, nPriority %d, strComment %s, strStatusBar %s, strReserved %s)" \ % (self.nVersion, self.nRelayUntil, self.nExpiration, self.nID, self.nCancel, self.nMinVer, self.nMaxVer, self.nPriority, self.strComment, self.strStatusBar, self.strReserved) class CAlert(object): def __init__(self): self.vchMsg = b"" self.vchSig = b"" def deserialize(self, f): self.vchMsg = deser_string(f) self.vchSig = deser_string(f) def serialize(self): r = b"" r += ser_string(self.vchMsg) r += ser_string(self.vchSig) return r def __repr__(self): return "CAlert(vchMsg.sz %d, vchSig.sz %d)" \ % (len(self.vchMsg), len(self.vchSig)) class PrefilledTransaction(object): def __init__(self, index=0, tx = None): self.index = index self.tx = tx def deserialize(self, f): self.index = deser_compact_size(f) self.tx = CTransaction() self.tx.deserialize(f) def serialize(self, with_witness=False): r = b"" r += ser_compact_size(self.index) if with_witness: r += self.tx.serialize_with_witness() else: r += self.tx.serialize_without_witness() return r def serialize_with_witness(self): return self.serialize(with_witness=True) def __repr__(self): return "PrefilledTransaction(index=%d, tx=%s)" % (self.index, repr(self.tx)) # This is what we send on the wire, in a cmpctblock message. class P2PHeaderAndShortIDs(object): def __init__(self): self.header = CBlockHeader() self.nonce = 0 self.shortids_length = 0 self.shortids = [] self.prefilled_txn_length = 0 self.prefilled_txn = [] def deserialize(self, f): self.header.deserialize(f) self.nonce = struct.unpack("<Q", f.read(8))[0] self.shortids_length = deser_compact_size(f) for i in range(self.shortids_length): # shortids are defined to be 6 bytes in the spec, so append # two zero bytes and read it in as an 8-byte number self.shortids.append(struct.unpack("<Q", f.read(6) + b'\x00\x00')[0]) self.prefilled_txn = deser_vector(f, PrefilledTransaction) self.prefilled_txn_length = len(self.prefilled_txn) # When using version 2 compact blocks, we must serialize with_witness. def serialize(self, with_witness=False): r = b"" r += self.header.serialize() r += struct.pack("<Q", self.nonce) r += ser_compact_size(self.shortids_length) for x in self.shortids: # We only want the first 6 bytes r += struct.pack("<Q", x)[0:6] if with_witness: r += ser_vector(self.prefilled_txn, "serialize_with_witness") else: r += ser_vector(self.prefilled_txn) return r def __repr__(self): return "P2PHeaderAndShortIDs(header=%s, nonce=%d, shortids_length=%d, shortids=%s, prefilled_txn_length=%d, prefilledtxn=%s" % (repr(self.header), self.nonce, self.shortids_length, repr(self.shortids), self.prefilled_txn_length, repr(self.prefilled_txn)) # P2P version of the above that will use witness serialization (for compact # block version 2) class P2PHeaderAndShortWitnessIDs(P2PHeaderAndShortIDs): def serialize(self): return super(P2PHeaderAndShortWitnessIDs, self).serialize(with_witness=True) # Calculate the BIP 152-compact blocks shortid for a given transaction hash def calculate_shortid(k0, k1, tx_hash): expected_shortid = siphash256(k0, k1, tx_hash) expected_shortid &= 0x0000ffffffffffff return expected_shortid # This version gets rid of the array lengths, and reinterprets the differential # encoding into indices that can be used for lookup. class HeaderAndShortIDs(object): def __init__(self, p2pheaders_and_shortids = None): self.header = CBlockHeader() self.nonce = 0 self.shortids = [] self.prefilled_txn = [] self.use_witness = False if p2pheaders_and_shortids != None: self.header = p2pheaders_and_shortids.header self.nonce = p2pheaders_and_shortids.nonce self.shortids = p2pheaders_and_shortids.shortids last_index = -1 for x in p2pheaders_and_shortids.prefilled_txn: self.prefilled_txn.append(PrefilledTransaction(x.index + last_index + 1, x.tx)) last_index = self.prefilled_txn[-1].index def to_p2p(self): if self.use_witness: ret = P2PHeaderAndShortWitnessIDs() else: ret = P2PHeaderAndShortIDs() ret.header = self.header ret.nonce = self.nonce ret.shortids_length = len(self.shortids) ret.shortids = self.shortids ret.prefilled_txn_length = len(self.prefilled_txn) ret.prefilled_txn = [] last_index = -1 for x in self.prefilled_txn: ret.prefilled_txn.append(PrefilledTransaction(x.index - last_index - 1, x.tx)) last_index = x.index return ret def get_siphash_keys(self): header_nonce = self.header.serialize() header_nonce += struct.pack("<Q", self.nonce) hash_header_nonce_as_str = sha256(header_nonce) key0 = struct.unpack("<Q", hash_header_nonce_as_str[0:8])[0] key1 = struct.unpack("<Q", hash_header_nonce_as_str[8:16])[0] return [ key0, key1 ] # Version 2 compact blocks use wtxid in shortids (rather than txid) def initialize_from_block(self, block, nonce=0, prefill_list = [0], use_witness = False): self.header = CBlockHeader(block) self.nonce = nonce self.prefilled_txn = [ PrefilledTransaction(i, block.vtx[i]) for i in prefill_list ] self.shortids = [] self.use_witness = use_witness [k0, k1] = self.get_siphash_keys() for i in range(len(block.vtx)): if i not in prefill_list: tx_hash = block.vtx[i].sha256 if use_witness: tx_hash = block.vtx[i].calc_sha256(with_witness=True) self.shortids.append(calculate_shortid(k0, k1, tx_hash)) def __repr__(self): return "HeaderAndShortIDs(header=%s, nonce=%d, shortids=%s, prefilledtxn=%s" % (repr(self.header), self.nonce, repr(self.shortids), repr(self.prefilled_txn)) class BlockTransactionsRequest(object): def __init__(self, blockhash=0, indexes = None): self.blockhash = blockhash self.indexes = indexes if indexes != None else [] def deserialize(self, f): self.blockhash = deser_uint256(f) indexes_length = deser_compact_size(f) for i in range(indexes_length): self.indexes.append(deser_compact_size(f)) def serialize(self): r = b"" r += ser_uint256(self.blockhash) r += ser_compact_size(len(self.indexes)) for x in self.indexes: r += ser_compact_size(x) return r # helper to set the differentially encoded indexes from absolute ones def from_absolute(self, absolute_indexes): self.indexes = [] last_index = -1 for x in absolute_indexes: self.indexes.append(x-last_index-1) last_index = x def to_absolute(self): absolute_indexes = [] last_index = -1 for x in self.indexes: absolute_indexes.append(x+last_index+1) last_index = absolute_indexes[-1] return absolute_indexes def __repr__(self): return "BlockTransactionsRequest(hash=%064x indexes=%s)" % (self.blockhash, repr(self.indexes)) class BlockTransactions(object): def __init__(self, blockhash=0, transactions = None): self.blockhash = blockhash self.transactions = transactions if transactions != None else [] def deserialize(self, f): self.blockhash = deser_uint256(f) self.transactions = deser_vector(f, CTransaction) def serialize(self, with_witness=False): r = b"" r += ser_uint256(self.blockhash) if with_witness: r += ser_vector(self.transactions, "serialize_with_witness") else: r += ser_vector(self.transactions) return r def __repr__(self): return "BlockTransactions(hash=%064x transactions=%s)" % (self.blockhash, repr(self.transactions)) # Objects that correspond to messages on the wire class msg_version(object): command = b"version" def __init__(self): self.nVersion = MY_VERSION self.nServices = 1 self.nTime = int(time.time()) self.addrTo = CAddress() self.addrFrom = CAddress() self.nNonce = random.getrandbits(64) self.strSubVer = MY_SUBVERSION self.nStartingHeight = -1 self.nRelay = MY_RELAY def deserialize(self, f): self.nVersion = struct.unpack("<i", f.read(4))[0] if self.nVersion == 10300: self.nVersion = 300 self.nServices = struct.unpack("<Q", f.read(8))[0] self.nTime = struct.unpack("<q", f.read(8))[0] self.addrTo = CAddress() self.addrTo.deserialize(f) if self.nVersion >= 106: self.addrFrom = CAddress() self.addrFrom.deserialize(f) self.nNonce = struct.unpack("<Q", f.read(8))[0] self.strSubVer = deser_string(f) else: self.addrFrom = None self.nNonce = None self.strSubVer = None self.nStartingHeight = None if self.nVersion >= 209: self.nStartingHeight = struct.unpack("<i", f.read(4))[0] else: self.nStartingHeight = None if self.nVersion >= 70001: # Relay field is optional for version 70001 onwards try: self.nRelay = struct.unpack("<b", f.read(1))[0] except: self.nRelay = 0 else: self.nRelay = 0 def serialize(self): r = b"" r += struct.pack("<i", self.nVersion) r += struct.pack("<Q", self.nServices) r += struct.pack("<q", self.nTime) r += self.addrTo.serialize() r += self.addrFrom.serialize() r += struct.pack("<Q", self.nNonce) r += ser_string(self.strSubVer) r += struct.pack("<i", self.nStartingHeight) r += struct.pack("<b", self.nRelay) return r def __repr__(self): return 'msg_version(nVersion=%i nServices=%i nTime=%s addrTo=%s addrFrom=%s nNonce=0x%016X strSubVer=%s nStartingHeight=%i nRelay=%i)' \ % (self.nVersion, self.nServices, time.ctime(self.nTime), repr(self.addrTo), repr(self.addrFrom), self.nNonce, self.strSubVer, self.nStartingHeight, self.nRelay) class msg_verack(object): command = b"verack" def __init__(self): pass def deserialize(self, f): pass def serialize(self): return b"" def __repr__(self): return "msg_verack()" class msg_addr(object): command = b"addr" def __init__(self): self.addrs = [] def deserialize(self, f): self.addrs = deser_vector(f, CAddress) def serialize(self): return ser_vector(self.addrs) def __repr__(self): return "msg_addr(addrs=%s)" % (repr(self.addrs)) class msg_alert(object): command = b"alert" def __init__(self): self.alert = CAlert() def deserialize(self, f): self.alert = CAlert() self.alert.deserialize(f) def serialize(self): r = b"" r += self.alert.serialize() return r def __repr__(self): return "msg_alert(alert=%s)" % (repr(self.alert), ) class msg_inv(object): command = b"inv" def __init__(self, inv=None): if inv is None: self.inv = [] else: self.inv = inv def deserialize(self, f): self.inv = deser_vector(f, CInv) def serialize(self): return ser_vector(self.inv) def __repr__(self): return "msg_inv(inv=%s)" % (repr(self.inv)) class msg_getdata(object): command = b"getdata" def __init__(self, inv=None): self.inv = inv if inv != None else [] def deserialize(self, f): self.inv = deser_vector(f, CInv) def serialize(self): return ser_vector(self.inv) def __repr__(self): return "msg_getdata(inv=%s)" % (repr(self.inv)) class msg_getblocks(object): command = b"getblocks" def __init__(self): self.locator = CBlockLocator() self.hashstop = 0 def deserialize(self, f): self.locator = CBlockLocator() self.locator.deserialize(f) self.hashstop = deser_uint256(f) def serialize(self): r = b"" r += self.locator.serialize() r += ser_uint256(self.hashstop) return r def __repr__(self): return "msg_getblocks(locator=%s hashstop=%064x)" \ % (repr(self.locator), self.hashstop) class msg_tx(object): command = b"tx" def __init__(self, tx=CTransaction()): self.tx = tx def deserialize(self, f): self.tx.deserialize(f) def serialize(self): return self.tx.serialize_without_witness() def __repr__(self): return "msg_tx(tx=%s)" % (repr(self.tx)) class msg_witness_tx(msg_tx): def serialize(self): return self.tx.serialize_with_witness() class msg_block(object): command = b"block" def __init__(self, block=None): if block is None: self.block = CBlock() else: self.block = block def deserialize(self, f): self.block.deserialize(f) def serialize(self): return self.block.serialize() def __repr__(self): return "msg_block(block=%s)" % (repr(self.block)) # for cases where a user needs tighter control over what is sent over the wire # note that the user must supply the name of the command, and the data class msg_generic(object): def __init__(self, command, data=None): self.command = command self.data = data def serialize(self): return self.data def __repr__(self): return "msg_generic()" class msg_witness_block(msg_block): def serialize(self): r = self.block.serialize(with_witness=True) return r class msg_getaddr(object): command = b"getaddr" def __init__(self): pass def deserialize(self, f): pass def serialize(self): return b"" def __repr__(self): return "msg_getaddr()" class msg_ping_prebip31(object): command = b"ping" def __init__(self): pass def deserialize(self, f): pass def serialize(self): return b"" def __repr__(self): return "msg_ping() (pre-bip31)" class msg_ping(object): command = b"ping" def __init__(self, nonce=0): self.nonce = nonce def deserialize(self, f): self.nonce = struct.unpack("<Q", f.read(8))[0] def serialize(self): r = b"" r += struct.pack("<Q", self.nonce) return r def __repr__(self): return "msg_ping(nonce=%08x)" % self.nonce class msg_pong(object): command = b"pong" def __init__(self, nonce=0): self.nonce = nonce def deserialize(self, f): self.nonce = struct.unpack("<Q", f.read(8))[0] def serialize(self): r = b"" r += struct.pack("<Q", self.nonce) return r def __repr__(self): return "msg_pong(nonce=%08x)" % self.nonce class msg_mempool(object): command = b"mempool" def __init__(self): pass def deserialize(self, f): pass def serialize(self): return b"" def __repr__(self): return "msg_mempool()" class msg_sendheaders(object): command = b"sendheaders" def __init__(self): pass def deserialize(self, f): pass def serialize(self): return b"" def __repr__(self): return "msg_sendheaders()" # getheaders message has # number of entries # vector of hashes # hash_stop (hash of last desired block header, 0 to get as many as possible) class msg_getheaders(object): command = b"getheaders" def __init__(self): self.locator = CBlockLocator() self.hashstop = 0 def deserialize(self, f): self.locator = CBlockLocator() self.locator.deserialize(f) self.hashstop = deser_uint256(f) def serialize(self): r = b"" r += self.locator.serialize() r += ser_uint256(self.hashstop) return r def __repr__(self): return "msg_getheaders(locator=%s, stop=%064x)" \ % (repr(self.locator), self.hashstop) # headers message has # <count> <vector of block headers> class msg_headers(object): command = b"headers" def __init__(self): self.headers = [] def deserialize(self, f): # comment in bitcoind indicates these should be deserialized as blocks blocks = deser_vector(f, CBlock) for x in blocks: self.headers.append(CBlockHeader(x)) def serialize(self): blocks = [CBlock(x) for x in self.headers] return ser_vector(blocks) def __repr__(self): return "msg_headers(headers=%s)" % repr(self.headers) class msg_reject(object): command = b"reject" REJECT_MALFORMED = 1 def __init__(self): self.message = b"" self.code = 0 self.reason = b"" self.data = 0 def deserialize(self, f): self.message = deser_string(f) self.code = struct.unpack("<B", f.read(1))[0] self.reason = deser_string(f) if (self.code != self.REJECT_MALFORMED and (self.message == b"block" or self.message == b"tx")): self.data = deser_uint256(f) def serialize(self): r = ser_string(self.message) r += struct.pack("<B", self.code) r += ser_string(self.reason) if (self.code != self.REJECT_MALFORMED and (self.message == b"block" or self.message == b"tx")): r += ser_uint256(self.data) return r def __repr__(self): return "msg_reject: %s %d %s [%064x]" \ % (self.message, self.code, self.reason, self.data) # Helper function def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf')): if attempts == float('inf') and timeout == float('inf'): timeout = 60 attempt = 0 elapsed = 0 while attempt < attempts and elapsed < timeout: with mininode_lock: if predicate(): return True attempt += 1 elapsed += 0.05 time.sleep(0.05) return False class msg_feefilter(object): command = b"feefilter" def __init__(self, feerate=0): self.feerate = feerate def deserialize(self, f): self.feerate = struct.unpack("<Q", f.read(8))[0] def serialize(self): r = b"" r += struct.pack("<Q", self.feerate) return r def __repr__(self): return "msg_feefilter(feerate=%08x)" % self.feerate class msg_sendcmpct(object): command = b"sendcmpct" def __init__(self): self.announce = False self.version = 1 def deserialize(self, f): self.announce = struct.unpack("<?", f.read(1))[0] self.version = struct.unpack("<Q", f.read(8))[0] def serialize(self): r = b"" r += struct.pack("<?", self.announce) r += struct.pack("<Q", self.version) return r def __repr__(self): return "msg_sendcmpct(announce=%s, version=%lu)" % (self.announce, self.version) class msg_cmpctblock(object): command = b"cmpctblock" def __init__(self, header_and_shortids = None): self.header_and_shortids = header_and_shortids def deserialize(self, f): self.header_and_shortids = P2PHeaderAndShortIDs() self.header_and_shortids.deserialize(f) def serialize(self): r = b"" r += self.header_and_shortids.serialize() return r def __repr__(self): return "msg_cmpctblock(HeaderAndShortIDs=%s)" % repr(self.header_and_shortids) class msg_getblocktxn(object): command = b"getblocktxn" def __init__(self): self.block_txn_request = None def deserialize(self, f): self.block_txn_request = BlockTransactionsRequest() self.block_txn_request.deserialize(f) def serialize(self): r = b"" r += self.block_txn_request.serialize() return r def __repr__(self): return "msg_getblocktxn(block_txn_request=%s)" % (repr(self.block_txn_request)) class msg_blocktxn(object): command = b"blocktxn" def __init__(self): self.block_transactions = BlockTransactions() def deserialize(self, f): self.block_transactions.deserialize(f) def serialize(self): r = b"" r += self.block_transactions.serialize() return r def __repr__(self): return "msg_blocktxn(block_transactions=%s)" % (repr(self.block_transactions)) class msg_witness_blocktxn(msg_blocktxn): def serialize(self): r = b"" r += self.block_transactions.serialize(with_witness=True) return r class NodeConnCB(object): """Callback and helper functions for P2P connection to a bitcoind node. Individual testcases should subclass this and override the on_* methods if they want to alter message handling behaviour. """ def __init__(self): # Track whether we have a P2P connection open to the node self.connected = False self.connection = None # Track number of messages of each type received and the most recent # message of each type self.message_count = defaultdict(int) self.last_message = {} # A count of the number of ping messages we've sent to the node self.ping_counter = 1 # deliver_sleep_time is helpful for debugging race conditions in p2p # tests; it causes message delivery to sleep for the specified time # before acquiring the global lock and delivering the next message. self.deliver_sleep_time = None # Remember the services our peer has advertised self.peer_services = None # Message receiving methods def deliver(self, conn, message): """Receive message and dispatch message to appropriate callback. We keep a count of how many of each message type has been received and the most recent message of each type. Optionally waits for deliver_sleep_time before dispatching message. """ deliver_sleep = self.get_deliver_sleep_time() if deliver_sleep is not None: time.sleep(deliver_sleep) with mininode_lock: try: command = message.command.decode('ascii') self.message_count[command] += 1 self.last_message[command] = message getattr(self, 'on_' + command)(conn, message) except: print("ERROR delivering %s (%s)" % (repr(message), sys.exc_info()[0])) def set_deliver_sleep_time(self, value): with mininode_lock: self.deliver_sleep_time = value def get_deliver_sleep_time(self): with mininode_lock: return self.deliver_sleep_time # Callback methods. Can be overridden by subclasses in individual test # cases to provide custom message handling behaviour. def on_open(self, conn): self.connected = True def on_close(self, conn): self.connected = False self.connection = None def on_addr(self, conn, message): pass def on_alert(self, conn, message): pass def on_block(self, conn, message): pass def on_blocktxn(self, conn, message): pass def on_cmpctblock(self, conn, message): pass def on_feefilter(self, conn, message): pass def on_getaddr(self, conn, message): pass def on_getblocks(self, conn, message): pass def on_getblocktxn(self, conn, message): pass def on_getdata(self, conn, message): pass def on_getheaders(self, conn, message): pass def on_headers(self, conn, message): pass def on_mempool(self, conn): pass def on_pong(self, conn, message): pass def on_reject(self, conn, message): pass def on_sendcmpct(self, conn, message): pass def on_sendheaders(self, conn, message): pass def on_tx(self, conn, message): pass def on_inv(self, conn, message): want = msg_getdata() for i in message.inv: if i.type != 0: want.inv.append(i) if len(want.inv): conn.send_message(want) def on_ping(self, conn, message): if conn.ver_send > BIP0031_VERSION: conn.send_message(msg_pong(message.nonce)) def on_verack(self, conn, message): conn.ver_recv = conn.ver_send self.verack_received = True def on_version(self, conn, message): if message.nVersion >= 209: conn.send_message(msg_verack()) conn.ver_send = min(MY_VERSION, message.nVersion) if message.nVersion < 209: conn.ver_recv = conn.ver_send conn.nServices = message.nServices # Connection helper methods def add_connection(self, conn): self.connection = conn def wait_for_disconnect(self, timeout=60): test_function = lambda: not self.connected assert wait_until(test_function, timeout=timeout) # Message receiving helper methods def wait_for_block(self, blockhash, timeout=60): test_function = lambda: self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash assert wait_until(test_function, timeout=timeout) def wait_for_getdata(self, timeout=60): test_function = lambda: self.last_message.get("getdata") assert wait_until(test_function, timeout=timeout) def wait_for_getheaders(self, timeout=60): test_function = lambda: self.last_message.get("getheaders") assert wait_until(test_function, timeout=timeout) def wait_for_inv(self, expected_inv, timeout=60): """Waits for an INV message and checks that the first inv object in the message was as expected.""" if len(expected_inv) > 1: raise NotImplementedError("wait_for_inv() will only verify the first inv object") test_function = lambda: self.last_message.get("inv") and \ self.last_message["inv"].inv[0].type == expected_inv[0].type and \ self.last_message["inv"].inv[0].hash == expected_inv[0].hash assert wait_until(test_function, timeout=timeout) def wait_for_verack(self, timeout=60): test_function = lambda: self.message_count["verack"] assert wait_until(test_function, timeout=timeout) # Message sending helper functions def send_message(self, message): if self.connection: self.connection.send_message(message) else: logger.error("Cannot send message. No connection to node!") def send_and_ping(self, message): self.send_message(message) self.sync_with_ping() # Sync up with the node def sync_with_ping(self, timeout=60): self.send_message(msg_ping(nonce=self.ping_counter)) test_function = lambda: self.last_message.get("pong") and self.last_message["pong"].nonce == self.ping_counter assert wait_until(test_function, timeout=timeout) self.ping_counter += 1 return True # The actual NodeConn class # This class provides an interface for a p2p connection to a specified node class NodeConn(asyncore.dispatcher): messagemap = { b"version": msg_version, b"verack": msg_verack, b"addr": msg_addr, b"alert": msg_alert, b"inv": msg_inv, b"getdata": msg_getdata, b"getblocks": msg_getblocks, b"tx": msg_tx, b"block": msg_block, b"getaddr": msg_getaddr, b"ping": msg_ping, b"pong": msg_pong, b"headers": msg_headers, b"getheaders": msg_getheaders, b"reject": msg_reject, b"mempool": msg_mempool, b"feefilter": msg_feefilter, b"sendheaders": msg_sendheaders, b"sendcmpct": msg_sendcmpct, b"cmpctblock": msg_cmpctblock, b"getblocktxn": msg_getblocktxn, b"blocktxn": msg_blocktxn } MAGIC_BYTES = { "mainnet": b"\xf9\xbe\xb4\xd9", # mainnet "testnet3": b"\x0b\x11\x09\x07", # testnet3 "regtest": b"\xfa\xbf\xb5\xda", # regtest } def __init__(self, dstaddr, dstport, rpc, callback, net="regtest", services=NODE_NETWORK, send_version=True): asyncore.dispatcher.__init__(self, map=mininode_socket_map) self.dstaddr = dstaddr self.dstport = dstport self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.sendbuf = b"" self.recvbuf = b"" self.ver_send = 209 self.ver_recv = 209 self.last_sent = 0 self.state = "connecting" self.network = net self.cb = callback self.disconnect = False self.nServices = 0 if send_version: # stuff version msg into sendbuf vt = msg_version() vt.nServices = services vt.addrTo.ip = self.dstaddr vt.addrTo.port = self.dstport vt.addrFrom.ip = "0.0.0.0" vt.addrFrom.port = 0 self.send_message(vt, True) logger.info('Connecting to Bitcoin Node: %s:%d' % (self.dstaddr, self.dstport)) try: self.connect((dstaddr, dstport)) except: self.handle_close() self.rpc = rpc def handle_connect(self): if self.state != "connected": logger.debug("Connected & Listening: %s:%d" % (self.dstaddr, self.dstport)) self.state = "connected" self.cb.on_open(self) def handle_close(self): logger.debug("Closing connection to: %s:%d" % (self.dstaddr, self.dstport)) self.state = "closed" self.recvbuf = b"" self.sendbuf = b"" try: self.close() except: pass self.cb.on_close(self) def handle_read(self): try: t = self.recv(8192) if len(t) > 0: self.recvbuf += t self.got_data() except: pass def readable(self): return True def writable(self): with mininode_lock: pre_connection = self.state == "connecting" length = len(self.sendbuf) return (length > 0 or pre_connection) def handle_write(self): with mininode_lock: # asyncore does not expose socket connection, only the first read/write # event, thus we must check connection manually here to know when we # actually connect if self.state == "connecting": self.handle_connect() if not self.writable(): return try: sent = self.send(self.sendbuf) except: self.handle_close() return self.sendbuf = self.sendbuf[sent:] def got_data(self): try: while True: if len(self.recvbuf) < 4: return if self.recvbuf[:4] != self.MAGIC_BYTES[self.network]: raise ValueError("got garbage %s" % repr(self.recvbuf)) if self.ver_recv < 209: if len(self.recvbuf) < 4 + 12 + 4: return command = self.recvbuf[4:4+12].split(b"\x00", 1)[0] msglen = struct.unpack("<i", self.recvbuf[4+12:4+12+4])[0] checksum = None if len(self.recvbuf) < 4 + 12 + 4 + msglen: return msg = self.recvbuf[4+12+4:4+12+4+msglen] self.recvbuf = self.recvbuf[4+12+4+msglen:] else: if len(self.recvbuf) < 4 + 12 + 4 + 4: return command = self.recvbuf[4:4+12].split(b"\x00", 1)[0] msglen = struct.unpack("<i", self.recvbuf[4+12:4+12+4])[0] checksum = self.recvbuf[4+12+4:4+12+4+4] if len(self.recvbuf) < 4 + 12 + 4 + 4 + msglen: return msg = self.recvbuf[4+12+4+4:4+12+4+4+msglen] th = sha256(msg) h = sha256(th) if checksum != h[:4]: raise ValueError("got bad checksum " + repr(self.recvbuf)) self.recvbuf = self.recvbuf[4+12+4+4+msglen:] if command in self.messagemap: f = BytesIO(msg) t = self.messagemap[command]() t.deserialize(f) self.got_message(t) else: logger.warning("Received unknown command from %s:%d: '%s' %s" % (self.dstaddr, self.dstport, command, repr(msg))) except Exception as e: logger.exception('got_data:', repr(e)) def send_message(self, message, pushbuf=False): if self.state != "connected" and not pushbuf: raise IOError('Not connected, no pushbuf') self._log_message("send", message) command = message.command data = message.serialize() tmsg = self.MAGIC_BYTES[self.network] tmsg += command tmsg += b"\x00" * (12 - len(command)) tmsg += struct.pack("<I", len(data)) if self.ver_send >= 209: th = sha256(data) h = sha256(th) tmsg += h[:4] tmsg += data with mininode_lock: self.sendbuf += tmsg self.last_sent = time.time() def got_message(self, message): if message.command == b"version": if message.nVersion <= BIP0031_VERSION: self.messagemap[b'ping'] = msg_ping_prebip31 if self.last_sent + 30 * 60 < time.time(): self.send_message(self.messagemap[b'ping']()) self._log_message("receive", message) self.cb.deliver(self, message) def _log_message(self, direction, msg): if direction == "send": log_message = "Send message to " elif direction == "receive": log_message = "Received message from " log_message += "%s:%d: %s" % (self.dstaddr, self.dstport, repr(msg)[:500]) if len(log_message) > 500: log_message += "... (msg truncated)" logger.debug(log_message) def disconnect_node(self): self.disconnect = True class NetworkThread(Thread): def run(self): while mininode_socket_map: # We check for whether to disconnect outside of the asyncore # loop to workaround the behavior of asyncore when using # select disconnected = [] for fd, obj in mininode_socket_map.items(): if obj.disconnect: disconnected.append(obj) [ obj.handle_close() for obj in disconnected ] asyncore.loop(0.1, use_poll=True, map=mininode_socket_map, count=1) # An exception we can raise if we detect a potential disconnect # (p2p or rpc) before the test is complete class EarlyDisconnectError(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value)
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 3, 1898, 334, 67, 9, 7129, 1952, 84, 1858, 90, 1553, 4575, 2881, 12995, 13, 65, 13, 932, 199, 3, 1898, 334, 67, 9, 6029, 1603, 3609, 598, 285, 90, 3258, 199, 3, 1898, 334, 67, 9, 7129, 13, 9261, 710, 21158, 11672, 19782, 199, 3, 17484, 1334, 314, 10697, 2032, 4190, 12, 1937, 314, 23073, 199, 3, 570, 9685, 503, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 14, 199, 624, 4734, 9061, 510, 18, 48, 2784, 12995, 13, 65, 13, 932, 14, 199, 199, 2765, 2366, 1233, 1990, 6042, 687, 1952, 84, 1858, 90, 7, 4575, 2881, 221, 12995, 13, 65, 13, 932, 12, 465, 199, 4214, 315, 314, 20536, 13, 932, 5246, 402, 1455, 921, 5031, 14, 957, 15, 74, 23909, 90, 3258, 15, 647, 932, 14, 199, 199, 1716, 6805, 26, 376, 909, 1314, 31965, 299, 18, 80, 20170, 370, 282, 27214, 1031, 199, 1716, 6805, 9956, 26, 282, 1300, 1021, 626, 23369, 314, 3217, 367, 18390, 288, 13484, 543, 2784, 3788, 687, 282, 5013, 6805, 199, 35, 3142, 12, 445, 10161, 12, 445, 3142, 2567, 12, 445, 8052, 607, 12, 445, 8052, 2204, 12, 5423, 4496, 26, 272, 666, 13955, 626, 1077, 2341, 370, 5226, 13955, 315, 272, 27214, 15, 1359, 22337, 199, 1328, 63, 1457, 12, 1499, 63, 2347, 12, 1499, 63, 2139, 12, 5423, 16781, 272, 666, 13955, 626, 2954, 2784, 3788, 199, 332, 63, 10381, 477, 332, 15192, 26, 3423, 626, 2429, 16953, 15, 271, 12161, 199, 624, 199, 199, 646, 30328, 199, 504, 6010, 492, 3752, 199, 504, 5055, 492, 10018, 199, 646, 1331, 199, 646, 8337, 199, 504, 5890, 492, 11808, 199, 646, 2050, 199, 646, 2196, 199, 646, 2838, 199, 646, 2702, 199, 646, 984, 199, 646, 900, 199, 504, 5796, 492, 820, 6432, 12, 11086, 199, 199, 504, 511, 63, 4857, 14, 338, 838, 1119, 492, 25342, 2227, 3912, 199, 504, 511, 63, 4857, 14, 1974, 492, 6318, 63, 495, 63, 475, 63, 2394, 12, 2783, 63, 475, 63, 4097, 63, 495, 199, 199, 34, 1772, 383, 2192, 63, 4612, 275, 1227, 993, 199, 12339, 63, 4612, 275, 1520, 24037, 221, 327, 13541, 330, 711, 13, 2192, 367, 18249, 15, 26992, 199, 12339, 63, 6348, 4612, 275, 330, 15313, 1548, 13, 827, 15993, 13, 8234, 26, 16, 14, 16, 14, 19, 6687, 199, 12339, 63, 13604, 3448, 275, 413, 327, 687, 1015, 1520, 4183, 641, 4751, 12, 289, 5640, 1187, 1077, 506, 11544, 370, 1015, 3788, 334, 34, 1772, 1401, 9, 199, 199, 4283, 63, 568, 54, 63, 18101, 275, 959, 993, 199, 4283, 63, 8475, 63, 5825, 63, 4305, 275, 19492, 199, 199, 1439, 568, 275, 413, 3607, 327, 413, 330, 3641, 315, 308, 11318, 609, 374, 199, 199, 8063, 63, 14560, 275, 334, 17, 5213, 378, 9, 199, 8063, 63, 2970, 934, 56, 47, 275, 334, 17, 5213, 413, 9, 199, 8063, 63, 34, 1484, 7474, 275, 334, 17, 5213, 499, 9, 199, 8063, 63, 55, 3061, 275, 334, 17, 5213, 650, 9, 199, 199, 2921, 275, 2050, 14, 5572, 480, 26203, 14, 827, 15993, 531, 199, 199, 3, 14797, 4154, 5705, 2838, 2341, 367, 30328, 12, 880, 626, 781, 883, 4426, 17639, 83, 199, 3, 26495, 334, 475, 18092, 376, 4976, 543, 11261, 376, 30328, 2838, 1380, 199, 3, 1808, 3504, 9, 199, 827, 15993, 63, 3450, 63, 1130, 275, 1211, 342, 199, 199, 3, 7309, 4650, 367, 15354, 9147, 1006, 666, 2879, 3382, 314, 2784, 316, 2462, 334, 3239, 199, 3, 7220, 4436, 5084, 9, 436, 314, 2462, 3879, 314, 511, 9661, 14, 221, 2104, 17553, 3690, 12, 199, 3, 5013, 6805, 1066, 3340, 642, 4650, 18119, 28503, 316, 282, 1245, 370, 282, 5013, 6805, 9956, 12, 199, 3, 436, 18119, 7791, 7003, 370, 314, 3222, 3335, 334, 262, 3222, 63, 1188, 8801, 221, 961, 199, 3, 4650, 1077, 506, 28320, 315, 314, 2462, 3879, 314, 511, 9661, 370, 31021, 199, 3, 2879, 370, 1263, 666, 5709, 543, 314, 5013, 6805, 9956, 503, 5013, 6805, 14, 199, 827, 15993, 63, 831, 275, 820, 6432, 342, 199, 199, 3, 11973, 2072, 15, 271, 12161, 7249, 199, 318, 7793, 3912, 8, 83, 304, 272, 372, 8337, 14, 1222, 360, 4835, 3912, 297, 308, 680, 5671, 342, 199, 199, 318, 8012, 321, 1064, 8488, 8, 83, 304, 272, 372, 8337, 14, 1222, 360, 322, 321, 1064, 8488, 297, 308, 680, 5671, 342, 199, 199, 318, 2631, 3912, 8, 83, 304, 272, 372, 7793, 3912, 8, 4835, 3912, 8, 83, 430, 199, 199, 318, 8926, 63, 23046, 63, 890, 8, 76, 304, 272, 519, 275, 330, 341, 272, 340, 634, 665, 26727, 26, 267, 519, 275, 2702, 14, 1389, 480, 34, 401, 634, 9, 272, 916, 634, 665, 378, 88, 9943, 26, 267, 519, 275, 2702, 14, 1389, 6757, 29931, 401, 26727, 12, 634, 9, 272, 916, 634, 665, 378, 88, 17, 3607, 26, 267, 519, 275, 2702, 14, 1389, 6757, 19419, 401, 22540, 12, 634, 9, 272, 587, 26, 267, 519, 275, 2702, 14, 1389, 6757, 27383, 401, 5450, 12, 634, 9, 272, 372, 519, 199, 199, 318, 477, 332, 63, 23046, 63, 890, 8, 70, 304, 272, 302, 390, 275, 2702, 14, 5301, 6757, 34, 401, 289, 14, 739, 8, 17, 11515, 16, 61, 272, 340, 302, 390, 508, 26727, 26, 267, 302, 390, 275, 2702, 14, 5301, 6757, 40, 401, 289, 14, 739, 8, 18, 11515, 16, 61, 272, 916, 302, 390, 508, 22540, 26, 267, 302, 390, 275, 2702, 14, 5301, 6757, 41, 401, 289, 14, 739, 8, 20, 11515, 16, 61, 272, 916, 302, 390, 508, 5450, 26, 267, 302, 390, 275, 2702, 14, 5301, 6757, 49, 401, 289, 14, 739, 8, 24, 11515, 16, 61, 272, 372, 302, 390, 199, 199, 318, 477, 332, 63, 875, 8, 70, 304, 272, 302, 390, 275, 477, 332, 63, 23046, 63, 890, 8, 70, 9, 272, 372, 289, 14, 739, 8, 30436, 9, 199, 199, 318, 8926, 63, 875, 8, 83, 304, 272, 372, 8926, 63, 23046, 63, 890, 8, 552, 8, 83, 430, 435, 308, 199, 199, 318, 477, 332, 63, 1635 ]
[ 2647, 15, 1393, 15, 1813, 2366, 19, 199, 3, 1898, 334, 67, 9, 7129, 1952, 84, 1858, 90, 1553, 4575, 2881, 12995, 13, 65, 13, 932, 199, 3, 1898, 334, 67, 9, 6029, 1603, 3609, 598, 285, 90, 3258, 199, 3, 1898, 334, 67, 9, 7129, 13, 9261, 710, 21158, 11672, 19782, 199, 3, 17484, 1334, 314, 10697, 2032, 4190, 12, 1937, 314, 23073, 199, 3, 570, 9685, 503, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 14, 199, 624, 4734, 9061, 510, 18, 48, 2784, 12995, 13, 65, 13, 932, 14, 199, 199, 2765, 2366, 1233, 1990, 6042, 687, 1952, 84, 1858, 90, 7, 4575, 2881, 221, 12995, 13, 65, 13, 932, 12, 465, 199, 4214, 315, 314, 20536, 13, 932, 5246, 402, 1455, 921, 5031, 14, 957, 15, 74, 23909, 90, 3258, 15, 647, 932, 14, 199, 199, 1716, 6805, 26, 376, 909, 1314, 31965, 299, 18, 80, 20170, 370, 282, 27214, 1031, 199, 1716, 6805, 9956, 26, 282, 1300, 1021, 626, 23369, 314, 3217, 367, 18390, 288, 13484, 543, 2784, 3788, 687, 282, 5013, 6805, 199, 35, 3142, 12, 445, 10161, 12, 445, 3142, 2567, 12, 445, 8052, 607, 12, 445, 8052, 2204, 12, 5423, 4496, 26, 272, 666, 13955, 626, 1077, 2341, 370, 5226, 13955, 315, 272, 27214, 15, 1359, 22337, 199, 1328, 63, 1457, 12, 1499, 63, 2347, 12, 1499, 63, 2139, 12, 5423, 16781, 272, 666, 13955, 626, 2954, 2784, 3788, 199, 332, 63, 10381, 477, 332, 15192, 26, 3423, 626, 2429, 16953, 15, 271, 12161, 199, 624, 199, 199, 646, 30328, 199, 504, 6010, 492, 3752, 199, 504, 5055, 492, 10018, 199, 646, 1331, 199, 646, 8337, 199, 504, 5890, 492, 11808, 199, 646, 2050, 199, 646, 2196, 199, 646, 2838, 199, 646, 2702, 199, 646, 984, 199, 646, 900, 199, 504, 5796, 492, 820, 6432, 12, 11086, 199, 199, 504, 511, 63, 4857, 14, 338, 838, 1119, 492, 25342, 2227, 3912, 199, 504, 511, 63, 4857, 14, 1974, 492, 6318, 63, 495, 63, 475, 63, 2394, 12, 2783, 63, 475, 63, 4097, 63, 495, 199, 199, 34, 1772, 383, 2192, 63, 4612, 275, 1227, 993, 199, 12339, 63, 4612, 275, 1520, 24037, 221, 327, 13541, 330, 711, 13, 2192, 367, 18249, 15, 26992, 199, 12339, 63, 6348, 4612, 275, 330, 15313, 1548, 13, 827, 15993, 13, 8234, 26, 16, 14, 16, 14, 19, 6687, 199, 12339, 63, 13604, 3448, 275, 413, 327, 687, 1015, 1520, 4183, 641, 4751, 12, 289, 5640, 1187, 1077, 506, 11544, 370, 1015, 3788, 334, 34, 1772, 1401, 9, 199, 199, 4283, 63, 568, 54, 63, 18101, 275, 959, 993, 199, 4283, 63, 8475, 63, 5825, 63, 4305, 275, 19492, 199, 199, 1439, 568, 275, 413, 3607, 327, 413, 330, 3641, 315, 308, 11318, 609, 374, 199, 199, 8063, 63, 14560, 275, 334, 17, 5213, 378, 9, 199, 8063, 63, 2970, 934, 56, 47, 275, 334, 17, 5213, 413, 9, 199, 8063, 63, 34, 1484, 7474, 275, 334, 17, 5213, 499, 9, 199, 8063, 63, 55, 3061, 275, 334, 17, 5213, 650, 9, 199, 199, 2921, 275, 2050, 14, 5572, 480, 26203, 14, 827, 15993, 531, 199, 199, 3, 14797, 4154, 5705, 2838, 2341, 367, 30328, 12, 880, 626, 781, 883, 4426, 17639, 83, 199, 3, 26495, 334, 475, 18092, 376, 4976, 543, 11261, 376, 30328, 2838, 1380, 199, 3, 1808, 3504, 9, 199, 827, 15993, 63, 3450, 63, 1130, 275, 1211, 342, 199, 199, 3, 7309, 4650, 367, 15354, 9147, 1006, 666, 2879, 3382, 314, 2784, 316, 2462, 334, 3239, 199, 3, 7220, 4436, 5084, 9, 436, 314, 2462, 3879, 314, 511, 9661, 14, 221, 2104, 17553, 3690, 12, 199, 3, 5013, 6805, 1066, 3340, 642, 4650, 18119, 28503, 316, 282, 1245, 370, 282, 5013, 6805, 9956, 12, 199, 3, 436, 18119, 7791, 7003, 370, 314, 3222, 3335, 334, 262, 3222, 63, 1188, 8801, 221, 961, 199, 3, 4650, 1077, 506, 28320, 315, 314, 2462, 3879, 314, 511, 9661, 370, 31021, 199, 3, 2879, 370, 1263, 666, 5709, 543, 314, 5013, 6805, 9956, 503, 5013, 6805, 14, 199, 827, 15993, 63, 831, 275, 820, 6432, 342, 199, 199, 3, 11973, 2072, 15, 271, 12161, 7249, 199, 318, 7793, 3912, 8, 83, 304, 272, 372, 8337, 14, 1222, 360, 4835, 3912, 297, 308, 680, 5671, 342, 199, 199, 318, 8012, 321, 1064, 8488, 8, 83, 304, 272, 372, 8337, 14, 1222, 360, 322, 321, 1064, 8488, 297, 308, 680, 5671, 342, 199, 199, 318, 2631, 3912, 8, 83, 304, 272, 372, 7793, 3912, 8, 4835, 3912, 8, 83, 430, 199, 199, 318, 8926, 63, 23046, 63, 890, 8, 76, 304, 272, 519, 275, 330, 341, 272, 340, 634, 665, 26727, 26, 267, 519, 275, 2702, 14, 1389, 480, 34, 401, 634, 9, 272, 916, 634, 665, 378, 88, 9943, 26, 267, 519, 275, 2702, 14, 1389, 6757, 29931, 401, 26727, 12, 634, 9, 272, 916, 634, 665, 378, 88, 17, 3607, 26, 267, 519, 275, 2702, 14, 1389, 6757, 19419, 401, 22540, 12, 634, 9, 272, 587, 26, 267, 519, 275, 2702, 14, 1389, 6757, 27383, 401, 5450, 12, 634, 9, 272, 372, 519, 199, 199, 318, 477, 332, 63, 23046, 63, 890, 8, 70, 304, 272, 302, 390, 275, 2702, 14, 5301, 6757, 34, 401, 289, 14, 739, 8, 17, 11515, 16, 61, 272, 340, 302, 390, 508, 26727, 26, 267, 302, 390, 275, 2702, 14, 5301, 6757, 40, 401, 289, 14, 739, 8, 18, 11515, 16, 61, 272, 916, 302, 390, 508, 22540, 26, 267, 302, 390, 275, 2702, 14, 5301, 6757, 41, 401, 289, 14, 739, 8, 20, 11515, 16, 61, 272, 916, 302, 390, 508, 5450, 26, 267, 302, 390, 275, 2702, 14, 5301, 6757, 49, 401, 289, 14, 739, 8, 24, 11515, 16, 61, 272, 372, 302, 390, 199, 199, 318, 477, 332, 63, 875, 8, 70, 304, 272, 302, 390, 275, 477, 332, 63, 23046, 63, 890, 8, 70, 9, 272, 372, 289, 14, 739, 8, 30436, 9, 199, 199, 318, 8926, 63, 875, 8, 83, 304, 272, 372, 8926, 63, 23046, 63, 890, 8, 552, 8, 83, 430, 435, 308, 199, 199, 318, 477, 332, 63, 1635, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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import pytest from numpy.testing import assert_array_almost_equal, assert_array_equal from pytest import approx from landlab.graph import TriGraph from landlab.graph.hex.hex import ( HorizontalHexTriGraph, HorizontalRectTriGraph, VerticalHexTriGraph, VerticalRectTriGraph, ) def test_number_of_nodes_horizontal_rect(): assert HorizontalRectTriGraph.number_of_nodes((1, 2)) == 2 assert HorizontalRectTriGraph.number_of_nodes((1, 3)) == 3 assert HorizontalRectTriGraph.number_of_nodes((2, 2)) == 4 assert HorizontalRectTriGraph.number_of_nodes((2, 3)) == 6 assert HorizontalRectTriGraph.number_of_nodes((3, 2)) == 6 assert HorizontalRectTriGraph.number_of_nodes((3, 3)) == 9 def test_number_of_nodes_vertical_rect(): assert VerticalRectTriGraph.number_of_nodes((1, 2)) == 2 assert VerticalRectTriGraph.number_of_nodes((1, 3)) == 3 assert VerticalRectTriGraph.number_of_nodes((2, 2)) == 4 assert VerticalRectTriGraph.number_of_nodes((2, 3)) == 6 assert VerticalRectTriGraph.number_of_nodes((3, 2)) == 6 assert VerticalRectTriGraph.number_of_nodes((3, 3)) == 9 def test_number_of_nodes_horizontal_hex(): assert HorizontalHexTriGraph.number_of_nodes((1, 2)) == 2 assert HorizontalHexTriGraph.number_of_nodes((1, 3)) == 3 assert HorizontalHexTriGraph.number_of_nodes((2, 2)) == 5 assert HorizontalHexTriGraph.number_of_nodes((2, 3)) == 7 assert HorizontalHexTriGraph.number_of_nodes((3, 2)) == 7 assert HorizontalHexTriGraph.number_of_nodes((3, 3)) == 10 def test_number_of_nodes_vertical_hex(): assert VerticalHexTriGraph.number_of_nodes((1, 2)) == 3 assert VerticalHexTriGraph.number_of_nodes((1, 3)) == 4 assert VerticalHexTriGraph.number_of_nodes((2, 2)) == 5 assert VerticalHexTriGraph.number_of_nodes((2, 3)) == 7 assert VerticalHexTriGraph.number_of_nodes((3, 2)) == 7 assert VerticalHexTriGraph.number_of_nodes((3, 3)) == 10 def test_number_of_nodes_symetric_rect(hex_shape): assert VerticalRectTriGraph.number_of_nodes( hex_shape ) == HorizontalRectTriGraph.number_of_nodes(hex_shape[::-1]) def test_number_of_nodes_symetric_hex(hex_shape): assert VerticalHexTriGraph.number_of_nodes( hex_shape ) == HorizontalHexTriGraph.number_of_nodes(hex_shape[::-1]) @pytest.mark.parametrize("n_rows", (3,)) @pytest.mark.parametrize("node_layout", ("rect", "hex")) @pytest.mark.parametrize("orientation", ("horizontal", "vertical")) @pytest.mark.parametrize("at", ("nodes", "links", "patches")) def test_create_hex_graph(n_rows, node_layout, orientation, at): expected = { "rect": { "horizontal": {"nodes": 6, "links": 9, "patches": 4}, "vertical": {"nodes": 6, "links": 9, "patches": 4}, }, "hex": { "horizontal": {"nodes": 7, "links": 12, "patches": 6}, "vertical": {"nodes": 7, "links": 12, "patches": 6}, }, } if orientation == "vertical": shape = (2, n_rows) else: shape = (n_rows, 2) graph = TriGraph(shape, node_layout=node_layout, orientation=orientation, sort=True) assert ( getattr(graph, "number_of_{at}".format(at=at)) == expected[node_layout][orientation][at] ) def test_create_rect(): """Test creating a hex graph with rectangular layout.""" graph = TriGraph((3, 2), node_layout="rect", sort=True) assert graph.number_of_nodes == 6 assert graph.number_of_links == 9 assert graph.number_of_patches == 4 def test_create_hex(): """Test creating a hex graph with hex layout.""" graph = TriGraph((3, 2), node_layout="hex", sort=True) assert graph.number_of_nodes == 7 assert graph.number_of_links == 12 assert graph.number_of_patches == 6 def test_spacing(small_hex_shape): """Test spacing of nodes.""" graph = TriGraph(small_hex_shape) assert_array_almost_equal(graph.length_of_link, 1.0) graph = TriGraph(small_hex_shape, spacing=2) assert_array_almost_equal(graph.length_of_link, 2.0) @pytest.mark.parametrize("orientation", ("horizontal", "vertical")) @pytest.mark.parametrize("node_layout", ("hex", "rect")) def test_origin_keyword(node_layout, orientation, small_hex_shape): """Test setting the origin.""" graph = TriGraph(small_hex_shape) assert np.min(graph.x_of_node) == approx(0.0) assert np.min(graph.y_of_node) == approx(0.0) graph = TriGraph(small_hex_shape, xy_of_lower_left=(0.5, 0.25)) assert np.min(graph.x_of_node[0]) == approx(0.5) assert np.min(graph.y_of_node[0]) == approx(0.25) def test_orientation(): """Test vertical and horizontal orientation.""" graph = TriGraph((3, 3), orientation="vertical") assert_array_almost_equal( graph.y_of_node, [0.0, 0.0, 0.5, 1.0, 1.0, 1.5, 2.0, 2.0, 2.5] ) graph = TriGraph((3, 3), orientation="horizontal") assert_array_almost_equal( graph.x_of_node, [0.0, 1.0, 2.0, 0.5, 1.5, 2.5, 0.0, 1.0, 2.0] ) def test_perimeter_nodes_rect(): graph = TriGraph((3, 4), node_layout="rect") assert_array_equal(graph.perimeter_nodes, [3, 7, 11, 10, 9, 8, 4, 0, 1, 2]) def test_perimeter_nodes_hex(): graph = TriGraph((4, 2), node_layout="hex") assert_array_equal(graph.perimeter_nodes, [8, 11, 10, 9, 5, 2, 0, 1, 4]) def test_adjacent_nodes_at_node(): graph = TriGraph((3, 3), node_layout="hex", sort=True) assert_array_equal( graph.adjacent_nodes_at_node, [ [1, 4, 3, -1, -1, -1], [2, 5, 4, 0, -1, -1], [6, 5, 1, -1, -1, -1], [4, 7, 0, -1, -1, -1], [5, 8, 7, 3, 0, 1], [6, 9, 8, 4, 1, 2], [9, 5, 2, -1, -1, -1], [8, 3, 4, -1, -1, -1], [9, 7, 4, 5, -1, -1], [8, 5, 6, -1, -1, -1], ], ) def test_patches_at_node(): grid = TriGraph((3, 3), node_layout="hex", sort=True) assert_array_equal( grid.patches_at_node, [ [0, 2, -1, -1, -1, -1], [1, 3, 0, -1, -1, -1], [4, 1, -1, -1, -1, -1], [5, 2, -1, -1, -1, -1], [6, 8, 5, 2, 0, 3], [7, 9, 6, 3, 1, 4], [7, 4, -1, -1, -1, -1], [5, 8, -1, -1, -1, -1], [8, 6, 9, -1, -1, -1], [9, 7, -1, -1, -1, -1], ], ) @pytest.mark.parametrize("n_cols", (2, 3)) @pytest.mark.parametrize("n_rows", (2, 3)) def test_xy_of_node_rect_vertical(n_rows, n_cols): expected = { (2, 2): ([0, 1, 0, 1], [0, 0.5, 1, 1.5]), (2, 3): ([0, 2, 1, 0, 2, 1], [0, 0, 0.5, 1, 1, 1.5]), (3, 2): ([0, 1, 0, 1, 0, 1], [0, 0.5, 1, 1.5, 2, 2.5]), (3, 3): ([0, 2, 1, 0, 2, 1, 0, 2, 1], [0, 0, 0.5, 1, 1, 1.5, 2, 2, 2.5]), } x_of_node, y_of_node = VerticalRectTriGraph.xy_of_node((n_rows, n_cols)) assert np.all( x_of_node / np.sin(np.pi / 3.0) == approx(expected[(n_rows, n_cols)][0]) ) assert np.all(y_of_node == approx(expected[(n_rows, n_cols)][1])) @pytest.mark.parametrize("n_cols", (2, 3)) @pytest.mark.parametrize("n_rows", (1, 2, 3)) def test_xy_of_node_hex_vertical(n_rows, n_cols): expected = { (1, 2): ([1.0, 0, 1.0], [0, 0.5, 1]), (1, 3): ([1.0, 0, 2, 1.0], [0, 0.5, 0.5, 1]), (2, 2): ([1.0, 0, 1.0, 0, 1.0], [0, 0.5, 1, 1.5, 2]), (2, 3): ([1.0, 0, 2, 1.0, 0, 2, 1.0], [0, 0.5, 0.5, 1, 1.5, 1.5, 2]), (3, 2): ([1.0, 0, 1.0, 0, 1.0, 0.0, 1.0], [0, 0.5, 1, 1.5, 2, 2.5, 3]), (3, 3): ( [1.0, 0, 2, 1.0, 0, 2, 1.0, 0, 2, 1.0], [0, 0.5, 0.5, 1, 1.5, 1.5, 2, 2.5, 2.5, 3], ), } x_of_node, y_of_node = VerticalHexTriGraph.xy_of_node((n_rows, n_cols)) assert np.all( x_of_node / np.sin(np.pi / 3.0) == approx(expected[(n_rows, n_cols)][0]) ) assert np.all(y_of_node == approx(expected[(n_rows, n_cols)][1])) def test_xy_of_node_spacing(hex_layout): x_of_node_expected, y_of_node_expected = hex_layout.xy_of_node((3, 4)) x_of_node, y_of_node = hex_layout.xy_of_node((3, 4), spacing=2.0) assert_array_almost_equal(x_of_node / 2.0, x_of_node_expected) assert_array_almost_equal(y_of_node / 2.0, y_of_node_expected) @pytest.mark.parametrize("n_cols", (2, 3)) @pytest.mark.parametrize("n_rows", (1, 2, 3)) def test_xy_of_node_lower_left(hex_layout, n_rows, n_cols): (x_of_node, y_of_node) = hex_layout.xy_of_node((n_rows, n_cols)) assert np.min(x_of_node) == approx(0.0) assert np.min(y_of_node) == approx(0.0)
mit
[ 646, 2680, 465, 980, 199, 646, 4613, 199, 504, 2680, 14, 4776, 492, 702, 63, 1144, 63, 4398, 63, 1452, 12, 702, 63, 1144, 63, 1452, 199, 504, 4613, 492, 14106, 199, 199, 504, 20078, 5561, 14, 2180, 492, 12480, 4578, 199, 504, 20078, 5561, 14, 2180, 14, 4097, 14, 4097, 492, 334, 272, 869, 7550, 10373, 6948, 4578, 12, 272, 869, 7550, 8252, 6948, 4578, 12, 272, 5444, 3294, 10373, 6948, 4578, 12, 272, 5444, 3294, 8252, 6948, 4578, 12, 199, 9, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 11392, 63, 1201, 837, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 499, 430, 508, 499, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 650, 430, 508, 650, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 499, 430, 508, 841, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 650, 430, 508, 1227, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 499, 430, 508, 1227, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 650, 430, 508, 1749, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 7870, 63, 1201, 837, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 499, 430, 508, 499, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 650, 430, 508, 650, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 499, 430, 508, 841, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 650, 430, 508, 1227, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 499, 430, 508, 1227, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 650, 430, 508, 1749, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 11392, 63, 4097, 837, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 499, 430, 508, 499, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 650, 430, 508, 650, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 499, 430, 508, 959, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 650, 430, 508, 1520, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 499, 430, 508, 1520, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 650, 430, 508, 1616, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 7870, 63, 4097, 837, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 499, 430, 508, 650, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 650, 430, 508, 841, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 499, 430, 508, 959, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 650, 430, 508, 1520, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 499, 430, 508, 1520, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 650, 430, 508, 1616, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 1786, 5165, 63, 1201, 8, 4097, 63, 1392, 304, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 8, 267, 6318, 63, 1392, 272, 776, 508, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 8, 4097, 63, 1392, 14172, 17, 566, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 1786, 5165, 63, 4097, 8, 4097, 63, 1392, 304, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 8, 267, 6318, 63, 1392, 272, 776, 508, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 8, 4097, 63, 1392, 14172, 17, 566, 421, 199, 32, 4462, 14, 1657, 14, 10396, 480, 78, 63, 3838, 401, 334, 19, 4641, 199, 32, 4462, 14, 1657, 14, 10396, 480, 932, 63, 4209, 401, 1689, 1201, 401, 298, 4097, 2237, 199, 32, 4462, 14, 1657, 14, 10396, 480, 17001, 401, 1689, 11392, 401, 298, 7870, 2237, 199, 32, 4462, 14, 1657, 14, 10396, 480, 292, 401, 1689, 2415, 401, 298, 4614, 401, 298, 11350, 2237, 199, 318, 511, 63, 981, 63, 4097, 63, 2180, 8, 78, 63, 3838, 12, 1031, 63, 4209, 12, 16774, 12, 737, 304, 272, 1420, 275, 469, 267, 298, 1201, 582, 469, 288, 298, 11392, 582, 2420, 2415, 582, 1227, 12, 298, 4614, 582, 1749, 12, 298, 11350, 582, 841, 1386, 288, 298, 7870, 582, 2420, 2415, 582, 1227, 12, 298, 4614, 582, 1749, 12, 298, 11350, 582, 841, 1386, 267, 1660, 267, 298, 4097, 582, 469, 288, 298, 11392, 582, 2420, 2415, 582, 1520, 12, 298, 4614, 582, 3144, 12, 298, 11350, 582, 1227, 1386, 288, 298, 7870, 582, 2420, 2415, 582, 1520, 12, 298, 4614, 582, 3144, 12, 298, 11350, 582, 1227, 1386, 267, 1660, 272, 789, 272, 340, 16774, 508, 298, 7870, 582, 267, 2215, 275, 334, 18, 12, 302, 63, 3838, 9, 272, 587, 26, 267, 2215, 275, 334, 78, 63, 3838, 12, 499, 9, 272, 3343, 275, 12480, 4578, 8, 1392, 12, 1031, 63, 4209, 29, 932, 63, 4209, 12, 16774, 29, 17001, 12, 4069, 29, 549, 9, 272, 702, 334, 267, 2519, 8, 2180, 12, 298, 1955, 63, 1618, 7348, 292, 5469, 908, 8, 292, 29, 292, 430, 267, 508, 1420, 59, 932, 63, 4209, 1527, 17001, 1527, 292, 61, 272, 776, 421, 199, 318, 511, 63, 981, 63 ]
[ 2680, 465, 980, 199, 646, 4613, 199, 504, 2680, 14, 4776, 492, 702, 63, 1144, 63, 4398, 63, 1452, 12, 702, 63, 1144, 63, 1452, 199, 504, 4613, 492, 14106, 199, 199, 504, 20078, 5561, 14, 2180, 492, 12480, 4578, 199, 504, 20078, 5561, 14, 2180, 14, 4097, 14, 4097, 492, 334, 272, 869, 7550, 10373, 6948, 4578, 12, 272, 869, 7550, 8252, 6948, 4578, 12, 272, 5444, 3294, 10373, 6948, 4578, 12, 272, 5444, 3294, 8252, 6948, 4578, 12, 199, 9, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 11392, 63, 1201, 837, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 499, 430, 508, 499, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 650, 430, 508, 650, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 499, 430, 508, 841, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 650, 430, 508, 1227, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 499, 430, 508, 1227, 272, 702, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 650, 430, 508, 1749, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 7870, 63, 1201, 837, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 499, 430, 508, 499, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 650, 430, 508, 650, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 499, 430, 508, 841, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 650, 430, 508, 1227, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 499, 430, 508, 1227, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 650, 430, 508, 1749, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 11392, 63, 4097, 837, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 499, 430, 508, 499, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 650, 430, 508, 650, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 499, 430, 508, 959, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 650, 430, 508, 1520, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 499, 430, 508, 1520, 272, 702, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 650, 430, 508, 1616, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 7870, 63, 4097, 837, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 499, 430, 508, 650, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 17, 12, 650, 430, 508, 841, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 499, 430, 508, 959, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 18, 12, 650, 430, 508, 1520, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 499, 430, 508, 1520, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 1332, 19, 12, 650, 430, 508, 1616, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 1786, 5165, 63, 1201, 8, 4097, 63, 1392, 304, 272, 702, 5444, 3294, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 8, 267, 6318, 63, 1392, 272, 776, 508, 869, 7550, 8252, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 8, 4097, 63, 1392, 14172, 17, 566, 421, 199, 318, 511, 63, 1955, 63, 1618, 63, 2415, 63, 1786, 5165, 63, 4097, 8, 4097, 63, 1392, 304, 272, 702, 5444, 3294, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 8, 267, 6318, 63, 1392, 272, 776, 508, 869, 7550, 10373, 6948, 4578, 14, 1955, 63, 1618, 63, 2415, 8, 4097, 63, 1392, 14172, 17, 566, 421, 199, 32, 4462, 14, 1657, 14, 10396, 480, 78, 63, 3838, 401, 334, 19, 4641, 199, 32, 4462, 14, 1657, 14, 10396, 480, 932, 63, 4209, 401, 1689, 1201, 401, 298, 4097, 2237, 199, 32, 4462, 14, 1657, 14, 10396, 480, 17001, 401, 1689, 11392, 401, 298, 7870, 2237, 199, 32, 4462, 14, 1657, 14, 10396, 480, 292, 401, 1689, 2415, 401, 298, 4614, 401, 298, 11350, 2237, 199, 318, 511, 63, 981, 63, 4097, 63, 2180, 8, 78, 63, 3838, 12, 1031, 63, 4209, 12, 16774, 12, 737, 304, 272, 1420, 275, 469, 267, 298, 1201, 582, 469, 288, 298, 11392, 582, 2420, 2415, 582, 1227, 12, 298, 4614, 582, 1749, 12, 298, 11350, 582, 841, 1386, 288, 298, 7870, 582, 2420, 2415, 582, 1227, 12, 298, 4614, 582, 1749, 12, 298, 11350, 582, 841, 1386, 267, 1660, 267, 298, 4097, 582, 469, 288, 298, 11392, 582, 2420, 2415, 582, 1520, 12, 298, 4614, 582, 3144, 12, 298, 11350, 582, 1227, 1386, 288, 298, 7870, 582, 2420, 2415, 582, 1520, 12, 298, 4614, 582, 3144, 12, 298, 11350, 582, 1227, 1386, 267, 1660, 272, 789, 272, 340, 16774, 508, 298, 7870, 582, 267, 2215, 275, 334, 18, 12, 302, 63, 3838, 9, 272, 587, 26, 267, 2215, 275, 334, 78, 63, 3838, 12, 499, 9, 272, 3343, 275, 12480, 4578, 8, 1392, 12, 1031, 63, 4209, 29, 932, 63, 4209, 12, 16774, 29, 17001, 12, 4069, 29, 549, 9, 272, 702, 334, 267, 2519, 8, 2180, 12, 298, 1955, 63, 1618, 7348, 292, 5469, 908, 8, 292, 29, 292, 430, 267, 508, 1420, 59, 932, 63, 4209, 1527, 17001, 1527, 292, 61, 272, 776, 421, 199, 318, 511, 63,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1, 1, 1, 1, 1 ]
ericdill/bokeh
examples/glyphs/dateaxis.py
43
1231
from __future__ import print_function from numpy import pi, arange, sin import numpy as np import time from bokeh.browserlib import view from bokeh.document import Document from bokeh.embed import file_html from bokeh.models.glyphs import Circle from bokeh.models import ( Plot, DataRange1d, DatetimeAxis, ColumnDataSource, PanTool, WheelZoomTool ) from bokeh.resources import INLINE x = arange(-2 * pi, 2 * pi, 0.1) y = sin(x) # Create an array of times, starting at the current time, and extending # for len(x) number of hours. times = np.arange(len(x)) * 3600000 + time.time() source = ColumnDataSource( data=dict(x=x, y=y, times=times) ) xdr = DataRange1d() ydr = DataRange1d() plot = Plot(x_range=xdr, y_range=ydr, min_border=80) circle = Circle(x="times", y="y", fill_color="red", size=5, line_color="black") plot.add_glyph(source, circle) plot.add_layout(DatetimeAxis(), 'below') plot.add_layout(DatetimeAxis(), 'left') plot.add_tools(PanTool(), WheelZoomTool()) doc = Document() doc.add(plot) if __name__ == "__main__": filename = "dateaxis.html" with open(filename, "w") as f: f.write(file_html(doc, INLINE, "Date Axis Example")) print("Wrote %s" % filename) view(filename)
bsd-3-clause
[ 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 2680, 492, 6682, 12, 20461, 12, 9829, 199, 646, 2680, 465, 980, 199, 646, 900, 199, 199, 504, 25214, 14, 5750, 773, 492, 2455, 199, 504, 25214, 14, 3554, 492, 7543, 199, 504, 25214, 14, 6427, 492, 570, 63, 1360, 199, 504, 25214, 14, 992, 14, 13723, 83, 492, 445, 12571, 199, 504, 25214, 14, 992, 492, 334, 272, 14794, 12, 3918, 4709, 17, 68, 12, 29825, 11220, 12, 272, 4996, 16693, 12, 510, 290, 5157, 12, 26161, 26798, 5157, 199, 9, 199, 504, 25214, 14, 4435, 492, 1621, 6174, 199, 199, 88, 275, 20461, 2801, 18, 627, 6682, 12, 499, 627, 6682, 12, 378, 14, 17, 9, 199, 89, 275, 9829, 8, 88, 9, 199, 199, 3, 2790, 376, 1625, 402, 5431, 12, 6617, 737, 314, 1453, 900, 12, 436, 2178, 1098, 199, 3, 367, 822, 8, 88, 9, 1329, 402, 10857, 14, 199, 4508, 275, 980, 14, 5605, 8, 552, 8, 88, 430, 627, 8780, 5345, 435, 900, 14, 521, 342, 199, 199, 1365, 275, 4996, 16693, 8, 272, 666, 29, 807, 8, 88, 29, 88, 12, 612, 29, 89, 12, 5431, 29, 4508, 9, 199, 9, 199, 199, 2207, 82, 275, 3918, 4709, 17, 68, 342, 199, 89, 5012, 275, 3918, 4709, 17, 68, 342, 199, 199, 2798, 275, 14794, 8, 88, 63, 1842, 29, 2207, 82, 12, 612, 63, 1842, 29, 89, 5012, 12, 1748, 63, 8665, 29, 1257, 9, 199, 199, 11001, 275, 445, 12571, 8, 88, 628, 4508, 401, 612, 628, 89, 401, 5554, 63, 2326, 628, 581, 401, 1568, 29, 21, 12, 1004, 63, 2326, 628, 8399, 531, 199, 2798, 14, 525, 63, 13723, 8, 1365, 12, 17990, 9, 199, 199, 2798, 14, 525, 63, 4209, 8, 19636, 11220, 1062, 283, 12843, 358, 199, 2798, 14, 525, 63, 4209, 8, 19636, 11220, 1062, 283, 3039, 358, 199, 199, 2798, 14, 525, 63, 2537, 8, 19266, 5157, 1062, 26161, 26798, 5157, 1012, 199, 199, 1301, 275, 7543, 342, 199, 1301, 14, 525, 8, 2798, 9, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 1788, 275, 298, 602, 3127, 14, 1360, 2, 272, 543, 1551, 8, 1501, 12, 298, 87, 531, 465, 289, 26, 267, 289, 14, 952, 8, 493, 63, 1360, 8, 1301, 12, 1621, 6174, 12, 298, 2506, 23205, 5679, 2237, 272, 870, 480, 55, 22665, 450, 83, 2, 450, 1788, 9, 272, 2455, 8, 1501, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 2680, 492, 6682, 12, 20461, 12, 9829, 199, 646, 2680, 465, 980, 199, 646, 900, 199, 199, 504, 25214, 14, 5750, 773, 492, 2455, 199, 504, 25214, 14, 3554, 492, 7543, 199, 504, 25214, 14, 6427, 492, 570, 63, 1360, 199, 504, 25214, 14, 992, 14, 13723, 83, 492, 445, 12571, 199, 504, 25214, 14, 992, 492, 334, 272, 14794, 12, 3918, 4709, 17, 68, 12, 29825, 11220, 12, 272, 4996, 16693, 12, 510, 290, 5157, 12, 26161, 26798, 5157, 199, 9, 199, 504, 25214, 14, 4435, 492, 1621, 6174, 199, 199, 88, 275, 20461, 2801, 18, 627, 6682, 12, 499, 627, 6682, 12, 378, 14, 17, 9, 199, 89, 275, 9829, 8, 88, 9, 199, 199, 3, 2790, 376, 1625, 402, 5431, 12, 6617, 737, 314, 1453, 900, 12, 436, 2178, 1098, 199, 3, 367, 822, 8, 88, 9, 1329, 402, 10857, 14, 199, 4508, 275, 980, 14, 5605, 8, 552, 8, 88, 430, 627, 8780, 5345, 435, 900, 14, 521, 342, 199, 199, 1365, 275, 4996, 16693, 8, 272, 666, 29, 807, 8, 88, 29, 88, 12, 612, 29, 89, 12, 5431, 29, 4508, 9, 199, 9, 199, 199, 2207, 82, 275, 3918, 4709, 17, 68, 342, 199, 89, 5012, 275, 3918, 4709, 17, 68, 342, 199, 199, 2798, 275, 14794, 8, 88, 63, 1842, 29, 2207, 82, 12, 612, 63, 1842, 29, 89, 5012, 12, 1748, 63, 8665, 29, 1257, 9, 199, 199, 11001, 275, 445, 12571, 8, 88, 628, 4508, 401, 612, 628, 89, 401, 5554, 63, 2326, 628, 581, 401, 1568, 29, 21, 12, 1004, 63, 2326, 628, 8399, 531, 199, 2798, 14, 525, 63, 13723, 8, 1365, 12, 17990, 9, 199, 199, 2798, 14, 525, 63, 4209, 8, 19636, 11220, 1062, 283, 12843, 358, 199, 2798, 14, 525, 63, 4209, 8, 19636, 11220, 1062, 283, 3039, 358, 199, 199, 2798, 14, 525, 63, 2537, 8, 19266, 5157, 1062, 26161, 26798, 5157, 1012, 199, 199, 1301, 275, 7543, 342, 199, 1301, 14, 525, 8, 2798, 9, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 1788, 275, 298, 602, 3127, 14, 1360, 2, 272, 543, 1551, 8, 1501, 12, 298, 87, 531, 465, 289, 26, 267, 289, 14, 952, 8, 493, 63, 1360, 8, 1301, 12, 1621, 6174, 12, 298, 2506, 23205, 5679, 2237, 272, 870, 480, 55, 22665, 450, 83, 2, 450, 1788, 9, 272, 2455, 8, 1501, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
davidsims9t/itis-graphql
venv/lib/python3.4/site-packages/setuptools/command/develop.py
106
7384
from distutils.util import convert_path from distutils import log from distutils.errors import DistutilsError, DistutilsOptionError import os import glob import io from setuptools.extern import six from pkg_resources import Distribution, PathMetadata, normalize_path from setuptools.command.easy_install import easy_install import setuptools class develop(easy_install): """Set up package for development""" description = "install package in 'development mode'" user_options = easy_install.user_options + [ ("uninstall", "u", "Uninstall this source package"), ("egg-path=", None, "Set the path to be used in the .egg-link file"), ] boolean_options = easy_install.boolean_options + ['uninstall'] command_consumes_arguments = False # override base def run(self): if self.uninstall: self.multi_version = True self.uninstall_link() else: self.install_for_development() self.warn_deprecated_options() def initialize_options(self): self.uninstall = None self.egg_path = None easy_install.initialize_options(self) self.setup_path = None self.always_copy_from = '.' # always copy eggs installed in curdir def finalize_options(self): ei = self.get_finalized_command("egg_info") if ei.broken_egg_info: template = "Please rename %r to %r before using 'develop'" args = ei.egg_info, ei.broken_egg_info raise DistutilsError(template % args) self.args = [ei.egg_name] easy_install.finalize_options(self) self.expand_basedirs() self.expand_dirs() # pick up setup-dir .egg files only: no .egg-info self.package_index.scan(glob.glob('*.egg')) egg_link_fn = ei.egg_name + '.egg-link' self.egg_link = os.path.join(self.install_dir, egg_link_fn) self.egg_base = ei.egg_base if self.egg_path is None: self.egg_path = os.path.abspath(ei.egg_base) target = normalize_path(self.egg_base) egg_path = normalize_path(os.path.join(self.install_dir, self.egg_path)) if egg_path != target: raise DistutilsOptionError( "--egg-path must be a relative path from the install" " directory to " + target ) # Make a distribution for the package's source self.dist = Distribution( target, PathMetadata(target, os.path.abspath(ei.egg_info)), project_name=ei.egg_name ) p = self.egg_base.replace(os.sep, '/') if p != os.curdir: p = '../' * (p.count('/') + 1) self.setup_path = p p = normalize_path(os.path.join(self.install_dir, self.egg_path, p)) if p != normalize_path(os.curdir): raise DistutilsOptionError( "Can't get a consistent path to setup script from" " installation directory", p, normalize_path(os.curdir)) def install_for_development(self): if six.PY3 and getattr(self.distribution, 'use_2to3', False): # If we run 2to3 we can not do this inplace: # Ensure metadata is up-to-date self.reinitialize_command('build_py', inplace=0) self.run_command('build_py') bpy_cmd = self.get_finalized_command("build_py") build_path = normalize_path(bpy_cmd.build_lib) # Build extensions self.reinitialize_command('egg_info', egg_base=build_path) self.run_command('egg_info') self.reinitialize_command('build_ext', inplace=0) self.run_command('build_ext') # Fixup egg-link and easy-install.pth ei_cmd = self.get_finalized_command("egg_info") self.egg_path = build_path self.dist.location = build_path # XXX self.dist._provider = PathMetadata(build_path, ei_cmd.egg_info) else: # Without 2to3 inplace works fine: self.run_command('egg_info') # Build extensions in-place self.reinitialize_command('build_ext', inplace=1) self.run_command('build_ext') self.install_site_py() # ensure that target dir is site-safe if setuptools.bootstrap_install_from: self.easy_install(setuptools.bootstrap_install_from) setuptools.bootstrap_install_from = None # create an .egg-link in the installation dir, pointing to our egg log.info("Creating %s (link to %s)", self.egg_link, self.egg_base) if not self.dry_run: with open(self.egg_link, "w") as f: f.write(self.egg_path + "\n" + self.setup_path) # postprocess the installed distro, fixing up .pth, installing scripts, # and handling requirements self.process_distribution(None, self.dist, not self.no_deps) def uninstall_link(self): if os.path.exists(self.egg_link): log.info("Removing %s (link to %s)", self.egg_link, self.egg_base) egg_link_file = open(self.egg_link) contents = [line.rstrip() for line in egg_link_file] egg_link_file.close() if contents not in ([self.egg_path], [self.egg_path, self.setup_path]): log.warn("Link points to %s: uninstall aborted", contents) return if not self.dry_run: os.unlink(self.egg_link) if not self.dry_run: self.update_pth(self.dist) # remove any .pth link to us if self.distribution.scripts: # XXX should also check for entry point scripts! log.warn("Note: you must uninstall or replace scripts manually!") def install_egg_scripts(self, dist): if dist is not self.dist: # Installing a dependency, so fall back to normal behavior return easy_install.install_egg_scripts(self, dist) # create wrapper scripts in the script dir, pointing to dist.scripts # new-style... self.install_wrapper_scripts(dist) # ...and old-style for script_name in self.distribution.scripts or []: script_path = os.path.abspath(convert_path(script_name)) script_name = os.path.basename(script_path) with io.open(script_path) as strm: script_text = strm.read() self.install_script(dist, script_name, script_text, script_path) def install_wrapper_scripts(self, dist): dist = VersionlessRequirement(dist) return easy_install.install_wrapper_scripts(self, dist) class VersionlessRequirement(object): """ Adapt a pkg_resources.Distribution to simply return the project name as the 'requirement' so that scripts will work across multiple versions. >>> dist = Distribution(project_name='foo', version='1.0') >>> str(dist.as_requirement()) 'foo==1.0' >>> adapted_dist = VersionlessRequirement(dist) >>> str(adapted_dist.as_requirement()) 'foo' """ def __init__(self, dist): self.__dist = dist def __getattr__(self, name): return getattr(self.__dist, name) def as_requirement(self): return self.project_name
gpl-3.0
[ 504, 7065, 14, 1974, 492, 3957, 63, 515, 199, 504, 7065, 492, 943, 199, 504, 7065, 14, 2550, 492, 12577, 547, 12, 31484, 199, 646, 747, 199, 646, 5739, 199, 646, 5890, 199, 199, 504, 9116, 14, 18587, 492, 3816, 199, 199, 504, 5496, 63, 4435, 492, 11839, 12, 6912, 5142, 12, 7666, 63, 515, 199, 504, 9116, 14, 1531, 14, 13581, 63, 3174, 492, 8837, 63, 3174, 199, 646, 9116, 421, 199, 533, 477, 7549, 8, 13581, 63, 3174, 304, 272, 408, 1084, 1536, 2559, 367, 16367, 624, 339, 1369, 275, 298, 3174, 2559, 315, 283, 31688, 818, 4065, 339, 922, 63, 1419, 275, 8837, 63, 3174, 14, 751, 63, 1419, 435, 359, 267, 1689, 19502, 401, 298, 85, 401, 298, 1358, 3174, 642, 1350, 2559, 1288, 267, 1689, 5799, 13, 515, 11107, 488, 12, 298, 1084, 314, 931, 370, 506, 1202, 315, 314, 1275, 5799, 13, 1073, 570, 1288, 272, 1622, 339, 5046, 63, 1419, 275, 8837, 63, 3174, 14, 4871, 63, 1419, 435, 788, 19502, 418, 339, 1414, 63, 10235, 83, 63, 4958, 275, 756, 221, 327, 4278, 1300, 339, 347, 1255, 8, 277, 304, 267, 340, 291, 14, 19502, 26, 288, 291, 14, 3029, 63, 1023, 275, 715, 288, 291, 14, 19502, 63, 1073, 342, 267, 587, 26, 288, 291, 14, 3174, 63, 509, 63, 31688, 342, 267, 291, 14, 4050, 63, 6667, 63, 1419, 342, 339, 347, 8265, 63, 1419, 8, 277, 304, 267, 291, 14, 19502, 275, 488, 267, 291, 14, 5799, 63, 515, 275, 488, 267, 8837, 63, 3174, 14, 8489, 63, 1419, 8, 277, 9, 267, 291, 14, 2758, 63, 515, 275, 488, 267, 291, 14, 9223, 63, 1574, 63, 504, 275, 7815, 221, 327, 3544, 1331, 22151, 4903, 315, 1094, 694, 339, 347, 17284, 63, 1419, 8, 277, 304, 267, 20654, 275, 291, 14, 362, 63, 19231, 63, 1531, 480, 5799, 63, 815, 531, 267, 340, 20654, 14, 15697, 63, 5799, 63, 815, 26, 288, 1978, 275, 298, 8254, 11441, 450, 82, 370, 450, 82, 2544, 1808, 283, 32176, 4065, 288, 1249, 275, 20654, 14, 5799, 63, 815, 12, 20654, 14, 15697, 63, 5799, 63, 815, 288, 746, 12577, 547, 8, 1160, 450, 1249, 9, 267, 291, 14, 589, 275, 359, 24708, 14, 5799, 63, 354, 61, 398, 8837, 63, 3174, 14, 14450, 63, 1419, 8, 277, 9, 267, 291, 14, 4441, 63, 1095, 3220, 342, 267, 291, 14, 4441, 63, 3220, 342, 267, 327, 3732, 1536, 3272, 13, 694, 1275, 5799, 1584, 1454, 26, 949, 1275, 5799, 13, 815, 267, 291, 14, 2491, 63, 1080, 14, 6282, 8, 6463, 14, 6463, 360, 4856, 5799, 1333, 398, 11393, 63, 1073, 63, 2324, 275, 20654, 14, 5799, 63, 354, 435, 1987, 5799, 13, 1073, 7, 267, 291, 14, 5799, 63, 1073, 275, 747, 14, 515, 14, 904, 8, 277, 14, 3174, 63, 694, 12, 11393, 63, 1073, 63, 2324, 9, 267, 291, 14, 5799, 63, 1095, 275, 20654, 14, 5799, 63, 1095, 267, 340, 291, 14, 5799, 63, 515, 365, 488, 26, 288, 291, 14, 5799, 63, 515, 275, 747, 14, 515, 14, 4832, 8, 24708, 14, 5799, 63, 1095, 9, 398, 1347, 275, 7666, 63, 515, 8, 277, 14, 5799, 63, 1095, 9, 267, 11393, 63, 515, 275, 7666, 63, 515, 8, 736, 14, 515, 14, 904, 8, 277, 14, 3174, 63, 694, 12, 6901, 291, 14, 5799, 63, 515, 430, 267, 340, 11393, 63, 515, 1137, 1347, 26, 288, 746, 31484, 8, 355, 4320, 5799, 13, 515, 1471, 506, 282, 3847, 931, 687, 314, 3907, 2, 355, 298, 2082, 370, 298, 435, 1347, 288, 776, 398, 327, 4155, 282, 4084, 367, 314, 2559, 1159, 1350, 267, 291, 14, 2686, 275, 11839, 8, 288, 1347, 12, 288, 6912, 5142, 8, 1375, 12, 747, 14, 515, 14, 4832, 8, 24708, 14, 5799, 63, 815, 1826, 288, 2199, 63, 354, 29, 24708, 14, 5799, 63, 354, 267, 776, 398, 299, 275, 291, 14, 5799, 63, 1095, 14, 1814, 8, 736, 14, 4127, 12, 15107, 267, 340, 299, 1137, 747, 14, 15594, 26, 288, 299, 275, 11541, 4805, 627, 334, 80, 14, 835, 7825, 435, 413, 9, 267, 291, 14, 2758, 63, 515, 275, 299, 267, 299, 275, 7666, 63, 515, 8, 736, 14, 515, 14, 904, 8, 277, 14, 3174, 63, 694, 12, 291, 14, 5799, 63, 515, 12, 299, 430, 267, 340, 299, 1137, 7666, 63, 515, 8, 736, 14, 15594, 304, 288, 746, 31484, 8, 355, 298, 6049, 1133, 664, 282, 12137, 931, 370, 3272, 2884, 687, 2, 355, 298, 12096, 2082, 401, 299, 12, 7666, 63, 515, 8, 736, 14, 15594, 430, 339, 347, 3907, 63, 509, 63, 31688, 8, 277, 304, 267, 340, 3816, 14, 4521, 19, 436, 2519, 8, 277, 14, 4972, 12, 283, 1180, 63, 18, 475, 19, 297, 756, 304, 288, 327, 982, 781, 1255, 499, 475, 19, 781, 883, 440, 886, 642, 16304, 26, 953, 327, 7523, 3341, 365, 1536, 13, 475, 13, 602, 288, 291, 14, 264, 8489, 63, 1531, 360, 1506, 63, 647, 297, 16304, 29, 16, 9, 288, 291, 14, 1065, 63, 1531, 360, 1506, 63, 647, 358, 288, 20575, 63, 1760, 275, 291, 14, 362, 63, 19231, 63, 1531, 480, 1506, 63, 647, 531, 288, 1900, 63, 515, 275, 7666, 63, 515, 8, 66, 647, 63, 1760, 14, 1506, 63, 773, 9, 953, 327, 6516, 5478, 288, 291, 14, 264, 8489, 63, 1531, 360, 5799, 63, 815, 297, 11393, 63, 1095, 29, 1506, 63, 515, 9, 288, 291, 14, 1065, 63, 1531, 360, 5799, 63, 815, 358, 953, 291, 14, 264, 8489, 63, 1531, 360, 1506, 63, 832, 297, 16304, 29, 16, 9, 288, 291, 14, 1065, 63, 1531, 360, 1506, 63, 832, 358, 953, 327, 14811, 384, 11393, 13, 1073, 436, 8837, 13, 3174, 14, 13316, 288, 20654, 63, 1760, 275, 291, 14, 362, 63, 19231, 63, 1531, 480, 5799, 63, 815, 531, 288, 291, 14, 5799, 63, 515, 275, 1900, 63, 515, 288, 291, 14, 2686, 14, 1985, 275, 1900, 63, 515, 288, 327, 5787, 288, 291, 14, 2686, 423, 3780, 275, 6912, 5142, 8, 1506, 63, 515, 12, 20654, 63, 1760, 14, 5799, 63, 815, 9, 267, 587, 26, 288, 327, 23952 ]
[ 7065, 14, 1974, 492, 3957, 63, 515, 199, 504, 7065, 492, 943, 199, 504, 7065, 14, 2550, 492, 12577, 547, 12, 31484, 199, 646, 747, 199, 646, 5739, 199, 646, 5890, 199, 199, 504, 9116, 14, 18587, 492, 3816, 199, 199, 504, 5496, 63, 4435, 492, 11839, 12, 6912, 5142, 12, 7666, 63, 515, 199, 504, 9116, 14, 1531, 14, 13581, 63, 3174, 492, 8837, 63, 3174, 199, 646, 9116, 421, 199, 533, 477, 7549, 8, 13581, 63, 3174, 304, 272, 408, 1084, 1536, 2559, 367, 16367, 624, 339, 1369, 275, 298, 3174, 2559, 315, 283, 31688, 818, 4065, 339, 922, 63, 1419, 275, 8837, 63, 3174, 14, 751, 63, 1419, 435, 359, 267, 1689, 19502, 401, 298, 85, 401, 298, 1358, 3174, 642, 1350, 2559, 1288, 267, 1689, 5799, 13, 515, 11107, 488, 12, 298, 1084, 314, 931, 370, 506, 1202, 315, 314, 1275, 5799, 13, 1073, 570, 1288, 272, 1622, 339, 5046, 63, 1419, 275, 8837, 63, 3174, 14, 4871, 63, 1419, 435, 788, 19502, 418, 339, 1414, 63, 10235, 83, 63, 4958, 275, 756, 221, 327, 4278, 1300, 339, 347, 1255, 8, 277, 304, 267, 340, 291, 14, 19502, 26, 288, 291, 14, 3029, 63, 1023, 275, 715, 288, 291, 14, 19502, 63, 1073, 342, 267, 587, 26, 288, 291, 14, 3174, 63, 509, 63, 31688, 342, 267, 291, 14, 4050, 63, 6667, 63, 1419, 342, 339, 347, 8265, 63, 1419, 8, 277, 304, 267, 291, 14, 19502, 275, 488, 267, 291, 14, 5799, 63, 515, 275, 488, 267, 8837, 63, 3174, 14, 8489, 63, 1419, 8, 277, 9, 267, 291, 14, 2758, 63, 515, 275, 488, 267, 291, 14, 9223, 63, 1574, 63, 504, 275, 7815, 221, 327, 3544, 1331, 22151, 4903, 315, 1094, 694, 339, 347, 17284, 63, 1419, 8, 277, 304, 267, 20654, 275, 291, 14, 362, 63, 19231, 63, 1531, 480, 5799, 63, 815, 531, 267, 340, 20654, 14, 15697, 63, 5799, 63, 815, 26, 288, 1978, 275, 298, 8254, 11441, 450, 82, 370, 450, 82, 2544, 1808, 283, 32176, 4065, 288, 1249, 275, 20654, 14, 5799, 63, 815, 12, 20654, 14, 15697, 63, 5799, 63, 815, 288, 746, 12577, 547, 8, 1160, 450, 1249, 9, 267, 291, 14, 589, 275, 359, 24708, 14, 5799, 63, 354, 61, 398, 8837, 63, 3174, 14, 14450, 63, 1419, 8, 277, 9, 267, 291, 14, 4441, 63, 1095, 3220, 342, 267, 291, 14, 4441, 63, 3220, 342, 267, 327, 3732, 1536, 3272, 13, 694, 1275, 5799, 1584, 1454, 26, 949, 1275, 5799, 13, 815, 267, 291, 14, 2491, 63, 1080, 14, 6282, 8, 6463, 14, 6463, 360, 4856, 5799, 1333, 398, 11393, 63, 1073, 63, 2324, 275, 20654, 14, 5799, 63, 354, 435, 1987, 5799, 13, 1073, 7, 267, 291, 14, 5799, 63, 1073, 275, 747, 14, 515, 14, 904, 8, 277, 14, 3174, 63, 694, 12, 11393, 63, 1073, 63, 2324, 9, 267, 291, 14, 5799, 63, 1095, 275, 20654, 14, 5799, 63, 1095, 267, 340, 291, 14, 5799, 63, 515, 365, 488, 26, 288, 291, 14, 5799, 63, 515, 275, 747, 14, 515, 14, 4832, 8, 24708, 14, 5799, 63, 1095, 9, 398, 1347, 275, 7666, 63, 515, 8, 277, 14, 5799, 63, 1095, 9, 267, 11393, 63, 515, 275, 7666, 63, 515, 8, 736, 14, 515, 14, 904, 8, 277, 14, 3174, 63, 694, 12, 6901, 291, 14, 5799, 63, 515, 430, 267, 340, 11393, 63, 515, 1137, 1347, 26, 288, 746, 31484, 8, 355, 4320, 5799, 13, 515, 1471, 506, 282, 3847, 931, 687, 314, 3907, 2, 355, 298, 2082, 370, 298, 435, 1347, 288, 776, 398, 327, 4155, 282, 4084, 367, 314, 2559, 1159, 1350, 267, 291, 14, 2686, 275, 11839, 8, 288, 1347, 12, 288, 6912, 5142, 8, 1375, 12, 747, 14, 515, 14, 4832, 8, 24708, 14, 5799, 63, 815, 1826, 288, 2199, 63, 354, 29, 24708, 14, 5799, 63, 354, 267, 776, 398, 299, 275, 291, 14, 5799, 63, 1095, 14, 1814, 8, 736, 14, 4127, 12, 15107, 267, 340, 299, 1137, 747, 14, 15594, 26, 288, 299, 275, 11541, 4805, 627, 334, 80, 14, 835, 7825, 435, 413, 9, 267, 291, 14, 2758, 63, 515, 275, 299, 267, 299, 275, 7666, 63, 515, 8, 736, 14, 515, 14, 904, 8, 277, 14, 3174, 63, 694, 12, 291, 14, 5799, 63, 515, 12, 299, 430, 267, 340, 299, 1137, 7666, 63, 515, 8, 736, 14, 15594, 304, 288, 746, 31484, 8, 355, 298, 6049, 1133, 664, 282, 12137, 931, 370, 3272, 2884, 687, 2, 355, 298, 12096, 2082, 401, 299, 12, 7666, 63, 515, 8, 736, 14, 15594, 430, 339, 347, 3907, 63, 509, 63, 31688, 8, 277, 304, 267, 340, 3816, 14, 4521, 19, 436, 2519, 8, 277, 14, 4972, 12, 283, 1180, 63, 18, 475, 19, 297, 756, 304, 288, 327, 982, 781, 1255, 499, 475, 19, 781, 883, 440, 886, 642, 16304, 26, 953, 327, 7523, 3341, 365, 1536, 13, 475, 13, 602, 288, 291, 14, 264, 8489, 63, 1531, 360, 1506, 63, 647, 297, 16304, 29, 16, 9, 288, 291, 14, 1065, 63, 1531, 360, 1506, 63, 647, 358, 288, 20575, 63, 1760, 275, 291, 14, 362, 63, 19231, 63, 1531, 480, 1506, 63, 647, 531, 288, 1900, 63, 515, 275, 7666, 63, 515, 8, 66, 647, 63, 1760, 14, 1506, 63, 773, 9, 953, 327, 6516, 5478, 288, 291, 14, 264, 8489, 63, 1531, 360, 5799, 63, 815, 297, 11393, 63, 1095, 29, 1506, 63, 515, 9, 288, 291, 14, 1065, 63, 1531, 360, 5799, 63, 815, 358, 953, 291, 14, 264, 8489, 63, 1531, 360, 1506, 63, 832, 297, 16304, 29, 16, 9, 288, 291, 14, 1065, 63, 1531, 360, 1506, 63, 832, 358, 953, 327, 14811, 384, 11393, 13, 1073, 436, 8837, 13, 3174, 14, 13316, 288, 20654, 63, 1760, 275, 291, 14, 362, 63, 19231, 63, 1531, 480, 5799, 63, 815, 531, 288, 291, 14, 5799, 63, 515, 275, 1900, 63, 515, 288, 291, 14, 2686, 14, 1985, 275, 1900, 63, 515, 288, 327, 5787, 288, 291, 14, 2686, 423, 3780, 275, 6912, 5142, 8, 1506, 63, 515, 12, 20654, 63, 1760, 14, 5799, 63, 815, 9, 267, 587, 26, 288, 327, 23952, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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 from __future__ import unicode_literals import base64 import re import time from .common import InfoExtractor from ..compat import compat_urlparse from ..utils import ( ExtractorError, float_or_none, remove_end, std_headers, struct_unpack, ) def _decrypt_url(png): encrypted_data = base64.b64decode(png.encode('utf-8')) text_index = encrypted_data.find(b'tEXt') text_chunk = encrypted_data[text_index - 4:] length = struct_unpack('!I', text_chunk[:4])[0] # Use bytearray to get integers when iterating in both python 2.x and 3.x data = bytearray(text_chunk[8:8 + length]) data = [chr(b) for b in data if b != 0] hash_index = data.index('#') alphabet_data = data[:hash_index] url_data = data[hash_index + 1:] alphabet = [] e = 0 d = 0 for l in alphabet_data: if d == 0: alphabet.append(l) d = e = (e + 1) % 4 else: d -= 1 url = '' f = 0 e = 3 b = 1 for letter in url_data: if f == 0: l = int(letter) * 10 f = 1 else: if e == 0: l += int(letter) url += alphabet[l] e = (b + 3) % 4 f = 0 b += 1 else: e -= 1 return url class RTVEALaCartaIE(InfoExtractor): IE_NAME = 'rtve.es:alacarta' IE_DESC = 'RTVE a la carta' _VALID_URL = r'http://www\.rtve\.es/(m/)?alacarta/videos/[^/]+/[^/]+/(?P<id>\d+)' _TESTS = [{ 'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/', 'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43', 'info_dict': { 'id': '2491869', 'ext': 'mp4', 'title': 'Balonmano - Swiss Cup masculina. Final: España-Suecia', 'duration': 5024.566, }, }, { 'note': 'Live stream', 'url': 'http://www.rtve.es/alacarta/videos/television/24h-live/1694255/', 'info_dict': { 'id': '1694255', 'ext': 'flv', 'title': 'TODO', }, 'skip': 'The f4m manifest can\'t be used yet', }, { 'url': 'http://www.rtve.es/m/alacarta/videos/cuentame-como-paso/cuentame-como-paso-t16-ultimo-minuto-nuestra-vida-capitulo-276/2969138/?media=tve', 'only_matching': True, }] def _real_initialize(self): user_agent_b64 = base64.b64encode(std_headers['User-Agent'].encode('utf-8')).decode('utf-8') manager_info = self._download_json( 'http://www.rtve.es/odin/loki/' + user_agent_b64, None, 'Fetching manager info') self._manager = manager_info['manager'] def _real_extract(self, url): mobj = re.match(self._VALID_URL, url) video_id = mobj.group('id') info = self._download_json( 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id, video_id)['page']['items'][0] if info['state'] == 'DESPU': raise ExtractorError('The video is no longer available', expected=True) png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/%s/videos/%s.png' % (self._manager, video_id) png = self._download_webpage(png_url, video_id, 'Downloading url information') video_url = _decrypt_url(png) if not video_url.endswith('.f4m'): auth_url = video_url.replace( 'resources/', 'auth/resources/' ).replace('.net.rtve', '.multimedia.cdn.rtve') video_path = self._download_webpage( auth_url, video_id, 'Getting video url') # Use mvod1.akcdn instead of flash.akamaihd.multimedia.cdn to get # the right Content-Length header and the mp4 format video_url = compat_urlparse.urljoin( 'http://mvod1.akcdn.rtve.es/', video_path) subtitles = None if info.get('sbtFile') is not None: subtitles = self.extract_subtitles(video_id, info['sbtFile']) return { 'id': video_id, 'title': info['title'], 'url': video_url, 'thumbnail': info.get('image'), 'page_url': url, 'subtitles': subtitles, 'duration': float_or_none(info.get('duration'), scale=1000), } def _get_subtitles(self, video_id, sub_file): subs = self._download_json( sub_file + '.json', video_id, 'Downloading subtitles info')['page']['items'] return dict( (s['lang'], [{'ext': 'vtt', 'url': s['src']}]) for s in subs) class RTVEInfantilIE(InfoExtractor): IE_NAME = 'rtve.es:infantil' IE_DESC = 'RTVE infantil' _VALID_URL = r'https?://(?:www\.)?rtve\.es/infantil/serie/(?P<show>[^/]*)/video/(?P<short_title>[^/]*)/(?P<id>[0-9]+)/' _TESTS = [{ 'url': 'http://www.rtve.es/infantil/serie/cleo/video/maneras-vivir/3040283/', 'md5': '915319587b33720b8e0357caaa6617e6', 'info_dict': { 'id': '3040283', 'ext': 'mp4', 'title': 'Maneras de vivir', 'thumbnail': 'http://www.rtve.es/resources/jpg/6/5/1426182947956.JPG', 'duration': 357.958, }, }] def _real_extract(self, url): video_id = self._match_id(url) info = self._download_json( 'http://www.rtve.es/api/videos/%s/config/alacarta_videos.json' % video_id, video_id)['page']['items'][0] webpage = self._download_webpage(url, video_id) vidplayer_id = self._search_regex( r' id="vidplayer([0-9]+)"', webpage, 'internal video ID') png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % vidplayer_id png = self._download_webpage(png_url, video_id, 'Downloading url information') video_url = _decrypt_url(png) return { 'id': video_id, 'ext': 'mp4', 'title': info['title'], 'url': video_url, 'thumbnail': info.get('image'), 'duration': float_or_none(info.get('duration'), scale=1000), } class RTVELiveIE(InfoExtractor): IE_NAME = 'rtve.es:live' IE_DESC = 'RTVE.es live streams' _VALID_URL = r'http://www\.rtve\.es/(?:deportes/directo|noticias|television)/(?P<id>[a-zA-Z0-9-]+)' _TESTS = [{ 'url': 'http://www.rtve.es/noticias/directo-la-1/', 'info_dict': { 'id': 'directo-la-1', 'ext': 'flv', 'title': 're:^La 1 de TVE [0-9]{4}-[0-9]{2}-[0-9]{2}Z[0-9]{6}$', }, 'params': { 'skip_download': 'live stream', } }] def _real_extract(self, url): mobj = re.match(self._VALID_URL, url) start_time = time.gmtime() video_id = mobj.group('id') webpage = self._download_webpage(url, video_id) player_url = self._search_regex( r'<param name="movie" value="([^"]+)"/>', webpage, 'player URL') title = remove_end(self._og_search_title(webpage), ' en directo') title += ' ' + time.strftime('%Y-%m-%dZ%H%M%S', start_time) vidplayer_id = self._search_regex( r' id="vidplayer([0-9]+)"', webpage, 'internal video ID') png_url = 'http://www.rtve.es/ztnr/movil/thumbnail/default/videos/%s.png' % vidplayer_id png = self._download_webpage(png_url, video_id, 'Downloading url information') video_url = _decrypt_url(png) return { 'id': video_id, 'ext': 'flv', 'title': title, 'url': video_url, 'app': 'rtve-live-live?ovpfv=2.1.2', 'player_url': player_url, 'rtmp_live': True, }
unlicense
[ 3, 2644, 26, 2774, 13, 24, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 1300, 772, 199, 646, 295, 199, 646, 900, 199, 199, 504, 1275, 2330, 492, 21298, 199, 504, 2508, 5819, 492, 8434, 63, 10290, 199, 504, 2508, 1208, 492, 334, 272, 19783, 12, 272, 2069, 63, 269, 63, 3592, 12, 272, 2813, 63, 500, 12, 272, 2418, 63, 2139, 12, 272, 2702, 63, 5301, 12, 199, 9, 421, 199, 318, 485, 15682, 63, 633, 8, 4524, 304, 272, 14862, 63, 576, 275, 1300, 772, 14, 66, 772, 2708, 8, 4524, 14, 2143, 360, 1624, 13, 24, 1333, 272, 1318, 63, 1080, 275, 14862, 63, 576, 14, 1623, 8, 66, 1133, 1438, 84, 358, 272, 1318, 63, 4604, 275, 14862, 63, 576, 59, 505, 63, 1080, 446, 841, 2938, 272, 2582, 275, 2702, 63, 5301, 16157, 41, 297, 1318, 63, 4604, 1491, 20, 11057, 16, 61, 272, 327, 3645, 11640, 370, 664, 9446, 1380, 25012, 315, 3865, 2366, 499, 14, 88, 436, 650, 14, 88, 272, 666, 275, 11640, 8, 505, 63, 4604, 59, 24, 26, 24, 435, 2582, 566, 272, 666, 275, 359, 10194, 8, 66, 9, 367, 330, 315, 666, 340, 330, 1137, 378, 61, 272, 2631, 63, 1080, 275, 666, 14, 1080, 7863, 358, 272, 27230, 63, 576, 275, 666, 1491, 2227, 63, 1080, 61, 272, 1166, 63, 576, 275, 666, 59, 2227, 63, 1080, 435, 413, 2938, 339, 27230, 275, 942, 272, 325, 275, 378, 272, 366, 275, 378, 272, 367, 634, 315, 27230, 63, 576, 26, 267, 340, 366, 508, 378, 26, 288, 27230, 14, 740, 8, 76, 9, 288, 366, 275, 325, 275, 334, 69, 435, 413, 9, 450, 841, 267, 587, 26, 288, 366, 4862, 413, 272, 1166, 275, 2125, 272, 289, 275, 378, 272, 325, 275, 650, 272, 330, 275, 413, 272, 367, 8082, 315, 1166, 63, 576, 26, 267, 340, 289, 508, 378, 26, 288, 634, 275, 1109, 8, 9269, 9, 627, 1616, 288, 289, 275, 413, 267, 587, 26, 288, 340, 325, 508, 378, 26, 355, 634, 847, 1109, 8, 9269, 9, 355, 1166, 847, 27230, 59, 76, 61, 355, 325, 275, 334, 66, 435, 650, 9, 450, 841, 355, 289, 275, 378, 355, 330, 847, 413, 288, 587, 26, 355, 325, 4862, 413, 339, 372, 1166, 421, 199, 533, 24090, 2524, 748, 65, 16034, 502, 4332, 8, 18283, 304, 272, 15292, 63, 2339, 275, 283, 2591, 432, 14, 397, 26, 279, 645, 29549, 7, 272, 15292, 63, 15119, 275, 283, 11876, 2524, 282, 1127, 9590, 502, 7, 272, 485, 5600, 63, 2632, 275, 519, 7, 1014, 921, 1544, 4537, 2591, 432, 4537, 397, 7985, 77, 15, 5547, 279, 645, 29549, 15, 11418, 15, 26285, 15, 26285, 9448, 48, 28, 344, 3072, 68, 29600, 339, 485, 7569, 275, 8910, 267, 283, 633, 356, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 279, 645, 29549, 15, 11418, 15, 4982, 265, 1237, 79, 15, 79, 13, 3519, 19857, 13, 17500, 13, 5892, 3119, 13765, 13, 5094, 13, 397, 80, 6738, 13, 3309, 16521, 15, 11032, 1085, 1876, 3678, 267, 283, 1064, 21, 356, 283, 17, 68, 1887, 66, 23, 69, 17, 696, 23, 65, 2194, 996, 67, 1367, 65, 20, 4361, 17, 66, 2259, 70, 17, 66, 2824, 297, 267, 283, 815, 63, 807, 356, 469, 288, 283, 344, 356, 283, 11032, 1085, 1876, 297, 288, 283, 832, 356, 283, 311, 20, 297, 288, 283, 1213, 356, 283, 13129, 265, 1237, 79, 446, 16666, 19857, 445, 384, 28065, 3119, 13765, 14, 21789, 26, 662, 3770, 22692, 65, 13, 51, 310, 16521, 297, 288, 283, 5553, 356, 959, 5284, 14, 29982, 12, 267, 1660, 272, 1660, 469, 267, 283, 4610, 356, 283, 17458, 2547, 297, 267, 283, 633, 356, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 279, 645, 29549, 15, 11418, 15, 15253, 2317, 15, 1194, 72, 13, 6442, 15, 975, 2635, 2299, 3678, 267, 283, 815, 63, 807, 356, 469, 288, 283, 344, 356, 283, 975, 2635, 2299, 297, 288, 283, 832, 356, 283, 22753, 297, 288, 283, 1213, 356, 283, 11768, 297, 267, 1660, 267, 283, 2759, 356, 283, 1918, 289, 20, 77, 7712, 883, 3985, 84, 506, 1202, 5966, 297, 272, 1660, 469, 267, 283, 633, 356, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 77, 15, 279, 645, 29549, 15, 11418, 15, 15140, 484, 313, 13, 331, 573, 13, 15534, 79, 15, 15140, 484, 313, 13, 331, 573, 13, 15534, 79, 13, 84, 975, 13, 1141, 573, 13, 827, 1283, 13, 78, 5291, 345, 13, 5017, 65, 13, 2874, 390, 13957, 13, 13319, 15, 1398, 1876, 8527, 10197, 4603, 29, 84, 432, 297, 267, 283, 2118, 63, 9467, 356, 715, 12, 272, 14877, 339, 347, 485, 3093, 63, 8489, 8, 277, 304, 267, 922, 63, 4054, 63, 66, 772, 275, 1300, 772, 14, 66, 772, 2143, 8, 1516, 63, 2139, 459, 1899, 13, 7788, 2278, 2143, 360, 1624, 13, 24, 11103, 2708, 360, 1624, 13, 24, 358, 267, 5256, 63, 815, 275, 291, 423, 4249, 63, 1001, 8, 288, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 364, 262, 15, 320, 8810, 4805, 435, 922, 63, 4054, 63, 66, 772, 12, 288, 488, 12, 283, 11135, 316, 5256, 2256, 358, 267, 291, 423, 2609, 275, 5256, 63, 815, 459, 2609, 418, 339, 347, 485, 3093, 63, 5005, 8, 277, 12, 1166, 304, 267, 14208, 275, 295, 14, 1431, 8, 277, 423, 5600, 63, 2632, 12, 1166, 9, 267, 3991, 63, 344, 275, 14208, 14, 923, 360, 344, 358, 267, 2256, 275, 291, 423, 4249, 63, 1001, 8, 288, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 1246, 15, 11418, 3149, 83, 15, 888, 15, 279, 645, 29549, 63, 11418, 14, 1001, 7, 450, 3991, 63, 344, 12, 288, 3991, 63, 344, 11820, 1606, 2545, 1744, 3488, 16, 61, 267, 340, 2256, 459, 929, 418, 508, 283, 4448, 6903, 356, 288, 746, 19783, 360, 1918, 3991, 365, 949, 8088, 2808, 297, 1420, 29, 549, 9, 267, 25296, 63, 633, 275, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 90, 5889, 82, 15, 14469, 382, 15 ]
[ 2644, 26, 2774, 13, 24, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 1300, 772, 199, 646, 295, 199, 646, 900, 199, 199, 504, 1275, 2330, 492, 21298, 199, 504, 2508, 5819, 492, 8434, 63, 10290, 199, 504, 2508, 1208, 492, 334, 272, 19783, 12, 272, 2069, 63, 269, 63, 3592, 12, 272, 2813, 63, 500, 12, 272, 2418, 63, 2139, 12, 272, 2702, 63, 5301, 12, 199, 9, 421, 199, 318, 485, 15682, 63, 633, 8, 4524, 304, 272, 14862, 63, 576, 275, 1300, 772, 14, 66, 772, 2708, 8, 4524, 14, 2143, 360, 1624, 13, 24, 1333, 272, 1318, 63, 1080, 275, 14862, 63, 576, 14, 1623, 8, 66, 1133, 1438, 84, 358, 272, 1318, 63, 4604, 275, 14862, 63, 576, 59, 505, 63, 1080, 446, 841, 2938, 272, 2582, 275, 2702, 63, 5301, 16157, 41, 297, 1318, 63, 4604, 1491, 20, 11057, 16, 61, 272, 327, 3645, 11640, 370, 664, 9446, 1380, 25012, 315, 3865, 2366, 499, 14, 88, 436, 650, 14, 88, 272, 666, 275, 11640, 8, 505, 63, 4604, 59, 24, 26, 24, 435, 2582, 566, 272, 666, 275, 359, 10194, 8, 66, 9, 367, 330, 315, 666, 340, 330, 1137, 378, 61, 272, 2631, 63, 1080, 275, 666, 14, 1080, 7863, 358, 272, 27230, 63, 576, 275, 666, 1491, 2227, 63, 1080, 61, 272, 1166, 63, 576, 275, 666, 59, 2227, 63, 1080, 435, 413, 2938, 339, 27230, 275, 942, 272, 325, 275, 378, 272, 366, 275, 378, 272, 367, 634, 315, 27230, 63, 576, 26, 267, 340, 366, 508, 378, 26, 288, 27230, 14, 740, 8, 76, 9, 288, 366, 275, 325, 275, 334, 69, 435, 413, 9, 450, 841, 267, 587, 26, 288, 366, 4862, 413, 272, 1166, 275, 2125, 272, 289, 275, 378, 272, 325, 275, 650, 272, 330, 275, 413, 272, 367, 8082, 315, 1166, 63, 576, 26, 267, 340, 289, 508, 378, 26, 288, 634, 275, 1109, 8, 9269, 9, 627, 1616, 288, 289, 275, 413, 267, 587, 26, 288, 340, 325, 508, 378, 26, 355, 634, 847, 1109, 8, 9269, 9, 355, 1166, 847, 27230, 59, 76, 61, 355, 325, 275, 334, 66, 435, 650, 9, 450, 841, 355, 289, 275, 378, 355, 330, 847, 413, 288, 587, 26, 355, 325, 4862, 413, 339, 372, 1166, 421, 199, 533, 24090, 2524, 748, 65, 16034, 502, 4332, 8, 18283, 304, 272, 15292, 63, 2339, 275, 283, 2591, 432, 14, 397, 26, 279, 645, 29549, 7, 272, 15292, 63, 15119, 275, 283, 11876, 2524, 282, 1127, 9590, 502, 7, 272, 485, 5600, 63, 2632, 275, 519, 7, 1014, 921, 1544, 4537, 2591, 432, 4537, 397, 7985, 77, 15, 5547, 279, 645, 29549, 15, 11418, 15, 26285, 15, 26285, 9448, 48, 28, 344, 3072, 68, 29600, 339, 485, 7569, 275, 8910, 267, 283, 633, 356, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 279, 645, 29549, 15, 11418, 15, 4982, 265, 1237, 79, 15, 79, 13, 3519, 19857, 13, 17500, 13, 5892, 3119, 13765, 13, 5094, 13, 397, 80, 6738, 13, 3309, 16521, 15, 11032, 1085, 1876, 3678, 267, 283, 1064, 21, 356, 283, 17, 68, 1887, 66, 23, 69, 17, 696, 23, 65, 2194, 996, 67, 1367, 65, 20, 4361, 17, 66, 2259, 70, 17, 66, 2824, 297, 267, 283, 815, 63, 807, 356, 469, 288, 283, 344, 356, 283, 11032, 1085, 1876, 297, 288, 283, 832, 356, 283, 311, 20, 297, 288, 283, 1213, 356, 283, 13129, 265, 1237, 79, 446, 16666, 19857, 445, 384, 28065, 3119, 13765, 14, 21789, 26, 662, 3770, 22692, 65, 13, 51, 310, 16521, 297, 288, 283, 5553, 356, 959, 5284, 14, 29982, 12, 267, 1660, 272, 1660, 469, 267, 283, 4610, 356, 283, 17458, 2547, 297, 267, 283, 633, 356, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 279, 645, 29549, 15, 11418, 15, 15253, 2317, 15, 1194, 72, 13, 6442, 15, 975, 2635, 2299, 3678, 267, 283, 815, 63, 807, 356, 469, 288, 283, 344, 356, 283, 975, 2635, 2299, 297, 288, 283, 832, 356, 283, 22753, 297, 288, 283, 1213, 356, 283, 11768, 297, 267, 1660, 267, 283, 2759, 356, 283, 1918, 289, 20, 77, 7712, 883, 3985, 84, 506, 1202, 5966, 297, 272, 1660, 469, 267, 283, 633, 356, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 77, 15, 279, 645, 29549, 15, 11418, 15, 15140, 484, 313, 13, 331, 573, 13, 15534, 79, 15, 15140, 484, 313, 13, 331, 573, 13, 15534, 79, 13, 84, 975, 13, 1141, 573, 13, 827, 1283, 13, 78, 5291, 345, 13, 5017, 65, 13, 2874, 390, 13957, 13, 13319, 15, 1398, 1876, 8527, 10197, 4603, 29, 84, 432, 297, 267, 283, 2118, 63, 9467, 356, 715, 12, 272, 14877, 339, 347, 485, 3093, 63, 8489, 8, 277, 304, 267, 922, 63, 4054, 63, 66, 772, 275, 1300, 772, 14, 66, 772, 2143, 8, 1516, 63, 2139, 459, 1899, 13, 7788, 2278, 2143, 360, 1624, 13, 24, 11103, 2708, 360, 1624, 13, 24, 358, 267, 5256, 63, 815, 275, 291, 423, 4249, 63, 1001, 8, 288, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 364, 262, 15, 320, 8810, 4805, 435, 922, 63, 4054, 63, 66, 772, 12, 288, 488, 12, 283, 11135, 316, 5256, 2256, 358, 267, 291, 423, 2609, 275, 5256, 63, 815, 459, 2609, 418, 339, 347, 485, 3093, 63, 5005, 8, 277, 12, 1166, 304, 267, 14208, 275, 295, 14, 1431, 8, 277, 423, 5600, 63, 2632, 12, 1166, 9, 267, 3991, 63, 344, 275, 14208, 14, 923, 360, 344, 358, 267, 2256, 275, 291, 423, 4249, 63, 1001, 8, 288, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 1246, 15, 11418, 3149, 83, 15, 888, 15, 279, 645, 29549, 63, 11418, 14, 1001, 7, 450, 3991, 63, 344, 12, 288, 3991, 63, 344, 11820, 1606, 2545, 1744, 3488, 16, 61, 267, 340, 2256, 459, 929, 418, 508, 283, 4448, 6903, 356, 288, 746, 19783, 360, 1918, 3991, 365, 949, 8088, 2808, 297, 1420, 29, 549, 9, 267, 25296, 63, 633, 275, 283, 1014, 921, 1544, 14, 2591, 432, 14, 397, 15, 90, 5889, 82, 15, 14469, 382, 15, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
craigcitro/pydatalab
google/datalab/stackdriver/monitoring/_query.py
5
2818
# Copyright 2016 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except # in compliance with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express # or implied. See the License for the specific language governing permissions and limitations under # the License. """Provides access to metric data as pandas dataframes.""" from __future__ import absolute_import import google.cloud.monitoring from . import _query_metadata from . import _utils class Query(google.cloud.monitoring.Query): """Query object for retrieving metric data.""" def __init__(self, metric_type=google.cloud.monitoring.Query.DEFAULT_METRIC_TYPE, end_time=None, days=0, hours=0, minutes=0, context=None): """Initializes the core query parameters. The start time (exclusive) is determined by combining the values of ``days``, ``hours``, and ``minutes``, and subtracting the resulting duration from the end time. It is also allowed to omit the end time and duration here, in which case :meth:`~google.cloud.monitoring.query.Query.select_interval` must be called before the query is executed. Args: metric_type: The metric type name. The default value is :data:`Query.DEFAULT_METRIC_TYPE <google.cloud.monitoring.query.Query.DEFAULT_METRIC_TYPE>`, but please note that this default value is provided only for demonstration purposes and is subject to change. end_time: The end time (inclusive) of the time interval for which results should be returned, as a datetime object. The default is the start of the current minute. days: The number of days in the time interval. hours: The number of hours in the time interval. minutes: The number of minutes in the time interval. context: An optional Context object to use instead of the global default. Raises: ValueError: ``end_time`` was specified but ``days``, ``hours``, and ``minutes`` are all zero. If you really want to specify a point in time, use :meth:`~google.cloud.monitoring.query.Query.select_interval`. """ client = _utils.make_client(context) super(Query, self).__init__(client, metric_type, end_time=end_time, days=days, hours=hours, minutes=minutes) def metadata(self): """Retrieves the metadata for the query.""" return _query_metadata.QueryMetadata(self)
apache-2.0
[ 3, 1898, 7800, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 199, 3, 315, 4151, 543, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 1854, 1334, 314, 844, 199, 3, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 199, 3, 503, 2478, 14, 221, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 1334, 199, 3, 314, 844, 14, 199, 199, 624, 17473, 2879, 370, 6370, 666, 465, 10634, 666, 8444, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 6233, 14, 4091, 14, 20554, 199, 199, 504, 1275, 492, 485, 1131, 63, 2343, 199, 504, 1275, 492, 485, 1208, 421, 199, 533, 8133, 8, 3098, 14, 4091, 14, 20554, 14, 3227, 304, 523, 408, 3227, 909, 367, 23812, 6370, 666, 1041, 819, 347, 636, 826, 721, 277, 12, 2049, 6370, 63, 466, 29, 3098, 14, 4091, 14, 20554, 14, 3227, 14, 3472, 63, 20141, 63, 2711, 12, 2049, 1284, 63, 521, 29, 403, 12, 7609, 29, 16, 12, 10857, 29, 16, 12, 9395, 29, 16, 12, 1067, 29, 403, 304, 272, 408, 23489, 314, 6170, 1827, 2633, 14, 339, 710, 1343, 900, 334, 12730, 9, 365, 12037, 701, 29391, 314, 272, 1338, 402, 1124, 4899, 4542, 1124, 8419, 4542, 436, 1124, 10430, 4542, 436, 24129, 316, 272, 314, 9183, 7373, 687, 314, 1284, 900, 14, 339, 2779, 365, 2597, 4370, 370, 19413, 314, 1284, 900, 436, 7373, 2348, 12, 272, 315, 1314, 1930, 520, 5247, 6054, 3098, 14, 4091, 14, 20554, 14, 1131, 14, 3227, 14, 2416, 63, 4284, 64, 272, 1471, 506, 2797, 2544, 314, 1827, 365, 7934, 14, 339, 3033, 26, 489, 6370, 63, 466, 26, 710, 6370, 730, 536, 14, 710, 849, 574, 365, 881, 520, 576, 1705, 3227, 14, 3472, 63, 20141, 63, 2711, 881, 665, 3098, 14, 4091, 14, 20554, 14, 1131, 14, 3227, 14, 3472, 63, 20141, 63, 2711, 30, 3559, 1325, 881, 8749, 5317, 626, 642, 849, 574, 365, 2741, 1454, 367, 881, 23789, 270, 1754, 12901, 436, 365, 5420, 370, 1570, 14, 489, 1284, 63, 521, 26, 710, 1284, 900, 334, 26062, 9, 402, 314, 900, 6252, 367, 1314, 881, 2058, 1077, 506, 2138, 12, 465, 282, 2197, 909, 14, 710, 849, 881, 365, 314, 1343, 402, 314, 1453, 12709, 14, 489, 7609, 26, 710, 1329, 402, 7609, 315, 314, 900, 6252, 14, 489, 10857, 26, 710, 1329, 402, 10857, 315, 314, 900, 6252, 14, 489, 9395, 26, 710, 1329, 402, 9395, 315, 314, 900, 6252, 14, 489, 1067, 26, 1626, 2716, 9470, 909, 370, 675, 3140, 402, 314, 2288, 849, 14, 339, 6218, 26, 267, 1722, 26, 1124, 500, 63, 521, 1040, 1990, 2013, 1325, 1124, 4899, 4542, 1124, 8419, 4542, 436, 288, 1124, 10430, 1040, 787, 1006, 4697, 14, 982, 1265, 7710, 2934, 370, 4165, 282, 2376, 315, 288, 900, 12, 675, 288, 520, 5247, 6054, 3098, 14, 4091, 14, 20554, 14, 1131, 14, 3227, 14, 2416, 63, 4284, 2313, 272, 408, 272, 1890, 275, 485, 1208, 14, 1875, 63, 1258, 8, 1100, 9, 272, 1613, 8, 3227, 12, 291, 2843, 826, 721, 1258, 12, 6370, 63, 466, 12, 1816, 1284, 63, 521, 29, 500, 63, 521, 12, 1816, 7609, 29, 4899, 12, 10857, 29, 8419, 12, 9395, 29, 10430, 9, 819, 347, 3341, 8, 277, 304, 272, 408, 28112, 314, 3341, 367, 314, 1827, 1041, 272, 372, 485, 1131, 63, 2343, 14, 3227, 5142, 8, 277, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1898, 7800, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 199, 3, 315, 4151, 543, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 1854, 1334, 314, 844, 199, 3, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 199, 3, 503, 2478, 14, 221, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 1334, 199, 3, 314, 844, 14, 199, 199, 624, 17473, 2879, 370, 6370, 666, 465, 10634, 666, 8444, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 6233, 14, 4091, 14, 20554, 199, 199, 504, 1275, 492, 485, 1131, 63, 2343, 199, 504, 1275, 492, 485, 1208, 421, 199, 533, 8133, 8, 3098, 14, 4091, 14, 20554, 14, 3227, 304, 523, 408, 3227, 909, 367, 23812, 6370, 666, 1041, 819, 347, 636, 826, 721, 277, 12, 2049, 6370, 63, 466, 29, 3098, 14, 4091, 14, 20554, 14, 3227, 14, 3472, 63, 20141, 63, 2711, 12, 2049, 1284, 63, 521, 29, 403, 12, 7609, 29, 16, 12, 10857, 29, 16, 12, 9395, 29, 16, 12, 1067, 29, 403, 304, 272, 408, 23489, 314, 6170, 1827, 2633, 14, 339, 710, 1343, 900, 334, 12730, 9, 365, 12037, 701, 29391, 314, 272, 1338, 402, 1124, 4899, 4542, 1124, 8419, 4542, 436, 1124, 10430, 4542, 436, 24129, 316, 272, 314, 9183, 7373, 687, 314, 1284, 900, 14, 339, 2779, 365, 2597, 4370, 370, 19413, 314, 1284, 900, 436, 7373, 2348, 12, 272, 315, 1314, 1930, 520, 5247, 6054, 3098, 14, 4091, 14, 20554, 14, 1131, 14, 3227, 14, 2416, 63, 4284, 64, 272, 1471, 506, 2797, 2544, 314, 1827, 365, 7934, 14, 339, 3033, 26, 489, 6370, 63, 466, 26, 710, 6370, 730, 536, 14, 710, 849, 574, 365, 881, 520, 576, 1705, 3227, 14, 3472, 63, 20141, 63, 2711, 881, 665, 3098, 14, 4091, 14, 20554, 14, 1131, 14, 3227, 14, 3472, 63, 20141, 63, 2711, 30, 3559, 1325, 881, 8749, 5317, 626, 642, 849, 574, 365, 2741, 1454, 367, 881, 23789, 270, 1754, 12901, 436, 365, 5420, 370, 1570, 14, 489, 1284, 63, 521, 26, 710, 1284, 900, 334, 26062, 9, 402, 314, 900, 6252, 367, 1314, 881, 2058, 1077, 506, 2138, 12, 465, 282, 2197, 909, 14, 710, 849, 881, 365, 314, 1343, 402, 314, 1453, 12709, 14, 489, 7609, 26, 710, 1329, 402, 7609, 315, 314, 900, 6252, 14, 489, 10857, 26, 710, 1329, 402, 10857, 315, 314, 900, 6252, 14, 489, 9395, 26, 710, 1329, 402, 9395, 315, 314, 900, 6252, 14, 489, 1067, 26, 1626, 2716, 9470, 909, 370, 675, 3140, 402, 314, 2288, 849, 14, 339, 6218, 26, 267, 1722, 26, 1124, 500, 63, 521, 1040, 1990, 2013, 1325, 1124, 4899, 4542, 1124, 8419, 4542, 436, 288, 1124, 10430, 1040, 787, 1006, 4697, 14, 982, 1265, 7710, 2934, 370, 4165, 282, 2376, 315, 288, 900, 12, 675, 288, 520, 5247, 6054, 3098, 14, 4091, 14, 20554, 14, 1131, 14, 3227, 14, 2416, 63, 4284, 2313, 272, 408, 272, 1890, 275, 485, 1208, 14, 1875, 63, 1258, 8, 1100, 9, 272, 1613, 8, 3227, 12, 291, 2843, 826, 721, 1258, 12, 6370, 63, 466, 12, 1816, 1284, 63, 521, 29, 500, 63, 521, 12, 1816, 7609, 29, 4899, 12, 10857, 29, 8419, 12, 9395, 29, 10430, 9, 819, 347, 3341, 8, 277, 304, 272, 408, 28112, 314, 3341, 367, 314, 1827, 1041, 272, 372, 485, 1131, 63, 2343, 14, 3227, 5142, 8, 277, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
p0cisk/Quantum-GIS
tests/src/python/test_qgscomposerlabel.py
5
3977
# -*- coding: utf-8 -*- ''' test_qgscomposerlabel.py -------------------------------------- Date : Oct 2012 Copyright : (C) 2012 by Dr. Hugo Mercier email : hugo dot mercier at oslandia dot com *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ ''' import qgis # NOQA from qgis.testing import start_app, unittest from qgis.PyQt.QtCore import QFileInfo, QDate, QDateTime from qgis.core import QgsVectorLayer, QgsMapLayerRegistry, QgsMapSettings, QgsComposition, QgsComposerLabel, QgsFeatureRequest, QgsFeature, QgsExpression from utilities import unitTestDataPath start_app() class TestQgsComposerLabel(unittest.TestCase): def testCase(self): TEST_DATA_DIR = unitTestDataPath() vectorFileInfo = QFileInfo(TEST_DATA_DIR + "/france_parts.shp") mVectorLayer = QgsVectorLayer(vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), "ogr") QgsMapLayerRegistry.instance().addMapLayers([mVectorLayer]) # create composition with composer map mapSettings = QgsMapSettings() mapSettings.setLayers([mVectorLayer.id()]) mapSettings.setCrsTransformEnabled(False) mComposition = QgsComposition(mapSettings) mComposition.setPaperSize(297, 210) mLabel = QgsComposerLabel(mComposition) mComposition.addComposerLabel(mLabel) self.evaluation_test(mComposition, mLabel) self.feature_evaluation_test(mComposition, mLabel, mVectorLayer) self.page_evaluation_test(mComposition, mLabel, mVectorLayer) def evaluation_test(self, mComposition, mLabel): # $CURRENT_DATE evaluation mLabel.setText("__$CURRENT_DATE__") assert mLabel.displayText() == ("__" + QDate.currentDate().toString() + "__") # $CURRENT_DATE() evaluation mLabel.setText("__$CURRENT_DATE(dd)(ok)__") expected = "__" + QDateTime.currentDateTime().toString("dd") + "(ok)__" assert mLabel.displayText() == expected # $CURRENT_DATE() evaluation (inside an expression) mLabel.setText("__[%$CURRENT_DATE(dd) + 1%](ok)__") dd = QDate.currentDate().day() expected = "__%d(ok)__" % (dd + 1) assert mLabel.displayText() == expected # expression evaluation (without associated feature) mLabel.setText("__[%\"NAME_1\"%][%21*2%]__") assert mLabel.displayText() == "__[NAME_1]42__" def feature_evaluation_test(self, mComposition, mLabel, mVectorLayer): atlas = mComposition.atlasComposition() atlas.setCoverageLayer(mVectorLayer) atlas.setEnabled(True) mComposition.setAtlasMode(QgsComposition.ExportAtlas) mLabel.setText("[%\"NAME_1\"||'_ok'%]") atlas.beginRender() atlas.prepareForFeature(0) assert mLabel.displayText() == "Basse-Normandie_ok" atlas.prepareForFeature(1) assert mLabel.displayText() == "Bretagne_ok" def page_evaluation_test(self, mComposition, mLabel, mVectorLayer): mComposition.setNumPages(2) mLabel.setText("[%@layout_page||'/'||@layout_numpages%]") assert mLabel.displayText() == "1/2" # move the the second page and re-evaluate mLabel.setItemPosition(0, 320) assert mLabel.displayText() == "2/2" if __name__ == '__main__': unittest.main()
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 2344, 199, 396, 63, 81, 458, 7784, 332, 1302, 14, 647, 2151, 11016, 8648, 2049, 6148, 463, 520, 18365, 6029, 2049, 1898, 3322, 520, 334, 35, 9, 6029, 701, 577, 82, 14, 869, 1518, 79, 18880, 559, 281, 2049, 3031, 4483, 520, 394, 1518, 79, 6308, 4004, 559, 281, 737, 747, 1502, 2391, 6308, 2414, 199, 1011, 14355, 10, 199, 627, 17997, 627, 199, 627, 257, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 221, 627, 199, 627, 257, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 221, 627, 199, 627, 257, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 258, 627, 199, 627, 257, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 15530, 627, 199, 627, 17997, 627, 199, 1011, 14355, 15870, 199, 2344, 199, 646, 15640, 221, 327, 20432, 199, 199, 504, 15640, 14, 4776, 492, 1343, 63, 571, 12, 2882, 199, 504, 15640, 14, 24107, 14, 10901, 492, 1413, 1173, 2354, 12, 1413, 2506, 12, 1413, 3926, 199, 504, 15640, 14, 1018, 492, 22507, 12, 31545, 5003, 10899, 12, 31545, 5268, 12, 4888, 30099, 12, 4888, 32325, 4314, 12, 26833, 2017, 12, 26833, 12, 4888, 9093, 199, 504, 15841, 492, 4137, 16550, 2042, 199, 199, 928, 63, 571, 342, 421, 199, 533, 1379, 7350, 32325, 4314, 8, 2796, 14, 1746, 304, 339, 347, 511, 1538, 8, 277, 304, 267, 7393, 63, 3998, 63, 3022, 275, 4137, 16550, 2042, 342, 267, 5477, 1173, 2354, 275, 1413, 1173, 2354, 8, 2864, 63, 3998, 63, 3022, 435, 3286, 4391, 554, 63, 4181, 14, 17299, 531, 267, 333, 18602, 275, 22507, 8, 4106, 1173, 2354, 14, 27501, 1062, 5477, 1173, 2354, 14, 4883, 1563, 985, 1062, 298, 14945, 531, 398, 31545, 5003, 10899, 14, 842, 1252, 525, 2956, 16862, 779, 77, 18602, 566, 398, 327, 1218, 31586, 543, 11395, 332, 2341, 267, 2341, 5268, 275, 31545, 5268, 342, 267, 2341, 5268, 14, 409, 16862, 779, 77, 18602, 14, 344, 9383, 267, 2341, 5268, 14, 409, 35, 2393, 6939, 6589, 8, 797, 9, 398, 333, 30099, 275, 4888, 30099, 8, 1130, 5268, 9, 267, 333, 30099, 14, 409, 48, 9804, 2320, 8, 12615, 12, 26160, 9, 398, 333, 4314, 275, 4888, 32325, 4314, 8, 77, 30099, 9, 267, 333, 30099, 14, 525, 32325, 4314, 8, 77, 4314, 9, 398, 291, 14, 19154, 63, 396, 8, 77, 30099, 12, 333, 4314, 9, 267, 291, 14, 4445, 63, 19154, 63, 396, 8, 77, 30099, 12, 333, 4314, 12, 333, 18602, 9, 267, 291, 14, 1606, 63, 19154, 63, 396, 8, 77, 30099, 12, 333, 4314, 12, 333, 18602, 9, 339, 347, 11735, 63, 396, 8, 277, 12, 333, 30099, 12, 333, 4314, 304, 267, 327, 2672, 14211, 63, 5390, 11735, 267, 333, 4314, 14, 8341, 16232, 4, 14211, 63, 5390, 18617, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 1689, 16526, 435, 1413, 2506, 14, 1818, 2506, 1252, 16695, 342, 435, 4396, 531, 398, 327, 2672, 14211, 63, 5390, 342, 11735, 267, 333, 4314, 14, 8341, 16232, 4, 14211, 63, 5390, 8, 617, 5130, 745, 9, 18617, 267, 1420, 275, 4396, 2, 435, 1413, 3926, 14, 1818, 3926, 1252, 16695, 480, 617, 531, 435, 7340, 745, 9, 16526, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 1420, 398, 327, 2672, 14211, 63, 5390, 342, 11735, 334, 17183, 376, 3965, 9, 267, 333, 4314, 14, 8341, 16232, 9722, 4, 14211, 63, 5390, 8, 617, 9, 435, 413, 5, 8738, 745, 9, 18617, 267, 13972, 275, 1413, 2506, 14, 1818, 2506, 1252, 2977, 342, 267, 1420, 275, 4396, 5, 68, 8, 745, 9, 16526, 450, 334, 617, 435, 413, 9, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 1420, 398, 327, 3965, 11735, 334, 7395, 4568, 3878, 9, 267, 333, 4314, 14, 8341, 16232, 9722, 4451, 2339, 63, 17, 4451, 5, 1527, 5, 2025, 10, 18, 5, 61, 18617, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 4396, 59, 2339, 63, 17, 61, 2260, 16526, 339, 347, 3878, 63, 19154, 63, 396, 8, 277, 12, 333, 30099, 12, 333, 4314, 12, 333, 18602, 304, 267, 737, 12536, 275, 333, 30099, 14, 24935, 30099, 342, 267, 737, 12536, 14, 409, 27444, 5003, 8, 77, 18602, 9, 267, 737, 12536, 14, 14329, 8, 549, 9, 267, 333, 30099, 14, 409, 1271, 12536, 1385, 8, 7350, 30099, 14, 11399, 1271, 12536, 9, 398, 333, 4314, 14, 8341, 480, 9722, 4451, 2339, 63, 17, 4451, 92, 5227, 63, 745, 5956, 12523, 267, 737, 12536, 14, 5037, 9216, 342, 267, 737, 12536, 14, 6726, 1858, 5968, 8, 16, 9, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 298, 34, 305, 261, 13, 15548, 290, 15130, 63, 745, 2, 398, 737, 12536, 14, 6726, 1858, 5968, 8, 17, 9, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 298, 34, 264, 1450, 685, 63, 745, 2, 339, 347, 2034, 63, 19154, 63, 396, 8, 277, 12, 333, 30099, 12, 333, 4314, 12, 333, 18602, 304, 267, 333, 30099, 14, 409, 5667, 17773, 8, 18, 9, 267, 333, 4314, 14, 8341, 480, 9722, 32, 4209, 63, 1606, 92, 5227, 4805, 10644, 32, 4209, 63, 78, 1220, 7441, 5, 12523, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 298, 17, 15, 18, 2, 398, 327, 4057, 314, 314, 3499, 2034, 436, 295, 13, 7383, 267, 333, 4314, 14, 29135, 5625, 8, 16, 12, 25611, 9, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 298, 18, 15, 18, 2, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2882, 14, 973, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 2344, 199, 396, 63, 81, 458, 7784, 332, 1302, 14, 647, 2151, 11016, 8648, 2049, 6148, 463, 520, 18365, 6029, 2049, 1898, 3322, 520, 334, 35, 9, 6029, 701, 577, 82, 14, 869, 1518, 79, 18880, 559, 281, 2049, 3031, 4483, 520, 394, 1518, 79, 6308, 4004, 559, 281, 737, 747, 1502, 2391, 6308, 2414, 199, 1011, 14355, 10, 199, 627, 17997, 627, 199, 627, 257, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 221, 627, 199, 627, 257, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 221, 627, 199, 627, 257, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 258, 627, 199, 627, 257, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 15530, 627, 199, 627, 17997, 627, 199, 1011, 14355, 15870, 199, 2344, 199, 646, 15640, 221, 327, 20432, 199, 199, 504, 15640, 14, 4776, 492, 1343, 63, 571, 12, 2882, 199, 504, 15640, 14, 24107, 14, 10901, 492, 1413, 1173, 2354, 12, 1413, 2506, 12, 1413, 3926, 199, 504, 15640, 14, 1018, 492, 22507, 12, 31545, 5003, 10899, 12, 31545, 5268, 12, 4888, 30099, 12, 4888, 32325, 4314, 12, 26833, 2017, 12, 26833, 12, 4888, 9093, 199, 504, 15841, 492, 4137, 16550, 2042, 199, 199, 928, 63, 571, 342, 421, 199, 533, 1379, 7350, 32325, 4314, 8, 2796, 14, 1746, 304, 339, 347, 511, 1538, 8, 277, 304, 267, 7393, 63, 3998, 63, 3022, 275, 4137, 16550, 2042, 342, 267, 5477, 1173, 2354, 275, 1413, 1173, 2354, 8, 2864, 63, 3998, 63, 3022, 435, 3286, 4391, 554, 63, 4181, 14, 17299, 531, 267, 333, 18602, 275, 22507, 8, 4106, 1173, 2354, 14, 27501, 1062, 5477, 1173, 2354, 14, 4883, 1563, 985, 1062, 298, 14945, 531, 398, 31545, 5003, 10899, 14, 842, 1252, 525, 2956, 16862, 779, 77, 18602, 566, 398, 327, 1218, 31586, 543, 11395, 332, 2341, 267, 2341, 5268, 275, 31545, 5268, 342, 267, 2341, 5268, 14, 409, 16862, 779, 77, 18602, 14, 344, 9383, 267, 2341, 5268, 14, 409, 35, 2393, 6939, 6589, 8, 797, 9, 398, 333, 30099, 275, 4888, 30099, 8, 1130, 5268, 9, 267, 333, 30099, 14, 409, 48, 9804, 2320, 8, 12615, 12, 26160, 9, 398, 333, 4314, 275, 4888, 32325, 4314, 8, 77, 30099, 9, 267, 333, 30099, 14, 525, 32325, 4314, 8, 77, 4314, 9, 398, 291, 14, 19154, 63, 396, 8, 77, 30099, 12, 333, 4314, 9, 267, 291, 14, 4445, 63, 19154, 63, 396, 8, 77, 30099, 12, 333, 4314, 12, 333, 18602, 9, 267, 291, 14, 1606, 63, 19154, 63, 396, 8, 77, 30099, 12, 333, 4314, 12, 333, 18602, 9, 339, 347, 11735, 63, 396, 8, 277, 12, 333, 30099, 12, 333, 4314, 304, 267, 327, 2672, 14211, 63, 5390, 11735, 267, 333, 4314, 14, 8341, 16232, 4, 14211, 63, 5390, 18617, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 1689, 16526, 435, 1413, 2506, 14, 1818, 2506, 1252, 16695, 342, 435, 4396, 531, 398, 327, 2672, 14211, 63, 5390, 342, 11735, 267, 333, 4314, 14, 8341, 16232, 4, 14211, 63, 5390, 8, 617, 5130, 745, 9, 18617, 267, 1420, 275, 4396, 2, 435, 1413, 3926, 14, 1818, 3926, 1252, 16695, 480, 617, 531, 435, 7340, 745, 9, 16526, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 1420, 398, 327, 2672, 14211, 63, 5390, 342, 11735, 334, 17183, 376, 3965, 9, 267, 333, 4314, 14, 8341, 16232, 9722, 4, 14211, 63, 5390, 8, 617, 9, 435, 413, 5, 8738, 745, 9, 18617, 267, 13972, 275, 1413, 2506, 14, 1818, 2506, 1252, 2977, 342, 267, 1420, 275, 4396, 5, 68, 8, 745, 9, 16526, 450, 334, 617, 435, 413, 9, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 1420, 398, 327, 3965, 11735, 334, 7395, 4568, 3878, 9, 267, 333, 4314, 14, 8341, 16232, 9722, 4451, 2339, 63, 17, 4451, 5, 1527, 5, 2025, 10, 18, 5, 61, 18617, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 4396, 59, 2339, 63, 17, 61, 2260, 16526, 339, 347, 3878, 63, 19154, 63, 396, 8, 277, 12, 333, 30099, 12, 333, 4314, 12, 333, 18602, 304, 267, 737, 12536, 275, 333, 30099, 14, 24935, 30099, 342, 267, 737, 12536, 14, 409, 27444, 5003, 8, 77, 18602, 9, 267, 737, 12536, 14, 14329, 8, 549, 9, 267, 333, 30099, 14, 409, 1271, 12536, 1385, 8, 7350, 30099, 14, 11399, 1271, 12536, 9, 398, 333, 4314, 14, 8341, 480, 9722, 4451, 2339, 63, 17, 4451, 92, 5227, 63, 745, 5956, 12523, 267, 737, 12536, 14, 5037, 9216, 342, 267, 737, 12536, 14, 6726, 1858, 5968, 8, 16, 9, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 298, 34, 305, 261, 13, 15548, 290, 15130, 63, 745, 2, 398, 737, 12536, 14, 6726, 1858, 5968, 8, 17, 9, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 298, 34, 264, 1450, 685, 63, 745, 2, 339, 347, 2034, 63, 19154, 63, 396, 8, 277, 12, 333, 30099, 12, 333, 4314, 12, 333, 18602, 304, 267, 333, 30099, 14, 409, 5667, 17773, 8, 18, 9, 267, 333, 4314, 14, 8341, 480, 9722, 32, 4209, 63, 1606, 92, 5227, 4805, 10644, 32, 4209, 63, 78, 1220, 7441, 5, 12523, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 298, 17, 15, 18, 2, 398, 327, 4057, 314, 314, 3499, 2034, 436, 295, 13, 7383, 267, 333, 4314, 14, 29135, 5625, 8, 16, 12, 25611, 9, 267, 702, 333, 4314, 14, 2918, 1872, 342, 508, 298, 18, 15, 18, 2, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2882, 14, 973, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
sebi-hgdata/ansible
v2/test/parsing/yaml/test_data_loader.py
11
2224
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) __metaclass__ = type from yaml.scanner import ScannerError from ansible.compat.tests import unittest from ansible.compat.tests.mock import patch from ansible.errors import AnsibleParserError from ansible.parsing.yaml import DataLoader from ansible.parsing.yaml.objects import AnsibleMapping class TestDataLoader(unittest.TestCase): def setUp(self): # FIXME: need to add tests that utilize vault_password self._loader = DataLoader() def tearDown(self): pass @patch.object(DataLoader, '_get_file_contents') def test_parse_json_from_file(self, mock_def): mock_def.return_value = ("""{"a": 1, "b": 2, "c": 3}""", True) output = self._loader.load_from_file('dummy_json.txt') self.assertEqual(output, dict(a=1,b=2,c=3)) @patch.object(DataLoader, '_get_file_contents') def test_parse_yaml_from_file(self, mock_def): mock_def.return_value = (""" a: 1 b: 2 c: 3 """, True) output = self._loader.load_from_file('dummy_yaml.txt') self.assertEqual(output, dict(a=1,b=2,c=3)) @patch.object(DataLoader, '_get_file_contents') def test_parse_fail_from_file(self, mock_def): mock_def.return_value = (""" TEXT: *** NOT VALID """, True) self.assertRaises(AnsibleParserError, self._loader.load_from_file, 'dummy_yaml_bad.txt')
gpl-3.0
[ 3, 334, 67, 9, 6029, 13, 7280, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 504, 8864, 14, 16378, 492, 28628, 547, 199, 199, 504, 3242, 14, 5819, 14, 2219, 492, 2882, 199, 504, 3242, 14, 5819, 14, 2219, 14, 1805, 492, 3371, 199, 504, 3242, 14, 2550, 492, 31775, 199, 199, 504, 3242, 14, 11059, 14, 5963, 492, 3918, 5455, 199, 504, 3242, 14, 11059, 14, 5963, 14, 1462, 492, 2622, 7674, 199, 199, 533, 1379, 1451, 5455, 8, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 327, 7600, 26, 1929, 370, 1050, 2295, 626, 7678, 13559, 12738, 63, 2060, 267, 291, 423, 3422, 275, 3918, 5455, 342, 339, 347, 6766, 8, 277, 304, 267, 986, 339, 768, 2068, 14, 785, 8, 1451, 5455, 12, 2513, 362, 63, 493, 63, 4407, 358, 272, 347, 511, 63, 1122, 63, 1001, 63, 504, 63, 493, 8, 277, 12, 1683, 63, 318, 304, 267, 1683, 63, 318, 14, 1107, 63, 585, 275, 334, 624, 6641, 65, 582, 413, 12, 298, 66, 582, 499, 12, 298, 67, 582, 650, 93, 7208, 715, 9, 267, 1072, 275, 291, 423, 3422, 14, 912, 63, 504, 63, 493, 360, 5869, 63, 1001, 14, 2424, 358, 267, 291, 14, 629, 8, 1199, 12, 1211, 8, 65, 29, 17, 12, 66, 29, 18, 12, 67, 29, 19, 430, 339, 768, 2068, 14, 785, 8, 1451, 5455, 12, 2513, 362, 63, 493, 63, 4407, 358, 272, 347, 511, 63, 1122, 63, 5963, 63, 504, 63, 493, 8, 277, 12, 1683, 63, 318, 304, 267, 1683, 63, 318, 14, 1107, 63, 585, 275, 334, 624, 267, 282, 26, 413, 267, 330, 26, 499, 267, 286, 26, 650, 267, 10327, 715, 9, 267, 1072, 275, 291, 423, 3422, 14, 912, 63, 504, 63, 493, 360, 5869, 63, 5963, 14, 2424, 358, 267, 291, 14, 629, 8, 1199, 12, 1211, 8, 65, 29, 17, 12, 66, 29, 18, 12, 67, 29, 19, 430, 339, 768, 2068, 14, 785, 8, 1451, 5455, 12, 2513, 362, 63, 493, 63, 4407, 358, 272, 347, 511, 63, 1122, 63, 1633, 63, 504, 63, 493, 8, 277, 12, 1683, 63, 318, 304, 267, 1683, 63, 318, 14, 1107, 63, 585, 275, 334, 624, 267, 11951, 26, 288, 19688, 2049, 2845, 22049, 267, 10327, 715, 9, 267, 291, 14, 1855, 8, 10047, 21811, 12, 291, 423, 3422, 14, 912, 63, 504, 63, 493, 12, 283, 5869, 63, 5963, 63, 4087, 14, 2424, 358, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 334, 67, 9, 6029, 13, 7280, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 504, 8864, 14, 16378, 492, 28628, 547, 199, 199, 504, 3242, 14, 5819, 14, 2219, 492, 2882, 199, 504, 3242, 14, 5819, 14, 2219, 14, 1805, 492, 3371, 199, 504, 3242, 14, 2550, 492, 31775, 199, 199, 504, 3242, 14, 11059, 14, 5963, 492, 3918, 5455, 199, 504, 3242, 14, 11059, 14, 5963, 14, 1462, 492, 2622, 7674, 199, 199, 533, 1379, 1451, 5455, 8, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 327, 7600, 26, 1929, 370, 1050, 2295, 626, 7678, 13559, 12738, 63, 2060, 267, 291, 423, 3422, 275, 3918, 5455, 342, 339, 347, 6766, 8, 277, 304, 267, 986, 339, 768, 2068, 14, 785, 8, 1451, 5455, 12, 2513, 362, 63, 493, 63, 4407, 358, 272, 347, 511, 63, 1122, 63, 1001, 63, 504, 63, 493, 8, 277, 12, 1683, 63, 318, 304, 267, 1683, 63, 318, 14, 1107, 63, 585, 275, 334, 624, 6641, 65, 582, 413, 12, 298, 66, 582, 499, 12, 298, 67, 582, 650, 93, 7208, 715, 9, 267, 1072, 275, 291, 423, 3422, 14, 912, 63, 504, 63, 493, 360, 5869, 63, 1001, 14, 2424, 358, 267, 291, 14, 629, 8, 1199, 12, 1211, 8, 65, 29, 17, 12, 66, 29, 18, 12, 67, 29, 19, 430, 339, 768, 2068, 14, 785, 8, 1451, 5455, 12, 2513, 362, 63, 493, 63, 4407, 358, 272, 347, 511, 63, 1122, 63, 5963, 63, 504, 63, 493, 8, 277, 12, 1683, 63, 318, 304, 267, 1683, 63, 318, 14, 1107, 63, 585, 275, 334, 624, 267, 282, 26, 413, 267, 330, 26, 499, 267, 286, 26, 650, 267, 10327, 715, 9, 267, 1072, 275, 291, 423, 3422, 14, 912, 63, 504, 63, 493, 360, 5869, 63, 5963, 14, 2424, 358, 267, 291, 14, 629, 8, 1199, 12, 1211, 8, 65, 29, 17, 12, 66, 29, 18, 12, 67, 29, 19, 430, 339, 768, 2068, 14, 785, 8, 1451, 5455, 12, 2513, 362, 63, 493, 63, 4407, 358, 272, 347, 511, 63, 1122, 63, 1633, 63, 504, 63, 493, 8, 277, 12, 1683, 63, 318, 304, 267, 1683, 63, 318, 14, 1107, 63, 585, 275, 334, 624, 267, 11951, 26, 288, 19688, 2049, 2845, 22049, 267, 10327, 715, 9, 267, 291, 14, 1855, 8, 10047, 21811, 12, 291, 423, 3422, 14, 912, 63, 504, 63, 493, 12, 283, 5869, 63, 5963, 63, 4087, 14, 2424, 358, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
KimNorgaard/ansible-modules-extras
cloud/profitbricks/profitbricks.py
112
20794
#!/usr/bin/python # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. DOCUMENTATION = ''' --- module: profitbricks short_description: Create, destroy, start, stop, and reboot a ProfitBricks virtual machine. description: - Create, destroy, update, start, stop, and reboot a ProfitBricks virtual machine. When the virtual machine is created it can optionally wait for it to be 'running' before returning. This module has a dependency on profitbricks >= 1.0.0 version_added: "2.0" options: auto_increment: description: - Whether or not to increment a single number in the name for created virtual machines. default: yes choices: ["yes", "no"] name: description: - The name of the virtual machine. required: true image: description: - The system image ID for creating the virtual machine, e.g. a3eae284-a2fe-11e4-b187-5f1f641608c8. required: true datacenter: description: - The Datacenter to provision this virtual machine. required: false default: null cores: description: - The number of CPU cores to allocate to the virtual machine. required: false default: 2 ram: description: - The amount of memory to allocate to the virtual machine. required: false default: 2048 volume_size: description: - The size in GB of the boot volume. required: false default: 10 bus: description: - The bus type for the volume. required: false default: VIRTIO choices: [ "IDE", "VIRTIO"] instance_ids: description: - list of instance ids, currently only used when state='absent' to remove instances. required: false count: description: - The number of virtual machines to create. required: false default: 1 location: description: - The datacenter location. Use only if you want to create the Datacenter or else this value is ignored. required: false default: us/las choices: [ "us/las", "us/lasdev", "de/fra", "de/fkb" ] assign_public_ip: description: - This will assign the machine to the public LAN. If no LAN exists with public Internet access it is created. required: false default: false lan: description: - The ID of the LAN you wish to add the servers to. required: false default: 1 subscription_user: description: - The ProfitBricks username. Overrides the PB_SUBSCRIPTION_ID environement variable. required: false default: null subscription_password: description: - THe ProfitBricks password. Overrides the PB_PASSWORD environement variable. required: false default: null wait: description: - wait for the instance to be in state 'running' before returning required: false default: "yes" choices: [ "yes", "no" ] wait_timeout: description: - how long before wait gives up, in seconds default: 600 remove_boot_volume: description: - remove the bootVolume of the virtual machine you're destroying. required: false default: "yes" choices: ["yes", "no"] state: description: - create or terminate instances required: false default: 'present' choices: [ "running", "stopped", "absent", "present" ] requirements: - "profitbricks" - "python >= 2.6" author: Matt Baldwin (baldwin@stackpointcloud.com) ''' EXAMPLES = ''' # Note: These examples do not set authentication details, see the AWS Guide for details. # Provisioning example. This will create three servers and enumerate their names. - profitbricks: datacenter: Tardis One name: web%02d.stackpointcloud.com cores: 4 ram: 2048 volume_size: 50 image: a3eae284-a2fe-11e4-b187-5f1f641608c8 location: us/las count: 3 assign_public_ip: true # Removing Virtual machines - profitbricks: datacenter: Tardis One instance_ids: - 'web001.stackpointcloud.com' - 'web002.stackpointcloud.com' - 'web003.stackpointcloud.com' wait_timeout: 500 state: absent # Starting Virtual Machines. - profitbricks: datacenter: Tardis One instance_ids: - 'web001.stackpointcloud.com' - 'web002.stackpointcloud.com' - 'web003.stackpointcloud.com' wait_timeout: 500 state: running # Stopping Virtual Machines - profitbricks: datacenter: Tardis One instance_ids: - 'web001.stackpointcloud.com' - 'web002.stackpointcloud.com' - 'web003.stackpointcloud.com' wait_timeout: 500 state: stopped ''' import re import uuid import time HAS_PB_SDK = True try: from profitbricks.client import ProfitBricksService, Volume, Server, Datacenter, NIC, LAN except ImportError: HAS_PB_SDK = False LOCATIONS = ['us/las', 'de/fra', 'de/fkb', 'us/lasdev'] uuid_match = re.compile( '[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) def _wait_for_completion(profitbricks, promise, wait_timeout, msg): if not promise: return wait_timeout = time.time() + wait_timeout while wait_timeout > time.time(): time.sleep(5) operation_result = profitbricks.get_request( request_id=promise['requestId'], status=True) if operation_result['metadata']['status'] == "DONE": return elif operation_result['metadata']['status'] == "FAILED": raise Exception( 'Request failed to complete ' + msg + ' "' + str( promise['requestId']) + '" to complete.') raise Exception( 'Timed out waiting for async operation ' + msg + ' "' + str( promise['requestId'] ) + '" to complete.') def _create_machine(module, profitbricks, datacenter, name): image = module.params.get('image') cores = module.params.get('cores') ram = module.params.get('ram') volume_size = module.params.get('volume_size') bus = module.params.get('bus') lan = module.params.get('lan') assign_public_ip = module.params.get('assign_public_ip') subscription_user = module.params.get('subscription_user') subscription_password = module.params.get('subscription_password') location = module.params.get('location') image = module.params.get('image') assign_public_ip = module.boolean(module.params.get('assign_public_ip')) wait = module.params.get('wait') wait_timeout = module.params.get('wait_timeout') try: # Generate name, but grab first 10 chars so we don't # screw up the uuid match routine. v = Volume( name=str(uuid.uuid4()).replace('-','')[:10], size=volume_size, image=image, bus=bus) volume_response = profitbricks.create_volume( datacenter_id=datacenter, volume=v) # We're forced to wait on the volume creation since # server create relies upon this existing. _wait_for_completion(profitbricks, volume_response, wait_timeout, "create_volume") except Exception as e: module.fail_json(msg="failed to create the new volume: %s" % str(e)) if assign_public_ip: public_found = False lans = profitbricks.list_lans(datacenter) for lan in lans['items']: if lan['properties']['public']: public_found = True lan = lan['id'] if not public_found: i = LAN( name='public', public=True) lan_response = profitbricks.create_lan(datacenter, i) lan = lan_response['id'] _wait_for_completion(profitbricks, lan_response, wait_timeout, "_create_machine") try: n = NIC( lan=int(lan) ) nics = [n] s = Server( name=name, ram=ram, cores=cores, nics=nics, boot_volume_id=volume_response['id'] ) server_response = profitbricks.create_server( datacenter_id=datacenter, server=s) if wait: _wait_for_completion(profitbricks, server_response, wait_timeout, "create_virtual_machine") return (server_response) except Exception as e: module.fail_json(msg="failed to create the new server: %s" % str(e)) def _remove_machine(module, profitbricks, datacenter, name): remove_boot_volume = module.params.get('remove_boot_volume') wait = module.params.get('wait') wait_timeout = module.params.get('wait_timeout') changed = False # User provided the actual UUID instead of the name. try: if remove_boot_volume: # Collect information needed for later. server = profitbricks.get_server(datacenter, name) volume_id = server['properties']['bootVolume']['href'].split('/')[7] server_response = profitbricks.delete_server(datacenter, name) changed = True except Exception as e: module.fail_json(msg="failed to terminate the virtual server: %s" % str(e)) # Remove the bootVolume if remove_boot_volume: try: volume_response = profitbricks.delete_volume(datacenter, volume_id) except Exception as e: module.fail_json(msg="failed to remove the virtual server's bootvolume: %s" % str(e)) return changed def _startstop_machine(module, profitbricks, datacenter, name): state = module.params.get('state') try: if state == 'running': profitbricks.start_server(datacenter, name) else: profitbricks.stop_server(datacenter, name) return True except Exception as e: module.fail_json(msg="failed to start or stop the virtual machine %s: %s" % (name, str(e))) def _create_datacenter(module, profitbricks): datacenter = module.params.get('datacenter') location = module.params.get('location') wait_timeout = module.params.get('wait_timeout') i = Datacenter( name=datacenter, location=location ) try: datacenter_response = profitbricks.create_datacenter(datacenter=i) _wait_for_completion(profitbricks, datacenter_response, wait_timeout, "_create_datacenter") return datacenter_response except Exception as e: module.fail_json(msg="failed to create the new server(s): %s" % str(e)) def create_virtual_machine(module, profitbricks): """ Create new virtual machine module : AnsibleModule object profitbricks: authenticated profitbricks object Returns: True if a new virtual machine was created, false otherwise """ datacenter = module.params.get('datacenter') name = module.params.get('name') auto_increment = module.params.get('auto_increment') count = module.params.get('count') lan = module.params.get('lan') wait_timeout = module.params.get('wait_timeout') failed = True datacenter_found = False virtual_machines = [] virtual_machine_ids = [] # Locate UUID for Datacenter if not (uuid_match.match(datacenter)): datacenter_list = profitbricks.list_datacenters() for d in datacenter_list['items']: dc = profitbricks.get_datacenter(d['id']) if datacenter == dc['properties']['name']: datacenter = d['id'] datacenter_found = True break if not datacenter_found: datacenter_response = _create_datacenter(module, profitbricks) datacenter = datacenter_response['id'] _wait_for_completion(profitbricks, datacenter_response, wait_timeout, "create_virtual_machine") if auto_increment: numbers = set() count_offset = 1 try: name % 0 except TypeError, e: if e.message.startswith('not all'): name = '%s%%d' % name else: module.fail_json(msg=e.message) number_range = xrange(count_offset,count_offset + count + len(numbers)) available_numbers = list(set(number_range).difference(numbers)) names = [] numbers_to_use = available_numbers[:count] for number in numbers_to_use: names.append(name % number) else: names = [name] * count for name in names: create_response = _create_machine(module, profitbricks, str(datacenter), name) nics = profitbricks.list_nics(datacenter,create_response['id']) for n in nics['items']: if lan == n['properties']['lan']: create_response.update({ 'public_ip': n['properties']['ips'][0] }) virtual_machines.append(create_response) failed = False results = { 'failed': failed, 'machines': virtual_machines, 'action': 'create', 'instance_ids': { 'instances': [i['id'] for i in virtual_machines], } } return results def remove_virtual_machine(module, profitbricks): """ Removes a virtual machine. This will remove the virtual machine along with the bootVolume. module : AnsibleModule object profitbricks: authenticated profitbricks object. Not yet supported: handle deletion of attached data disks. Returns: True if a new virtual server was deleted, false otherwise """ if not isinstance(module.params.get('instance_ids'), list) or len(module.params.get('instance_ids')) < 1: module.fail_json(msg='instance_ids should be a list of virtual machine ids or names, aborting') datacenter = module.params.get('datacenter') instance_ids = module.params.get('instance_ids') # Locate UUID for Datacenter if not (uuid_match.match(datacenter)): datacenter_list = profitbricks.list_datacenters() for d in datacenter_list['items']: dc = profitbricks.get_datacenter(d['id']) if datacenter == dc['properties']['name']: datacenter = d['id'] break for n in instance_ids: if(uuid_match.match(n)): _remove_machine(module, profitbricks, d['id'], n) else: servers = profitbricks.list_servers(d['id']) for s in servers['items']: if n == s['properties']['name']: server_id = s['id'] _remove_machine(module, profitbricks, datacenter, server_id) def startstop_machine(module, profitbricks, state): """ Starts or Stops a virtual machine. module : AnsibleModule object profitbricks: authenticated profitbricks object. Returns: True when the servers process the action successfully, false otherwise. """ if not isinstance(module.params.get('instance_ids'), list) or len(module.params.get('instance_ids')) < 1: module.fail_json(msg='instance_ids should be a list of virtual machine ids or names, aborting') wait = module.params.get('wait') wait_timeout = module.params.get('wait_timeout') changed = False datacenter = module.params.get('datacenter') instance_ids = module.params.get('instance_ids') # Locate UUID for Datacenter if not (uuid_match.match(datacenter)): datacenter_list = profitbricks.list_datacenters() for d in datacenter_list['items']: dc = profitbricks.get_datacenter(d['id']) if datacenter == dc['properties']['name']: datacenter = d['id'] break for n in instance_ids: if(uuid_match.match(n)): _startstop_machine(module, profitbricks, datacenter, n) changed = True else: servers = profitbricks.list_servers(d['id']) for s in servers['items']: if n == s['properties']['name']: server_id = s['id'] _startstop_machine(module, profitbricks, datacenter, server_id) changed = True if wait: wait_timeout = time.time() + wait_timeout while wait_timeout > time.time(): matched_instances = [] for res in profitbricks.list_servers(datacenter)['items']: if state == 'running': if res['properties']['vmState'].lower() == state: matched_instances.append(res) elif state == 'stopped': if res['properties']['vmState'].lower() == 'shutoff': matched_instances.append(res) if len(matched_instances) < len(instance_ids): time.sleep(5) else: break if wait_timeout <= time.time(): # waiting took too long module.fail_json(msg = "wait for virtual machine state timeout on %s" % time.asctime()) return (changed) def main(): module = AnsibleModule( argument_spec=dict( datacenter=dict(), name=dict(), image=dict(), cores=dict(default=2), ram=dict(default=2048), volume_size=dict(default=10), bus=dict(default='VIRTIO'), lan=dict(default=1), count=dict(default=1), auto_increment=dict(type='bool', default=True), instance_ids=dict(), subscription_user=dict(), subscription_password=dict(), location=dict(choices=LOCATIONS, default='us/las'), assign_public_ip=dict(type='bool', default=False), wait=dict(type='bool', default=True), wait_timeout=dict(type='int', default=600), remove_boot_volume=dict(type='bool', default=True), state=dict(default='present'), ) ) if not HAS_PB_SDK: module.fail_json(msg='profitbricks required for this module') subscription_user = module.params.get('subscription_user') subscription_password = module.params.get('subscription_password') wait = module.params.get('wait') wait_timeout = module.params.get('wait_timeout') profitbricks = ProfitBricksService( username=subscription_user, password=subscription_password) state = module.params.get('state') if state == 'absent': if not module.params.get('datacenter'): module.fail_json(msg='datacenter parameter is required ' + 'for running or stopping machines.') try: (changed) = remove_virtual_machine(module, profitbricks) module.exit_json(changed=changed) except Exception as e: module.fail_json(msg='failed to set instance state: %s' % str(e)) elif state in ('running', 'stopped'): if not module.params.get('datacenter'): module.fail_json(msg='datacenter parameter is required for ' + 'running or stopping machines.') try: (changed) = startstop_machine(module, profitbricks, state) module.exit_json(changed=changed) except Exception as e: module.fail_json(msg='failed to set instance state: %s' % str(e)) elif state == 'present': if not module.params.get('name'): module.fail_json(msg='name parameter is required for new instance') if not module.params.get('image'): module.fail_json(msg='image parameter is required for new instance') if not module.params.get('subscription_user'): module.fail_json(msg='subscription_user parameter is ' + 'required for new instance') if not module.params.get('subscription_password'): module.fail_json(msg='subscription_password parameter is ' + 'required for new instance') try: (machine_dict_array) = create_virtual_machine(module, profitbricks) module.exit_json(**machine_dict_array) except Exception as e: module.fail_json(msg='failed to set instance state: %s' % str(e)) from ansible.module_utils.basic import * main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 32630, 30855, 199, 3612, 63, 1802, 26, 2790, 12, 11972, 12, 1343, 12, 3631, 12, 436, 19457, 282, 2165, 3269, 34, 322, 5618, 5791, 6844, 14, 199, 1802, 26, 1362, 446, 2790, 12, 11972, 12, 1678, 12, 1343, 12, 3631, 12, 436, 19457, 282, 2165, 3269, 34, 322, 5618, 5791, 6844, 14, 3979, 314, 5791, 6844, 365, 2737, 652, 883, 14190, 3618, 367, 652, 370, 506, 283, 5720, 7, 2544, 8152, 14, 961, 859, 965, 282, 5936, 641, 32630, 30855, 2356, 413, 14, 16, 14, 16, 199, 1023, 63, 3270, 26, 298, 18, 14, 16, 2, 199, 1419, 26, 523, 2599, 63, 9728, 26, 272, 1369, 26, 489, 446, 7480, 503, 440, 370, 11609, 282, 2849, 1329, 315, 314, 536, 367, 2737, 5791, 20601, 14, 272, 849, 26, 9456, 272, 3415, 26, 2097, 5066, 401, 298, 889, 937, 523, 536, 26, 272, 1369, 26, 489, 446, 710, 536, 402, 314, 5791, 6844, 14, 272, 1415, 26, 2549, 523, 1834, 26, 5591, 1369, 26, 489, 446, 710, 2656, 1834, 2870, 367, 6425, 314, 5791, 6844, 12, 325, 14, 71, 14, 282, 19, 69, 3624, 10681, 13, 65, 18, 771, 13, 845, 69, 20, 13, 66, 11775, 13, 21, 70, 17, 70, 772, 975, 2036, 67, 24, 14, 272, 1415, 26, 2549, 523, 16606, 26, 272, 1369, 26, 489, 446, 710, 3918, 4218, 370, 15408, 642, 5791, 6844, 14, 272, 1415, 26, 3055, 272, 849, 26, 2973, 523, 23857, 26, 272, 1369, 26, 489, 446, 710, 1329, 402, 11952, 23857, 370, 18310, 370, 314, 5791, 6844, 14, 272, 1415, 26, 3055, 272, 849, 26, 499, 523, 21394, 26, 272, 1369, 26, 489, 446, 710, 5982, 402, 4402, 370, 18310, 370, 314, 5791, 6844, 14, 272, 1415, 26, 3055, 272, 849, 26, 18427, 523, 3301, 63, 890, 26, 272, 1369, 26, 489, 446, 710, 1568, 315, 18553, 402, 314, 8498, 3301, 14, 272, 1415, 26, 3055, 272, 849, 26, 1616, 523, 10414, 26, 272, 1369, 26, 489, 446, 710, 10414, 730, 367, 314, 3301, 14, 272, 1415, 26, 3055, 272, 849, 26, 812, 3927, 52, 2090, 272, 3415, 26, 359, 298, 11259, 401, 298, 18228, 2090, 937, 523, 1256, 63, 1580, 26, 272, 1369, 26, 489, 446, 769, 402, 1256, 2762, 12, 5544, 1454, 1202, 1380, 1174, 534, 5575, 7, 370, 2813, 4454, 14, 272, 1415, 26, 3055, 523, 2338, 26, 272, 1369, 26, 489, 446, 710, 1329, 402, 5791, 20601, 370, 1218, 14, 272, 1415, 26, 3055, 272, 849, 26, 413, 523, 2909, 26, 272, 1369, 26, 489, 446, 710, 16606, 2909, 14, 3645, 1454, 340, 1265, 2934, 370, 1218, 314, 3918, 4218, 503, 587, 642, 574, 365, 5525, 14, 5591, 1415, 26, 3055, 272, 849, 26, 2739, 15, 12536, 272, 3415, 26, 359, 298, 527, 15, 12536, 401, 298, 527, 15, 12536, 2374, 401, 298, 271, 15, 21844, 401, 298, 271, 15, 70, 7862, 2, 1622, 523, 5090, 63, 3455, 63, 711, 26, 272, 1369, 26, 489, 446, 961, 911, 5090, 314, 6844, 370, 314, 4575, 491, 879, 14, 982, 949, 491, 879, 3495, 543, 4575, 22026, 2879, 652, 365, 2737, 14, 272, 1415, 26, 3055, 272, 849, 26, 3055, 523, 634, 290, 26, 272, 1369, 26, 489, 446, 710, 2870, 402, 314, 491, 879, 1265, 13809, 370, 1050, 314, 8037, 370, 14, 272, 1415, 26, 3055, 272, 849, 26, 413, 523, 9966, 63, 751, 26, 272, 1369, 26, 489, 446, 710, 2165, 3269, 34, 322, 5618, 3434, 14, 31144, 314, 510, 34, 63, 6348, 10484, 1075, 63, 998, 655, 1042, 368, 434, 1750, 14, 272, 1415, 26, 3055, 272, 849, 26, 2973, 523, 9966, 63, 2060, 26, 272, 1369, 26, 489, 446, 377, 1966, 2165, 3269, 34, 322, 5618, 2505, 14, 31144, 314, 510, 34, 63, 9032, 655, 1042, 368, 434, 1750, 14, 272, 1415, 26, 3055, 272, 849, 26, 2973, 523, 3618, 26, 272, 1369, 26, 489, 446, 3618, 367, 314, 1256, 370, 506, 315, 1174, 283, 5720, 7, 2544, 8152, 272, 1415, 26, 3055, 272, 849, 26, 298, 5066, 2, 272, 3415, 26, 359, 298, 5066, 401, 298, 889, 2, 1622, 523, 3618, 63, 2593, 26, 272, 1369, 26, 489, 446, 4212, 1846, 2544, 3618, 10557, 1536, 12, 315, 4696, 272, 849, 26, 11624, 523, 2813, 63, 4930, 63, 2405, 26, 272, 1369, 26, 489, 446, 2813, 314, 8498, 6464, 402, 314, 5791, 6844, 1265, 3984, 11972, 316, 14, 272, 1415, 26, 3055, 272, 849, 26, 298, 5066, 2, 272, 3415, 26, 2097, 5066, 401, 298, 889, 937, 523, 1174, 26, 272, 1369, 26, 489, 446, 1218, 503, 15095, 4454, 272, 1415, 26, 3055, 272, 849, 26, 283, 1881, 7, 272, 3415, 26, 359, 298, 5720, 401, 298, 14661, 401, 298, 5575, 401, 298, 1881, 2, 1622, 199, 199, 7538, 26, 1362, 446, 298, 496, 3269, 30855, 2, 1362, 446, 298, 1548, 2356, 499, 14, 22, 2, 199, 2502, 26, 31653, 23928, 68, 2676, 334, 4982, 68, 2676, 32, 2340, 1403, 4091, 14, 957, 9, 199, 2344, 199, 199, 8918, 275, 1449, 199, 199, 3, 3390, 26, 5723, 7251, 886, 440, 663, 6299, 2436, 12, 1937, 314, 10168, 15423, 367, 2436, 14, 199, 199, 3, 2165, 2317, 316, 2893, 14 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 32630, 30855, 199, 3612, 63, 1802, 26, 2790, 12, 11972, 12, 1343, 12, 3631, 12, 436, 19457, 282, 2165, 3269, 34, 322, 5618, 5791, 6844, 14, 199, 1802, 26, 1362, 446, 2790, 12, 11972, 12, 1678, 12, 1343, 12, 3631, 12, 436, 19457, 282, 2165, 3269, 34, 322, 5618, 5791, 6844, 14, 3979, 314, 5791, 6844, 365, 2737, 652, 883, 14190, 3618, 367, 652, 370, 506, 283, 5720, 7, 2544, 8152, 14, 961, 859, 965, 282, 5936, 641, 32630, 30855, 2356, 413, 14, 16, 14, 16, 199, 1023, 63, 3270, 26, 298, 18, 14, 16, 2, 199, 1419, 26, 523, 2599, 63, 9728, 26, 272, 1369, 26, 489, 446, 7480, 503, 440, 370, 11609, 282, 2849, 1329, 315, 314, 536, 367, 2737, 5791, 20601, 14, 272, 849, 26, 9456, 272, 3415, 26, 2097, 5066, 401, 298, 889, 937, 523, 536, 26, 272, 1369, 26, 489, 446, 710, 536, 402, 314, 5791, 6844, 14, 272, 1415, 26, 2549, 523, 1834, 26, 5591, 1369, 26, 489, 446, 710, 2656, 1834, 2870, 367, 6425, 314, 5791, 6844, 12, 325, 14, 71, 14, 282, 19, 69, 3624, 10681, 13, 65, 18, 771, 13, 845, 69, 20, 13, 66, 11775, 13, 21, 70, 17, 70, 772, 975, 2036, 67, 24, 14, 272, 1415, 26, 2549, 523, 16606, 26, 272, 1369, 26, 489, 446, 710, 3918, 4218, 370, 15408, 642, 5791, 6844, 14, 272, 1415, 26, 3055, 272, 849, 26, 2973, 523, 23857, 26, 272, 1369, 26, 489, 446, 710, 1329, 402, 11952, 23857, 370, 18310, 370, 314, 5791, 6844, 14, 272, 1415, 26, 3055, 272, 849, 26, 499, 523, 21394, 26, 272, 1369, 26, 489, 446, 710, 5982, 402, 4402, 370, 18310, 370, 314, 5791, 6844, 14, 272, 1415, 26, 3055, 272, 849, 26, 18427, 523, 3301, 63, 890, 26, 272, 1369, 26, 489, 446, 710, 1568, 315, 18553, 402, 314, 8498, 3301, 14, 272, 1415, 26, 3055, 272, 849, 26, 1616, 523, 10414, 26, 272, 1369, 26, 489, 446, 710, 10414, 730, 367, 314, 3301, 14, 272, 1415, 26, 3055, 272, 849, 26, 812, 3927, 52, 2090, 272, 3415, 26, 359, 298, 11259, 401, 298, 18228, 2090, 937, 523, 1256, 63, 1580, 26, 272, 1369, 26, 489, 446, 769, 402, 1256, 2762, 12, 5544, 1454, 1202, 1380, 1174, 534, 5575, 7, 370, 2813, 4454, 14, 272, 1415, 26, 3055, 523, 2338, 26, 272, 1369, 26, 489, 446, 710, 1329, 402, 5791, 20601, 370, 1218, 14, 272, 1415, 26, 3055, 272, 849, 26, 413, 523, 2909, 26, 272, 1369, 26, 489, 446, 710, 16606, 2909, 14, 3645, 1454, 340, 1265, 2934, 370, 1218, 314, 3918, 4218, 503, 587, 642, 574, 365, 5525, 14, 5591, 1415, 26, 3055, 272, 849, 26, 2739, 15, 12536, 272, 3415, 26, 359, 298, 527, 15, 12536, 401, 298, 527, 15, 12536, 2374, 401, 298, 271, 15, 21844, 401, 298, 271, 15, 70, 7862, 2, 1622, 523, 5090, 63, 3455, 63, 711, 26, 272, 1369, 26, 489, 446, 961, 911, 5090, 314, 6844, 370, 314, 4575, 491, 879, 14, 982, 949, 491, 879, 3495, 543, 4575, 22026, 2879, 652, 365, 2737, 14, 272, 1415, 26, 3055, 272, 849, 26, 3055, 523, 634, 290, 26, 272, 1369, 26, 489, 446, 710, 2870, 402, 314, 491, 879, 1265, 13809, 370, 1050, 314, 8037, 370, 14, 272, 1415, 26, 3055, 272, 849, 26, 413, 523, 9966, 63, 751, 26, 272, 1369, 26, 489, 446, 710, 2165, 3269, 34, 322, 5618, 3434, 14, 31144, 314, 510, 34, 63, 6348, 10484, 1075, 63, 998, 655, 1042, 368, 434, 1750, 14, 272, 1415, 26, 3055, 272, 849, 26, 2973, 523, 9966, 63, 2060, 26, 272, 1369, 26, 489, 446, 377, 1966, 2165, 3269, 34, 322, 5618, 2505, 14, 31144, 314, 510, 34, 63, 9032, 655, 1042, 368, 434, 1750, 14, 272, 1415, 26, 3055, 272, 849, 26, 2973, 523, 3618, 26, 272, 1369, 26, 489, 446, 3618, 367, 314, 1256, 370, 506, 315, 1174, 283, 5720, 7, 2544, 8152, 272, 1415, 26, 3055, 272, 849, 26, 298, 5066, 2, 272, 3415, 26, 359, 298, 5066, 401, 298, 889, 2, 1622, 523, 3618, 63, 2593, 26, 272, 1369, 26, 489, 446, 4212, 1846, 2544, 3618, 10557, 1536, 12, 315, 4696, 272, 849, 26, 11624, 523, 2813, 63, 4930, 63, 2405, 26, 272, 1369, 26, 489, 446, 2813, 314, 8498, 6464, 402, 314, 5791, 6844, 1265, 3984, 11972, 316, 14, 272, 1415, 26, 3055, 272, 849, 26, 298, 5066, 2, 272, 3415, 26, 2097, 5066, 401, 298, 889, 937, 523, 1174, 26, 272, 1369, 26, 489, 446, 1218, 503, 15095, 4454, 272, 1415, 26, 3055, 272, 849, 26, 283, 1881, 7, 272, 3415, 26, 359, 298, 5720, 401, 298, 14661, 401, 298, 5575, 401, 298, 1881, 2, 1622, 199, 199, 7538, 26, 1362, 446, 298, 496, 3269, 30855, 2, 1362, 446, 298, 1548, 2356, 499, 14, 22, 2,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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
santosh0705/cobbler
cobbler/web/templatetags/site.py
12
11715
from django import template from django.utils.datastructures import SortedDict register = template.Library() # ========================== # -*- coding: utf-8 -*- ''' A smarter {% if %} tag for django templates. While retaining current Django functionality, it also handles equality, greater than and less than operators. Some common case examples:: {% if articles|length >= 5 %}...{% endif %} {% if "ifnotequal tag" != "beautiful" %}...{% endif %} ''' import unittest from django import template register = template.Library() # =============================================================================== # Calculation objects # =============================================================================== class BaseCalc(object): def __init__(self, var1, var2=None, negate=False): self.var1 = var1 self.var2 = var2 self.negate = negate def resolve(self, context): try: var1, var2 = self.resolve_vars(context) outcome = self.calculate(var1, var2) except: outcome = False if self.negate: return not outcome return outcome def resolve_vars(self, context): var2 = self.var2 and self.var2.resolve(context) return self.var1.resolve(context), var2 def calculate(self, var1, var2): raise NotImplementedError() class Or(BaseCalc): def calculate(self, var1, var2): return var1 or var2 class And(BaseCalc): def calculate(self, var1, var2): return var1 and var2 class Equals(BaseCalc): def calculate(self, var1, var2): return var1 == var2 class Greater(BaseCalc): def calculate(self, var1, var2): return var1 > var2 class GreaterOrEqual(BaseCalc): def calculate(self, var1, var2): return var1 >= var2 class In(BaseCalc): def calculate(self, var1, var2): return var1 in var2 # =============================================================================== # Tests # =============================================================================== class TestVar(object): """ A basic self-resolvable object similar to a Django template variable. Used to assist with tests. """ def __init__(self, value): self.value = value def resolve(self, context): return self.value class SmartIfTests(unittest.TestCase): def setUp(self): self.true = TestVar(True) self.false = TestVar(False) self.high = TestVar(9000) self.low = TestVar(1) def assertCalc(self, calc, context=None): """ Test a calculation is True, also checking the inverse "negate" case. """ context = context or {} self.assertTrue(calc.resolve(context)) calc.negate = not calc.negate self.assertFalse(calc.resolve(context)) def assertCalcFalse(self, calc, context=None): """ Test a calculation is False, also checking the inverse "negate" case. """ context = context or {} self.assertFalse(calc.resolve(context)) calc.negate = not calc.negate self.assertTrue(calc.resolve(context)) def test_or(self): self.assertCalc(Or(self.true)) self.assertCalcFalse(Or(self.false)) self.assertCalc(Or(self.true, self.true)) self.assertCalc(Or(self.true, self.false)) self.assertCalc(Or(self.false, self.true)) self.assertCalcFalse(Or(self.false, self.false)) def test_and(self): self.assertCalc(And(self.true, self.true)) self.assertCalcFalse(And(self.true, self.false)) self.assertCalcFalse(And(self.false, self.true)) self.assertCalcFalse(And(self.false, self.false)) def test_equals(self): self.assertCalc(Equals(self.low, self.low)) self.assertCalcFalse(Equals(self.low, self.high)) def test_greater(self): self.assertCalc(Greater(self.high, self.low)) self.assertCalcFalse(Greater(self.low, self.low)) self.assertCalcFalse(Greater(self.low, self.high)) def test_greater_or_equal(self): self.assertCalc(GreaterOrEqual(self.high, self.low)) self.assertCalc(GreaterOrEqual(self.low, self.low)) self.assertCalcFalse(GreaterOrEqual(self.low, self.high)) def test_in(self): list_ = TestVar([1, 2, 3]) invalid_list = TestVar(None) self.assertCalc(In(self.low, list_)) self.assertCalcFalse(In(self.low, invalid_list)) def test_parse_bits(self): var = IfParser([True]).parse() self.assertTrue(var.resolve({})) var = IfParser([False]).parse() self.assertFalse(var.resolve({})) var = IfParser([False, 'or', True]).parse() self.assertTrue(var.resolve({})) var = IfParser([False, 'and', True]).parse() self.assertFalse(var.resolve({})) var = IfParser(['not', False, 'and', 'not', False]).parse() self.assertTrue(var.resolve({})) var = IfParser([1, '=', 1]).parse() self.assertTrue(var.resolve({})) var = IfParser([1, '!=', 1]).parse() self.assertFalse(var.resolve({})) var = IfParser([3, '>', 2]).parse() self.assertTrue(var.resolve({})) var = IfParser([1, '<', 2]).parse() self.assertTrue(var.resolve({})) var = IfParser([2, 'not', 'in', [2, 3]]).parse() self.assertFalse(var.resolve({})) def test_boolean(self): var = IfParser([True, 'and', True, 'and', True]).parse() self.assertTrue(var.resolve({})) var = IfParser([False, 'or', False, 'or', True]).parse() self.assertTrue(var.resolve({})) var = IfParser([True, 'and', False, 'or', True]).parse() self.assertTrue(var.resolve({})) var = IfParser([False, 'or', True, 'and', True]).parse() self.assertTrue(var.resolve({})) var = IfParser([True, 'and', True, 'and', False]).parse() self.assertFalse(var.resolve({})) var = IfParser([False, 'or', False, 'or', False]).parse() self.assertFalse(var.resolve({})) var = IfParser([False, 'or', True, 'and', False]).parse() self.assertFalse(var.resolve({})) var = IfParser([False, 'and', True, 'or', False]).parse() self.assertFalse(var.resolve({})) OPERATORS = { '=': (Equals, True), '==': (Equals, True), '!=': (Equals, False), '>': (Greater, True), '>=': (GreaterOrEqual, True), '<=': (Greater, False), '<': (GreaterOrEqual, False), 'or': (Or, True), 'and': (And, True), 'in': (In, True), } class IfParser(object): error_class = ValueError def __init__(self, tokens): self.tokens = tokens def _get_tokens(self): return self._tokens def _set_tokens(self, tokens): self._tokens = tokens self.len = len(tokens) self.pos = 0 tokens = property(_get_tokens, _set_tokens) def parse(self): if self.at_end(): raise self.error_class('No variables provided.') var1 = self.get_var() while not self.at_end(): token = self.get_token() if token == 'not': if self.at_end(): raise self.error_class('No variable provided after "not".') token = self.get_token() negate = True else: negate = False if token not in OPERATORS: raise self.error_class('%s is not a valid operator.' % token) if self.at_end(): raise self.error_class('No variable provided after "%s"' % token) op, true = OPERATORS[token] if not true: negate = not negate var2 = self.get_var() var1 = op(var1, var2, negate=negate) return var1 def get_token(self): token = self.tokens[self.pos] self.pos += 1 return token def at_end(self): return self.pos >= self.len def create_var(self, value): return TestVar(value) def get_var(self): token = self.get_token() if token == 'not': if self.at_end(): raise self.error_class('No variable provided after "not".') token = self.get_token() return Or(self.create_var(token), negate=True) return self.create_var(token) # =============================================================================== # Actual templatetag code. # =============================================================================== class TemplateIfParser(IfParser): error_class = template.TemplateSyntaxError def __init__(self, parser, *args, **kwargs): self.template_parser = parser super(TemplateIfParser, self).__init__(*args, **kwargs) def create_var(self, value): return self.template_parser.compile_filter(value) class SmartIfNode(template.Node): def __init__(self, var, nodelist_true, nodelist_false=None): self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false self.var = var def render(self, context): if self.var.resolve(context): return self.nodelist_true.render(context) if self.nodelist_false: return self.nodelist_false.render(context) return '' def __repr__(self): return "<Smart If node>" def __iter__(self): for node in self.nodelist_true: yield node if self.nodelist_false: for node in self.nodelist_false: yield node def get_nodes_by_type(self, nodetype): nodes = [] if isinstance(self, nodetype): nodes.append(self) nodes.extend(self.nodelist_true.get_nodes_by_type(nodetype)) if self.nodelist_false: nodes.extend(self.nodelist_false.get_nodes_by_type(nodetype)) return nodes # @register.tag('if') def smart_if(parser, token): ''' A smarter {% if %} tag for django templates. While retaining current Django functionality, it also handles equality, greater than and less than operators. Some common case examples:: {% if articles|length >= 5 %}...{% endif %} {% if "ifnotequal tag" != "beautiful" %}...{% endif %} Arguments and operators _must_ have a space between them, so ``{% if 1>2 %}`` is not a valid smart if tag. All supported operators are: ``or``, ``and``, ``in``, ``=`` (or ``==``), ``!=``, ``>``, ``>=``, ``<`` and ``<=``. ''' bits = token.split_contents()[1:] var = TemplateIfParser(parser, bits).parse() nodelist_true = parser.parse(('else', 'endsmart_if')) token = parser.next_token() if token.contents == 'else': nodelist_false = parser.parse(('endsmart_if',)) parser.delete_first_token() else: nodelist_false = None return SmartIfNode(var, nodelist_true, nodelist_false) # ========================== ifinlist = register.tag(smart_if) # ========================== # Based on code found here: # http://stackoverflow.com/questions/2024660/django-sort-dict-in-template # # Required since dict.items|dictsort doesn't seem to work # when iterating over the keys with a for loop @register.filter(name='sort') def listsort(value): if isinstance(value, dict): new_dict = SortedDict() key_list = value.keys() key_list.sort() for key in key_list: new_dict[key] = value[key] return new_dict elif isinstance(value, list): new_list = list(value) new_list.sort() return new_list else: return value listsort.is_safe = True
gpl-2.0
[ 504, 1639, 492, 1978, 199, 504, 1639, 14, 1208, 14, 23004, 492, 27432, 2141, 199, 199, 2683, 275, 1978, 14, 7424, 342, 199, 199, 3, 16248, 15495, 199, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 2344, 199, 33, 4383, 16972, 7749, 340, 3674, 1947, 367, 1639, 7009, 14, 199, 199, 25215, 8074, 316, 1453, 5634, 9330, 12, 652, 2597, 10022, 16612, 12, 199, 13154, 2419, 436, 6656, 2419, 10211, 14, 6601, 2863, 1930, 7251, 447, 339, 7749, 340, 23242, 92, 1267, 2356, 959, 3674, 1396, 3996, 14454, 3674, 272, 7749, 340, 298, 692, 4610, 537, 1947, 2, 1137, 298, 1235, 25146, 2, 3674, 1396, 3996, 14454, 3674, 199, 2344, 199, 646, 2882, 199, 504, 1639, 492, 1978, 421, 199, 2683, 275, 1978, 14, 7424, 342, 421, 199, 3, 7819, 17224, 199, 3, 19821, 425, 2251, 199, 3, 7819, 17224, 199, 199, 533, 3523, 19511, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 2729, 17, 12, 2729, 18, 29, 403, 12, 30112, 29, 797, 304, 267, 291, 14, 1391, 17, 275, 2729, 17, 267, 291, 14, 1391, 18, 275, 2729, 18, 267, 291, 14, 28901, 275, 30112, 339, 347, 7512, 8, 277, 12, 1067, 304, 267, 862, 26, 288, 2729, 17, 12, 2729, 18, 275, 291, 14, 6983, 63, 2936, 8, 1100, 9, 288, 15955, 275, 291, 14, 12063, 8, 1391, 17, 12, 2729, 18, 9, 267, 871, 26, 288, 15955, 275, 756, 267, 340, 291, 14, 28901, 26, 288, 372, 440, 15955, 267, 372, 15955, 339, 347, 7512, 63, 2936, 8, 277, 12, 1067, 304, 267, 2729, 18, 275, 291, 14, 1391, 18, 436, 291, 14, 1391, 18, 14, 6983, 8, 1100, 9, 267, 372, 291, 14, 1391, 17, 14, 6983, 8, 1100, 395, 2729, 18, 339, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 746, 4279, 342, 421, 199, 533, 4236, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 503, 2729, 18, 421, 199, 533, 6061, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 436, 2729, 18, 421, 199, 533, 221, 13317, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 508, 2729, 18, 421, 199, 533, 598, 5588, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 690, 2729, 18, 421, 199, 533, 598, 5588, 2844, 591, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 2356, 2729, 18, 421, 199, 533, 1010, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 315, 2729, 18, 421, 199, 3, 7819, 17224, 199, 3, 6496, 199, 3, 7819, 17224, 199, 199, 533, 1379, 5894, 8, 785, 304, 272, 408, 272, 437, 5678, 291, 13, 26702, 30456, 909, 8545, 370, 282, 5634, 1978, 1750, 14, 8051, 272, 370, 465, 11734, 543, 2295, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 574, 304, 267, 291, 14, 585, 275, 574, 339, 347, 7512, 8, 277, 12, 1067, 304, 267, 372, 291, 14, 585, 421, 199, 533, 26017, 3917, 2925, 8, 2796, 14, 1746, 304, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 2052, 275, 1379, 5894, 8, 549, 9, 267, 291, 14, 3910, 275, 1379, 5894, 8, 797, 9, 267, 291, 14, 6260, 275, 1379, 5894, 8, 25, 1493, 9, 267, 291, 14, 674, 275, 1379, 5894, 8, 17, 9, 339, 347, 702, 19511, 8, 277, 12, 12831, 12, 1067, 29, 403, 304, 267, 408, 267, 1379, 282, 15232, 365, 715, 12, 2597, 7907, 314, 11484, 298, 28901, 2, 1930, 14, 267, 408, 267, 1067, 275, 1067, 503, 1052, 267, 291, 14, 1815, 8, 8104, 14, 6983, 8, 1100, 430, 267, 12831, 14, 28901, 275, 440, 12831, 14, 28901, 267, 291, 14, 3334, 8, 8104, 14, 6983, 8, 1100, 430, 339, 347, 702, 19511, 797, 8, 277, 12, 12831, 12, 1067, 29, 403, 304, 267, 408, 267, 1379, 282, 15232, 365, 756, 12, 2597, 7907, 314, 11484, 298, 28901, 2, 1930, 14, 267, 408, 267, 1067, 275, 1067, 503, 1052, 267, 291, 14, 3334, 8, 8104, 14, 6983, 8, 1100, 430, 267, 12831, 14, 28901, 275, 440, 12831, 14, 28901, 267, 291, 14, 1815, 8, 8104, 14, 6983, 8, 1100, 430, 339, 347, 511, 63, 269, 8, 277, 304, 267, 291, 14, 479, 19511, 8, 2844, 8, 277, 14, 2052, 430, 267, 291, 14, 479, 19511, 797, 8, 2844, 8, 277, 14, 3910, 430, 267, 291, 14, 479, 19511, 8, 2844, 8, 277, 14, 2052, 12, 291, 14, 2052, 430, 267, 291, 14, 479, 19511, 8, 2844, 8, 277, 14, 2052, 12, 291, 14, 3910, 430, 267, 291, 14, 479, 19511, 8, 2844, 8, 277, 14, 3910, 12, 291, 14, 2052, 430, 267, 291, 14, 479, 19511, 797, 8, 2844, 8, 277, 14, 3910, 12, 291, 14, 3910, 430, 339, 347, 511, 63, 460, 8, 277, 304, 267, 291, 14, 479, 19511, 8, 3325, 8, 277, 14, 2052, 12, 291, 14, 2052, 430, 267, 291, 14, 479, 19511, 797, 8, 3325, 8, 277, 14, 2052, 12, 291, 14, 3910, 430, 267, 291, 14, 479, 19511, 797, 8, 3325, 8, 277, 14, 3910, 12, 291, 14, 2052, 430, 267, 291, 14, 479, 19511, 797, 8, 3325, 8, 277, 14, 3910, 12, 291, 14, 3910, 430, 339, 347, 511, 63, 11332, 8, 277, 304, 267, 291, 14, 479, 19511, 8, 13317, 8, 277, 14, 674, 12, 291, 14, 674, 430, 267, 291, 14, 479, 19511, 797, 8, 13317, 8, 277, 14, 674, 12, 291, 14, 6260, 430, 339, 347, 511, 63, 13154, 8, 277, 304, 267, 291, 14, 479, 19511, 8, 11891, 8, 277, 14, 6260, 12, 291, 14, 674, 430, 267, 291, 14, 479, 19511, 797, 8, 11891, 8, 277, 14, 674, 12, 291, 14, 674, 430, 267, 291, 14, 479, 19511, 797, 8, 11891, 8, 277, 14, 674, 12, 291, 14, 6260, 430, 339, 347, 511, 63 ]
[ 1639, 492, 1978, 199, 504, 1639, 14, 1208, 14, 23004, 492, 27432, 2141, 199, 199, 2683, 275, 1978, 14, 7424, 342, 199, 199, 3, 16248, 15495, 199, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 2344, 199, 33, 4383, 16972, 7749, 340, 3674, 1947, 367, 1639, 7009, 14, 199, 199, 25215, 8074, 316, 1453, 5634, 9330, 12, 652, 2597, 10022, 16612, 12, 199, 13154, 2419, 436, 6656, 2419, 10211, 14, 6601, 2863, 1930, 7251, 447, 339, 7749, 340, 23242, 92, 1267, 2356, 959, 3674, 1396, 3996, 14454, 3674, 272, 7749, 340, 298, 692, 4610, 537, 1947, 2, 1137, 298, 1235, 25146, 2, 3674, 1396, 3996, 14454, 3674, 199, 2344, 199, 646, 2882, 199, 504, 1639, 492, 1978, 421, 199, 2683, 275, 1978, 14, 7424, 342, 421, 199, 3, 7819, 17224, 199, 3, 19821, 425, 2251, 199, 3, 7819, 17224, 199, 199, 533, 3523, 19511, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 2729, 17, 12, 2729, 18, 29, 403, 12, 30112, 29, 797, 304, 267, 291, 14, 1391, 17, 275, 2729, 17, 267, 291, 14, 1391, 18, 275, 2729, 18, 267, 291, 14, 28901, 275, 30112, 339, 347, 7512, 8, 277, 12, 1067, 304, 267, 862, 26, 288, 2729, 17, 12, 2729, 18, 275, 291, 14, 6983, 63, 2936, 8, 1100, 9, 288, 15955, 275, 291, 14, 12063, 8, 1391, 17, 12, 2729, 18, 9, 267, 871, 26, 288, 15955, 275, 756, 267, 340, 291, 14, 28901, 26, 288, 372, 440, 15955, 267, 372, 15955, 339, 347, 7512, 63, 2936, 8, 277, 12, 1067, 304, 267, 2729, 18, 275, 291, 14, 1391, 18, 436, 291, 14, 1391, 18, 14, 6983, 8, 1100, 9, 267, 372, 291, 14, 1391, 17, 14, 6983, 8, 1100, 395, 2729, 18, 339, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 746, 4279, 342, 421, 199, 533, 4236, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 503, 2729, 18, 421, 199, 533, 6061, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 436, 2729, 18, 421, 199, 533, 221, 13317, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 508, 2729, 18, 421, 199, 533, 598, 5588, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 690, 2729, 18, 421, 199, 533, 598, 5588, 2844, 591, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 2356, 2729, 18, 421, 199, 533, 1010, 8, 1563, 19511, 304, 272, 347, 8671, 8, 277, 12, 2729, 17, 12, 2729, 18, 304, 267, 372, 2729, 17, 315, 2729, 18, 421, 199, 3, 7819, 17224, 199, 3, 6496, 199, 3, 7819, 17224, 199, 199, 533, 1379, 5894, 8, 785, 304, 272, 408, 272, 437, 5678, 291, 13, 26702, 30456, 909, 8545, 370, 282, 5634, 1978, 1750, 14, 8051, 272, 370, 465, 11734, 543, 2295, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 574, 304, 267, 291, 14, 585, 275, 574, 339, 347, 7512, 8, 277, 12, 1067, 304, 267, 372, 291, 14, 585, 421, 199, 533, 26017, 3917, 2925, 8, 2796, 14, 1746, 304, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 2052, 275, 1379, 5894, 8, 549, 9, 267, 291, 14, 3910, 275, 1379, 5894, 8, 797, 9, 267, 291, 14, 6260, 275, 1379, 5894, 8, 25, 1493, 9, 267, 291, 14, 674, 275, 1379, 5894, 8, 17, 9, 339, 347, 702, 19511, 8, 277, 12, 12831, 12, 1067, 29, 403, 304, 267, 408, 267, 1379, 282, 15232, 365, 715, 12, 2597, 7907, 314, 11484, 298, 28901, 2, 1930, 14, 267, 408, 267, 1067, 275, 1067, 503, 1052, 267, 291, 14, 1815, 8, 8104, 14, 6983, 8, 1100, 430, 267, 12831, 14, 28901, 275, 440, 12831, 14, 28901, 267, 291, 14, 3334, 8, 8104, 14, 6983, 8, 1100, 430, 339, 347, 702, 19511, 797, 8, 277, 12, 12831, 12, 1067, 29, 403, 304, 267, 408, 267, 1379, 282, 15232, 365, 756, 12, 2597, 7907, 314, 11484, 298, 28901, 2, 1930, 14, 267, 408, 267, 1067, 275, 1067, 503, 1052, 267, 291, 14, 3334, 8, 8104, 14, 6983, 8, 1100, 430, 267, 12831, 14, 28901, 275, 440, 12831, 14, 28901, 267, 291, 14, 1815, 8, 8104, 14, 6983, 8, 1100, 430, 339, 347, 511, 63, 269, 8, 277, 304, 267, 291, 14, 479, 19511, 8, 2844, 8, 277, 14, 2052, 430, 267, 291, 14, 479, 19511, 797, 8, 2844, 8, 277, 14, 3910, 430, 267, 291, 14, 479, 19511, 8, 2844, 8, 277, 14, 2052, 12, 291, 14, 2052, 430, 267, 291, 14, 479, 19511, 8, 2844, 8, 277, 14, 2052, 12, 291, 14, 3910, 430, 267, 291, 14, 479, 19511, 8, 2844, 8, 277, 14, 3910, 12, 291, 14, 2052, 430, 267, 291, 14, 479, 19511, 797, 8, 2844, 8, 277, 14, 3910, 12, 291, 14, 3910, 430, 339, 347, 511, 63, 460, 8, 277, 304, 267, 291, 14, 479, 19511, 8, 3325, 8, 277, 14, 2052, 12, 291, 14, 2052, 430, 267, 291, 14, 479, 19511, 797, 8, 3325, 8, 277, 14, 2052, 12, 291, 14, 3910, 430, 267, 291, 14, 479, 19511, 797, 8, 3325, 8, 277, 14, 3910, 12, 291, 14, 2052, 430, 267, 291, 14, 479, 19511, 797, 8, 3325, 8, 277, 14, 3910, 12, 291, 14, 3910, 430, 339, 347, 511, 63, 11332, 8, 277, 304, 267, 291, 14, 479, 19511, 8, 13317, 8, 277, 14, 674, 12, 291, 14, 674, 430, 267, 291, 14, 479, 19511, 797, 8, 13317, 8, 277, 14, 674, 12, 291, 14, 6260, 430, 339, 347, 511, 63, 13154, 8, 277, 304, 267, 291, 14, 479, 19511, 8, 11891, 8, 277, 14, 6260, 12, 291, 14, 674, 430, 267, 291, 14, 479, 19511, 797, 8, 11891, 8, 277, 14, 674, 12, 291, 14, 674, 430, 267, 291, 14, 479, 19511, 797, 8, 11891, 8, 277, 14, 674, 12, 291, 14, 6260, 430, 339, 347, 511, 63, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
ghber/My-Django-Nonrel
django/conf/locale/mk/formats.py
251
1758
# -*- encoding: utf-8 -*- # This file is distributed under the same license as the Django package. # # The *_FORMAT strings use the Django date format syntax, # see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date DATE_FORMAT = 'd F Y' TIME_FORMAT = 'H:i:s' DATETIME_FORMAT = 'j. F Y. H:i' YEAR_MONTH_FORMAT = 'F Y.' MONTH_DAY_FORMAT = 'j. F' SHORT_DATE_FORMAT = 'j.m.Y.' SHORT_DATETIME_FORMAT = 'j.m.Y. H:i' FIRST_DAY_OF_WEEK = 1 # The *_INPUT_FORMATS strings use the Python strftime format syntax, # see http://docs.python.org/library/datetime.html#strftime-strptime-behavior DATE_INPUT_FORMATS = ( '%d.%m.%Y.', '%d.%m.%y.', # '25.10.2006.', '25.10.06.' '%d. %m. %Y.', '%d. %m. %y.', # '25. 10. 2006.', '25. 10. 06.' '%Y-%m-%d', # '2006-10-25' ) TIME_INPUT_FORMATS = ( '%H:%M:%S', # '14:30:59' '%H:%M', # '14:30' ) DATETIME_INPUT_FORMATS = ( '%d.%m.%Y. %H:%M:%S', # '25.10.2006. 14:30:59' '%d.%m.%Y. %H:%M', # '25.10.2006. 14:30' '%d.%m.%Y.', # '25.10.2006.' '%d.%m.%y. %H:%M:%S', # '25.10.06. 14:30:59' '%d.%m.%y. %H:%M', # '25.10.06. 14:30' '%d.%m.%y.', # '25.10.06.' '%d. %m. %Y. %H:%M:%S', # '25. 10. 2006. 14:30:59' '%d. %m. %Y. %H:%M', # '25. 10. 2006. 14:30' '%d. %m. %Y.', # '25. 10. 2006.' '%d. %m. %y. %H:%M:%S', # '25. 10. 06. 14:30:59' '%d. %m. %y. %H:%M', # '25. 10. 06. 14:30' '%d. %m. %y.', # '25. 10. 06.' '%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59' '%Y-%m-%d %H:%M', # '2006-10-25 14:30' '%Y-%m-%d', # '2006-10-25' ) DECIMAL_SEPARATOR = ',' THOUSAND_SEPARATOR = '.' NUMBER_GROUPING = 3
bsd-3-clause
[ 3, 1882, 2644, 26, 2774, 13, 24, 1882, 199, 3, 961, 570, 365, 1854, 1334, 314, 2011, 4190, 465, 314, 5634, 2559, 14, 199, 3, 199, 199, 3, 710, 20841, 4807, 3326, 675, 314, 5634, 1434, 1475, 6302, 12, 199, 3, 1937, 1455, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 2374, 15, 1121, 15, 5876, 15, 10372, 12645, 602, 199, 5390, 63, 4807, 275, 283, 68, 481, 1488, 7, 199, 4961, 63, 4807, 275, 283, 40, 26, 73, 26, 83, 7, 199, 12488, 63, 4807, 275, 283, 74, 14, 481, 1488, 14, 869, 26, 73, 7, 199, 19216, 63, 16413, 63, 4807, 275, 283, 38, 1488, 3530, 199, 16413, 63, 11655, 63, 4807, 275, 283, 74, 14, 481, 7, 199, 13003, 63, 5390, 63, 4807, 275, 283, 74, 14, 77, 14, 57, 3530, 199, 13003, 63, 12488, 63, 4807, 275, 283, 74, 14, 77, 14, 57, 14, 869, 26, 73, 7, 199, 12903, 63, 11655, 63, 3359, 63, 24929, 275, 413, 199, 199, 3, 710, 20841, 7321, 63, 14019, 3326, 675, 314, 2018, 14053, 1475, 6302, 12, 199, 3, 1937, 1455, 921, 4757, 14, 1548, 14, 1308, 15, 4342, 15, 2083, 14, 1360, 3, 6205, 13, 9866, 13, 17537, 199, 5390, 63, 7321, 63, 14019, 275, 334, 272, 1543, 68, 4111, 77, 4111, 57, 3130, 1543, 68, 4111, 77, 4111, 89, 3130, 755, 327, 283, 821, 14, 709, 14, 7968, 3130, 283, 821, 14, 709, 14, 1690, 3530, 272, 1543, 68, 14, 450, 77, 14, 450, 57, 3130, 1543, 68, 14, 450, 77, 14, 450, 89, 3130, 257, 327, 283, 821, 14, 1616, 14, 8315, 3130, 283, 821, 14, 1616, 14, 24293, 3530, 272, 1543, 57, 3295, 77, 3295, 68, 297, 9326, 327, 283, 7968, 13, 709, 13, 821, 7, 199, 9, 199, 199, 4961, 63, 7321, 63, 14019, 275, 334, 272, 1543, 40, 2689, 45, 2689, 51, 297, 258, 327, 283, 1079, 26, 1216, 26, 1427, 7, 272, 1543, 40, 2689, 45, 297, 263, 327, 283, 1079, 26, 1216, 7, 199, 9, 199, 199, 12488, 63, 7321, 63, 14019, 275, 334, 272, 1543, 68, 4111, 77, 4111, 57, 14, 450, 40, 2689, 45, 2689, 51, 297, 258, 327, 283, 821, 14, 709, 14, 7968, 14, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 4111, 77, 4111, 57, 14, 450, 40, 2689, 45, 297, 263, 327, 283, 821, 14, 709, 14, 7968, 14, 4329, 26, 1216, 7, 272, 1543, 68, 4111, 77, 4111, 57, 3130, 4519, 327, 283, 821, 14, 709, 14, 7968, 3530, 272, 1543, 68, 4111, 77, 4111, 89, 14, 450, 40, 2689, 45, 2689, 51, 297, 258, 327, 283, 821, 14, 709, 14, 1690, 14, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 4111, 77, 4111, 89, 14, 450, 40, 2689, 45, 297, 263, 327, 283, 821, 14, 709, 14, 1690, 14, 4329, 26, 1216, 7, 272, 1543, 68, 4111, 77, 4111, 89, 3130, 4519, 327, 283, 821, 14, 709, 14, 1690, 3530, 272, 1543, 68, 14, 450, 77, 14, 450, 57, 14, 450, 40, 2689, 45, 2689, 51, 297, 257, 327, 283, 821, 14, 1616, 14, 8315, 14, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 14, 450, 77, 14, 450, 57, 14, 450, 40, 2689, 45, 297, 420, 327, 283, 821, 14, 1616, 14, 8315, 14, 4329, 26, 1216, 7, 272, 1543, 68, 14, 450, 77, 14, 450, 57, 3130, 3322, 327, 283, 821, 14, 1616, 14, 8315, 3530, 272, 1543, 68, 14, 450, 77, 14, 450, 89, 14, 450, 40, 2689, 45, 2689, 51, 297, 257, 327, 283, 821, 14, 1616, 14, 24293, 14, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 14, 450, 77, 14, 450, 89, 14, 450, 40, 2689, 45, 297, 420, 327, 283, 821, 14, 1616, 14, 24293, 14, 4329, 26, 1216, 7, 272, 1543, 68, 14, 450, 77, 14, 450, 89, 3130, 3322, 327, 283, 821, 14, 1616, 14, 24293, 3530, 272, 1543, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 297, 420, 327, 283, 7968, 13, 709, 13, 821, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 297, 260, 327, 283, 7968, 13, 709, 13, 821, 4329, 26, 1216, 7, 272, 1543, 57, 3295, 77, 3295, 68, 297, 5185, 327, 283, 7968, 13, 709, 13, 821, 7, 199, 9, 199, 199, 23925, 63, 15828, 275, 13647, 199, 28714, 63, 15828, 275, 7815, 199, 9190, 63, 7823, 1206, 275, 650, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2644, 26, 2774, 13, 24, 1882, 199, 3, 961, 570, 365, 1854, 1334, 314, 2011, 4190, 465, 314, 5634, 2559, 14, 199, 3, 199, 199, 3, 710, 20841, 4807, 3326, 675, 314, 5634, 1434, 1475, 6302, 12, 199, 3, 1937, 1455, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 2374, 15, 1121, 15, 5876, 15, 10372, 12645, 602, 199, 5390, 63, 4807, 275, 283, 68, 481, 1488, 7, 199, 4961, 63, 4807, 275, 283, 40, 26, 73, 26, 83, 7, 199, 12488, 63, 4807, 275, 283, 74, 14, 481, 1488, 14, 869, 26, 73, 7, 199, 19216, 63, 16413, 63, 4807, 275, 283, 38, 1488, 3530, 199, 16413, 63, 11655, 63, 4807, 275, 283, 74, 14, 481, 7, 199, 13003, 63, 5390, 63, 4807, 275, 283, 74, 14, 77, 14, 57, 3530, 199, 13003, 63, 12488, 63, 4807, 275, 283, 74, 14, 77, 14, 57, 14, 869, 26, 73, 7, 199, 12903, 63, 11655, 63, 3359, 63, 24929, 275, 413, 199, 199, 3, 710, 20841, 7321, 63, 14019, 3326, 675, 314, 2018, 14053, 1475, 6302, 12, 199, 3, 1937, 1455, 921, 4757, 14, 1548, 14, 1308, 15, 4342, 15, 2083, 14, 1360, 3, 6205, 13, 9866, 13, 17537, 199, 5390, 63, 7321, 63, 14019, 275, 334, 272, 1543, 68, 4111, 77, 4111, 57, 3130, 1543, 68, 4111, 77, 4111, 89, 3130, 755, 327, 283, 821, 14, 709, 14, 7968, 3130, 283, 821, 14, 709, 14, 1690, 3530, 272, 1543, 68, 14, 450, 77, 14, 450, 57, 3130, 1543, 68, 14, 450, 77, 14, 450, 89, 3130, 257, 327, 283, 821, 14, 1616, 14, 8315, 3130, 283, 821, 14, 1616, 14, 24293, 3530, 272, 1543, 57, 3295, 77, 3295, 68, 297, 9326, 327, 283, 7968, 13, 709, 13, 821, 7, 199, 9, 199, 199, 4961, 63, 7321, 63, 14019, 275, 334, 272, 1543, 40, 2689, 45, 2689, 51, 297, 258, 327, 283, 1079, 26, 1216, 26, 1427, 7, 272, 1543, 40, 2689, 45, 297, 263, 327, 283, 1079, 26, 1216, 7, 199, 9, 199, 199, 12488, 63, 7321, 63, 14019, 275, 334, 272, 1543, 68, 4111, 77, 4111, 57, 14, 450, 40, 2689, 45, 2689, 51, 297, 258, 327, 283, 821, 14, 709, 14, 7968, 14, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 4111, 77, 4111, 57, 14, 450, 40, 2689, 45, 297, 263, 327, 283, 821, 14, 709, 14, 7968, 14, 4329, 26, 1216, 7, 272, 1543, 68, 4111, 77, 4111, 57, 3130, 4519, 327, 283, 821, 14, 709, 14, 7968, 3530, 272, 1543, 68, 4111, 77, 4111, 89, 14, 450, 40, 2689, 45, 2689, 51, 297, 258, 327, 283, 821, 14, 709, 14, 1690, 14, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 4111, 77, 4111, 89, 14, 450, 40, 2689, 45, 297, 263, 327, 283, 821, 14, 709, 14, 1690, 14, 4329, 26, 1216, 7, 272, 1543, 68, 4111, 77, 4111, 89, 3130, 4519, 327, 283, 821, 14, 709, 14, 1690, 3530, 272, 1543, 68, 14, 450, 77, 14, 450, 57, 14, 450, 40, 2689, 45, 2689, 51, 297, 257, 327, 283, 821, 14, 1616, 14, 8315, 14, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 14, 450, 77, 14, 450, 57, 14, 450, 40, 2689, 45, 297, 420, 327, 283, 821, 14, 1616, 14, 8315, 14, 4329, 26, 1216, 7, 272, 1543, 68, 14, 450, 77, 14, 450, 57, 3130, 3322, 327, 283, 821, 14, 1616, 14, 8315, 3530, 272, 1543, 68, 14, 450, 77, 14, 450, 89, 14, 450, 40, 2689, 45, 2689, 51, 297, 257, 327, 283, 821, 14, 1616, 14, 24293, 14, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 14, 450, 77, 14, 450, 89, 14, 450, 40, 2689, 45, 297, 420, 327, 283, 821, 14, 1616, 14, 24293, 14, 4329, 26, 1216, 7, 272, 1543, 68, 14, 450, 77, 14, 450, 89, 3130, 3322, 327, 283, 821, 14, 1616, 14, 24293, 3530, 272, 1543, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 297, 420, 327, 283, 7968, 13, 709, 13, 821, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 297, 260, 327, 283, 7968, 13, 709, 13, 821, 4329, 26, 1216, 7, 272, 1543, 57, 3295, 77, 3295, 68, 297, 5185, 327, 283, 7968, 13, 709, 13, 821, 7, 199, 9, 199, 199, 23925, 63, 15828, 275, 13647, 199, 28714, 63, 15828, 275, 7815, 199, 9190, 63, 7823, 1206, 275, 650, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
karstenw/nodebox-pyobjc
examples/Extended Application/matplotlib/examples/lines_bars_and_markers/simple_plot.py
1
1292
""" =========== Simple Plot =========== Create a simple plot. """ import matplotlib.pyplot as plt import numpy as np # nodebox section if __name__ == '__builtin__': # were in nodebox import os import tempfile W = 800 inset = 20 size(W, 600) plt.cla() plt.clf() plt.close('all') def tempimage(): fob = tempfile.NamedTemporaryFile(mode='w+b', suffix='.png', delete=False) fname = fob.name fob.close() return fname imgx = 20 imgy = 0 def pltshow(plt, dpi=150): global imgx, imgy temppath = tempimage() plt.savefig(temppath, dpi=dpi) dx,dy = imagesize(temppath) w = min(W,dx) image(temppath,imgx,imgy,width=w) imgy = imgy + dy + 20 os.remove(temppath) size(W, HEIGHT+dy+40) else: def pltshow(mplpyplot): mplpyplot.show() # nodebox section end # Data for plotting t = np.arange(0.0, 2.0, 0.01) s = 1 + np.sin(2 * np.pi * t) # Note that using plt.subplots below is equivalent to using # fig = plt.figure and then ax = fig.add_subplot(111) fig, ax = plt.subplots() ax.plot(t, s) ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='About as simple as it gets, folks') ax.grid() fig.savefig("test.png") pltshow(plt)
mit
[ 624, 199, 21326, 199, 3184, 14794, 199, 21326, 199, 199, 2499, 282, 3486, 5137, 14, 199, 624, 199, 646, 8027, 14, 13563, 465, 4488, 199, 646, 2680, 465, 980, 199, 199, 3, 1031, 1977, 3420, 199, 692, 636, 354, 363, 508, 2560, 5351, 3706, 272, 327, 4898, 315, 1031, 1977, 272, 492, 747, 272, 492, 5549, 272, 644, 275, 23466, 272, 315, 409, 275, 3388, 272, 1568, 8, 55, 12, 11624, 9, 272, 4488, 14, 3995, 342, 272, 4488, 14, 9694, 342, 272, 4488, 14, 1600, 360, 452, 358, 272, 347, 2388, 1569, 837, 267, 289, 2873, 275, 5549, 14, 19320, 8, 632, 534, 87, 11, 66, 297, 4739, 15637, 4524, 297, 3145, 29, 797, 9, 267, 6748, 275, 289, 2873, 14, 354, 267, 289, 2873, 14, 1600, 342, 267, 372, 6748, 272, 6050, 88, 275, 3388, 272, 3416, 4312, 275, 378, 272, 347, 1620, 1086, 1917, 8, 6003, 12, 26910, 29, 8251, 304, 267, 2288, 6050, 88, 12, 3416, 4312, 267, 2388, 515, 275, 2388, 1569, 342, 267, 4488, 14, 19556, 8, 808, 515, 12, 26910, 29, 23595, 9, 267, 11868, 12, 8161, 275, 1834, 890, 8, 808, 515, 9, 267, 336, 275, 1748, 8, 55, 12, 8373, 9, 267, 1834, 8, 808, 515, 12, 4060, 88, 12, 4060, 89, 12, 2063, 29, 87, 9, 267, 3416, 4312, 275, 3416, 4312, 435, 13119, 435, 3388, 267, 747, 14, 2168, 8, 808, 515, 9, 267, 1568, 8, 55, 12, 8378, 2830, 11, 8161, 11, 2167, 9, 199, 2836, 26, 272, 347, 1620, 1086, 1917, 8, 2421, 13563, 304, 267, 22513, 13563, 14, 2384, 342, 199, 3, 1031, 1977, 3420, 1284, 199, 199, 3, 3918, 367, 25174, 199, 84, 275, 980, 14, 5605, 8, 16, 14, 16, 12, 499, 14, 16, 12, 378, 14, 614, 9, 199, 83, 275, 413, 435, 980, 14, 5911, 8, 18, 627, 980, 14, 1038, 627, 307, 9, 199, 199, 3, 3390, 626, 1808, 4488, 14, 21430, 5084, 365, 7353, 370, 1808, 199, 3, 6085, 275, 4488, 14, 8941, 436, 2066, 2185, 275, 6085, 14, 525, 63, 13334, 8, 6673, 9, 199, 592, 12, 2185, 275, 4488, 14, 21430, 342, 199, 1219, 14, 2798, 8, 84, 12, 308, 9, 199, 199, 1219, 14, 409, 8, 14168, 534, 521, 334, 83, 3196, 612, 1302, 534, 27543, 334, 25489, 3196, 2126, 2538, 534, 18816, 465, 3486, 465, 652, 7545, 12, 1699, 6080, 358, 199, 1219, 14, 3825, 342, 199, 199, 592, 14, 19556, 480, 396, 14, 4524, 531, 199, 1168, 1086, 1917, 8, 6003, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 21326, 199, 3184, 14794, 199, 21326, 199, 199, 2499, 282, 3486, 5137, 14, 199, 624, 199, 646, 8027, 14, 13563, 465, 4488, 199, 646, 2680, 465, 980, 199, 199, 3, 1031, 1977, 3420, 199, 692, 636, 354, 363, 508, 2560, 5351, 3706, 272, 327, 4898, 315, 1031, 1977, 272, 492, 747, 272, 492, 5549, 272, 644, 275, 23466, 272, 315, 409, 275, 3388, 272, 1568, 8, 55, 12, 11624, 9, 272, 4488, 14, 3995, 342, 272, 4488, 14, 9694, 342, 272, 4488, 14, 1600, 360, 452, 358, 272, 347, 2388, 1569, 837, 267, 289, 2873, 275, 5549, 14, 19320, 8, 632, 534, 87, 11, 66, 297, 4739, 15637, 4524, 297, 3145, 29, 797, 9, 267, 6748, 275, 289, 2873, 14, 354, 267, 289, 2873, 14, 1600, 342, 267, 372, 6748, 272, 6050, 88, 275, 3388, 272, 3416, 4312, 275, 378, 272, 347, 1620, 1086, 1917, 8, 6003, 12, 26910, 29, 8251, 304, 267, 2288, 6050, 88, 12, 3416, 4312, 267, 2388, 515, 275, 2388, 1569, 342, 267, 4488, 14, 19556, 8, 808, 515, 12, 26910, 29, 23595, 9, 267, 11868, 12, 8161, 275, 1834, 890, 8, 808, 515, 9, 267, 336, 275, 1748, 8, 55, 12, 8373, 9, 267, 1834, 8, 808, 515, 12, 4060, 88, 12, 4060, 89, 12, 2063, 29, 87, 9, 267, 3416, 4312, 275, 3416, 4312, 435, 13119, 435, 3388, 267, 747, 14, 2168, 8, 808, 515, 9, 267, 1568, 8, 55, 12, 8378, 2830, 11, 8161, 11, 2167, 9, 199, 2836, 26, 272, 347, 1620, 1086, 1917, 8, 2421, 13563, 304, 267, 22513, 13563, 14, 2384, 342, 199, 3, 1031, 1977, 3420, 1284, 199, 199, 3, 3918, 367, 25174, 199, 84, 275, 980, 14, 5605, 8, 16, 14, 16, 12, 499, 14, 16, 12, 378, 14, 614, 9, 199, 83, 275, 413, 435, 980, 14, 5911, 8, 18, 627, 980, 14, 1038, 627, 307, 9, 199, 199, 3, 3390, 626, 1808, 4488, 14, 21430, 5084, 365, 7353, 370, 1808, 199, 3, 6085, 275, 4488, 14, 8941, 436, 2066, 2185, 275, 6085, 14, 525, 63, 13334, 8, 6673, 9, 199, 592, 12, 2185, 275, 4488, 14, 21430, 342, 199, 1219, 14, 2798, 8, 84, 12, 308, 9, 199, 199, 1219, 14, 409, 8, 14168, 534, 521, 334, 83, 3196, 612, 1302, 534, 27543, 334, 25489, 3196, 2126, 2538, 534, 18816, 465, 3486, 465, 652, 7545, 12, 1699, 6080, 358, 199, 1219, 14, 3825, 342, 199, 199, 592, 14, 19556, 480, 396, 14, 4524, 531, 199, 1168, 1086, 1917, 8, 6003, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
ntonjeta/iidea-Docker
examples/sobel/src/boost_1_63_0/tools/build/test/preprocessor.py
58
1070
#!/usr/bin/python # Copyright 2003 Vladimir Prus # Copyright 2011 Steven Watanabe # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) # Test the C/C++ preprocessor. import BoostBuild t = BoostBuild.Tester() t.write("jamroot.jam", """ project ; preprocessed hello : hello.cpp ; preprocessed a : a.c ; exe hello.exe : hello a : <define>FAIL ; """) t.write("hello.cpp", """ #ifndef __cplusplus #error "This file must be compiled as C++" #endif #ifdef FAIL #error "Not preprocessed?" #endif extern "C" int foo(); int main() { return foo(); } """) t.write("a.c", """ /* This will not compile unless in C mode. */ #ifdef __cplusplus #error "This file must be compiled as C" #endif #ifdef FAIL #error "Not preprocessed?" #endif int foo() { int new = 0; new = (new+1)*7; return new; } """) t.run_build_system() t.expect_addition("bin/$toolset/debug/hello.ii") t.expect_addition("bin/$toolset/debug/a.i") t.expect_addition("bin/$toolset/debug/hello.exe") t.cleanup()
agpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 199, 3, 1898, 13004, 812, 416, 3572, 723, 510, 20791, 199, 3, 1898, 7760, 17854, 1856, 644, 16080, 7570, 199, 3, 17484, 1334, 314, 30470, 2290, 844, 12, 3394, 413, 14, 16, 14, 199, 3, 334, 9295, 23073, 570, 5113, 63, 17, 63, 16, 14, 2424, 503, 1455, 921, 1544, 14, 15589, 14, 1308, 15, 3961, 63, 17, 63, 16, 14, 2424, 9, 199, 199, 3, 1379, 314, 445, 15, 35, 4176, 22335, 14, 199, 199, 646, 30470, 3425, 199, 199, 84, 275, 30470, 3425, 14, 22403, 342, 199, 199, 84, 14, 952, 480, 16997, 1231, 14, 16997, 401, 408, 199, 1715, 8700, 199, 657, 7292, 16509, 520, 16509, 14, 5910, 8700, 199, 657, 7292, 282, 520, 282, 14, 67, 8700, 199, 5803, 16509, 14, 5803, 520, 16509, 282, 520, 665, 4640, 30, 8784, 8700, 199, 6141, 199, 199, 84, 14, 952, 480, 5006, 14, 5910, 401, 408, 199, 3, 27708, 636, 67, 6666, 6666, 199, 3, 705, 298, 2765, 570, 1471, 506, 10311, 465, 445, 4176, 2, 199, 3, 13739, 199, 3, 27737, 10341, 199, 3, 705, 298, 1763, 876, 7292, 13472, 199, 3, 13739, 199, 18587, 298, 35, 2, 1109, 3925, 7303, 199, 442, 2446, 342, 469, 372, 3925, 7303, 789, 199, 6141, 199, 199, 84, 14, 952, 480, 65, 14, 67, 401, 408, 199, 6331, 961, 911, 440, 6555, 7444, 315, 445, 818, 14, 11589, 199, 3, 27737, 636, 67, 6666, 6666, 199, 3, 705, 298, 2765, 570, 1471, 506, 10311, 465, 445, 2, 199, 3, 13739, 199, 3, 27737, 10341, 199, 3, 705, 298, 1763, 876, 7292, 13472, 199, 3, 13739, 199, 442, 3925, 342, 199, 91, 272, 1109, 892, 275, 378, 27, 272, 892, 275, 334, 1222, 11, 17, 3342, 23, 27, 272, 372, 892, 27, 199, 93, 199, 6141, 199, 199, 84, 14, 1065, 63, 1506, 63, 2253, 342, 199, 84, 14, 4921, 63, 26799, 480, 1393, 21792, 12081, 15, 1757, 15, 5006, 14, 5908, 531, 199, 84, 14, 4921, 63, 26799, 480, 1393, 21792, 12081, 15, 1757, 15, 65, 14, 73, 531, 199, 84, 14, 4921, 63, 26799, 480, 1393, 21792, 12081, 15, 1757, 15, 5006, 14, 5803, 531, 199, 199, 84, 14, 7661, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 199, 199, 3, 1898, 13004, 812, 416, 3572, 723, 510, 20791, 199, 3, 1898, 7760, 17854, 1856, 644, 16080, 7570, 199, 3, 17484, 1334, 314, 30470, 2290, 844, 12, 3394, 413, 14, 16, 14, 199, 3, 334, 9295, 23073, 570, 5113, 63, 17, 63, 16, 14, 2424, 503, 1455, 921, 1544, 14, 15589, 14, 1308, 15, 3961, 63, 17, 63, 16, 14, 2424, 9, 199, 199, 3, 1379, 314, 445, 15, 35, 4176, 22335, 14, 199, 199, 646, 30470, 3425, 199, 199, 84, 275, 30470, 3425, 14, 22403, 342, 199, 199, 84, 14, 952, 480, 16997, 1231, 14, 16997, 401, 408, 199, 1715, 8700, 199, 657, 7292, 16509, 520, 16509, 14, 5910, 8700, 199, 657, 7292, 282, 520, 282, 14, 67, 8700, 199, 5803, 16509, 14, 5803, 520, 16509, 282, 520, 665, 4640, 30, 8784, 8700, 199, 6141, 199, 199, 84, 14, 952, 480, 5006, 14, 5910, 401, 408, 199, 3, 27708, 636, 67, 6666, 6666, 199, 3, 705, 298, 2765, 570, 1471, 506, 10311, 465, 445, 4176, 2, 199, 3, 13739, 199, 3, 27737, 10341, 199, 3, 705, 298, 1763, 876, 7292, 13472, 199, 3, 13739, 199, 18587, 298, 35, 2, 1109, 3925, 7303, 199, 442, 2446, 342, 469, 372, 3925, 7303, 789, 199, 6141, 199, 199, 84, 14, 952, 480, 65, 14, 67, 401, 408, 199, 6331, 961, 911, 440, 6555, 7444, 315, 445, 818, 14, 11589, 199, 3, 27737, 636, 67, 6666, 6666, 199, 3, 705, 298, 2765, 570, 1471, 506, 10311, 465, 445, 2, 199, 3, 13739, 199, 3, 27737, 10341, 199, 3, 705, 298, 1763, 876, 7292, 13472, 199, 3, 13739, 199, 442, 3925, 342, 199, 91, 272, 1109, 892, 275, 378, 27, 272, 892, 275, 334, 1222, 11, 17, 3342, 23, 27, 272, 372, 892, 27, 199, 93, 199, 6141, 199, 199, 84, 14, 1065, 63, 1506, 63, 2253, 342, 199, 84, 14, 4921, 63, 26799, 480, 1393, 21792, 12081, 15, 1757, 15, 5006, 14, 5908, 531, 199, 84, 14, 4921, 63, 26799, 480, 1393, 21792, 12081, 15, 1757, 15, 65, 14, 73, 531, 199, 84, 14, 4921, 63, 26799, 480, 1393, 21792, 12081, 15, 1757, 15, 5006, 14, 5803, 531, 199, 199, 84, 14, 7661, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
sciCloud/OLiMS
lims/content/samplepartition.py
2
9978
from dependencies.dependency import ClassSecurityInfo from lims.browser.fields import DurationField from lims.config import PROJECTNAME from lims.content.bikaschema import BikaSchema from lims.interfaces import ISamplePartition from lims.workflow import doActionFor from lims.workflow import skip from dependencies.dependency import DateTime from datetime import timedelta from dependencies.dependency import * from dependencies.dependency import HistoryAwareMixin from dependencies.dependency import DT2dt, dt2DT from dependencies.dependency import getToolByName from dependencies.dependency import safe_unicode from dependencies.dependency import implements schema = BikaSchema.copy() + Schema(( ReferenceField('Container', allowed_types=('Container',), relationship='SamplePartitionContainer', required=1, multiValued=0, ), ReferenceField('Preservation', allowed_types=('Preservation',), relationship='SamplePartitionPreservation', required=0, multiValued=0, ), BooleanField('Separate', default=False ), ReferenceField('Analyses', allowed_types=('Analysis',), relationship='SamplePartitionAnalysis', required=0, multiValued=1, ), DateTimeField('DatePreserved', ), StringField('Preserver', searchable=True ), DurationField('RetentionPeriod', ), ComputedField('DisposalDate', expression = 'context.disposal_date()', widget = ComputedWidget( visible=False, ), ), ) ) schema['title'].required = False class SamplePartition(BaseContent, HistoryAwareMixin): implements(ISamplePartition) security = ClassSecurityInfo() displayContentsTab = False schema = schema _at_rename_after_creation = True def _renameAfterCreation(self, check_auto_id=False): from lims.idserver import renameAfterCreation renameAfterCreation(self) def _getCatalogTool(self): from lims.catalog import getCatalog return getCatalog(self) def Title(self): """ Return the Sample ID as title """ return safe_unicode(self.getId()).encode('utf-8') security.declarePublic('getAnalyses') def getAnalyses(self): """ return list of titles of analyses linked to this sample Partition """ analyses = sorted(self.getBackReferences("AnalysisSamplePartition")) return analyses security.declarePublic('current_date') def current_date(self): """ return current date """ return DateTime() security.declarePublic('disposal_date') def disposal_date(self): """ return disposal date """ DateSampled = self.getDateSampled() # fallback to sampletype retention period st_retention = self.aq_parent.getSampleType().getRetentionPeriod() # but prefer retention period from preservation pres = self.getPreservation() pres_retention = pres and pres.getRetentionPeriod() or None rp = pres_retention and pres_retention or None rp = rp or st_retention td = timedelta( days='days' in rp and int(rp['days']) or 0, hours='hours' in rp and int(rp['hours']) or 0, minutes='minutes' in rp and int(rp['minutes']) or 0) dis_date = DateSampled and dt2DT(DT2dt(DateSampled) + td) or None return dis_date def workflow_script_preserve(self): workflow = getToolByName(self, 'portal_workflow') sample = self.aq_parent # Transition our analyses analyses = self.getBackReferences('AnalysisSamplePartition') if analyses: for analysis in analyses: doActionFor(analysis, "preserve") # if all our siblings are now up to date, promote sample and ARs. parts = sample.objectValues("SamplePartition") if parts: lower_states = ['to_be_sampled', 'to_be_preserved', ] escalate = True for part in parts: if workflow.getInfoFor(part, 'review_state') in lower_states: escalate = False if escalate: doActionFor(sample, "preserve") for ar in sample.getAnalysisRequests(): doActionFor(ar, "preserve") def workflow_transition_expire(self): self.setDateExpired(DateTime()) self.reindexObject(idxs=["review_state", "getDateExpired", ]) def workflow_script_sample(self): if skip(self, "sample"): return sample = self.aq_parent workflow = getToolByName(self, 'portal_workflow') # Transition our analyses analyses = self.getBackReferences('AnalysisSamplePartition') for analysis in analyses: doActionFor(analysis, "sample") # if all our siblings are now up to date, promote sample and ARs. parts = sample.objectValues("SamplePartition") if parts: lower_states = ['to_be_sampled', ] escalate = True for part in parts: pstate = workflow.getInfoFor(part, 'review_state') if pstate in lower_states: escalate = False if escalate: doActionFor(sample, "sample") for ar in sample.getAnalysisRequests(): doActionFor(ar, "sample") def workflow_script_to_be_preserved(self): if skip(self, "to_be_preserved"): return sample = self.aq_parent workflow = getToolByName(self, 'portal_workflow') # Transition our analyses analyses = self.getBackReferences('AnalysisSamplePartition') for analysis in analyses: doActionFor(analysis, "to_be_preserved") # if all our siblings are now up to date, promote sample and ARs. parts = sample.objectValues("SamplePartition") if parts: lower_states = ['to_be_sampled', 'to_be_preserved', ] escalate = True for part in parts: if workflow.getInfoFor(part, 'review_state') in lower_states: escalate = False if escalate: doActionFor(sample, "to_be_preserved") for ar in sample.getAnalysisRequests(): doActionFor(ar, "to_be_preserved") def workflow_script_sample_due(self): if skip(self, "sample_due"): return sample = self.aq_parent workflow = getToolByName(self, 'portal_workflow') # Transition our analyses analyses = self.getBackReferences('AnalysisSamplePartition') for analysis in analyses: doActionFor(analysis, "sample_due") # if all our siblings are now up to date, promote sample and ARs. parts = sample.objectValues("SamplePartition") if parts: lower_states = ['to_be_preserved', ] escalate = True for part in parts: pstate = workflow.getInfoFor(part, 'review_state') if pstate in lower_states: escalate = False if escalate: doActionFor(sample, "sample_due") for ar in sample.getAnalysisRequests(): doActionFor(ar, "sample_due") def workflow_script_receive(self): if skip(self, "receive"): return sample = self.aq_parent workflow = getToolByName(self, 'portal_workflow') sample_state = workflow.getInfoFor(sample, 'review_state') self.setDateReceived(DateTime()) self.reindexObject(idxs=["getDateReceived", ]) # Transition our analyses analyses = self.getBackReferences('AnalysisSamplePartition') for analysis in analyses: doActionFor(analysis, "receive") # if all sibling partitions are received, promote sample if not skip(sample, "receive", peek=True): due = [sp for sp in sample.objectValues("SamplePartition") if workflow.getInfoFor(sp, 'review_state') == 'sample_due'] if sample_state == 'sample_due' and not due: doActionFor(sample, 'receive') def workflow_script_reinstate(self): if skip(self, "reinstate"): return sample = self.aq_parent workflow = getToolByName(self, 'portal_workflow') self.reindexObject(idxs=["cancellation_state", ]) sample_c_state = workflow.getInfoFor(sample, 'cancellation_state') # if all sibling partitions are active, activate sample if not skip(sample, "reinstate", peek=True): cancelled = [sp for sp in sample.objectValues("SamplePartition") if workflow.getInfoFor(sp, 'cancellation_state') == 'cancelled'] if sample_c_state == 'cancelled' and not cancelled: workflow.doActionFor(sample, 'reinstate') def workflow_script_cancel(self): if skip(self, "cancel"): return sample = self.aq_parent workflow = getToolByName(self, 'portal_workflow') self.reindexObject(idxs=["cancellation_state", ]) sample_c_state = workflow.getInfoFor(sample, 'cancellation_state') # if all sibling partitions are cancelled, cancel sample if not skip(sample, "cancel", peek=True): active = [sp for sp in sample.objectValues("SamplePartition") if workflow.getInfoFor(sp, 'cancellation_state') == 'active'] if sample_c_state == 'active' and not active: workflow.doActionFor(sample, 'cancel') registerType(SamplePartition, PROJECTNAME)
agpl-3.0
[ 504, 5124, 14, 8575, 492, 8089, 7676, 2354, 202, 199, 504, 1212, 706, 14, 5750, 14, 955, 492, 31836, 792, 202, 199, 504, 1212, 706, 14, 888, 492, 21915, 2339, 202, 199, 504, 1212, 706, 14, 1317, 14, 66, 3258, 305, 2095, 492, 699, 26966, 6700, 202, 199, 504, 1212, 706, 14, 7436, 492, 2281, 865, 13068, 202, 199, 504, 1212, 706, 14, 8856, 492, 886, 3310, 1858, 202, 199, 504, 1212, 706, 14, 8856, 492, 3372, 202, 199, 504, 5124, 14, 8575, 492, 13686, 202, 199, 504, 2197, 492, 6871, 202, 199, 504, 5124, 14, 8575, 492, 627, 202, 199, 504, 5124, 14, 8575, 492, 27829, 24290, 4256, 202, 199, 504, 5124, 14, 8575, 492, 19852, 18, 3583, 12, 4487, 18, 7438, 202, 199, 504, 5124, 14, 8575, 492, 664, 5157, 11190, 202, 199, 504, 5124, 14, 8575, 492, 5048, 63, 2975, 202, 199, 504, 5124, 14, 8575, 492, 9031, 2999, 199, 3629, 275, 699, 26966, 6700, 14, 1574, 342, 435, 13268, 1332, 1128, 10944, 792, 360, 4076, 297, 1039, 4370, 63, 1313, 7782, 4076, 5529, 1039, 8931, 534, 8176, 13068, 4076, 297, 1039, 1415, 29, 17, 12, 1039, 3510, 1110, 68, 29, 16, 12, 1128, 2318, 1128, 10944, 792, 360, 2398, 8213, 297, 1039, 4370, 63, 1313, 7782, 2398, 8213, 5529, 1039, 8931, 534, 8176, 13068, 2398, 8213, 297, 1039, 1415, 29, 16, 12, 1039, 3510, 1110, 68, 29, 16, 12, 1128, 2318, 1128, 9411, 792, 360, 12653, 323, 297, 1039, 849, 29, 797, 1128, 2318, 1128, 10944, 792, 360, 8014, 874, 297, 1039, 4370, 63, 1313, 7782, 13182, 5529, 1039, 8931, 534, 8176, 13068, 13182, 297, 1039, 1415, 29, 16, 12, 1039, 3510, 1110, 68, 29, 17, 12, 1128, 2318, 1128, 31637, 360, 2506, 2398, 2485, 297, 1128, 2318, 1128, 21409, 360, 2398, 1000, 297, 1039, 2754, 461, 29, 549, 1128, 2318, 1128, 31836, 792, 360, 497, 9553, 15518, 297, 1128, 2318, 1128, 3599, 4241, 792, 360, 2825, 14506, 2506, 297, 1039, 3965, 275, 283, 1100, 14, 2297, 14506, 63, 602, 19633, 1039, 3938, 275, 3599, 4241, 3339, 8, 1675, 8917, 29, 797, 12, 1039, 2318, 1128, 2318, 202, 199, 9, 202, 199, 9, 2999, 199, 3629, 459, 1213, 2278, 2427, 275, 756, 8065, 199, 533, 15227, 13068, 8, 1563, 2714, 12, 27829, 24290, 4256, 304, 1128, 9031, 8, 1311, 865, 13068, 9, 1128, 6391, 275, 8089, 7676, 2354, 342, 1128, 2929, 11383, 7690, 275, 756, 1128, 4177, 275, 4177, 2958, 485, 292, 63, 8165, 63, 4399, 63, 8782, 275, 715, 2958, 347, 485, 8165, 10881, 13921, 8, 277, 12, 1104, 63, 2495, 63, 344, 29, 797, 304, 1039, 687, 1212, 706, 14, 344, 1000, 492, 11441, 10881, 13921, 1039, 11441, 10881, 13921, 8, 277, 9, 2958, 347, 485, 362, 17161, 5157, 8, 277, 304, 1039, 687, 1212, 706, 14, 7959, 492, 664, 17161, 1039, 372, 664, 17161, 8, 277, 9, 2958, 347, 16881, 8, 277, 304, 1039, 408, 1432, 314, 15227, 2870, 465, 2538, 408, 1039, 372, 5048, 63, 2975, 8, 277, 14, 362, 1304, 8801, 2143, 360, 1624, 13, 24, 358, 2958, 6391, 14, 16536, 9885, 360, 362, 8014, 874, 358, 2958, 347, 664, 8014, 874, 8, 277, 304, 1039, 408, 372, 769, 402, 16194, 402, 5909, 874, 10632, 370, 642, 2690, 27353, 408, 1039, 5909, 874, 275, 3355, 8, 277, 14, 362, 4540, 15242, 480, 13182, 8176, 13068, 2237, 1039, 372, 5909, 874, 2958, 6391, 14, 16536, 9885, 360, 1818, 63, 602, 358, 2958, 347, 1453, 63, 602, 8, 277, 304, 1039, 408, 372, 1453, 1434, 408, 1039, 372, 13686, 342, 2958, 6391, 14, 16536, 9885, 360, 2297, 14506, 63, 602, 358, 2958, 347, 2153, 14506, 63, 602, 8, 277, 304, 1039, 408, 372, 2153, 14506, 1434, 408, 4341, 6148, 8176, 68, 275, 291, 14, 362, 2506, 8176, 68, 342, 4341, 327, 9567, 370, 2690, 466, 295, 9553, 6247, 1039, 410, 63, 28307, 275, 291, 14, 30030, 63, 1708, 14, 362, 8176, 804, 1252, 362, 497, 9553, 15518, 342, 4341, 327, 1325, 16602, 295, 9553, 6247, 687, 876, 8213, 1039, 25210, 275, 291, 14, 362, 2398, 8213, 342, 1039, 25210, 63, 28307, 275, 25210, 436, 25210, 14, 362, 497, 9553, 15518, 342, 503, 488, 4341, 15099, 275, 25210, 63, 28307, 436, 25210, 63, 28307, 503, 488, 1039, 15099, 275, 15099, 503, 410, 63, 28307, 4341, 12749, 275, 6871, 8, 1675, 7609, 534, 4899, 7, 315, 15099, 436, 1109, 8, 4599, 459, 4899, 1105, 503, 378, 12, 1675, 10857, 534, 8419, 7, 315, 15099, 436, 1109, 8, 4599, 459, 8419, 1105, 503, 378, 12, 1675, 9395, 534, 10430, 7, 315, 15099, 436, 1109, 8, 4599, 459, 10430, 1105, 503, 378, 9, 4341, 2153, 63, 602, 275, 6148, 8176, 68, 436, 4487, 18, 7438, 8, 7438, 18, 3583, 8, 2506, 8176, 68, 9, 435, 12749, 9, 503, 488, 1039, 372, 2153, 63, 602, 2958, 347, 10431, 63, 1579, 63, 17053, 8, 277, 304, 1039, 10431, 275, 664, 5157, 11190, 8, 277, 12, 283, 8707, 63, 8856, 358, 1039, 2690, 275, 291, 14, 30030, 63, 1708, 1039, 327, 19894, 1588, 4154, 5909, 874, 1039, 5909, 874, 275, 291, 14, 362, 4540, 15242, 360, 13182, 8176, 13068, 358, 1039, 340, 5909, 874, 26, 1675, 367, 11284, 315, 5909, 874, 26, 2628, 886, 3310, 1858, 8, 10466, 12, 298, 17053, 531, 1039, 327, 340, 1006, 4154, 31871, 787, 3063, 1536, 370, 1434, 12, 10016, 2690, 436, 4160, 83, 14, 1039, 4184, 275, 2690, 14, 785, 6550, 480, 8176, 13068, 531, 1039, 340, 4184, 26, 1675, 5117, 63, 4981, 275, 788, 475, 63, 1235, 63, 25042, 297, 283, 475, 63, 1235, 63, 32104, 297, 1622, 1675, 325, 4732, 323, 275, 715, 1675, 367, 1777, 315, 4184, 26, 2628, 340, 10431, 14, 362, 2354, 1858, 8, 2064, 12, 283, 8578, 63, 929, 358, 315, 5117, 63, 4981, 26, 4906, 325, 4732, 323, 275, 756, 1675, 340, 325, 4732, 323, 26, 2628, 886, 3310, 1858, 8, 3271, 12, 298, 17053, 531, 2628, 367, 601, 315, 2690, 14, 362, 13182, 16272, 837, 4906, 886, 3310, 1858, 8, 285, 12, 298, 17053, 531, 2958, 347, 10431, 63, 14143, 63, 14691, 8, 277, 304, 1039, 291, 14, 409, 2506, 20898, 8, 3926, 1012, 1039, 291, 14, 21764, 1692, 8 ]
[ 5124, 14, 8575, 492, 8089, 7676, 2354, 202, 199, 504, 1212, 706, 14, 5750, 14, 955, 492, 31836, 792, 202, 199, 504, 1212, 706, 14, 888, 492, 21915, 2339, 202, 199, 504, 1212, 706, 14, 1317, 14, 66, 3258, 305, 2095, 492, 699, 26966, 6700, 202, 199, 504, 1212, 706, 14, 7436, 492, 2281, 865, 13068, 202, 199, 504, 1212, 706, 14, 8856, 492, 886, 3310, 1858, 202, 199, 504, 1212, 706, 14, 8856, 492, 3372, 202, 199, 504, 5124, 14, 8575, 492, 13686, 202, 199, 504, 2197, 492, 6871, 202, 199, 504, 5124, 14, 8575, 492, 627, 202, 199, 504, 5124, 14, 8575, 492, 27829, 24290, 4256, 202, 199, 504, 5124, 14, 8575, 492, 19852, 18, 3583, 12, 4487, 18, 7438, 202, 199, 504, 5124, 14, 8575, 492, 664, 5157, 11190, 202, 199, 504, 5124, 14, 8575, 492, 5048, 63, 2975, 202, 199, 504, 5124, 14, 8575, 492, 9031, 2999, 199, 3629, 275, 699, 26966, 6700, 14, 1574, 342, 435, 13268, 1332, 1128, 10944, 792, 360, 4076, 297, 1039, 4370, 63, 1313, 7782, 4076, 5529, 1039, 8931, 534, 8176, 13068, 4076, 297, 1039, 1415, 29, 17, 12, 1039, 3510, 1110, 68, 29, 16, 12, 1128, 2318, 1128, 10944, 792, 360, 2398, 8213, 297, 1039, 4370, 63, 1313, 7782, 2398, 8213, 5529, 1039, 8931, 534, 8176, 13068, 2398, 8213, 297, 1039, 1415, 29, 16, 12, 1039, 3510, 1110, 68, 29, 16, 12, 1128, 2318, 1128, 9411, 792, 360, 12653, 323, 297, 1039, 849, 29, 797, 1128, 2318, 1128, 10944, 792, 360, 8014, 874, 297, 1039, 4370, 63, 1313, 7782, 13182, 5529, 1039, 8931, 534, 8176, 13068, 13182, 297, 1039, 1415, 29, 16, 12, 1039, 3510, 1110, 68, 29, 17, 12, 1128, 2318, 1128, 31637, 360, 2506, 2398, 2485, 297, 1128, 2318, 1128, 21409, 360, 2398, 1000, 297, 1039, 2754, 461, 29, 549, 1128, 2318, 1128, 31836, 792, 360, 497, 9553, 15518, 297, 1128, 2318, 1128, 3599, 4241, 792, 360, 2825, 14506, 2506, 297, 1039, 3965, 275, 283, 1100, 14, 2297, 14506, 63, 602, 19633, 1039, 3938, 275, 3599, 4241, 3339, 8, 1675, 8917, 29, 797, 12, 1039, 2318, 1128, 2318, 202, 199, 9, 202, 199, 9, 2999, 199, 3629, 459, 1213, 2278, 2427, 275, 756, 8065, 199, 533, 15227, 13068, 8, 1563, 2714, 12, 27829, 24290, 4256, 304, 1128, 9031, 8, 1311, 865, 13068, 9, 1128, 6391, 275, 8089, 7676, 2354, 342, 1128, 2929, 11383, 7690, 275, 756, 1128, 4177, 275, 4177, 2958, 485, 292, 63, 8165, 63, 4399, 63, 8782, 275, 715, 2958, 347, 485, 8165, 10881, 13921, 8, 277, 12, 1104, 63, 2495, 63, 344, 29, 797, 304, 1039, 687, 1212, 706, 14, 344, 1000, 492, 11441, 10881, 13921, 1039, 11441, 10881, 13921, 8, 277, 9, 2958, 347, 485, 362, 17161, 5157, 8, 277, 304, 1039, 687, 1212, 706, 14, 7959, 492, 664, 17161, 1039, 372, 664, 17161, 8, 277, 9, 2958, 347, 16881, 8, 277, 304, 1039, 408, 1432, 314, 15227, 2870, 465, 2538, 408, 1039, 372, 5048, 63, 2975, 8, 277, 14, 362, 1304, 8801, 2143, 360, 1624, 13, 24, 358, 2958, 6391, 14, 16536, 9885, 360, 362, 8014, 874, 358, 2958, 347, 664, 8014, 874, 8, 277, 304, 1039, 408, 372, 769, 402, 16194, 402, 5909, 874, 10632, 370, 642, 2690, 27353, 408, 1039, 5909, 874, 275, 3355, 8, 277, 14, 362, 4540, 15242, 480, 13182, 8176, 13068, 2237, 1039, 372, 5909, 874, 2958, 6391, 14, 16536, 9885, 360, 1818, 63, 602, 358, 2958, 347, 1453, 63, 602, 8, 277, 304, 1039, 408, 372, 1453, 1434, 408, 1039, 372, 13686, 342, 2958, 6391, 14, 16536, 9885, 360, 2297, 14506, 63, 602, 358, 2958, 347, 2153, 14506, 63, 602, 8, 277, 304, 1039, 408, 372, 2153, 14506, 1434, 408, 4341, 6148, 8176, 68, 275, 291, 14, 362, 2506, 8176, 68, 342, 4341, 327, 9567, 370, 2690, 466, 295, 9553, 6247, 1039, 410, 63, 28307, 275, 291, 14, 30030, 63, 1708, 14, 362, 8176, 804, 1252, 362, 497, 9553, 15518, 342, 4341, 327, 1325, 16602, 295, 9553, 6247, 687, 876, 8213, 1039, 25210, 275, 291, 14, 362, 2398, 8213, 342, 1039, 25210, 63, 28307, 275, 25210, 436, 25210, 14, 362, 497, 9553, 15518, 342, 503, 488, 4341, 15099, 275, 25210, 63, 28307, 436, 25210, 63, 28307, 503, 488, 1039, 15099, 275, 15099, 503, 410, 63, 28307, 4341, 12749, 275, 6871, 8, 1675, 7609, 534, 4899, 7, 315, 15099, 436, 1109, 8, 4599, 459, 4899, 1105, 503, 378, 12, 1675, 10857, 534, 8419, 7, 315, 15099, 436, 1109, 8, 4599, 459, 8419, 1105, 503, 378, 12, 1675, 9395, 534, 10430, 7, 315, 15099, 436, 1109, 8, 4599, 459, 10430, 1105, 503, 378, 9, 4341, 2153, 63, 602, 275, 6148, 8176, 68, 436, 4487, 18, 7438, 8, 7438, 18, 3583, 8, 2506, 8176, 68, 9, 435, 12749, 9, 503, 488, 1039, 372, 2153, 63, 602, 2958, 347, 10431, 63, 1579, 63, 17053, 8, 277, 304, 1039, 10431, 275, 664, 5157, 11190, 8, 277, 12, 283, 8707, 63, 8856, 358, 1039, 2690, 275, 291, 14, 30030, 63, 1708, 1039, 327, 19894, 1588, 4154, 5909, 874, 1039, 5909, 874, 275, 291, 14, 362, 4540, 15242, 360, 13182, 8176, 13068, 358, 1039, 340, 5909, 874, 26, 1675, 367, 11284, 315, 5909, 874, 26, 2628, 886, 3310, 1858, 8, 10466, 12, 298, 17053, 531, 1039, 327, 340, 1006, 4154, 31871, 787, 3063, 1536, 370, 1434, 12, 10016, 2690, 436, 4160, 83, 14, 1039, 4184, 275, 2690, 14, 785, 6550, 480, 8176, 13068, 531, 1039, 340, 4184, 26, 1675, 5117, 63, 4981, 275, 788, 475, 63, 1235, 63, 25042, 297, 283, 475, 63, 1235, 63, 32104, 297, 1622, 1675, 325, 4732, 323, 275, 715, 1675, 367, 1777, 315, 4184, 26, 2628, 340, 10431, 14, 362, 2354, 1858, 8, 2064, 12, 283, 8578, 63, 929, 358, 315, 5117, 63, 4981, 26, 4906, 325, 4732, 323, 275, 756, 1675, 340, 325, 4732, 323, 26, 2628, 886, 3310, 1858, 8, 3271, 12, 298, 17053, 531, 2628, 367, 601, 315, 2690, 14, 362, 13182, 16272, 837, 4906, 886, 3310, 1858, 8, 285, 12, 298, 17053, 531, 2958, 347, 10431, 63, 14143, 63, 14691, 8, 277, 304, 1039, 291, 14, 409, 2506, 20898, 8, 3926, 1012, 1039, 291, 14, 21764, 1692, 8, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
AltSchool/django
tests/template_tests/filter_tests/test_striptags.py
197
1632
from django.template.defaultfilters import striptags from django.test import SimpleTestCase from django.utils.functional import lazystr from django.utils.safestring import mark_safe from ..utils import setup class StriptagsTests(SimpleTestCase): @setup({'striptags01': '{{ a|striptags }} {{ b|striptags }}'}) def test_striptags01(self): output = self.engine.render_to_string( 'striptags01', { 'a': '<a>x</a> <p><b>y</b></p>', 'b': mark_safe('<a>x</a> <p><b>y</b></p>'), }, ) self.assertEqual(output, 'x y x y') @setup({'striptags02': '{% autoescape off %}{{ a|striptags }} {{ b|striptags }}{% endautoescape %}'}) def test_striptags02(self): output = self.engine.render_to_string( 'striptags02', { 'a': '<a>x</a> <p><b>y</b></p>', 'b': mark_safe('<a>x</a> <p><b>y</b></p>'), }, ) self.assertEqual(output, 'x y x y') class FunctionTests(SimpleTestCase): def test_strip(self): self.assertEqual( striptags('some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags'), 'some html with alert("You smell") disallowed tags', ) def test_non_string_input(self): self.assertEqual(striptags(123), '123') def test_strip_lazy_string(self): self.assertEqual( striptags(lazystr('some <b>html</b> with <script>alert("Hello")</script> disallowed <img /> tags')), 'some html with alert("Hello") disallowed tags', )
bsd-3-clause
[ 504, 1639, 14, 1160, 14, 885, 4273, 492, 6202, 2969, 199, 504, 1639, 14, 396, 492, 24424, 199, 504, 1639, 14, 1208, 14, 15481, 492, 9617, 495, 199, 504, 1639, 14, 1208, 14, 28389, 492, 2216, 63, 3489, 199, 199, 504, 2508, 1208, 492, 3272, 421, 199, 533, 19828, 2969, 2925, 8, 17968, 304, 339, 768, 2758, 3252, 1913, 2969, 614, 356, 11400, 282, 92, 1913, 2969, 3586, 8448, 330, 92, 1913, 2969, 29281, 272, 347, 511, 63, 1913, 2969, 614, 8, 277, 304, 267, 1072, 275, 291, 14, 3908, 14, 3352, 63, 475, 63, 875, 8, 288, 283, 1913, 2969, 614, 297, 288, 469, 355, 283, 65, 356, 2650, 65, 30, 88, 1108, 65, 30, 665, 80, 2535, 66, 30, 89, 1108, 66, 2957, 80, 4206, 355, 283, 66, 356, 2216, 63, 3489, 4827, 65, 30, 88, 1108, 65, 30, 665, 80, 2535, 66, 30, 89, 1108, 66, 2957, 80, 25642, 288, 1660, 267, 776, 267, 291, 14, 629, 8, 1199, 12, 283, 88, 612, 671, 612, 358, 339, 768, 2758, 3252, 1913, 2969, 996, 356, 12100, 19102, 2331, 17337, 282, 92, 1913, 2969, 3586, 8448, 330, 92, 1913, 2969, 20104, 1284, 15818, 17776, 272, 347, 511, 63, 1913, 2969, 996, 8, 277, 304, 267, 1072, 275, 291, 14, 3908, 14, 3352, 63, 475, 63, 875, 8, 288, 283, 1913, 2969, 996, 297, 288, 469, 355, 283, 65, 356, 2650, 65, 30, 88, 1108, 65, 30, 665, 80, 2535, 66, 30, 89, 1108, 66, 2957, 80, 4206, 355, 283, 66, 356, 2216, 63, 3489, 4827, 65, 30, 88, 1108, 65, 30, 665, 80, 2535, 66, 30, 89, 1108, 66, 2957, 80, 25642, 288, 1660, 267, 776, 267, 291, 14, 629, 8, 1199, 12, 283, 88, 612, 671, 612, 358, 421, 199, 533, 6801, 2925, 8, 17968, 304, 339, 347, 511, 63, 1913, 8, 277, 304, 267, 291, 14, 629, 8, 288, 6202, 2969, 360, 3972, 665, 66, 30, 1360, 1108, 66, 30, 543, 665, 1579, 30, 9241, 480, 5556, 308, 278, 914, 531, 1108, 1579, 30, 30994, 665, 4060, 7082, 3762, 659, 288, 283, 3972, 3517, 543, 10459, 480, 5556, 308, 278, 914, 531, 30994, 221, 3762, 297, 267, 776, 339, 347, 511, 63, 2865, 63, 875, 63, 1210, 8, 277, 304, 267, 291, 14, 629, 8, 1913, 2969, 8, 4288, 395, 283, 4288, 358, 339, 347, 511, 63, 1913, 63, 6395, 63, 875, 8, 277, 304, 267, 291, 14, 629, 8, 288, 6202, 2969, 8, 6395, 495, 360, 3972, 665, 66, 30, 1360, 1108, 66, 30, 543, 665, 1579, 30, 9241, 480, 6257, 531, 1108, 1579, 30, 30994, 665, 4060, 7082, 3762, 3855, 288, 283, 3972, 3517, 543, 10459, 480, 6257, 531, 30994, 221, 3762, 297, 267, 776, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1639, 14, 1160, 14, 885, 4273, 492, 6202, 2969, 199, 504, 1639, 14, 396, 492, 24424, 199, 504, 1639, 14, 1208, 14, 15481, 492, 9617, 495, 199, 504, 1639, 14, 1208, 14, 28389, 492, 2216, 63, 3489, 199, 199, 504, 2508, 1208, 492, 3272, 421, 199, 533, 19828, 2969, 2925, 8, 17968, 304, 339, 768, 2758, 3252, 1913, 2969, 614, 356, 11400, 282, 92, 1913, 2969, 3586, 8448, 330, 92, 1913, 2969, 29281, 272, 347, 511, 63, 1913, 2969, 614, 8, 277, 304, 267, 1072, 275, 291, 14, 3908, 14, 3352, 63, 475, 63, 875, 8, 288, 283, 1913, 2969, 614, 297, 288, 469, 355, 283, 65, 356, 2650, 65, 30, 88, 1108, 65, 30, 665, 80, 2535, 66, 30, 89, 1108, 66, 2957, 80, 4206, 355, 283, 66, 356, 2216, 63, 3489, 4827, 65, 30, 88, 1108, 65, 30, 665, 80, 2535, 66, 30, 89, 1108, 66, 2957, 80, 25642, 288, 1660, 267, 776, 267, 291, 14, 629, 8, 1199, 12, 283, 88, 612, 671, 612, 358, 339, 768, 2758, 3252, 1913, 2969, 996, 356, 12100, 19102, 2331, 17337, 282, 92, 1913, 2969, 3586, 8448, 330, 92, 1913, 2969, 20104, 1284, 15818, 17776, 272, 347, 511, 63, 1913, 2969, 996, 8, 277, 304, 267, 1072, 275, 291, 14, 3908, 14, 3352, 63, 475, 63, 875, 8, 288, 283, 1913, 2969, 996, 297, 288, 469, 355, 283, 65, 356, 2650, 65, 30, 88, 1108, 65, 30, 665, 80, 2535, 66, 30, 89, 1108, 66, 2957, 80, 4206, 355, 283, 66, 356, 2216, 63, 3489, 4827, 65, 30, 88, 1108, 65, 30, 665, 80, 2535, 66, 30, 89, 1108, 66, 2957, 80, 25642, 288, 1660, 267, 776, 267, 291, 14, 629, 8, 1199, 12, 283, 88, 612, 671, 612, 358, 421, 199, 533, 6801, 2925, 8, 17968, 304, 339, 347, 511, 63, 1913, 8, 277, 304, 267, 291, 14, 629, 8, 288, 6202, 2969, 360, 3972, 665, 66, 30, 1360, 1108, 66, 30, 543, 665, 1579, 30, 9241, 480, 5556, 308, 278, 914, 531, 1108, 1579, 30, 30994, 665, 4060, 7082, 3762, 659, 288, 283, 3972, 3517, 543, 10459, 480, 5556, 308, 278, 914, 531, 30994, 221, 3762, 297, 267, 776, 339, 347, 511, 63, 2865, 63, 875, 63, 1210, 8, 277, 304, 267, 291, 14, 629, 8, 1913, 2969, 8, 4288, 395, 283, 4288, 358, 339, 347, 511, 63, 1913, 63, 6395, 63, 875, 8, 277, 304, 267, 291, 14, 629, 8, 288, 6202, 2969, 8, 6395, 495, 360, 3972, 665, 66, 30, 1360, 1108, 66, 30, 543, 665, 1579, 30, 9241, 480, 6257, 531, 1108, 1579, 30, 30994, 665, 4060, 7082, 3762, 3855, 288, 283, 3972, 3517, 543, 10459, 480, 6257, 531, 30994, 221, 3762, 297, 267, 776, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
morissette/devopsdays-hackathon-2016
venv/lib/python2.7/site-packages/werkzeug/contrib/profiler.py
362
5151
# -*- coding: utf-8 -*- """ werkzeug.contrib.profiler ~~~~~~~~~~~~~~~~~~~~~~~~~ This module provides a simple WSGI profiler middleware for finding bottlenecks in web application. It uses the :mod:`profile` or :mod:`cProfile` module to do the profiling and writes the stats to the stream provided (defaults to stderr). Example usage:: from werkzeug.contrib.profiler import ProfilerMiddleware app = ProfilerMiddleware(app) :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ import sys import time import os.path try: try: from cProfile import Profile except ImportError: from profile import Profile from pstats import Stats available = True except ImportError: available = False class MergeStream(object): """An object that redirects `write` calls to multiple streams. Use this to log to both `sys.stdout` and a file:: f = open('profiler.log', 'w') stream = MergeStream(sys.stdout, f) profiler = ProfilerMiddleware(app, stream) """ def __init__(self, *streams): if not streams: raise TypeError('at least one stream must be given') self.streams = streams def write(self, data): for stream in self.streams: stream.write(data) class ProfilerMiddleware(object): """Simple profiler middleware. Wraps a WSGI application and profiles a request. This intentionally buffers the response so that timings are more exact. By giving the `profile_dir` argument, pstat.Stats files are saved to that directory, one file per request. Without it, a summary is printed to `stream` instead. For the exact meaning of `sort_by` and `restrictions` consult the :mod:`profile` documentation. .. versionadded:: 0.9 Added support for `restrictions` and `profile_dir`. :param app: the WSGI application to profile. :param stream: the stream for the profiled stats. defaults to stderr. :param sort_by: a tuple of columns to sort the result by. :param restrictions: a tuple of profiling strictions, not used if dumping to `profile_dir`. :param profile_dir: directory name to save pstat files """ def __init__(self, app, stream=None, sort_by=('time', 'calls'), restrictions=(), profile_dir=None): if not available: raise RuntimeError('the profiler is not available because ' 'profile or pstat is not installed.') self._app = app self._stream = stream or sys.stdout self._sort_by = sort_by self._restrictions = restrictions self._profile_dir = profile_dir def __call__(self, environ, start_response): response_body = [] def catching_start_response(status, headers, exc_info=None): start_response(status, headers, exc_info) return response_body.append def runapp(): appiter = self._app(environ, catching_start_response) response_body.extend(appiter) if hasattr(appiter, 'close'): appiter.close() p = Profile() start = time.time() p.runcall(runapp) body = b''.join(response_body) elapsed = time.time() - start if self._profile_dir is not None: prof_filename = os.path.join(self._profile_dir, '%s.%s.%06dms.%d.prof' % ( environ['REQUEST_METHOD'], environ.get('PATH_INFO').strip( '/').replace('/', '.') or 'root', elapsed * 1000.0, time.time() )) p.dump_stats(prof_filename) else: stats = Stats(p, stream=self._stream) stats.sort_stats(*self._sort_by) self._stream.write('-' * 80) self._stream.write('\nPATH: %r\n' % environ.get('PATH_INFO')) stats.print_stats(*self._restrictions) self._stream.write('-' * 80 + '\n\n') return [body] def make_action(app_factory, hostname='localhost', port=5000, threaded=False, processes=1, stream=None, sort_by=('time', 'calls'), restrictions=()): """Return a new callback for :mod:`werkzeug.script` that starts a local server with the profiler enabled. :: from werkzeug.contrib import profiler action_profile = profiler.make_action(make_app) """ def action(hostname=('h', hostname), port=('p', port), threaded=threaded, processes=processes): """Start a new development server.""" from werkzeug.serving import run_simple app = ProfilerMiddleware(app_factory(), stream, sort_by, restrictions) run_simple(hostname, port, app, False, None, threaded, processes) return action
gpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 10380, 14, 2828, 14, 20132, 272, 18294, 4919, 94, 339, 961, 859, 6571, 282, 3486, 9279, 23173, 10816, 367, 17196, 272, 5888, 25263, 5618, 315, 3330, 4223, 14, 221, 2779, 4440, 314, 520, 1494, 1705, 2913, 64, 503, 272, 520, 1494, 1705, 67, 5736, 64, 859, 370, 886, 314, 30238, 436, 14511, 314, 5020, 370, 314, 272, 2547, 2741, 334, 4322, 370, 4635, 680, 339, 5679, 4503, 447, 398, 687, 10380, 14, 2828, 14, 20132, 492, 14386, 82, 6608, 267, 1145, 275, 14386, 82, 6608, 8, 571, 9, 339, 520, 7307, 26, 334, 67, 9, 6927, 701, 314, 22798, 11682, 12, 1937, 10610, 367, 1655, 2436, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 1655, 2436, 14, 199, 624, 199, 646, 984, 199, 646, 900, 199, 646, 747, 14, 515, 199, 893, 26, 272, 862, 26, 267, 687, 286, 5736, 492, 14386, 272, 871, 3545, 26, 267, 687, 4690, 492, 14386, 272, 687, 299, 3200, 492, 29062, 272, 2808, 275, 715, 199, 2590, 3545, 26, 272, 2808, 275, 756, 421, 199, 533, 14076, 3296, 8, 785, 304, 339, 408, 2493, 909, 626, 17784, 658, 952, 64, 4882, 370, 3663, 13788, 14, 272, 3645, 642, 370, 943, 370, 3865, 658, 1274, 14, 2703, 64, 436, 282, 570, 447, 398, 289, 275, 1551, 360, 20132, 14, 793, 297, 283, 87, 358, 267, 2547, 275, 14076, 3296, 8, 1274, 14, 2703, 12, 289, 9, 267, 23173, 275, 14386, 82, 6608, 8, 571, 12, 2547, 9, 272, 408, 339, 347, 636, 826, 721, 277, 12, 627, 11231, 304, 267, 340, 440, 13788, 26, 288, 746, 3146, 360, 292, 5210, 1373, 2547, 1471, 506, 1627, 358, 267, 291, 14, 11231, 275, 13788, 339, 347, 2218, 8, 277, 12, 666, 304, 267, 367, 2547, 315, 291, 14, 11231, 26, 288, 2547, 14, 952, 8, 576, 9, 421, 199, 533, 14386, 82, 6608, 8, 785, 304, 339, 408, 3184, 23173, 10816, 14, 221, 644, 8146, 282, 9279, 4223, 436, 17390, 272, 282, 1056, 14, 221, 961, 32005, 19383, 314, 1177, 880, 626, 221, 27337, 787, 272, 1655, 5835, 14, 339, 4885, 15131, 314, 658, 2913, 63, 694, 64, 1423, 12, 299, 3736, 14, 8257, 1584, 787, 6290, 370, 626, 272, 2082, 12, 1373, 570, 1126, 1056, 14, 23952, 652, 12, 282, 6212, 365, 12487, 370, 272, 658, 1745, 64, 3140, 14, 339, 2104, 314, 5835, 11150, 402, 658, 3191, 63, 991, 64, 436, 658, 12099, 2452, 64, 13447, 427, 314, 272, 520, 1494, 1705, 2913, 64, 3794, 14, 339, 2508, 7445, 447, 378, 14, 25, 2126, 16230, 2291, 367, 658, 12099, 2452, 64, 436, 658, 2913, 63, 694, 2313, 339, 520, 635, 1145, 26, 314, 9279, 4223, 370, 4690, 14, 272, 520, 635, 2547, 26, 314, 2547, 367, 314, 4690, 68, 5020, 14, 221, 4243, 370, 4635, 14, 272, 520, 635, 4069, 63, 991, 26, 282, 2008, 402, 4362, 370, 4069, 314, 754, 701, 14, 272, 520, 635, 24488, 26, 282, 2008, 402, 30238, 4024, 2452, 12, 440, 1202, 340, 5461, 316, 586, 370, 658, 2913, 63, 694, 2313, 272, 520, 635, 4690, 63, 694, 26, 2082, 536, 370, 3354, 299, 3736, 1584, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1145, 12, 2547, 29, 403, 12, 326, 4069, 63, 991, 7782, 521, 297, 283, 5352, 659, 24488, 16729, 4690, 63, 694, 29, 403, 304, 267, 340, 440, 2808, 26, 288, 746, 6064, 360, 1589, 23173, 365, 440, 2808, 2952, 283, 3044, 283, 2913, 503, 299, 3736, 365, 440, 4903, 2659, 267, 291, 423, 571, 275, 1145, 267, 291, 423, 1745, 275, 2547, 503, 984, 14, 2703, 267, 291, 423, 3191, 63, 991, 275, 4069, 63, 991, 267, 291, 423, 12099, 2452, 275, 24488, 267, 291, 423, 2913, 63, 694, 275, 4690, 63, 694, 339, 347, 636, 1250, 721, 277, 12, 6160, 12, 1343, 63, 1310, 304, 267, 1177, 63, 2030, 275, 942, 398, 347, 8579, 316, 63, 928, 63, 1310, 8, 1205, 12, 2323, 12, 3178, 63, 815, 29, 403, 304, 288, 1343, 63, 1310, 8, 1205, 12, 2323, 12, 3178, 63, 815, 9, 288, 372, 1177, 63, 2030, 14, 740, 398, 347, 1255, 571, 837, 288, 1145, 1661, 275, 291, 423, 571, 8, 2314, 12, 8579, 316, 63, 928, 63, 1310, 9, 288, 1177, 63, 2030, 14, 2880, 8, 571, 1661, 9, 288, 340, 2688, 8, 571, 1661, 12, 283, 1600, 735, 355, 1145, 1661, 14, 1600, 342, 398, 299, 275, 14386, 342, 267, 1343, 275, 900, 14, 521, 342, 267, 299, 14, 1065, 1250, 8, 1065, 571, 9, 267, 2396, 275, 330, 17067, 904, 8, 1310, 63, 2030, 9, 267, 14439, 275, 900, 14, 521, 342, 446, 1343, 398, 340, 291, 423, 2913, 63, 694, 365, 440, 488, 26, 288, 22398, 63, 1501, 275, 747, 14, 515, 14, 904, 8, 277, 423, 2913, 63, 694, 12, 1460, 1543, 83, 4111, 83, 4111, 1690, 68, 706, 4111, 68, 14, 14979, 7, 450, 334, 6163, 6160, 459, 6780, 63, 9977, 995, 6163, 6160, 14, 362, 360, 3243, 63, 4531, 1959, 1913, 8, 1740, 1994, 1959, 1814, 10998, 20093, 503, 283, 1231, 297, 6163, 14439, 627, 5198, 14, 16, 12, 6163, 900, 14, 521, 342, 1460, 5082, 288, 299, 14, 2724, 63, 3200, 8, 14979, 63, 1501, 9, 398, 587, 26, 288, 5020, 275, 29062, 8, 80, 12, 2547, 29, 277, 423, 1745, 9, 288, 5020, 14, 3191, 63, 3200, 2031, 277, 423, 3191, 63, 991, 9, 953, 291, 423, 1745, 14, 952, 3654, 7, 627, 5939, 9, 288, 291, 423, 1745, 14, 952, 2258, 78, 3243, 26, 450, 82, 60, 78, 7, 450, 6160, 14, 362, 360, 3243, 63, 4531, 1333, 288, 5020, 14, 1361, 63, 3200, 2031, 277, 423, 12099, 2452, 9, 288, 291, 423, 1745, 14, 952, 3654, 7, 627, 5939, 435, 1557, 78, 60, 78, 358, 398, 372, 359, 2030, 61, 421, 199, 318, 1852, 63, 1287, 8, 571, 63, 3702, 12, 6246, 534, 5967, 297, 1844, 29, 13128, 12, 355, 25396, 29, 797, 12, 10358, 29, 17, 12, 2547, 29, 403, 12, 355, 4069, 63, 991, 7782, 521, 297, 283, 5352, 659, 24488, 23603, 272, 408, 1767, 282, 892, 3233, 367, 520 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 10380, 14, 2828, 14, 20132, 272, 18294, 4919, 94, 339, 961, 859, 6571, 282, 3486, 9279, 23173, 10816, 367, 17196, 272, 5888, 25263, 5618, 315, 3330, 4223, 14, 221, 2779, 4440, 314, 520, 1494, 1705, 2913, 64, 503, 272, 520, 1494, 1705, 67, 5736, 64, 859, 370, 886, 314, 30238, 436, 14511, 314, 5020, 370, 314, 272, 2547, 2741, 334, 4322, 370, 4635, 680, 339, 5679, 4503, 447, 398, 687, 10380, 14, 2828, 14, 20132, 492, 14386, 82, 6608, 267, 1145, 275, 14386, 82, 6608, 8, 571, 9, 339, 520, 7307, 26, 334, 67, 9, 6927, 701, 314, 22798, 11682, 12, 1937, 10610, 367, 1655, 2436, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 1655, 2436, 14, 199, 624, 199, 646, 984, 199, 646, 900, 199, 646, 747, 14, 515, 199, 893, 26, 272, 862, 26, 267, 687, 286, 5736, 492, 14386, 272, 871, 3545, 26, 267, 687, 4690, 492, 14386, 272, 687, 299, 3200, 492, 29062, 272, 2808, 275, 715, 199, 2590, 3545, 26, 272, 2808, 275, 756, 421, 199, 533, 14076, 3296, 8, 785, 304, 339, 408, 2493, 909, 626, 17784, 658, 952, 64, 4882, 370, 3663, 13788, 14, 272, 3645, 642, 370, 943, 370, 3865, 658, 1274, 14, 2703, 64, 436, 282, 570, 447, 398, 289, 275, 1551, 360, 20132, 14, 793, 297, 283, 87, 358, 267, 2547, 275, 14076, 3296, 8, 1274, 14, 2703, 12, 289, 9, 267, 23173, 275, 14386, 82, 6608, 8, 571, 12, 2547, 9, 272, 408, 339, 347, 636, 826, 721, 277, 12, 627, 11231, 304, 267, 340, 440, 13788, 26, 288, 746, 3146, 360, 292, 5210, 1373, 2547, 1471, 506, 1627, 358, 267, 291, 14, 11231, 275, 13788, 339, 347, 2218, 8, 277, 12, 666, 304, 267, 367, 2547, 315, 291, 14, 11231, 26, 288, 2547, 14, 952, 8, 576, 9, 421, 199, 533, 14386, 82, 6608, 8, 785, 304, 339, 408, 3184, 23173, 10816, 14, 221, 644, 8146, 282, 9279, 4223, 436, 17390, 272, 282, 1056, 14, 221, 961, 32005, 19383, 314, 1177, 880, 626, 221, 27337, 787, 272, 1655, 5835, 14, 339, 4885, 15131, 314, 658, 2913, 63, 694, 64, 1423, 12, 299, 3736, 14, 8257, 1584, 787, 6290, 370, 626, 272, 2082, 12, 1373, 570, 1126, 1056, 14, 23952, 652, 12, 282, 6212, 365, 12487, 370, 272, 658, 1745, 64, 3140, 14, 339, 2104, 314, 5835, 11150, 402, 658, 3191, 63, 991, 64, 436, 658, 12099, 2452, 64, 13447, 427, 314, 272, 520, 1494, 1705, 2913, 64, 3794, 14, 339, 2508, 7445, 447, 378, 14, 25, 2126, 16230, 2291, 367, 658, 12099, 2452, 64, 436, 658, 2913, 63, 694, 2313, 339, 520, 635, 1145, 26, 314, 9279, 4223, 370, 4690, 14, 272, 520, 635, 2547, 26, 314, 2547, 367, 314, 4690, 68, 5020, 14, 221, 4243, 370, 4635, 14, 272, 520, 635, 4069, 63, 991, 26, 282, 2008, 402, 4362, 370, 4069, 314, 754, 701, 14, 272, 520, 635, 24488, 26, 282, 2008, 402, 30238, 4024, 2452, 12, 440, 1202, 340, 5461, 316, 586, 370, 658, 2913, 63, 694, 2313, 272, 520, 635, 4690, 63, 694, 26, 2082, 536, 370, 3354, 299, 3736, 1584, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1145, 12, 2547, 29, 403, 12, 326, 4069, 63, 991, 7782, 521, 297, 283, 5352, 659, 24488, 16729, 4690, 63, 694, 29, 403, 304, 267, 340, 440, 2808, 26, 288, 746, 6064, 360, 1589, 23173, 365, 440, 2808, 2952, 283, 3044, 283, 2913, 503, 299, 3736, 365, 440, 4903, 2659, 267, 291, 423, 571, 275, 1145, 267, 291, 423, 1745, 275, 2547, 503, 984, 14, 2703, 267, 291, 423, 3191, 63, 991, 275, 4069, 63, 991, 267, 291, 423, 12099, 2452, 275, 24488, 267, 291, 423, 2913, 63, 694, 275, 4690, 63, 694, 339, 347, 636, 1250, 721, 277, 12, 6160, 12, 1343, 63, 1310, 304, 267, 1177, 63, 2030, 275, 942, 398, 347, 8579, 316, 63, 928, 63, 1310, 8, 1205, 12, 2323, 12, 3178, 63, 815, 29, 403, 304, 288, 1343, 63, 1310, 8, 1205, 12, 2323, 12, 3178, 63, 815, 9, 288, 372, 1177, 63, 2030, 14, 740, 398, 347, 1255, 571, 837, 288, 1145, 1661, 275, 291, 423, 571, 8, 2314, 12, 8579, 316, 63, 928, 63, 1310, 9, 288, 1177, 63, 2030, 14, 2880, 8, 571, 1661, 9, 288, 340, 2688, 8, 571, 1661, 12, 283, 1600, 735, 355, 1145, 1661, 14, 1600, 342, 398, 299, 275, 14386, 342, 267, 1343, 275, 900, 14, 521, 342, 267, 299, 14, 1065, 1250, 8, 1065, 571, 9, 267, 2396, 275, 330, 17067, 904, 8, 1310, 63, 2030, 9, 267, 14439, 275, 900, 14, 521, 342, 446, 1343, 398, 340, 291, 423, 2913, 63, 694, 365, 440, 488, 26, 288, 22398, 63, 1501, 275, 747, 14, 515, 14, 904, 8, 277, 423, 2913, 63, 694, 12, 1460, 1543, 83, 4111, 83, 4111, 1690, 68, 706, 4111, 68, 14, 14979, 7, 450, 334, 6163, 6160, 459, 6780, 63, 9977, 995, 6163, 6160, 14, 362, 360, 3243, 63, 4531, 1959, 1913, 8, 1740, 1994, 1959, 1814, 10998, 20093, 503, 283, 1231, 297, 6163, 14439, 627, 5198, 14, 16, 12, 6163, 900, 14, 521, 342, 1460, 5082, 288, 299, 14, 2724, 63, 3200, 8, 14979, 63, 1501, 9, 398, 587, 26, 288, 5020, 275, 29062, 8, 80, 12, 2547, 29, 277, 423, 1745, 9, 288, 5020, 14, 3191, 63, 3200, 2031, 277, 423, 3191, 63, 991, 9, 953, 291, 423, 1745, 14, 952, 3654, 7, 627, 5939, 9, 288, 291, 423, 1745, 14, 952, 2258, 78, 3243, 26, 450, 82, 60, 78, 7, 450, 6160, 14, 362, 360, 3243, 63, 4531, 1333, 288, 5020, 14, 1361, 63, 3200, 2031, 277, 423, 12099, 2452, 9, 288, 291, 423, 1745, 14, 952, 3654, 7, 627, 5939, 435, 1557, 78, 60, 78, 358, 398, 372, 359, 2030, 61, 421, 199, 318, 1852, 63, 1287, 8, 571, 63, 3702, 12, 6246, 534, 5967, 297, 1844, 29,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
mmnelemane/nova
nova/tests/unit/compute/test_compute_utils.py
20
35630
# Copyright 2011 OpenStack Foundation # All Rights Reserved. # Copyright 2013 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """Tests For miscellaneous util methods used with compute.""" import copy import string import uuid import mock from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import importutils import six from nova.compute import flavors from nova.compute import power_state from nova.compute import task_states from nova.compute import utils as compute_utils from nova import context from nova import db from nova import exception from nova.image import glance from nova.network import api as network_api from nova.network import model from nova import objects from nova.objects import block_device as block_device_obj from nova import rpc from nova import test from nova.tests.unit import fake_block_device from nova.tests.unit import fake_instance from nova.tests.unit import fake_network from nova.tests.unit import fake_notifier from nova.tests.unit import fake_server_actions import nova.tests.unit.image.fake from nova.tests.unit.objects import test_flavor from nova.tests.unit.objects import test_migration from nova.virt import driver CONF = cfg.CONF CONF.import_opt('compute_manager', 'nova.service') CONF.import_opt('compute_driver', 'nova.virt.driver') def create_instance(context, user_id='fake', project_id='fake', params=None): """Create a test instance.""" flavor = flavors.get_flavor_by_name('m1.tiny') net_info = model.NetworkInfo([]) info_cache = objects.InstanceInfoCache(network_info=net_info) inst = objects.Instance(context=context, image_ref=1, reservation_id='r-fakeres', user_id=user_id, project_id=project_id, instance_type_id=flavor.id, flavor=flavor, old_flavor=None, new_flavor=None, system_metadata={}, ami_launch_index=0, root_gb=0, ephemeral_gb=0, info_cache=info_cache) if params: inst.update(params) inst.create() return inst class ComputeValidateDeviceTestCase(test.NoDBTestCase): def setUp(self): super(ComputeValidateDeviceTestCase, self).setUp() self.context = context.RequestContext('fake', 'fake') # check if test name includes "xen" if 'xen' in self.id(): self.flags(compute_driver='xenapi.XenAPIDriver') self.instance = objects.Instance(uuid=uuid.uuid4().hex, root_device_name=None, default_ephemeral_device=None) else: self.instance = objects.Instance(uuid=uuid.uuid4().hex, root_device_name='/dev/vda', default_ephemeral_device='/dev/vdb') flavor = objects.Flavor(**test_flavor.fake_flavor) self.instance.system_metadata = {} with mock.patch.object(self.instance, 'save'): self.instance.set_flavor(flavor) self.instance.default_swap_device = None self.data = [] self.stubs.Set(db, 'block_device_mapping_get_all_by_instance', lambda context, instance, use_slave=False: self.data) def _update_flavor(self, flavor_info): self.flavor = { 'id': 1, 'name': 'foo', 'memory_mb': 128, 'vcpus': 1, 'root_gb': 10, 'ephemeral_gb': 10, 'flavorid': 1, 'swap': 0, 'rxtx_factor': 1.0, 'vcpu_weight': 1, } self.flavor.update(flavor_info) with mock.patch.object(self.instance, 'save'): self.instance.set_flavor(self.flavor) def _validate_device(self, device=None): bdms = objects.BlockDeviceMappingList.get_by_instance_uuid( self.context, self.instance['uuid']) return compute_utils.get_device_name_for_instance( self.instance, bdms, device) @staticmethod def _fake_bdm(device): return fake_block_device.FakeDbBlockDeviceDict({ 'source_type': 'volume', 'destination_type': 'volume', 'device_name': device, 'no_device': None, 'volume_id': 'fake', 'snapshot_id': None, 'guest_format': None }) def test_wrap(self): self.data = [] for letter in string.ascii_lowercase[2:]: self.data.append(self._fake_bdm('/dev/vd' + letter)) device = self._validate_device() self.assertEqual(device, '/dev/vdaa') def test_wrap_plus_one(self): self.data = [] for letter in string.ascii_lowercase[2:]: self.data.append(self._fake_bdm('/dev/vd' + letter)) self.data.append(self._fake_bdm('/dev/vdaa')) device = self._validate_device() self.assertEqual(device, '/dev/vdab') def test_later(self): self.data = [ self._fake_bdm('/dev/vdc'), self._fake_bdm('/dev/vdd'), self._fake_bdm('/dev/vde'), ] device = self._validate_device() self.assertEqual(device, '/dev/vdf') def test_gap(self): self.data = [ self._fake_bdm('/dev/vdc'), self._fake_bdm('/dev/vde'), ] device = self._validate_device() self.assertEqual(device, '/dev/vdd') def test_no_bdms(self): self.data = [] device = self._validate_device() self.assertEqual(device, '/dev/vdc') def test_lxc_names_work(self): self.instance['root_device_name'] = '/dev/a' self.instance['ephemeral_device_name'] = '/dev/b' self.data = [] device = self._validate_device() self.assertEqual(device, '/dev/c') def test_name_conversion(self): self.data = [] device = self._validate_device('/dev/c') self.assertEqual(device, '/dev/vdc') device = self._validate_device('/dev/sdc') self.assertEqual(device, '/dev/vdc') device = self._validate_device('/dev/xvdc') self.assertEqual(device, '/dev/vdc') def test_invalid_device_prefix(self): self.assertRaises(exception.InvalidDevicePath, self._validate_device, '/baddata/vdc') def test_device_in_use(self): exc = self.assertRaises(exception.DevicePathInUse, self._validate_device, '/dev/vda') self.assertIn('/dev/vda', six.text_type(exc)) def test_swap(self): self.instance['default_swap_device'] = "/dev/vdc" device = self._validate_device() self.assertEqual(device, '/dev/vdd') def test_swap_no_ephemeral(self): self.instance.default_ephemeral_device = None self.instance.default_swap_device = "/dev/vdb" device = self._validate_device() self.assertEqual(device, '/dev/vdc') def test_ephemeral_xenapi(self): self._update_flavor({ 'ephemeral_gb': 10, 'swap': 0, }) self.stubs.Set(flavors, 'get_flavor', lambda instance_type_id, ctxt=None: self.flavor) device = self._validate_device() self.assertEqual(device, '/dev/xvdc') def test_swap_xenapi(self): self._update_flavor({ 'ephemeral_gb': 0, 'swap': 10, }) self.stubs.Set(flavors, 'get_flavor', lambda instance_type_id, ctxt=None: self.flavor) device = self._validate_device() self.assertEqual(device, '/dev/xvdb') def test_swap_and_ephemeral_xenapi(self): self._update_flavor({ 'ephemeral_gb': 10, 'swap': 10, }) self.stubs.Set(flavors, 'get_flavor', lambda instance_type_id, ctxt=None: self.flavor) device = self._validate_device() self.assertEqual(device, '/dev/xvdd') def test_swap_and_one_attachment_xenapi(self): self._update_flavor({ 'ephemeral_gb': 0, 'swap': 10, }) self.stubs.Set(flavors, 'get_flavor', lambda instance_type_id, ctxt=None: self.flavor) device = self._validate_device() self.assertEqual(device, '/dev/xvdb') self.data.append(self._fake_bdm(device)) device = self._validate_device() self.assertEqual(device, '/dev/xvdd') def test_no_dev_root_device_name_get_next_name(self): self.instance['root_device_name'] = 'vda' device = self._validate_device() self.assertEqual('/dev/vdc', device) class DefaultDeviceNamesForInstanceTestCase(test.NoDBTestCase): def setUp(self): super(DefaultDeviceNamesForInstanceTestCase, self).setUp() self.context = context.RequestContext('fake', 'fake') self.ephemerals = block_device_obj.block_device_make_list( self.context, [fake_block_device.FakeDbBlockDeviceDict( {'id': 1, 'instance_uuid': 'fake-instance', 'device_name': '/dev/vdb', 'source_type': 'blank', 'destination_type': 'local', 'delete_on_termination': True, 'guest_format': None, 'boot_index': -1})]) self.swap = block_device_obj.block_device_make_list( self.context, [fake_block_device.FakeDbBlockDeviceDict( {'id': 2, 'instance_uuid': 'fake-instance', 'device_name': '/dev/vdc', 'source_type': 'blank', 'destination_type': 'local', 'delete_on_termination': True, 'guest_format': 'swap', 'boot_index': -1})]) self.block_device_mapping = block_device_obj.block_device_make_list( self.context, [fake_block_device.FakeDbBlockDeviceDict( {'id': 3, 'instance_uuid': 'fake-instance', 'device_name': '/dev/vda', 'source_type': 'volume', 'destination_type': 'volume', 'volume_id': 'fake-volume-id-1', 'boot_index': 0}), fake_block_device.FakeDbBlockDeviceDict( {'id': 4, 'instance_uuid': 'fake-instance', 'device_name': '/dev/vdd', 'source_type': 'snapshot', 'destination_type': 'volume', 'snapshot_id': 'fake-snapshot-id-1', 'boot_index': -1}), fake_block_device.FakeDbBlockDeviceDict( {'id': 5, 'instance_uuid': 'fake-instance', 'device_name': '/dev/vde', 'source_type': 'blank', 'destination_type': 'volume', 'boot_index': -1})]) self.instance = {'uuid': 'fake_instance', 'ephemeral_gb': 2} self.is_libvirt = False self.root_device_name = '/dev/vda' self.update_called = False def fake_driver_matches(driver_string): if driver_string == 'libvirt.LibvirtDriver': return self.is_libvirt return False self.patchers = [] self.patchers.append( mock.patch.object(objects.BlockDeviceMapping, 'save')) self.patchers.append( mock.patch.object(driver, 'compute_driver_matches', new=mock.Mock( side_effect=fake_driver_matches))) for patcher in self.patchers: patcher.start() def tearDown(self): super(DefaultDeviceNamesForInstanceTestCase, self).tearDown() for patcher in self.patchers: patcher.stop() def _test_default_device_names(self, *block_device_lists): compute_utils.default_device_names_for_instance(self.instance, self.root_device_name, *block_device_lists) def test_only_block_device_mapping(self): # Test no-op original_bdm = copy.deepcopy(self.block_device_mapping) self._test_default_device_names([], [], self.block_device_mapping) for original, new in zip(original_bdm, self.block_device_mapping): self.assertEqual(original.device_name, new.device_name) # Assert it defaults the missing one as expected self.block_device_mapping[1]['device_name'] = None self.block_device_mapping[2]['device_name'] = None self._test_default_device_names([], [], self.block_device_mapping) self.assertEqual('/dev/vdb', self.block_device_mapping[1]['device_name']) self.assertEqual('/dev/vdc', self.block_device_mapping[2]['device_name']) def test_with_ephemerals(self): # Test ephemeral gets assigned self.ephemerals[0]['device_name'] = None self._test_default_device_names(self.ephemerals, [], self.block_device_mapping) self.assertEqual(self.ephemerals[0]['device_name'], '/dev/vdb') self.block_device_mapping[1]['device_name'] = None self.block_device_mapping[2]['device_name'] = None self._test_default_device_names(self.ephemerals, [], self.block_device_mapping) self.assertEqual('/dev/vdc', self.block_device_mapping[1]['device_name']) self.assertEqual('/dev/vdd', self.block_device_mapping[2]['device_name']) def test_with_swap(self): # Test swap only self.swap[0]['device_name'] = None self._test_default_device_names([], self.swap, []) self.assertEqual(self.swap[0]['device_name'], '/dev/vdb') # Test swap and block_device_mapping self.swap[0]['device_name'] = None self.block_device_mapping[1]['device_name'] = None self.block_device_mapping[2]['device_name'] = None self._test_default_device_names([], self.swap, self.block_device_mapping) self.assertEqual(self.swap[0]['device_name'], '/dev/vdb') self.assertEqual('/dev/vdc', self.block_device_mapping[1]['device_name']) self.assertEqual('/dev/vdd', self.block_device_mapping[2]['device_name']) def test_all_together(self): # Test swap missing self.swap[0]['device_name'] = None self._test_default_device_names(self.ephemerals, self.swap, self.block_device_mapping) self.assertEqual(self.swap[0]['device_name'], '/dev/vdc') # Test swap and eph missing self.swap[0]['device_name'] = None self.ephemerals[0]['device_name'] = None self._test_default_device_names(self.ephemerals, self.swap, self.block_device_mapping) self.assertEqual(self.ephemerals[0]['device_name'], '/dev/vdb') self.assertEqual(self.swap[0]['device_name'], '/dev/vdc') # Test all missing self.swap[0]['device_name'] = None self.ephemerals[0]['device_name'] = None self.block_device_mapping[1]['device_name'] = None self.block_device_mapping[2]['device_name'] = None self._test_default_device_names(self.ephemerals, self.swap, self.block_device_mapping) self.assertEqual(self.ephemerals[0]['device_name'], '/dev/vdb') self.assertEqual(self.swap[0]['device_name'], '/dev/vdc') self.assertEqual('/dev/vdd', self.block_device_mapping[1]['device_name']) self.assertEqual('/dev/vde', self.block_device_mapping[2]['device_name']) class UsageInfoTestCase(test.TestCase): def setUp(self): def fake_get_nw_info(cls, ctxt, instance): self.assertTrue(ctxt.is_admin) return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1) super(UsageInfoTestCase, self).setUp() self.stubs.Set(network_api.API, 'get_instance_nw_info', fake_get_nw_info) fake_notifier.stub_notifier(self.stubs) self.addCleanup(fake_notifier.reset) self.flags(use_local=True, group='conductor') self.flags(compute_driver='nova.virt.fake.FakeDriver', network_manager='nova.network.manager.FlatManager') self.compute = importutils.import_object(CONF.compute_manager) self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) def fake_show(meh, context, id, **kwargs): return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}} self.stubs.Set(nova.tests.unit.image.fake._FakeImageService, 'show', fake_show) fake_network.set_stub_network_methods(self.stubs) fake_server_actions.stub_out_action_events(self.stubs) def test_notify_usage_exists(self): # Ensure 'exists' notification generates appropriate usage data. instance = create_instance(self.context) # Set some system metadata sys_metadata = {'image_md_key1': 'val1', 'image_md_key2': 'val2', 'other_data': 'meow'} instance.system_metadata.update(sys_metadata) instance.save() compute_utils.notify_usage_exists( rpc.get_notifier('compute'), self.context, instance) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1) msg = fake_notifier.NOTIFICATIONS[0] self.assertEqual(msg.priority, 'INFO') self.assertEqual(msg.event_type, 'compute.instance.exists') payload = msg.payload self.assertEqual(payload['tenant_id'], self.project_id) self.assertEqual(payload['user_id'], self.user_id) self.assertEqual(payload['instance_id'], instance['uuid']) self.assertEqual(payload['instance_type'], 'm1.tiny') type_id = flavors.get_flavor_by_name('m1.tiny')['id'] self.assertEqual(str(payload['instance_type_id']), str(type_id)) flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid'] self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id)) for attr in ('display_name', 'created_at', 'launched_at', 'state', 'state_description', 'bandwidth', 'audit_period_beginning', 'audit_period_ending', 'image_meta'): self.assertIn(attr, payload, "Key %s not in payload" % attr) self.assertEqual(payload['image_meta'], {'md_key1': 'val1', 'md_key2': 'val2'}) image_ref_url = "%s/images/1" % glance.generate_glance_url() self.assertEqual(payload['image_ref_url'], image_ref_url) self.compute.terminate_instance(self.context, instance, [], []) def test_notify_usage_exists_deleted_instance(self): # Ensure 'exists' notification generates appropriate usage data. instance = create_instance(self.context) # Set some system metadata sys_metadata = {'image_md_key1': 'val1', 'image_md_key2': 'val2', 'other_data': 'meow'} instance.system_metadata.update(sys_metadata) instance.save() self.compute.terminate_instance(self.context, instance, [], []) compute_utils.notify_usage_exists( rpc.get_notifier('compute'), self.context, instance) msg = fake_notifier.NOTIFICATIONS[-1] self.assertEqual(msg.priority, 'INFO') self.assertEqual(msg.event_type, 'compute.instance.exists') payload = msg.payload self.assertEqual(payload['tenant_id'], self.project_id) self.assertEqual(payload['user_id'], self.user_id) self.assertEqual(payload['instance_id'], instance['uuid']) self.assertEqual(payload['instance_type'], 'm1.tiny') type_id = flavors.get_flavor_by_name('m1.tiny')['id'] self.assertEqual(str(payload['instance_type_id']), str(type_id)) flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid'] self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id)) for attr in ('display_name', 'created_at', 'launched_at', 'state', 'state_description', 'bandwidth', 'audit_period_beginning', 'audit_period_ending', 'image_meta'): self.assertIn(attr, payload, "Key %s not in payload" % attr) self.assertEqual(payload['image_meta'], {'md_key1': 'val1', 'md_key2': 'val2'}) image_ref_url = "%s/images/1" % glance.generate_glance_url() self.assertEqual(payload['image_ref_url'], image_ref_url) def test_notify_usage_exists_instance_not_found(self): # Ensure 'exists' notification generates appropriate usage data. instance = create_instance(self.context) self.compute.terminate_instance(self.context, instance, [], []) compute_utils.notify_usage_exists( rpc.get_notifier('compute'), self.context, instance) msg = fake_notifier.NOTIFICATIONS[-1] self.assertEqual(msg.priority, 'INFO') self.assertEqual(msg.event_type, 'compute.instance.exists') payload = msg.payload self.assertEqual(payload['tenant_id'], self.project_id) self.assertEqual(payload['user_id'], self.user_id) self.assertEqual(payload['instance_id'], instance['uuid']) self.assertEqual(payload['instance_type'], 'm1.tiny') type_id = flavors.get_flavor_by_name('m1.tiny')['id'] self.assertEqual(str(payload['instance_type_id']), str(type_id)) flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid'] self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id)) for attr in ('display_name', 'created_at', 'launched_at', 'state', 'state_description', 'bandwidth', 'audit_period_beginning', 'audit_period_ending', 'image_meta'): self.assertIn(attr, payload, "Key %s not in payload" % attr) self.assertEqual(payload['image_meta'], {}) image_ref_url = "%s/images/1" % glance.generate_glance_url() self.assertEqual(payload['image_ref_url'], image_ref_url) def test_notify_about_instance_usage(self): instance = create_instance(self.context) # Set some system metadata sys_metadata = {'image_md_key1': 'val1', 'image_md_key2': 'val2', 'other_data': 'meow'} instance.system_metadata.update(sys_metadata) instance.save() extra_usage_info = {'image_name': 'fake_name'} compute_utils.notify_about_instance_usage( rpc.get_notifier('compute'), self.context, instance, 'create.start', extra_usage_info=extra_usage_info) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1) msg = fake_notifier.NOTIFICATIONS[0] self.assertEqual(msg.priority, 'INFO') self.assertEqual(msg.event_type, 'compute.instance.create.start') payload = msg.payload self.assertEqual(payload['tenant_id'], self.project_id) self.assertEqual(payload['user_id'], self.user_id) self.assertEqual(payload['instance_id'], instance['uuid']) self.assertEqual(payload['instance_type'], 'm1.tiny') type_id = flavors.get_flavor_by_name('m1.tiny')['id'] self.assertEqual(str(payload['instance_type_id']), str(type_id)) flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid'] self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id)) for attr in ('display_name', 'created_at', 'launched_at', 'state', 'state_description', 'image_meta'): self.assertIn(attr, payload, "Key %s not in payload" % attr) self.assertEqual(payload['image_meta'], {'md_key1': 'val1', 'md_key2': 'val2'}) self.assertEqual(payload['image_name'], 'fake_name') image_ref_url = "%s/images/1" % glance.generate_glance_url() self.assertEqual(payload['image_ref_url'], image_ref_url) self.compute.terminate_instance(self.context, instance, [], []) def test_notify_about_aggregate_update_with_id(self): # Set aggregate payload aggregate_payload = {'aggregate_id': 1} compute_utils.notify_about_aggregate_update(self.context, "create.end", aggregate_payload) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1) msg = fake_notifier.NOTIFICATIONS[0] self.assertEqual(msg.priority, 'INFO') self.assertEqual(msg.event_type, 'aggregate.create.end') payload = msg.payload self.assertEqual(payload['aggregate_id'], 1) def test_notify_about_aggregate_update_with_name(self): # Set aggregate payload aggregate_payload = {'name': 'fakegroup'} compute_utils.notify_about_aggregate_update(self.context, "create.start", aggregate_payload) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1) msg = fake_notifier.NOTIFICATIONS[0] self.assertEqual(msg.priority, 'INFO') self.assertEqual(msg.event_type, 'aggregate.create.start') payload = msg.payload self.assertEqual(payload['name'], 'fakegroup') def test_notify_about_aggregate_update_without_name_id(self): # Set empty aggregate payload aggregate_payload = {} compute_utils.notify_about_aggregate_update(self.context, "create.start", aggregate_payload) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0) class ComputeUtilsGetValFromSysMetadata(test.NoDBTestCase): def test_get_value_from_system_metadata(self): instance = fake_instance.fake_instance_obj('fake-context') system_meta = {'int_val': 1, 'int_string': '2', 'not_int': 'Nope'} instance.system_metadata = system_meta result = compute_utils.get_value_from_system_metadata( instance, 'int_val', int, 0) self.assertEqual(1, result) result = compute_utils.get_value_from_system_metadata( instance, 'int_string', int, 0) self.assertEqual(2, result) result = compute_utils.get_value_from_system_metadata( instance, 'not_int', int, 0) self.assertEqual(0, result) class ComputeUtilsGetNWInfo(test.NoDBTestCase): def test_instance_object_none_info_cache(self): inst = fake_instance.fake_instance_obj('fake-context', expected_attrs=['info_cache']) self.assertIsNone(inst.info_cache) result = compute_utils.get_nw_info_for_instance(inst) self.assertEqual(jsonutils.dumps([]), result.json()) class ComputeUtilsGetRebootTypes(test.NoDBTestCase): def setUp(self): super(ComputeUtilsGetRebootTypes, self).setUp() self.context = context.RequestContext('fake', 'fake') def test_get_reboot_type_started_soft(self): reboot_type = compute_utils.get_reboot_type(task_states.REBOOT_STARTED, power_state.RUNNING) self.assertEqual(reboot_type, 'SOFT') def test_get_reboot_type_pending_soft(self): reboot_type = compute_utils.get_reboot_type(task_states.REBOOT_PENDING, power_state.RUNNING) self.assertEqual(reboot_type, 'SOFT') def test_get_reboot_type_hard(self): reboot_type = compute_utils.get_reboot_type('foo', power_state.RUNNING) self.assertEqual(reboot_type, 'HARD') def test_get_reboot_not_running_hard(self): reboot_type = compute_utils.get_reboot_type('foo', 'bar') self.assertEqual(reboot_type, 'HARD') class ComputeUtilsTestCase(test.NoDBTestCase): @mock.patch('netifaces.interfaces') def test_get_machine_ips_value_error(self, mock_interfaces): # Tests that the utility method does not explode if netifaces raises # a ValueError. iface = mock.sentinel mock_interfaces.return_value = [iface] with mock.patch('netifaces.ifaddresses', side_effect=ValueError) as mock_ifaddresses: addresses = compute_utils.get_machine_ips() self.assertEqual([], addresses) mock_ifaddresses.assert_called_once_with(iface) class ComputeUtilsQuotaDeltaTestCase(test.TestCase): def setUp(self): super(ComputeUtilsQuotaDeltaTestCase, self).setUp() self.context = context.RequestContext('fake', 'fake') def test_upsize_quota_delta(self): old_flavor = flavors.get_flavor_by_name('m1.tiny') new_flavor = flavors.get_flavor_by_name('m1.medium') expected_deltas = { 'cores': new_flavor['vcpus'] - old_flavor['vcpus'], 'ram': new_flavor['memory_mb'] - old_flavor['memory_mb'] } deltas = compute_utils.upsize_quota_delta(self.context, new_flavor, old_flavor) self.assertEqual(expected_deltas, deltas) def test_downsize_quota_delta(self): inst = create_instance(self.context, params=None) inst.old_flavor = flavors.get_flavor_by_name('m1.medium') inst.new_flavor = flavors.get_flavor_by_name('m1.tiny') expected_deltas = { 'cores': (inst.new_flavor['vcpus'] - inst.old_flavor['vcpus']), 'ram': (inst.new_flavor['memory_mb'] - inst.old_flavor['memory_mb']) } deltas = compute_utils.downsize_quota_delta(self.context, inst) self.assertEqual(expected_deltas, deltas) @mock.patch.object(objects.Flavor, 'get_by_id') def test_reverse_quota_delta(self, mock_get_flavor): inst = create_instance(self.context, params=None) inst.old_flavor = flavors.get_flavor_by_name('m1.tiny') inst.new_flavor = flavors.get_flavor_by_name('m1.medium') expected_deltas = { 'cores': -1 * (inst.new_flavor['vcpus'] - inst.old_flavor['vcpus']), 'ram': -1 * (inst.new_flavor['memory_mb'] - inst.old_flavor['memory_mb']) } updates = {'old_instance_type_id': inst.old_flavor['id'], 'new_instance_type_id': inst.new_flavor['id']} fake_migration = test_migration.fake_db_migration(**updates) def _flavor_get_by_id(context, type_id): if type_id == updates['old_instance_type_id']: return inst.old_flavor else: return inst.new_flavor mock_get_flavor.side_effect = _flavor_get_by_id deltas = compute_utils.reverse_upsize_quota_delta(self.context, fake_migration) self.assertEqual(expected_deltas, deltas) @mock.patch.object(objects.Quotas, 'reserve') @mock.patch.object(objects.quotas, 'ids_from_instance') def test_reserve_quota_delta(self, mock_ids_from_instance, mock_reserve): quotas = objects.Quotas(context=context) inst = create_instance(self.context, params=None) inst.old_flavor = flavors.get_flavor_by_name('m1.tiny') inst.new_flavor = flavors.get_flavor_by_name('m1.medium') mock_ids_from_instance.return_value = (inst.project_id, inst.user_id) mock_reserve.return_value = quotas deltas = compute_utils.upsize_quota_delta(self.context, inst.new_flavor, inst.old_flavor) compute_utils.reserve_quota_delta(self.context, deltas, inst) mock_reserve.assert_called_once_with(project_id=inst.project_id, user_id=inst.user_id, **deltas) class ComputeUtilsMigrationTestCase(test.TestCase): def setUp(self): super(ComputeUtilsMigrationTestCase, self).setUp() self.context = context.RequestContext('fake', 'fake') def _test_get_resources(self): old_flavor = flavors.get_flavor_by_name('m1.tiny') new_flavor = flavors.get_flavor_by_name('m1.medium') params = {'flavor': new_flavor, 'old_flavor': old_flavor, 'new_flavor': new_flavor, 'vcpus': new_flavor['vcpus'], 'memory_mb': new_flavor['memory_mb']} instance = create_instance(self.context, params=params) updates = {'old_instance_type_id': old_flavor['id'], 'new_instance_type_id': new_flavor['id']} fake_migration = test_migration.fake_db_migration(**updates) migration = objects.Migration._from_db_object(self.context, objects.Migration(), fake_migration) return old_flavor, migration, instance @mock.patch.object(objects.Flavor, 'get_by_id') def test_get_inst_attrs_from_migration(self, mock_get_flavor): old_flavor, migration, instance = self._test_get_resources() expected_result = (old_flavor['vcpus'], old_flavor['memory_mb']) mock_get_flavor.return_value = old_flavor result = compute_utils.get_inst_attrs_from_migration(migration, instance) self.assertEqual(expected_result, result) @mock.patch.object(objects.Flavor, 'get_by_id') def test_get_inst_attrs_from_migration_flavor_not_found( self, mock_get_flavor): old_flavor, migration, instance = self._test_get_resources() expected_result = (instance.vcpus, instance.memory_mb) mock_get_flavor.side_effect = exception.FlavorNotFound(old_flavor.id) result = compute_utils.get_inst_attrs_from_migration(migration, instance) self.assertEqual(expected_result, result)
apache-2.0
[ 3, 1898, 7760, 14260, 2752, 199, 3, 2900, 5924, 5702, 14, 199, 3, 1898, 6171, 9572, 13002, 12, 3277, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 624, 2925, 2104, 3201, 19549, 4884, 3102, 1202, 543, 4526, 1041, 199, 199, 646, 1331, 199, 646, 1059, 199, 646, 5377, 199, 199, 646, 1683, 199, 504, 11258, 63, 888, 492, 4810, 199, 504, 11258, 63, 12161, 492, 18705, 199, 504, 11258, 63, 1208, 492, 492, 1208, 199, 646, 3816, 199, 199, 504, 5913, 14, 3357, 492, 23547, 199, 504, 5913, 14, 3357, 492, 7074, 63, 929, 199, 504, 5913, 14, 3357, 492, 2120, 63, 4981, 199, 504, 5913, 14, 3357, 492, 3778, 465, 4526, 63, 1208, 199, 504, 5913, 492, 1067, 199, 504, 5913, 492, 1592, 199, 504, 5913, 492, 1919, 199, 504, 5913, 14, 1569, 492, 21785, 199, 504, 5913, 14, 1200, 492, 2986, 465, 2784, 63, 1246, 199, 504, 5913, 14, 1200, 492, 1402, 199, 504, 5913, 492, 2251, 199, 504, 5913, 14, 1462, 492, 1853, 63, 1782, 465, 1853, 63, 1782, 63, 1113, 199, 504, 5913, 492, 8985, 199, 504, 5913, 492, 511, 199, 504, 5913, 14, 2219, 14, 3248, 492, 4026, 63, 1457, 63, 1782, 199, 504, 5913, 14, 2219, 14, 3248, 492, 4026, 63, 842, 199, 504, 5913, 14, 2219, 14, 3248, 492, 4026, 63, 1200, 199, 504, 5913, 14, 2219, 14, 3248, 492, 4026, 63, 18031, 199, 504, 5913, 14, 2219, 14, 3248, 492, 4026, 63, 1000, 63, 3723, 199, 646, 5913, 14, 2219, 14, 3248, 14, 1569, 14, 3183, 199, 504, 5913, 14, 2219, 14, 3248, 14, 1462, 492, 511, 63, 6081, 199, 504, 5913, 14, 2219, 14, 3248, 14, 1462, 492, 511, 63, 8998, 199, 504, 5913, 14, 4549, 492, 5253, 199, 199, 3103, 275, 4810, 14, 3103, 199, 3103, 14, 646, 63, 2992, 360, 3357, 63, 2609, 297, 283, 6765, 14, 1364, 358, 199, 3103, 14, 646, 63, 2992, 360, 3357, 63, 3090, 297, 283, 6765, 14, 4549, 14, 3090, 358, 421, 199, 318, 1218, 63, 842, 8, 1100, 12, 922, 63, 344, 534, 3183, 297, 2199, 63, 344, 534, 3183, 297, 1862, 29, 403, 304, 272, 408, 2499, 282, 511, 1256, 1041, 272, 8541, 275, 23547, 14, 362, 63, 6081, 63, 991, 63, 354, 360, 77, 17, 14, 9864, 358, 272, 1851, 63, 815, 275, 1402, 14, 4491, 2354, 4157, 272, 2256, 63, 1637, 275, 2251, 14, 3244, 2354, 4437, 8, 1200, 63, 815, 29, 846, 63, 815, 9, 272, 2727, 275, 2251, 14, 3244, 8, 1100, 29, 1100, 12, 1169, 1834, 63, 1121, 29, 17, 12, 1169, 25476, 63, 344, 534, 82, 13, 3183, 470, 297, 1169, 922, 63, 344, 29, 751, 63, 344, 12, 1169, 2199, 63, 344, 29, 1715, 63, 344, 12, 1169, 1256, 63, 466, 63, 344, 29, 6081, 14, 344, 12, 1169, 8541, 29, 6081, 12, 1169, 2269, 63, 6081, 29, 403, 12, 1169, 892, 63, 6081, 29, 403, 12, 1169, 2656, 63, 2343, 10324, 1169, 31644, 63, 9850, 63, 1080, 29, 16, 12, 1169, 1738, 63, 4908, 29, 16, 12, 1169, 26288, 63, 4908, 29, 16, 12, 1169, 2256, 63, 1637, 29, 815, 63, 1637, 9, 272, 340, 1862, 26, 267, 2727, 14, 873, 8, 1162, 9, 272, 2727, 14, 981, 342, 272, 372, 2727, 421, 199, 533, 8354, 12584, 2510, 1746, 8, 396, 14, 32437, 304, 272, 347, 3613, 8, 277, 304, 267, 1613, 8, 8564, 12584, 2510, 1746, 12, 291, 680, 5996, 342, 267, 291, 14, 1100, 275, 1067, 14, 17679, 360, 3183, 297, 283, 3183, 358, 267, 327, 1104, 340, 511, 536, 6952, 298, 13615, 2, 267, 340, 283, 13615, 7, 315, 291, 14, 344, 837, 288, 291, 14, 2469, 8, 3357, 63, 3090, 534, 20392, 14, 30643, 1282, 998, 2046, 358, 288, 291, 14, 842, 275, 2251, 14, 3244, 8, 2580, 29, 2580, 14, 2580, 20, 1252, 4097, 12, 355, 1738, 63, 1782, 63, 354, 29, 403, 12, 355, 849, 63, 19562, 63, 1782, 29, 403, 9, 267, 587, 26, 288, 291, 14, 842, 275, 2251, 14, 3244, 8, 2580, 29, 2580, 14, 2580, 20, 1252, 4097, 12, 355, 1738, 63, 1782, 63, 354, 8805, 2374, 15, 86, 983, 297, 355, 849, 63, 19562, 63, 1782, 8805, 2374, 15, 86, 697, 358, 398, 8541, 275, 2251, 14, 16739, 3682, 396, 63, 6081, 14, 3183, 63, 6081, 9, 267, 291, 14, 842, 14, 2253, 63, 2343, 275, 1052, 267, 543, 1683, 14, 2068, 14, 785, 8, 277, 14, 842, 12, 283, 2117, 735, 288, 291, 14, 842, 14, 409, 63, 6081, 8, 6081, 9, 267, 291, 14, 842, 14, 885, 63, 9286, 63, 1782, 275, 488, 398, 291, 14, 576, 275, 942, 398, 291, 14, 8957, 14, 1084, 8, 697, 12, 283, 1457, 63, 1782, 63, 4745, 63, 362, 63, 452, 63, 991, 63, 842, 297, 2432, 2400, 1067, 12, 1256, 12, 675, 63, 12384, 29, 797, 26, 291, 14, 576, 9, 339, 347, 485, 873, 63, 6081, 8, 277, 12, 8541, 63, 815, 304, 267, 291, 14, 6081, 275, 469, 288, 283, 344, 356, 413, 12, 288, 283, 354, 356, 283, 1421, 297, 288, 283, 4844, 63, 887, 356, 7960, 12, 288, 283, 19685, 356, 413, 12, 288, 283, 1231, 63, 4908, 356, 1616, 12, 288, 283, 19562, 63, 4908, 356, 1616, 12, 288, 283, 6081, 344, 356, 413, 12, 288, 283, 9286, 356, 378, 12, 288, 283, 82, 400, 88, 63 ]
[ 1898, 7760, 14260, 2752, 199, 3, 2900, 5924, 5702, 14, 199, 3, 1898, 6171, 9572, 13002, 12, 3277, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 624, 2925, 2104, 3201, 19549, 4884, 3102, 1202, 543, 4526, 1041, 199, 199, 646, 1331, 199, 646, 1059, 199, 646, 5377, 199, 199, 646, 1683, 199, 504, 11258, 63, 888, 492, 4810, 199, 504, 11258, 63, 12161, 492, 18705, 199, 504, 11258, 63, 1208, 492, 492, 1208, 199, 646, 3816, 199, 199, 504, 5913, 14, 3357, 492, 23547, 199, 504, 5913, 14, 3357, 492, 7074, 63, 929, 199, 504, 5913, 14, 3357, 492, 2120, 63, 4981, 199, 504, 5913, 14, 3357, 492, 3778, 465, 4526, 63, 1208, 199, 504, 5913, 492, 1067, 199, 504, 5913, 492, 1592, 199, 504, 5913, 492, 1919, 199, 504, 5913, 14, 1569, 492, 21785, 199, 504, 5913, 14, 1200, 492, 2986, 465, 2784, 63, 1246, 199, 504, 5913, 14, 1200, 492, 1402, 199, 504, 5913, 492, 2251, 199, 504, 5913, 14, 1462, 492, 1853, 63, 1782, 465, 1853, 63, 1782, 63, 1113, 199, 504, 5913, 492, 8985, 199, 504, 5913, 492, 511, 199, 504, 5913, 14, 2219, 14, 3248, 492, 4026, 63, 1457, 63, 1782, 199, 504, 5913, 14, 2219, 14, 3248, 492, 4026, 63, 842, 199, 504, 5913, 14, 2219, 14, 3248, 492, 4026, 63, 1200, 199, 504, 5913, 14, 2219, 14, 3248, 492, 4026, 63, 18031, 199, 504, 5913, 14, 2219, 14, 3248, 492, 4026, 63, 1000, 63, 3723, 199, 646, 5913, 14, 2219, 14, 3248, 14, 1569, 14, 3183, 199, 504, 5913, 14, 2219, 14, 3248, 14, 1462, 492, 511, 63, 6081, 199, 504, 5913, 14, 2219, 14, 3248, 14, 1462, 492, 511, 63, 8998, 199, 504, 5913, 14, 4549, 492, 5253, 199, 199, 3103, 275, 4810, 14, 3103, 199, 3103, 14, 646, 63, 2992, 360, 3357, 63, 2609, 297, 283, 6765, 14, 1364, 358, 199, 3103, 14, 646, 63, 2992, 360, 3357, 63, 3090, 297, 283, 6765, 14, 4549, 14, 3090, 358, 421, 199, 318, 1218, 63, 842, 8, 1100, 12, 922, 63, 344, 534, 3183, 297, 2199, 63, 344, 534, 3183, 297, 1862, 29, 403, 304, 272, 408, 2499, 282, 511, 1256, 1041, 272, 8541, 275, 23547, 14, 362, 63, 6081, 63, 991, 63, 354, 360, 77, 17, 14, 9864, 358, 272, 1851, 63, 815, 275, 1402, 14, 4491, 2354, 4157, 272, 2256, 63, 1637, 275, 2251, 14, 3244, 2354, 4437, 8, 1200, 63, 815, 29, 846, 63, 815, 9, 272, 2727, 275, 2251, 14, 3244, 8, 1100, 29, 1100, 12, 1169, 1834, 63, 1121, 29, 17, 12, 1169, 25476, 63, 344, 534, 82, 13, 3183, 470, 297, 1169, 922, 63, 344, 29, 751, 63, 344, 12, 1169, 2199, 63, 344, 29, 1715, 63, 344, 12, 1169, 1256, 63, 466, 63, 344, 29, 6081, 14, 344, 12, 1169, 8541, 29, 6081, 12, 1169, 2269, 63, 6081, 29, 403, 12, 1169, 892, 63, 6081, 29, 403, 12, 1169, 2656, 63, 2343, 10324, 1169, 31644, 63, 9850, 63, 1080, 29, 16, 12, 1169, 1738, 63, 4908, 29, 16, 12, 1169, 26288, 63, 4908, 29, 16, 12, 1169, 2256, 63, 1637, 29, 815, 63, 1637, 9, 272, 340, 1862, 26, 267, 2727, 14, 873, 8, 1162, 9, 272, 2727, 14, 981, 342, 272, 372, 2727, 421, 199, 533, 8354, 12584, 2510, 1746, 8, 396, 14, 32437, 304, 272, 347, 3613, 8, 277, 304, 267, 1613, 8, 8564, 12584, 2510, 1746, 12, 291, 680, 5996, 342, 267, 291, 14, 1100, 275, 1067, 14, 17679, 360, 3183, 297, 283, 3183, 358, 267, 327, 1104, 340, 511, 536, 6952, 298, 13615, 2, 267, 340, 283, 13615, 7, 315, 291, 14, 344, 837, 288, 291, 14, 2469, 8, 3357, 63, 3090, 534, 20392, 14, 30643, 1282, 998, 2046, 358, 288, 291, 14, 842, 275, 2251, 14, 3244, 8, 2580, 29, 2580, 14, 2580, 20, 1252, 4097, 12, 355, 1738, 63, 1782, 63, 354, 29, 403, 12, 355, 849, 63, 19562, 63, 1782, 29, 403, 9, 267, 587, 26, 288, 291, 14, 842, 275, 2251, 14, 3244, 8, 2580, 29, 2580, 14, 2580, 20, 1252, 4097, 12, 355, 1738, 63, 1782, 63, 354, 8805, 2374, 15, 86, 983, 297, 355, 849, 63, 19562, 63, 1782, 8805, 2374, 15, 86, 697, 358, 398, 8541, 275, 2251, 14, 16739, 3682, 396, 63, 6081, 14, 3183, 63, 6081, 9, 267, 291, 14, 842, 14, 2253, 63, 2343, 275, 1052, 267, 543, 1683, 14, 2068, 14, 785, 8, 277, 14, 842, 12, 283, 2117, 735, 288, 291, 14, 842, 14, 409, 63, 6081, 8, 6081, 9, 267, 291, 14, 842, 14, 885, 63, 9286, 63, 1782, 275, 488, 398, 291, 14, 576, 275, 942, 398, 291, 14, 8957, 14, 1084, 8, 697, 12, 283, 1457, 63, 1782, 63, 4745, 63, 362, 63, 452, 63, 991, 63, 842, 297, 2432, 2400, 1067, 12, 1256, 12, 675, 63, 12384, 29, 797, 26, 291, 14, 576, 9, 339, 347, 485, 873, 63, 6081, 8, 277, 12, 8541, 63, 815, 304, 267, 291, 14, 6081, 275, 469, 288, 283, 344, 356, 413, 12, 288, 283, 354, 356, 283, 1421, 297, 288, 283, 4844, 63, 887, 356, 7960, 12, 288, 283, 19685, 356, 413, 12, 288, 283, 1231, 63, 4908, 356, 1616, 12, 288, 283, 19562, 63, 4908, 356, 1616, 12, 288, 283, 6081, 344, 356, 413, 12, 288, 283, 9286, 356, 378, 12, 288, 283, 82, 400, 88, 63, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
ToyamaTetsuji/hello-world
lib/build_pack_utils/cloudfoundry.py
12
9633
import os import sys import json import tempfile import shutil import utils import logging from urlparse import urlparse from zips import UnzipUtil from hashes import HashUtil from cache import DirectoryCacheManager from downloads import Downloader from downloads import CurlDownloader from utils import safe_makedirs _log = logging.getLogger('cloudfoundry') class CloudFoundryUtil(object): @staticmethod def initialize(): # Open stdout unbuffered if hasattr(sys.stdout, 'fileno'): sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0) ctx = utils.FormattedDict() # Add environment variables ctx.update(os.environ) # Convert JSON env variables ctx['VCAP_APPLICATION'] = json.loads(ctx.get('VCAP_APPLICATION', '{}', format=False)) ctx['VCAP_SERVICES'] = json.loads(ctx.get('VCAP_SERVICES', '{}', format=False)) # Build Pack Location ctx['BP_DIR'] = os.path.dirname(os.path.dirname(sys.argv[0])) # User's Application Files, build droplet here ctx['BUILD_DIR'] = sys.argv[1] # Cache space for the build pack ctx['CACHE_DIR'] = (len(sys.argv) == 3) and sys.argv[2] or None # Temp space if 'TMPDIR' not in ctx.keys(): ctx['TMPDIR'] = tempfile.gettempdir() # Make sure cache & build directories exist if not os.path.exists(ctx['BUILD_DIR']): os.makedirs(ctx['BUILD_DIR']) if ctx['CACHE_DIR'] and not os.path.exists(ctx['CACHE_DIR']): os.makedirs(ctx['CACHE_DIR']) # Add place holder for extensions ctx['EXTENSIONS'] = [] # Init Logging CloudFoundryUtil.init_logging(ctx) _log.info('CloudFoundry Initialized.') _log.debug("CloudFoundry Context Setup [%s]", ctx) return ctx @staticmethod def init_logging(ctx): logFmt = '%(asctime)s [%(levelname)s] %(name)s - %(message)s' if ctx.get('BP_DEBUG', False): logging.basicConfig(level=logging.DEBUG, format=logFmt) else: logLevelStr = ctx.get('BP_LOG_LEVEL', 'INFO') logLevel = getattr(logging, logLevelStr, logging.INFO) logDir = os.path.join(ctx['BUILD_DIR'], '.bp', 'logs') safe_makedirs(logDir) logging.basicConfig(level=logLevel, format=logFmt, filename=os.path.join(logDir, 'bp.log')) @staticmethod def load_json_config_file_from(folder, cfgFile): return CloudFoundryUtil.load_json_config_file(os.path.join(folder, cfgFile)) @staticmethod def load_json_config_file(cfgPath): if os.path.exists(cfgPath): _log.debug("Loading config from [%s]", cfgPath) with open(cfgPath, 'rt') as cfgFile: return json.load(cfgFile) return {} class CloudFoundryInstaller(object): def __init__(self, ctx): self._log = _log self._ctx = ctx self._unzipUtil = UnzipUtil(ctx) self._hashUtil = HashUtil(ctx) self._dcm = DirectoryCacheManager(ctx) self._dwn = self._get_downloader(ctx)(ctx) def _get_downloader(self, ctx): method = ctx.get('DOWNLOAD_METHOD', 'python') if method == 'python': self._log.debug('Using python downloader.') return Downloader elif method == 'curl': self._log.debug('Using cURL downloader.') return CurlDownloader elif method == 'custom': fullClsName = ctx['DOWNLOAD_CLASS'] self._log.debug('Using custom downloader [%s].', fullClsName) dotLoc = fullClsName.rfind('.') if dotLoc >= 0: clsName = fullClsName[dotLoc + 1: len(fullClsName)] modName = fullClsName[0:dotLoc] m = __import__(modName, globals(), locals(), [clsName]) try: return getattr(m, clsName) except AttributeError: self._log.exception( 'WARNING: DOWNLOAD_CLASS not found!') else: self._log.error( 'WARNING: DOWNLOAD_CLASS invalid, must include ' 'package name!') return Downloader def _is_url(self, val): return urlparse(val).scheme != '' def install_binary_direct(self, url, hsh, installDir, fileName=None, strip=False): self._log.debug("Installing direct [%s]", url) if not fileName: fileName = url.split('/')[-1] if self._is_url(hsh): digest = self._dwn.download_direct(hsh) else: digest = hsh self._log.debug( "Installing [%s] with digest [%s] into [%s] with " "name [%s] stripping [%s]", url, digest, installDir, fileName, strip) fileToInstall = self._dcm.get(fileName, digest) if fileToInstall is None: self._log.debug('File [%s] not in cache.', fileName) fileToInstall = os.path.join(self._ctx['TMPDIR'], fileName) self._dwn.download(url, fileToInstall) digest = self._hashUtil.calculate_hash(fileToInstall) fileToInstall = self._dcm.put(fileName, fileToInstall, digest) return self._unzipUtil.extract(fileToInstall, installDir, strip) def install_binary(self, installKey): self._log.debug('Installing [%s]', installKey) url = self._ctx['%s_DOWNLOAD_URL' % installKey] hashUrl = self._ctx.get( '%s_HASH_DOWNLOAD_URL' % installKey, "%s.%s" % (url, self._ctx['CACHE_HASH_ALGORITHM'])) installDir = os.path.join(self._ctx['BUILD_DIR'], self._ctx.get( '%s_PACKAGE_INSTALL_DIR' % installKey, installKey.lower())) strip = self._ctx.get('%s_STRIP' % installKey, False) return self.install_binary_direct(url, hashUrl, installDir, strip=strip) def _install_from(self, fromPath, fromLoc, toLocation=None, ignore=None): """Copy file or directory from a location to the droplet Copies a file or directory from a location to the application droplet. Directories are copied recursively, but specific files in those directories can be ignored by specifing the ignore parameter. fromPath -> file to copy, relative build pack fromLoc -> root of the from path. Full path to file or directory to be copied is fromLoc + fromPath toLocation -> optional location where to copy the file relative to app droplet. If not specified uses fromPath. ignore -> an optional callable that is passed to the ignore argument of shutil.copytree. """ self._log.debug("Install file [%s] from [%s]", fromPath, fromLoc) fullPathFrom = os.path.join(fromLoc, fromPath) if os.path.exists(fullPathFrom): fullPathTo = os.path.join( self._ctx['BUILD_DIR'], ((toLocation is None) and fromPath or toLocation)) safe_makedirs(os.path.dirname(fullPathTo)) self._log.debug("Copying [%s] to [%s]", fullPathFrom, fullPathTo) if os.path.isfile(fullPathFrom): shutil.copy(fullPathFrom, fullPathTo) else: utils.copytree(fullPathFrom, fullPathTo, ignore=ignore) def install_from_build_pack(self, fromPath, toLocation=None, ignore=None): """Copy file or directory from the build pack to the droplet Copies a file or directory from the build pack to the application droplet. Directories are copied recursively, but specific files in those directories can be ignored by specifing the ignore parameter. fromPath -> file to copy, relative build pack toLocation -> optional location where to copy the file relative to app droplet. If not specified uses fromPath. ignore -> an optional callable that is passed to the ignore argument of shutil.copytree. """ self._install_from( fromPath, self._ctx['BP_DIR'], toLocation, ignore) def install_from_application(self, fromPath, toLocation, ignore=None): """Copy file or directory from one place to another in the application Copies a file or directory from one place to another place within the application droplet. fromPath -> file or directory to copy, relative to application droplet. toLocation -> location where to copy the file, relative to app droplet. ignore -> optional callable that is passed to the ignore argument of shutil.copytree """ self._install_from( fromPath, self._ctx['BUILD_DIR'], toLocation, ignore)
apache-2.0
[ 646, 747, 199, 646, 984, 199, 646, 2022, 199, 646, 5549, 199, 646, 5145, 199, 646, 3778, 199, 646, 2050, 199, 504, 7097, 492, 7097, 199, 504, 3482, 83, 492, 1910, 3065, 9562, 199, 504, 14647, 492, 16101, 9562, 199, 504, 2581, 492, 15191, 4437, 2988, 199, 504, 28242, 492, 13392, 3422, 199, 504, 28242, 492, 445, 633, 3514, 3422, 199, 504, 3778, 492, 5048, 63, 8347, 421, 199, 63, 793, 275, 2050, 14, 5572, 360, 4091, 4214, 651, 358, 421, 199, 533, 8142, 3601, 651, 9562, 8, 785, 304, 272, 768, 4639, 272, 347, 8265, 837, 267, 327, 3232, 3839, 625, 17605, 267, 340, 2688, 8, 1274, 14, 2703, 12, 283, 9843, 735, 288, 984, 14, 2703, 275, 747, 14, 23140, 8, 1274, 14, 2703, 14, 9843, 1062, 283, 6603, 297, 378, 9, 267, 4027, 275, 3778, 14, 31602, 2141, 342, 267, 327, 2654, 3734, 2860, 267, 4027, 14, 873, 8, 736, 14, 2314, 9, 267, 327, 7905, 4840, 2589, 2860, 267, 4027, 459, 54, 8549, 63, 24051, 418, 275, 2022, 14, 3640, 8, 3799, 14, 362, 360, 54, 8549, 63, 24051, 297, 9349, 9005, 297, 9349, 1475, 29, 797, 430, 267, 4027, 459, 54, 8549, 63, 3279, 8670, 418, 275, 2022, 14, 3640, 8, 3799, 14, 362, 360, 54, 8549, 63, 3279, 8670, 297, 8179, 9005, 297, 8179, 1475, 29, 797, 430, 267, 327, 6516, 9954, 12625, 267, 4027, 459, 24408, 63, 3022, 418, 275, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 3475, 8, 1274, 14, 3020, 59, 16, 2459, 267, 327, 2876, 1159, 13515, 16920, 12, 1900, 5978, 2723, 2348, 267, 4027, 459, 8248, 63, 3022, 418, 275, 984, 14, 3020, 59, 17, 61, 267, 327, 11977, 4601, 367, 314, 1900, 1706, 267, 4027, 459, 8677, 63, 3022, 418, 275, 334, 552, 8, 1274, 14, 3020, 9, 508, 650, 9, 436, 984, 14, 3020, 59, 18, 61, 503, 488, 267, 327, 12540, 4601, 267, 340, 283, 17983, 3022, 7, 440, 315, 4027, 14, 1612, 837, 288, 4027, 459, 17983, 3022, 418, 275, 5549, 14, 31572, 342, 267, 327, 4155, 3238, 2581, 1253, 1900, 6602, 2187, 267, 340, 440, 747, 14, 515, 14, 2444, 8, 3799, 459, 8248, 63, 3022, 9090, 288, 747, 14, 8347, 8, 3799, 459, 8248, 63, 3022, 1105, 267, 340, 4027, 459, 8677, 63, 3022, 418, 436, 440, 747, 14, 515, 14, 2444, 8, 3799, 459, 8677, 63, 3022, 9090, 288, 747, 14, 8347, 8, 3799, 459, 8677, 63, 3022, 1105, 267, 327, 2654, 4192, 16712, 367, 5478, 267, 4027, 459, 18451, 418, 275, 942, 267, 327, 21026, 19928, 267, 8142, 3601, 651, 9562, 14, 826, 63, 4806, 8, 3799, 9, 267, 485, 793, 14, 815, 360, 9089, 3601, 651, 6026, 1759, 2659, 267, 485, 793, 14, 1757, 480, 9089, 3601, 651, 9470, 12439, 8978, 83, 11472, 4027, 9, 267, 372, 4027, 339, 768, 4639, 272, 347, 4205, 63, 4806, 8, 3799, 304, 267, 943, 38, 2037, 275, 9487, 18331, 9, 83, 359, 2840, 20056, 9, 83, 61, 2818, 354, 9, 83, 446, 2818, 1188, 9, 83, 7, 267, 340, 4027, 14, 362, 360, 24408, 63, 5287, 297, 756, 304, 288, 2050, 14, 19602, 8, 1896, 29, 4806, 14, 5287, 12, 1475, 29, 793, 38, 2037, 9, 267, 587, 26, 288, 943, 4670, 2848, 275, 4027, 14, 362, 360, 24408, 63, 4947, 63, 11817, 297, 283, 4531, 358, 288, 943, 4670, 275, 2519, 8, 4806, 12, 943, 4670, 2848, 12, 2050, 14, 4531, 9, 288, 943, 3567, 275, 747, 14, 515, 14, 904, 8, 3799, 459, 8248, 63, 3022, 995, 1987, 10913, 297, 283, 7270, 358, 288, 5048, 63, 8347, 8, 793, 3567, 9, 288, 2050, 14, 19602, 8, 1896, 29, 793, 4670, 12, 1475, 29, 793, 38, 2037, 12, 1816, 1788, 29, 736, 14, 515, 14, 904, 8, 793, 3567, 12, 283, 10913, 14, 793, 1333, 339, 768, 4639, 272, 347, 2248, 63, 1001, 63, 888, 63, 493, 63, 504, 8, 3741, 12, 4810, 1173, 304, 267, 372, 8142, 3601, 651, 9562, 14, 912, 63, 1001, 63, 888, 63, 493, 8, 736, 14, 515, 14, 904, 8, 3741, 12, 28095, 4810, 1173, 430, 339, 768, 4639, 272, 347, 2248, 63, 1001, 63, 888, 63, 493, 8, 4128, 2042, 304, 267, 340, 747, 14, 515, 14, 2444, 8, 4128, 2042, 304, 288, 485, 793, 14, 1757, 480, 19236, 1101, 687, 8978, 83, 11472, 4810, 2042, 9, 288, 543, 1551, 8, 4128, 2042, 12, 283, 2591, 358, 465, 4810, 1173, 26, 355, 372, 2022, 14, 912, 8, 4128, 1173, 9, 267, 372, 1052, 421, 199, 533, 8142, 3601, 651, 27598, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 4027, 304, 267, 291, 423, 793, 275, 485, 793, 267, 291, 423, 3799, 275, 4027, 267, 291, 423, 26700, 9562, 275, 1910, 3065, 9562, 8, 3799, 9, 267, 291, 423, 2227, 9562, 275, 16101, 9562, 8, 3799, 9, 267, 291, 423, 3833, 77, 275, 15191, 4437, 2988, 8, 3799, 9, 267, 291, 423, 68, 3501, 275, 291, 423, 362, 63, 22846, 8, 3799, 5130, 3799, 9, 339, 347, 485, 362, 63, 22846, 8, 277, 12, 4027, 304, 267, 1083, 275, 4027, 14, 362, 360, 24930, 63, 9977, 297, 283, 1548, 358, 267, 340, 1083, 508, 283, 1548, 356, 288, 291, 423, 793, 14, 1757, 360, 10369, 2366, 3224, 3422, 2659, 288, 372, 13392, 3422, 267, 916, 1083, 508, 283, 17096, 356, 288, 291, 423, 793, 14, 1757, 360, 10369, 286, 2632, 3224, 3422, 2659, 288, 372, 445, 633, 3514, 3422, 267, 916, 1083, 508, 283, 4229, 356, 288, 2615, 24342, 985, 275, 4027, 459, 24930, 63, 6885, 418, 288, 291, 423, 793, 14, 1757, 360, 10369, 3537, 3224, 3422, 8978, 83, 1055, 297, 2615, 24342, 985, 9, 288, 6308, 3040, 275, 2615, 24342, 985, 14, 14542, 7563, 288, 340, 6308, 3040, 2356, 378, 26, 355, 843, 985, 275, 2615, 24342, 985, 59, 3287, 3040, 435, 413, 26, 822, 8, 2861, 24342, 985, 1874, 355, 3413, 985, 275, 2615, 24342, 985, 59, 16, 26, 3287, 3040, 61, 355, 333, 275, 636, 646, 721, 1494, 985, 12, 7992, 1062, 9480, 1062, 359, 1886, 985, 566, 355, 862, 26, 490, 372, 2519, 8, 77, 12, 843, 985, 9, 355 ]
[ 747, 199, 646, 984, 199, 646, 2022, 199, 646, 5549, 199, 646, 5145, 199, 646, 3778, 199, 646, 2050, 199, 504, 7097, 492, 7097, 199, 504, 3482, 83, 492, 1910, 3065, 9562, 199, 504, 14647, 492, 16101, 9562, 199, 504, 2581, 492, 15191, 4437, 2988, 199, 504, 28242, 492, 13392, 3422, 199, 504, 28242, 492, 445, 633, 3514, 3422, 199, 504, 3778, 492, 5048, 63, 8347, 421, 199, 63, 793, 275, 2050, 14, 5572, 360, 4091, 4214, 651, 358, 421, 199, 533, 8142, 3601, 651, 9562, 8, 785, 304, 272, 768, 4639, 272, 347, 8265, 837, 267, 327, 3232, 3839, 625, 17605, 267, 340, 2688, 8, 1274, 14, 2703, 12, 283, 9843, 735, 288, 984, 14, 2703, 275, 747, 14, 23140, 8, 1274, 14, 2703, 14, 9843, 1062, 283, 6603, 297, 378, 9, 267, 4027, 275, 3778, 14, 31602, 2141, 342, 267, 327, 2654, 3734, 2860, 267, 4027, 14, 873, 8, 736, 14, 2314, 9, 267, 327, 7905, 4840, 2589, 2860, 267, 4027, 459, 54, 8549, 63, 24051, 418, 275, 2022, 14, 3640, 8, 3799, 14, 362, 360, 54, 8549, 63, 24051, 297, 9349, 9005, 297, 9349, 1475, 29, 797, 430, 267, 4027, 459, 54, 8549, 63, 3279, 8670, 418, 275, 2022, 14, 3640, 8, 3799, 14, 362, 360, 54, 8549, 63, 3279, 8670, 297, 8179, 9005, 297, 8179, 1475, 29, 797, 430, 267, 327, 6516, 9954, 12625, 267, 4027, 459, 24408, 63, 3022, 418, 275, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 3475, 8, 1274, 14, 3020, 59, 16, 2459, 267, 327, 2876, 1159, 13515, 16920, 12, 1900, 5978, 2723, 2348, 267, 4027, 459, 8248, 63, 3022, 418, 275, 984, 14, 3020, 59, 17, 61, 267, 327, 11977, 4601, 367, 314, 1900, 1706, 267, 4027, 459, 8677, 63, 3022, 418, 275, 334, 552, 8, 1274, 14, 3020, 9, 508, 650, 9, 436, 984, 14, 3020, 59, 18, 61, 503, 488, 267, 327, 12540, 4601, 267, 340, 283, 17983, 3022, 7, 440, 315, 4027, 14, 1612, 837, 288, 4027, 459, 17983, 3022, 418, 275, 5549, 14, 31572, 342, 267, 327, 4155, 3238, 2581, 1253, 1900, 6602, 2187, 267, 340, 440, 747, 14, 515, 14, 2444, 8, 3799, 459, 8248, 63, 3022, 9090, 288, 747, 14, 8347, 8, 3799, 459, 8248, 63, 3022, 1105, 267, 340, 4027, 459, 8677, 63, 3022, 418, 436, 440, 747, 14, 515, 14, 2444, 8, 3799, 459, 8677, 63, 3022, 9090, 288, 747, 14, 8347, 8, 3799, 459, 8677, 63, 3022, 1105, 267, 327, 2654, 4192, 16712, 367, 5478, 267, 4027, 459, 18451, 418, 275, 942, 267, 327, 21026, 19928, 267, 8142, 3601, 651, 9562, 14, 826, 63, 4806, 8, 3799, 9, 267, 485, 793, 14, 815, 360, 9089, 3601, 651, 6026, 1759, 2659, 267, 485, 793, 14, 1757, 480, 9089, 3601, 651, 9470, 12439, 8978, 83, 11472, 4027, 9, 267, 372, 4027, 339, 768, 4639, 272, 347, 4205, 63, 4806, 8, 3799, 304, 267, 943, 38, 2037, 275, 9487, 18331, 9, 83, 359, 2840, 20056, 9, 83, 61, 2818, 354, 9, 83, 446, 2818, 1188, 9, 83, 7, 267, 340, 4027, 14, 362, 360, 24408, 63, 5287, 297, 756, 304, 288, 2050, 14, 19602, 8, 1896, 29, 4806, 14, 5287, 12, 1475, 29, 793, 38, 2037, 9, 267, 587, 26, 288, 943, 4670, 2848, 275, 4027, 14, 362, 360, 24408, 63, 4947, 63, 11817, 297, 283, 4531, 358, 288, 943, 4670, 275, 2519, 8, 4806, 12, 943, 4670, 2848, 12, 2050, 14, 4531, 9, 288, 943, 3567, 275, 747, 14, 515, 14, 904, 8, 3799, 459, 8248, 63, 3022, 995, 1987, 10913, 297, 283, 7270, 358, 288, 5048, 63, 8347, 8, 793, 3567, 9, 288, 2050, 14, 19602, 8, 1896, 29, 793, 4670, 12, 1475, 29, 793, 38, 2037, 12, 1816, 1788, 29, 736, 14, 515, 14, 904, 8, 793, 3567, 12, 283, 10913, 14, 793, 1333, 339, 768, 4639, 272, 347, 2248, 63, 1001, 63, 888, 63, 493, 63, 504, 8, 3741, 12, 4810, 1173, 304, 267, 372, 8142, 3601, 651, 9562, 14, 912, 63, 1001, 63, 888, 63, 493, 8, 736, 14, 515, 14, 904, 8, 3741, 12, 28095, 4810, 1173, 430, 339, 768, 4639, 272, 347, 2248, 63, 1001, 63, 888, 63, 493, 8, 4128, 2042, 304, 267, 340, 747, 14, 515, 14, 2444, 8, 4128, 2042, 304, 288, 485, 793, 14, 1757, 480, 19236, 1101, 687, 8978, 83, 11472, 4810, 2042, 9, 288, 543, 1551, 8, 4128, 2042, 12, 283, 2591, 358, 465, 4810, 1173, 26, 355, 372, 2022, 14, 912, 8, 4128, 1173, 9, 267, 372, 1052, 421, 199, 533, 8142, 3601, 651, 27598, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 4027, 304, 267, 291, 423, 793, 275, 485, 793, 267, 291, 423, 3799, 275, 4027, 267, 291, 423, 26700, 9562, 275, 1910, 3065, 9562, 8, 3799, 9, 267, 291, 423, 2227, 9562, 275, 16101, 9562, 8, 3799, 9, 267, 291, 423, 3833, 77, 275, 15191, 4437, 2988, 8, 3799, 9, 267, 291, 423, 68, 3501, 275, 291, 423, 362, 63, 22846, 8, 3799, 5130, 3799, 9, 339, 347, 485, 362, 63, 22846, 8, 277, 12, 4027, 304, 267, 1083, 275, 4027, 14, 362, 360, 24930, 63, 9977, 297, 283, 1548, 358, 267, 340, 1083, 508, 283, 1548, 356, 288, 291, 423, 793, 14, 1757, 360, 10369, 2366, 3224, 3422, 2659, 288, 372, 13392, 3422, 267, 916, 1083, 508, 283, 17096, 356, 288, 291, 423, 793, 14, 1757, 360, 10369, 286, 2632, 3224, 3422, 2659, 288, 372, 445, 633, 3514, 3422, 267, 916, 1083, 508, 283, 4229, 356, 288, 2615, 24342, 985, 275, 4027, 459, 24930, 63, 6885, 418, 288, 291, 423, 793, 14, 1757, 360, 10369, 3537, 3224, 3422, 8978, 83, 1055, 297, 2615, 24342, 985, 9, 288, 6308, 3040, 275, 2615, 24342, 985, 14, 14542, 7563, 288, 340, 6308, 3040, 2356, 378, 26, 355, 843, 985, 275, 2615, 24342, 985, 59, 3287, 3040, 435, 413, 26, 822, 8, 2861, 24342, 985, 1874, 355, 3413, 985, 275, 2615, 24342, 985, 59, 16, 26, 3287, 3040, 61, 355, 333, 275, 636, 646, 721, 1494, 985, 12, 7992, 1062, 9480, 1062, 359, 1886, 985, 566, 355, 862, 26, 490, 372, 2519, 8, 77, 12, 843, 985, 9, 355, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
yangchaogit/boto
boto/__init__.py
87
41904
# Copyright (c) 2006-2012 Mitch Garnaat http://garnaat.org/ # Copyright (c) 2010-2011, Eucalyptus Systems, Inc. # Copyright (c) 2011, Nexenta Systems Inc. # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. # Copyright (c) 2010, Google, Inc. # All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, dis- # tribute, sublicense, and/or sell copies of the Software, and to permit # persons to whom the Software is furnished to do so, subject to the fol- # lowing conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # from boto.pyami.config import Config, BotoConfigLocations from boto.storage_uri import BucketStorageUri, FileStorageUri import boto.plugin import datetime import os import platform import re import sys import logging import logging.config from boto.compat import urlparse from boto.exception import InvalidUriError __version__ = '2.38.0' Version = __version__ # for backware compatibility # http://bugs.python.org/issue7980 datetime.datetime.strptime('', '') UserAgent = 'Boto/%s Python/%s %s/%s' % ( __version__, platform.python_version(), platform.system(), platform.release() ) config = Config() # Regex to disallow buckets violating charset or not [3..255] chars total. BUCKET_NAME_RE = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9\._-]{1,253}[a-zA-Z0-9]$') # Regex to disallow buckets with individual DNS labels longer than 63. TOO_LONG_DNS_NAME_COMP = re.compile(r'[-_a-z0-9]{64}') GENERATION_RE = re.compile(r'(?P<versionless_uri_str>.+)' r'#(?P<generation>[0-9]+)$') VERSION_RE = re.compile('(?P<versionless_uri_str>.+)#(?P<version_id>.+)$') ENDPOINTS_PATH = os.path.join(os.path.dirname(__file__), 'endpoints.json') def init_logging(): for file in BotoConfigLocations: try: logging.config.fileConfig(os.path.expanduser(file)) except: pass class NullHandler(logging.Handler): def emit(self, record): pass log = logging.getLogger('boto') perflog = logging.getLogger('boto.perf') log.addHandler(NullHandler()) perflog.addHandler(NullHandler()) init_logging() # convenience function to set logging to a particular file def set_file_logger(name, filepath, level=logging.INFO, format_string=None): global log if not format_string: format_string = "%(asctime)s %(name)s [%(levelname)s]:%(message)s" logger = logging.getLogger(name) logger.setLevel(level) fh = logging.FileHandler(filepath) fh.setLevel(level) formatter = logging.Formatter(format_string) fh.setFormatter(formatter) logger.addHandler(fh) log = logger def set_stream_logger(name, level=logging.DEBUG, format_string=None): global log if not format_string: format_string = "%(asctime)s %(name)s [%(levelname)s]:%(message)s" logger = logging.getLogger(name) logger.setLevel(level) fh = logging.StreamHandler() fh.setLevel(level) formatter = logging.Formatter(format_string) fh.setFormatter(formatter) logger.addHandler(fh) log = logger def connect_sqs(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.sqs.connection.SQSConnection` :return: A connection to Amazon's SQS """ from boto.sqs.connection import SQSConnection return SQSConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_s3(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.s3.connection.S3Connection` :return: A connection to Amazon's S3 """ from boto.s3.connection import S3Connection return S3Connection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_gs(gs_access_key_id=None, gs_secret_access_key=None, **kwargs): """ @type gs_access_key_id: string @param gs_access_key_id: Your Google Cloud Storage Access Key ID @type gs_secret_access_key: string @param gs_secret_access_key: Your Google Cloud Storage Secret Access Key @rtype: L{GSConnection<boto.gs.connection.GSConnection>} @return: A connection to Google's Storage service """ from boto.gs.connection import GSConnection return GSConnection(gs_access_key_id, gs_secret_access_key, **kwargs) def connect_ec2(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.ec2.connection.EC2Connection` :return: A connection to Amazon's EC2 """ from boto.ec2.connection import EC2Connection return EC2Connection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_elb(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.ec2.elb.ELBConnection` :return: A connection to Amazon's Load Balancing Service """ from boto.ec2.elb import ELBConnection return ELBConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_autoscale(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.ec2.autoscale.AutoScaleConnection` :return: A connection to Amazon's Auto Scaling Service :type use_block_device_types bool :param use_block_device_types: Specifies whether to return described Launch Configs with block device mappings containing block device types, or a list of old style block device mappings (deprecated). This defaults to false for compatability with the old incorrect style. """ from boto.ec2.autoscale import AutoScaleConnection return AutoScaleConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_cloudwatch(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.ec2.cloudwatch.CloudWatchConnection` :return: A connection to Amazon's EC2 Monitoring service """ from boto.ec2.cloudwatch import CloudWatchConnection return CloudWatchConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_sdb(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.sdb.connection.SDBConnection` :return: A connection to Amazon's SDB """ from boto.sdb.connection import SDBConnection return SDBConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_fps(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.fps.connection.FPSConnection` :return: A connection to FPS """ from boto.fps.connection import FPSConnection return FPSConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_mturk(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.mturk.connection.MTurkConnection` :return: A connection to MTurk """ from boto.mturk.connection import MTurkConnection return MTurkConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_cloudfront(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.fps.connection.FPSConnection` :return: A connection to FPS """ from boto.cloudfront import CloudFrontConnection return CloudFrontConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_vpc(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.vpc.VPCConnection` :return: A connection to VPC """ from boto.vpc import VPCConnection return VPCConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_rds(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.rds.RDSConnection` :return: A connection to RDS """ from boto.rds import RDSConnection return RDSConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_rds2(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.rds2.layer1.RDSConnection` :return: A connection to RDS """ from boto.rds2.layer1 import RDSConnection return RDSConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_emr(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.emr.EmrConnection` :return: A connection to Elastic mapreduce """ from boto.emr import EmrConnection return EmrConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_sns(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.sns.SNSConnection` :return: A connection to Amazon's SNS """ from boto.sns import SNSConnection return SNSConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_iam(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.iam.IAMConnection` :return: A connection to Amazon's IAM """ from boto.iam import IAMConnection return IAMConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_route53(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.dns.Route53Connection` :return: A connection to Amazon's Route53 DNS Service """ from boto.route53 import Route53Connection return Route53Connection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_cloudformation(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.cloudformation.CloudFormationConnection` :return: A connection to Amazon's CloudFormation Service """ from boto.cloudformation import CloudFormationConnection return CloudFormationConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_euca(host=None, aws_access_key_id=None, aws_secret_access_key=None, port=8773, path='/services/Eucalyptus', is_secure=False, **kwargs): """ Connect to a Eucalyptus service. :type host: string :param host: the host name or ip address of the Eucalyptus server :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.ec2.connection.EC2Connection` :return: A connection to Eucalyptus server """ from boto.ec2 import EC2Connection from boto.ec2.regioninfo import RegionInfo # Check for values in boto config, if not supplied as args if not aws_access_key_id: aws_access_key_id = config.get('Credentials', 'euca_access_key_id', None) if not aws_secret_access_key: aws_secret_access_key = config.get('Credentials', 'euca_secret_access_key', None) if not host: host = config.get('Boto', 'eucalyptus_host', None) reg = RegionInfo(name='eucalyptus', endpoint=host) return EC2Connection(aws_access_key_id, aws_secret_access_key, region=reg, port=port, path=path, is_secure=is_secure, **kwargs) def connect_glacier(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.glacier.layer2.Layer2` :return: A connection to Amazon's Glacier Service """ from boto.glacier.layer2 import Layer2 return Layer2(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_ec2_endpoint(url, aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to an EC2 Api endpoint. Additional arguments are passed through to connect_ec2. :type url: string :param url: A url for the ec2 api endpoint to connect to :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.ec2.connection.EC2Connection` :return: A connection to Eucalyptus server """ from boto.ec2.regioninfo import RegionInfo purl = urlparse(url) kwargs['port'] = purl.port kwargs['host'] = purl.hostname kwargs['path'] = purl.path if not 'is_secure' in kwargs: kwargs['is_secure'] = (purl.scheme == "https") kwargs['region'] = RegionInfo(name=purl.hostname, endpoint=purl.hostname) kwargs['aws_access_key_id'] = aws_access_key_id kwargs['aws_secret_access_key'] = aws_secret_access_key return(connect_ec2(**kwargs)) def connect_walrus(host=None, aws_access_key_id=None, aws_secret_access_key=None, port=8773, path='/services/Walrus', is_secure=False, **kwargs): """ Connect to a Walrus service. :type host: string :param host: the host name or ip address of the Walrus server :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.s3.connection.S3Connection` :return: A connection to Walrus """ from boto.s3.connection import S3Connection from boto.s3.connection import OrdinaryCallingFormat # Check for values in boto config, if not supplied as args if not aws_access_key_id: aws_access_key_id = config.get('Credentials', 'euca_access_key_id', None) if not aws_secret_access_key: aws_secret_access_key = config.get('Credentials', 'euca_secret_access_key', None) if not host: host = config.get('Boto', 'walrus_host', None) return S3Connection(aws_access_key_id, aws_secret_access_key, host=host, port=port, path=path, calling_format=OrdinaryCallingFormat(), is_secure=is_secure, **kwargs) def connect_ses(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.ses.SESConnection` :return: A connection to Amazon's SES """ from boto.ses import SESConnection return SESConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_sts(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.sts.STSConnection` :return: A connection to Amazon's STS """ from boto.sts import STSConnection return STSConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_ia(ia_access_key_id=None, ia_secret_access_key=None, is_secure=False, **kwargs): """ Connect to the Internet Archive via their S3-like API. :type ia_access_key_id: string :param ia_access_key_id: Your IA Access Key ID. This will also look in your boto config file for an entry in the Credentials section called "ia_access_key_id" :type ia_secret_access_key: string :param ia_secret_access_key: Your IA Secret Access Key. This will also look in your boto config file for an entry in the Credentials section called "ia_secret_access_key" :rtype: :class:`boto.s3.connection.S3Connection` :return: A connection to the Internet Archive """ from boto.s3.connection import S3Connection from boto.s3.connection import OrdinaryCallingFormat access_key = config.get('Credentials', 'ia_access_key_id', ia_access_key_id) secret_key = config.get('Credentials', 'ia_secret_access_key', ia_secret_access_key) return S3Connection(access_key, secret_key, host='s3.us.archive.org', calling_format=OrdinaryCallingFormat(), is_secure=is_secure, **kwargs) def connect_dynamodb(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.dynamodb.layer2.Layer2` :return: A connection to the Layer2 interface for DynamoDB. """ from boto.dynamodb.layer2 import Layer2 return Layer2(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_swf(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.swf.layer1.Layer1` :return: A connection to the Layer1 interface for SWF. """ from boto.swf.layer1 import Layer1 return Layer1(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_cloudsearch(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.cloudsearch.layer2.Layer2` :return: A connection to Amazon's CloudSearch service """ from boto.cloudsearch.layer2 import Layer2 return Layer2(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_cloudsearch2(aws_access_key_id=None, aws_secret_access_key=None, sign_request=False, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :type sign_request: bool :param sign_request: whether or not to sign search and upload requests :rtype: :class:`boto.cloudsearch2.layer2.Layer2` :return: A connection to Amazon's CloudSearch2 service """ from boto.cloudsearch2.layer2 import Layer2 return Layer2(aws_access_key_id, aws_secret_access_key, sign_request=sign_request, **kwargs) def connect_cloudsearchdomain(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.cloudsearchdomain.layer1.CloudSearchDomainConnection` :return: A connection to Amazon's CloudSearch Domain service """ from boto.cloudsearchdomain.layer1 import CloudSearchDomainConnection return CloudSearchDomainConnection(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_beanstalk(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.beanstalk.layer1.Layer1` :return: A connection to Amazon's Elastic Beanstalk service """ from boto.beanstalk.layer1 import Layer1 return Layer1(aws_access_key_id, aws_secret_access_key, **kwargs) def connect_elastictranscoder(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.ets.layer1.ElasticTranscoderConnection` :return: A connection to Amazon's Elastic Transcoder service """ from boto.elastictranscoder.layer1 import ElasticTranscoderConnection return ElasticTranscoderConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs) def connect_opsworks(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): from boto.opsworks.layer1 import OpsWorksConnection return OpsWorksConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs) def connect_redshift(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.redshift.layer1.RedshiftConnection` :return: A connection to Amazon's Redshift service """ from boto.redshift.layer1 import RedshiftConnection return RedshiftConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_support(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.support.layer1.SupportConnection` :return: A connection to Amazon's Support service """ from boto.support.layer1 import SupportConnection return SupportConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_cloudtrail(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to AWS CloudTrail :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.cloudtrail.layer1.CloudtrailConnection` :return: A connection to the AWS Cloudtrail service """ from boto.cloudtrail.layer1 import CloudTrailConnection return CloudTrailConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_directconnect(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to AWS DirectConnect :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key :rtype: :class:`boto.directconnect.layer1.DirectConnectConnection` :return: A connection to the AWS DirectConnect service """ from boto.directconnect.layer1 import DirectConnectConnection return DirectConnectConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_kinesis(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to Amazon Kinesis :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key rtype: :class:`boto.kinesis.layer1.KinesisConnection` :return: A connection to the Amazon Kinesis service """ from boto.kinesis.layer1 import KinesisConnection return KinesisConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_logs(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to Amazon CloudWatch Logs :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key rtype: :class:`boto.kinesis.layer1.CloudWatchLogsConnection` :return: A connection to the Amazon CloudWatch Logs service """ from boto.logs.layer1 import CloudWatchLogsConnection return CloudWatchLogsConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_route53domains(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to Amazon Route 53 Domains :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key rtype: :class:`boto.route53.domains.layer1.Route53DomainsConnection` :return: A connection to the Amazon Route 53 Domains service """ from boto.route53.domains.layer1 import Route53DomainsConnection return Route53DomainsConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_cognito_identity(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to Amazon Cognito Identity :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key rtype: :class:`boto.cognito.identity.layer1.CognitoIdentityConnection` :return: A connection to the Amazon Cognito Identity service """ from boto.cognito.identity.layer1 import CognitoIdentityConnection return CognitoIdentityConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_cognito_sync(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to Amazon Cognito Sync :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key rtype: :class:`boto.cognito.sync.layer1.CognitoSyncConnection` :return: A connection to the Amazon Cognito Sync service """ from boto.cognito.sync.layer1 import CognitoSyncConnection return CognitoSyncConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_kms(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to AWS Key Management Service :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key rtype: :class:`boto.kms.layer1.KMSConnection` :return: A connection to the AWS Key Management Service """ from boto.kms.layer1 import KMSConnection return KMSConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_awslambda(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to AWS Lambda :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key rtype: :class:`boto.awslambda.layer1.AWSLambdaConnection` :return: A connection to the AWS Lambda service """ from boto.awslambda.layer1 import AWSLambdaConnection return AWSLambdaConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_codedeploy(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to AWS CodeDeploy :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key rtype: :class:`boto.cognito.sync.layer1.CodeDeployConnection` :return: A connection to the AWS CodeDeploy service """ from boto.codedeploy.layer1 import CodeDeployConnection return CodeDeployConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_configservice(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to AWS Config :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key rtype: :class:`boto.kms.layer1.ConfigServiceConnection` :return: A connection to the AWS Config service """ from boto.configservice.layer1 import ConfigServiceConnection return ConfigServiceConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_cloudhsm(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to AWS CloudHSM :type aws_access_key_id: string :param aws_access_key_id: Your AWS Access Key ID :type aws_secret_access_key: string :param aws_secret_access_key: Your AWS Secret Access Key rtype: :class:`boto.cloudhsm.layer1.CloudHSMConnection` :return: A connection to the AWS CloudHSM service """ from boto.cloudhsm.layer1 import CloudHSMConnection return CloudHSMConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_ec2containerservice(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to Amazon EC2 Container Service rtype: :class:`boto.ec2containerservice.layer1.EC2ContainerServiceConnection` :return: A connection to the Amazon EC2 Container Service """ from boto.ec2containerservice.layer1 import EC2ContainerServiceConnection return EC2ContainerServiceConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def connect_machinelearning(aws_access_key_id=None, aws_secret_access_key=None, **kwargs): """ Connect to Amazon Machine Learning service rtype: :class:`boto.machinelearning.layer1.MachineLearningConnection` :return: A connection to the Amazon Machine Learning service """ from boto.machinelearning.layer1 import MachineLearningConnection return MachineLearningConnection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, **kwargs ) def storage_uri(uri_str, default_scheme='file', debug=0, validate=True, bucket_storage_uri_class=BucketStorageUri, suppress_consec_slashes=True, is_latest=False): """ Instantiate a StorageUri from a URI string. :type uri_str: string :param uri_str: URI naming bucket + optional object. :type default_scheme: string :param default_scheme: default scheme for scheme-less URIs. :type debug: int :param debug: debug level to pass in to boto connection (range 0..2). :type validate: bool :param validate: whether to check for bucket name validity. :type bucket_storage_uri_class: BucketStorageUri interface. :param bucket_storage_uri_class: Allows mocking for unit tests. :param suppress_consec_slashes: If provided, controls whether consecutive slashes will be suppressed in key paths. :type is_latest: bool :param is_latest: whether this versioned object represents the current version. We allow validate to be disabled to allow caller to implement bucket-level wildcarding (outside the boto library; see gsutil). :rtype: :class:`boto.StorageUri` subclass :return: StorageUri subclass for given URI. ``uri_str`` must be one of the following formats: * gs://bucket/name * gs://bucket/name#ver * s3://bucket/name * gs://bucket * s3://bucket * filename (which could be a Unix path like /a/b/c or a Windows path like C:\a\b\c) The last example uses the default scheme ('file', unless overridden). """ version_id = None generation = None # Manually parse URI components instead of using urlparse because # what we're calling URIs don't really fit the standard syntax for URIs # (the latter includes an optional host/net location part). end_scheme_idx = uri_str.find('://') if end_scheme_idx == -1: scheme = default_scheme.lower() path = uri_str else: scheme = uri_str[0:end_scheme_idx].lower() path = uri_str[end_scheme_idx + 3:] if scheme not in ['file', 's3', 'gs']: raise InvalidUriError('Unrecognized scheme "%s"' % scheme) if scheme == 'file': # For file URIs we have no bucket name, and use the complete path # (minus 'file://') as the object name. is_stream = False if path == '-': is_stream = True return FileStorageUri(path, debug, is_stream) else: path_parts = path.split('/', 1) bucket_name = path_parts[0] object_name = '' # If validate enabled, ensure the bucket name is valid, to avoid # possibly confusing other parts of the code. (For example if we didn't # catch bucket names containing ':', when a user tried to connect to # the server with that name they might get a confusing error about # non-integer port numbers.) if (validate and bucket_name and (not BUCKET_NAME_RE.match(bucket_name) or TOO_LONG_DNS_NAME_COMP.search(bucket_name))): raise InvalidUriError('Invalid bucket name in URI "%s"' % uri_str) if scheme == 'gs': match = GENERATION_RE.search(path) if match: md = match.groupdict() versionless_uri_str = md['versionless_uri_str'] path_parts = versionless_uri_str.split('/', 1) generation = int(md['generation']) elif scheme == 's3': match = VERSION_RE.search(path) if match: md = match.groupdict() versionless_uri_str = md['versionless_uri_str'] path_parts = versionless_uri_str.split('/', 1) version_id = md['version_id'] else: raise InvalidUriError('Unrecognized scheme "%s"' % scheme) if len(path_parts) > 1: object_name = path_parts[1] return bucket_storage_uri_class( scheme, bucket_name, object_name, debug, suppress_consec_slashes=suppress_consec_slashes, version_id=version_id, generation=generation, is_latest=is_latest) def storage_uri_for_key(key): """Returns a StorageUri for the given key. :type key: :class:`boto.s3.key.Key` or subclass :param key: URI naming bucket + optional object. """ if not isinstance(key, boto.s3.key.Key): raise InvalidUriError('Requested key (%s) is not a subclass of ' 'boto.s3.key.Key' % str(type(key))) prov_name = key.bucket.connection.provider.get_provider_name() uri_str = '%s://%s/%s' % (prov_name, key.bucket.name, key.name) return storage_uri(uri_str) boto.plugin.load_plugins(config)
mit
[ 3, 1898, 334, 67, 9, 8315, 13, 7409, 603, 9414, 598, 26272, 1455, 921, 71, 26272, 14, 1308, 15, 199, 3, 1898, 334, 67, 9, 7129, 13, 8128, 12, 662, 85, 915, 89, 541, 527, 15285, 12, 3277, 14, 199, 3, 1898, 334, 67, 9, 7760, 12, 653, 476, 21335, 15285, 3277, 14, 199, 3, 1898, 334, 67, 9, 6029, 14347, 14, 957, 12, 3277, 14, 503, 2399, 29172, 2335, 14, 199, 3, 1898, 334, 67, 9, 7129, 12, 4475, 12, 3277, 14, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 199, 3, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 199, 3, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 199, 3, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 2153, 13, 199, 3, 28420, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 436, 370, 11291, 199, 3, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 5420, 370, 314, 1699, 13, 199, 3, 28486, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 199, 3, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 199, 3, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 28471, 13, 199, 3, 28463, 12, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 199, 3, 7000, 2334, 17632, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 199, 3, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 199, 3, 1621, 2334, 4141, 14, 199, 3, 199, 504, 6055, 14, 647, 13496, 14, 888, 492, 4094, 12, 24411, 2028, 27727, 199, 504, 6055, 14, 3494, 63, 2302, 492, 31479, 6408, 14014, 12, 3814, 6408, 14014, 199, 646, 6055, 14, 2718, 199, 646, 2197, 199, 646, 747, 199, 646, 4298, 199, 646, 295, 199, 646, 984, 199, 646, 2050, 199, 646, 2050, 14, 888, 199, 199, 504, 6055, 14, 5819, 492, 7097, 199, 504, 6055, 14, 1971, 492, 6378, 14014, 547, 199, 199, 363, 1023, 363, 275, 283, 18, 14, 1703, 14, 16, 7, 199, 3353, 275, 636, 1023, 363, 221, 327, 367, 1771, 1068, 7163, 199, 199, 3, 1455, 921, 13017, 14, 1548, 14, 1308, 15, 5237, 1965, 1257, 199, 2083, 14, 2083, 14, 9866, 8594, 4074, 199, 199, 1899, 7788, 275, 283, 20380, 3149, 83, 2018, 3149, 83, 450, 83, 3149, 83, 7, 450, 334, 272, 636, 1023, 3108, 272, 4298, 14, 1548, 63, 1023, 1062, 272, 4298, 14, 2253, 1062, 272, 4298, 14, 3221, 342, 199, 9, 199, 888, 275, 4094, 342, 199, 199, 3, 12939, 370, 2153, 3306, 18655, 1321, 393, 1958, 5960, 503, 440, 359, 19, 703, 2299, 61, 8365, 3141, 14, 199, 20156, 63, 2339, 63, 907, 275, 295, 14, 2014, 8, 82, 23811, 65, 13, 6353, 13, 58, 16, 13, 25, 1527, 65, 13, 6353, 13, 58, 16, 13, 25, 60, 423, 13, 8194, 17, 12, 3781, 22857, 65, 13, 6353, 13, 58, 16, 13, 25, 61, 9988, 199, 3, 12939, 370, 2153, 3306, 18655, 543, 8212, 10237, 3628, 8088, 2419, 13668, 14, 199, 30947, 63, 12375, 63, 12323, 63, 2339, 63, 6790, 275, 295, 14, 2014, 8, 82, 7, 1988, 63, 65, 13, 90, 16, 13, 25, 8194, 772, 12216, 199, 12795, 2594, 63, 907, 275, 295, 14, 2014, 8, 82, 10120, 48, 28, 1023, 2003, 63, 2302, 63, 495, 31411, 3171, 2574, 519, 11525, 2229, 48, 28, 15043, 9514, 16, 13, 25, 11896, 9988, 199, 4612, 63, 907, 275, 295, 14, 2014, 28353, 48, 28, 1023, 2003, 63, 2302, 63, 495, 31411, 28017, 2229, 48, 28, 1023, 63, 344, 31411, 9, 9988, 199, 21054, 51, 63, 3243, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 283, 14461, 14, 1001, 358, 421, 199, 318, 4205, 63, 4806, 837, 272, 367, 570, 315, 24411, 2028, 27727, 26, 267, 862, 26, 288, 2050, 14, 888, 14, 493, 2028, 8, 736, 14, 515, 14, 12131, 8, 493, 430, 267, 871, 26, 288, 986, 421, 199, 533, 12119, 2461, 8, 4806, 14, 2461, 304, 272, 347, 8689, 8, 277, 12, 2777, 304, 267, 986, 199, 199, 793, 275, 2050, 14, 5572, 360, 10914, 358, 199, 9452, 793, 275, 2050, 14, 5572, 360, 10914, 14, 9452, 358, 199, 793, 14, 18826, 8, 8849, 2461, 1012, 199, 9452, 793, 14, 18826, 8, 8849, 2461, 1012, 199, 826, 63, 4806, 342, 199, 199, 3, 16777, 805, 370, 663, 2050, 370, 282, 6770, 570, 421, 199, 318, 663, 63, 493, 63, 2921, 8, 354, 12, 9911, 12, 2166, 29, 4806, 14, 4531, 12, 1475, 63, 875, 29, 403, 304, 272, 2288, 943, 272, 340, 440, 1475, 63, 875, 26, 267, 1475, 63, 875, 275, 11792, 18331, 9, 83, 2818, 354, 9, 83, 359, 2840, 20056, 9, 83, 2189, 2840, 1188, 9, 83, 2, 272, 2512, 275, 2050, 14, 5572, 8, 354, 9, 272, 2512, 14, 13548, 8, 1896, 9, 272, 11155, 275, 2050, 14, 21982, 8, 7218, 9, 272, 11155, 14, 13548, 8, 1896, 9, 272, 9698, 275, 2050, 14, 7772, 8, 908, 63, 875, 9, 272, 11155, 14, 26076, 8, 8911, 9, 272, 2512, 14, 18826, 8, 12853, 9, 272, 943, 275, 2512, 421, 199, 318, 663, 63, 1745, 63, 2921, 8, 354, 12, 2166, 29, 4806, 14, 5287, 12, 1475, 63, 875, 29, 403, 304, 272, 2288, 943, 272, 340, 440, 1475, 63, 875, 26, 267, 1475, 63, 875, 275, 11792, 18331, 9, 83, 2818, 354, 9, 83, 359, 2840, 20056, 9, 83, 2189, 2840, 1188, 9, 83, 2, 272, 2512, 275, 2050, 14, 5572, 8, 354, 9, 272, 2512, 14, 13548, 8, 1896, 9, 272, 11155, 275, 2050, 14, 22482, 342, 272, 11155, 14, 13548, 8, 1896, 9, 272, 9698, 275, 2050, 14, 7772, 8, 908 ]
[ 1898, 334, 67, 9, 8315, 13, 7409, 603, 9414, 598, 26272, 1455, 921, 71, 26272, 14, 1308, 15, 199, 3, 1898, 334, 67, 9, 7129, 13, 8128, 12, 662, 85, 915, 89, 541, 527, 15285, 12, 3277, 14, 199, 3, 1898, 334, 67, 9, 7760, 12, 653, 476, 21335, 15285, 3277, 14, 199, 3, 1898, 334, 67, 9, 6029, 14347, 14, 957, 12, 3277, 14, 503, 2399, 29172, 2335, 14, 199, 3, 1898, 334, 67, 9, 7129, 12, 4475, 12, 3277, 14, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 199, 3, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 199, 3, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 199, 3, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 2153, 13, 199, 3, 28420, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 436, 370, 11291, 199, 3, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 5420, 370, 314, 1699, 13, 199, 3, 28486, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 199, 3, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 199, 3, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 28471, 13, 199, 3, 28463, 12, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 199, 3, 7000, 2334, 17632, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 199, 3, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 199, 3, 1621, 2334, 4141, 14, 199, 3, 199, 504, 6055, 14, 647, 13496, 14, 888, 492, 4094, 12, 24411, 2028, 27727, 199, 504, 6055, 14, 3494, 63, 2302, 492, 31479, 6408, 14014, 12, 3814, 6408, 14014, 199, 646, 6055, 14, 2718, 199, 646, 2197, 199, 646, 747, 199, 646, 4298, 199, 646, 295, 199, 646, 984, 199, 646, 2050, 199, 646, 2050, 14, 888, 199, 199, 504, 6055, 14, 5819, 492, 7097, 199, 504, 6055, 14, 1971, 492, 6378, 14014, 547, 199, 199, 363, 1023, 363, 275, 283, 18, 14, 1703, 14, 16, 7, 199, 3353, 275, 636, 1023, 363, 221, 327, 367, 1771, 1068, 7163, 199, 199, 3, 1455, 921, 13017, 14, 1548, 14, 1308, 15, 5237, 1965, 1257, 199, 2083, 14, 2083, 14, 9866, 8594, 4074, 199, 199, 1899, 7788, 275, 283, 20380, 3149, 83, 2018, 3149, 83, 450, 83, 3149, 83, 7, 450, 334, 272, 636, 1023, 3108, 272, 4298, 14, 1548, 63, 1023, 1062, 272, 4298, 14, 2253, 1062, 272, 4298, 14, 3221, 342, 199, 9, 199, 888, 275, 4094, 342, 199, 199, 3, 12939, 370, 2153, 3306, 18655, 1321, 393, 1958, 5960, 503, 440, 359, 19, 703, 2299, 61, 8365, 3141, 14, 199, 20156, 63, 2339, 63, 907, 275, 295, 14, 2014, 8, 82, 23811, 65, 13, 6353, 13, 58, 16, 13, 25, 1527, 65, 13, 6353, 13, 58, 16, 13, 25, 60, 423, 13, 8194, 17, 12, 3781, 22857, 65, 13, 6353, 13, 58, 16, 13, 25, 61, 9988, 199, 3, 12939, 370, 2153, 3306, 18655, 543, 8212, 10237, 3628, 8088, 2419, 13668, 14, 199, 30947, 63, 12375, 63, 12323, 63, 2339, 63, 6790, 275, 295, 14, 2014, 8, 82, 7, 1988, 63, 65, 13, 90, 16, 13, 25, 8194, 772, 12216, 199, 12795, 2594, 63, 907, 275, 295, 14, 2014, 8, 82, 10120, 48, 28, 1023, 2003, 63, 2302, 63, 495, 31411, 3171, 2574, 519, 11525, 2229, 48, 28, 15043, 9514, 16, 13, 25, 11896, 9988, 199, 4612, 63, 907, 275, 295, 14, 2014, 28353, 48, 28, 1023, 2003, 63, 2302, 63, 495, 31411, 28017, 2229, 48, 28, 1023, 63, 344, 31411, 9, 9988, 199, 21054, 51, 63, 3243, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 283, 14461, 14, 1001, 358, 421, 199, 318, 4205, 63, 4806, 837, 272, 367, 570, 315, 24411, 2028, 27727, 26, 267, 862, 26, 288, 2050, 14, 888, 14, 493, 2028, 8, 736, 14, 515, 14, 12131, 8, 493, 430, 267, 871, 26, 288, 986, 421, 199, 533, 12119, 2461, 8, 4806, 14, 2461, 304, 272, 347, 8689, 8, 277, 12, 2777, 304, 267, 986, 199, 199, 793, 275, 2050, 14, 5572, 360, 10914, 358, 199, 9452, 793, 275, 2050, 14, 5572, 360, 10914, 14, 9452, 358, 199, 793, 14, 18826, 8, 8849, 2461, 1012, 199, 9452, 793, 14, 18826, 8, 8849, 2461, 1012, 199, 826, 63, 4806, 342, 199, 199, 3, 16777, 805, 370, 663, 2050, 370, 282, 6770, 570, 421, 199, 318, 663, 63, 493, 63, 2921, 8, 354, 12, 9911, 12, 2166, 29, 4806, 14, 4531, 12, 1475, 63, 875, 29, 403, 304, 272, 2288, 943, 272, 340, 440, 1475, 63, 875, 26, 267, 1475, 63, 875, 275, 11792, 18331, 9, 83, 2818, 354, 9, 83, 359, 2840, 20056, 9, 83, 2189, 2840, 1188, 9, 83, 2, 272, 2512, 275, 2050, 14, 5572, 8, 354, 9, 272, 2512, 14, 13548, 8, 1896, 9, 272, 11155, 275, 2050, 14, 21982, 8, 7218, 9, 272, 11155, 14, 13548, 8, 1896, 9, 272, 9698, 275, 2050, 14, 7772, 8, 908, 63, 875, 9, 272, 11155, 14, 26076, 8, 8911, 9, 272, 2512, 14, 18826, 8, 12853, 9, 272, 943, 275, 2512, 421, 199, 318, 663, 63, 1745, 63, 2921, 8, 354, 12, 2166, 29, 4806, 14, 5287, 12, 1475, 63, 875, 29, 403, 304, 272, 2288, 943, 272, 340, 440, 1475, 63, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
junhuac/MQUIC
depot_tools/ENV/lib/python2.7/site-packages/google/protobuf/message.py
57
10262
# Protocol Buffers - Google's data interchange format # Copyright 2008 Google Inc. All rights reserved. # http://code.google.com/p/protobuf/ # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # TODO(robinson): We should just make these methods all "pure-virtual" and move # all implementation out, into reflection.py for now. """Contains an abstract base class for protocol messages.""" __author__ = 'robinson@google.com (Will Robinson)' class Error(Exception): pass class DecodeError(Error): pass class EncodeError(Error): pass class Message(object): """Abstract base class for protocol messages. Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below. TODO(robinson): Link to an HTML document here. TODO(robinson): Document that instances of this class will also have an Extensions attribute with __getitem__ and __setitem__. Again, not sure how to best convey this. TODO(robinson): Document that the class must also have a static RegisterExtension(extension_field) method. Not sure how to best express at this point. """ # TODO(robinson): Document these fields and methods. __slots__ = [] DESCRIPTOR = None def __deepcopy__(self, memo=None): clone = type(self)() clone.MergeFrom(self) return clone def __eq__(self, other_msg): """Recursively compares two messages by value and structure.""" raise NotImplementedError def __ne__(self, other_msg): # Can't just say self != other_msg, since that would infinitely recurse. :) return not self == other_msg def __hash__(self): raise TypeError('unhashable object') def __str__(self): """Outputs a human-readable representation of the message.""" raise NotImplementedError def __unicode__(self): """Outputs a human-readable representation of the message.""" raise NotImplementedError def MergeFrom(self, other_msg): """Merges the contents of the specified message into current message. This method merges the contents of the specified message into the current message. Singular fields that are set in the specified message overwrite the corresponding fields in the current message. Repeated fields are appended. Singular sub-messages and groups are recursively merged. Args: other_msg: Message to merge into the current message. """ raise NotImplementedError def CopyFrom(self, other_msg): """Copies the content of the specified message into the current message. The method clears the current message and then merges the specified message using MergeFrom. Args: other_msg: Message to copy into the current one. """ if self is other_msg: return self.Clear() self.MergeFrom(other_msg) def Clear(self): """Clears all data that was set in the message.""" raise NotImplementedError def SetInParent(self): """Mark this as present in the parent. This normally happens automatically when you assign a field of a sub-message, but sometimes you want to make the sub-message present while keeping it empty. If you find yourself using this, you may want to reconsider your design.""" raise NotImplementedError def IsInitialized(self): """Checks if the message is initialized. Returns: The method returns True if the message is initialized (i.e. all of its required fields are set). """ raise NotImplementedError # TODO(robinson): MergeFromString() should probably return None and be # implemented in terms of a helper that returns the # of bytes read. Our # deserialization routines would use the helper when recursively # deserializing, but the end user would almost always just want the no-return # MergeFromString(). def MergeFromString(self, serialized): """Merges serialized protocol buffer data into this message. When we find a field in |serialized| that is already present in this message: - If it's a "repeated" field, we append to the end of our list. - Else, if it's a scalar, we overwrite our field. - Else, (it's a nonrepeated composite), we recursively merge into the existing composite. TODO(robinson): Document handling of unknown fields. Args: serialized: Any object that allows us to call buffer(serialized) to access a string of bytes using the buffer interface. TODO(robinson): When we switch to a helper, this will return None. Returns: The number of bytes read from |serialized|. For non-group messages, this will always be len(serialized), but for messages which are actually groups, this will generally be less than len(serialized), since we must stop when we reach an END_GROUP tag. Note that if we *do* stop because of an END_GROUP tag, the number of bytes returned does not include the bytes for the END_GROUP tag information. """ raise NotImplementedError def ParseFromString(self, serialized): """Parse serialized protocol buffer data into this message. Like MergeFromString(), except we clear the object first and do not return the value that MergeFromString returns. """ self.Clear() self.MergeFromString(serialized) def SerializeToString(self): """Serializes the protocol message to a binary string. Returns: A binary string representation of the message if all of the required fields in the message are set (i.e. the message is initialized). Raises: message.EncodeError if the message isn't initialized. """ raise NotImplementedError def SerializePartialToString(self): """Serializes the protocol message to a binary string. This method is similar to SerializeToString but doesn't check if the message is initialized. Returns: A string representation of the partial message. """ raise NotImplementedError # TODO(robinson): Decide whether we like these better # than auto-generated has_foo() and clear_foo() methods # on the instances themselves. This way is less consistent # with C++, but it makes reflection-type access easier and # reduces the number of magically autogenerated things. # # TODO(robinson): Be sure to document (and test) exactly # which field names are accepted here. Are we case-sensitive? # What do we do with fields that share names with Python keywords # like 'lambda' and 'yield'? # # nnorwitz says: # """ # Typically (in python), an underscore is appended to names that are # keywords. So they would become lambda_ or yield_. # """ def ListFields(self): """Returns a list of (FieldDescriptor, value) tuples for all fields in the message which are not empty. A singular field is non-empty if HasField() would return true, and a repeated field is non-empty if it contains at least one element. The fields are ordered by field number""" raise NotImplementedError def HasField(self, field_name): """Checks if a certain field is set for the message. Note if the field_name is not defined in the message descriptor, ValueError will be raised.""" raise NotImplementedError def ClearField(self, field_name): raise NotImplementedError def HasExtension(self, extension_handle): raise NotImplementedError def ClearExtension(self, extension_handle): raise NotImplementedError def ByteSize(self): """Returns the serialized size of this message. Recursively calls ByteSize() on all contained messages. """ raise NotImplementedError def _SetListener(self, message_listener): """Internal method used by the protocol message implementation. Clients should not call this directly. Sets a listener that this message will call on certain state transitions. The purpose of this method is to register back-edges from children to parents at runtime, for the purpose of setting "has" bits and byte-size-dirty bits in the parent and ancestor objects whenever a child or descendant object is modified. If the client wants to disconnect this Message from the object tree, she explicitly sets callback to None. If message_listener is None, unregisters any existing listener. Otherwise, message_listener must implement the MessageListener interface in internal/message_listener.py, and we discard any listener registered via a previous _SetListener() call. """ raise NotImplementedError def __getstate__(self): """Support the pickle protocol.""" return dict(serialized=self.SerializePartialToString()) def __setstate__(self, state): """Support the pickle protocol.""" self.__init__() self.ParseFromString(state['serialized'])
mit
[ 3, 11557, 699, 3043, 1192, 446, 4475, 1159, 666, 1640, 1461, 1475, 199, 3, 1898, 9079, 4475, 3277, 14, 221, 2900, 4481, 4644, 14, 199, 3, 1455, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 7204, 15, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 3, 3254, 8, 28191, 834, 304, 2136, 1077, 2951, 1852, 3520, 3102, 1006, 298, 5115, 13, 2065, 2, 436, 4057, 199, 3, 1006, 4514, 734, 12, 1901, 25572, 14, 647, 367, 3063, 14, 421, 199, 624, 6906, 376, 9006, 1300, 1021, 367, 4113, 3788, 1041, 199, 199, 363, 2502, 363, 275, 283, 28191, 834, 32, 3098, 14, 957, 334, 20326, 6848, 1393, 834, 3171, 421, 199, 533, 4520, 8, 1726, 304, 986, 199, 533, 22462, 547, 8, 547, 304, 986, 199, 533, 19244, 547, 8, 547, 304, 986, 421, 199, 533, 6430, 8, 785, 304, 819, 408, 8458, 1300, 1021, 367, 4113, 3788, 14, 819, 11557, 1245, 3992, 787, 18871, 3544, 4046, 701, 314, 4113, 523, 6365, 14, 221, 5723, 4046, 2943, 5516, 6430, 436, 5669, 314, 3102, 523, 9164, 5084, 14, 819, 3254, 8, 28191, 834, 304, 10967, 370, 376, 4163, 2213, 2348, 14, 819, 3254, 8, 28191, 834, 304, 7543, 626, 4454, 402, 642, 1021, 911, 2597, 523, 1172, 376, 11524, 1356, 2225, 543, 636, 6095, 363, 436, 636, 8617, 4343, 523, 437, 13020, 12, 440, 3238, 4212, 370, 5526, 406, 7158, 642, 14, 819, 3254, 8, 28191, 834, 304, 7543, 626, 314, 1021, 1471, 2597, 1172, 282, 2955, 272, 11828, 6382, 8, 3435, 63, 698, 9, 1083, 14, 272, 2832, 3238, 4212, 370, 5526, 4056, 737, 642, 2376, 14, 523, 408, 819, 327, 3254, 8, 28191, 834, 304, 7543, 3520, 1504, 436, 3102, 14, 819, 636, 7257, 363, 275, 942, 819, 21034, 275, 488, 819, 347, 636, 8293, 721, 277, 12, 11955, 29, 403, 304, 272, 7289, 275, 730, 8, 277, 16315, 272, 7289, 14, 11359, 2532, 8, 277, 9, 272, 372, 7289, 819, 347, 636, 4077, 721, 277, 12, 1163, 63, 1328, 304, 272, 408, 14244, 9840, 30827, 2877, 3788, 701, 574, 436, 5523, 1041, 272, 746, 4279, 819, 347, 636, 685, 721, 277, 12, 1163, 63, 1328, 304, 272, 327, 6855, 1133, 2951, 14722, 291, 1137, 1163, 63, 1328, 12, 3967, 626, 3955, 15258, 590, 18011, 14, 32428, 272, 372, 440, 291, 508, 1163, 63, 1328, 819, 347, 636, 2227, 721, 277, 304, 272, 746, 3146, 360, 324, 24596, 909, 358, 819, 347, 636, 495, 721, 277, 304, 272, 408, 18669, 282, 11779, 13, 11875, 6025, 402, 314, 1245, 1041, 272, 746, 4279, 819, 347, 636, 2975, 721, 277, 304, 272, 408, 18669, 282, 11779, 13, 11875, 6025, 402, 314, 1245, 1041, 272, 746, 4279, 819, 347, 14076, 2532, 8, 277, 12, 1163, 63, 1328, 304, 272, 408, 16797, 3389, 314, 4072, 402, 314, 2013, 1245, 1901, 1453, 1245, 14, 339, 961, 1083, 32716, 314, 4072, 402, 314, 2013, 1245, 1901, 314, 1453, 272, 1245, 14, 428, 14257, 1504, 626, 787, 663, 315, 314, 2013, 1245, 8970, 272, 314, 5226, 1504, 315, 314, 1453, 1245, 14, 21973, 972, 1504, 787, 272, 11544, 14, 428, 14257, 1007, 13, 3431, 436, 4652, 787, 15035, 9545, 14, 339, 3033, 26, 489, 1163, 63, 1328, 26, 6430, 370, 5389, 1901, 314, 1453, 1245, 14, 272, 408, 272, 746, 4279, 819, 347, 11247, 2532, 8, 277, 12, 1163, 63, 1328, 304, 272, 408, 29042, 314, 1564, 402, 314, 2013, 1245, 1901, 314, 1453, 1245, 14, 339, 710, 1083, 5436, 83, 314, 1453, 1245, 436, 2066, 32716, 314, 2013, 272, 1245, 1808, 14076, 2532, 14, 339, 3033, 26, 489, 1163, 63, 1328, 26, 6430, 370, 1331, 1901, 314, 1453, 1373, 14, 272, 408, 272, 340, 291, 365, 1163, 63, 1328, 26, 489, 372, 272, 291, 14, 9721, 342, 272, 291, 14, 11359, 2532, 8, 1848, 63, 1328, 9, 819, 347, 14836, 8, 277, 304, 272, 408, 9721, 83, 1006, 666, 626, 1990, 663, 315, 314, 1245, 1041, 272, 746, 4279, 819, 347, 2494, 607, 6652, 8, 277, 304, 272, 408, 6470, 642, 465, 3451, 315, 314, 1676, 14, 339, 961, 12252, 10986, 5847, 1380, 1265, 5090, 282, 901, 402, 282, 272, 1007, 13, 1188, 12, 1325, 15026, 1265, 2934, 370, 1852, 314, 1007, 13, 1188, 272, 3451, 1830, 22181, 652, 2701, 14, 221, 982, 1265, 2342, 28225, 1808, 642, 12, 272, 1265, 1443, 2934, 370, 24711, 16994, 2195 ]
[ 11557, 699, 3043, 1192, 446, 4475, 1159, 666, 1640, 1461, 1475, 199, 3, 1898, 9079, 4475, 3277, 14, 221, 2900, 4481, 4644, 14, 199, 3, 1455, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 7204, 15, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 3, 3254, 8, 28191, 834, 304, 2136, 1077, 2951, 1852, 3520, 3102, 1006, 298, 5115, 13, 2065, 2, 436, 4057, 199, 3, 1006, 4514, 734, 12, 1901, 25572, 14, 647, 367, 3063, 14, 421, 199, 624, 6906, 376, 9006, 1300, 1021, 367, 4113, 3788, 1041, 199, 199, 363, 2502, 363, 275, 283, 28191, 834, 32, 3098, 14, 957, 334, 20326, 6848, 1393, 834, 3171, 421, 199, 533, 4520, 8, 1726, 304, 986, 199, 533, 22462, 547, 8, 547, 304, 986, 199, 533, 19244, 547, 8, 547, 304, 986, 421, 199, 533, 6430, 8, 785, 304, 819, 408, 8458, 1300, 1021, 367, 4113, 3788, 14, 819, 11557, 1245, 3992, 787, 18871, 3544, 4046, 701, 314, 4113, 523, 6365, 14, 221, 5723, 4046, 2943, 5516, 6430, 436, 5669, 314, 3102, 523, 9164, 5084, 14, 819, 3254, 8, 28191, 834, 304, 10967, 370, 376, 4163, 2213, 2348, 14, 819, 3254, 8, 28191, 834, 304, 7543, 626, 4454, 402, 642, 1021, 911, 2597, 523, 1172, 376, 11524, 1356, 2225, 543, 636, 6095, 363, 436, 636, 8617, 4343, 523, 437, 13020, 12, 440, 3238, 4212, 370, 5526, 406, 7158, 642, 14, 819, 3254, 8, 28191, 834, 304, 7543, 626, 314, 1021, 1471, 2597, 1172, 282, 2955, 272, 11828, 6382, 8, 3435, 63, 698, 9, 1083, 14, 272, 2832, 3238, 4212, 370, 5526, 4056, 737, 642, 2376, 14, 523, 408, 819, 327, 3254, 8, 28191, 834, 304, 7543, 3520, 1504, 436, 3102, 14, 819, 636, 7257, 363, 275, 942, 819, 21034, 275, 488, 819, 347, 636, 8293, 721, 277, 12, 11955, 29, 403, 304, 272, 7289, 275, 730, 8, 277, 16315, 272, 7289, 14, 11359, 2532, 8, 277, 9, 272, 372, 7289, 819, 347, 636, 4077, 721, 277, 12, 1163, 63, 1328, 304, 272, 408, 14244, 9840, 30827, 2877, 3788, 701, 574, 436, 5523, 1041, 272, 746, 4279, 819, 347, 636, 685, 721, 277, 12, 1163, 63, 1328, 304, 272, 327, 6855, 1133, 2951, 14722, 291, 1137, 1163, 63, 1328, 12, 3967, 626, 3955, 15258, 590, 18011, 14, 32428, 272, 372, 440, 291, 508, 1163, 63, 1328, 819, 347, 636, 2227, 721, 277, 304, 272, 746, 3146, 360, 324, 24596, 909, 358, 819, 347, 636, 495, 721, 277, 304, 272, 408, 18669, 282, 11779, 13, 11875, 6025, 402, 314, 1245, 1041, 272, 746, 4279, 819, 347, 636, 2975, 721, 277, 304, 272, 408, 18669, 282, 11779, 13, 11875, 6025, 402, 314, 1245, 1041, 272, 746, 4279, 819, 347, 14076, 2532, 8, 277, 12, 1163, 63, 1328, 304, 272, 408, 16797, 3389, 314, 4072, 402, 314, 2013, 1245, 1901, 1453, 1245, 14, 339, 961, 1083, 32716, 314, 4072, 402, 314, 2013, 1245, 1901, 314, 1453, 272, 1245, 14, 428, 14257, 1504, 626, 787, 663, 315, 314, 2013, 1245, 8970, 272, 314, 5226, 1504, 315, 314, 1453, 1245, 14, 21973, 972, 1504, 787, 272, 11544, 14, 428, 14257, 1007, 13, 3431, 436, 4652, 787, 15035, 9545, 14, 339, 3033, 26, 489, 1163, 63, 1328, 26, 6430, 370, 5389, 1901, 314, 1453, 1245, 14, 272, 408, 272, 746, 4279, 819, 347, 11247, 2532, 8, 277, 12, 1163, 63, 1328, 304, 272, 408, 29042, 314, 1564, 402, 314, 2013, 1245, 1901, 314, 1453, 1245, 14, 339, 710, 1083, 5436, 83, 314, 1453, 1245, 436, 2066, 32716, 314, 2013, 272, 1245, 1808, 14076, 2532, 14, 339, 3033, 26, 489, 1163, 63, 1328, 26, 6430, 370, 1331, 1901, 314, 1453, 1373, 14, 272, 408, 272, 340, 291, 365, 1163, 63, 1328, 26, 489, 372, 272, 291, 14, 9721, 342, 272, 291, 14, 11359, 2532, 8, 1848, 63, 1328, 9, 819, 347, 14836, 8, 277, 304, 272, 408, 9721, 83, 1006, 666, 626, 1990, 663, 315, 314, 1245, 1041, 272, 746, 4279, 819, 347, 2494, 607, 6652, 8, 277, 304, 272, 408, 6470, 642, 465, 3451, 315, 314, 1676, 14, 339, 961, 12252, 10986, 5847, 1380, 1265, 5090, 282, 901, 402, 282, 272, 1007, 13, 1188, 12, 1325, 15026, 1265, 2934, 370, 1852, 314, 1007, 13, 1188, 272, 3451, 1830, 22181, 652, 2701, 14, 221, 982, 1265, 2342, 28225, 1808, 642, 12, 272, 1265, 1443, 2934, 370, 24711, 16994, 2195, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
kreisl/AliPhysics
PWGJE/EMCALJetTasks/Tracks/analysis/__init__.py
369
1063
#************************************************************************** #* Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. * #* * #* Author: The ALICE Off-line Project. * #* Contributors are mentioned in the code where appropriate. * #* * #* Permission to use, copy, modify and distribute this software and its * #* documentation strictly for non-commercial purposes is hereby granted * #* without fee, provided that the above copyright notice appears in all * #* copies and that both the copyright notice and this permission notice * #* appear in the supporting documentation. The authors make no claims * #* about the suitability of this software for any purpose. It is * #* provided "as is" without express or implied warranty. * #**************************************************************************
bsd-3-clause
[ 3, 14355, 538, 199, 15002, 1898, 8, 67, 9, 19960, 13, 7280, 12, 437, 2507, 37, 23997, 737, 24354, 12, 2900, 4481, 4644, 14, 627, 199, 15002, 6208, 263, 627, 199, 15002, 6529, 26, 710, 437, 2507, 37, 28856, 13, 604, 7290, 14, 27503, 627, 199, 15002, 23212, 787, 26239, 315, 314, 1233, 2382, 5827, 14, 4519, 627, 199, 15002, 6208, 263, 627, 199, 15002, 8779, 370, 675, 12, 1331, 12, 2811, 436, 11207, 642, 2032, 436, 2399, 257, 627, 199, 15002, 3794, 22699, 367, 2222, 13, 957, 23012, 12901, 365, 11882, 10009, 257, 627, 199, 15002, 1928, 14751, 12, 2741, 626, 314, 3432, 4248, 4245, 11337, 315, 1006, 257, 627, 199, 15002, 6866, 436, 626, 3865, 314, 4248, 4245, 436, 642, 4983, 4245, 257, 627, 199, 15002, 7468, 315, 314, 21038, 3794, 14, 710, 11462, 1852, 949, 6108, 11171, 258, 627, 199, 15002, 3595, 314, 308, 4993, 3616, 402, 642, 2032, 367, 1263, 12016, 14, 2779, 365, 3515, 627, 199, 15002, 2741, 298, 305, 365, 2, 1928, 4056, 503, 2478, 3750, 14, 8295, 627, 199, 3, 14355, 538, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 14355, 538, 199, 15002, 1898, 8, 67, 9, 19960, 13, 7280, 12, 437, 2507, 37, 23997, 737, 24354, 12, 2900, 4481, 4644, 14, 627, 199, 15002, 6208, 263, 627, 199, 15002, 6529, 26, 710, 437, 2507, 37, 28856, 13, 604, 7290, 14, 27503, 627, 199, 15002, 23212, 787, 26239, 315, 314, 1233, 2382, 5827, 14, 4519, 627, 199, 15002, 6208, 263, 627, 199, 15002, 8779, 370, 675, 12, 1331, 12, 2811, 436, 11207, 642, 2032, 436, 2399, 257, 627, 199, 15002, 3794, 22699, 367, 2222, 13, 957, 23012, 12901, 365, 11882, 10009, 257, 627, 199, 15002, 1928, 14751, 12, 2741, 626, 314, 3432, 4248, 4245, 11337, 315, 1006, 257, 627, 199, 15002, 6866, 436, 626, 3865, 314, 4248, 4245, 436, 642, 4983, 4245, 257, 627, 199, 15002, 7468, 315, 314, 21038, 3794, 14, 710, 11462, 1852, 949, 6108, 11171, 258, 627, 199, 15002, 3595, 314, 308, 4993, 3616, 402, 642, 2032, 367, 1263, 12016, 14, 2779, 365, 3515, 627, 199, 15002, 2741, 298, 305, 365, 2, 1928, 4056, 503, 2478, 3750, 14, 8295, 627, 199, 3, 14355, 538, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
stevekuznetsov/ansible
test/units/modules/network/junos/test_junos_command.py
15
4221
# (c) 2016 Red Hat Inc. # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) __metaclass__ = type import json from ansible.compat.tests.mock import patch from .junos_module import TestJunosModule, load_fixture, set_module_args from ansible.modules.network.junos import junos_command class TestJunosCommandModule(TestJunosModule): module = junos_command def setUp(self): self.mock_run_commands = patch('ansible.modules.network.junos.junos_command.run_commands') self.run_commands = self.mock_run_commands.start() def tearDown(self): self.mock_run_commands.stop() def load_fixtures(self, commands=None): def load_from_file(*args, **kwargs): module, commands = args output = list() for item in commands: try: obj = json.loads(item['command']) command = obj['command'] except ValueError: command = item['command'] filename = 'junos_command_%s.txt' % str(command).replace(' ', '_') output.append(load_fixture(filename)) return output self.run_commands.side_effect = load_from_file def test_junos_command_format_text(self): set_module_args(dict(commands=['show version'], display='text')) result = self.execute_module() self.assertEqual(len(result['stdout']), 1) self.assertTrue(result['stdout'][0].startswith('Hostname')) def test_junos_command_multiple(self): set_module_args(dict(commands=['show version', 'show version'], display='text')) result = self.execute_module() self.assertEqual(len(result['stdout']), 2) self.assertTrue(result['stdout'][0].startswith('Hostname')) def test_junos_command_wait_for(self): wait_for = 'result[0] contains "Hostname"' set_module_args(dict(commands=['show version'], wait_for=wait_for, display='text')) self.execute_module() def test_junos_command_wait_for_fails(self): wait_for = 'result[0] contains "test string"' set_module_args(dict(commands=['show version'], wait_for=wait_for, display='text')) self.execute_module(failed=True) self.assertEqual(self.run_commands.call_count, 10) def test_junos_command_retries(self): wait_for = 'result[0] contains "test string"' set_module_args(dict(commands=['show version'], wait_for=wait_for, retries=2, display='text')) self.execute_module(failed=True) self.assertEqual(self.run_commands.call_count, 2) def test_junos_command_match_any(self): wait_for = ['result[0] contains "Hostname"', 'result[0] contains "test string"'] set_module_args(dict(commands=['show version'], wait_for=wait_for, match='any', display='text')) self.execute_module() def test_junos_command_match_all(self): wait_for = ['result[0] contains "Hostname"', 'result[0] contains "Model"'] set_module_args(dict(commands=['show version'], wait_for=wait_for, match='all', display='text')) self.execute_module() def test_junos_command_match_all_failure(self): wait_for = ['result[0] contains "Hostname"', 'result[0] contains "test string"'] commands = ['show version', 'show version'] set_module_args(dict(commands=commands, wait_for=wait_for, match='all', display='text')) self.execute_module(failed=True)
gpl-3.0
[ 3, 334, 67, 9, 7800, 9572, 13002, 3277, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 646, 2022, 199, 199, 504, 3242, 14, 5819, 14, 2219, 14, 1805, 492, 3371, 199, 504, 1275, 31959, 63, 578, 492, 1379, 42, 21003, 2377, 12, 2248, 63, 5997, 12, 663, 63, 578, 63, 589, 199, 199, 504, 3242, 14, 3112, 14, 1200, 14, 31959, 492, 1335, 21003, 63, 1531, 421, 199, 533, 1379, 42, 21003, 3110, 2377, 8, 774, 42, 21003, 2377, 304, 339, 859, 275, 1335, 21003, 63, 1531, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 1805, 63, 1065, 63, 4405, 275, 3371, 360, 4853, 14, 3112, 14, 1200, 14, 31959, 14, 31959, 63, 1531, 14, 1065, 63, 4405, 358, 267, 291, 14, 1065, 63, 4405, 275, 291, 14, 1805, 63, 1065, 63, 4405, 14, 928, 342, 339, 347, 6766, 8, 277, 304, 267, 291, 14, 1805, 63, 1065, 63, 4405, 14, 2379, 342, 339, 347, 2248, 63, 8769, 8, 277, 12, 3718, 29, 403, 304, 398, 347, 2248, 63, 504, 63, 493, 2031, 589, 12, 1011, 958, 304, 288, 859, 12, 3718, 275, 1249, 288, 1072, 275, 769, 342, 953, 367, 1242, 315, 3718, 26, 355, 862, 26, 490, 1559, 275, 2022, 14, 3640, 8, 1053, 459, 1531, 1105, 490, 1414, 275, 1559, 459, 1531, 418, 355, 871, 1722, 26, 490, 1414, 275, 1242, 459, 1531, 418, 355, 1788, 275, 283, 31959, 63, 1531, 4970, 83, 14, 2424, 7, 450, 620, 8, 1531, 680, 1814, 360, 1656, 18962, 355, 1072, 14, 740, 8, 912, 63, 5997, 8, 1501, 430, 288, 372, 1072, 398, 291, 14, 1065, 63, 4405, 14, 2441, 63, 5881, 275, 2248, 63, 504, 63, 493, 339, 347, 511, 63, 31959, 63, 1531, 63, 908, 63, 505, 8, 277, 304, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 2929, 534, 505, 1333, 267, 754, 275, 291, 14, 2526, 63, 578, 342, 267, 291, 14, 629, 8, 552, 8, 1099, 459, 2703, 3815, 413, 9, 267, 291, 14, 1815, 8, 1099, 459, 2703, 3488, 16, 1055, 2460, 360, 25680, 1333, 339, 347, 511, 63, 31959, 63, 1531, 63, 6048, 8, 277, 304, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 297, 283, 2384, 1015, 995, 2929, 534, 505, 1333, 267, 754, 275, 291, 14, 2526, 63, 578, 342, 267, 291, 14, 629, 8, 552, 8, 1099, 459, 2703, 3815, 499, 9, 267, 291, 14, 1815, 8, 1099, 459, 2703, 3488, 16, 1055, 2460, 360, 25680, 1333, 339, 347, 511, 63, 31959, 63, 1531, 63, 2573, 63, 509, 8, 277, 304, 267, 3618, 63, 509, 275, 283, 1099, 59, 16, 61, 3509, 298, 25680, 4507, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 3618, 63, 509, 29, 2573, 63, 509, 12, 2929, 534, 505, 1333, 267, 291, 14, 2526, 63, 578, 342, 339, 347, 511, 63, 31959, 63, 1531, 63, 2573, 63, 509, 63, 15762, 8, 277, 304, 267, 3618, 63, 509, 275, 283, 1099, 59, 16, 61, 3509, 298, 396, 1059, 4507, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 3618, 63, 509, 29, 2573, 63, 509, 12, 2929, 534, 505, 1333, 267, 291, 14, 2526, 63, 578, 8, 4892, 29, 549, 9, 267, 291, 14, 629, 8, 277, 14, 1065, 63, 4405, 14, 1250, 63, 835, 12, 1616, 9, 339, 347, 511, 63, 31959, 63, 1531, 63, 10937, 8, 277, 304, 267, 3618, 63, 509, 275, 283, 1099, 59, 16, 61, 3509, 298, 396, 1059, 4507, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 3618, 63, 509, 29, 2573, 63, 509, 12, 10086, 29, 18, 12, 2929, 534, 505, 1333, 267, 291, 14, 2526, 63, 578, 8, 4892, 29, 549, 9, 267, 291, 14, 629, 8, 277, 14, 1065, 63, 4405, 14, 1250, 63, 835, 12, 499, 9, 339, 347, 511, 63, 31959, 63, 1531, 63, 1431, 63, 1629, 8, 277, 304, 267, 3618, 63, 509, 275, 788, 1099, 59, 16, 61, 3509, 298, 25680, 6949, 490, 283, 1099, 59, 16, 61, 3509, 298, 396, 1059, 2, 418, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 3618, 63, 509, 29, 2573, 63, 509, 12, 1336, 534, 1629, 297, 2929, 534, 505, 1333, 267, 291, 14, 2526, 63, 578, 342, 339, 347, 511, 63, 31959, 63, 1531, 63, 1431, 63, 452, 8, 277, 304, 267, 3618, 63, 509, 275, 788, 1099, 59, 16, 61, 3509, 298, 25680, 6949, 490, 283, 1099, 59, 16, 61, 3509, 298, 1685, 2, 418, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 3618, 63, 509, 29, 2573, 63, 509, 12, 1336, 534, 452, 297, 2929, 534, 505, 1333, 267, 291, 14, 2526, 63, 578, 342, 339, 347, 511, 63, 31959, 63, 1531, 63, 1431, 63, 452, 63, 5328, 8, 277, 304, 267, 3618, 63, 509, 275, 788, 1099, 59, 16, 61, 3509, 298, 25680, 6949, 490, 283, 1099, 59, 16 ]
[ 334, 67, 9, 7800, 9572, 13002, 3277, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 646, 2022, 199, 199, 504, 3242, 14, 5819, 14, 2219, 14, 1805, 492, 3371, 199, 504, 1275, 31959, 63, 578, 492, 1379, 42, 21003, 2377, 12, 2248, 63, 5997, 12, 663, 63, 578, 63, 589, 199, 199, 504, 3242, 14, 3112, 14, 1200, 14, 31959, 492, 1335, 21003, 63, 1531, 421, 199, 533, 1379, 42, 21003, 3110, 2377, 8, 774, 42, 21003, 2377, 304, 339, 859, 275, 1335, 21003, 63, 1531, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 1805, 63, 1065, 63, 4405, 275, 3371, 360, 4853, 14, 3112, 14, 1200, 14, 31959, 14, 31959, 63, 1531, 14, 1065, 63, 4405, 358, 267, 291, 14, 1065, 63, 4405, 275, 291, 14, 1805, 63, 1065, 63, 4405, 14, 928, 342, 339, 347, 6766, 8, 277, 304, 267, 291, 14, 1805, 63, 1065, 63, 4405, 14, 2379, 342, 339, 347, 2248, 63, 8769, 8, 277, 12, 3718, 29, 403, 304, 398, 347, 2248, 63, 504, 63, 493, 2031, 589, 12, 1011, 958, 304, 288, 859, 12, 3718, 275, 1249, 288, 1072, 275, 769, 342, 953, 367, 1242, 315, 3718, 26, 355, 862, 26, 490, 1559, 275, 2022, 14, 3640, 8, 1053, 459, 1531, 1105, 490, 1414, 275, 1559, 459, 1531, 418, 355, 871, 1722, 26, 490, 1414, 275, 1242, 459, 1531, 418, 355, 1788, 275, 283, 31959, 63, 1531, 4970, 83, 14, 2424, 7, 450, 620, 8, 1531, 680, 1814, 360, 1656, 18962, 355, 1072, 14, 740, 8, 912, 63, 5997, 8, 1501, 430, 288, 372, 1072, 398, 291, 14, 1065, 63, 4405, 14, 2441, 63, 5881, 275, 2248, 63, 504, 63, 493, 339, 347, 511, 63, 31959, 63, 1531, 63, 908, 63, 505, 8, 277, 304, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 2929, 534, 505, 1333, 267, 754, 275, 291, 14, 2526, 63, 578, 342, 267, 291, 14, 629, 8, 552, 8, 1099, 459, 2703, 3815, 413, 9, 267, 291, 14, 1815, 8, 1099, 459, 2703, 3488, 16, 1055, 2460, 360, 25680, 1333, 339, 347, 511, 63, 31959, 63, 1531, 63, 6048, 8, 277, 304, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 297, 283, 2384, 1015, 995, 2929, 534, 505, 1333, 267, 754, 275, 291, 14, 2526, 63, 578, 342, 267, 291, 14, 629, 8, 552, 8, 1099, 459, 2703, 3815, 499, 9, 267, 291, 14, 1815, 8, 1099, 459, 2703, 3488, 16, 1055, 2460, 360, 25680, 1333, 339, 347, 511, 63, 31959, 63, 1531, 63, 2573, 63, 509, 8, 277, 304, 267, 3618, 63, 509, 275, 283, 1099, 59, 16, 61, 3509, 298, 25680, 4507, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 3618, 63, 509, 29, 2573, 63, 509, 12, 2929, 534, 505, 1333, 267, 291, 14, 2526, 63, 578, 342, 339, 347, 511, 63, 31959, 63, 1531, 63, 2573, 63, 509, 63, 15762, 8, 277, 304, 267, 3618, 63, 509, 275, 283, 1099, 59, 16, 61, 3509, 298, 396, 1059, 4507, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 3618, 63, 509, 29, 2573, 63, 509, 12, 2929, 534, 505, 1333, 267, 291, 14, 2526, 63, 578, 8, 4892, 29, 549, 9, 267, 291, 14, 629, 8, 277, 14, 1065, 63, 4405, 14, 1250, 63, 835, 12, 1616, 9, 339, 347, 511, 63, 31959, 63, 1531, 63, 10937, 8, 277, 304, 267, 3618, 63, 509, 275, 283, 1099, 59, 16, 61, 3509, 298, 396, 1059, 4507, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 3618, 63, 509, 29, 2573, 63, 509, 12, 10086, 29, 18, 12, 2929, 534, 505, 1333, 267, 291, 14, 2526, 63, 578, 8, 4892, 29, 549, 9, 267, 291, 14, 629, 8, 277, 14, 1065, 63, 4405, 14, 1250, 63, 835, 12, 499, 9, 339, 347, 511, 63, 31959, 63, 1531, 63, 1431, 63, 1629, 8, 277, 304, 267, 3618, 63, 509, 275, 788, 1099, 59, 16, 61, 3509, 298, 25680, 6949, 490, 283, 1099, 59, 16, 61, 3509, 298, 396, 1059, 2, 418, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 3618, 63, 509, 29, 2573, 63, 509, 12, 1336, 534, 1629, 297, 2929, 534, 505, 1333, 267, 291, 14, 2526, 63, 578, 342, 339, 347, 511, 63, 31959, 63, 1531, 63, 1431, 63, 452, 8, 277, 304, 267, 3618, 63, 509, 275, 788, 1099, 59, 16, 61, 3509, 298, 25680, 6949, 490, 283, 1099, 59, 16, 61, 3509, 298, 1685, 2, 418, 267, 663, 63, 578, 63, 589, 8, 807, 8, 4405, 2968, 2384, 1015, 995, 3618, 63, 509, 29, 2573, 63, 509, 12, 1336, 534, 452, 297, 2929, 534, 505, 1333, 267, 291, 14, 2526, 63, 578, 342, 339, 347, 511, 63, 31959, 63, 1531, 63, 1431, 63, 452, 63, 5328, 8, 277, 304, 267, 3618, 63, 509, 275, 788, 1099, 59, 16, 61, 3509, 298, 25680, 6949, 490, 283, 1099, 59, 16, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
hujiajie/chromium-crosswalk
tools/telemetry/third_party/webpagereplay/httpproxy_test.py
19
6296
#!/usr/bin/env python # Copyright 2015 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import httparchive import httplib import httpproxy import threading import unittest import util class MockCustomResponseHandler(object): def __init__(self, response): """ Args: response: An instance of ArchivedHttpResponse that is returned for each request. """ self._response = response def handle(self, request): del request return self._response class MockHttpArchiveFetch(object): def __init__(self): self.is_record_mode = False def __call__(self, request): return None class MockHttpArchiveHandler(httpproxy.HttpArchiveHandler): def handle_one_request(self): httpproxy.HttpArchiveHandler.handle_one_request(self) HttpProxyTest.HANDLED_REQUEST_COUNT += 1 class MockRules(object): def Find(self, unused_rule_type_name): # pylint: disable=unused-argument return lambda unused_request, unused_response: None class HttpProxyTest(unittest.TestCase): def setUp(self): self.has_proxy_server_bound_port = False self.has_proxy_server_started = False def set_up_proxy_server(self, response): """ Args: response: An instance of ArchivedHttpResponse that is returned for each request. """ HttpProxyTest.HANDLED_REQUEST_COUNT = 0 self.host = 'localhost' self.port = 8889 custom_handlers = MockCustomResponseHandler(response) rules = MockRules() http_archive_fetch = MockHttpArchiveFetch() self.proxy_server = httpproxy.HttpProxyServer( http_archive_fetch, custom_handlers, rules, host=self.host, port=self.port) self.proxy_server.RequestHandlerClass = MockHttpArchiveHandler self.has_proxy_server_bound_port = True def tearDown(self): if self.has_proxy_server_started: self.proxy_server.shutdown() if self.has_proxy_server_bound_port: self.proxy_server.server_close() def serve_requests_forever(self): self.has_proxy_server_started = True self.proxy_server.serve_forever(poll_interval=0.01) # Tests that handle_one_request does not leak threads, and does not try to # re-handle connections that are finished. def test_handle_one_request_closes_connection(self): # By default, BaseHTTPServer.py treats all HTTP 1.1 requests as keep-alive. # Intentionally use HTTP 1.0 to prevent this behavior. response = httparchive.ArchivedHttpResponse( version=10, status=200, reason="OK", headers=[], response_data=["bat1"]) self.set_up_proxy_server(response) t = threading.Thread( target=HttpProxyTest.serve_requests_forever, args=(self,)) t.start() initial_thread_count = threading.activeCount() # Make a bunch of requests. request_count = 10 for _ in range(request_count): conn = httplib.HTTPConnection('localhost', 8889, timeout=10) conn.request("GET", "/index.html") res = conn.getresponse().read() self.assertEqual(res, "bat1") conn.close() # Check to make sure that there is no leaked thread. util.WaitFor(lambda: threading.activeCount() == initial_thread_count, 2) self.assertEqual(request_count, HttpProxyTest.HANDLED_REQUEST_COUNT) # Tests that keep-alive header works. def test_keep_alive_header(self): response = httparchive.ArchivedHttpResponse( version=11, status=200, reason="OK", headers=[("Connection", "keep-alive")], response_data=["bat1"]) self.set_up_proxy_server(response) t = threading.Thread( target=HttpProxyTest.serve_requests_forever, args=(self,)) t.start() initial_thread_count = threading.activeCount() # Make a bunch of requests. request_count = 10 connections = [] for _ in range(request_count): conn = httplib.HTTPConnection('localhost', 8889, timeout=10) conn.request("GET", "/index.html", headers={"Connection": "keep-alive"}) res = conn.getresponse().read() self.assertEqual(res, "bat1") connections.append(conn) # Repeat the same requests. for conn in connections: conn.request("GET", "/index.html", headers={"Connection": "keep-alive"}) res = conn.getresponse().read() self.assertEqual(res, "bat1") # Check that the right number of requests have been handled. self.assertEqual(2 * request_count, HttpProxyTest.HANDLED_REQUEST_COUNT) # Check to make sure that exactly "request_count" new threads are active. self.assertEqual( threading.activeCount(), initial_thread_count + request_count) for conn in connections: conn.close() util.WaitFor(lambda: threading.activeCount() == initial_thread_count, 1) # Test that opening 400 simultaneous connections does not cause httpproxy to # hit a process fd limit. The default limit is 256 fds. def test_max_fd(self): response = httparchive.ArchivedHttpResponse( version=11, status=200, reason="OK", headers=[("Connection", "keep-alive")], response_data=["bat1"]) self.set_up_proxy_server(response) t = threading.Thread( target=HttpProxyTest.serve_requests_forever, args=(self,)) t.start() # Make a bunch of requests. request_count = 400 connections = [] for _ in range(request_count): conn = httplib.HTTPConnection('localhost', 8889, timeout=10) conn.request("GET", "/index.html", headers={"Connection": "keep-alive"}) res = conn.getresponse().read() self.assertEqual(res, "bat1") connections.append(conn) # Check that the right number of requests have been handled. self.assertEqual(request_count, HttpProxyTest.HANDLED_REQUEST_COUNT) for conn in connections: conn.close() if __name__ == '__main__': unittest.main()
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 6900, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 421, 199, 646, 22768, 462, 335, 1912, 199, 646, 8809, 199, 646, 1455, 3280, 199, 646, 5796, 199, 646, 2882, 199, 646, 4884, 421, 199, 533, 4420, 7223, 2364, 2461, 8, 785, 304, 523, 347, 636, 826, 721, 277, 12, 1177, 304, 272, 408, 272, 3033, 26, 489, 1177, 26, 1626, 1256, 402, 19521, 12905, 16287, 626, 365, 2138, 367, 1924, 489, 1056, 14, 272, 408, 272, 291, 423, 1310, 275, 1177, 819, 347, 2429, 8, 277, 12, 1056, 304, 272, 2150, 1056, 272, 372, 291, 423, 1310, 421, 199, 533, 4420, 5779, 13042, 11135, 8, 785, 304, 523, 347, 636, 826, 721, 277, 304, 272, 291, 14, 374, 63, 3059, 63, 632, 275, 756, 819, 347, 636, 1250, 721, 277, 12, 1056, 304, 272, 372, 488, 421, 199, 533, 4420, 5779, 13042, 2461, 8, 1014, 3280, 14, 5779, 13042, 2461, 304, 523, 347, 2429, 63, 368, 63, 1069, 8, 277, 304, 272, 1455, 3280, 14, 5779, 13042, 2461, 14, 2479, 63, 368, 63, 1069, 8, 277, 9, 272, 4760, 4936, 774, 14, 10854, 5290, 63, 6780, 63, 8760, 847, 413, 421, 199, 533, 4420, 12920, 8, 785, 304, 523, 347, 6668, 8, 277, 12, 9563, 63, 2200, 63, 466, 63, 354, 304, 221, 327, 4287, 26, 3507, 29, 8618, 13, 2094, 272, 372, 2400, 9563, 63, 1069, 12, 9563, 63, 1310, 26, 488, 421, 199, 533, 4760, 4936, 774, 8, 2796, 14, 1746, 304, 523, 347, 3613, 8, 277, 304, 272, 291, 14, 1989, 63, 3280, 63, 1000, 63, 3556, 63, 719, 275, 756, 272, 291, 14, 1989, 63, 3280, 63, 1000, 63, 8924, 275, 756, 819, 347, 663, 63, 384, 63, 3280, 63, 1000, 8, 277, 12, 1177, 304, 272, 408, 272, 3033, 26, 489, 1177, 26, 1626, 1256, 402, 19521, 12905, 16287, 626, 365, 2138, 367, 1924, 489, 1056, 14, 272, 408, 272, 4760, 4936, 774, 14, 10854, 5290, 63, 6780, 63, 8760, 275, 378, 272, 291, 14, 1102, 275, 283, 5967, 7, 272, 291, 14, 719, 275, 10523, 1407, 272, 3537, 63, 5586, 275, 4420, 7223, 2364, 2461, 8, 1310, 9, 272, 4713, 275, 4420, 12920, 342, 272, 1455, 63, 6404, 63, 3535, 275, 4420, 5779, 13042, 11135, 342, 272, 291, 14, 3280, 63, 1000, 275, 1455, 3280, 14, 5779, 4936, 3120, 8, 267, 1455, 63, 6404, 63, 3535, 12, 3537, 63, 5586, 12, 4713, 12, 267, 1591, 29, 277, 14, 1102, 12, 1844, 29, 277, 14, 719, 9, 272, 291, 14, 3280, 63, 1000, 14, 11149, 2543, 275, 4420, 5779, 13042, 2461, 272, 291, 14, 1989, 63, 3280, 63, 1000, 63, 3556, 63, 719, 275, 715, 819, 347, 6766, 8, 277, 304, 272, 340, 291, 14, 1989, 63, 3280, 63, 1000, 63, 8924, 26, 489, 291, 14, 3280, 63, 1000, 14, 8831, 342, 272, 340, 291, 14, 1989, 63, 3280, 63, 1000, 63, 3556, 63, 719, 26, 489, 291, 14, 3280, 63, 1000, 14, 1000, 63, 1600, 342, 819, 347, 14062, 63, 6615, 63, 21327, 8, 277, 304, 272, 291, 14, 1989, 63, 3280, 63, 1000, 63, 8924, 275, 715, 272, 291, 14, 3280, 63, 1000, 14, 4909, 63, 21327, 8, 6843, 63, 4284, 29, 16, 14, 614, 9, 819, 327, 6496, 626, 2429, 63, 368, 63, 1069, 1630, 440, 25831, 7183, 12, 436, 1630, 440, 862, 370, 523, 327, 295, 13, 2479, 6947, 626, 787, 9158, 14, 523, 347, 511, 63, 2479, 63, 368, 63, 1069, 63, 1251, 874, 63, 2105, 8, 277, 304, 272, 327, 4885, 849, 12, 3523, 14938, 14, 647, 20991, 1956, 1006, 3101, 413, 14, 17, 4145, 465, 4215, 13, 9631, 14, 272, 327, 1010, 9553, 1183, 675, 3101, 413, 14, 16, 370, 7981, 642, 5953, 14, 272, 1177, 275, 22768, 462, 335, 1912, 14, 8438, 12905, 16287, 8, 267, 1015, 29, 709, 12, 2004, 29, 1840, 12, 4499, 628, 3593, 401, 267, 2323, 6034, 1177, 63, 576, 6270, 13475, 17, 3135, 272, 291, 14, 409, 63, 384, 63, 3280, 63, 1000, 8, 1310, 9, 272, 307, 275, 5796, 14, 4436, 8, 267, 1347, 29, 5779, 4936, 774, 14, 4909, 63, 6615, 63, 21327, 12, 1249, 2687, 277, 4641, 272, 307, 14, 928, 342, 339, 2536, 63, 2671, 63, 835, 275, 5796, 14, 2682, 2353, 342, 339, 327, 4155, 282, 22219, 402, 4145, 14, 272, 1056, 63, 835, 275, 1616, 272, 367, 485, 315, 1425, 8, 1069, 63, 835, 304, 489, 2557, 275, 8809, 14, 19114, 360, 5967, 297, 10523, 1407, 12, 2653, 29, 709, 9, 489, 2557, 14, 1069, 480, 2970, 401, 3286, 1080, 14, 1360, 531, 489, 522, 275, 2557, 14, 25006, 1252, 739, 342, 489, 291, 14, 629, 8, 470, 12, 298, 13475, 17, 531, 489, 2557, 14, 1600, 342, 339, 327, 2670, 370, 1852, 3238, 626, 2337, 365, 949, 1026, 16702, 2462, 14, 272, 4884, 14, 21433, 8, 2734, 26, 5796, 14, 2682, 2353, 342, 508, 2536, 63, 2671, 63, 835, 12, 499, 9, 339, 291, 14, 629, 8, 1069, 63, 835, 12, 4760, 4936, 774, 14, 10854, 5290, 63, 6780, 63, 8760, 9, 8330, 327, 6496, 626, 4215, 13, 9631, 1406, 5419, 14, 523, 347, 511, 63, 3250, 63, 9631, 63, 1291, 8, 277, 304, 272, 1177, 275, 22768, 462, 335, 1912, 14, 8438, 12905, 16287, 8, 267, 1015, 29, 845, 12, 2004, 29, 1840, 12, 4499, 628, 3593, 401 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 6900, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 421, 199, 646, 22768, 462, 335, 1912, 199, 646, 8809, 199, 646, 1455, 3280, 199, 646, 5796, 199, 646, 2882, 199, 646, 4884, 421, 199, 533, 4420, 7223, 2364, 2461, 8, 785, 304, 523, 347, 636, 826, 721, 277, 12, 1177, 304, 272, 408, 272, 3033, 26, 489, 1177, 26, 1626, 1256, 402, 19521, 12905, 16287, 626, 365, 2138, 367, 1924, 489, 1056, 14, 272, 408, 272, 291, 423, 1310, 275, 1177, 819, 347, 2429, 8, 277, 12, 1056, 304, 272, 2150, 1056, 272, 372, 291, 423, 1310, 421, 199, 533, 4420, 5779, 13042, 11135, 8, 785, 304, 523, 347, 636, 826, 721, 277, 304, 272, 291, 14, 374, 63, 3059, 63, 632, 275, 756, 819, 347, 636, 1250, 721, 277, 12, 1056, 304, 272, 372, 488, 421, 199, 533, 4420, 5779, 13042, 2461, 8, 1014, 3280, 14, 5779, 13042, 2461, 304, 523, 347, 2429, 63, 368, 63, 1069, 8, 277, 304, 272, 1455, 3280, 14, 5779, 13042, 2461, 14, 2479, 63, 368, 63, 1069, 8, 277, 9, 272, 4760, 4936, 774, 14, 10854, 5290, 63, 6780, 63, 8760, 847, 413, 421, 199, 533, 4420, 12920, 8, 785, 304, 523, 347, 6668, 8, 277, 12, 9563, 63, 2200, 63, 466, 63, 354, 304, 221, 327, 4287, 26, 3507, 29, 8618, 13, 2094, 272, 372, 2400, 9563, 63, 1069, 12, 9563, 63, 1310, 26, 488, 421, 199, 533, 4760, 4936, 774, 8, 2796, 14, 1746, 304, 523, 347, 3613, 8, 277, 304, 272, 291, 14, 1989, 63, 3280, 63, 1000, 63, 3556, 63, 719, 275, 756, 272, 291, 14, 1989, 63, 3280, 63, 1000, 63, 8924, 275, 756, 819, 347, 663, 63, 384, 63, 3280, 63, 1000, 8, 277, 12, 1177, 304, 272, 408, 272, 3033, 26, 489, 1177, 26, 1626, 1256, 402, 19521, 12905, 16287, 626, 365, 2138, 367, 1924, 489, 1056, 14, 272, 408, 272, 4760, 4936, 774, 14, 10854, 5290, 63, 6780, 63, 8760, 275, 378, 272, 291, 14, 1102, 275, 283, 5967, 7, 272, 291, 14, 719, 275, 10523, 1407, 272, 3537, 63, 5586, 275, 4420, 7223, 2364, 2461, 8, 1310, 9, 272, 4713, 275, 4420, 12920, 342, 272, 1455, 63, 6404, 63, 3535, 275, 4420, 5779, 13042, 11135, 342, 272, 291, 14, 3280, 63, 1000, 275, 1455, 3280, 14, 5779, 4936, 3120, 8, 267, 1455, 63, 6404, 63, 3535, 12, 3537, 63, 5586, 12, 4713, 12, 267, 1591, 29, 277, 14, 1102, 12, 1844, 29, 277, 14, 719, 9, 272, 291, 14, 3280, 63, 1000, 14, 11149, 2543, 275, 4420, 5779, 13042, 2461, 272, 291, 14, 1989, 63, 3280, 63, 1000, 63, 3556, 63, 719, 275, 715, 819, 347, 6766, 8, 277, 304, 272, 340, 291, 14, 1989, 63, 3280, 63, 1000, 63, 8924, 26, 489, 291, 14, 3280, 63, 1000, 14, 8831, 342, 272, 340, 291, 14, 1989, 63, 3280, 63, 1000, 63, 3556, 63, 719, 26, 489, 291, 14, 3280, 63, 1000, 14, 1000, 63, 1600, 342, 819, 347, 14062, 63, 6615, 63, 21327, 8, 277, 304, 272, 291, 14, 1989, 63, 3280, 63, 1000, 63, 8924, 275, 715, 272, 291, 14, 3280, 63, 1000, 14, 4909, 63, 21327, 8, 6843, 63, 4284, 29, 16, 14, 614, 9, 819, 327, 6496, 626, 2429, 63, 368, 63, 1069, 1630, 440, 25831, 7183, 12, 436, 1630, 440, 862, 370, 523, 327, 295, 13, 2479, 6947, 626, 787, 9158, 14, 523, 347, 511, 63, 2479, 63, 368, 63, 1069, 63, 1251, 874, 63, 2105, 8, 277, 304, 272, 327, 4885, 849, 12, 3523, 14938, 14, 647, 20991, 1956, 1006, 3101, 413, 14, 17, 4145, 465, 4215, 13, 9631, 14, 272, 327, 1010, 9553, 1183, 675, 3101, 413, 14, 16, 370, 7981, 642, 5953, 14, 272, 1177, 275, 22768, 462, 335, 1912, 14, 8438, 12905, 16287, 8, 267, 1015, 29, 709, 12, 2004, 29, 1840, 12, 4499, 628, 3593, 401, 267, 2323, 6034, 1177, 63, 576, 6270, 13475, 17, 3135, 272, 291, 14, 409, 63, 384, 63, 3280, 63, 1000, 8, 1310, 9, 272, 307, 275, 5796, 14, 4436, 8, 267, 1347, 29, 5779, 4936, 774, 14, 4909, 63, 6615, 63, 21327, 12, 1249, 2687, 277, 4641, 272, 307, 14, 928, 342, 339, 2536, 63, 2671, 63, 835, 275, 5796, 14, 2682, 2353, 342, 339, 327, 4155, 282, 22219, 402, 4145, 14, 272, 1056, 63, 835, 275, 1616, 272, 367, 485, 315, 1425, 8, 1069, 63, 835, 304, 489, 2557, 275, 8809, 14, 19114, 360, 5967, 297, 10523, 1407, 12, 2653, 29, 709, 9, 489, 2557, 14, 1069, 480, 2970, 401, 3286, 1080, 14, 1360, 531, 489, 522, 275, 2557, 14, 25006, 1252, 739, 342, 489, 291, 14, 629, 8, 470, 12, 298, 13475, 17, 531, 489, 2557, 14, 1600, 342, 339, 327, 2670, 370, 1852, 3238, 626, 2337, 365, 949, 1026, 16702, 2462, 14, 272, 4884, 14, 21433, 8, 2734, 26, 5796, 14, 2682, 2353, 342, 508, 2536, 63, 2671, 63, 835, 12, 499, 9, 339, 291, 14, 629, 8, 1069, 63, 835, 12, 4760, 4936, 774, 14, 10854, 5290, 63, 6780, 63, 8760, 9, 8330, 327, 6496, 626, 4215, 13, 9631, 1406, 5419, 14, 523, 347, 511, 63, 3250, 63, 9631, 63, 1291, 8, 277, 304, 272, 1177, 275, 22768, 462, 335, 1912, 14, 8438, 12905, 16287, 8, 267, 1015, 29, 845, 12, 2004, 29, 1840, 12, 4499, 628, 3593, 401, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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