code
stringlengths 9
256k
|
---|
<s> """<STR_LIT>""" <EOL> from django . core . files . uploadhandler import FileUploadHandler , StopUpload <EOL> class QuotaUploadHandler ( FileUploadHandler ) : <EOL> """<STR_LIT>""" <EOL> QUOTA = <NUM_LIT:5> * <NUM_LIT:2> ** <NUM_LIT:20> <EOL> def __init__ ( self , request = None ) : <EOL> super ( QuotaUploadHandler , self ) . __init__ ( request ) <EOL> self . total_upload = <NUM_LIT:0> <EOL> def receive_data_chunk ( self , raw_data , start ) : <EOL> self . total_upload += len ( raw_data ) <EOL> if self . total_upload >= self . QUOTA : <EOL> raise StopUpload ( connection_reset = True ) <EOL> return raw_data <EOL> def file_complete ( self , file_size ) : <EOL> return None <EOL> class CustomUploadError ( Exception ) : <EOL> pass <EOL> class ErroringUploadHandler ( FileUploadHandler ) : <EOL> """<STR_LIT>""" <EOL> def receive_data_chunk ( self , raw_data , start ) : <EOL> raise CustomUploadError ( "<STR_LIT>" ) </s>
|
<s> from __future__ import absolute_import <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . test import TestCase <EOL> from . models import Author , Artist <EOL> class ListViewTests ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> urls = '<STR_LIT>' <EOL> def test_items ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_queryset ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) , list ( Author . objects . all ( ) ) ) <EOL> self . assertIs ( res . context [ '<STR_LIT>' ] , res . context [ '<STR_LIT>' ] ) <EOL> self . assertIsNone ( res . context [ '<STR_LIT>' ] ) <EOL> self . assertIsNone ( res . context [ '<STR_LIT>' ] ) <EOL> self . assertFalse ( res . context [ '<STR_LIT>' ] ) <EOL> def test_paginated_queryset ( self ) : <EOL> self . _make_authors ( <NUM_LIT:100> ) <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] ) , <NUM_LIT:30> ) <EOL> self . assertIs ( res . context [ '<STR_LIT>' ] , res . context [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( res . context [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . number , <NUM_LIT:1> ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . num_pages , <NUM_LIT:4> ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) [ - <NUM_LIT:1> ] . name , '<STR_LIT>' ) <EOL> def test_paginated_queryset_shortdata ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) , list ( Author . objects . all ( ) ) ) <EOL> self . assertIs ( res . context [ '<STR_LIT>' ] , res . context [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . number , <NUM_LIT:1> ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . num_pages , <NUM_LIT:1> ) <EOL> self . assertFalse ( res . context [ '<STR_LIT>' ] ) <EOL> def test_paginated_get_page_by_query_string ( self ) : <EOL> self . _make_authors ( <NUM_LIT:100> ) <EOL> res = self . client . get ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:2>' } ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] ) , <NUM_LIT:30> ) <EOL> self . assertIs ( res . context [ '<STR_LIT>' ] , res . context [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . number , <NUM_LIT:2> ) <EOL> def test_paginated_get_last_page_by_query_string ( self ) : <EOL> self . _make_authors ( <NUM_LIT:100> ) <EOL> res = self . client . get ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] ) , <NUM_LIT:10> ) <EOL> self . assertIs ( res . context [ '<STR_LIT>' ] , res . context [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . number , <NUM_LIT:4> ) <EOL> def test_paginated_get_page_by_urlvar ( self ) : <EOL> self . _make_authors ( <NUM_LIT:100> ) <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] ) , <NUM_LIT:30> ) <EOL> self . assertIs ( res . context [ '<STR_LIT>' ] , res . context [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . number , <NUM_LIT:3> ) <EOL> def test_paginated_page_out_of_range ( self ) : <EOL> self . _make_authors ( <NUM_LIT:100> ) <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT> ) <EOL> def test_paginated_invalid_page ( self ) : <EOL> self . _make_authors ( <NUM_LIT:100> ) <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT> ) <EOL> def test_paginated_custom_paginator_class ( self ) : <EOL> self . _make_authors ( <NUM_LIT:7> ) <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . num_pages , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] ) , <NUM_LIT:7> ) <EOL> def test_paginated_custom_paginator_constructor ( self ) : <EOL> self . _make_authors ( <NUM_LIT:7> ) <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] ) , <NUM_LIT:7> ) <EOL> def test_paginated_non_queryset ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_verbose_name ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) , list ( Artist . objects . all ( ) ) ) <EOL> self . assertIs ( res . context [ '<STR_LIT>' ] , res . context [ '<STR_LIT>' ] ) <EOL> self . assertIsNone ( res . context [ '<STR_LIT>' ] ) <EOL> self . assertIsNone ( res . context [ '<STR_LIT>' ] ) <EOL> self . assertFalse ( res . context [ '<STR_LIT>' ] ) <EOL> def test_allow_empty_false ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> Author . objects . all ( ) . delete ( ) <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT> ) <EOL> def test_template_name ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) , list ( Author . objects . all ( ) ) ) <EOL> self . assertIs ( res . context [ '<STR_LIT>' ] , res . context [ '<STR_LIT>' ] ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> def test_template_name_suffix ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) , list ( Author . objects . all ( ) ) ) <EOL> self . assertIs ( res . context [ '<STR_LIT>' ] , res . context [ '<STR_LIT>' ] ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> def test_context_object_name ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) , list ( Author . objects . all ( ) ) ) <EOL> self . assertNotIn ( '<STR_LIT>' , res . context ) <EOL> self . assertIs ( res . context [ '<STR_LIT>' ] , res . context [ '<STR_LIT>' ] ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> def test_duplicate_context_object_name ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) , list ( Author . objects . all ( ) ) ) <EOL> self . assertNotIn ( '<STR_LIT>' , res . context ) <EOL> self . assertNotIn ( '<STR_LIT>' , res . context ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> def test_missing_items ( self ) : <EOL> self . assertRaises ( ImproperlyConfigured , self . client . get , '<STR_LIT>' ) <EOL> def _make_authors ( self , n ) : <EOL> Author . objects . all ( ) . delete ( ) <EOL> for i in range ( n ) : <EOL> Author . objects . create ( name = '<STR_LIT>' % i , slug = '<STR_LIT>' % i ) </s>
|
<s> from django . db import models <EOL> class Reporter ( models . Model ) : <EOL> first_name = models . CharField ( max_length = <NUM_LIT:30> ) <EOL> last_name = models . CharField ( max_length = <NUM_LIT:30> ) <EOL> email = models . EmailField ( ) <EOL> facebook_user_id = models . BigIntegerField ( null = True ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . first_name , self . last_name ) <EOL> class Article ( models . Model ) : <EOL> headline = models . CharField ( max_length = <NUM_LIT:100> ) <EOL> pub_date = models . DateField ( ) <EOL> reporter = models . ForeignKey ( Reporter ) <EOL> def __unicode__ ( self ) : <EOL> return self . headline <EOL> class Meta : <EOL> ordering = ( '<STR_LIT>' , ) </s>
|
<s> from __future__ import absolute_import , with_statement <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> from django . core import management <EOL> from django . contrib . auth . models import User <EOL> from django . test import TestCase <EOL> from . models import ( Person , Group , Membership , UserMembership , Car , Driver , <EOL> CarDriver ) <EOL> class M2MThroughTestCase ( TestCase ) : <EOL> def test_everything ( self ) : <EOL> bob = Person . objects . create ( name = "<STR_LIT>" ) <EOL> jim = Person . objects . create ( name = "<STR_LIT>" ) <EOL> rock = Group . objects . create ( name = "<STR_LIT>" ) <EOL> roll = Group . objects . create ( name = "<STR_LIT>" ) <EOL> frank = User . objects . create_user ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:password>" ) <EOL> jane = User . objects . create_user ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:password>" ) <EOL> Membership . objects . create ( person = bob , group = rock ) <EOL> Membership . objects . create ( person = bob , group = roll ) <EOL> Membership . objects . create ( person = jim , group = rock ) <EOL> self . assertQuerysetEqual ( <EOL> bob . group_set . all ( ) , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> roll . members . all ( ) , [ <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> self . assertRaises ( AttributeError , setattr , bob , "<STR_LIT>" , [ ] ) <EOL> self . assertRaises ( AttributeError , setattr , roll , "<STR_LIT>" , [ ] ) <EOL> self . assertRaises ( AttributeError , rock . members . create , name = "<STR_LIT>" ) <EOL> self . assertRaises ( AttributeError , bob . group_set . create , name = "<STR_LIT>" ) <EOL> UserMembership . objects . create ( user = frank , group = rock ) <EOL> UserMembership . objects . create ( user = frank , group = roll ) <EOL> UserMembership . objects . create ( user = jane , group = rock ) <EOL> self . assertQuerysetEqual ( <EOL> frank . group_set . all ( ) , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> roll . user_members . all ( ) , [ <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> def test_serialization ( self ) : <EOL> "<STR_LIT>" <EOL> p = Person . objects . create ( name = "<STR_LIT>" ) <EOL> g = Group . objects . create ( name = "<STR_LIT>" ) <EOL> m = Membership . objects . create ( person = p , group = g ) <EOL> pks = { "<STR_LIT>" : p . pk , "<STR_LIT>" : g . pk , "<STR_LIT>" : m . pk } <EOL> out = StringIO ( ) <EOL> management . call_command ( "<STR_LIT>" , "<STR_LIT>" , format = "<STR_LIT>" , stdout = out ) <EOL> self . assertEqual ( out . getvalue ( ) . strip ( ) , """<STR_LIT>""" % pks ) <EOL> out = StringIO ( ) <EOL> management . call_command ( "<STR_LIT>" , "<STR_LIT>" , format = "<STR_LIT>" , <EOL> indent = <NUM_LIT:2> , stdout = out ) <EOL> self . assertEqual ( out . getvalue ( ) . strip ( ) , """<STR_LIT>""" . strip ( ) % pks ) <EOL> def test_join_trimming ( self ) : <EOL> "<STR_LIT>" <EOL> bob = Person . objects . create ( name = "<STR_LIT>" ) <EOL> jim = Person . objects . create ( name = "<STR_LIT>" ) <EOL> rock = Group . objects . create ( name = "<STR_LIT>" ) <EOL> roll = Group . objects . create ( name = "<STR_LIT>" ) <EOL> Membership . objects . create ( person = bob , group = rock ) <EOL> Membership . objects . create ( person = jim , group = rock , price = <NUM_LIT:50> ) <EOL> Membership . objects . create ( person = bob , group = roll , price = <NUM_LIT:50> ) <EOL> self . assertQuerysetEqual ( <EOL> rock . members . filter ( membership__price = <NUM_LIT:50> ) , [ <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> bob . group_set . filter ( membership__price = <NUM_LIT:50> ) , [ <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> class ToFieldThroughTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . car = Car . objects . create ( make = "<STR_LIT>" ) <EOL> self . driver = Driver . objects . create ( name = "<STR_LIT>" ) <EOL> CarDriver . objects . create ( car = self . car , driver = self . driver ) <EOL> self . unused_driver = Driver . objects . create ( name = "<STR_LIT>" ) <EOL> self . unused_car1 = Car . objects . create ( make = "<STR_LIT>" ) <EOL> self . unused_car2 = Car . objects . create ( make = "<STR_LIT>" ) <EOL> def test_to_field ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> self . car . drivers . all ( ) , <EOL> [ "<STR_LIT>" ] <EOL> ) <EOL> def test_to_field_reverse ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> self . driver . car_set . all ( ) , <EOL> [ "<STR_LIT>" ] <EOL> ) <EOL> def test_to_field_clear_reverse ( self ) : <EOL> self . driver . car_set . clear ( ) <EOL> self . assertQuerysetEqual ( <EOL> self . driver . car_set . all ( ) , [ ] ) <EOL> def test_to_field_clear ( self ) : <EOL> self . car . drivers . clear ( ) <EOL> self . assertQuerysetEqual ( <EOL> self . car . drivers . all ( ) , [ ] ) <EOL> def test_add ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> self . car . drivers . all ( ) , <EOL> [ "<STR_LIT>" ] <EOL> ) <EOL> self . car . drivers . _add_items ( '<STR_LIT>' , '<STR_LIT>' , self . unused_driver ) <EOL> self . assertQuerysetEqual ( <EOL> self . car . drivers . all ( ) , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ) <EOL> def test_add_null ( self ) : <EOL> nullcar = Car . objects . create ( make = None ) <EOL> with self . assertRaises ( ValueError ) : <EOL> nullcar . drivers . _add_items ( '<STR_LIT>' , '<STR_LIT>' , self . unused_driver ) <EOL> def test_add_related_null ( self ) : <EOL> nulldriver = Driver . objects . create ( name = None ) <EOL> with self . assertRaises ( ValueError ) : <EOL> self . car . drivers . _add_items ( '<STR_LIT>' , '<STR_LIT>' , nulldriver ) <EOL> def test_add_reverse ( self ) : <EOL> car2 = Car . objects . create ( make = "<STR_LIT>" ) <EOL> self . assertQuerysetEqual ( <EOL> self . driver . car_set . all ( ) , <EOL> [ "<STR_LIT>" ] <EOL> ) <EOL> self . driver . car_set . _add_items ( '<STR_LIT>' , '<STR_LIT>' , car2 ) <EOL> self . assertQuerysetEqual ( <EOL> self . driver . car_set . all ( ) , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ) <EOL> def test_add_null_reverse ( self ) : <EOL> nullcar = Car . objects . create ( make = None ) <EOL> with self . assertRaises ( ValueError ) : <EOL> self . driver . car_set . _add_items ( '<STR_LIT>' , '<STR_LIT>' , nullcar ) <EOL> def test_add_null_reverse_related ( self ) : <EOL> nulldriver = Driver . objects . create ( name = None ) <EOL> with self . assertRaises ( ValueError ) : <EOL> nulldriver . car_set . _add_items ( '<STR_LIT>' , '<STR_LIT>' , self . car ) <EOL> def test_remove ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> self . car . drivers . all ( ) , <EOL> [ "<STR_LIT>" ] <EOL> ) <EOL> self . car . drivers . _remove_items ( '<STR_LIT>' , '<STR_LIT>' , self . driver ) <EOL> self . assertQuerysetEqual ( <EOL> self . car . drivers . all ( ) , [ ] ) <EOL> def test_remove_reverse ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> self . driver . car_set . all ( ) , <EOL> [ "<STR_LIT>" ] <EOL> ) <EOL> self . driver . car_set . _remove_items ( '<STR_LIT>' , '<STR_LIT>' , self . car ) <EOL> self . assertQuerysetEqual ( <EOL> self . driver . car_set . all ( ) , [ ] ) <EOL> class ThroughLoadDataTestCase ( TestCase ) : <EOL> fixtures = [ "<STR_LIT>" ] <EOL> def test_sequence_creation ( self ) : <EOL> "<STR_LIT>" <EOL> out = StringIO ( ) <EOL> management . call_command ( "<STR_LIT>" , "<STR_LIT>" , format = "<STR_LIT>" , stdout = out ) <EOL> self . assertEqual ( out . getvalue ( ) . strip ( ) , """<STR_LIT>""" ) </s>
|
<s> from __future__ import absolute_import , with_statement <EOL> from datetime import date <EOL> from django import forms <EOL> from django . conf import settings <EOL> from django . contrib . admin . options import ( ModelAdmin , TabularInline , <EOL> InlineModelAdmin , HORIZONTAL , VERTICAL ) <EOL> from django . contrib . admin . sites import AdminSite <EOL> from django . contrib . admin . validation import validate <EOL> from django . contrib . admin . widgets import AdminDateWidget , AdminRadioSelect <EOL> from django . contrib . admin import ( SimpleListFilter , <EOL> BooleanFieldListFilter ) <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . forms . models import BaseModelFormSet <EOL> from django . forms . widgets import Select <EOL> from django . test import TestCase <EOL> from django . test . utils import override_settings <EOL> from django . utils import unittest <EOL> from . models import Band , Concert , ValidationTestModel , ValidationTestInlineModel <EOL> class MockRequest ( object ) : <EOL> pass <EOL> class MockSuperUser ( object ) : <EOL> def has_perm ( self , perm ) : <EOL> return True <EOL> request = MockRequest ( ) <EOL> request . user = MockSuperUser ( ) <EOL> class ModelAdminTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . band = Band . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> bio = '<STR_LIT>' , <EOL> sign_date = date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> ) <EOL> self . site = AdminSite ( ) <EOL> def test_default_fields ( self ) : <EOL> ma = ModelAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_default_fieldsets ( self ) : <EOL> ma = ModelAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_fieldsets ( request ) , <EOL> [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] } ) ] ) <EOL> self . assertEqual ( ma . get_fieldsets ( request , self . band ) , <EOL> [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] } ) ] ) <EOL> def test_field_arguments ( self ) : <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fields = [ '<STR_LIT:name>' ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_fieldsets ( request ) , <EOL> [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' ] } ) ] ) <EOL> self . assertEqual ( ma . get_fieldsets ( request , self . band ) , <EOL> [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' ] } ) ] ) <EOL> def test_field_arguments_restricted_on_form ( self ) : <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fields = [ '<STR_LIT:name>' ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( ma . get_form ( request , self . band ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' ] ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fieldsets = [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' ] } ) ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( ma . get_form ( request , self . band ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' ] ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> exclude = [ '<STR_LIT>' ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' , '<STR_LIT>' ] ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> exclude = ( '<STR_LIT>' , ) <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' , '<STR_LIT>' ] ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fields = [ '<STR_LIT:name>' , '<STR_LIT>' ] <EOL> exclude = [ '<STR_LIT>' ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' ] ) <EOL> def test_custom_form_meta_exclude_with_readonly ( self ) : <EOL> """<STR_LIT>""" <EOL> class AdminBandForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Band <EOL> exclude = [ '<STR_LIT>' ] <EOL> class BandAdmin ( ModelAdmin ) : <EOL> readonly_fields = [ '<STR_LIT:name>' ] <EOL> form = AdminBandForm <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT>' , ] ) <EOL> class AdminConcertForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Concert <EOL> exclude = [ '<STR_LIT>' ] <EOL> class ConcertInline ( TabularInline ) : <EOL> readonly_fields = [ '<STR_LIT>' ] <EOL> form = AdminConcertForm <EOL> fk_name = '<STR_LIT>' <EOL> model = Concert <EOL> class BandAdmin ( ModelAdmin ) : <EOL> inlines = [ <EOL> ConcertInline <EOL> ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( <EOL> list ( ma . get_formsets ( request ) ) [ <NUM_LIT:0> ] ( ) . forms [ <NUM_LIT:0> ] . fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , ] ) <EOL> def test_custom_form_meta_exclude ( self ) : <EOL> """<STR_LIT>""" <EOL> class AdminBandForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Band <EOL> exclude = [ '<STR_LIT>' ] <EOL> class BandAdmin ( ModelAdmin ) : <EOL> exclude = [ '<STR_LIT:name>' ] <EOL> form = AdminBandForm <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , ] ) <EOL> class AdminConcertForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Concert <EOL> exclude = [ '<STR_LIT>' ] <EOL> class ConcertInline ( TabularInline ) : <EOL> exclude = [ '<STR_LIT>' ] <EOL> form = AdminConcertForm <EOL> fk_name = '<STR_LIT>' <EOL> model = Concert <EOL> class BandAdmin ( ModelAdmin ) : <EOL> inlines = [ <EOL> ConcertInline <EOL> ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( <EOL> list ( ma . get_formsets ( request ) ) [ <NUM_LIT:0> ] ( ) . forms [ <NUM_LIT:0> ] . fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , ] ) <EOL> def test_custom_form_validation ( self ) : <EOL> class AdminBandForm ( forms . ModelForm ) : <EOL> delete = forms . BooleanField ( ) <EOL> class Meta : <EOL> model = Band <EOL> class BandAdmin ( ModelAdmin ) : <EOL> form = AdminBandForm <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> type ( ma . get_form ( request ) . base_fields [ '<STR_LIT>' ] . widget ) , <EOL> AdminDateWidget ) <EOL> def test_form_exclude_kwarg_override ( self ) : <EOL> """<STR_LIT>""" <EOL> class AdminBandForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Band <EOL> exclude = [ '<STR_LIT:name>' ] <EOL> class BandAdmin ( ModelAdmin ) : <EOL> exclude = [ '<STR_LIT>' , ] <EOL> form = AdminBandForm <EOL> def get_form ( self , request , obj = None , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> return super ( BandAdmin , self ) . get_form ( request , obj , ** kwargs ) <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' , '<STR_LIT>' , ] ) <EOL> def test_formset_exclude_kwarg_override ( self ) : <EOL> """<STR_LIT>""" <EOL> class AdminConcertForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Concert <EOL> exclude = [ '<STR_LIT>' ] <EOL> class ConcertInline ( TabularInline ) : <EOL> exclude = [ '<STR_LIT>' ] <EOL> form = AdminConcertForm <EOL> fk_name = '<STR_LIT>' <EOL> model = Concert <EOL> def get_formset ( self , request , obj = None , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> return super ( ConcertInline , self ) . get_formset ( request , obj , ** kwargs ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> inlines = [ <EOL> ConcertInline <EOL> ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( <EOL> list ( ma . get_formsets ( request ) ) [ <NUM_LIT:0> ] ( ) . forms [ <NUM_LIT:0> ] . fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , ] ) <EOL> def test_queryset_override ( self ) : <EOL> band2 = Band ( name = '<STR_LIT>' , bio = '<STR_LIT>' , sign_date = date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> band2 . save ( ) <EOL> class ConcertAdmin ( ModelAdmin ) : <EOL> pass <EOL> ma = ConcertAdmin ( Concert , self . site ) <EOL> form = ma . get_form ( request ) ( ) <EOL> self . assertHTMLEqual ( str ( form [ "<STR_LIT>" ] ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( band2 . id , self . band . id ) ) <EOL> class AdminConcertForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Concert <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( AdminConcertForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ "<STR_LIT>" ] . queryset = Band . objects . filter ( name = '<STR_LIT>' ) <EOL> class ConcertAdmin ( ModelAdmin ) : <EOL> form = AdminConcertForm <EOL> ma = ConcertAdmin ( Concert , self . site ) <EOL> form = ma . get_form ( request ) ( ) <EOL> self . assertHTMLEqual ( str ( form [ "<STR_LIT>" ] ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % self . band . id ) <EOL> def test_regression_for_ticket_15820 ( self ) : <EOL> """<STR_LIT>""" <EOL> class CustomConcertForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Concert <EOL> fields = [ '<STR_LIT>' ] <EOL> class ConcertInline ( TabularInline ) : <EOL> model = Concert <EOL> fk_name = '<STR_LIT>' <EOL> def get_formset ( self , request , obj = None , ** kwargs ) : <EOL> if obj : <EOL> kwargs [ '<STR_LIT>' ] = CustomConcertForm <EOL> return super ( ConcertInline , self ) . get_formset ( request , obj , ** kwargs ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> inlines = [ <EOL> ConcertInline <EOL> ] <EOL> concert = Concert . objects . create ( main_band = self . band , opening_band = self . band , day = <NUM_LIT:1> ) <EOL> ma = BandAdmin ( Band , self . site ) <EOL> inline_instances = ma . get_inline_instances ( request ) <EOL> fieldsets = list ( inline_instances [ <NUM_LIT:0> ] . get_fieldsets ( request ) ) <EOL> self . assertEqual ( fieldsets [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> fieldsets = list ( inline_instances [ <NUM_LIT:0> ] . get_fieldsets ( request , inline_instances [ <NUM_LIT:0> ] . model ) ) <EOL> self . assertEqual ( fieldsets [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ) <EOL> def test_default_foreign_key_widget ( self ) : <EOL> cma = ModelAdmin ( Concert , self . site ) <EOL> cmafa = cma . get_form ( request ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget . widget ) , <EOL> Select ) <EOL> self . assertEqual ( <EOL> list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( self . band . id , u'<STR_LIT>' ) ] ) <EOL> self . assertEqual ( <EOL> type ( cmafa . base_fields [ '<STR_LIT>' ] . widget . widget ) , Select ) <EOL> self . assertEqual ( <EOL> list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( self . band . id , u'<STR_LIT>' ) ] ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget ) , Select ) <EOL> self . assertEqual ( list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( <NUM_LIT:1> , '<STR_LIT>' ) , ( <NUM_LIT:2> , '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget ) , <EOL> Select ) <EOL> self . assertEqual ( <EOL> list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( <NUM_LIT:1> , '<STR_LIT>' ) , ( <NUM_LIT:2> , '<STR_LIT>' ) , ( <NUM_LIT:3> , '<STR_LIT>' ) ] ) <EOL> def test_foreign_key_as_radio_field ( self ) : <EOL> class ConcertAdmin ( ModelAdmin ) : <EOL> radio_fields = { <EOL> '<STR_LIT>' : HORIZONTAL , <EOL> '<STR_LIT>' : VERTICAL , <EOL> '<STR_LIT>' : VERTICAL , <EOL> '<STR_LIT>' : HORIZONTAL , <EOL> } <EOL> cma = ConcertAdmin ( Concert , self . site ) <EOL> cmafa = cma . get_form ( request ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget . widget ) , <EOL> AdminRadioSelect ) <EOL> self . assertEqual ( cmafa . base_fields [ '<STR_LIT>' ] . widget . attrs , <EOL> { '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( self . band . id , u'<STR_LIT>' ) ] ) <EOL> self . assertEqual ( <EOL> type ( cmafa . base_fields [ '<STR_LIT>' ] . widget . widget ) , <EOL> AdminRadioSelect ) <EOL> self . assertEqual ( cmafa . base_fields [ '<STR_LIT>' ] . widget . attrs , <EOL> { '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( <EOL> list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( u'<STR_LIT>' , u'<STR_LIT:None>' ) , ( self . band . id , u'<STR_LIT>' ) ] ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget ) , <EOL> AdminRadioSelect ) <EOL> self . assertEqual ( cmafa . base_fields [ '<STR_LIT>' ] . widget . attrs , <EOL> { '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( <NUM_LIT:1> , '<STR_LIT>' ) , ( <NUM_LIT:2> , '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget ) , <EOL> AdminRadioSelect ) <EOL> self . assertEqual ( cmafa . base_fields [ '<STR_LIT>' ] . widget . attrs , <EOL> { '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( '<STR_LIT>' , u'<STR_LIT:None>' ) , ( <NUM_LIT:1> , '<STR_LIT>' ) , ( <NUM_LIT:2> , '<STR_LIT>' ) , ( <NUM_LIT:3> , '<STR_LIT>' ) ] ) <EOL> class AdminConcertForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Concert <EOL> exclude = ( '<STR_LIT>' , ) <EOL> class ConcertAdmin ( ModelAdmin ) : <EOL> form = AdminConcertForm <EOL> ma = ConcertAdmin ( Concert , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class AdminConcertForm ( forms . ModelForm ) : <EOL> extra = forms . CharField ( ) <EOL> class Meta : <EOL> model = Concert <EOL> fields = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> class ConcertAdmin ( ModelAdmin ) : <EOL> form = AdminConcertForm <EOL> ma = ConcertAdmin ( Concert , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class ConcertInline ( TabularInline ) : <EOL> form = AdminConcertForm <EOL> model = Concert <EOL> fk_name = '<STR_LIT>' <EOL> can_delete = True <EOL> class BandAdmin ( ModelAdmin ) : <EOL> inlines = [ <EOL> ConcertInline <EOL> ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( <EOL> list ( ma . get_formsets ( request ) ) [ <NUM_LIT:0> ] ( ) . forms [ <NUM_LIT:0> ] . fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class ValidationTests ( unittest . TestCase ) : <EOL> def test_validation_only_runs_in_debug ( self ) : <EOL> try : <EOL> settings . DEBUG = True <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> raw_id_fields = <NUM_LIT:10> <EOL> site = AdminSite ( ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> site . register , <EOL> ValidationTestModel , <EOL> ValidationTestModelAdmin , <EOL> ) <EOL> finally : <EOL> settings . DEBUG = False <EOL> site = AdminSite ( ) <EOL> site . register ( ValidationTestModel , ValidationTestModelAdmin ) <EOL> def test_raw_id_fields_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> raw_id_fields = <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> raw_id_fields = ( '<STR_LIT>' , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> raw_id_fields = ( '<STR_LIT:name>' , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> raw_id_fields = ( '<STR_LIT>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_fieldsets_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( { } , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( ) , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( "<STR_LIT>" , ( ) ) , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( "<STR_LIT>" , { } ) , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( "<STR_LIT>" , { "<STR_LIT>" : ( "<STR_LIT>" , ) } ) , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( "<STR_LIT>" , { "<STR_LIT>" : ( "<STR_LIT:name>" , ) } ) , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( "<STR_LIT>" , { "<STR_LIT>" : ( "<STR_LIT:name>" , ) } ) , ) <EOL> fields = [ "<STR_LIT:name>" , ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT:name>' ] } ) ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fields = [ "<STR_LIT:name>" , "<STR_LIT:name>" ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> def test_form_validation ( self ) : <EOL> class FakeForm ( object ) : <EOL> pass <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> form = FakeForm <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> def test_fieldsets_with_custom_form_validation ( self ) : <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fieldsets = ( <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) <EOL> } ) , <EOL> ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> BandAdmin , <EOL> Band , <EOL> ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fieldsets = ( <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT:name>' , ) <EOL> } ) , <EOL> ) <EOL> validate ( BandAdmin , Band ) <EOL> class AdminBandForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Band <EOL> class BandAdmin ( ModelAdmin ) : <EOL> form = AdminBandForm <EOL> fieldsets = ( <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) <EOL> } ) , <EOL> ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> BandAdmin , <EOL> Band , <EOL> ) <EOL> class AdminBandForm ( forms . ModelForm ) : <EOL> delete = forms . BooleanField ( ) <EOL> class Meta : <EOL> model = Band <EOL> class BandAdmin ( ModelAdmin ) : <EOL> form = AdminBandForm <EOL> fieldsets = ( <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> } ) , <EOL> ) <EOL> validate ( BandAdmin , Band ) <EOL> def test_filter_vertical_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_vertical = <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_vertical = ( "<STR_LIT>" , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_vertical = ( "<STR_LIT:name>" , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_vertical = ( "<STR_LIT>" , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_filter_horizontal_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_horizontal = <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_horizontal = ( "<STR_LIT>" , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_horizontal = ( "<STR_LIT:name>" , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_horizontal = ( "<STR_LIT>" , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_radio_fields_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> radio_fields = ( ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> radio_fields = { "<STR_LIT>" : None } <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> radio_fields = { "<STR_LIT:name>" : None } <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> radio_fields = { "<STR_LIT:state>" : None } <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> radio_fields = { "<STR_LIT:state>" : VERTICAL } <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_prepopulated_fields_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> prepopulated_fields = ( ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> prepopulated_fields = { "<STR_LIT>" : None } <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> prepopulated_fields = { "<STR_LIT>" : ( "<STR_LIT>" , ) } <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> prepopulated_fields = { "<STR_LIT>" : ( "<STR_LIT:name>" , ) } <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> prepopulated_fields = { "<STR_LIT>" : ( "<STR_LIT:name>" , ) } <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_list_display_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display = <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> def a_callable ( obj ) : <EOL> pass <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> def a_method ( self , obj ) : <EOL> pass <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , a_callable ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_list_display_links_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display_links = <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display_links = ( '<STR_LIT>' , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display_links = ( '<STR_LIT:name>' , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> def a_callable ( obj ) : <EOL> pass <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> def a_method ( self , obj ) : <EOL> pass <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , a_callable ) <EOL> list_display_links = ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , a_callable ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_list_filter_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_filter = <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_filter = ( '<STR_LIT>' , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class RandomClass ( object ) : <EOL> pass <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_filter = ( RandomClass , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_filter = ( ( '<STR_LIT>' , RandomClass ) , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class AwesomeFilter ( SimpleListFilter ) : <EOL> def get_title ( self ) : <EOL> return '<STR_LIT>' <EOL> def get_choices ( self , request ) : <EOL> return ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ) <EOL> def get_query_set ( self , cl , qs ) : <EOL> return qs <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_filter = ( ( '<STR_LIT>' , AwesomeFilter ) , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_filter = ( BooleanFieldListFilter , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_filter = ( '<STR_LIT>' , AwesomeFilter , ( '<STR_LIT>' , BooleanFieldListFilter ) , '<STR_LIT>' ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_list_per_page_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_per_page = '<STR_LIT:hello>' <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_per_page = <NUM_LIT:100> <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_max_show_all_allowed_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_max_show_all = '<STR_LIT:hello>' <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_max_show_all = <NUM_LIT:200> <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_search_fields_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> search_fields = <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> def test_date_hierarchy_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> date_hierarchy = '<STR_LIT>' <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> date_hierarchy = '<STR_LIT:name>' <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> date_hierarchy = '<STR_LIT>' <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_ordering_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = ( '<STR_LIT:?>' , '<STR_LIT:name>' ) <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = ( '<STR_LIT:?>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = ( '<STR_LIT:name>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_list_select_related_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_select_related = <NUM_LIT:1> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_select_related = False <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_save_as_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> save_as = <NUM_LIT:1> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> save_as = True <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_save_on_top_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> save_on_top = <NUM_LIT:1> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> save_on_top = True <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_inlines_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( object ) : <EOL> pass <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> pass <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class SomethingBad ( object ) : <EOL> pass <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = SomethingBad <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_fields_validation ( self ) : <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> fields = <NUM_LIT:10> <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> fields = ( "<STR_LIT>" , ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> def test_fk_name_validation ( self ) : <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> fk_name = "<STR_LIT>" <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> fk_name = "<STR_LIT>" <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_extra_validation ( self ) : <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> extra = "<STR_LIT:hello>" <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> extra = <NUM_LIT:2> <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_max_num_validation ( self ) : <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> max_num = "<STR_LIT:hello>" <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> max_num = <NUM_LIT:2> <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_formset_validation ( self ) : <EOL> class FakeFormSet ( object ) : <EOL> pass <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> formset = FakeFormSet <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesRegexp ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class RealModelFormSet ( BaseModelFormSet ) : <EOL> pass <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> formset = RealModelFormSet <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) </s>
|
<s> from __future__ import with_statement <EOL> import os <EOL> from django . conf import settings , global_settings <EOL> from django . http import HttpRequest <EOL> from django . test import TransactionTestCase , TestCase , signals <EOL> from django . test . utils import override_settings <EOL> class FullyDecoratedTranTestCase ( TransactionTestCase ) : <EOL> def test_override ( self ) : <EOL> self . assertEqual ( settings . TEST , '<STR_LIT>' ) <EOL> @ override_settings ( TEST = '<STR_LIT>' ) <EOL> def test_method_override ( self ) : <EOL> self . assertEqual ( settings . TEST , '<STR_LIT>' ) <EOL> def test_decorated_testcase_name ( self ) : <EOL> self . assertEquals ( FullyDecoratedTranTestCase . __name__ , '<STR_LIT>' ) <EOL> def test_decorated_testcase_module ( self ) : <EOL> self . assertEquals ( FullyDecoratedTranTestCase . __module__ , __name__ ) <EOL> FullyDecoratedTranTestCase = override_settings ( TEST = '<STR_LIT>' ) ( FullyDecoratedTranTestCase ) <EOL> class FullyDecoratedTestCase ( TestCase ) : <EOL> def test_override ( self ) : <EOL> self . assertEqual ( settings . TEST , '<STR_LIT>' ) <EOL> @ override_settings ( TEST = '<STR_LIT>' ) <EOL> def test_method_override ( self ) : <EOL> self . assertEqual ( settings . TEST , '<STR_LIT>' ) <EOL> FullyDecoratedTestCase = override_settings ( TEST = '<STR_LIT>' ) ( FullyDecoratedTestCase ) <EOL> class ClassDecoratedTestCaseSuper ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_max_recursion_error ( self ) : <EOL> pass <EOL> class ClassDecoratedTestCase ( ClassDecoratedTestCaseSuper ) : <EOL> def test_override ( self ) : <EOL> self . assertEqual ( settings . TEST , '<STR_LIT>' ) <EOL> @ override_settings ( TEST = '<STR_LIT>' ) <EOL> def test_method_override ( self ) : <EOL> self . assertEqual ( settings . TEST , '<STR_LIT>' ) <EOL> def test_max_recursion_error ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> super ( ClassDecoratedTestCase , self ) . test_max_recursion_error ( ) <EOL> except RuntimeError , e : <EOL> self . fail ( ) <EOL> ClassDecoratedTestCase = override_settings ( TEST = '<STR_LIT>' ) ( ClassDecoratedTestCase ) <EOL> class SettingGetter ( object ) : <EOL> def __init__ ( self ) : <EOL> self . test = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> testvalue = None <EOL> def signal_callback ( sender , setting , value , ** kwargs ) : <EOL> if setting == '<STR_LIT>' : <EOL> global testvalue <EOL> testvalue = value <EOL> signals . setting_changed . connect ( signal_callback ) <EOL> class SettingsTests ( TestCase ) : <EOL> def test_override ( self ) : <EOL> settings . TEST = '<STR_LIT:test>' <EOL> self . assertEqual ( '<STR_LIT:test>' , settings . TEST ) <EOL> with self . settings ( TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( '<STR_LIT>' , settings . TEST ) <EOL> self . assertEqual ( '<STR_LIT:test>' , settings . TEST ) <EOL> del settings . TEST <EOL> def test_override_change ( self ) : <EOL> settings . TEST = '<STR_LIT:test>' <EOL> self . assertEqual ( '<STR_LIT:test>' , settings . TEST ) <EOL> with self . settings ( TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( '<STR_LIT>' , settings . TEST ) <EOL> settings . TEST = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT:test>' , settings . TEST ) <EOL> del settings . TEST <EOL> def test_override_doesnt_leak ( self ) : <EOL> self . assertRaises ( AttributeError , getattr , settings , '<STR_LIT>' ) <EOL> with self . settings ( TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( '<STR_LIT>' , settings . TEST ) <EOL> settings . TEST = '<STR_LIT:test>' <EOL> self . assertRaises ( AttributeError , getattr , settings , '<STR_LIT>' ) <EOL> @ override_settings ( TEST = '<STR_LIT>' ) <EOL> def test_decorator ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , settings . TEST ) <EOL> def test_context_manager ( self ) : <EOL> self . assertRaises ( AttributeError , getattr , settings , '<STR_LIT>' ) <EOL> override = override_settings ( TEST = '<STR_LIT>' ) <EOL> self . assertRaises ( AttributeError , getattr , settings , '<STR_LIT>' ) <EOL> override . enable ( ) <EOL> self . assertEqual ( '<STR_LIT>' , settings . TEST ) <EOL> override . disable ( ) <EOL> self . assertRaises ( AttributeError , getattr , settings , '<STR_LIT>' ) <EOL> def test_class_decorator ( self ) : <EOL> self . assertEqual ( SettingGetter ( ) . test , '<STR_LIT>' ) <EOL> DecoratedSettingGetter = override_settings ( TEST = '<STR_LIT>' ) ( SettingGetter ) <EOL> self . assertEqual ( DecoratedSettingGetter ( ) . test , '<STR_LIT>' ) <EOL> self . assertRaises ( AttributeError , getattr , settings , '<STR_LIT>' ) <EOL> def test_signal_callback_context_manager ( self ) : <EOL> self . assertRaises ( AttributeError , getattr , settings , '<STR_LIT>' ) <EOL> with self . settings ( TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( testvalue , '<STR_LIT>' ) <EOL> self . assertEqual ( testvalue , None ) <EOL> @ override_settings ( TEST = '<STR_LIT>' ) <EOL> def test_signal_callback_decorator ( self ) : <EOL> self . assertEqual ( testvalue , '<STR_LIT>' ) <EOL> def test_settings_delete ( self ) : <EOL> settings . TEST = '<STR_LIT:test>' <EOL> self . assertEqual ( '<STR_LIT:test>' , settings . TEST ) <EOL> del settings . TEST <EOL> self . assertRaises ( AttributeError , getattr , settings , '<STR_LIT>' ) <EOL> def test_settings_delete_wrapped ( self ) : <EOL> self . assertRaises ( TypeError , delattr , settings , '<STR_LIT>' ) <EOL> def test_allowed_include_roots_string ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( ValueError , setattr , settings , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TrailingSlashURLTests ( TestCase ) : <EOL> settings_module = settings <EOL> def setUp ( self ) : <EOL> self . _original_media_url = self . settings_module . MEDIA_URL <EOL> def tearDown ( self ) : <EOL> self . settings_module . MEDIA_URL = self . _original_media_url <EOL> def test_blank ( self ) : <EOL> """<STR_LIT>""" <EOL> self . settings_module . MEDIA_URL = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT>' , self . settings_module . MEDIA_URL ) <EOL> def test_end_slash ( self ) : <EOL> """<STR_LIT>""" <EOL> self . settings_module . MEDIA_URL = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT>' , self . settings_module . MEDIA_URL ) <EOL> self . settings_module . MEDIA_URL = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> self . settings_module . MEDIA_URL ) <EOL> def test_no_end_slash ( self ) : <EOL> """<STR_LIT>""" <EOL> import warnings <EOL> warnings . filterwarnings ( '<STR_LIT:error>' , '<STR_LIT>' , DeprecationWarning ) <EOL> def setattr_settings ( settings_module , attr , value ) : <EOL> setattr ( settings_module , attr , value ) <EOL> self . assertRaises ( DeprecationWarning , setattr_settings , <EOL> self . settings_module , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRaises ( DeprecationWarning , setattr_settings , <EOL> self . settings_module , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def test_double_slash ( self ) : <EOL> """<STR_LIT>""" <EOL> self . settings_module . MEDIA_URL = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT>' , self . settings_module . MEDIA_URL ) <EOL> self . settings_module . MEDIA_URL = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> self . settings_module . MEDIA_URL ) <EOL> class SecureProxySslHeaderTest ( TestCase ) : <EOL> settings_module = settings <EOL> def setUp ( self ) : <EOL> self . _original_setting = self . settings_module . SECURE_PROXY_SSL_HEADER <EOL> def tearDown ( self ) : <EOL> self . settings_module . SECURE_PROXY_SSL_HEADER = self . _original_setting <EOL> def test_none ( self ) : <EOL> self . settings_module . SECURE_PROXY_SSL_HEADER = None <EOL> req = HttpRequest ( ) <EOL> self . assertEqual ( req . is_secure ( ) , False ) <EOL> def test_set_without_xheader ( self ) : <EOL> self . settings_module . SECURE_PROXY_SSL_HEADER = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> req = HttpRequest ( ) <EOL> self . assertEqual ( req . is_secure ( ) , False ) <EOL> def test_set_with_xheader_wrong ( self ) : <EOL> self . settings_module . SECURE_PROXY_SSL_HEADER = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> req = HttpRequest ( ) <EOL> req . META [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( req . is_secure ( ) , False ) <EOL> def test_set_with_xheader_right ( self ) : <EOL> self . settings_module . SECURE_PROXY_SSL_HEADER = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> req = HttpRequest ( ) <EOL> req . META [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( req . is_secure ( ) , True ) <EOL> class EnvironmentVariableTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . original_value = os . environ . get ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> if self . original_value : <EOL> os . environ [ '<STR_LIT>' ] = self . original_value <EOL> elif '<STR_LIT>' in os . environ : <EOL> del ( os . environ [ '<STR_LIT>' ] ) <EOL> def test_env_var_used ( self ) : <EOL> """<STR_LIT>""" <EOL> from django . core . management import setup_environ <EOL> original_module = os . environ . get ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> user_override = '<STR_LIT>' <EOL> orig_path = '<STR_LIT>' <EOL> setup_environ ( global_settings ) <EOL> self . assertEqual ( <EOL> os . environ . get ( '<STR_LIT>' ) , <EOL> original_module <EOL> ) <EOL> os . environ [ '<STR_LIT>' ] = user_override <EOL> setup_environ ( global_settings ) <EOL> self . assertEqual ( <EOL> os . environ . get ( '<STR_LIT>' ) , <EOL> user_override <EOL> ) <EOL> os . environ [ '<STR_LIT>' ] = user_override <EOL> setup_environ ( global_settings , original_settings_path = orig_path ) <EOL> self . assertEqual ( <EOL> os . environ . get ( '<STR_LIT>' ) , <EOL> orig_path <EOL> ) </s>
|
<s> import operator <EOL> from django import template <EOL> from django . template . defaultfilters import stringfilter <EOL> from django . template . loader import get_template <EOL> register = template . Library ( ) <EOL> @ register . filter <EOL> @ stringfilter <EOL> def trim ( value , num ) : <EOL> return value [ : num ] <EOL> @ register . simple_tag <EOL> def no_params ( ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> no_params . anything = "<STR_LIT>" <EOL> @ register . simple_tag <EOL> def one_param ( arg ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % arg <EOL> one_param . anything = "<STR_LIT>" <EOL> @ register . simple_tag ( takes_context = False ) <EOL> def explicit_no_context ( arg ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % arg <EOL> explicit_no_context . anything = "<STR_LIT>" <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def no_params_with_context ( context ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % context [ '<STR_LIT:value>' ] <EOL> no_params_with_context . anything = "<STR_LIT>" <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def params_and_context ( context , arg ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( context [ '<STR_LIT:value>' ] , arg ) <EOL> params_and_context . anything = "<STR_LIT>" <EOL> @ register . simple_tag <EOL> def simple_two_params ( one , two ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( one , two ) <EOL> simple_two_params . anything = "<STR_LIT>" <EOL> @ register . simple_tag <EOL> def simple_one_default ( one , two = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( one , two ) <EOL> simple_one_default . anything = "<STR_LIT>" <EOL> @ register . simple_tag <EOL> def simple_unlimited_args ( one , two = '<STR_LIT>' , * args ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in [ one , two ] + list ( args ) ] ) ) <EOL> simple_unlimited_args . anything = "<STR_LIT>" <EOL> @ register . simple_tag <EOL> def simple_only_unlimited_args ( * args ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in args ] ) <EOL> simple_only_unlimited_args . anything = "<STR_LIT>" <EOL> @ register . simple_tag <EOL> def simple_unlimited_args_kwargs ( one , two = '<STR_LIT>' , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> sorted_kwarg = sorted ( kwargs . iteritems ( ) , key = operator . itemgetter ( <NUM_LIT:0> ) ) <EOL> return "<STR_LIT>" % ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in [ one , two ] + list ( args ) ] ) , <EOL> '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' % ( k , v ) for ( k , v ) in sorted_kwarg ] ) <EOL> ) <EOL> simple_unlimited_args_kwargs . anything = "<STR_LIT>" <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def simple_tag_without_context_parameter ( arg ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> simple_tag_without_context_parameter . anything = "<STR_LIT>" <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def current_app ( context ) : <EOL> return "<STR_LIT:%s>" % context . current_app <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def use_l10n ( context ) : <EOL> return "<STR_LIT:%s>" % context . use_l10n <EOL> @ register . simple_tag ( name = '<STR_LIT>' ) <EOL> def minustwo_overridden_name ( value ) : <EOL> return value - <NUM_LIT:2> <EOL> register . simple_tag ( lambda x : x - <NUM_LIT:1> , name = '<STR_LIT>' ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def inclusion_no_params ( ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" } <EOL> inclusion_no_params . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( get_template ( '<STR_LIT>' ) ) <EOL> def inclusion_no_params_from_template ( ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" } <EOL> inclusion_no_params_from_template . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def inclusion_one_param ( arg ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % arg } <EOL> inclusion_one_param . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( get_template ( '<STR_LIT>' ) ) <EOL> def inclusion_one_param_from_template ( arg ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % arg } <EOL> inclusion_one_param_from_template . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = False ) <EOL> def inclusion_explicit_no_context ( arg ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % arg } <EOL> inclusion_explicit_no_context . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( get_template ( '<STR_LIT>' ) , takes_context = False ) <EOL> def inclusion_explicit_no_context_from_template ( arg ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % arg } <EOL> inclusion_explicit_no_context_from_template . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def inclusion_no_params_with_context ( context ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % context [ '<STR_LIT:value>' ] } <EOL> inclusion_no_params_with_context . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( get_template ( '<STR_LIT>' ) , takes_context = True ) <EOL> def inclusion_no_params_with_context_from_template ( context ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % context [ '<STR_LIT:value>' ] } <EOL> inclusion_no_params_with_context_from_template . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def inclusion_params_and_context ( context , arg ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( context [ '<STR_LIT:value>' ] , arg ) } <EOL> inclusion_params_and_context . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( get_template ( '<STR_LIT>' ) , takes_context = True ) <EOL> def inclusion_params_and_context_from_template ( context , arg ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( context [ '<STR_LIT:value>' ] , arg ) } <EOL> inclusion_params_and_context_from_template . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def inclusion_two_params ( one , two ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( one , two ) } <EOL> inclusion_two_params . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( get_template ( '<STR_LIT>' ) ) <EOL> def inclusion_two_params_from_template ( one , two ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( one , two ) } <EOL> inclusion_two_params_from_template . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def inclusion_one_default ( one , two = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( one , two ) } <EOL> inclusion_one_default . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( get_template ( '<STR_LIT>' ) ) <EOL> def inclusion_one_default_from_template ( one , two = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( one , two ) } <EOL> inclusion_one_default_from_template . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def inclusion_unlimited_args ( one , two = '<STR_LIT>' , * args ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in [ one , two ] + list ( args ) ] ) ) } <EOL> inclusion_unlimited_args . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( get_template ( '<STR_LIT>' ) ) <EOL> def inclusion_unlimited_args_from_template ( one , two = '<STR_LIT>' , * args ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in [ one , two ] + list ( args ) ] ) ) } <EOL> inclusion_unlimited_args_from_template . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def inclusion_only_unlimited_args ( * args ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in args ] ) ) } <EOL> inclusion_only_unlimited_args . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( get_template ( '<STR_LIT>' ) ) <EOL> def inclusion_only_unlimited_args_from_template ( * args ) : <EOL> """<STR_LIT>""" <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in args ] ) ) } <EOL> inclusion_only_unlimited_args_from_template . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def inclusion_tag_current_app ( context ) : <EOL> """<STR_LIT>""" <EOL> return { } <EOL> inclusion_tag_current_app . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def inclusion_tag_use_l10n ( context ) : <EOL> """<STR_LIT>""" <EOL> return { } <EOL> inclusion_tag_use_l10n . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def inclusion_unlimited_args_kwargs ( one , two = '<STR_LIT>' , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> sorted_kwarg = sorted ( kwargs . iteritems ( ) , key = operator . itemgetter ( <NUM_LIT:0> ) ) <EOL> return { "<STR_LIT:result>" : "<STR_LIT>" % ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in [ one , two ] + list ( args ) ] ) , <EOL> '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' % ( k , v ) for ( k , v ) in sorted_kwarg ] ) <EOL> ) } <EOL> inclusion_unlimited_args_kwargs . anything = "<STR_LIT>" <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def inclusion_tag_without_context_parameter ( arg ) : <EOL> """<STR_LIT>""" <EOL> return { } <EOL> inclusion_tag_without_context_parameter . anything = "<STR_LIT>" <EOL> @ register . assignment_tag <EOL> def assignment_no_params ( ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> assignment_no_params . anything = "<STR_LIT>" <EOL> @ register . assignment_tag <EOL> def assignment_one_param ( arg ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % arg <EOL> assignment_one_param . anything = "<STR_LIT>" <EOL> @ register . assignment_tag ( takes_context = False ) <EOL> def assignment_explicit_no_context ( arg ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % arg <EOL> assignment_explicit_no_context . anything = "<STR_LIT>" <EOL> @ register . assignment_tag ( takes_context = True ) <EOL> def assignment_no_params_with_context ( context ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % context [ '<STR_LIT:value>' ] <EOL> assignment_no_params_with_context . anything = "<STR_LIT>" <EOL> @ register . assignment_tag ( takes_context = True ) <EOL> def assignment_params_and_context ( context , arg ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( context [ '<STR_LIT:value>' ] , arg ) <EOL> assignment_params_and_context . anything = "<STR_LIT>" <EOL> @ register . assignment_tag <EOL> def assignment_two_params ( one , two ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( one , two ) <EOL> assignment_two_params . anything = "<STR_LIT>" <EOL> @ register . assignment_tag <EOL> def assignment_one_default ( one , two = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( one , two ) <EOL> assignment_one_default . anything = "<STR_LIT>" <EOL> @ register . assignment_tag <EOL> def assignment_unlimited_args ( one , two = '<STR_LIT>' , * args ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in [ one , two ] + list ( args ) ] ) ) <EOL> assignment_unlimited_args . anything = "<STR_LIT>" <EOL> @ register . assignment_tag <EOL> def assignment_only_unlimited_args ( * args ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in args ] ) <EOL> assignment_only_unlimited_args . anything = "<STR_LIT>" <EOL> @ register . assignment_tag <EOL> def assignment_unlimited_args_kwargs ( one , two = '<STR_LIT>' , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> sorted_kwarg = sorted ( kwargs . iteritems ( ) , key = operator . itemgetter ( <NUM_LIT:0> ) ) <EOL> return "<STR_LIT>" % ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( [ unicode ( arg ) for arg in [ one , two ] + list ( args ) ] ) , <EOL> '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' % ( k , v ) for ( k , v ) in sorted_kwarg ] ) <EOL> ) <EOL> assignment_unlimited_args_kwargs . anything = "<STR_LIT>" <EOL> @ register . assignment_tag ( takes_context = True ) <EOL> def assignment_tag_without_context_parameter ( arg ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> assignment_tag_without_context_parameter . anything = "<STR_LIT>" </s>
|
<s> from __future__ import absolute_import <EOL> from django . conf . urls import patterns , url , include <EOL> from . views import empty_view <EOL> urlpatterns = patterns ( '<STR_LIT>' , <EOL> url ( r'<STR_LIT>' , empty_view , name = "<STR_LIT>" ) , <EOL> url ( r'<STR_LIT>' , empty_view , name = "<STR_LIT>" ) , <EOL> url ( r'<STR_LIT>' , empty_view ) , <EOL> ( r'<STR_LIT>' , include ( '<STR_LIT>' ) ) , <EOL> ) </s>
|
<s> import sys <EOL> from lib2to3 . main import main <EOL> sys . exit ( main ( "<STR_LIT>" ) ) </s>
|
<s> """<STR_LIT>""" <EOL> import datetime <EOL> from django . db import models <EOL> from django . core . exceptions import ImproperlyConfigured , ValidationError <EOL> from django . utils . encoding import smart_text , force_text <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils import timezone <EOL> from django . contrib . admin . util import ( get_model_from_relation , <EOL> reverse_field_path , get_limit_choices_to_from_path , prepare_lookup_value ) <EOL> from django . contrib . admin . options import IncorrectLookupParameters <EOL> class ListFilter ( object ) : <EOL> title = None <EOL> template = '<STR_LIT>' <EOL> def __init__ ( self , request , params , model , model_admin ) : <EOL> self . used_parameters = { } <EOL> if self . title is None : <EOL> raise ImproperlyConfigured ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . __class__ . __name__ ) <EOL> def has_output ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def choices ( self , cl ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def queryset ( self , request , queryset ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def expected_parameters ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class SimpleListFilter ( ListFilter ) : <EOL> parameter_name = None <EOL> def __init__ ( self , request , params , model , model_admin ) : <EOL> super ( SimpleListFilter , self ) . __init__ ( <EOL> request , params , model , model_admin ) <EOL> if self . parameter_name is None : <EOL> raise ImproperlyConfigured ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . __class__ . __name__ ) <EOL> lookup_choices = self . lookups ( request , model_admin ) <EOL> if lookup_choices is None : <EOL> lookup_choices = ( ) <EOL> self . lookup_choices = list ( lookup_choices ) <EOL> if self . parameter_name in params : <EOL> value = params . pop ( self . parameter_name ) <EOL> self . used_parameters [ self . parameter_name ] = value <EOL> def has_output ( self ) : <EOL> return len ( self . lookup_choices ) > <NUM_LIT:0> <EOL> def value ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . used_parameters . get ( self . parameter_name , None ) <EOL> def lookups ( self , request , model_admin ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def expected_parameters ( self ) : <EOL> return [ self . parameter_name ] <EOL> def choices ( self , cl ) : <EOL> yield { <EOL> '<STR_LIT>' : self . value ( ) is None , <EOL> '<STR_LIT>' : cl . get_query_string ( { } , [ self . parameter_name ] ) , <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> for lookup , title in self . lookup_choices : <EOL> yield { <EOL> '<STR_LIT>' : self . value ( ) == force_text ( lookup ) , <EOL> '<STR_LIT>' : cl . get_query_string ( { <EOL> self . parameter_name : lookup , <EOL> } , [ ] ) , <EOL> '<STR_LIT>' : title , <EOL> } <EOL> class FieldListFilter ( ListFilter ) : <EOL> _field_list_filters = [ ] <EOL> _take_priority_index = <NUM_LIT:0> <EOL> def __init__ ( self , field , request , params , model , model_admin , field_path ) : <EOL> self . field = field <EOL> self . field_path = field_path <EOL> self . title = getattr ( field , '<STR_LIT>' , field_path ) <EOL> super ( FieldListFilter , self ) . __init__ ( <EOL> request , params , model , model_admin ) <EOL> for p in self . expected_parameters ( ) : <EOL> if p in params : <EOL> value = params . pop ( p ) <EOL> self . used_parameters [ p ] = prepare_lookup_value ( p , value ) <EOL> def has_output ( self ) : <EOL> return True <EOL> def queryset ( self , request , queryset ) : <EOL> try : <EOL> return queryset . filter ( ** self . used_parameters ) <EOL> except ValidationError as e : <EOL> raise IncorrectLookupParameters ( e ) <EOL> @ classmethod <EOL> def register ( cls , test , list_filter_class , take_priority = False ) : <EOL> if take_priority : <EOL> cls . _field_list_filters . insert ( <EOL> cls . _take_priority_index , ( test , list_filter_class ) ) <EOL> cls . _take_priority_index += <NUM_LIT:1> <EOL> else : <EOL> cls . _field_list_filters . append ( ( test , list_filter_class ) ) <EOL> @ classmethod <EOL> def create ( cls , field , request , params , model , model_admin , field_path ) : <EOL> for test , list_filter_class in cls . _field_list_filters : <EOL> if not test ( field ) : <EOL> continue <EOL> return list_filter_class ( field , request , params , <EOL> model , model_admin , field_path = field_path ) <EOL> class RelatedFieldListFilter ( FieldListFilter ) : <EOL> def __init__ ( self , field , request , params , model , model_admin , field_path ) : <EOL> other_model = get_model_from_relation ( field ) <EOL> if hasattr ( field , '<STR_LIT>' ) : <EOL> rel_name = field . rel . get_related_field ( ) . name <EOL> else : <EOL> rel_name = other_model . _meta . pk . name <EOL> self . lookup_kwarg = '<STR_LIT>' % ( field_path , rel_name ) <EOL> self . lookup_kwarg_isnull = '<STR_LIT>' % field_path <EOL> self . lookup_val = request . GET . get ( self . lookup_kwarg , None ) <EOL> self . lookup_val_isnull = request . GET . get ( <EOL> self . lookup_kwarg_isnull , None ) <EOL> self . lookup_choices = field . get_choices ( include_blank = False ) <EOL> super ( RelatedFieldListFilter , self ) . __init__ ( <EOL> field , request , params , model , model_admin , field_path ) <EOL> if hasattr ( field , '<STR_LIT>' ) : <EOL> self . lookup_title = field . verbose_name <EOL> else : <EOL> self . lookup_title = other_model . _meta . verbose_name <EOL> self . title = self . lookup_title <EOL> def has_output ( self ) : <EOL> if ( isinstance ( self . field , models . related . RelatedObject ) <EOL> and self . field . field . null or hasattr ( self . field , '<STR_LIT>' ) <EOL> and self . field . null ) : <EOL> extra = <NUM_LIT:1> <EOL> else : <EOL> extra = <NUM_LIT:0> <EOL> return len ( self . lookup_choices ) + extra > <NUM_LIT:1> <EOL> def expected_parameters ( self ) : <EOL> return [ self . lookup_kwarg , self . lookup_kwarg_isnull ] <EOL> def choices ( self , cl ) : <EOL> from django . contrib . admin . views . main import EMPTY_CHANGELIST_VALUE <EOL> yield { <EOL> '<STR_LIT>' : self . lookup_val is None and not self . lookup_val_isnull , <EOL> '<STR_LIT>' : cl . get_query_string ( { } , <EOL> [ self . lookup_kwarg , self . lookup_kwarg_isnull ] ) , <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> for pk_val , val in self . lookup_choices : <EOL> yield { <EOL> '<STR_LIT>' : self . lookup_val == smart_text ( pk_val ) , <EOL> '<STR_LIT>' : cl . get_query_string ( { <EOL> self . lookup_kwarg : pk_val , <EOL> } , [ self . lookup_kwarg_isnull ] ) , <EOL> '<STR_LIT>' : val , <EOL> } <EOL> if ( isinstance ( self . field , models . related . RelatedObject ) <EOL> and self . field . field . null or hasattr ( self . field , '<STR_LIT>' ) <EOL> and self . field . null ) : <EOL> yield { <EOL> '<STR_LIT>' : bool ( self . lookup_val_isnull ) , <EOL> '<STR_LIT>' : cl . get_query_string ( { <EOL> self . lookup_kwarg_isnull : '<STR_LIT:True>' , <EOL> } , [ self . lookup_kwarg ] ) , <EOL> '<STR_LIT>' : EMPTY_CHANGELIST_VALUE , <EOL> } <EOL> FieldListFilter . register ( lambda f : ( <EOL> hasattr ( f , '<STR_LIT>' ) and bool ( f . rel ) or <EOL> isinstance ( f , models . related . RelatedObject ) ) , RelatedFieldListFilter ) <EOL> class BooleanFieldListFilter ( FieldListFilter ) : <EOL> def __init__ ( self , field , request , params , model , model_admin , field_path ) : <EOL> self . lookup_kwarg = '<STR_LIT>' % field_path <EOL> self . lookup_kwarg2 = '<STR_LIT>' % field_path <EOL> self . lookup_val = request . GET . get ( self . lookup_kwarg , None ) <EOL> self . lookup_val2 = request . GET . get ( self . lookup_kwarg2 , None ) <EOL> super ( BooleanFieldListFilter , self ) . __init__ ( field , <EOL> request , params , model , model_admin , field_path ) <EOL> def expected_parameters ( self ) : <EOL> return [ self . lookup_kwarg , self . lookup_kwarg2 ] <EOL> def choices ( self , cl ) : <EOL> for lookup , title in ( <EOL> ( None , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT:1>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT:0>' , _ ( '<STR_LIT>' ) ) ) : <EOL> yield { <EOL> '<STR_LIT>' : self . lookup_val == lookup and not self . lookup_val2 , <EOL> '<STR_LIT>' : cl . get_query_string ( { <EOL> self . lookup_kwarg : lookup , <EOL> } , [ self . lookup_kwarg2 ] ) , <EOL> '<STR_LIT>' : title , <EOL> } <EOL> if isinstance ( self . field , models . NullBooleanField ) : <EOL> yield { <EOL> '<STR_LIT>' : self . lookup_val2 == '<STR_LIT:True>' , <EOL> '<STR_LIT>' : cl . get_query_string ( { <EOL> self . lookup_kwarg2 : '<STR_LIT:True>' , <EOL> } , [ self . lookup_kwarg ] ) , <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> FieldListFilter . register ( lambda f : isinstance ( f , <EOL> ( models . BooleanField , models . NullBooleanField ) ) , BooleanFieldListFilter ) <EOL> class ChoicesFieldListFilter ( FieldListFilter ) : <EOL> def __init__ ( self , field , request , params , model , model_admin , field_path ) : <EOL> self . lookup_kwarg = '<STR_LIT>' % field_path <EOL> self . lookup_val = request . GET . get ( self . lookup_kwarg ) <EOL> super ( ChoicesFieldListFilter , self ) . __init__ ( <EOL> field , request , params , model , model_admin , field_path ) <EOL> def expected_parameters ( self ) : <EOL> return [ self . lookup_kwarg ] <EOL> def choices ( self , cl ) : <EOL> yield { <EOL> '<STR_LIT>' : self . lookup_val is None , <EOL> '<STR_LIT>' : cl . get_query_string ( { } , [ self . lookup_kwarg ] ) , <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) <EOL> } <EOL> for lookup , title in self . field . flatchoices : <EOL> yield { <EOL> '<STR_LIT>' : smart_text ( lookup ) == self . lookup_val , <EOL> '<STR_LIT>' : cl . get_query_string ( { <EOL> self . lookup_kwarg : lookup } ) , <EOL> '<STR_LIT>' : title , <EOL> } <EOL> FieldListFilter . register ( lambda f : bool ( f . choices ) , ChoicesFieldListFilter ) <EOL> class DateFieldListFilter ( FieldListFilter ) : <EOL> def __init__ ( self , field , request , params , model , model_admin , field_path ) : <EOL> self . field_generic = '<STR_LIT>' % field_path <EOL> self . date_params = dict ( [ ( k , v ) for k , v in params . items ( ) <EOL> if k . startswith ( self . field_generic ) ] ) <EOL> now = timezone . now ( ) <EOL> if timezone . is_aware ( now ) : <EOL> now = timezone . localtime ( now ) <EOL> if isinstance ( field , models . DateTimeField ) : <EOL> today = now . replace ( hour = <NUM_LIT:0> , minute = <NUM_LIT:0> , second = <NUM_LIT:0> , microsecond = <NUM_LIT:0> ) <EOL> else : <EOL> today = now . date ( ) <EOL> tomorrow = today + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> self . lookup_kwarg_since = '<STR_LIT>' % field_path <EOL> self . lookup_kwarg_until = '<STR_LIT>' % field_path <EOL> self . links = ( <EOL> ( _ ( '<STR_LIT>' ) , { } ) , <EOL> ( _ ( '<STR_LIT>' ) , { <EOL> self . lookup_kwarg_since : str ( today ) , <EOL> self . lookup_kwarg_until : str ( tomorrow ) , <EOL> } ) , <EOL> ( _ ( '<STR_LIT>' ) , { <EOL> self . lookup_kwarg_since : str ( today - datetime . timedelta ( days = <NUM_LIT:7> ) ) , <EOL> self . lookup_kwarg_until : str ( tomorrow ) , <EOL> } ) , <EOL> ( _ ( '<STR_LIT>' ) , { <EOL> self . lookup_kwarg_since : str ( today . replace ( day = <NUM_LIT:1> ) ) , <EOL> self . lookup_kwarg_until : str ( tomorrow ) , <EOL> } ) , <EOL> ( _ ( '<STR_LIT>' ) , { <EOL> self . lookup_kwarg_since : str ( today . replace ( month = <NUM_LIT:1> , day = <NUM_LIT:1> ) ) , <EOL> self . lookup_kwarg_until : str ( tomorrow ) , <EOL> } ) , <EOL> ) <EOL> super ( DateFieldListFilter , self ) . __init__ ( <EOL> field , request , params , model , model_admin , field_path ) <EOL> def expected_parameters ( self ) : <EOL> return [ self . lookup_kwarg_since , self . lookup_kwarg_until ] <EOL> def choices ( self , cl ) : <EOL> for title , param_dict in self . links : <EOL> yield { <EOL> '<STR_LIT>' : self . date_params == param_dict , <EOL> '<STR_LIT>' : cl . get_query_string ( <EOL> param_dict , [ self . field_generic ] ) , <EOL> '<STR_LIT>' : title , <EOL> } <EOL> FieldListFilter . register ( <EOL> lambda f : isinstance ( f , models . DateField ) , DateFieldListFilter ) <EOL> class AllValuesFieldListFilter ( FieldListFilter ) : <EOL> def __init__ ( self , field , request , params , model , model_admin , field_path ) : <EOL> self . lookup_kwarg = field_path <EOL> self . lookup_kwarg_isnull = '<STR_LIT>' % field_path <EOL> self . lookup_val = request . GET . get ( self . lookup_kwarg , None ) <EOL> self . lookup_val_isnull = request . GET . get ( self . lookup_kwarg_isnull , <EOL> None ) <EOL> parent_model , reverse_path = reverse_field_path ( model , field_path ) <EOL> queryset = parent_model . _default_manager . all ( ) <EOL> limit_choices_to = get_limit_choices_to_from_path ( model , field_path ) <EOL> queryset = queryset . filter ( limit_choices_to ) <EOL> self . lookup_choices = ( queryset <EOL> . distinct ( ) <EOL> . order_by ( field . name ) <EOL> . values_list ( field . name , flat = True ) ) <EOL> super ( AllValuesFieldListFilter , self ) . __init__ ( <EOL> field , request , params , model , model_admin , field_path ) <EOL> def expected_parameters ( self ) : <EOL> return [ self . lookup_kwarg , self . lookup_kwarg_isnull ] <EOL> def choices ( self , cl ) : <EOL> from django . contrib . admin . views . main import EMPTY_CHANGELIST_VALUE <EOL> yield { <EOL> '<STR_LIT>' : ( self . lookup_val is None <EOL> and self . lookup_val_isnull is None ) , <EOL> '<STR_LIT>' : cl . get_query_string ( { } , <EOL> [ self . lookup_kwarg , self . lookup_kwarg_isnull ] ) , <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> include_none = False <EOL> for val in self . lookup_choices : <EOL> if val is None : <EOL> include_none = True <EOL> continue <EOL> val = smart_text ( val ) <EOL> yield { <EOL> '<STR_LIT>' : self . lookup_val == val , <EOL> '<STR_LIT>' : cl . get_query_string ( { <EOL> self . lookup_kwarg : val , <EOL> } , [ self . lookup_kwarg_isnull ] ) , <EOL> '<STR_LIT>' : val , <EOL> } <EOL> if include_none : <EOL> yield { <EOL> '<STR_LIT>' : bool ( self . lookup_val_isnull ) , <EOL> '<STR_LIT>' : cl . get_query_string ( { <EOL> self . lookup_kwarg_isnull : '<STR_LIT:True>' , <EOL> } , [ self . lookup_kwarg ] ) , <EOL> '<STR_LIT>' : EMPTY_CHANGELIST_VALUE , <EOL> } <EOL> FieldListFilter . register ( lambda f : True , AllValuesFieldListFilter ) </s>
|
<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import getpass <EOL> import locale <EOL> import unicodedata <EOL> from django . contrib . auth import models as auth_app , get_user_model <EOL> from django . core import exceptions <EOL> from django . core . management . base import CommandError <EOL> from django . db import DEFAULT_DB_ALIAS , router <EOL> from django . db . models import get_models , signals <EOL> from django . utils import six <EOL> from django . utils . six . moves import input <EOL> def _get_permission_codename ( action , opts ) : <EOL> return '<STR_LIT>' % ( action , opts . object_name . lower ( ) ) <EOL> def _get_all_permissions ( opts , ctype ) : <EOL> """<STR_LIT>""" <EOL> builtin = _get_builtin_permissions ( opts ) <EOL> custom = list ( opts . permissions ) <EOL> _check_permission_clashing ( custom , builtin , ctype ) <EOL> return builtin + custom <EOL> def _get_builtin_permissions ( opts ) : <EOL> """<STR_LIT>""" <EOL> perms = [ ] <EOL> for action in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> perms . append ( ( _get_permission_codename ( action , opts ) , <EOL> '<STR_LIT>' % ( action , opts . verbose_name_raw ) ) ) <EOL> return perms <EOL> def _check_permission_clashing ( custom , builtin , ctype ) : <EOL> """<STR_LIT>""" <EOL> pool = set ( ) <EOL> builtin_codenames = set ( p [ <NUM_LIT:0> ] for p in builtin ) <EOL> for codename , _name in custom : <EOL> if codename in pool : <EOL> raise CommandError ( <EOL> "<STR_LIT>" % <EOL> ( codename , ctype . app_label , ctype . model_class ( ) . __name__ ) ) <EOL> elif codename in builtin_codenames : <EOL> raise CommandError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( codename , ctype . app_label , ctype . model_class ( ) . __name__ ) ) <EOL> pool . add ( codename ) <EOL> def create_permissions ( app , created_models , verbosity , db = DEFAULT_DB_ALIAS , ** kwargs ) : <EOL> if not router . allow_syncdb ( db , auth_app . Permission ) : <EOL> return <EOL> from django . contrib . contenttypes . models import ContentType <EOL> app_models = get_models ( app ) <EOL> searched_perms = list ( ) <EOL> ctypes = set ( ) <EOL> for klass in app_models : <EOL> ctype = ContentType . objects . db_manager ( db ) . get_for_model ( klass ) <EOL> ctypes . add ( ctype ) <EOL> for perm in _get_all_permissions ( klass . _meta , ctype ) : <EOL> searched_perms . append ( ( ctype , perm ) ) <EOL> all_perms = set ( auth_app . Permission . objects . using ( db ) . filter ( <EOL> content_type__in = ctypes , <EOL> ) . values_list ( <EOL> "<STR_LIT>" , "<STR_LIT>" <EOL> ) ) <EOL> perms = [ <EOL> auth_app . Permission ( codename = codename , name = name , content_type = ctype ) <EOL> for ctype , ( codename , name ) in searched_perms <EOL> if ( ctype . pk , codename ) not in all_perms <EOL> ] <EOL> auth_app . Permission . objects . using ( db ) . bulk_create ( perms ) <EOL> if verbosity >= <NUM_LIT:2> : <EOL> for perm in perms : <EOL> print ( "<STR_LIT>" % perm ) <EOL> def create_superuser ( app , created_models , verbosity , db , ** kwargs ) : <EOL> from django . core . management import call_command <EOL> UserModel = get_user_model ( ) <EOL> if UserModel in created_models and kwargs . get ( '<STR_LIT>' , True ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> confirm = input ( msg ) <EOL> while <NUM_LIT:1> : <EOL> if confirm not in ( '<STR_LIT:yes>' , '<STR_LIT>' ) : <EOL> confirm = input ( '<STR_LIT>' ) <EOL> continue <EOL> if confirm == '<STR_LIT:yes>' : <EOL> call_command ( "<STR_LIT>" , interactive = True , database = db ) <EOL> break <EOL> def get_system_username ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> result = getpass . getuser ( ) <EOL> except ( ImportError , KeyError ) : <EOL> return '<STR_LIT>' <EOL> if not six . PY3 : <EOL> default_locale = locale . getdefaultlocale ( ) [ <NUM_LIT:1> ] <EOL> if not default_locale : <EOL> return '<STR_LIT>' <EOL> try : <EOL> result = result . decode ( default_locale ) <EOL> except UnicodeDecodeError : <EOL> return '<STR_LIT>' <EOL> return result <EOL> def get_default_username ( check_db = True ) : <EOL> """<STR_LIT>""" <EOL> if auth_app . User . _meta . swapped : <EOL> return '<STR_LIT>' <EOL> default_username = get_system_username ( ) <EOL> try : <EOL> default_username = unicodedata . normalize ( '<STR_LIT>' , default_username ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) . decode ( '<STR_LIT:ascii>' ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) . lower ( ) <EOL> except UnicodeDecodeError : <EOL> return '<STR_LIT>' <EOL> try : <EOL> auth_app . User . _meta . get_field ( '<STR_LIT:username>' ) . run_validators ( default_username ) <EOL> except exceptions . ValidationError : <EOL> return '<STR_LIT>' <EOL> if check_db and default_username : <EOL> try : <EOL> auth_app . User . _default_manager . get ( username = default_username ) <EOL> except auth_app . User . DoesNotExist : <EOL> pass <EOL> else : <EOL> return '<STR_LIT>' <EOL> return default_username <EOL> signals . post_syncdb . connect ( create_permissions , <EOL> dispatch_uid = "<STR_LIT>" ) <EOL> signals . post_syncdb . connect ( create_superuser , <EOL> sender = auth_app , dispatch_uid = "<STR_LIT>" ) </s>
|
<s> from django . contrib . syndication . views import Feed <EOL> from django . contrib . sites . models import get_current_site <EOL> from django . contrib import comments <EOL> from django . utils . translation import ugettext as _ <EOL> class LatestCommentFeed ( Feed ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , request , * args , ** kwargs ) : <EOL> self . site = get_current_site ( request ) <EOL> return super ( LatestCommentFeed , self ) . __call__ ( request , * args , ** kwargs ) <EOL> def title ( self ) : <EOL> return _ ( "<STR_LIT>" ) % dict ( site_name = self . site . name ) <EOL> def link ( self ) : <EOL> return "<STR_LIT>" % ( self . site . domain ) <EOL> def description ( self ) : <EOL> return _ ( "<STR_LIT>" ) % dict ( site_name = self . site . name ) <EOL> def items ( self ) : <EOL> qs = comments . get_model ( ) . objects . filter ( <EOL> site__pk = self . site . pk , <EOL> is_public = True , <EOL> is_removed = False , <EOL> ) <EOL> return qs . order_by ( '<STR_LIT>' ) [ : <NUM_LIT> ] <EOL> def item_pubdate ( self , item ) : <EOL> return item . submit_date </s>
|
<s> import os <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . flatpages . models import FlatPage <EOL> from django . test import TestCase <EOL> from django . test . utils import override_settings <EOL> @ override_settings ( <EOL> LOGIN_URL = '<STR_LIT>' , <EOL> MIDDLEWARE_CLASSES = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> TEMPLATE_DIRS = ( <EOL> os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) , <EOL> ) , <EOL> SITE_ID = <NUM_LIT:1> , <EOL> ) <EOL> class FlatpageViewTests ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> urls = '<STR_LIT>' <EOL> def test_view_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_view_non_existent_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_view_authenticated_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertRedirects ( response , '<STR_LIT>' ) <EOL> User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_fallback_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_fallback_non_existent_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_view_flatpage_special_chars ( self ) : <EOL> "<STR_LIT>" <EOL> fp = FlatPage . objects . create ( <EOL> url = "<STR_LIT>" , <EOL> title = "<STR_LIT>" , <EOL> content = "<STR_LIT>" , <EOL> enable_comments = False , <EOL> registration_required = False , <EOL> ) <EOL> fp . sites . add ( settings . SITE_ID ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> @ override_settings ( <EOL> APPEND_SLASH = True , <EOL> LOGIN_URL = '<STR_LIT>' , <EOL> MIDDLEWARE_CLASSES = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> TEMPLATE_DIRS = ( <EOL> os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) , <EOL> ) , <EOL> SITE_ID = <NUM_LIT:1> , <EOL> ) <EOL> class FlatpageViewAppendSlashTests ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> urls = '<STR_LIT>' <EOL> def test_redirect_view_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertRedirects ( response , '<STR_LIT>' , status_code = <NUM_LIT> ) <EOL> def test_redirect_view_non_existent_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_redirect_fallback_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_redirect_fallback_non_existent_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_redirect_view_flatpage_special_chars ( self ) : <EOL> "<STR_LIT>" <EOL> fp = FlatPage . objects . create ( <EOL> url = "<STR_LIT>" , <EOL> title = "<STR_LIT>" , <EOL> content = "<STR_LIT>" , <EOL> enable_comments = False , <EOL> registration_required = False , <EOL> ) <EOL> fp . sites . add ( settings . SITE_ID ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertRedirects ( response , '<STR_LIT>' , status_code = <NUM_LIT> ) </s>
|
<s> from django . contrib . gis . gdal import OGRGeomType <EOL> from django . db . backends . sqlite3 . introspection import DatabaseIntrospection , FlexibleFieldLookupDict <EOL> from django . utils import six <EOL> class GeoFlexibleFieldLookupDict ( FlexibleFieldLookupDict ) : <EOL> """<STR_LIT>""" <EOL> base_data_types_reverse = FlexibleFieldLookupDict . base_data_types_reverse . copy ( ) <EOL> base_data_types_reverse . update ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> class SpatiaLiteIntrospection ( DatabaseIntrospection ) : <EOL> data_types_reverse = GeoFlexibleFieldLookupDict ( ) <EOL> def get_geometry_type ( self , table_name , geo_col ) : <EOL> cursor = self . connection . cursor ( ) <EOL> try : <EOL> cursor . execute ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ( table_name , geo_col ) ) <EOL> row = cursor . fetchone ( ) <EOL> if not row : <EOL> raise Exception ( '<STR_LIT>' % <EOL> ( table_name , geo_col ) ) <EOL> field_type = OGRGeomType ( row [ <NUM_LIT:2> ] ) . django <EOL> dim = row [ <NUM_LIT:0> ] <EOL> srid = row [ <NUM_LIT:1> ] <EOL> field_params = { } <EOL> if srid != <NUM_LIT> : <EOL> field_params [ '<STR_LIT>' ] = srid <EOL> if isinstance ( dim , six . string_types ) and '<STR_LIT>' in dim : <EOL> field_params [ '<STR_LIT>' ] = <NUM_LIT:3> <EOL> finally : <EOL> cursor . close ( ) <EOL> return field_type , field_params </s>
|
<s> from ctypes import c_char_p , c_double , c_int , c_void_p , POINTER <EOL> from django . contrib . gis . gdal . envelope import OGREnvelope <EOL> from django . contrib . gis . gdal . libgdal import lgdal <EOL> from django . contrib . gis . gdal . prototypes . errcheck import check_bool , check_envelope <EOL> from django . contrib . gis . gdal . prototypes . generation import ( const_string_output , <EOL> double_output , geom_output , int_output , srs_output , string_output , void_output ) <EOL> def env_func ( f , argtypes ) : <EOL> "<STR_LIT>" <EOL> f . argtypes = argtypes <EOL> f . restype = None <EOL> f . errcheck = check_envelope <EOL> return f <EOL> def pnt_func ( f ) : <EOL> "<STR_LIT>" <EOL> return double_output ( f , [ c_void_p , c_int ] ) <EOL> def topology_func ( f ) : <EOL> f . argtypes = [ c_void_p , c_void_p ] <EOL> f . restype = c_int <EOL> f . errchck = check_bool <EOL> return f <EOL> from_json = geom_output ( lgdal . OGR_G_CreateGeometryFromJson , [ c_char_p ] ) <EOL> to_json = string_output ( lgdal . OGR_G_ExportToJson , [ c_void_p ] , str_result = True , decoding = '<STR_LIT:ascii>' ) <EOL> to_kml = string_output ( lgdal . OGR_G_ExportToKML , [ c_void_p , c_char_p ] , str_result = True , decoding = '<STR_LIT:ascii>' ) <EOL> getx = pnt_func ( lgdal . OGR_G_GetX ) <EOL> gety = pnt_func ( lgdal . OGR_G_GetY ) <EOL> getz = pnt_func ( lgdal . OGR_G_GetZ ) <EOL> from_wkb = geom_output ( lgdal . OGR_G_CreateFromWkb , [ c_char_p , c_void_p , POINTER ( c_void_p ) , c_int ] , offset = - <NUM_LIT:2> ) <EOL> from_wkt = geom_output ( lgdal . OGR_G_CreateFromWkt , [ POINTER ( c_char_p ) , c_void_p , POINTER ( c_void_p ) ] , offset = - <NUM_LIT:1> ) <EOL> create_geom = geom_output ( lgdal . OGR_G_CreateGeometry , [ c_int ] ) <EOL> clone_geom = geom_output ( lgdal . OGR_G_Clone , [ c_void_p ] ) <EOL> get_geom_ref = geom_output ( lgdal . OGR_G_GetGeometryRef , [ c_void_p , c_int ] ) <EOL> get_boundary = geom_output ( lgdal . OGR_G_GetBoundary , [ c_void_p ] ) <EOL> geom_convex_hull = geom_output ( lgdal . OGR_G_ConvexHull , [ c_void_p ] ) <EOL> geom_diff = geom_output ( lgdal . OGR_G_Difference , [ c_void_p , c_void_p ] ) <EOL> geom_intersection = geom_output ( lgdal . OGR_G_Intersection , [ c_void_p , c_void_p ] ) <EOL> geom_sym_diff = geom_output ( lgdal . OGR_G_SymmetricDifference , [ c_void_p , c_void_p ] ) <EOL> geom_union = geom_output ( lgdal . OGR_G_Union , [ c_void_p , c_void_p ] ) <EOL> add_geom = void_output ( lgdal . OGR_G_AddGeometry , [ c_void_p , c_void_p ] ) <EOL> import_wkt = void_output ( lgdal . OGR_G_ImportFromWkt , [ c_void_p , POINTER ( c_char_p ) ] ) <EOL> destroy_geom = void_output ( lgdal . OGR_G_DestroyGeometry , [ c_void_p ] , errcheck = False ) <EOL> to_wkb = void_output ( lgdal . OGR_G_ExportToWkb , None , errcheck = True ) <EOL> to_wkt = string_output ( lgdal . OGR_G_ExportToWkt , [ c_void_p , POINTER ( c_char_p ) ] , decoding = '<STR_LIT:ascii>' ) <EOL> to_gml = string_output ( lgdal . OGR_G_ExportToGML , [ c_void_p ] , str_result = True , decoding = '<STR_LIT:ascii>' ) <EOL> get_wkbsize = int_output ( lgdal . OGR_G_WkbSize , [ c_void_p ] ) <EOL> assign_srs = void_output ( lgdal . OGR_G_AssignSpatialReference , [ c_void_p , c_void_p ] , errcheck = False ) <EOL> get_geom_srs = srs_output ( lgdal . OGR_G_GetSpatialReference , [ c_void_p ] ) <EOL> get_area = double_output ( lgdal . OGR_G_GetArea , [ c_void_p ] ) <EOL> get_centroid = void_output ( lgdal . OGR_G_Centroid , [ c_void_p , c_void_p ] ) <EOL> get_dims = int_output ( lgdal . OGR_G_GetDimension , [ c_void_p ] ) <EOL> get_coord_dim = int_output ( lgdal . OGR_G_GetCoordinateDimension , [ c_void_p ] ) <EOL> set_coord_dim = void_output ( lgdal . OGR_G_SetCoordinateDimension , [ c_void_p , c_int ] , errcheck = False ) <EOL> get_geom_count = int_output ( lgdal . OGR_G_GetGeometryCount , [ c_void_p ] ) <EOL> get_geom_name = const_string_output ( lgdal . OGR_G_GetGeometryName , [ c_void_p ] , decoding = '<STR_LIT:ascii>' ) <EOL> get_geom_type = int_output ( lgdal . OGR_G_GetGeometryType , [ c_void_p ] ) <EOL> get_point_count = int_output ( lgdal . OGR_G_GetPointCount , [ c_void_p ] ) <EOL> get_point = void_output ( lgdal . OGR_G_GetPoint , [ c_void_p , c_int , POINTER ( c_double ) , POINTER ( c_double ) , POINTER ( c_double ) ] , errcheck = False ) <EOL> geom_close_rings = void_output ( lgdal . OGR_G_CloseRings , [ c_void_p ] , errcheck = False ) <EOL> ogr_contains = topology_func ( lgdal . OGR_G_Contains ) <EOL> ogr_crosses = topology_func ( lgdal . OGR_G_Crosses ) <EOL> ogr_disjoint = topology_func ( lgdal . OGR_G_Disjoint ) <EOL> ogr_equals = topology_func ( lgdal . OGR_G_Equals ) <EOL> ogr_intersects = topology_func ( lgdal . OGR_G_Intersects ) <EOL> ogr_overlaps = topology_func ( lgdal . OGR_G_Overlaps ) <EOL> ogr_touches = topology_func ( lgdal . OGR_G_Touches ) <EOL> ogr_within = topology_func ( lgdal . OGR_G_Within ) <EOL> geom_transform = void_output ( lgdal . OGR_G_Transform , [ c_void_p , c_void_p ] ) <EOL> geom_transform_to = void_output ( lgdal . OGR_G_TransformTo , [ c_void_p , c_void_p ] ) <EOL> get_envelope = env_func ( lgdal . OGR_G_GetEnvelope , [ c_void_p , POINTER ( OGREnvelope ) ] ) </s>
|
<s> from __future__ import unicode_literals <EOL> import binascii <EOL> import unittest <EOL> from django . contrib . gis import memoryview <EOL> from django . contrib . gis . geos import GEOSGeometry , WKTReader , WKTWriter , WKBReader , WKBWriter , geos_version_info <EOL> from django . utils import six <EOL> class GEOSIOTest ( unittest . TestCase ) : <EOL> def test01_wktreader ( self ) : <EOL> wkt_r = WKTReader ( ) <EOL> wkt = '<STR_LIT>' <EOL> ref = GEOSGeometry ( wkt ) <EOL> g1 = wkt_r . read ( wkt . encode ( ) ) <EOL> g2 = wkt_r . read ( wkt ) <EOL> for geom in ( g1 , g2 ) : <EOL> self . assertEqual ( ref , geom ) <EOL> self . assertRaises ( TypeError , wkt_r . read , <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , wkt_r . read , memoryview ( b'<STR_LIT:foo>' ) ) <EOL> def test02_wktwriter ( self ) : <EOL> wkt_w = WKTWriter ( ) <EOL> self . assertRaises ( TypeError , wkt_w . _set_ptr , WKTReader . ptr_type ( ) ) <EOL> ref = GEOSGeometry ( '<STR_LIT>' ) <EOL> ref_wkt = '<STR_LIT>' <EOL> self . assertEqual ( ref_wkt , wkt_w . write ( ref ) . decode ( ) ) <EOL> def test03_wkbreader ( self ) : <EOL> wkb_r = WKBReader ( ) <EOL> hex = b'<STR_LIT>' <EOL> wkb = memoryview ( binascii . a2b_hex ( hex ) ) <EOL> ref = GEOSGeometry ( hex ) <EOL> g1 = wkb_r . read ( wkb ) <EOL> g2 = wkb_r . read ( hex ) <EOL> for geom in ( g1 , g2 ) : <EOL> self . assertEqual ( ref , geom ) <EOL> bad_input = ( <NUM_LIT:1> , <NUM_LIT> , None , False ) <EOL> for bad_wkb in bad_input : <EOL> self . assertRaises ( TypeError , wkb_r . read , bad_wkb ) <EOL> def test04_wkbwriter ( self ) : <EOL> wkb_w = WKBWriter ( ) <EOL> g = GEOSGeometry ( '<STR_LIT>' ) <EOL> hex1 = b'<STR_LIT>' <EOL> wkb1 = memoryview ( binascii . a2b_hex ( hex1 ) ) <EOL> hex2 = b'<STR_LIT>' <EOL> wkb2 = memoryview ( binascii . a2b_hex ( hex2 ) ) <EOL> self . assertEqual ( hex1 , wkb_w . write_hex ( g ) ) <EOL> self . assertEqual ( wkb1 , wkb_w . write ( g ) ) <EOL> for bad_byteorder in ( - <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT> , '<STR_LIT:foo>' , None ) : <EOL> self . assertRaises ( ValueError , wkb_w . _set_byteorder , bad_byteorder ) <EOL> wkb_w . byteorder = <NUM_LIT:0> <EOL> self . assertEqual ( hex2 , wkb_w . write_hex ( g ) ) <EOL> self . assertEqual ( wkb2 , wkb_w . write ( g ) ) <EOL> wkb_w . byteorder = <NUM_LIT:1> <EOL> g = GEOSGeometry ( '<STR_LIT>' ) <EOL> g . srid = <NUM_LIT> <EOL> hex3d = b'<STR_LIT>' <EOL> wkb3d = memoryview ( binascii . a2b_hex ( hex3d ) ) <EOL> hex3d_srid = b'<STR_LIT>' <EOL> wkb3d_srid = memoryview ( binascii . a2b_hex ( hex3d_srid ) ) <EOL> for bad_outdim in ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT> , '<STR_LIT:foo>' , None ) : <EOL> self . assertRaises ( ValueError , wkb_w . _set_outdim , bad_outdim ) <EOL> if not geos_version_info ( ) [ '<STR_LIT:version>' ] . startswith ( '<STR_LIT>' ) : <EOL> wkb_w . outdim = <NUM_LIT:3> <EOL> self . assertEqual ( hex3d , wkb_w . write_hex ( g ) ) <EOL> self . assertEqual ( wkb3d , wkb_w . write ( g ) ) <EOL> wkb_w . srid = True <EOL> self . assertEqual ( hex3d_srid , wkb_w . write_hex ( g ) ) <EOL> self . assertEqual ( wkb3d_srid , wkb_w . write ( g ) ) <EOL> def suite ( ) : <EOL> s = unittest . TestSuite ( ) <EOL> s . addTest ( unittest . makeSuite ( GEOSIOTest ) ) <EOL> return s <EOL> def run ( verbosity = <NUM_LIT:2> ) : <EOL> unittest . TextTestRunner ( verbosity = verbosity ) . run ( suite ( ) ) </s>
|
<s> from django . conf import settings <EOL> from django . db import DEFAULT_DB_ALIAS <EOL> def pass_test ( * args ) : return <EOL> def no_backend ( test_func , backend ) : <EOL> "<STR_LIT>" <EOL> if settings . DATABASES [ DEFAULT_DB_ALIAS ] [ '<STR_LIT>' ] . rsplit ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] == backend : <EOL> return pass_test <EOL> else : <EOL> return test_func <EOL> def no_oracle ( func ) : return no_backend ( func , '<STR_LIT>' ) <EOL> def no_postgis ( func ) : return no_backend ( func , '<STR_LIT>' ) <EOL> def no_mysql ( func ) : return no_backend ( func , '<STR_LIT>' ) <EOL> def no_spatialite ( func ) : return no_backend ( func , '<STR_LIT>' ) <EOL> _default_db = settings . DATABASES [ DEFAULT_DB_ALIAS ] [ '<STR_LIT>' ] . rsplit ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> oracle = _default_db == '<STR_LIT>' <EOL> postgis = _default_db == '<STR_LIT>' <EOL> mysql = _default_db == '<STR_LIT>' <EOL> spatialite = _default_db == '<STR_LIT>' <EOL> HAS_SPATIALREFSYS = True <EOL> if oracle and '<STR_LIT>' in settings . DATABASES [ DEFAULT_DB_ALIAS ] [ '<STR_LIT>' ] : <EOL> from django . contrib . gis . db . backends . oracle . models import SpatialRefSys <EOL> elif postgis : <EOL> from django . contrib . gis . db . backends . postgis . models import SpatialRefSys <EOL> elif spatialite : <EOL> from django . contrib . gis . db . backends . spatialite . models import SpatialRefSys <EOL> else : <EOL> HAS_SPATIALREFSYS = False <EOL> SpatialRefSys = None </s>
|
<s> from django . utils . translation import ugettext_lazy as _ <EOL> PROVINCE_CHOICES = ( <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ) </s>
|
<s> from django . contrib . messages import constants <EOL> from django . contrib . messages . tests . base import BaseTest <EOL> from django . contrib . messages . storage . base import Message <EOL> from django . contrib . messages . storage . session import SessionStorage <EOL> from django . utils . safestring import SafeData , mark_safe <EOL> def set_session_data ( storage , messages ) : <EOL> """<STR_LIT>""" <EOL> storage . request . session [ storage . session_key ] = messages <EOL> if hasattr ( storage , '<STR_LIT>' ) : <EOL> del storage . _loaded_data <EOL> def stored_session_messages_count ( storage ) : <EOL> data = storage . request . session . get ( storage . session_key , [ ] ) <EOL> return len ( data ) <EOL> class SessionTest ( BaseTest ) : <EOL> storage_class = SessionStorage <EOL> def get_request ( self ) : <EOL> self . session = { } <EOL> request = super ( SessionTest , self ) . get_request ( ) <EOL> request . session = self . session <EOL> return request <EOL> def stored_messages_count ( self , storage , response ) : <EOL> return stored_session_messages_count ( storage ) <EOL> def test_get ( self ) : <EOL> storage = self . storage_class ( self . get_request ( ) ) <EOL> example_messages = [ '<STR_LIT:test>' , '<STR_LIT>' ] <EOL> set_session_data ( storage , example_messages ) <EOL> self . assertEqual ( list ( storage ) , example_messages ) <EOL> def test_safedata ( self ) : <EOL> """<STR_LIT>""" <EOL> storage = self . get_storage ( ) <EOL> message = Message ( constants . DEBUG , mark_safe ( "<STR_LIT>" ) ) <EOL> set_session_data ( storage , [ message ] ) <EOL> self . assertIsInstance ( list ( storage ) [ <NUM_LIT:0> ] . message , SafeData ) </s>
|
<s> from optparse import make_option <EOL> from django . conf import settings <EOL> from django . core . management . commands . runserver import Command as RunserverCommand <EOL> from django . contrib . staticfiles . handlers import StaticFilesHandler <EOL> class Command ( RunserverCommand ) : <EOL> option_list = RunserverCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , action = "<STR_LIT>" , dest = '<STR_LIT>' , default = True , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> help = "<STR_LIT>" <EOL> def get_handler ( self , * args , ** options ) : <EOL> """<STR_LIT>""" <EOL> handler = super ( Command , self ) . get_handler ( * args , ** options ) <EOL> use_static_handler = options . get ( '<STR_LIT>' , True ) <EOL> insecure_serving = options . get ( '<STR_LIT>' , False ) <EOL> if use_static_handler and ( settings . DEBUG or insecure_serving ) : <EOL> return StaticFilesHandler ( handler ) <EOL> return handler </s>
|
<s> """<STR_LIT>""" <EOL> import smtplib <EOL> import ssl <EOL> import threading <EOL> from django . conf import settings <EOL> from django . core . mail . backends . base import BaseEmailBackend <EOL> from django . core . mail . utils import DNS_NAME <EOL> from django . core . mail . message import sanitize_address <EOL> from django . utils . encoding import force_bytes <EOL> class EmailBackend ( BaseEmailBackend ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , host = None , port = None , username = None , password = None , <EOL> use_tls = None , fail_silently = False , ** kwargs ) : <EOL> super ( EmailBackend , self ) . __init__ ( fail_silently = fail_silently ) <EOL> self . host = host or settings . EMAIL_HOST <EOL> self . port = port or settings . EMAIL_PORT <EOL> if username is None : <EOL> self . username = settings . EMAIL_HOST_USER <EOL> else : <EOL> self . username = username <EOL> if password is None : <EOL> self . password = settings . EMAIL_HOST_PASSWORD <EOL> else : <EOL> self . password = password <EOL> if use_tls is None : <EOL> self . use_tls = settings . EMAIL_USE_TLS <EOL> else : <EOL> self . use_tls = use_tls <EOL> self . connection = None <EOL> self . _lock = threading . RLock ( ) <EOL> def open ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . connection : <EOL> return False <EOL> try : <EOL> self . connection = smtplib . SMTP ( self . host , self . port , <EOL> local_hostname = DNS_NAME . get_fqdn ( ) ) <EOL> if self . use_tls : <EOL> self . connection . ehlo ( ) <EOL> self . connection . starttls ( ) <EOL> self . connection . ehlo ( ) <EOL> if self . username and self . password : <EOL> self . connection . login ( self . username , self . password ) <EOL> return True <EOL> except : <EOL> if not self . fail_silently : <EOL> raise <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . connection is None : <EOL> return <EOL> try : <EOL> try : <EOL> self . connection . quit ( ) <EOL> except ( ssl . SSLError , smtplib . SMTPServerDisconnected ) : <EOL> self . connection . close ( ) <EOL> except : <EOL> if self . fail_silently : <EOL> return <EOL> raise <EOL> finally : <EOL> self . connection = None <EOL> def send_messages ( self , email_messages ) : <EOL> """<STR_LIT>""" <EOL> if not email_messages : <EOL> return <EOL> with self . _lock : <EOL> new_conn_created = self . open ( ) <EOL> if not self . connection : <EOL> return <EOL> num_sent = <NUM_LIT:0> <EOL> for message in email_messages : <EOL> sent = self . _send ( message ) <EOL> if sent : <EOL> num_sent += <NUM_LIT:1> <EOL> if new_conn_created : <EOL> self . close ( ) <EOL> return num_sent <EOL> def _send ( self , email_message ) : <EOL> """<STR_LIT>""" <EOL> if not email_message . recipients ( ) : <EOL> return False <EOL> from_email = sanitize_address ( email_message . from_email , email_message . encoding ) <EOL> recipients = [ sanitize_address ( addr , email_message . encoding ) <EOL> for addr in email_message . recipients ( ) ] <EOL> message = email_message . message ( ) <EOL> charset = message . get_charset ( ) . get_output_charset ( ) if message . get_charset ( ) else '<STR_LIT:utf-8>' <EOL> try : <EOL> self . connection . sendmail ( from_email , recipients , <EOL> force_bytes ( message . as_string ( ) , charset ) ) <EOL> except : <EOL> if not self . fail_silently : <EOL> raise <EOL> return False <EOL> return True </s>
|
<s> """<STR_LIT>""" <EOL> from django . db import models <EOL> from django . utils . encoding import smart_text <EOL> from django . utils import six <EOL> class SerializerDoesNotExist ( KeyError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SerializationError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DeserializationError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class Serializer ( object ) : <EOL> """<STR_LIT>""" <EOL> internal_use_only = False <EOL> def serialize ( self , queryset , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . options = options <EOL> self . stream = options . pop ( "<STR_LIT>" , six . StringIO ( ) ) <EOL> self . selected_fields = options . pop ( "<STR_LIT>" , None ) <EOL> self . use_natural_keys = options . pop ( "<STR_LIT>" , False ) <EOL> self . start_serialization ( ) <EOL> self . first = True <EOL> for obj in queryset : <EOL> self . start_object ( obj ) <EOL> concrete_model = obj . _meta . concrete_model <EOL> for field in concrete_model . _meta . local_fields : <EOL> if field . serialize : <EOL> if field . rel is None : <EOL> if self . selected_fields is None or field . attname in self . selected_fields : <EOL> self . handle_field ( obj , field ) <EOL> else : <EOL> if self . selected_fields is None or field . attname [ : - <NUM_LIT:3> ] in self . selected_fields : <EOL> self . handle_fk_field ( obj , field ) <EOL> for field in concrete_model . _meta . many_to_many : <EOL> if field . serialize : <EOL> if self . selected_fields is None or field . attname in self . selected_fields : <EOL> self . handle_m2m_field ( obj , field ) <EOL> self . end_object ( obj ) <EOL> if self . first : <EOL> self . first = False <EOL> self . end_serialization ( ) <EOL> return self . getvalue ( ) <EOL> def start_serialization ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def end_serialization ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def start_object ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def end_object ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def handle_field ( self , obj , field ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def handle_fk_field ( self , obj , field ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def handle_m2m_field ( self , obj , field ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def getvalue ( self ) : <EOL> """<STR_LIT>""" <EOL> if callable ( getattr ( self . stream , '<STR_LIT>' , None ) ) : <EOL> return self . stream . getvalue ( ) <EOL> class Deserializer ( six . Iterator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , stream_or_string , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . options = options <EOL> if isinstance ( stream_or_string , six . string_types ) : <EOL> self . stream = six . StringIO ( stream_or_string ) <EOL> else : <EOL> self . stream = stream_or_string <EOL> models . get_apps ( ) <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def __next__ ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class DeserializedObject ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , obj , m2m_data = None ) : <EOL> self . object = obj <EOL> self . m2m_data = m2m_data <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . object . _meta . app_label , self . object . _meta . object_name , self . object . pk ) <EOL> def save ( self , save_m2m = True , using = None ) : <EOL> models . Model . save_base ( self . object , using = using , raw = True ) <EOL> if self . m2m_data and save_m2m : <EOL> for accessor_name , object_list in self . m2m_data . items ( ) : <EOL> setattr ( self . object , accessor_name , object_list ) <EOL> self . m2m_data = None </s>
|
<s> import re <EOL> from django . db . backends import BaseDatabaseIntrospection <EOL> field_size_re = re . compile ( r'<STR_LIT>' ) <EOL> def get_field_size ( name ) : <EOL> """<STR_LIT>""" <EOL> m = field_size_re . search ( name ) <EOL> return int ( m . group ( <NUM_LIT:1> ) ) if m else None <EOL> class FlexibleFieldLookupDict ( object ) : <EOL> base_data_types_reverse = { <EOL> '<STR_LIT:bool>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:int>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:text>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:date>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:time>' : '<STR_LIT>' , <EOL> } <EOL> def __getitem__ ( self , key ) : <EOL> key = key . lower ( ) <EOL> try : <EOL> return self . base_data_types_reverse [ key ] <EOL> except KeyError : <EOL> size = get_field_size ( key ) <EOL> if size is not None : <EOL> return ( '<STR_LIT>' , { '<STR_LIT:max_length>' : size } ) <EOL> raise KeyError <EOL> class DatabaseIntrospection ( BaseDatabaseIntrospection ) : <EOL> data_types_reverse = FlexibleFieldLookupDict ( ) <EOL> def get_table_list ( self , cursor ) : <EOL> "<STR_LIT>" <EOL> cursor . execute ( """<STR_LIT>""" ) <EOL> return [ row [ <NUM_LIT:0> ] for row in cursor . fetchall ( ) ] <EOL> def get_table_description ( self , cursor , table_name ) : <EOL> "<STR_LIT>" <EOL> return [ ( info [ '<STR_LIT:name>' ] , info [ '<STR_LIT:type>' ] , None , info [ '<STR_LIT:size>' ] , None , None , <EOL> info [ '<STR_LIT>' ] ) for info in self . _table_info ( cursor , table_name ) ] <EOL> def get_relations ( self , cursor , table_name ) : <EOL> """<STR_LIT>""" <EOL> relations = { } <EOL> cursor . execute ( "<STR_LIT>" , [ table_name , "<STR_LIT>" ] ) <EOL> results = cursor . fetchone ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> results = results [ results . index ( '<STR_LIT:(>' ) + <NUM_LIT:1> : results . rindex ( '<STR_LIT:)>' ) ] <EOL> for field_index , field_desc in enumerate ( results . split ( '<STR_LIT:U+002C>' ) ) : <EOL> field_desc = field_desc . strip ( ) <EOL> if field_desc . startswith ( "<STR_LIT>" ) : <EOL> continue <EOL> m = re . search ( '<STR_LIT>' , field_desc , re . I ) <EOL> if not m : <EOL> continue <EOL> table , column = [ s . strip ( '<STR_LIT:">' ) for s in m . groups ( ) ] <EOL> cursor . execute ( "<STR_LIT>" , [ table ] ) <EOL> result = cursor . fetchall ( ) [ <NUM_LIT:0> ] <EOL> other_table_results = result [ <NUM_LIT:0> ] . strip ( ) <EOL> li , ri = other_table_results . index ( '<STR_LIT:(>' ) , other_table_results . rindex ( '<STR_LIT:)>' ) <EOL> other_table_results = other_table_results [ li + <NUM_LIT:1> : ri ] <EOL> for other_index , other_desc in enumerate ( other_table_results . split ( '<STR_LIT:U+002C>' ) ) : <EOL> other_desc = other_desc . strip ( ) <EOL> if other_desc . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> name = other_desc . split ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . strip ( '<STR_LIT:">' ) <EOL> if name == column : <EOL> relations [ field_index ] = ( other_index , table ) <EOL> break <EOL> return relations <EOL> def get_key_columns ( self , cursor , table_name ) : <EOL> """<STR_LIT>""" <EOL> key_columns = [ ] <EOL> cursor . execute ( "<STR_LIT>" , [ table_name , "<STR_LIT>" ] ) <EOL> results = cursor . fetchone ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> results = results [ results . index ( '<STR_LIT:(>' ) + <NUM_LIT:1> : results . rindex ( '<STR_LIT:)>' ) ] <EOL> for field_index , field_desc in enumerate ( results . split ( '<STR_LIT:U+002C>' ) ) : <EOL> field_desc = field_desc . strip ( ) <EOL> if field_desc . startswith ( "<STR_LIT>" ) : <EOL> continue <EOL> m = re . search ( '<STR_LIT>' , field_desc , re . I ) <EOL> if not m : <EOL> continue <EOL> key_columns . append ( tuple ( [ s . strip ( '<STR_LIT:">' ) for s in m . groups ( ) ] ) ) <EOL> return key_columns <EOL> def get_indexes ( self , cursor , table_name ) : <EOL> indexes = { } <EOL> for info in self . _table_info ( cursor , table_name ) : <EOL> if info [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> indexes [ info [ '<STR_LIT:name>' ] ] = { '<STR_LIT:primary_key>' : True , <EOL> '<STR_LIT>' : False } <EOL> cursor . execute ( '<STR_LIT>' % self . connection . ops . quote_name ( table_name ) ) <EOL> for index , unique in [ ( field [ <NUM_LIT:1> ] , field [ <NUM_LIT:2> ] ) for field in cursor . fetchall ( ) ] : <EOL> cursor . execute ( '<STR_LIT>' % self . connection . ops . quote_name ( index ) ) <EOL> info = cursor . fetchall ( ) <EOL> if len ( info ) != <NUM_LIT:1> : <EOL> continue <EOL> name = info [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> indexes [ name ] = { '<STR_LIT:primary_key>' : False , <EOL> '<STR_LIT>' : unique } <EOL> return indexes <EOL> def get_primary_key_column ( self , cursor , table_name ) : <EOL> """<STR_LIT>""" <EOL> cursor . execute ( "<STR_LIT>" , [ table_name , "<STR_LIT>" ] ) <EOL> results = cursor . fetchone ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> results = results [ results . index ( '<STR_LIT:(>' ) + <NUM_LIT:1> : results . rindex ( '<STR_LIT:)>' ) ] <EOL> for field_desc in results . split ( '<STR_LIT:U+002C>' ) : <EOL> field_desc = field_desc . strip ( ) <EOL> m = re . search ( '<STR_LIT>' , field_desc ) <EOL> if m : <EOL> return m . groups ( ) [ <NUM_LIT:0> ] <EOL> return None <EOL> def _table_info ( self , cursor , name ) : <EOL> cursor . execute ( '<STR_LIT>' % self . connection . ops . quote_name ( name ) ) <EOL> return [ { '<STR_LIT:name>' : field [ <NUM_LIT:1> ] , <EOL> '<STR_LIT:type>' : field [ <NUM_LIT:2> ] , <EOL> '<STR_LIT:size>' : get_field_size ( field [ <NUM_LIT:2> ] ) , <EOL> '<STR_LIT>' : not field [ <NUM_LIT:3> ] , <EOL> '<STR_LIT>' : field [ <NUM_LIT:5> ] <EOL> } for field in cursor . fetchall ( ) ] </s>
|
<s> """<STR_LIT>""" <EOL> import traceback <EOL> import weakref <EOL> def safeRef ( target , onDelete = None ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( target , '<STR_LIT>' ) : <EOL> if target . __self__ is not None : <EOL> assert hasattr ( target , '<STR_LIT>' ) , """<STR_LIT>""" % ( target , ) <EOL> reference = get_bound_method_weakref ( <EOL> target = target , <EOL> onDelete = onDelete <EOL> ) <EOL> return reference <EOL> if callable ( onDelete ) : <EOL> return weakref . ref ( target , onDelete ) <EOL> else : <EOL> return weakref . ref ( target ) <EOL> class BoundMethodWeakref ( object ) : <EOL> """<STR_LIT>""" <EOL> _allInstances = weakref . WeakValueDictionary ( ) <EOL> def __new__ ( cls , target , onDelete = None , * arguments , ** named ) : <EOL> """<STR_LIT>""" <EOL> key = cls . calculateKey ( target ) <EOL> current = cls . _allInstances . get ( key ) <EOL> if current is not None : <EOL> current . deletionMethods . append ( onDelete ) <EOL> return current <EOL> else : <EOL> base = super ( BoundMethodWeakref , cls ) . __new__ ( cls ) <EOL> cls . _allInstances [ key ] = base <EOL> base . __init__ ( target , onDelete , * arguments , ** named ) <EOL> return base <EOL> def __init__ ( self , target , onDelete = None ) : <EOL> """<STR_LIT>""" <EOL> def remove ( weak , self = self ) : <EOL> """<STR_LIT>""" <EOL> methods = self . deletionMethods [ : ] <EOL> del self . deletionMethods [ : ] <EOL> try : <EOL> del self . __class__ . _allInstances [ self . key ] <EOL> except KeyError : <EOL> pass <EOL> for function in methods : <EOL> try : <EOL> if callable ( function ) : <EOL> function ( self ) <EOL> except Exception as e : <EOL> try : <EOL> traceback . print_exc ( ) <EOL> except AttributeError : <EOL> print ( '<STR_LIT>' % ( <EOL> self , function , e ) <EOL> ) <EOL> self . deletionMethods = [ onDelete ] <EOL> self . key = self . calculateKey ( target ) <EOL> self . weakSelf = weakref . ref ( target . __self__ , remove ) <EOL> self . weakFunc = weakref . ref ( target . __func__ , remove ) <EOL> self . selfName = str ( target . __self__ ) <EOL> self . funcName = str ( target . __func__ . __name__ ) <EOL> def calculateKey ( cls , target ) : <EOL> """<STR_LIT>""" <EOL> return ( id ( target . __self__ ) , id ( target . __func__ ) ) <EOL> calculateKey = classmethod ( calculateKey ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return """<STR_LIT>""" % ( <EOL> self . __class__ . __name__ , <EOL> self . selfName , <EOL> self . funcName , <EOL> ) <EOL> __repr__ = __str__ <EOL> def __hash__ ( self ) : <EOL> return hash ( self . key ) <EOL> def __bool__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self ( ) is not None <EOL> def __nonzero__ ( self ) : <EOL> return type ( self ) . __bool__ ( self ) <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( other , self . __class__ ) : <EOL> return self . __class__ == type ( other ) <EOL> return self . key == other . key <EOL> def __call__ ( self ) : <EOL> """<STR_LIT>""" <EOL> target = self . weakSelf ( ) <EOL> if target is not None : <EOL> function = self . weakFunc ( ) <EOL> if function is not None : <EOL> return function . __get__ ( target ) <EOL> return None <EOL> class BoundNonDescriptorMethodWeakref ( BoundMethodWeakref ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , target , onDelete = None ) : <EOL> """<STR_LIT>""" <EOL> assert getattr ( target . __self__ , target . __name__ ) == target , ( "<STR_LIT>" % <EOL> ( target , target . __name__ , target . __self__ ) ) <EOL> super ( BoundNonDescriptorMethodWeakref , self ) . __init__ ( target , onDelete ) <EOL> def __call__ ( self ) : <EOL> """<STR_LIT>""" <EOL> target = self . weakSelf ( ) <EOL> if target is not None : <EOL> function = self . weakFunc ( ) <EOL> if function is not None : <EOL> return getattr ( target , function . __name__ ) <EOL> return None <EOL> def get_bound_method_weakref ( target , onDelete ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( target , '<STR_LIT>' ) : <EOL> return BoundMethodWeakref ( target = target , onDelete = onDelete ) <EOL> else : <EOL> return BoundNonDescriptorMethodWeakref ( target = target , onDelete = onDelete ) </s>
|
<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import sys <EOL> import re <EOL> from datetime import datetime <EOL> from itertools import groupby , cycle as itertools_cycle <EOL> from django . conf import settings <EOL> from django . template . base import ( Node , NodeList , Template , Context , Library , <EOL> TemplateSyntaxError , VariableDoesNotExist , InvalidTemplateLibrary , <EOL> BLOCK_TAG_START , BLOCK_TAG_END , VARIABLE_TAG_START , VARIABLE_TAG_END , <EOL> SINGLE_BRACE_START , SINGLE_BRACE_END , COMMENT_TAG_START , COMMENT_TAG_END , <EOL> VARIABLE_ATTRIBUTE_SEPARATOR , get_library , token_kwargs , kwarg_re ) <EOL> from django . template . smartif import IfParser , Literal <EOL> from django . template . defaultfilters import date <EOL> from django . utils . encoding import smart_text <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . html import format_html <EOL> from django . utils import six <EOL> from django . utils import timezone <EOL> register = Library ( ) <EOL> class AutoEscapeControlNode ( Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , setting , nodelist ) : <EOL> self . setting , self . nodelist = setting , nodelist <EOL> def render ( self , context ) : <EOL> old_setting = context . autoescape <EOL> context . autoescape = self . setting <EOL> output = self . nodelist . render ( context ) <EOL> context . autoescape = old_setting <EOL> if self . setting : <EOL> return mark_safe ( output ) <EOL> else : <EOL> return output <EOL> class CommentNode ( Node ) : <EOL> def render ( self , context ) : <EOL> return '<STR_LIT>' <EOL> class CsrfTokenNode ( Node ) : <EOL> def render ( self , context ) : <EOL> csrf_token = context . get ( '<STR_LIT>' , None ) <EOL> if csrf_token : <EOL> if csrf_token == '<STR_LIT>' : <EOL> return format_html ( "<STR_LIT>" ) <EOL> else : <EOL> return format_html ( "<STR_LIT>" , csrf_token ) <EOL> else : <EOL> from django . conf import settings <EOL> if settings . DEBUG : <EOL> import warnings <EOL> warnings . warn ( "<STR_LIT>" ) <EOL> return '<STR_LIT>' <EOL> class CycleNode ( Node ) : <EOL> def __init__ ( self , cyclevars , variable_name = None , silent = False ) : <EOL> self . cyclevars = cyclevars <EOL> self . variable_name = variable_name <EOL> self . silent = silent <EOL> def render ( self , context ) : <EOL> if self not in context . render_context : <EOL> context . render_context [ self ] = itertools_cycle ( self . cyclevars ) <EOL> cycle_iter = context . render_context [ self ] <EOL> value = next ( cycle_iter ) . resolve ( context ) <EOL> if self . variable_name : <EOL> context [ self . variable_name ] = value <EOL> if self . silent : <EOL> return '<STR_LIT>' <EOL> return value <EOL> class DebugNode ( Node ) : <EOL> def render ( self , context ) : <EOL> from pprint import pformat <EOL> output = [ pformat ( val ) for val in context ] <EOL> output . append ( '<STR_LIT>' ) <EOL> output . append ( pformat ( sys . modules ) ) <EOL> return '<STR_LIT>' . join ( output ) <EOL> class FilterNode ( Node ) : <EOL> def __init__ ( self , filter_expr , nodelist ) : <EOL> self . filter_expr , self . nodelist = filter_expr , nodelist <EOL> def render ( self , context ) : <EOL> output = self . nodelist . render ( context ) <EOL> context . update ( { '<STR_LIT>' : output } ) <EOL> filtered = self . filter_expr . resolve ( context ) <EOL> context . pop ( ) <EOL> return filtered <EOL> class FirstOfNode ( Node ) : <EOL> def __init__ ( self , vars ) : <EOL> self . vars = vars <EOL> def render ( self , context ) : <EOL> for var in self . vars : <EOL> value = var . resolve ( context , True ) <EOL> if value : <EOL> return smart_text ( value ) <EOL> return '<STR_LIT>' <EOL> class ForNode ( Node ) : <EOL> child_nodelists = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , loopvars , sequence , is_reversed , nodelist_loop , nodelist_empty = None ) : <EOL> self . loopvars , self . sequence = loopvars , sequence <EOL> self . is_reversed = is_reversed <EOL> self . nodelist_loop = nodelist_loop <EOL> if nodelist_empty is None : <EOL> self . nodelist_empty = NodeList ( ) <EOL> else : <EOL> self . nodelist_empty = nodelist_empty <EOL> def __repr__ ( self ) : <EOL> reversed_text = self . is_reversed and '<STR_LIT>' or '<STR_LIT>' <EOL> return "<STR_LIT>" % ( '<STR_LIT:U+002CU+0020>' . join ( self . loopvars ) , self . sequence , len ( self . nodelist_loop ) , <EOL> reversed_text ) <EOL> def __iter__ ( self ) : <EOL> for node in self . nodelist_loop : <EOL> yield node <EOL> for node in self . nodelist_empty : <EOL> yield node <EOL> def render ( self , context ) : <EOL> if '<STR_LIT>' in context : <EOL> parentloop = context [ '<STR_LIT>' ] <EOL> else : <EOL> parentloop = { } <EOL> context . push ( ) <EOL> try : <EOL> values = self . sequence . resolve ( context , True ) <EOL> except VariableDoesNotExist : <EOL> values = [ ] <EOL> if values is None : <EOL> values = [ ] <EOL> if not hasattr ( values , '<STR_LIT>' ) : <EOL> values = list ( values ) <EOL> len_values = len ( values ) <EOL> if len_values < <NUM_LIT:1> : <EOL> context . pop ( ) <EOL> return self . nodelist_empty . render ( context ) <EOL> nodelist = NodeList ( ) <EOL> if self . is_reversed : <EOL> values = reversed ( values ) <EOL> unpack = len ( self . loopvars ) > <NUM_LIT:1> <EOL> loop_dict = context [ '<STR_LIT>' ] = { '<STR_LIT>' : parentloop } <EOL> for i , item in enumerate ( values ) : <EOL> loop_dict [ '<STR_LIT>' ] = i <EOL> loop_dict [ '<STR_LIT>' ] = i + <NUM_LIT:1> <EOL> loop_dict [ '<STR_LIT>' ] = len_values - i <EOL> loop_dict [ '<STR_LIT>' ] = len_values - i - <NUM_LIT:1> <EOL> loop_dict [ '<STR_LIT>' ] = ( i == <NUM_LIT:0> ) <EOL> loop_dict [ '<STR_LIT>' ] = ( i == len_values - <NUM_LIT:1> ) <EOL> pop_context = False <EOL> if unpack : <EOL> try : <EOL> unpacked_vars = dict ( zip ( self . loopvars , item ) ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> pop_context = True <EOL> context . update ( unpacked_vars ) <EOL> else : <EOL> context [ self . loopvars [ <NUM_LIT:0> ] ] = item <EOL> if settings . TEMPLATE_DEBUG : <EOL> for node in self . nodelist_loop : <EOL> try : <EOL> nodelist . append ( node . render ( context ) ) <EOL> except Exception as e : <EOL> if not hasattr ( e , '<STR_LIT>' ) : <EOL> e . django_template_source = node . source <EOL> raise <EOL> else : <EOL> for node in self . nodelist_loop : <EOL> nodelist . append ( node . render ( context ) ) <EOL> if pop_context : <EOL> context . pop ( ) <EOL> context . pop ( ) <EOL> return nodelist . render ( context ) <EOL> class IfChangedNode ( Node ) : <EOL> child_nodelists = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , nodelist_true , nodelist_false , * varlist ) : <EOL> self . nodelist_true , self . nodelist_false = nodelist_true , nodelist_false <EOL> self . _last_seen = None <EOL> self . _varlist = varlist <EOL> self . _id = str ( id ( self ) ) <EOL> def render ( self , context ) : <EOL> if '<STR_LIT>' in context and self . _id not in context [ '<STR_LIT>' ] : <EOL> self . _last_seen = None <EOL> context [ '<STR_LIT>' ] [ self . _id ] = <NUM_LIT:1> <EOL> try : <EOL> if self . _varlist : <EOL> compare_to = [ var . resolve ( context , True ) for var in self . _varlist ] <EOL> else : <EOL> compare_to = self . nodelist_true . render ( context ) <EOL> except VariableDoesNotExist : <EOL> compare_to = None <EOL> if compare_to != self . _last_seen : <EOL> self . _last_seen = compare_to <EOL> content = self . nodelist_true . render ( context ) <EOL> return content <EOL> elif self . nodelist_false : <EOL> return self . nodelist_false . render ( context ) <EOL> return '<STR_LIT>' <EOL> class IfEqualNode ( Node ) : <EOL> child_nodelists = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , var1 , var2 , nodelist_true , nodelist_false , negate ) : <EOL> self . var1 , self . var2 = var1 , var2 <EOL> self . nodelist_true , self . nodelist_false = nodelist_true , nodelist_false <EOL> self . negate = negate <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def render ( self , context ) : <EOL> val1 = self . var1 . resolve ( context , True ) <EOL> val2 = self . var2 . resolve ( context , True ) <EOL> if ( self . negate and val1 != val2 ) or ( not self . negate and val1 == val2 ) : <EOL> return self . nodelist_true . render ( context ) <EOL> return self . nodelist_false . render ( context ) <EOL> class IfNode ( Node ) : <EOL> def __init__ ( self , conditions_nodelists ) : <EOL> self . conditions_nodelists = conditions_nodelists <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def __iter__ ( self ) : <EOL> for _ , nodelist in self . conditions_nodelists : <EOL> for node in nodelist : <EOL> yield node <EOL> @ property <EOL> def nodelist ( self ) : <EOL> return NodeList ( node for _ , nodelist in self . conditions_nodelists for node in nodelist ) <EOL> def render ( self , context ) : <EOL> for condition , nodelist in self . conditions_nodelists : <EOL> if condition is not None : <EOL> try : <EOL> match = condition . eval ( context ) <EOL> except VariableDoesNotExist : <EOL> match = None <EOL> else : <EOL> match = True <EOL> if match : <EOL> return nodelist . render ( context ) <EOL> return '<STR_LIT>' <EOL> class RegroupNode ( Node ) : <EOL> def __init__ ( self , target , expression , var_name ) : <EOL> self . target , self . expression = target , expression <EOL> self . var_name = var_name <EOL> def resolve_expression ( self , obj , context ) : <EOL> context [ self . var_name ] = obj <EOL> return self . expression . resolve ( context , True ) <EOL> def render ( self , context ) : <EOL> obj_list = self . target . resolve ( context , True ) <EOL> if obj_list == None : <EOL> context [ self . var_name ] = [ ] <EOL> return '<STR_LIT>' <EOL> context [ self . var_name ] = [ <EOL> { '<STR_LIT>' : key , '<STR_LIT:list>' : list ( val ) } <EOL> for key , val in <EOL> groupby ( obj_list , lambda obj : self . resolve_expression ( obj , context ) ) <EOL> ] <EOL> return '<STR_LIT>' <EOL> def include_is_allowed ( filepath ) : <EOL> for root in settings . ALLOWED_INCLUDE_ROOTS : <EOL> if filepath . startswith ( root ) : <EOL> return True <EOL> return False <EOL> class SsiNode ( Node ) : <EOL> def __init__ ( self , filepath , parsed ) : <EOL> self . filepath = filepath <EOL> self . parsed = parsed <EOL> def render ( self , context ) : <EOL> filepath = self . filepath . resolve ( context ) <EOL> if not include_is_allowed ( filepath ) : <EOL> if settings . DEBUG : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return '<STR_LIT>' <EOL> try : <EOL> with open ( filepath , '<STR_LIT:r>' ) as fp : <EOL> output = fp . read ( ) <EOL> except IOError : <EOL> output = '<STR_LIT>' <EOL> if self . parsed : <EOL> try : <EOL> t = Template ( output , name = filepath ) <EOL> return t . render ( context ) <EOL> except TemplateSyntaxError as e : <EOL> if settings . DEBUG : <EOL> return "<STR_LIT>" % e <EOL> else : <EOL> return '<STR_LIT>' <EOL> return output <EOL> class LoadNode ( Node ) : <EOL> def render ( self , context ) : <EOL> return '<STR_LIT>' <EOL> class NowNode ( Node ) : <EOL> def __init__ ( self , format_string ) : <EOL> self . format_string = format_string <EOL> def render ( self , context ) : <EOL> tzinfo = timezone . get_current_timezone ( ) if settings . USE_TZ else None <EOL> return date ( datetime . now ( tz = tzinfo ) , self . format_string ) <EOL> class SpacelessNode ( Node ) : <EOL> def __init__ ( self , nodelist ) : <EOL> self . nodelist = nodelist <EOL> def render ( self , context ) : <EOL> from django . utils . html import strip_spaces_between_tags <EOL> return strip_spaces_between_tags ( self . nodelist . render ( context ) . strip ( ) ) <EOL> class TemplateTagNode ( Node ) : <EOL> mapping = { '<STR_LIT>' : BLOCK_TAG_START , <EOL> '<STR_LIT>' : BLOCK_TAG_END , <EOL> '<STR_LIT>' : VARIABLE_TAG_START , <EOL> '<STR_LIT>' : VARIABLE_TAG_END , <EOL> '<STR_LIT>' : SINGLE_BRACE_START , <EOL> '<STR_LIT>' : SINGLE_BRACE_END , <EOL> '<STR_LIT>' : COMMENT_TAG_START , <EOL> '<STR_LIT>' : COMMENT_TAG_END , <EOL> } <EOL> def __init__ ( self , tagtype ) : <EOL> self . tagtype = tagtype <EOL> def render ( self , context ) : <EOL> return self . mapping . get ( self . tagtype , '<STR_LIT>' ) <EOL> class URLNode ( Node ) : <EOL> def __init__ ( self , view_name , args , kwargs , asvar ) : <EOL> self . view_name = view_name <EOL> self . args = args <EOL> self . kwargs = kwargs <EOL> self . asvar = asvar <EOL> def render ( self , context ) : <EOL> from django . core . urlresolvers import reverse , NoReverseMatch <EOL> args = [ arg . resolve ( context ) for arg in self . args ] <EOL> kwargs = dict ( [ ( smart_text ( k , '<STR_LIT:ascii>' ) , v . resolve ( context ) ) <EOL> for k , v in self . kwargs . items ( ) ] ) <EOL> view_name = self . view_name . resolve ( context ) <EOL> if not view_name : <EOL> raise NoReverseMatch ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> url = '<STR_LIT>' <EOL> try : <EOL> url = reverse ( view_name , args = args , kwargs = kwargs , current_app = context . current_app ) <EOL> except NoReverseMatch as e : <EOL> if settings . SETTINGS_MODULE : <EOL> project_name = settings . SETTINGS_MODULE . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> try : <EOL> url = reverse ( project_name + '<STR_LIT:.>' + view_name , <EOL> args = args , kwargs = kwargs , <EOL> current_app = context . current_app ) <EOL> except NoReverseMatch : <EOL> if self . asvar is None : <EOL> raise e <EOL> else : <EOL> if self . asvar is None : <EOL> raise e <EOL> if self . asvar : <EOL> context [ self . asvar ] = url <EOL> return '<STR_LIT>' <EOL> else : <EOL> return url <EOL> class VerbatimNode ( Node ) : <EOL> def __init__ ( self , content ) : <EOL> self . content = content <EOL> def render ( self , context ) : <EOL> return self . content <EOL> class WidthRatioNode ( Node ) : <EOL> def __init__ ( self , val_expr , max_expr , max_width ) : <EOL> self . val_expr = val_expr <EOL> self . max_expr = max_expr <EOL> self . max_width = max_width <EOL> def render ( self , context ) : <EOL> try : <EOL> value = self . val_expr . resolve ( context ) <EOL> max_value = self . max_expr . resolve ( context ) <EOL> max_width = int ( self . max_width . resolve ( context ) ) <EOL> except VariableDoesNotExist : <EOL> return '<STR_LIT>' <EOL> except ( ValueError , TypeError ) : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> try : <EOL> value = float ( value ) <EOL> max_value = float ( max_value ) <EOL> ratio = ( value / max_value ) * max_width <EOL> except ZeroDivisionError : <EOL> return '<STR_LIT:0>' <EOL> except ( ValueError , TypeError ) : <EOL> return '<STR_LIT>' <EOL> return str ( int ( round ( ratio ) ) ) <EOL> class WithNode ( Node ) : <EOL> def __init__ ( self , var , name , nodelist , extra_context = None ) : <EOL> self . nodelist = nodelist <EOL> self . extra_context = extra_context or { } <EOL> if name : <EOL> self . extra_context [ name ] = var <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def render ( self , context ) : <EOL> values = dict ( [ ( key , val . resolve ( context ) ) for key , val in <EOL> six . iteritems ( self . extra_context ) ] ) <EOL> context . update ( values ) <EOL> output = self . nodelist . render ( context ) <EOL> context . pop ( ) <EOL> return output <EOL> @ register . tag <EOL> def autoescape ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> args = token . contents . split ( ) <EOL> if len ( args ) != <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> arg = args [ <NUM_LIT:1> ] <EOL> if arg not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> nodelist = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> parser . delete_first_token ( ) <EOL> return AutoEscapeControlNode ( ( arg == '<STR_LIT>' ) , nodelist ) <EOL> @ register . tag <EOL> def comment ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> parser . skip_past ( '<STR_LIT>' ) <EOL> return CommentNode ( ) <EOL> @ register . tag <EOL> def cycle ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> args = token . split_contents ( ) <EOL> if len ( args ) < <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> if '<STR_LIT:U+002C>' in args [ <NUM_LIT:1> ] : <EOL> args [ <NUM_LIT:1> : <NUM_LIT:2> ] = [ '<STR_LIT>' % arg for arg in args [ <NUM_LIT:1> ] . split ( "<STR_LIT:U+002C>" ) ] <EOL> if len ( args ) == <NUM_LIT:2> : <EOL> name = args [ <NUM_LIT:1> ] <EOL> if not hasattr ( parser , '<STR_LIT>' ) : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % name ) <EOL> if not name in parser . _namedCycleNodes : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % name ) <EOL> return parser . _namedCycleNodes [ name ] <EOL> as_form = False <EOL> if len ( args ) > <NUM_LIT:4> : <EOL> if args [ - <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> if args [ - <NUM_LIT:1> ] != "<STR_LIT>" : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % args [ - <NUM_LIT:1> ] ) <EOL> as_form = True <EOL> silent = True <EOL> args = args [ : - <NUM_LIT:1> ] <EOL> elif args [ - <NUM_LIT:2> ] == "<STR_LIT>" : <EOL> as_form = True <EOL> silent = False <EOL> if as_form : <EOL> name = args [ - <NUM_LIT:1> ] <EOL> values = [ parser . compile_filter ( arg ) for arg in args [ <NUM_LIT:1> : - <NUM_LIT:2> ] ] <EOL> node = CycleNode ( values , name , silent = silent ) <EOL> if not hasattr ( parser , '<STR_LIT>' ) : <EOL> parser . _namedCycleNodes = { } <EOL> parser . _namedCycleNodes [ name ] = node <EOL> else : <EOL> values = [ parser . compile_filter ( arg ) for arg in args [ <NUM_LIT:1> : ] ] <EOL> node = CycleNode ( values ) <EOL> return node <EOL> @ register . tag <EOL> def csrf_token ( parser , token ) : <EOL> return CsrfTokenNode ( ) <EOL> @ register . tag <EOL> def debug ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> return DebugNode ( ) <EOL> @ register . tag ( '<STR_LIT>' ) <EOL> def do_filter ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> _ , rest = token . contents . split ( None , <NUM_LIT:1> ) <EOL> filter_expr = parser . compile_filter ( "<STR_LIT>" % ( rest ) ) <EOL> for func , unused in filter_expr . filters : <EOL> if getattr ( func , '<STR_LIT>' , func ) . __name__ in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise TemplateSyntaxError ( '<STR_LIT>' % func . __name__ ) <EOL> nodelist = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> parser . delete_first_token ( ) <EOL> return FilterNode ( filter_expr , nodelist ) <EOL> @ register . tag <EOL> def firstof ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . split_contents ( ) [ <NUM_LIT:1> : ] <EOL> if len ( bits ) < <NUM_LIT:1> : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> return FirstOfNode ( [ parser . compile_filter ( bit ) for bit in bits ] ) <EOL> @ register . tag ( '<STR_LIT>' ) <EOL> def do_for ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> if len ( bits ) < <NUM_LIT:4> : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" % token . contents ) <EOL> is_reversed = bits [ - <NUM_LIT:1> ] == '<STR_LIT>' <EOL> in_index = is_reversed and - <NUM_LIT:3> or - <NUM_LIT:2> <EOL> if bits [ in_index ] != '<STR_LIT>' : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" % token . contents ) <EOL> loopvars = re . split ( r'<STR_LIT>' , '<STR_LIT:U+0020>' . join ( bits [ <NUM_LIT:1> : in_index ] ) ) <EOL> for var in loopvars : <EOL> if not var or '<STR_LIT:U+0020>' in var : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" % token . contents ) <EOL> sequence = parser . compile_filter ( bits [ in_index + <NUM_LIT:1> ] ) <EOL> nodelist_loop = parser . parse ( ( '<STR_LIT>' , '<STR_LIT>' , ) ) <EOL> token = parser . next_token ( ) <EOL> if token . contents == '<STR_LIT>' : <EOL> nodelist_empty = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> parser . delete_first_token ( ) <EOL> else : <EOL> nodelist_empty = None <EOL> return ForNode ( loopvars , sequence , is_reversed , nodelist_loop , nodelist_empty ) <EOL> def do_ifequal ( parser , token , negate ) : <EOL> bits = list ( token . split_contents ( ) ) <EOL> if len ( bits ) != <NUM_LIT:3> : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % bits [ <NUM_LIT:0> ] ) <EOL> end_tag = '<STR_LIT:end>' + bits [ <NUM_LIT:0> ] <EOL> nodelist_true = parser . parse ( ( '<STR_LIT>' , end_tag ) ) <EOL> token = parser . next_token ( ) <EOL> if token . contents == '<STR_LIT>' : <EOL> nodelist_false = parser . parse ( ( end_tag , ) ) <EOL> parser . delete_first_token ( ) <EOL> else : <EOL> nodelist_false = NodeList ( ) <EOL> val1 = parser . compile_filter ( bits [ <NUM_LIT:1> ] ) <EOL> val2 = parser . compile_filter ( bits [ <NUM_LIT:2> ] ) <EOL> return IfEqualNode ( val1 , val2 , nodelist_true , nodelist_false , negate ) <EOL> @ register . tag <EOL> def ifequal ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> return do_ifequal ( parser , token , False ) <EOL> @ register . tag <EOL> def ifnotequal ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> return do_ifequal ( parser , token , True ) <EOL> class TemplateLiteral ( Literal ) : <EOL> def __init__ ( self , value , text ) : <EOL> self . value = value <EOL> self . text = text <EOL> def display ( self ) : <EOL> return self . text <EOL> def eval ( self , context ) : <EOL> return self . value . resolve ( context , ignore_failures = True ) <EOL> class TemplateIfParser ( IfParser ) : <EOL> error_class = TemplateSyntaxError <EOL> def __init__ ( self , parser , * args , ** kwargs ) : <EOL> self . template_parser = parser <EOL> super ( TemplateIfParser , self ) . __init__ ( * args , ** kwargs ) <EOL> def create_var ( self , value ) : <EOL> return TemplateLiteral ( self . template_parser . compile_filter ( value ) , value ) <EOL> @ register . tag ( '<STR_LIT>' ) <EOL> def do_if ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . split_contents ( ) [ <NUM_LIT:1> : ] <EOL> condition = TemplateIfParser ( parser , bits ) . parse ( ) <EOL> nodelist = parser . parse ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> conditions_nodelists = [ ( condition , nodelist ) ] <EOL> token = parser . next_token ( ) <EOL> while token . contents . startswith ( '<STR_LIT>' ) : <EOL> bits = token . split_contents ( ) [ <NUM_LIT:1> : ] <EOL> condition = TemplateIfParser ( parser , bits ) . parse ( ) <EOL> nodelist = parser . parse ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> conditions_nodelists . append ( ( condition , nodelist ) ) <EOL> token = parser . next_token ( ) <EOL> if token . contents == '<STR_LIT>' : <EOL> nodelist = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> conditions_nodelists . append ( ( None , nodelist ) ) <EOL> token = parser . next_token ( ) <EOL> assert token . contents == '<STR_LIT>' <EOL> return IfNode ( conditions_nodelists ) <EOL> @ register . tag <EOL> def ifchanged ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> nodelist_true = parser . parse ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> token = parser . next_token ( ) <EOL> if token . contents == '<STR_LIT>' : <EOL> nodelist_false = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> parser . delete_first_token ( ) <EOL> else : <EOL> nodelist_false = NodeList ( ) <EOL> values = [ parser . compile_filter ( bit ) for bit in bits [ <NUM_LIT:1> : ] ] <EOL> return IfChangedNode ( nodelist_true , nodelist_false , * values ) <EOL> @ register . tag <EOL> def ssi ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . split_contents ( ) <EOL> parsed = False <EOL> if len ( bits ) not in ( <NUM_LIT:2> , <NUM_LIT:3> ) : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if len ( bits ) == <NUM_LIT:3> : <EOL> if bits [ <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> parsed = True <EOL> else : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" % bits [ <NUM_LIT:0> ] ) <EOL> filepath = parser . compile_filter ( bits [ <NUM_LIT:1> ] ) <EOL> return SsiNode ( filepath , parsed ) <EOL> @ register . tag <EOL> def load ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> if len ( bits ) >= <NUM_LIT:4> and bits [ - <NUM_LIT:2> ] == "<STR_LIT>" : <EOL> try : <EOL> taglib = bits [ - <NUM_LIT:1> ] <EOL> lib = get_library ( taglib ) <EOL> except InvalidTemplateLibrary as e : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % <EOL> ( taglib , e ) ) <EOL> else : <EOL> temp_lib = Library ( ) <EOL> for name in bits [ <NUM_LIT:1> : - <NUM_LIT:2> ] : <EOL> if name in lib . tags : <EOL> temp_lib . tags [ name ] = lib . tags [ name ] <EOL> if name in lib . filters : <EOL> temp_lib . filters [ name ] = lib . filters [ name ] <EOL> elif name in lib . filters : <EOL> temp_lib . filters [ name ] = lib . filters [ name ] <EOL> else : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % <EOL> ( name , taglib ) ) <EOL> parser . add_library ( temp_lib ) <EOL> else : <EOL> for taglib in bits [ <NUM_LIT:1> : ] : <EOL> try : <EOL> lib = get_library ( taglib ) <EOL> parser . add_library ( lib ) <EOL> except InvalidTemplateLibrary as e : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % <EOL> ( taglib , e ) ) <EOL> return LoadNode ( ) <EOL> @ register . tag <EOL> def now ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . split_contents ( ) <EOL> if len ( bits ) != <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> format_string = bits [ <NUM_LIT:1> ] [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> return NowNode ( format_string ) <EOL> @ register . tag <EOL> def regroup ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> firstbits = token . contents . split ( None , <NUM_LIT:3> ) <EOL> if len ( firstbits ) != <NUM_LIT:4> : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> target = parser . compile_filter ( firstbits [ <NUM_LIT:1> ] ) <EOL> if firstbits [ <NUM_LIT:2> ] != '<STR_LIT>' : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> lastbits_reversed = firstbits [ <NUM_LIT:3> ] [ : : - <NUM_LIT:1> ] . split ( None , <NUM_LIT:2> ) <EOL> if lastbits_reversed [ <NUM_LIT:1> ] [ : : - <NUM_LIT:1> ] != '<STR_LIT>' : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> var_name = lastbits_reversed [ <NUM_LIT:0> ] [ : : - <NUM_LIT:1> ] <EOL> expression = parser . compile_filter ( var_name + <EOL> VARIABLE_ATTRIBUTE_SEPARATOR + <EOL> lastbits_reversed [ <NUM_LIT:2> ] [ : : - <NUM_LIT:1> ] ) <EOL> return RegroupNode ( target , expression , var_name ) <EOL> @ register . tag <EOL> def spaceless ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> nodelist = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> parser . delete_first_token ( ) <EOL> return SpacelessNode ( nodelist ) <EOL> @ register . tag <EOL> def templatetag ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> if len ( bits ) != <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> tag = bits [ <NUM_LIT:1> ] <EOL> if tag not in TemplateTagNode . mapping : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( tag , list ( TemplateTagNode . mapping ) ) ) <EOL> return TemplateTagNode ( tag ) <EOL> @ register . tag <EOL> def url ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . split_contents ( ) <EOL> if len ( bits ) < <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" % bits [ <NUM_LIT:0> ] ) <EOL> try : <EOL> viewname = parser . compile_filter ( bits [ <NUM_LIT:1> ] ) <EOL> except TemplateSyntaxError as exc : <EOL> exc . args = ( exc . args [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> raise <EOL> args = [ ] <EOL> kwargs = { } <EOL> asvar = None <EOL> bits = bits [ <NUM_LIT:2> : ] <EOL> if len ( bits ) >= <NUM_LIT:2> and bits [ - <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> asvar = bits [ - <NUM_LIT:1> ] <EOL> bits = bits [ : - <NUM_LIT:2> ] <EOL> if len ( bits ) : <EOL> for bit in bits : <EOL> match = kwarg_re . match ( bit ) <EOL> if not match : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> name , value = match . groups ( ) <EOL> if name : <EOL> kwargs [ name ] = parser . compile_filter ( value ) <EOL> else : <EOL> args . append ( parser . compile_filter ( value ) ) <EOL> return URLNode ( viewname , args , kwargs , asvar ) <EOL> @ register . tag <EOL> def verbatim ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> nodelist = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> parser . delete_first_token ( ) <EOL> return VerbatimNode ( nodelist . render ( Context ( ) ) ) <EOL> @ register . tag <EOL> def widthratio ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> if len ( bits ) != <NUM_LIT:4> : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" ) <EOL> tag , this_value_expr , max_value_expr , max_width = bits <EOL> return WidthRatioNode ( parser . compile_filter ( this_value_expr ) , <EOL> parser . compile_filter ( max_value_expr ) , <EOL> parser . compile_filter ( max_width ) ) <EOL> @ register . tag ( '<STR_LIT>' ) <EOL> def do_with ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . split_contents ( ) <EOL> remaining_bits = bits [ <NUM_LIT:1> : ] <EOL> extra_context = token_kwargs ( remaining_bits , parser , support_legacy = True ) <EOL> if not extra_context : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" % bits [ <NUM_LIT:0> ] ) <EOL> if remaining_bits : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % <EOL> ( bits [ <NUM_LIT:0> ] , remaining_bits [ <NUM_LIT:0> ] ) ) <EOL> nodelist = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> parser . delete_first_token ( ) <EOL> return WithNode ( None , None , nodelist , extra_context = extra_context ) </s>
|
<s> """<STR_LIT>""" <EOL> import copy <EOL> import types <EOL> import warnings <EOL> warnings . warn ( "<STR_LIT>" , <EOL> DeprecationWarning ) <EOL> if ( hasattr ( copy , '<STR_LIT>' ) and types . FunctionType not in copy . _deepcopy_dispatch ) : <EOL> copy . _deepcopy_dispatch [ types . FunctionType ] = copy . _deepcopy_atomic <EOL> del copy , types <EOL> from copy import * </s>
|
<s> from __future__ import unicode_literals <EOL> import datetime <EOL> from django . utils . timezone import is_aware , utc <EOL> from django . utils . translation import ungettext , ugettext <EOL> def timesince ( d , now = None , reversed = False ) : <EOL> """<STR_LIT>""" <EOL> chunks = ( <EOL> ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> , lambda n : ungettext ( '<STR_LIT>' , '<STR_LIT>' , n ) ) , <EOL> ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:30> , lambda n : ungettext ( '<STR_LIT>' , '<STR_LIT>' , n ) ) , <EOL> ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:7> , lambda n : ungettext ( '<STR_LIT>' , '<STR_LIT>' , n ) ) , <EOL> ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> , lambda n : ungettext ( '<STR_LIT>' , '<STR_LIT>' , n ) ) , <EOL> ( <NUM_LIT> * <NUM_LIT> , lambda n : ungettext ( '<STR_LIT>' , '<STR_LIT>' , n ) ) , <EOL> ( <NUM_LIT> , lambda n : ungettext ( '<STR_LIT>' , '<STR_LIT>' , n ) ) <EOL> ) <EOL> if not isinstance ( d , datetime . datetime ) : <EOL> d = datetime . datetime ( d . year , d . month , d . day ) <EOL> if now and not isinstance ( now , datetime . datetime ) : <EOL> now = datetime . datetime ( now . year , now . month , now . day ) <EOL> if not now : <EOL> now = datetime . datetime . now ( utc if is_aware ( d ) else None ) <EOL> delta = ( d - now ) if reversed else ( now - d ) <EOL> since = delta . days * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> + delta . seconds <EOL> if since <= <NUM_LIT:0> : <EOL> return '<STR_LIT>' + ugettext ( '<STR_LIT>' ) <EOL> for i , ( seconds , name ) in enumerate ( chunks ) : <EOL> count = since // seconds <EOL> if count != <NUM_LIT:0> : <EOL> break <EOL> s = ugettext ( '<STR_LIT>' ) % { '<STR_LIT>' : count , '<STR_LIT:type>' : name ( count ) } <EOL> if i + <NUM_LIT:1> < len ( chunks ) : <EOL> seconds2 , name2 = chunks [ i + <NUM_LIT:1> ] <EOL> count2 = ( since - ( seconds * count ) ) // seconds2 <EOL> if count2 != <NUM_LIT:0> : <EOL> s += ugettext ( '<STR_LIT>' ) % { '<STR_LIT>' : count2 , '<STR_LIT:type>' : name2 ( count2 ) } <EOL> return s <EOL> def timeuntil ( d , now = None ) : <EOL> """<STR_LIT>""" <EOL> return timesince ( d , now , reversed = True ) </s>
|
<s> import os <EOL> from optparse import OptionParser <EOL> from subprocess import call , Popen , PIPE <EOL> from django . core . management import call_command <EOL> HAVE_JS = [ '<STR_LIT>' ] <EOL> def _get_locale_dirs ( include_core = True ) : <EOL> """<STR_LIT>""" <EOL> contrib_dir = os . path . join ( os . getcwd ( ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> dirs = [ ] <EOL> for contrib_name in os . listdir ( contrib_dir ) : <EOL> path = os . path . join ( contrib_dir , contrib_name , '<STR_LIT>' ) <EOL> if os . path . isdir ( path ) : <EOL> dirs . append ( ( contrib_name , path ) ) <EOL> if contrib_name in HAVE_JS : <EOL> dirs . append ( ( "<STR_LIT>" % contrib_name , path ) ) <EOL> if include_core : <EOL> dirs . insert ( <NUM_LIT:0> , ( '<STR_LIT>' , os . path . join ( os . getcwd ( ) , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> return dirs <EOL> def _tx_resource_for_name ( name ) : <EOL> """<STR_LIT>""" <EOL> if name == '<STR_LIT>' : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" % name <EOL> def _check_diff ( cat_name , base_path ) : <EOL> """<STR_LIT>""" <EOL> po_path = '<STR_LIT>' % { <EOL> '<STR_LIT:path>' : base_path , '<STR_LIT>' : '<STR_LIT>' if cat_name . endswith ( '<STR_LIT>' ) else '<STR_LIT>' } <EOL> p = Popen ( "<STR_LIT>" % po_path , <EOL> stdout = PIPE , stderr = PIPE , shell = True ) <EOL> output , errors = p . communicate ( ) <EOL> num_changes = int ( output . strip ( ) ) - <NUM_LIT:4> <EOL> print ( "<STR_LIT>" % ( num_changes , cat_name ) ) <EOL> def update_catalogs ( resources = None , languages = None ) : <EOL> """<STR_LIT>""" <EOL> contrib_dirs = _get_locale_dirs ( include_core = False ) <EOL> os . chdir ( os . path . join ( os . getcwd ( ) , '<STR_LIT>' ) ) <EOL> print ( "<STR_LIT>" ) <EOL> call_command ( '<STR_LIT>' , locale = '<STR_LIT>' ) <EOL> _check_diff ( '<STR_LIT>' , os . path . join ( os . getcwd ( ) , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> for name , dir_ in contrib_dirs : <EOL> if resources and not name in resources : <EOL> continue <EOL> os . chdir ( os . path . join ( dir_ , '<STR_LIT:..>' ) ) <EOL> print ( "<STR_LIT>" % dir_ ) <EOL> if name . endswith ( '<STR_LIT>' ) : <EOL> call_command ( '<STR_LIT>' , locale = '<STR_LIT>' , domain = '<STR_LIT>' ) <EOL> else : <EOL> call_command ( '<STR_LIT>' , locale = '<STR_LIT>' ) <EOL> _check_diff ( name , dir_ ) <EOL> def lang_stats ( resources = None , languages = None ) : <EOL> """<STR_LIT>""" <EOL> locale_dirs = _get_locale_dirs ( ) <EOL> for name , dir_ in locale_dirs : <EOL> if resources and not name in resources : <EOL> continue <EOL> print ( "<STR_LIT>" % name ) <EOL> langs = sorted ( [ d for d in os . listdir ( dir_ ) if not d . startswith ( '<STR_LIT:_>' ) ] ) <EOL> for lang in langs : <EOL> if languages and not lang in languages : <EOL> continue <EOL> p = Popen ( "<STR_LIT>" % { <EOL> '<STR_LIT:path>' : dir_ , '<STR_LIT>' : lang , '<STR_LIT>' : '<STR_LIT>' if name . endswith ( '<STR_LIT>' ) else '<STR_LIT>' } , <EOL> stdout = PIPE , stderr = PIPE , shell = True ) <EOL> output , errors = p . communicate ( ) <EOL> if p . returncode == <NUM_LIT:0> : <EOL> print ( "<STR_LIT>" % ( lang , errors . strip ( ) ) ) <EOL> def fetch ( resources = None , languages = None ) : <EOL> """<STR_LIT>""" <EOL> locale_dirs = _get_locale_dirs ( ) <EOL> for name , dir_ in locale_dirs : <EOL> if resources and not name in resources : <EOL> continue <EOL> if languages is None : <EOL> call ( '<STR_LIT>' % { '<STR_LIT>' : _tx_resource_for_name ( name ) } , shell = True ) <EOL> languages = sorted ( [ d for d in os . listdir ( dir_ ) if not d . startswith ( '<STR_LIT:_>' ) ] ) <EOL> else : <EOL> for lang in languages : <EOL> call ( '<STR_LIT>' % { <EOL> '<STR_LIT>' : _tx_resource_for_name ( name ) , '<STR_LIT>' : lang } , shell = True ) <EOL> for lang in languages : <EOL> po_path = '<STR_LIT>' % { <EOL> '<STR_LIT:path>' : dir_ , '<STR_LIT>' : lang , '<STR_LIT>' : '<STR_LIT>' if name . endswith ( '<STR_LIT>' ) else '<STR_LIT>' } <EOL> call ( '<STR_LIT>' % ( po_path , po_path ) , shell = True ) <EOL> mo_path = '<STR_LIT>' % po_path [ : - <NUM_LIT:3> ] <EOL> call ( '<STR_LIT>' % ( mo_path , po_path ) , shell = True ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> RUNABLE_SCRIPTS = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> parser = OptionParser ( usage = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> options , args = parser . parse_args ( ) <EOL> if not args : <EOL> parser . print_usage ( ) <EOL> exit ( <NUM_LIT:1> ) <EOL> if args [ <NUM_LIT:0> ] in RUNABLE_SCRIPTS : <EOL> eval ( args [ <NUM_LIT:0> ] ) ( options . resources , options . languages ) <EOL> else : <EOL> print ( "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( RUNABLE_SCRIPTS ) ) </s>
|
<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from django . db import models <EOL> from django . utils . encoding import force_text <EOL> from . fields import SmallField , SmallerField , JSONField <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> @ python_2_unicode_compatible <EOL> class MyModel ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:10> ) <EOL> data = SmallField ( '<STR_LIT>' ) <EOL> def __str__ ( self ) : <EOL> return force_text ( self . name ) <EOL> class OtherModel ( models . Model ) : <EOL> data = SmallerField ( ) <EOL> class DataModel ( models . Model ) : <EOL> data = JSONField ( ) </s>
|
<s> """<STR_LIT>""" <EOL> from django . db import models <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> @ python_2_unicode_compatible <EOL> class Publication ( models . Model ) : <EOL> title = models . CharField ( max_length = <NUM_LIT:30> ) <EOL> def __str__ ( self ) : <EOL> return self . title <EOL> class Meta : <EOL> ordering = ( '<STR_LIT:title>' , ) <EOL> @ python_2_unicode_compatible <EOL> class Article ( models . Model ) : <EOL> headline = models . CharField ( max_length = <NUM_LIT:100> ) <EOL> publications = models . ManyToManyField ( Publication ) <EOL> def __str__ ( self ) : <EOL> return self . headline <EOL> class Meta : <EOL> ordering = ( '<STR_LIT>' , ) </s>
|
<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from django . db import models <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> @ python_2_unicode_compatible <EOL> class Person ( models . Model ) : <EOL> first_name = models . CharField ( max_length = <NUM_LIT:20> ) <EOL> last_name = models . CharField ( max_length = <NUM_LIT:20> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( Person , self ) . __init__ ( * args , ** kwargs ) <EOL> self . data = [ ] <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . first_name , self . last_name ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> self . data . append ( "<STR_LIT>" ) <EOL> super ( Person , self ) . save ( * args , ** kwargs ) <EOL> self . data . append ( "<STR_LIT>" ) <EOL> def delete ( self ) : <EOL> self . data . append ( "<STR_LIT>" ) <EOL> super ( Person , self ) . delete ( ) <EOL> self . data . append ( "<STR_LIT>" ) </s>
|
<s> from __future__ import absolute_import , unicode_literals <EOL> import datetime <EOL> from django . core . exceptions import ValidationError <EOL> from django . test import TestCase <EOL> from django . utils import unittest <EOL> from . models import ( CustomPKModel , UniqueTogetherModel , UniqueFieldsModel , <EOL> UniqueForDateModel , ModelToValidate , Post , FlexibleDatePost , <EOL> UniqueErrorsModel ) <EOL> class GetUniqueCheckTests ( unittest . TestCase ) : <EOL> def test_unique_fields_get_collected ( self ) : <EOL> m = UniqueFieldsModel ( ) <EOL> self . assertEqual ( <EOL> ( [ ( UniqueFieldsModel , ( '<STR_LIT:id>' , ) ) , <EOL> ( UniqueFieldsModel , ( '<STR_LIT>' , ) ) , <EOL> ( UniqueFieldsModel , ( '<STR_LIT>' , ) ) ] , <EOL> [ ] ) , <EOL> m . _get_unique_checks ( ) <EOL> ) <EOL> def test_unique_together_gets_picked_up_and_converted_to_tuple ( self ) : <EOL> m = UniqueTogetherModel ( ) <EOL> self . assertEqual ( <EOL> ( [ ( UniqueTogetherModel , ( '<STR_LIT>' , '<STR_LIT>' , ) ) , <EOL> ( UniqueTogetherModel , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( UniqueTogetherModel , ( '<STR_LIT:id>' , ) ) , ] , <EOL> [ ] ) , <EOL> m . _get_unique_checks ( ) <EOL> ) <EOL> def test_primary_key_is_considered_unique ( self ) : <EOL> m = CustomPKModel ( ) <EOL> self . assertEqual ( ( [ ( CustomPKModel , ( '<STR_LIT>' , ) ) ] , [ ] ) , m . _get_unique_checks ( ) ) <EOL> def test_unique_for_date_gets_picked_up ( self ) : <EOL> m = UniqueForDateModel ( ) <EOL> self . assertEqual ( ( <EOL> [ ( UniqueForDateModel , ( '<STR_LIT:id>' , ) ) ] , <EOL> [ ( UniqueForDateModel , '<STR_LIT:date>' , '<STR_LIT:count>' , '<STR_LIT>' ) , <EOL> ( UniqueForDateModel , '<STR_LIT>' , '<STR_LIT:count>' , '<STR_LIT>' ) , <EOL> ( UniqueForDateModel , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> ) , m . _get_unique_checks ( ) <EOL> ) <EOL> def test_unique_for_date_exclusion ( self ) : <EOL> m = UniqueForDateModel ( ) <EOL> self . assertEqual ( ( <EOL> [ ( UniqueForDateModel , ( '<STR_LIT:id>' , ) ) ] , <EOL> [ ( UniqueForDateModel , '<STR_LIT>' , '<STR_LIT:count>' , '<STR_LIT>' ) , <EOL> ( UniqueForDateModel , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> ) , m . _get_unique_checks ( exclude = '<STR_LIT>' ) <EOL> ) <EOL> class PerformUniqueChecksTest ( TestCase ) : <EOL> def test_primary_key_unique_check_not_performed_when_adding_and_pk_not_specified ( self ) : <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> mtv = ModelToValidate ( number = <NUM_LIT:10> , name = '<STR_LIT>' ) <EOL> setattr ( mtv , '<STR_LIT>' , True ) <EOL> mtv . full_clean ( ) <EOL> def test_primary_key_unique_check_performed_when_adding_and_pk_specified ( self ) : <EOL> with self . assertNumQueries ( <NUM_LIT:1> ) : <EOL> mtv = ModelToValidate ( number = <NUM_LIT:10> , name = '<STR_LIT>' , id = <NUM_LIT> ) <EOL> setattr ( mtv , '<STR_LIT>' , True ) <EOL> mtv . full_clean ( ) <EOL> def test_primary_key_unique_check_not_performed_when_not_adding ( self ) : <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> mtv = ModelToValidate ( number = <NUM_LIT:10> , name = '<STR_LIT>' ) <EOL> mtv . full_clean ( ) <EOL> def test_unique_for_date ( self ) : <EOL> p1 = Post . objects . create ( title = "<STR_LIT>" , <EOL> slug = "<STR_LIT>" , subtitle = "<STR_LIT>" , posted = datetime . date ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:3> ) ) <EOL> p = Post ( title = "<STR_LIT>" , posted = datetime . date ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:3> ) ) <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> p . full_clean ( ) <EOL> self . assertEqual ( cm . exception . message_dict , { '<STR_LIT:title>' : [ '<STR_LIT>' ] } ) <EOL> p = Post ( title = "<STR_LIT>" , posted = datetime . date ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:3> ) ) <EOL> p . full_clean ( ) <EOL> p = Post ( title = "<STR_LIT>" , posted = datetime . datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:4> ) ) <EOL> p . full_clean ( ) <EOL> p = Post ( slug = "<STR_LIT>" , posted = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> p . full_clean ( ) <EOL> self . assertEqual ( cm . exception . message_dict , { '<STR_LIT>' : [ '<STR_LIT>' ] } ) <EOL> p = Post ( subtitle = "<STR_LIT>" , posted = datetime . datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:30> ) ) <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> p . full_clean ( ) <EOL> self . assertEqual ( cm . exception . message_dict , { '<STR_LIT>' : [ '<STR_LIT>' ] } ) <EOL> p = Post ( title = "<STR_LIT>" ) <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> p . full_clean ( ) <EOL> self . assertEqual ( cm . exception . message_dict , { '<STR_LIT>' : [ '<STR_LIT>' ] } ) <EOL> def test_unique_for_date_with_nullable_date ( self ) : <EOL> p1 = FlexibleDatePost . objects . create ( title = "<STR_LIT>" , <EOL> slug = "<STR_LIT>" , subtitle = "<STR_LIT>" , posted = datetime . date ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:3> ) ) <EOL> p = FlexibleDatePost ( title = "<STR_LIT>" ) <EOL> try : <EOL> p . full_clean ( ) <EOL> except ValidationError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> p = FlexibleDatePost ( slug = "<STR_LIT>" ) <EOL> try : <EOL> p . full_clean ( ) <EOL> except ValidationError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> p = FlexibleDatePost ( subtitle = "<STR_LIT>" ) <EOL> try : <EOL> p . full_clean ( ) <EOL> except ValidationError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_unique_errors ( self ) : <EOL> m1 = UniqueErrorsModel . objects . create ( name = '<STR_LIT>' , no = <NUM_LIT:10> ) <EOL> m = UniqueErrorsModel ( name = '<STR_LIT>' , no = <NUM_LIT:11> ) <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> m . full_clean ( ) <EOL> self . assertEqual ( cm . exception . message_dict , { '<STR_LIT:name>' : [ '<STR_LIT>' ] } ) <EOL> m = UniqueErrorsModel ( name = '<STR_LIT>' , no = <NUM_LIT:10> ) <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> m . full_clean ( ) <EOL> self . assertEqual ( cm . exception . message_dict , { '<STR_LIT>' : [ '<STR_LIT>' ] } ) </s>
|
<s> from __future__ import absolute_import , unicode_literals <EOL> import tempfile <EOL> import os <EOL> from django import forms <EOL> from django . contrib import admin <EOL> from django . contrib . admin . views . main import ChangeList <EOL> from django . core . files . storage import FileSystemStorage <EOL> from django . core . mail import EmailMessage <EOL> from django . conf . urls import patterns , url <EOL> from django . db import models <EOL> from django . forms . models import BaseModelFormSet <EOL> from django . http import HttpResponse <EOL> from django . contrib . admin import BooleanFieldListFilter <EOL> from . models import ( Article , Chapter , Account , Media , Child , Parent , Picture , <EOL> Widget , DooHickey , Grommet , Whatsit , FancyDoodad , Category , Link , <EOL> PrePopulatedPost , PrePopulatedSubPost , CustomArticle , Section , <EOL> ModelWithStringPrimaryKey , Color , Thing , Actor , Inquisition , Sketch , Person , <EOL> Persona , Subscriber , ExternalSubscriber , OldSubscriber , Vodcast , EmptyModel , <EOL> Fabric , Gallery , Language , Recommendation , Recommender , Collector , Post , <EOL> Gadget , Villain , SuperVillain , Plot , PlotDetails , CyclicOne , CyclicTwo , <EOL> WorkHour , Reservation , FoodDelivery , RowLevelChangePermissionModel , Paper , <EOL> CoverLetter , Story , OtherStory , Book , Promo , ChapterXtra1 , Pizza , Topping , <EOL> Album , Question , Answer , ComplexSortedPerson , PrePopulatedPostLargeSlug , <EOL> AdminOrderedField , AdminOrderedModelMethod , AdminOrderedAdminMethod , <EOL> AdminOrderedCallable , Report , Color2 , UnorderedObject , MainPrepopulated , <EOL> RelatedPrepopulated , UndeletableObject , UserMessenger , Simple , Choice , <EOL> ShortMessage , Telegram ) <EOL> def callable_year ( dt_value ) : <EOL> try : <EOL> return dt_value . year <EOL> except AttributeError : <EOL> return None <EOL> callable_year . admin_order_field = '<STR_LIT:date>' <EOL> class ArticleInline ( admin . TabularInline ) : <EOL> model = Article <EOL> prepopulated_fields = { <EOL> '<STR_LIT:title>' : ( '<STR_LIT:content>' , ) <EOL> } <EOL> fieldsets = ( <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:title>' , '<STR_LIT:content>' ) <EOL> } ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:date>' , '<STR_LIT>' ) <EOL> } ) <EOL> ) <EOL> class ChapterInline ( admin . TabularInline ) : <EOL> model = Chapter <EOL> class ChapterXtra1Admin ( admin . ModelAdmin ) : <EOL> list_filter = ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) <EOL> class ArticleAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:content>' , '<STR_LIT:date>' , callable_year , '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_filter = ( '<STR_LIT:date>' , '<STR_LIT>' ) <EOL> def changelist_view ( self , request ) : <EOL> "<STR_LIT>" <EOL> return super ( ArticleAdmin , self ) . changelist_view ( <EOL> request , extra_context = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> def modeladmin_year ( self , obj ) : <EOL> return obj . date . year <EOL> modeladmin_year . admin_order_field = '<STR_LIT:date>' <EOL> modeladmin_year . short_description = None <EOL> def delete_model ( self , request , obj ) : <EOL> EmailMessage ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] <EOL> ) . send ( ) <EOL> return super ( ArticleAdmin , self ) . delete_model ( request , obj ) <EOL> def save_model ( self , request , obj , form , change = True ) : <EOL> EmailMessage ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] <EOL> ) . send ( ) <EOL> return super ( ArticleAdmin , self ) . save_model ( request , obj , form , change ) <EOL> class RowLevelChangePermissionModelAdmin ( admin . ModelAdmin ) : <EOL> def has_change_permission ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> return request . user . is_staff and ( obj is not None ) and ( obj . id % <NUM_LIT:2> == <NUM_LIT:0> ) <EOL> class CustomArticleAdmin ( admin . ModelAdmin ) : <EOL> """<STR_LIT>""" <EOL> change_list_template = '<STR_LIT>' <EOL> change_form_template = '<STR_LIT>' <EOL> add_form_template = '<STR_LIT>' <EOL> object_history_template = '<STR_LIT>' <EOL> delete_confirmation_template = '<STR_LIT>' <EOL> delete_selected_confirmation_template = '<STR_LIT>' <EOL> def changelist_view ( self , request ) : <EOL> "<STR_LIT>" <EOL> return super ( CustomArticleAdmin , self ) . changelist_view ( <EOL> request , extra_context = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> class ThingAdmin ( admin . ModelAdmin ) : <EOL> list_filter = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> class InquisitionAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class SketchAdmin ( admin . ModelAdmin ) : <EOL> raw_id_fields = ( '<STR_LIT>' , ) <EOL> class FabricAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , ) <EOL> list_filter = ( '<STR_LIT>' , ) <EOL> class BasePersonModelFormSet ( BaseModelFormSet ) : <EOL> def clean ( self ) : <EOL> for person_dict in self . cleaned_data : <EOL> person = person_dict . get ( '<STR_LIT:id>' ) <EOL> alive = person_dict . get ( '<STR_LIT>' ) <EOL> if person and alive and person . name == "<STR_LIT>" : <EOL> raise forms . ValidationError ( "<STR_LIT>" ) <EOL> class PersonAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_editable = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_filter = ( '<STR_LIT>' , ) <EOL> search_fields = ( '<STR_LIT>' , ) <EOL> save_as = True <EOL> def get_changelist_formset ( self , request , ** kwargs ) : <EOL> return super ( PersonAdmin , self ) . get_changelist_formset ( request , <EOL> formset = BasePersonModelFormSet , ** kwargs ) <EOL> def queryset ( self , request ) : <EOL> return super ( PersonAdmin , self ) . queryset ( request ) . order_by ( '<STR_LIT>' ) <EOL> class FooAccount ( Account ) : <EOL> """<STR_LIT>""" <EOL> servicename = '<STR_LIT:foo>' <EOL> class BarAccount ( Account ) : <EOL> """<STR_LIT>""" <EOL> servicename = '<STR_LIT:bar>' <EOL> class FooAccountAdmin ( admin . StackedInline ) : <EOL> model = FooAccount <EOL> extra = <NUM_LIT:1> <EOL> class BarAccountAdmin ( admin . StackedInline ) : <EOL> model = BarAccount <EOL> extra = <NUM_LIT:1> <EOL> class PersonaAdmin ( admin . ModelAdmin ) : <EOL> inlines = ( <EOL> FooAccountAdmin , <EOL> BarAccountAdmin <EOL> ) <EOL> class SubscriberAdmin ( admin . ModelAdmin ) : <EOL> actions = [ '<STR_LIT>' ] <EOL> def mail_admin ( self , request , selected ) : <EOL> EmailMessage ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] <EOL> ) . send ( ) <EOL> def external_mail ( modeladmin , request , selected ) : <EOL> EmailMessage ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] <EOL> ) . send ( ) <EOL> external_mail . short_description = '<STR_LIT>' <EOL> def redirect_to ( modeladmin , request , selected ) : <EOL> from django . http import HttpResponseRedirect <EOL> return HttpResponseRedirect ( '<STR_LIT>' ) <EOL> redirect_to . short_description = '<STR_LIT>' <EOL> class ExternalSubscriberAdmin ( admin . ModelAdmin ) : <EOL> actions = [ redirect_to , external_mail ] <EOL> class Podcast ( Media ) : <EOL> release_date = models . DateField ( ) <EOL> class Meta : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> class PodcastAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> list_editable = ( '<STR_LIT>' , ) <EOL> date_hierarchy = '<STR_LIT>' <EOL> ordering = ( '<STR_LIT:name>' , ) <EOL> class VodcastAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> list_editable = ( '<STR_LIT>' , ) <EOL> ordering = ( '<STR_LIT:name>' , ) <EOL> class ChildInline ( admin . StackedInline ) : <EOL> model = Child <EOL> class ParentAdmin ( admin . ModelAdmin ) : <EOL> model = Parent <EOL> inlines = [ ChildInline ] <EOL> list_editable = ( '<STR_LIT:name>' , ) <EOL> def save_related ( self , request , form , formsets , change ) : <EOL> super ( ParentAdmin , self ) . save_related ( request , form , formsets , change ) <EOL> first_name , last_name = form . instance . name . split ( ) <EOL> for child in form . instance . child_set . all ( ) : <EOL> if len ( child . name . split ( ) ) < <NUM_LIT:2> : <EOL> child . name = child . name + '<STR_LIT:U+0020>' + last_name <EOL> child . save ( ) <EOL> class EmptyModelAdmin ( admin . ModelAdmin ) : <EOL> def queryset ( self , request ) : <EOL> return super ( EmptyModelAdmin , self ) . queryset ( request ) . filter ( pk__gt = <NUM_LIT:1> ) <EOL> class OldSubscriberAdmin ( admin . ModelAdmin ) : <EOL> actions = None <EOL> temp_storage = FileSystemStorage ( tempfile . mkdtemp ( dir = os . environ [ '<STR_LIT>' ] ) ) <EOL> UPLOAD_TO = os . path . join ( temp_storage . location , '<STR_LIT>' ) <EOL> class PictureInline ( admin . TabularInline ) : <EOL> model = Picture <EOL> extra = <NUM_LIT:1> <EOL> class GalleryAdmin ( admin . ModelAdmin ) : <EOL> inlines = [ PictureInline ] <EOL> class PictureAdmin ( admin . ModelAdmin ) : <EOL> pass <EOL> class LanguageAdmin ( admin . ModelAdmin ) : <EOL> list_display = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' ] <EOL> list_editable = [ '<STR_LIT>' ] <EOL> class RecommendationAdmin ( admin . ModelAdmin ) : <EOL> search_fields = ( '<STR_LIT>' , '<STR_LIT>' , ) <EOL> class WidgetInline ( admin . StackedInline ) : <EOL> model = Widget <EOL> class DooHickeyInline ( admin . StackedInline ) : <EOL> model = DooHickey <EOL> class GrommetInline ( admin . StackedInline ) : <EOL> model = Grommet <EOL> class WhatsitInline ( admin . StackedInline ) : <EOL> model = Whatsit <EOL> class FancyDoodadInline ( admin . StackedInline ) : <EOL> model = FancyDoodad <EOL> class CategoryAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_editable = ( '<STR_LIT>' , ) <EOL> class CategoryInline ( admin . StackedInline ) : <EOL> model = Category <EOL> class CollectorAdmin ( admin . ModelAdmin ) : <EOL> inlines = [ <EOL> WidgetInline , DooHickeyInline , GrommetInline , WhatsitInline , <EOL> FancyDoodadInline , CategoryInline <EOL> ] <EOL> class LinkInline ( admin . TabularInline ) : <EOL> model = Link <EOL> extra = <NUM_LIT:1> <EOL> readonly_fields = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def multiline ( self , instance ) : <EOL> return "<STR_LIT>" <EOL> class SubPostInline ( admin . TabularInline ) : <EOL> model = PrePopulatedSubPost <EOL> prepopulated_fields = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) <EOL> } <EOL> def get_readonly_fields ( self , request , obj = None ) : <EOL> if obj and obj . published : <EOL> return ( '<STR_LIT>' , ) <EOL> return self . readonly_fields <EOL> def get_prepopulated_fields ( self , request , obj = None ) : <EOL> if obj and obj . published : <EOL> return { } <EOL> return self . prepopulated_fields <EOL> class PrePopulatedPostAdmin ( admin . ModelAdmin ) : <EOL> list_display = [ '<STR_LIT:title>' , '<STR_LIT>' ] <EOL> prepopulated_fields = { <EOL> '<STR_LIT>' : ( '<STR_LIT:title>' , ) <EOL> } <EOL> inlines = [ SubPostInline ] <EOL> def get_readonly_fields ( self , request , obj = None ) : <EOL> if obj and obj . published : <EOL> return ( '<STR_LIT>' , ) <EOL> return self . readonly_fields <EOL> def get_prepopulated_fields ( self , request , obj = None ) : <EOL> if obj and obj . published : <EOL> return { } <EOL> return self . prepopulated_fields <EOL> class PostAdmin ( admin . ModelAdmin ) : <EOL> list_display = [ '<STR_LIT:title>' , '<STR_LIT>' ] <EOL> readonly_fields = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:value>' , '<STR_LIT>' , <EOL> lambda obj : "<STR_LIT:foo>" <EOL> ) <EOL> inlines = [ <EOL> LinkInline <EOL> ] <EOL> def coolness ( self , instance ) : <EOL> if instance . pk : <EOL> return "<STR_LIT>" % instance . pk <EOL> else : <EOL> return "<STR_LIT>" <EOL> def value ( self , instance ) : <EOL> return <NUM_LIT:1000> <EOL> def multiline ( self , instance ) : <EOL> return "<STR_LIT>" <EOL> value . short_description = '<STR_LIT>' <EOL> class CustomChangeList ( ChangeList ) : <EOL> def get_query_set ( self , request ) : <EOL> return self . root_query_set . filter ( pk = <NUM_LIT> ) <EOL> class GadgetAdmin ( admin . ModelAdmin ) : <EOL> def get_changelist ( self , request , ** kwargs ) : <EOL> return CustomChangeList <EOL> class PizzaAdmin ( admin . ModelAdmin ) : <EOL> readonly_fields = ( '<STR_LIT>' , ) <EOL> class WorkHourAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_filter = ( '<STR_LIT>' , ) <EOL> class FoodDeliveryAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_editable = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class CoverLetterAdmin ( admin . ModelAdmin ) : <EOL> """<STR_LIT>""" <EOL> def queryset ( self , request ) : <EOL> return super ( CoverLetterAdmin , self ) . queryset ( request ) . defer ( '<STR_LIT>' ) <EOL> class PaperAdmin ( admin . ModelAdmin ) : <EOL> """<STR_LIT>""" <EOL> def queryset ( self , request ) : <EOL> return super ( PaperAdmin , self ) . queryset ( request ) . only ( '<STR_LIT:title>' ) <EOL> class ShortMessageAdmin ( admin . ModelAdmin ) : <EOL> """<STR_LIT>""" <EOL> def queryset ( self , request ) : <EOL> return super ( ShortMessageAdmin , self ) . queryset ( request ) . defer ( '<STR_LIT>' ) <EOL> class TelegramAdmin ( admin . ModelAdmin ) : <EOL> """<STR_LIT>""" <EOL> def queryset ( self , request ) : <EOL> return super ( TelegramAdmin , self ) . queryset ( request ) . only ( '<STR_LIT:title>' ) <EOL> class StoryForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> widgets = { '<STR_LIT:title>' : forms . HiddenInput } <EOL> class StoryAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:id>' , '<STR_LIT:title>' , '<STR_LIT:content>' ) <EOL> list_display_links = ( '<STR_LIT:title>' , ) <EOL> list_editable = ( '<STR_LIT:content>' , ) <EOL> form = StoryForm <EOL> ordering = [ "<STR_LIT>" ] <EOL> class OtherStoryAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:id>' , '<STR_LIT:title>' , '<STR_LIT:content>' ) <EOL> list_display_links = ( '<STR_LIT:title>' , '<STR_LIT:id>' ) <EOL> list_editable = ( '<STR_LIT:content>' , ) <EOL> ordering = [ "<STR_LIT>" ] <EOL> class ComplexSortedPersonAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ordering = ( '<STR_LIT:name>' , ) <EOL> def colored_name ( self , obj ) : <EOL> return '<STR_LIT>' % ( '<STR_LIT>' , obj . name ) <EOL> colored_name . allow_tags = True <EOL> colored_name . admin_order_field = '<STR_LIT:name>' <EOL> class AlbumAdmin ( admin . ModelAdmin ) : <EOL> list_filter = [ '<STR_LIT:title>' ] <EOL> class WorkHourAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_filter = ( '<STR_LIT>' , ) <EOL> class PrePopulatedPostLargeSlugAdmin ( admin . ModelAdmin ) : <EOL> prepopulated_fields = { <EOL> '<STR_LIT>' : ( '<STR_LIT:title>' , ) <EOL> } <EOL> class AdminOrderedFieldAdmin ( admin . ModelAdmin ) : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class AdminOrderedModelMethodAdmin ( admin . ModelAdmin ) : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class AdminOrderedAdminMethodAdmin ( admin . ModelAdmin ) : <EOL> def some_admin_order ( self , obj ) : <EOL> return obj . order <EOL> some_admin_order . admin_order_field = '<STR_LIT>' <EOL> ordering = ( '<STR_LIT>' , ) <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def admin_ordered_callable ( obj ) : <EOL> return obj . order <EOL> admin_ordered_callable . admin_order_field = '<STR_LIT>' <EOL> class AdminOrderedCallableAdmin ( admin . ModelAdmin ) : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> list_display = ( '<STR_LIT>' , admin_ordered_callable ) <EOL> class ReportAdmin ( admin . ModelAdmin ) : <EOL> def extra ( self , request ) : <EOL> return HttpResponse ( ) <EOL> def get_urls ( self ) : <EOL> return patterns ( '<STR_LIT>' , <EOL> url ( r'<STR_LIT>' , <EOL> self . extra , <EOL> name = '<STR_LIT>' ) , <EOL> ) <EOL> class CustomTemplateBooleanFieldListFilter ( BooleanFieldListFilter ) : <EOL> template = '<STR_LIT>' <EOL> class CustomTemplateFilterColorAdmin ( admin . ModelAdmin ) : <EOL> list_filter = ( ( '<STR_LIT>' , CustomTemplateBooleanFieldListFilter ) , ) <EOL> class RelatedPrepopulatedInline1 ( admin . StackedInline ) : <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( ( '<STR_LIT>' , '<STR_LIT:status>' ) , ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , ) , ) <EOL> } ) , <EOL> ) <EOL> model = RelatedPrepopulated <EOL> extra = <NUM_LIT:1> <EOL> prepopulated_fields = { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:status>' , '<STR_LIT:name>' ] } <EOL> class RelatedPrepopulatedInline2 ( admin . TabularInline ) : <EOL> model = RelatedPrepopulated <EOL> extra = <NUM_LIT:1> <EOL> prepopulated_fields = { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:status>' , '<STR_LIT:name>' ] } <EOL> class MainPrepopulatedAdmin ( admin . ModelAdmin ) : <EOL> inlines = [ RelatedPrepopulatedInline1 , RelatedPrepopulatedInline2 ] <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( ( '<STR_LIT>' , '<STR_LIT:status>' ) , ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , ) , ) <EOL> } ) , <EOL> ) <EOL> prepopulated_fields = { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:status>' , '<STR_LIT:name>' ] } <EOL> class UnorderedObjectAdmin ( admin . ModelAdmin ) : <EOL> list_display = [ '<STR_LIT:name>' ] <EOL> list_editable = [ '<STR_LIT:name>' ] <EOL> list_per_page = <NUM_LIT:2> <EOL> class UndeletableObjectAdmin ( admin . ModelAdmin ) : <EOL> def change_view ( self , * args , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = { '<STR_LIT>' : False } <EOL> return super ( UndeletableObjectAdmin , self ) . change_view ( * args , ** kwargs ) <EOL> def callable_on_unknown ( obj ) : <EOL> return obj . unknown <EOL> class AttributeErrorRaisingAdmin ( admin . ModelAdmin ) : <EOL> list_display = [ callable_on_unknown , ] <EOL> class MessageTestingAdmin ( admin . ModelAdmin ) : <EOL> actions = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def message_debug ( self , request , selected ) : <EOL> self . message_user ( request , "<STR_LIT>" , level = "<STR_LIT>" ) <EOL> def message_info ( self , request , selected ) : <EOL> self . message_user ( request , "<STR_LIT>" , level = "<STR_LIT:info>" ) <EOL> def message_success ( self , request , selected ) : <EOL> self . message_user ( request , "<STR_LIT>" , level = "<STR_LIT:success>" ) <EOL> def message_warning ( self , request , selected ) : <EOL> self . message_user ( request , "<STR_LIT>" , level = "<STR_LIT>" ) <EOL> def message_error ( self , request , selected ) : <EOL> self . message_user ( request , "<STR_LIT>" , level = "<STR_LIT:error>" ) <EOL> def message_extra_tags ( self , request , selected ) : <EOL> self . message_user ( request , "<STR_LIT>" , extra_tags = "<STR_LIT>" ) <EOL> class ChoiceList ( admin . ModelAdmin ) : <EOL> list_display = [ '<STR_LIT>' ] <EOL> readonly_fields = [ '<STR_LIT>' ] <EOL> fields = [ '<STR_LIT>' ] <EOL> site = admin . AdminSite ( name = "<STR_LIT>" ) <EOL> site . register ( Article , ArticleAdmin ) <EOL> site . register ( CustomArticle , CustomArticleAdmin ) <EOL> site . register ( Section , save_as = True , inlines = [ ArticleInline ] ) <EOL> site . register ( ModelWithStringPrimaryKey ) <EOL> site . register ( Color ) <EOL> site . register ( Thing , ThingAdmin ) <EOL> site . register ( Actor ) <EOL> site . register ( Inquisition , InquisitionAdmin ) <EOL> site . register ( Sketch , SketchAdmin ) <EOL> site . register ( Person , PersonAdmin ) <EOL> site . register ( Persona , PersonaAdmin ) <EOL> site . register ( Subscriber , SubscriberAdmin ) <EOL> site . register ( ExternalSubscriber , ExternalSubscriberAdmin ) <EOL> site . register ( OldSubscriber , OldSubscriberAdmin ) <EOL> site . register ( Podcast , PodcastAdmin ) <EOL> site . register ( Vodcast , VodcastAdmin ) <EOL> site . register ( Parent , ParentAdmin ) <EOL> site . register ( EmptyModel , EmptyModelAdmin ) <EOL> site . register ( Fabric , FabricAdmin ) <EOL> site . register ( Gallery , GalleryAdmin ) <EOL> site . register ( Picture , PictureAdmin ) <EOL> site . register ( Language , LanguageAdmin ) <EOL> site . register ( Recommendation , RecommendationAdmin ) <EOL> site . register ( Recommender ) <EOL> site . register ( Collector , CollectorAdmin ) <EOL> site . register ( Category , CategoryAdmin ) <EOL> site . register ( Post , PostAdmin ) <EOL> site . register ( Gadget , GadgetAdmin ) <EOL> site . register ( Villain ) <EOL> site . register ( SuperVillain ) <EOL> site . register ( Plot ) <EOL> site . register ( PlotDetails ) <EOL> site . register ( CyclicOne ) <EOL> site . register ( CyclicTwo ) <EOL> site . register ( WorkHour , WorkHourAdmin ) <EOL> site . register ( Reservation ) <EOL> site . register ( FoodDelivery , FoodDeliveryAdmin ) <EOL> site . register ( RowLevelChangePermissionModel , RowLevelChangePermissionModelAdmin ) <EOL> site . register ( Paper , PaperAdmin ) <EOL> site . register ( CoverLetter , CoverLetterAdmin ) <EOL> site . register ( ShortMessage , ShortMessageAdmin ) <EOL> site . register ( Telegram , TelegramAdmin ) <EOL> site . register ( Story , StoryAdmin ) <EOL> site . register ( OtherStory , OtherStoryAdmin ) <EOL> site . register ( Report , ReportAdmin ) <EOL> site . register ( MainPrepopulated , MainPrepopulatedAdmin ) <EOL> site . register ( UnorderedObject , UnorderedObjectAdmin ) <EOL> site . register ( UndeletableObject , UndeletableObjectAdmin ) <EOL> site . register ( Book , inlines = [ ChapterInline ] ) <EOL> site . register ( Promo ) <EOL> site . register ( ChapterXtra1 , ChapterXtra1Admin ) <EOL> site . register ( Pizza , PizzaAdmin ) <EOL> site . register ( Topping ) <EOL> site . register ( Album , AlbumAdmin ) <EOL> site . register ( Question ) <EOL> site . register ( Answer ) <EOL> site . register ( PrePopulatedPost , PrePopulatedPostAdmin ) <EOL> site . register ( ComplexSortedPerson , ComplexSortedPersonAdmin ) <EOL> site . register ( PrePopulatedPostLargeSlug , PrePopulatedPostLargeSlugAdmin ) <EOL> site . register ( AdminOrderedField , AdminOrderedFieldAdmin ) <EOL> site . register ( AdminOrderedModelMethod , AdminOrderedModelMethodAdmin ) <EOL> site . register ( AdminOrderedAdminMethod , AdminOrderedAdminMethodAdmin ) <EOL> site . register ( AdminOrderedCallable , AdminOrderedCallableAdmin ) <EOL> site . register ( Color2 , CustomTemplateFilterColorAdmin ) <EOL> site . register ( Simple , AttributeErrorRaisingAdmin ) <EOL> site . register ( UserMessenger , MessageTestingAdmin ) <EOL> site . register ( Choice , ChoiceList ) <EOL> from django . contrib . auth . models import User , Group <EOL> from django . contrib . auth . admin import UserAdmin , GroupAdmin <EOL> site . register ( User , UserAdmin ) <EOL> site . register ( Group , GroupAdmin ) </s>
|
<s> from __future__ import unicode_literals <EOL> from datetime import datetime <EOL> from django . test import TestCase <EOL> FULL_RESPONSE = '<STR_LIT>' <EOL> LAST_MODIFIED = datetime ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> LAST_MODIFIED_STR = '<STR_LIT>' <EOL> LAST_MODIFIED_NEWER_STR = '<STR_LIT>' <EOL> LAST_MODIFIED_INVALID_STR = '<STR_LIT>' <EOL> EXPIRED_LAST_MODIFIED_STR = '<STR_LIT>' <EOL> ETAG = '<STR_LIT>' <EOL> EXPIRED_ETAG = '<STR_LIT>' <EOL> class ConditionalGet ( TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> def assertFullResponse ( self , response , check_last_modified = True , check_etag = True ) : <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . content , FULL_RESPONSE . encode ( ) ) <EOL> if check_last_modified : <EOL> self . assertEqual ( response [ '<STR_LIT>' ] , LAST_MODIFIED_STR ) <EOL> if check_etag : <EOL> self . assertEqual ( response [ '<STR_LIT>' ] , '<STR_LIT>' % ETAG ) <EOL> def assertNotModified ( self , response ) : <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( response . content , b'<STR_LIT>' ) <EOL> def testWithoutConditions ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response ) <EOL> def testIfModifiedSince ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = LAST_MODIFIED_STR <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertNotModified ( response ) <EOL> self . client . defaults [ '<STR_LIT>' ] = LAST_MODIFIED_NEWER_STR <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertNotModified ( response ) <EOL> self . client . defaults [ '<STR_LIT>' ] = LAST_MODIFIED_INVALID_STR <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response ) <EOL> self . client . defaults [ '<STR_LIT>' ] = EXPIRED_LAST_MODIFIED_STR <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response ) <EOL> def testIfNoneMatch ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % ETAG <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertNotModified ( response ) <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % EXPIRED_ETAG <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response ) <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % ( ETAG , EXPIRED_ETAG ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertNotModified ( response ) <EOL> def testIfMatch ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % ETAG <EOL> response = self . client . put ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % EXPIRED_ETAG <EOL> response = self . client . put ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def testBothHeaders ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = LAST_MODIFIED_STR <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % ETAG <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertNotModified ( response ) <EOL> self . client . defaults [ '<STR_LIT>' ] = EXPIRED_LAST_MODIFIED_STR <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % ETAG <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response ) <EOL> self . client . defaults [ '<STR_LIT>' ] = LAST_MODIFIED_STR <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % EXPIRED_ETAG <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response ) <EOL> def testSingleCondition1 ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = LAST_MODIFIED_STR <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertNotModified ( response ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response , check_last_modified = False ) <EOL> def testSingleCondition2 ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % ETAG <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertNotModified ( response ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response , check_etag = False ) <EOL> def testSingleCondition3 ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = EXPIRED_LAST_MODIFIED_STR <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response , check_etag = False ) <EOL> def testSingleCondition4 ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % EXPIRED_ETAG <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response , check_last_modified = False ) <EOL> def testSingleCondition5 ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = LAST_MODIFIED_STR <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertNotModified ( response ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response , check_last_modified = False ) <EOL> def testSingleCondition6 ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = '<STR_LIT>' % ETAG <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertNotModified ( response ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response , check_etag = False ) <EOL> def testInvalidETag ( self ) : <EOL> self . client . defaults [ '<STR_LIT>' ] = r'<STR_LIT>' <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertFullResponse ( response , check_last_modified = False ) </s>
|
<s> from __future__ import absolute_import <EOL> from . error_messages import ( FormsErrorMessagesTestCase , <EOL> ModelChoiceFieldErrorMessagesTestCase ) <EOL> from . extra import FormsExtraTestCase , FormsExtraL10NTestCase <EOL> from . fields import FieldsTests <EOL> from . forms import FormsTestCase <EOL> from . formsets import ( FormsFormsetTestCase , FormsetAsFooTests , <EOL> TestIsBoundBehavior , TestEmptyFormSet ) <EOL> from . input_formats import ( LocalizedTimeTests , CustomTimeInputFormatsTests , <EOL> SimpleTimeFormatTests , LocalizedDateTests , CustomDateInputFormatsTests , <EOL> SimpleDateFormatTests , LocalizedDateTimeTests , <EOL> CustomDateTimeInputFormatsTests , SimpleDateTimeFormatTests ) <EOL> from . media import FormsMediaTestCase , StaticFormsMediaTestCase <EOL> from . models import ( TestTicket12510 , ModelFormCallableModelDefault , <EOL> FormsModelTestCase , RelatedModelFormTests ) <EOL> from . regressions import FormsRegressionsTestCase <EOL> from . util import FormsUtilTestCase <EOL> from . validators import TestFieldWithValidators <EOL> from . widgets import ( FormsWidgetTestCase , FormsI18NWidgetsTestCase , <EOL> WidgetTests , LiveWidgetTests , ClearableFileInputTests ) </s>
|
<s> """<STR_LIT>""" <EOL> from django . db import models <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> class OnlyFred ( models . Manager ) : <EOL> def get_query_set ( self ) : <EOL> return super ( OnlyFred , self ) . get_query_set ( ) . filter ( name = '<STR_LIT>' ) <EOL> class OnlyBarney ( models . Manager ) : <EOL> def get_query_set ( self ) : <EOL> return super ( OnlyBarney , self ) . get_query_set ( ) . filter ( name = '<STR_LIT>' ) <EOL> class Value42 ( models . Manager ) : <EOL> def get_query_set ( self ) : <EOL> return super ( Value42 , self ) . get_query_set ( ) . filter ( value = <NUM_LIT> ) <EOL> class AbstractBase1 ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:50> ) <EOL> class Meta : <EOL> abstract = True <EOL> manager1 = OnlyFred ( ) <EOL> manager2 = OnlyBarney ( ) <EOL> objects = models . Manager ( ) <EOL> class AbstractBase2 ( models . Model ) : <EOL> value = models . IntegerField ( ) <EOL> class Meta : <EOL> abstract = True <EOL> restricted = Value42 ( ) <EOL> class AbstractBase3 ( models . Model ) : <EOL> comment = models . CharField ( max_length = <NUM_LIT:50> ) <EOL> class Meta : <EOL> abstract = True <EOL> @ python_2_unicode_compatible <EOL> class Parent ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:50> ) <EOL> manager = OnlyFred ( ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> @ python_2_unicode_compatible <EOL> class Child1 ( AbstractBase1 ) : <EOL> data = models . CharField ( max_length = <NUM_LIT> ) <EOL> def __str__ ( self ) : <EOL> return self . data <EOL> @ python_2_unicode_compatible <EOL> class Child2 ( AbstractBase1 , AbstractBase2 ) : <EOL> data = models . CharField ( max_length = <NUM_LIT> ) <EOL> def __str__ ( self ) : <EOL> return self . data <EOL> @ python_2_unicode_compatible <EOL> class Child3 ( AbstractBase1 , AbstractBase3 ) : <EOL> data = models . CharField ( max_length = <NUM_LIT> ) <EOL> def __str__ ( self ) : <EOL> return self . data <EOL> @ python_2_unicode_compatible <EOL> class Child4 ( AbstractBase1 ) : <EOL> data = models . CharField ( max_length = <NUM_LIT> ) <EOL> default = models . Manager ( ) <EOL> def __str__ ( self ) : <EOL> return self . data <EOL> @ python_2_unicode_compatible <EOL> class Child5 ( AbstractBase3 ) : <EOL> name = models . CharField ( max_length = <NUM_LIT> ) <EOL> default = OnlyFred ( ) <EOL> objects = models . Manager ( ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> class Child6 ( Child4 ) : <EOL> value = models . IntegerField ( ) <EOL> class Child7 ( Parent ) : <EOL> pass </s>
|
<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from django . db import models <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> class Author ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT> ) <EOL> @ python_2_unicode_compatible <EOL> class Article ( models . Model ) : <EOL> title = models . CharField ( max_length = <NUM_LIT> ) <EOL> author = models . ForeignKey ( Author , null = True ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . title , ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' , ] <EOL> class SystemInfo ( models . Model ) : <EOL> system_name = models . CharField ( max_length = <NUM_LIT:32> ) <EOL> class Forum ( models . Model ) : <EOL> system_info = models . ForeignKey ( SystemInfo ) <EOL> forum_name = models . CharField ( max_length = <NUM_LIT:32> ) <EOL> @ python_2_unicode_compatible <EOL> class Post ( models . Model ) : <EOL> forum = models . ForeignKey ( Forum , null = True ) <EOL> title = models . CharField ( max_length = <NUM_LIT:32> ) <EOL> def __str__ ( self ) : <EOL> return self . title <EOL> @ python_2_unicode_compatible <EOL> class Comment ( models . Model ) : <EOL> post = models . ForeignKey ( Post , null = True ) <EOL> comment_text = models . CharField ( max_length = <NUM_LIT> ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . comment_text </s>
|
<s> from django . core . xheaders import populate_xheaders <EOL> from django . http import HttpResponse <EOL> from django . utils . decorators import decorator_from_middleware <EOL> from django . views . generic import View <EOL> from django . middleware . doc import XViewMiddleware <EOL> from . models import Article <EOL> xview_dec = decorator_from_middleware ( XViewMiddleware ) <EOL> def xview ( request ) : <EOL> return HttpResponse ( ) <EOL> def xview_xheaders ( request , object_id ) : <EOL> response = HttpResponse ( ) <EOL> populate_xheaders ( request , response , Article , <NUM_LIT:1> ) <EOL> return response <EOL> class XViewClass ( View ) : <EOL> def get ( self , request ) : <EOL> return HttpResponse ( ) </s>
|
<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import pickle <EOL> import threading <EOL> from apiclient . oauth import Storage as BaseStorage <EOL> class Storage ( BaseStorage ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename ) : <EOL> self . _filename = filename <EOL> self . _lock = threading . Lock ( ) <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _lock . acquire ( ) <EOL> try : <EOL> f = open ( self . _filename , '<STR_LIT:r>' ) <EOL> credentials = pickle . loads ( f . read ( ) ) <EOL> f . close ( ) <EOL> credentials . set_store ( self . put ) <EOL> except : <EOL> credentials = None <EOL> self . _lock . release ( ) <EOL> return credentials <EOL> def put ( self , credentials ) : <EOL> """<STR_LIT>""" <EOL> self . _lock . acquire ( ) <EOL> f = open ( self . _filename , '<STR_LIT:w>' ) <EOL> f . write ( pickle . dumps ( credentials ) ) <EOL> f . close ( ) <EOL> self . _lock . release ( ) </s>
|
<s> """<STR_LIT>""" <EOL> __docformat__ = "<STR_LIT>" <EOL> from optparse import OptionParser <EOL> import sys <EOL> __all__ = [ '<STR_LIT>' ] <EOL> class CommandLineParser ( OptionParser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kw ) : <EOL> """<STR_LIT>""" <EOL> OptionParser . __init__ ( self , * args , ** kw ) <EOL> self . remove_option ( '<STR_LIT>' ) <EOL> self . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> self . epilogue = None <EOL> def print_help ( self , out = sys . stderr ) : <EOL> """<STR_LIT>""" <EOL> OptionParser . print_help ( self , out ) <EOL> if self . epilogue : <EOL> import textwrap <EOL> print >> out , '<STR_LIT>' % textwrap . fill ( self . epilogue , <NUM_LIT> ) <EOL> out . flush ( ) <EOL> def die_with_usage ( self , msg = None , exit_code = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> if msg != None : <EOL> print >> sys . stderr , msg <EOL> self . print_help ( sys . stderr ) <EOL> sys . exit ( exit_code ) <EOL> def error ( self , msg ) : <EOL> """<STR_LIT>""" <EOL> sys . stderr . write ( "<STR_LIT>" % ( self . get_prog_name ( ) , msg ) ) <EOL> self . die_with_usage ( msg ) </s>
|
<s> from __future__ import absolute_import <EOL> from grizzled . proxy import Forwarder <EOL> import tempfile <EOL> from grizzled . file import unlink_quietly <EOL> from . test_helpers import exception_expected <EOL> class ForwardToFile ( Forwarder ) : <EOL> def __init__ ( self , file , * exceptions ) : <EOL> Forwarder . __init__ ( self , file , exceptions ) <EOL> class TestProxyPackage ( object ) : <EOL> def test_forward_all ( self ) : <EOL> path = self . _create_file ( ) <EOL> try : <EOL> with open ( path ) as f : <EOL> contents = '<STR_LIT>' . join ( f . readlines ( ) ) <EOL> with open ( path ) as f : <EOL> fwd = ForwardToFile ( f ) <EOL> contents2 = '<STR_LIT>' . join ( fwd . readlines ( ) ) <EOL> assert contents2 == contents <EOL> finally : <EOL> unlink_quietly ( path ) <EOL> def test_forward_all_but_name ( self ) : <EOL> path = self . _create_file ( ) <EOL> try : <EOL> with exception_expected ( AttributeError ) : <EOL> with open ( path ) as f : <EOL> fwd = ForwardToFile ( f , '<STR_LIT:name>' , '<STR_LIT:foo>' ) <EOL> fwd . name <EOL> finally : <EOL> unlink_quietly ( path ) <EOL> def test_forward_all_but_name_mode ( self ) : <EOL> path = self . _create_file ( ) <EOL> try : <EOL> with open ( path ) as f : <EOL> fwd = ForwardToFile ( f , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> fwd . closed <EOL> with exception_expected ( AttributeError ) : <EOL> fwd . name <EOL> with exception_expected ( AttributeError ) : <EOL> fwd . mode <EOL> finally : <EOL> unlink_quietly ( path ) <EOL> def _create_file ( self ) : <EOL> temp = tempfile . NamedTemporaryFile ( prefix = "<STR_LIT>" , delete = False ) <EOL> temp . write ( '<STR_LIT:U+002CU+0020>' . join ( [ str ( x ) for x in range ( <NUM_LIT:1> , <NUM_LIT> ) ] ) ) <EOL> temp . write ( '<STR_LIT:U+002CU+0020>' . join ( [ str ( x ) for x in range ( <NUM_LIT:1> , <NUM_LIT> ) ] ) ) <EOL> temp . close <EOL> return temp . name </s>
|
<s> from jinja2 import Environment <EOL> from jinja2 . loaders import DictLoader <EOL> env = Environment ( loader = DictLoader ( { <EOL> '<STR_LIT>' : u'''<STR_LIT>''' , <EOL> '<STR_LIT>' : u'''<STR_LIT>''' , <EOL> '<STR_LIT>' : u'''<STR_LIT>''' <EOL> } ) ) <EOL> tmpl = env . get_template ( "<STR_LIT>" ) <EOL> print tmpl . render ( ) </s>
|
<s> """<STR_LIT>""" <EOL> from collections import deque <EOL> from jinja2 import nodes <EOL> from jinja2 . defaults import * <EOL> from jinja2 . environment import Environment <EOL> from jinja2 . runtime import Undefined , concat <EOL> from jinja2 . exceptions import TemplateAssertionError , TemplateSyntaxError <EOL> from jinja2 . utils import contextfunction , import_string , Markup , next <EOL> GETTEXT_FUNCTIONS = ( '<STR_LIT:_>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class ExtensionRegistry ( type ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , name , bases , d ) : <EOL> rv = type . __new__ ( cls , name , bases , d ) <EOL> rv . identifier = rv . __module__ + '<STR_LIT:.>' + rv . __name__ <EOL> return rv <EOL> class Extension ( object ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = ExtensionRegistry <EOL> tags = set ( ) <EOL> priority = <NUM_LIT:100> <EOL> def __init__ ( self , environment ) : <EOL> self . environment = environment <EOL> def bind ( self , environment ) : <EOL> """<STR_LIT>""" <EOL> rv = object . __new__ ( self . __class__ ) <EOL> rv . __dict__ . update ( self . __dict__ ) <EOL> rv . environment = environment <EOL> return rv <EOL> def preprocess ( self , source , name , filename = None ) : <EOL> """<STR_LIT>""" <EOL> return source <EOL> def filter_stream ( self , stream ) : <EOL> """<STR_LIT>""" <EOL> return stream <EOL> def parse ( self , parser ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def attr ( self , name , lineno = None ) : <EOL> """<STR_LIT>""" <EOL> return nodes . ExtensionAttribute ( self . identifier , name , lineno = lineno ) <EOL> def call_method ( self , name , args = None , kwargs = None , dyn_args = None , <EOL> dyn_kwargs = None , lineno = None ) : <EOL> """<STR_LIT>""" <EOL> if args is None : <EOL> args = [ ] <EOL> if kwargs is None : <EOL> kwargs = [ ] <EOL> return nodes . Call ( self . attr ( name , lineno = lineno ) , args , kwargs , <EOL> dyn_args , dyn_kwargs , lineno = lineno ) <EOL> @ contextfunction <EOL> def _gettext_alias ( __context , * args , ** kwargs ) : <EOL> return __context . call ( __context . resolve ( '<STR_LIT>' ) , * args , ** kwargs ) <EOL> def _make_new_gettext ( func ) : <EOL> @ contextfunction <EOL> def gettext ( __context , __string , ** variables ) : <EOL> rv = __context . call ( func , __string ) <EOL> if __context . eval_ctx . autoescape : <EOL> rv = Markup ( rv ) <EOL> return rv % variables <EOL> return gettext <EOL> def _make_new_ngettext ( func ) : <EOL> @ contextfunction <EOL> def ngettext ( __context , __singular , __plural , __num , ** variables ) : <EOL> variables . setdefault ( '<STR_LIT>' , __num ) <EOL> rv = __context . call ( func , __singular , __plural , __num ) <EOL> if __context . eval_ctx . autoescape : <EOL> rv = Markup ( rv ) <EOL> return rv % variables <EOL> return ngettext <EOL> class InternationalizationExtension ( Extension ) : <EOL> """<STR_LIT>""" <EOL> tags = set ( [ '<STR_LIT>' ] ) <EOL> def __init__ ( self , environment ) : <EOL> Extension . __init__ ( self , environment ) <EOL> environment . globals [ '<STR_LIT:_>' ] = _gettext_alias <EOL> environment . extend ( <EOL> install_gettext_translations = self . _install , <EOL> install_null_translations = self . _install_null , <EOL> install_gettext_callables = self . _install_callables , <EOL> uninstall_gettext_translations = self . _uninstall , <EOL> extract_translations = self . _extract , <EOL> newstyle_gettext = False <EOL> ) <EOL> def _install ( self , translations , newstyle = None ) : <EOL> gettext = getattr ( translations , '<STR_LIT>' , None ) <EOL> if gettext is None : <EOL> gettext = translations . gettext <EOL> ngettext = getattr ( translations , '<STR_LIT>' , None ) <EOL> if ngettext is None : <EOL> ngettext = translations . ngettext <EOL> self . _install_callables ( gettext , ngettext , newstyle ) <EOL> def _install_null ( self , newstyle = None ) : <EOL> self . _install_callables ( <EOL> lambda x : x , <EOL> lambda s , p , n : ( n != <NUM_LIT:1> and ( p , ) or ( s , ) ) [ <NUM_LIT:0> ] , <EOL> newstyle <EOL> ) <EOL> def _install_callables ( self , gettext , ngettext , newstyle = None ) : <EOL> if newstyle is not None : <EOL> self . environment . newstyle_gettext = newstyle <EOL> if self . environment . newstyle_gettext : <EOL> gettext = _make_new_gettext ( gettext ) <EOL> ngettext = _make_new_ngettext ( ngettext ) <EOL> self . environment . globals . update ( <EOL> gettext = gettext , <EOL> ngettext = ngettext <EOL> ) <EOL> def _uninstall ( self , translations ) : <EOL> for key in '<STR_LIT>' , '<STR_LIT>' : <EOL> self . environment . globals . pop ( key , None ) <EOL> def _extract ( self , source , gettext_functions = GETTEXT_FUNCTIONS ) : <EOL> if isinstance ( source , basestring ) : <EOL> source = self . environment . parse ( source ) <EOL> return extract_from_ast ( source , gettext_functions ) <EOL> def parse ( self , parser ) : <EOL> """<STR_LIT>""" <EOL> lineno = next ( parser . stream ) . lineno <EOL> num_called_num = False <EOL> plural_expr = None <EOL> variables = { } <EOL> while parser . stream . current . type != '<STR_LIT>' : <EOL> if variables : <EOL> parser . stream . expect ( '<STR_LIT>' ) <EOL> if parser . stream . skip_if ( '<STR_LIT>' ) : <EOL> break <EOL> name = parser . stream . expect ( '<STR_LIT:name>' ) <EOL> if name . value in variables : <EOL> parser . fail ( '<STR_LIT>' % <EOL> name . value , name . lineno , <EOL> exc = TemplateAssertionError ) <EOL> if parser . stream . current . type == '<STR_LIT>' : <EOL> next ( parser . stream ) <EOL> variables [ name . value ] = var = parser . parse_expression ( ) <EOL> else : <EOL> variables [ name . value ] = var = nodes . Name ( name . value , '<STR_LIT>' ) <EOL> if plural_expr is None : <EOL> plural_expr = var <EOL> num_called_num = name . value == '<STR_LIT>' <EOL> parser . stream . expect ( '<STR_LIT>' ) <EOL> plural = plural_names = None <EOL> have_plural = False <EOL> referenced = set ( ) <EOL> singular_names , singular = self . _parse_block ( parser , True ) <EOL> if singular_names : <EOL> referenced . update ( singular_names ) <EOL> if plural_expr is None : <EOL> plural_expr = nodes . Name ( singular_names [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> num_called_num = singular_names [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> if parser . stream . current . test ( '<STR_LIT>' ) : <EOL> have_plural = True <EOL> next ( parser . stream ) <EOL> if parser . stream . current . type != '<STR_LIT>' : <EOL> name = parser . stream . expect ( '<STR_LIT:name>' ) <EOL> if name . value not in variables : <EOL> parser . fail ( '<STR_LIT>' % <EOL> name . value , name . lineno , <EOL> exc = TemplateAssertionError ) <EOL> plural_expr = variables [ name . value ] <EOL> num_called_num = name . value == '<STR_LIT>' <EOL> parser . stream . expect ( '<STR_LIT>' ) <EOL> plural_names , plural = self . _parse_block ( parser , False ) <EOL> next ( parser . stream ) <EOL> referenced . update ( plural_names ) <EOL> else : <EOL> next ( parser . stream ) <EOL> for var in referenced : <EOL> if var not in variables : <EOL> variables [ var ] = nodes . Name ( var , '<STR_LIT>' ) <EOL> if not have_plural : <EOL> plural_expr = None <EOL> elif plural_expr is None : <EOL> parser . fail ( '<STR_LIT>' , lineno ) <EOL> node = self . _make_node ( singular , plural , variables , plural_expr , <EOL> bool ( referenced ) , <EOL> num_called_num and have_plural ) <EOL> node . set_lineno ( lineno ) <EOL> return node <EOL> def _parse_block ( self , parser , allow_pluralize ) : <EOL> """<STR_LIT>""" <EOL> referenced = [ ] <EOL> buf = [ ] <EOL> while <NUM_LIT:1> : <EOL> if parser . stream . current . type == '<STR_LIT:data>' : <EOL> buf . append ( parser . stream . current . value . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) ) <EOL> next ( parser . stream ) <EOL> elif parser . stream . current . type == '<STR_LIT>' : <EOL> next ( parser . stream ) <EOL> name = parser . stream . expect ( '<STR_LIT:name>' ) . value <EOL> referenced . append ( name ) <EOL> buf . append ( '<STR_LIT>' % name ) <EOL> parser . stream . expect ( '<STR_LIT>' ) <EOL> elif parser . stream . current . type == '<STR_LIT>' : <EOL> next ( parser . stream ) <EOL> if parser . stream . current . test ( '<STR_LIT>' ) : <EOL> break <EOL> elif parser . stream . current . test ( '<STR_LIT>' ) : <EOL> if allow_pluralize : <EOL> break <EOL> parser . fail ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . fail ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif parser . stream . eos : <EOL> parser . fail ( '<STR_LIT>' ) <EOL> else : <EOL> assert False , '<STR_LIT>' <EOL> return referenced , concat ( buf ) <EOL> def _make_node ( self , singular , plural , variables , plural_expr , <EOL> vars_referenced , num_called_num ) : <EOL> """<STR_LIT>""" <EOL> if not vars_referenced and not self . environment . newstyle_gettext : <EOL> singular = singular . replace ( '<STR_LIT>' , '<STR_LIT:%>' ) <EOL> if plural : <EOL> plural = plural . replace ( '<STR_LIT>' , '<STR_LIT:%>' ) <EOL> if plural_expr is None : <EOL> gettext = nodes . Name ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> node = nodes . Call ( gettext , [ nodes . Const ( singular ) ] , <EOL> [ ] , None , None ) <EOL> else : <EOL> ngettext = nodes . Name ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> node = nodes . Call ( ngettext , [ <EOL> nodes . Const ( singular ) , <EOL> nodes . Const ( plural ) , <EOL> plural_expr <EOL> ] , [ ] , None , None ) <EOL> if self . environment . newstyle_gettext : <EOL> for key , value in variables . iteritems ( ) : <EOL> if num_called_num and key == '<STR_LIT>' : <EOL> continue <EOL> node . kwargs . append ( nodes . Keyword ( key , value ) ) <EOL> else : <EOL> node = nodes . MarkSafeIfAutoescape ( node ) <EOL> if variables : <EOL> node = nodes . Mod ( node , nodes . Dict ( [ <EOL> nodes . Pair ( nodes . Const ( key ) , value ) <EOL> for key , value in variables . items ( ) <EOL> ] ) ) <EOL> return nodes . Output ( [ node ] ) <EOL> class ExprStmtExtension ( Extension ) : <EOL> """<STR_LIT>""" <EOL> tags = set ( [ '<STR_LIT>' ] ) <EOL> def parse ( self , parser ) : <EOL> node = nodes . ExprStmt ( lineno = next ( parser . stream ) . lineno ) <EOL> node . node = parser . parse_tuple ( ) <EOL> return node <EOL> class LoopControlExtension ( Extension ) : <EOL> """<STR_LIT>""" <EOL> tags = set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def parse ( self , parser ) : <EOL> token = next ( parser . stream ) <EOL> if token . value == '<STR_LIT>' : <EOL> return nodes . Break ( lineno = token . lineno ) <EOL> return nodes . Continue ( lineno = token . lineno ) <EOL> class WithExtension ( Extension ) : <EOL> """<STR_LIT>""" <EOL> tags = set ( [ '<STR_LIT>' ] ) <EOL> def parse ( self , parser ) : <EOL> node = nodes . Scope ( lineno = next ( parser . stream ) . lineno ) <EOL> assignments = [ ] <EOL> while parser . stream . current . type != '<STR_LIT>' : <EOL> lineno = parser . stream . current . lineno <EOL> if assignments : <EOL> parser . stream . expect ( '<STR_LIT>' ) <EOL> target = parser . parse_assign_target ( ) <EOL> parser . stream . expect ( '<STR_LIT>' ) <EOL> expr = parser . parse_expression ( ) <EOL> assignments . append ( nodes . Assign ( target , expr , lineno = lineno ) ) <EOL> node . body = assignments + list ( parser . parse_statements ( ( '<STR_LIT>' , ) , <EOL> drop_needle = True ) ) <EOL> return node <EOL> class AutoEscapeExtension ( Extension ) : <EOL> """<STR_LIT>""" <EOL> tags = set ( [ '<STR_LIT>' ] ) <EOL> def parse ( self , parser ) : <EOL> node = nodes . ScopedEvalContextModifier ( lineno = next ( parser . stream ) . lineno ) <EOL> node . options = [ <EOL> nodes . Keyword ( '<STR_LIT>' , parser . parse_expression ( ) ) <EOL> ] <EOL> node . body = parser . parse_statements ( ( '<STR_LIT>' , ) , <EOL> drop_needle = True ) <EOL> return nodes . Scope ( [ node ] ) <EOL> def extract_from_ast ( node , gettext_functions = GETTEXT_FUNCTIONS , <EOL> babel_style = True ) : <EOL> """<STR_LIT>""" <EOL> for node in node . find_all ( nodes . Call ) : <EOL> if not isinstance ( node . node , nodes . Name ) or node . node . name not in gettext_functions : <EOL> continue <EOL> strings = [ ] <EOL> for arg in node . args : <EOL> if isinstance ( arg , nodes . Const ) and isinstance ( arg . value , basestring ) : <EOL> strings . append ( arg . value ) <EOL> else : <EOL> strings . append ( None ) <EOL> for arg in node . kwargs : <EOL> strings . append ( None ) <EOL> if node . dyn_args is not None : <EOL> strings . append ( None ) <EOL> if node . dyn_kwargs is not None : <EOL> strings . append ( None ) <EOL> if not babel_style : <EOL> strings = tuple ( x for x in strings if x is not None ) <EOL> if not strings : <EOL> continue <EOL> else : <EOL> if len ( strings ) == <NUM_LIT:1> : <EOL> strings = strings [ <NUM_LIT:0> ] <EOL> else : <EOL> strings = tuple ( strings ) <EOL> yield node . lineno , node . node . name , strings <EOL> class _CommentFinder ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , tokens , comment_tags ) : <EOL> self . tokens = tokens <EOL> self . comment_tags = comment_tags <EOL> self . offset = <NUM_LIT:0> <EOL> self . last_lineno = <NUM_LIT:0> <EOL> def find_backwards ( self , offset ) : <EOL> try : <EOL> for _ , token_type , token_value in reversed ( self . tokens [ self . offset : offset ] ) : <EOL> if token_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> try : <EOL> prefix , comment = token_value . split ( None , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> continue <EOL> if prefix in self . comment_tags : <EOL> return [ comment . rstrip ( ) ] <EOL> return [ ] <EOL> finally : <EOL> self . offset = offset <EOL> def find_comments ( self , lineno ) : <EOL> if not self . comment_tags or self . last_lineno > lineno : <EOL> return [ ] <EOL> for idx , ( token_lineno , _ , _ ) in enumerate ( self . tokens [ self . offset : ] ) : <EOL> if token_lineno > lineno : <EOL> return self . find_backwards ( self . offset + idx ) <EOL> return self . find_backwards ( len ( self . tokens ) ) <EOL> def babel_extract ( fileobj , keywords , comment_tags , options ) : <EOL> """<STR_LIT>""" <EOL> extensions = set ( ) <EOL> for extension in options . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) : <EOL> extension = extension . strip ( ) <EOL> if not extension : <EOL> continue <EOL> extensions . add ( import_string ( extension ) ) <EOL> if InternationalizationExtension not in extensions : <EOL> extensions . add ( InternationalizationExtension ) <EOL> def getbool ( options , key , default = False ) : <EOL> options . get ( key , str ( default ) ) . lower ( ) in ( '<STR_LIT:1>' , '<STR_LIT>' , '<STR_LIT:yes>' , '<STR_LIT:true>' ) <EOL> environment = Environment ( <EOL> options . get ( '<STR_LIT>' , BLOCK_START_STRING ) , <EOL> options . get ( '<STR_LIT>' , BLOCK_END_STRING ) , <EOL> options . get ( '<STR_LIT>' , VARIABLE_START_STRING ) , <EOL> options . get ( '<STR_LIT>' , VARIABLE_END_STRING ) , <EOL> options . get ( '<STR_LIT>' , COMMENT_START_STRING ) , <EOL> options . get ( '<STR_LIT>' , COMMENT_END_STRING ) , <EOL> options . get ( '<STR_LIT>' ) or LINE_STATEMENT_PREFIX , <EOL> options . get ( '<STR_LIT>' ) or LINE_COMMENT_PREFIX , <EOL> getbool ( options , '<STR_LIT>' , TRIM_BLOCKS ) , <EOL> NEWLINE_SEQUENCE , frozenset ( extensions ) , <EOL> cache_size = <NUM_LIT:0> , <EOL> auto_reload = False <EOL> ) <EOL> if getbool ( options , '<STR_LIT>' ) : <EOL> environment . newstyle_gettext = True <EOL> source = fileobj . read ( ) . decode ( options . get ( '<STR_LIT>' , '<STR_LIT:utf-8>' ) ) <EOL> try : <EOL> node = environment . parse ( source ) <EOL> tokens = list ( environment . lex ( environment . preprocess ( source ) ) ) <EOL> except TemplateSyntaxError , e : <EOL> return <EOL> finder = _CommentFinder ( tokens , comment_tags ) <EOL> for lineno , func , message in extract_from_ast ( node , keywords ) : <EOL> yield lineno , func , message , finder . find_comments ( lineno ) <EOL> i18n = InternationalizationExtension <EOL> do = ExprStmtExtension <EOL> loopcontrols = LoopControlExtension <EOL> with_ = WithExtension <EOL> autoescape = AutoEscapeExtension </s>
|
<s> """<STR_LIT>""" <EOL> import sys <EOL> from setuptools import setup , Extension , Feature <EOL> debugsupport = Feature ( <EOL> '<STR_LIT>' , <EOL> standard = False , <EOL> ext_modules = [ <EOL> Extension ( '<STR_LIT>' , [ '<STR_LIT>' ] ) , <EOL> ] , <EOL> ) <EOL> extra = { } <EOL> if sys . version_info >= ( <NUM_LIT:3> , <NUM_LIT:0> ) : <EOL> extra . update ( <EOL> use_2to3 = True , <EOL> use_2to3_fixers = [ '<STR_LIT>' ] <EOL> ) <EOL> try : <EOL> speedups_pos = sys . argv . index ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> sys . argv [ speedups_pos ] = '<STR_LIT>' <EOL> sys . stderr . write ( '<STR_LIT:*>' * <NUM_LIT> + '<STR_LIT:\n>' ) <EOL> sys . stderr . write ( '<STR_LIT>' ) <EOL> sys . stderr . write ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> sys . stderr . write ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> sys . stderr . write ( '<STR_LIT:*>' * <NUM_LIT> + '<STR_LIT:\n>' ) <EOL> setup ( <EOL> name = '<STR_LIT>' , <EOL> version = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> license = '<STR_LIT>' , <EOL> author = '<STR_LIT>' , <EOL> author_email = '<STR_LIT>' , <EOL> description = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> long_description = __doc__ , <EOL> zip_safe = False , <EOL> classifiers = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] , <EOL> packages = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> extras_require = { '<STR_LIT>' : [ '<STR_LIT>' ] } , <EOL> test_suite = '<STR_LIT>' , <EOL> include_package_data = True , <EOL> entry_points = """<STR_LIT>""" , <EOL> features = { '<STR_LIT>' : debugsupport } , <EOL> ** extra <EOL> ) </s>
|
<s> __author__ = '<STR_LIT>' </s>
|
<s> import os . path , sys , fnmatch <EOL> from distutils . command . build_py import build_py as _build_py <EOL> from distutils . util import convert_path <EOL> from glob import glob <EOL> class build_py ( _build_py ) : <EOL> """<STR_LIT>""" <EOL> def finalize_options ( self ) : <EOL> _build_py . finalize_options ( self ) <EOL> self . package_data = self . distribution . package_data <EOL> self . exclude_package_data = self . distribution . exclude_package_data or { } <EOL> if '<STR_LIT>' in self . __dict__ : del self . __dict__ [ '<STR_LIT>' ] <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . py_modules and not self . packages : <EOL> return <EOL> if self . py_modules : <EOL> self . build_modules ( ) <EOL> if self . packages : <EOL> self . build_packages ( ) <EOL> self . build_package_data ( ) <EOL> self . byte_compile ( _build_py . get_outputs ( self , include_bytecode = <NUM_LIT:0> ) ) <EOL> def __getattr__ ( self , attr ) : <EOL> if attr == '<STR_LIT>' : <EOL> self . data_files = files = self . _get_data_files ( ) ; return files <EOL> return _build_py . __getattr__ ( self , attr ) <EOL> def _get_data_files ( self ) : <EOL> """<STR_LIT>""" <EOL> self . analyze_manifest ( ) <EOL> data = [ ] <EOL> for package in self . packages or ( ) : <EOL> src_dir = self . get_package_dir ( package ) <EOL> build_dir = os . path . join ( * ( [ self . build_lib ] + package . split ( '<STR_LIT:.>' ) ) ) <EOL> plen = len ( src_dir ) + <NUM_LIT:1> <EOL> filenames = [ <EOL> file [ plen : ] for file in self . find_data_files ( package , src_dir ) <EOL> ] <EOL> data . append ( ( package , src_dir , build_dir , filenames ) ) <EOL> return data <EOL> def find_data_files ( self , package , src_dir ) : <EOL> """<STR_LIT>""" <EOL> globs = ( self . package_data . get ( '<STR_LIT>' , [ ] ) <EOL> + self . package_data . get ( package , [ ] ) ) <EOL> files = self . manifest_files . get ( package , [ ] ) [ : ] <EOL> for pattern in globs : <EOL> files . extend ( glob ( os . path . join ( src_dir , convert_path ( pattern ) ) ) ) <EOL> return self . exclude_data_files ( package , src_dir , files ) <EOL> def build_package_data ( self ) : <EOL> """<STR_LIT>""" <EOL> lastdir = None <EOL> for package , src_dir , build_dir , filenames in self . data_files : <EOL> for filename in filenames : <EOL> target = os . path . join ( build_dir , filename ) <EOL> self . mkpath ( os . path . dirname ( target ) ) <EOL> self . copy_file ( os . path . join ( src_dir , filename ) , target ) <EOL> def analyze_manifest ( self ) : <EOL> self . manifest_files = mf = { } <EOL> if not self . distribution . include_package_data : <EOL> return <EOL> src_dirs = { } <EOL> for package in self . packages or ( ) : <EOL> src_dirs [ assert_relative ( self . get_package_dir ( package ) ) ] = package <EOL> self . run_command ( '<STR_LIT>' ) <EOL> ei_cmd = self . get_finalized_command ( '<STR_LIT>' ) <EOL> for path in ei_cmd . filelist . files : <EOL> d , f = os . path . split ( assert_relative ( path ) ) <EOL> prev = None <EOL> oldf = f <EOL> while d and d != prev and d not in src_dirs : <EOL> prev = d <EOL> d , df = os . path . split ( d ) <EOL> f = os . path . join ( df , f ) <EOL> if d in src_dirs : <EOL> if path . endswith ( '<STR_LIT>' ) and f == oldf : <EOL> continue <EOL> mf . setdefault ( src_dirs [ d ] , [ ] ) . append ( path ) <EOL> def get_data_files ( self ) : pass <EOL> if sys . version < "<STR_LIT>" : <EOL> def get_outputs ( self , include_bytecode = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> return _build_py . get_outputs ( self , include_bytecode ) + [ <EOL> os . path . join ( build_dir , filename ) <EOL> for package , src_dir , build_dir , filenames in self . data_files <EOL> for filename in filenames <EOL> ] <EOL> def check_package ( self , package , package_dir ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . packages_checked [ package ] <EOL> except KeyError : <EOL> pass <EOL> init_py = _build_py . check_package ( self , package , package_dir ) <EOL> self . packages_checked [ package ] = init_py <EOL> if not init_py or not self . distribution . namespace_packages : <EOL> return init_py <EOL> for pkg in self . distribution . namespace_packages : <EOL> if pkg == package or pkg . startswith ( package + '<STR_LIT:.>' ) : <EOL> break <EOL> else : <EOL> return init_py <EOL> f = open ( init_py , '<STR_LIT>' ) <EOL> if '<STR_LIT>' not in f . read ( ) : <EOL> from distutils import log <EOL> log . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> '<STR_LIT>' <EOL> "<STR_LIT>" , package <EOL> ) <EOL> f . close ( ) <EOL> return init_py <EOL> def initialize_options ( self ) : <EOL> self . packages_checked = { } <EOL> _build_py . initialize_options ( self ) <EOL> def exclude_data_files ( self , package , src_dir , files ) : <EOL> """<STR_LIT>""" <EOL> globs = ( self . exclude_package_data . get ( '<STR_LIT>' , [ ] ) <EOL> + self . exclude_package_data . get ( package , [ ] ) ) <EOL> bad = [ ] <EOL> for pattern in globs : <EOL> bad . extend ( <EOL> fnmatch . filter ( <EOL> files , os . path . join ( src_dir , convert_path ( pattern ) ) <EOL> ) <EOL> ) <EOL> bad = dict . fromkeys ( bad ) <EOL> seen = { } <EOL> return [ <EOL> f for f in files if f not in bad <EOL> and f not in seen and seen . setdefault ( f , <NUM_LIT:1> ) <EOL> ] <EOL> def assert_relative ( path ) : <EOL> if not os . path . isabs ( path ) : <EOL> return path <EOL> from distutils . errors import DistutilsSetupError <EOL> raise DistutilsSetupError ( <EOL> """<STR_LIT>""" % path <EOL> ) </s>
|
<s> """<STR_LIT>""" <EOL> import re <EOL> import sys <EOL> import struct <EOL> from simplejson . scanner import make_scanner <EOL> def _import_c_scanstring ( ) : <EOL> try : <EOL> from simplejson . _speedups import scanstring <EOL> return scanstring <EOL> except ImportError : <EOL> return None <EOL> c_scanstring = _import_c_scanstring ( ) <EOL> __all__ = [ '<STR_LIT>' ] <EOL> FLAGS = re . VERBOSE | re . MULTILINE | re . DOTALL <EOL> def _floatconstants ( ) : <EOL> _BYTES = '<STR_LIT>' . decode ( '<STR_LIT>' ) <EOL> if sys . byteorder != '<STR_LIT>' : <EOL> _BYTES = _BYTES [ : <NUM_LIT:8> ] [ : : - <NUM_LIT:1> ] + _BYTES [ <NUM_LIT:8> : ] [ : : - <NUM_LIT:1> ] <EOL> nan , inf = struct . unpack ( '<STR_LIT>' , _BYTES ) <EOL> return nan , inf , - inf <EOL> NaN , PosInf , NegInf = _floatconstants ( ) <EOL> class JSONDecodeError ( ValueError ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , msg , doc , pos , end = None ) : <EOL> ValueError . __init__ ( self , errmsg ( msg , doc , pos , end = end ) ) <EOL> self . msg = msg <EOL> self . doc = doc <EOL> self . pos = pos <EOL> self . end = end <EOL> self . lineno , self . colno = linecol ( doc , pos ) <EOL> if end is not None : <EOL> self . endlineno , self . endcolno = linecol ( doc , end ) <EOL> else : <EOL> self . endlineno , self . endcolno = None , None <EOL> def linecol ( doc , pos ) : <EOL> lineno = doc . count ( '<STR_LIT:\n>' , <NUM_LIT:0> , pos ) + <NUM_LIT:1> <EOL> if lineno == <NUM_LIT:1> : <EOL> colno = pos <EOL> else : <EOL> colno = pos - doc . rindex ( '<STR_LIT:\n>' , <NUM_LIT:0> , pos ) <EOL> return lineno , colno <EOL> def errmsg ( msg , doc , pos , end = None ) : <EOL> lineno , colno = linecol ( doc , pos ) <EOL> if end is None : <EOL> fmt = '<STR_LIT>' <EOL> return fmt % ( msg , lineno , colno , pos ) <EOL> endlineno , endcolno = linecol ( doc , end ) <EOL> fmt = '<STR_LIT>' <EOL> return fmt % ( msg , lineno , colno , endlineno , endcolno , pos , end ) <EOL> _CONSTANTS = { <EOL> '<STR_LIT>' : NegInf , <EOL> '<STR_LIT>' : PosInf , <EOL> '<STR_LIT>' : NaN , <EOL> } <EOL> STRINGCHUNK = re . compile ( r'<STR_LIT>' , FLAGS ) <EOL> BACKSLASH = { <EOL> '<STR_LIT:">' : u'<STR_LIT:">' , '<STR_LIT:\\>' : u'<STR_LIT:\\>' , '<STR_LIT:/>' : u'<STR_LIT:/>' , <EOL> '<STR_LIT:b>' : u'<STR_LIT>' , '<STR_LIT:f>' : u'<STR_LIT>' , '<STR_LIT:n>' : u'<STR_LIT:\n>' , '<STR_LIT:r>' : u'<STR_LIT:\r>' , '<STR_LIT:t>' : u'<STR_LIT:\t>' , <EOL> } <EOL> DEFAULT_ENCODING = "<STR_LIT:utf-8>" <EOL> def py_scanstring ( s , end , encoding = None , strict = True , <EOL> _b = BACKSLASH , _m = STRINGCHUNK . match ) : <EOL> """<STR_LIT>""" <EOL> if encoding is None : <EOL> encoding = DEFAULT_ENCODING <EOL> chunks = [ ] <EOL> _append = chunks . append <EOL> begin = end - <NUM_LIT:1> <EOL> while <NUM_LIT:1> : <EOL> chunk = _m ( s , end ) <EOL> if chunk is None : <EOL> raise JSONDecodeError ( <EOL> "<STR_LIT>" , s , begin ) <EOL> end = chunk . end ( ) <EOL> content , terminator = chunk . groups ( ) <EOL> if content : <EOL> if not isinstance ( content , unicode ) : <EOL> content = unicode ( content , encoding ) <EOL> _append ( content ) <EOL> if terminator == '<STR_LIT:">' : <EOL> break <EOL> elif terminator != '<STR_LIT:\\>' : <EOL> if strict : <EOL> msg = "<STR_LIT>" % ( terminator , ) <EOL> raise JSONDecodeError ( msg , s , end ) <EOL> else : <EOL> _append ( terminator ) <EOL> continue <EOL> try : <EOL> esc = s [ end ] <EOL> except IndexError : <EOL> raise JSONDecodeError ( <EOL> "<STR_LIT>" , s , begin ) <EOL> if esc != '<STR_LIT:u>' : <EOL> try : <EOL> char = _b [ esc ] <EOL> except KeyError : <EOL> msg = "<STR_LIT>" + repr ( esc ) <EOL> raise JSONDecodeError ( msg , s , end ) <EOL> end += <NUM_LIT:1> <EOL> else : <EOL> esc = s [ end + <NUM_LIT:1> : end + <NUM_LIT:5> ] <EOL> next_end = end + <NUM_LIT:5> <EOL> if len ( esc ) != <NUM_LIT:4> : <EOL> msg = "<STR_LIT>" <EOL> raise JSONDecodeError ( msg , s , end ) <EOL> uni = int ( esc , <NUM_LIT:16> ) <EOL> if <NUM_LIT> <= uni <= <NUM_LIT> and sys . maxunicode > <NUM_LIT> : <EOL> msg = "<STR_LIT>" <EOL> if not s [ end + <NUM_LIT:5> : end + <NUM_LIT:7> ] == '<STR_LIT>' : <EOL> raise JSONDecodeError ( msg , s , end ) <EOL> esc2 = s [ end + <NUM_LIT:7> : end + <NUM_LIT:11> ] <EOL> if len ( esc2 ) != <NUM_LIT:4> : <EOL> raise JSONDecodeError ( msg , s , end ) <EOL> uni2 = int ( esc2 , <NUM_LIT:16> ) <EOL> uni = <NUM_LIT> + ( ( ( uni - <NUM_LIT> ) << <NUM_LIT:10> ) | ( uni2 - <NUM_LIT> ) ) <EOL> next_end += <NUM_LIT:6> <EOL> char = unichr ( uni ) <EOL> end = next_end <EOL> _append ( char ) <EOL> return u'<STR_LIT>' . join ( chunks ) , end <EOL> scanstring = c_scanstring or py_scanstring <EOL> WHITESPACE = re . compile ( r'<STR_LIT>' , FLAGS ) <EOL> WHITESPACE_STR = '<STR_LIT>' <EOL> def JSONObject ( ( s , end ) , encoding , strict , scan_once , object_hook , <EOL> object_pairs_hook , memo = None , <EOL> _w = WHITESPACE . match , _ws = WHITESPACE_STR ) : <EOL> if memo is None : <EOL> memo = { } <EOL> memo_get = memo . setdefault <EOL> pairs = [ ] <EOL> nextchar = s [ end : end + <NUM_LIT:1> ] <EOL> if nextchar != '<STR_LIT:">' : <EOL> if nextchar in _ws : <EOL> end = _w ( s , end ) . end ( ) <EOL> nextchar = s [ end : end + <NUM_LIT:1> ] <EOL> if nextchar == '<STR_LIT:}>' : <EOL> if object_pairs_hook is not None : <EOL> result = object_pairs_hook ( pairs ) <EOL> return result , end + <NUM_LIT:1> <EOL> pairs = { } <EOL> if object_hook is not None : <EOL> pairs = object_hook ( pairs ) <EOL> return pairs , end + <NUM_LIT:1> <EOL> elif nextchar != '<STR_LIT:">' : <EOL> raise JSONDecodeError ( "<STR_LIT>" , s , end ) <EOL> end += <NUM_LIT:1> <EOL> while True : <EOL> key , end = scanstring ( s , end , encoding , strict ) <EOL> key = memo_get ( key , key ) <EOL> if s [ end : end + <NUM_LIT:1> ] != '<STR_LIT::>' : <EOL> end = _w ( s , end ) . end ( ) <EOL> if s [ end : end + <NUM_LIT:1> ] != '<STR_LIT::>' : <EOL> raise JSONDecodeError ( "<STR_LIT>" , s , end ) <EOL> end += <NUM_LIT:1> <EOL> try : <EOL> if s [ end ] in _ws : <EOL> end += <NUM_LIT:1> <EOL> if s [ end ] in _ws : <EOL> end = _w ( s , end + <NUM_LIT:1> ) . end ( ) <EOL> except IndexError : <EOL> pass <EOL> try : <EOL> value , end = scan_once ( s , end ) <EOL> except StopIteration : <EOL> raise JSONDecodeError ( "<STR_LIT>" , s , end ) <EOL> pairs . append ( ( key , value ) ) <EOL> try : <EOL> nextchar = s [ end ] <EOL> if nextchar in _ws : <EOL> end = _w ( s , end + <NUM_LIT:1> ) . end ( ) <EOL> nextchar = s [ end ] <EOL> except IndexError : <EOL> nextchar = '<STR_LIT>' <EOL> end += <NUM_LIT:1> <EOL> if nextchar == '<STR_LIT:}>' : <EOL> break <EOL> elif nextchar != '<STR_LIT:U+002C>' : <EOL> raise JSONDecodeError ( "<STR_LIT>" , s , end - <NUM_LIT:1> ) <EOL> try : <EOL> nextchar = s [ end ] <EOL> if nextchar in _ws : <EOL> end += <NUM_LIT:1> <EOL> nextchar = s [ end ] <EOL> if nextchar in _ws : <EOL> end = _w ( s , end + <NUM_LIT:1> ) . end ( ) <EOL> nextchar = s [ end ] <EOL> except IndexError : <EOL> nextchar = '<STR_LIT>' <EOL> end += <NUM_LIT:1> <EOL> if nextchar != '<STR_LIT:">' : <EOL> raise JSONDecodeError ( "<STR_LIT>" , s , end - <NUM_LIT:1> ) <EOL> if object_pairs_hook is not None : <EOL> result = object_pairs_hook ( pairs ) <EOL> return result , end <EOL> pairs = dict ( pairs ) <EOL> if object_hook is not None : <EOL> pairs = object_hook ( pairs ) <EOL> return pairs , end <EOL> def JSONArray ( ( s , end ) , scan_once , _w = WHITESPACE . match , _ws = WHITESPACE_STR ) : <EOL> values = [ ] <EOL> nextchar = s [ end : end + <NUM_LIT:1> ] <EOL> if nextchar in _ws : <EOL> end = _w ( s , end + <NUM_LIT:1> ) . end ( ) <EOL> nextchar = s [ end : end + <NUM_LIT:1> ] <EOL> if nextchar == '<STR_LIT:]>' : <EOL> return values , end + <NUM_LIT:1> <EOL> _append = values . append <EOL> while True : <EOL> try : <EOL> value , end = scan_once ( s , end ) <EOL> except StopIteration : <EOL> raise JSONDecodeError ( "<STR_LIT>" , s , end ) <EOL> _append ( value ) <EOL> nextchar = s [ end : end + <NUM_LIT:1> ] <EOL> if nextchar in _ws : <EOL> end = _w ( s , end + <NUM_LIT:1> ) . end ( ) <EOL> nextchar = s [ end : end + <NUM_LIT:1> ] <EOL> end += <NUM_LIT:1> <EOL> if nextchar == '<STR_LIT:]>' : <EOL> break <EOL> elif nextchar != '<STR_LIT:U+002C>' : <EOL> raise JSONDecodeError ( "<STR_LIT>" , s , end ) <EOL> try : <EOL> if s [ end ] in _ws : <EOL> end += <NUM_LIT:1> <EOL> if s [ end ] in _ws : <EOL> end = _w ( s , end + <NUM_LIT:1> ) . end ( ) <EOL> except IndexError : <EOL> pass <EOL> return values , end <EOL> class JSONDecoder ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , encoding = None , object_hook = None , parse_float = None , <EOL> parse_int = None , parse_constant = None , strict = True , <EOL> object_pairs_hook = None ) : <EOL> """<STR_LIT>""" <EOL> self . encoding = encoding <EOL> self . object_hook = object_hook <EOL> self . object_pairs_hook = object_pairs_hook <EOL> self . parse_float = parse_float or float <EOL> self . parse_int = parse_int or int <EOL> self . parse_constant = parse_constant or _CONSTANTS . __getitem__ <EOL> self . strict = strict <EOL> self . parse_object = JSONObject <EOL> self . parse_array = JSONArray <EOL> self . parse_string = scanstring <EOL> self . memo = { } <EOL> self . scan_once = make_scanner ( self ) <EOL> def decode ( self , s , _w = WHITESPACE . match ) : <EOL> """<STR_LIT>""" <EOL> obj , end = self . raw_decode ( s , idx = _w ( s , <NUM_LIT:0> ) . end ( ) ) <EOL> end = _w ( s , end ) . end ( ) <EOL> if end != len ( s ) : <EOL> raise JSONDecodeError ( "<STR_LIT>" , s , end , len ( s ) ) <EOL> return obj <EOL> def raw_decode ( self , s , idx = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> obj , end = self . scan_once ( s , idx ) <EOL> except StopIteration : <EOL> raise JSONDecodeError ( "<STR_LIT>" , s , idx ) <EOL> return obj , end </s>
|
<s> """<STR_LIT>""" <EOL> import hashlib <EOL> import hmac <EOL> import logging <EOL> import time <EOL> from webapp2_extras import json <EOL> from webapp2_extras import security <EOL> class SecureCookieSerializer ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , secret_key ) : <EOL> """<STR_LIT>""" <EOL> self . secret_key = secret_key <EOL> def serialize ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> timestamp = str ( self . _get_timestamp ( ) ) <EOL> value = self . _encode ( value ) <EOL> signature = self . _get_signature ( name , value , timestamp ) <EOL> return '<STR_LIT:|>' . join ( [ value , timestamp , signature ] ) <EOL> def deserialize ( self , name , value , max_age = None ) : <EOL> """<STR_LIT>""" <EOL> if not value : <EOL> return None <EOL> parts = value . split ( '<STR_LIT:|>' ) <EOL> if len ( parts ) != <NUM_LIT:3> : <EOL> return None <EOL> signature = self . _get_signature ( name , parts [ <NUM_LIT:0> ] , parts [ <NUM_LIT:1> ] ) <EOL> if not security . compare_hashes ( parts [ <NUM_LIT:2> ] , signature ) : <EOL> logging . warning ( '<STR_LIT>' , value ) <EOL> return None <EOL> if max_age is not None : <EOL> if int ( parts [ <NUM_LIT:1> ] ) < self . _get_timestamp ( ) - max_age : <EOL> logging . warning ( '<STR_LIT>' , value ) <EOL> return None <EOL> try : <EOL> return self . _decode ( parts [ <NUM_LIT:0> ] ) <EOL> except Exception , e : <EOL> logging . warning ( '<STR_LIT>' , parts [ <NUM_LIT:0> ] ) <EOL> return None <EOL> def _encode ( self , value ) : <EOL> return json . b64encode ( value ) <EOL> def _decode ( self , value ) : <EOL> return json . b64decode ( value ) <EOL> def _get_timestamp ( self ) : <EOL> return int ( time . time ( ) ) <EOL> def _get_signature ( self , * parts ) : <EOL> """<STR_LIT>""" <EOL> signature = hmac . new ( self . secret_key , digestmod = hashlib . sha1 ) <EOL> signature . update ( '<STR_LIT:|>' . join ( parts ) ) <EOL> return signature . hexdigest ( ) </s>
|
<s> import cgi , warnings <EOL> from webob . headers import _trans_key <EOL> def html_escape ( s ) : <EOL> """<STR_LIT>""" <EOL> if s is None : <EOL> return '<STR_LIT>' <EOL> if hasattr ( s , '<STR_LIT>' ) : <EOL> return s . __html__ ( ) <EOL> if not isinstance ( s , basestring ) : <EOL> if hasattr ( s , '<STR_LIT>' ) : <EOL> s = unicode ( s ) <EOL> else : <EOL> s = str ( s ) <EOL> s = cgi . escape ( s , True ) <EOL> if isinstance ( s , unicode ) : <EOL> s = s . encode ( '<STR_LIT:ascii>' , '<STR_LIT>' ) <EOL> return s <EOL> def header_docstring ( header , rfc_section ) : <EOL> if header . isupper ( ) : <EOL> header = _trans_key ( header ) <EOL> major_section = rfc_section . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> link = '<STR_LIT>' % ( major_section , rfc_section ) <EOL> return "<STR_LIT>" % ( header , rfc_section , link ) <EOL> def warn_deprecation ( text , version , stacklevel ) : <EOL> if version == '<STR_LIT>' : <EOL> cls = DeprecationWarning <EOL> elif version == '<STR_LIT>' : <EOL> cls = PendingDeprecationWarning <EOL> else : <EOL> cls = DeprecationWarning <EOL> warnings . warn ( "<STR_LIT>" % version , <EOL> RuntimeWarning , <EOL> stacklevel = <NUM_LIT:1> <EOL> ) <EOL> warnings . warn ( text , cls , stacklevel = stacklevel + <NUM_LIT:1> ) <EOL> status_reasons = { <EOL> <NUM_LIT:100> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT:200> : '<STR_LIT:OK>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> } </s>
|
<s> """<STR_LIT>""" <EOL> from webob . util . dictmixin import DictMixin <EOL> class EnvironHeaders ( DictMixin ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , environ ) : <EOL> self . environ = environ <EOL> def _trans_name ( self , name ) : <EOL> key = '<STR_LIT>' + name . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) . upper ( ) <EOL> if key == '<STR_LIT>' : <EOL> key = '<STR_LIT>' <EOL> elif key == '<STR_LIT>' : <EOL> key = '<STR_LIT>' <EOL> return key <EOL> def _trans_key ( self , key ) : <EOL> if key == '<STR_LIT>' : <EOL> return '<STR_LIT:Content-Type>' <EOL> elif key == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> elif key . startswith ( '<STR_LIT>' ) : <EOL> return key [ <NUM_LIT:5> : ] . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) . title ( ) <EOL> else : <EOL> return None <EOL> def __getitem__ ( self , item ) : <EOL> return self . environ [ self . _trans_name ( item ) ] <EOL> def __setitem__ ( self , item , value ) : <EOL> self . environ [ self . _trans_name ( item ) ] = value <EOL> def __delitem__ ( self , item ) : <EOL> del self . environ [ self . _trans_name ( item ) ] <EOL> def __iter__ ( self ) : <EOL> for key in self . environ : <EOL> name = self . _trans_key ( key ) <EOL> if name is not None : <EOL> yield name <EOL> def keys ( self ) : <EOL> return list ( iter ( self ) ) <EOL> def __contains__ ( self , item ) : <EOL> return self . _trans_name ( item ) in self . environ </s>
|
<s> class Token ( object ) : <EOL> def __init__ ( self , start_mark , end_mark ) : <EOL> self . start_mark = start_mark <EOL> self . end_mark = end_mark <EOL> def __repr__ ( self ) : <EOL> attributes = [ key for key in self . __dict__ <EOL> if not key . endswith ( '<STR_LIT>' ) ] <EOL> attributes . sort ( ) <EOL> arguments = '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' % ( key , getattr ( self , key ) ) <EOL> for key in attributes ] ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , arguments ) <EOL> class DirectiveToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> def __init__ ( self , name , value , start_mark , end_mark ) : <EOL> self . name = name <EOL> self . value = value <EOL> self . start_mark = start_mark <EOL> self . end_mark = end_mark <EOL> class DocumentStartToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> class DocumentEndToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> class StreamStartToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> def __init__ ( self , start_mark = None , end_mark = None , <EOL> encoding = None ) : <EOL> self . start_mark = start_mark <EOL> self . end_mark = end_mark <EOL> self . encoding = encoding <EOL> class StreamEndToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> class BlockSequenceStartToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> class BlockMappingStartToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> class BlockEndToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> class FlowSequenceStartToken ( Token ) : <EOL> id = '<STR_LIT:[>' <EOL> class FlowMappingStartToken ( Token ) : <EOL> id = '<STR_LIT:{>' <EOL> class FlowSequenceEndToken ( Token ) : <EOL> id = '<STR_LIT:]>' <EOL> class FlowMappingEndToken ( Token ) : <EOL> id = '<STR_LIT:}>' <EOL> class KeyToken ( Token ) : <EOL> id = '<STR_LIT:?>' <EOL> class ValueToken ( Token ) : <EOL> id = '<STR_LIT::>' <EOL> class BlockEntryToken ( Token ) : <EOL> id = '<STR_LIT:->' <EOL> class FlowEntryToken ( Token ) : <EOL> id = '<STR_LIT:U+002C>' <EOL> class AliasToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> def __init__ ( self , value , start_mark , end_mark ) : <EOL> self . value = value <EOL> self . start_mark = start_mark <EOL> self . end_mark = end_mark <EOL> class AnchorToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> def __init__ ( self , value , start_mark , end_mark ) : <EOL> self . value = value <EOL> self . start_mark = start_mark <EOL> self . end_mark = end_mark <EOL> class TagToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> def __init__ ( self , value , start_mark , end_mark ) : <EOL> self . value = value <EOL> self . start_mark = start_mark <EOL> self . end_mark = end_mark <EOL> class ScalarToken ( Token ) : <EOL> id = '<STR_LIT>' <EOL> def __init__ ( self , value , plain , start_mark , end_mark , style = None ) : <EOL> self . value = value <EOL> self . plain = plain <EOL> self . start_mark = start_mark <EOL> self . end_mark = end_mark <EOL> self . style = style </s>
|
<s> import httplib <EOL> import json <EOL> import os <EOL> import socket <EOL> import sys <EOL> import unittest <EOL> import urllib2 <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> import file_io <EOL> FILE_LOC = "<STR_LIT>" <EOL> def create_test_yaml ( ) : <EOL> file_loc = FILE_LOC <EOL> config = """<STR_LIT>""" <EOL> try : <EOL> os . mkdir ( "<STR_LIT>" ) <EOL> os . mkdir ( "<STR_LIT>" ) <EOL> except OSError : <EOL> pass <EOL> FILE = file_io . write ( file_loc , config ) <EOL> class TestTaskQueueServer ( unittest . TestCase ) : <EOL> def test_slave ( self ) : <EOL> create_test_yaml ( ) <EOL> values = { '<STR_LIT>' : '<STR_LIT>' } <EOL> host = socket . gethostbyname ( socket . gethostname ( ) ) <EOL> req = urllib2 . Request ( '<STR_LIT>' + host + '<STR_LIT>' ) <EOL> req . add_header ( '<STR_LIT:Content-Type>' , '<STR_LIT:application/json>' ) <EOL> response = urllib2 . urlopen ( req , json . dumps ( values ) ) <EOL> print response . read ( ) <EOL> self . assertEquals ( response . getcode ( ) , <NUM_LIT:200> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
|
<s> import os <EOL> import Queue <EOL> import sys <EOL> import threading <EOL> import tornado . httpclient <EOL> import unittest <EOL> from flexmock import flexmock <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> import helper <EOL> import hermes_constants <EOL> from custom_hermes_exceptions import MissingRequestArgs <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> import appscale_info <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> from google . appengine . api . appcontroller_client import AppControllerClient <EOL> class FakeAppControllerClient ( ) : <EOL> def __init__ ( self , registered ) : <EOL> self . registered = registered <EOL> def deployment_id_exists ( self ) : <EOL> return self . registered <EOL> def get_deployment_id ( self ) : <EOL> return '<STR_LIT>' <EOL> class FakeAsyncClient ( ) : <EOL> def fetch ( self ) : <EOL> pass <EOL> class FakeClient ( ) : <EOL> def fetch ( self ) : <EOL> pass <EOL> class FakeLock ( ) : <EOL> def __init__ ( self , wrapped_class ) : <EOL> pass <EOL> def acquire ( self ) : <EOL> pass <EOL> def release ( self ) : <EOL> pass <EOL> class FakeRequest ( ) : <EOL> def __init__ ( self ) : <EOL> self . url = fake_url <EOL> self . body = fake_data <EOL> class FakeResponse ( ) : <EOL> def __init__ ( self , request , code ) : <EOL> self . request = request <EOL> self . code = code <EOL> fake_url = '<STR_LIT>' <EOL> fake_data = '<STR_LIT>' <EOL> fake_node_info = [ <EOL> { <EOL> '<STR_LIT:host>' : fake_url , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:index>' : None <EOL> } , <EOL> { <EOL> '<STR_LIT:host>' : fake_url , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:index>' : <NUM_LIT:0> <EOL> } <EOL> ] <EOL> class TestHelper ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_create_request ( self ) : <EOL> self . assertRaises ( MissingRequestArgs , helper . create_request ) <EOL> self . assertIsNotNone ( helper . create_request , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertIsNotNone ( helper . create_request , [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def test_urlfetch ( self ) : <EOL> fake_request = FakeRequest ( ) <EOL> fake_response = FakeResponse ( fake_request , <NUM_LIT:200> ) <EOL> fake_client = flexmock ( tornado . httpclient . HTTPClient ( ) ) <EOL> fake_client . should_receive ( '<STR_LIT>' ) . and_return ( fake_response ) <EOL> self . assertIsNotNone ( helper . urlfetch , fake_request ) <EOL> def test_urlfetch_async ( self ) : <EOL> fake_request = FakeRequest ( ) <EOL> fake_response = FakeResponse ( fake_request , <NUM_LIT:200> ) <EOL> fake_client = flexmock ( tornado . httpclient . AsyncHTTPClient ( ) ) <EOL> fake_client . should_receive ( '<STR_LIT>' ) . and_return ( fake_response ) <EOL> self . assertIsNotNone ( helper . urlfetch , fake_request ) <EOL> def test_get_br_service_url ( self ) : <EOL> fake_url = '<STR_LIT>' . format ( hermes_constants . BR_SERVICE_PORT , <EOL> hermes_constants . BR_SERVICE_PATH ) <EOL> self . assertEquals ( fake_url , helper . get_br_service_url ( '<STR_LIT:host>' ) ) <EOL> def test_get_deployment_id ( self ) : <EOL> fake_acc = FakeAppControllerClient ( True ) <EOL> flexmock ( appscale_info ) . should_receive ( '<STR_LIT>' ) . and_return ( fake_acc ) <EOL> flexmock ( AppControllerClient ) . should_receive ( '<STR_LIT>' ) . and_return ( True ) <EOL> flexmock ( AppControllerClient ) . should_receive ( '<STR_LIT>' ) . and_return ( '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , helper . get_deployment_id ( ) ) <EOL> fake_acc = FakeAppControllerClient ( False ) <EOL> flexmock ( appscale_info ) . should_receive ( '<STR_LIT>' ) . and_return ( fake_acc ) <EOL> flexmock ( AppControllerClient ) . should_receive ( '<STR_LIT>' ) . and_return ( False ) <EOL> self . assertIsNone ( helper . get_deployment_id ( ) ) <EOL> def test_get_node_info ( self ) : <EOL> flexmock ( appscale_info ) . should_receive ( '<STR_LIT>' ) . and_return ( <EOL> '<STR_LIT:foo>' ) <EOL> flexmock ( appscale_info ) . should_receive ( '<STR_LIT>' ) . and_return ( <EOL> [ '<STR_LIT:bar>' ] ) <EOL> flexmock ( appscale_info ) . should_receive ( '<STR_LIT>' ) . and_return ( <EOL> [ '<STR_LIT>' ] ) <EOL> flexmock ( helper ) . should_receive ( '<STR_LIT>' ) . and_return ( <EOL> '<STR_LIT>' ) . at_least ( ) . times ( <NUM_LIT:2> ) <EOL> self . assertEquals ( fake_node_info , helper . get_node_info ( ) ) <EOL> def test_create_br_json_data ( self ) : <EOL> pass <EOL> def test_delete_task_from_mem ( self ) : <EOL> flexmock ( FakeLock ( threading . Lock ( ) ) ) . should_receive ( '<STR_LIT>' ) . and_return ( ) <EOL> flexmock ( FakeLock ( threading . Lock ( ) ) ) . should_receive ( '<STR_LIT>' ) . and_return ( ) <EOL> helper . delete_task_from_mem ( '<STR_LIT:foo>' ) <EOL> def test_report_status ( self ) : <EOL> pass <EOL> def test_send_remote_request ( self ) : <EOL> flexmock ( Queue . Queue ) . should_receive ( '<STR_LIT>' ) . and_return ( ) . at_least ( ) . times ( <NUM_LIT:1> ) <EOL> flexmock ( helper ) . should_receive ( '<STR_LIT>' ) . and_return ( '<STR_LIT>' ) . at_least ( ) . times ( <NUM_LIT:1> ) <EOL> helper . send_remote_request ( FakeRequest ( ) , Queue . Queue ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
|
<s> """<STR_LIT>""" <EOL> from search_api import SearchService <EOL> import logging <EOL> import tornado . httpserver <EOL> import tornado . httputil <EOL> import tornado . ioloop <EOL> import tornado . web <EOL> import time <EOL> DEFAULT_PORT = <NUM_LIT> <EOL> class MainHandler ( tornado . web . RequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , search_service ) : <EOL> """<STR_LIT>""" <EOL> self . search_service = search_service <EOL> @ tornado . web . asynchronous <EOL> def post ( self ) : <EOL> """<STR_LIT>""" <EOL> request = self . request <EOL> http_request_data = request . body <EOL> pb_type = request . headers [ '<STR_LIT>' ] <EOL> if pb_type == "<STR_LIT>" : <EOL> response = self . search_service . remote_request ( http_request_data ) <EOL> else : <EOL> response = self . search_service . unknown_request ( pb_type ) <EOL> request . connection . write_headers ( <EOL> tornado . httputil . ResponseStartLine ( '<STR_LIT>' , <NUM_LIT:200> , '<STR_LIT:OK>' ) , <EOL> tornado . httputil . HTTPHeaders ( { "<STR_LIT>" : str ( len ( response ) ) } ) ) <EOL> request . connection . write ( response ) <EOL> request . connection . finish ( ) <EOL> def get_application ( ) : <EOL> """<STR_LIT>""" <EOL> return tornado . web . Application ( [ <EOL> ( r"<STR_LIT>" , MainHandler , dict ( search_service = SearchService ( ) ) ) , <EOL> ] , ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> logging . getLogger ( ) . setLevel ( logging . INFO ) <EOL> logging . info ( "<STR_LIT>" . format ( DEFAULT_PORT ) ) <EOL> http_server = tornado . httpserver . HTTPServer ( get_application ( ) ) <EOL> http_server . bind ( DEFAULT_PORT ) <EOL> http_server . start ( <NUM_LIT:0> ) <EOL> tornado . ioloop . IOLoop . instance ( ) . start ( ) </s>
|
<s> from os . path import basename <EOL> import subprocess <EOL> import sys <EOL> if len ( sys . argv ) != <NUM_LIT:3> : <EOL> print sys . argv [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> process = sys . argv [ <NUM_LIT:1> ] <EOL> identifier = sys . argv [ <NUM_LIT:2> ] <EOL> ps_output = subprocess . check_output ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) . split ( '<STR_LIT:\n>' ) <EOL> for line in ps_output : <EOL> if basename ( sys . argv [ <NUM_LIT:0> ] ) in line : <EOL> continue <EOL> if identifier in line and process in line : <EOL> pgid = "<STR_LIT:->" + line . split ( ) [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" + line <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , pgid ] ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:2> ) </s>
|
<s> '''<STR_LIT>''' <EOL> import xml . dom , math , re <EOL> from arelle . ModelValue import qname <EOL> from arelle import XPathContext , XbrlUtil <EOL> from arelle . ModelInstanceObject import ModelDimensionValue <EOL> from decimal import Decimal <EOL> class fnFunctionNotAvailable ( Exception ) : <EOL> def __init__ ( self ) : <EOL> self . args = ( "<STR_LIT>" , ) <EOL> def __repr__ ( self ) : <EOL> return self . args [ <NUM_LIT:0> ] <EOL> def call ( xc , p , qname , contextItem , args ) : <EOL> try : <EOL> cfSig = xc . modelXbrl . modelCustomFunctionSignatures [ qname , len ( args ) ] <EOL> if cfSig is not None and cfSig . customFunctionImplementation is not None : <EOL> return callCfi ( xc , p , qname , cfSig , contextItem , args ) <EOL> elif qname in xc . customFunctions : <EOL> return xc . customFunctions [ qname ] ( xc , p , contextItem , args ) <EOL> elif qname not in customFunctions : <EOL> raise fnFunctionNotAvailable <EOL> return customFunctions [ qname ] ( xc , p , contextItem , args ) <EOL> except ( fnFunctionNotAvailable , KeyError ) : <EOL> raise XPathContext . FunctionNotAvailable ( "<STR_LIT>" . format ( str ( qname ) ) ) <EOL> def callCfi ( xc , p , qname , cfSig , contextItem , args ) : <EOL> if len ( args ) != len ( cfSig . inputTypes ) : <EOL> raise XPathContext . FunctionNumArgs ( ) <EOL> cfi = cfSig . customFunctionImplementation <EOL> overriddenInScopeVars = { } <EOL> traceSource = xc . formulaOptions . traceSource ( xc . traceType ) <EOL> traceEvaluation = xc . formulaOptions . traceEvaluation ( xc . traceType ) <EOL> inputNames = cfi . inputNames <EOL> for i , argName in enumerate ( inputNames ) : <EOL> if argName in xc . inScopeVars : <EOL> overriddenInScopeVars [ argName ] = xc . inScopeVars [ argName ] <EOL> xc . inScopeVars [ argName ] = args [ i ] <EOL> if traceEvaluation : <EOL> xc . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = cfi , <EOL> cfi = qname , <EOL> arguments = '<STR_LIT:U+002CU+0020>' . join ( "<STR_LIT>" . format ( argName , args [ i ] ) <EOL> for i , argName in enumerate ( inputNames ) ) ) <EOL> for i , step in enumerate ( cfi . stepExpressions ) : <EOL> stepQname , stepExpression = step <EOL> stepProg = cfi . stepProgs [ i ] <EOL> if traceSource : <EOL> xc . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = cfi , <EOL> cfi = qname , step = stepQname , expression = stepExpression ) <EOL> result = xc . evaluate ( stepProg ) <EOL> if traceEvaluation : <EOL> xc . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = cfi , <EOL> cfi = qname , step = stepQname , expression = result ) <EOL> if stepQname in xc . inScopeVars : <EOL> overriddenInScopeVars [ stepQname ] = xc . inScopeVars [ stepQname ] <EOL> xc . inScopeVars [ stepQname ] = result <EOL> if traceSource : <EOL> xc . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = cfi , <EOL> cfi = qname , expression = cfi . outputExpression ) <EOL> result = xc . evaluateAtomicValue ( cfi . outputProg , cfSig . outputType ) <EOL> if traceEvaluation : <EOL> xc . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = cfi , <EOL> cfi = qname , expression = result ) <EOL> for step in cfi . stepExpressions : <EOL> stepQname = step [ <NUM_LIT:0> ] <EOL> if stepQname in overriddenInScopeVars : <EOL> xc . inScopeVars [ stepQname ] = overriddenInScopeVars [ stepQname ] <EOL> for i , argName in enumerate ( inputNames ) : <EOL> if argName in overriddenInScopeVars : <EOL> xc . inScopeVars [ argName ] = overriddenInScopeVars [ argName ] <EOL> else : <EOL> del xc . inScopeVars [ argName ] <EOL> if result is None : <EOL> raise XPathContext . FunctionArgType ( "<STR_LIT>" , cfSig . outputType , result ) <EOL> return result <EOL> def my_fn_PDxEV ( xc , p , contextItem , args ) : <EOL> if len ( args ) != <NUM_LIT:2> : raise XPathContext . FunctionNumArgs ( ) <EOL> PDseq = args [ <NUM_LIT:0> ] if isinstance ( args [ <NUM_LIT:0> ] , ( list , tuple ) ) else ( args [ <NUM_LIT:0> ] , ) <EOL> EVseq = args [ <NUM_LIT:1> ] if isinstance ( args [ <NUM_LIT:1> ] , ( list , tuple ) ) else ( args [ <NUM_LIT:1> ] , ) <EOL> dimQname = qname ( "<STR_LIT>" ) <EOL> PDxEV = [ ] <EOL> for pd in PDseq : <EOL> if pd . context is not None : <EOL> pdDim = pd . context . dimValue ( dimQname ) <EOL> for ev in EVseq : <EOL> if ev . context is not None : <EOL> evDim = ev . context . dimValue ( dimQname ) <EOL> if pdDim is not None and isinstance ( pdDim , ModelDimensionValue ) : <EOL> dimEqual = pdDim . isEqualTo ( evDim , equalMode = XbrlUtil . S_EQUAL2 ) <EOL> elif evDim is not None and isinstance ( evDim , ModelDimensionValue ) : <EOL> dimEqual = evDim . isEqualTo ( pdDim , equalMode = XbrlUtil . S_EQUAL2 ) <EOL> else : <EOL> dimEqual = ( pdDim == evDim ) <EOL> if dimEqual : <EOL> pdX = pd . xValue <EOL> evX = ev . xValue <EOL> if isinstance ( pdX , Decimal ) and isinstance ( evX , float ) : <EOL> pdX = float ( pdX ) <EOL> elif isinstance ( evX , Decimal ) and isinstance ( pdX , float ) : <EOL> pdX = float ( evX ) <EOL> PDxEV . append ( pdX * evX ) <EOL> break <EOL> return PDxEV <EOL> customFunctions = { <EOL> qname ( "<STR_LIT>" ) : my_fn_PDxEV <EOL> } </s>
|
<s> '''<STR_LIT>''' <EOL> from collections import defaultdict <EOL> import os , sys , traceback , uuid <EOL> import logging <EOL> from decimal import Decimal <EOL> from arelle import UrlUtil , XmlUtil , ModelValue , XbrlConst , XmlValidate <EOL> from arelle . FileSource import FileNamedStringIO <EOL> from arelle . ModelObject import ModelObject , ObjectPropertyViewWrapper <EOL> from arelle . Locale import format_string <EOL> from arelle . PluginManager import pluginClassMethods <EOL> from arelle . PrototypeInstanceObject import FactPrototype , DimValuePrototype <EOL> from arelle . PythonUtil import flattenSequence <EOL> from arelle . UrlUtil import isHttpUrl <EOL> from arelle . ValidateXbrlDimensions import isFactDimensionallyValid <EOL> ModelRelationshipSet = None <EOL> ModelFact = None <EOL> profileStatNumber = <NUM_LIT:0> <EOL> AUTO_LOCATE_ELEMENT = '<STR_LIT>' <EOL> DEFAULT = sys . intern ( _STR_8BIT ( "<STR_LIT:default>" ) ) <EOL> NONDEFAULT = sys . intern ( _STR_8BIT ( "<STR_LIT>" ) ) <EOL> DEFAULTorNONDEFAULT = sys . intern ( _STR_8BIT ( "<STR_LIT>" ) ) <EOL> def load ( modelManager , url , nextaction = None , base = None , useFileSource = None , errorCaptureLevel = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if nextaction is None : nextaction = _ ( "<STR_LIT>" ) <EOL> from arelle import ( ModelDocument , FileSource ) <EOL> modelXbrl = create ( modelManager , errorCaptureLevel = errorCaptureLevel ) <EOL> if useFileSource is not None : <EOL> modelXbrl . fileSource = useFileSource <EOL> modelXbrl . closeFileSource = False <EOL> url = url <EOL> elif isinstance ( url , FileSource . FileSource ) : <EOL> modelXbrl . fileSource = url <EOL> modelXbrl . closeFileSource = True <EOL> url = modelXbrl . fileSource . url <EOL> else : <EOL> modelXbrl . fileSource = FileSource . FileSource ( url , modelManager . cntlr ) <EOL> modelXbrl . closeFileSource = True <EOL> modelXbrl . modelDocument = ModelDocument . load ( modelXbrl , url , base , isEntry = True , ** kwargs ) <EOL> del modelXbrl . entryLoadingUrl <EOL> loadSchemalocatedSchemas ( modelXbrl ) <EOL> modelManager . cntlr . webCache . saveUrlCheckTimes ( ) <EOL> modelManager . showStatus ( _ ( "<STR_LIT>" ) . format ( nextaction ) ) <EOL> return modelXbrl <EOL> def create ( modelManager , newDocumentType = None , url = None , schemaRefs = None , createModelDocument = True , isEntry = False , errorCaptureLevel = None , initialXml = None , initialComment = None , base = None , discover = True ) : <EOL> from arelle import ( ModelDocument , FileSource ) <EOL> modelXbrl = ModelXbrl ( modelManager , errorCaptureLevel = errorCaptureLevel ) <EOL> modelXbrl . locale = modelManager . locale <EOL> if newDocumentType : <EOL> modelXbrl . fileSource = FileSource . FileSource ( url , modelManager . cntlr ) <EOL> modelXbrl . closeFileSource = True <EOL> if createModelDocument : <EOL> modelXbrl . modelDocument = ModelDocument . create ( modelXbrl , newDocumentType , str ( url ) , schemaRefs = schemaRefs , isEntry = isEntry , initialXml = initialXml , initialComment = initialComment , base = base , discover = discover ) <EOL> if isEntry : <EOL> del modelXbrl . entryLoadingUrl <EOL> loadSchemalocatedSchemas ( modelXbrl ) <EOL> return modelXbrl <EOL> def loadSchemalocatedSchemas ( modelXbrl ) : <EOL> from arelle import ModelDocument <EOL> if modelXbrl . modelDocument is not None and modelXbrl . modelDocument . type < ModelDocument . Type . DTSENTRIES : <EOL> modelDocumentsSchemaLocated = set ( ) <EOL> while True : <EOL> modelDocuments = set ( modelXbrl . urlDocs . values ( ) ) - modelDocumentsSchemaLocated <EOL> if not modelDocuments : <EOL> break <EOL> modelDocument = modelDocuments . pop ( ) <EOL> modelDocumentsSchemaLocated . add ( modelDocument ) <EOL> modelDocument . loadSchemalocatedSchemas ( ) <EOL> class ModelXbrl : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , modelManager , errorCaptureLevel = None ) : <EOL> self . modelManager = modelManager <EOL> self . skipDTS = modelManager . skipDTS <EOL> self . init ( errorCaptureLevel = errorCaptureLevel ) <EOL> def init ( self , keepViews = False , errorCaptureLevel = None ) : <EOL> self . uuid = uuid . uuid1 ( ) . urn <EOL> self . namespaceDocs = defaultdict ( list ) <EOL> self . urlDocs = { } <EOL> self . urlUnloadableDocs = { } <EOL> self . errorCaptureLevel = ( errorCaptureLevel or logging . _checkLevel ( "<STR_LIT>" ) ) <EOL> self . errors = [ ] <EOL> self . logCount = { } <EOL> self . arcroleTypes = defaultdict ( list ) <EOL> self . roleTypes = defaultdict ( list ) <EOL> self . qnameConcepts = { } <EOL> self . nameConcepts = defaultdict ( list ) <EOL> self . qnameAttributes = { } <EOL> self . qnameAttributeGroups = { } <EOL> self . qnameGroupDefinitions = { } <EOL> self . qnameTypes = { } <EOL> self . baseSets = defaultdict ( list ) <EOL> self . relationshipSets = { } <EOL> self . qnameDimensionDefaults = { } <EOL> self . facts = [ ] <EOL> self . factsInInstance = set ( ) <EOL> self . undefinedFacts = [ ] <EOL> self . contexts = { } <EOL> self . units = { } <EOL> self . modelObjects = [ ] <EOL> self . qnameParameters = { } <EOL> self . modelVariableSets = set ( ) <EOL> self . modelCustomFunctionSignatures = { } <EOL> self . modelCustomFunctionImplementations = set ( ) <EOL> self . modelRenderingTables = set ( ) <EOL> if not keepViews : <EOL> self . views = [ ] <EOL> self . langs = { self . modelManager . defaultLang } <EOL> from arelle . XbrlConst import standardLabel <EOL> self . labelroles = { standardLabel } <EOL> self . hasXDT = False <EOL> self . hasTableRendering = False <EOL> self . hasTableIndexing = False <EOL> self . hasFormulae = False <EOL> self . formulaOutputInstance = None <EOL> self . logger = logging . getLogger ( "<STR_LIT>" ) <EOL> self . logRefObjectProperties = getattr ( self . logger , "<STR_LIT>" , False ) <EOL> self . logRefHasPluginAttrs = any ( True for m in pluginClassMethods ( "<STR_LIT>" ) ) <EOL> self . logRefHasPluginProperties = any ( True for m in pluginClassMethods ( "<STR_LIT>" ) ) <EOL> self . profileStats = { } <EOL> self . schemaDocsToValidate = set ( ) <EOL> self . modelXbrl = self <EOL> self . arelleUnitTests = { } <EOL> for pluginXbrlMethod in pluginClassMethods ( "<STR_LIT>" ) : <EOL> pluginXbrlMethod ( self ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . isClosed : <EOL> self . closeViews ( ) <EOL> if self . formulaOutputInstance : <EOL> self . formulaOutputInstance . close ( ) <EOL> if hasattr ( self , "<STR_LIT>" ) and self . closeFileSource : <EOL> self . fileSource . close ( ) <EOL> modelDocument = getattr ( self , "<STR_LIT>" , None ) <EOL> urlDocs = getattr ( self , "<STR_LIT>" , None ) <EOL> for relSet in self . relationshipSets . values ( ) : <EOL> relSet . clear ( ) <EOL> self . __dict__ . clear ( ) <EOL> if modelDocument : <EOL> modelDocument . close ( urlDocs = urlDocs ) <EOL> @ property <EOL> def isClosed ( self ) : <EOL> """<STR_LIT>""" <EOL> return not bool ( self . __dict__ ) <EOL> def reload ( self , nextaction , reloadCache = False ) : <EOL> """<STR_LIT>""" <EOL> from arelle import ModelDocument <EOL> self . init ( keepViews = True ) <EOL> self . modelDocument = ModelDocument . load ( self , self . fileSource . url , isEntry = True , reloadCache = reloadCache ) <EOL> self . modelManager . showStatus ( _ ( "<STR_LIT>" ) . format ( nextaction ) , <NUM_LIT> ) <EOL> self . modelManager . reloadViews ( self ) <EOL> def closeViews ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . isClosed : <EOL> for view in range ( len ( self . views ) ) : <EOL> if len ( self . views ) > <NUM_LIT:0> : <EOL> self . views [ <NUM_LIT:0> ] . close ( ) <EOL> def relationshipSet ( self , arcrole , linkrole = None , linkqname = None , arcqname = None , includeProhibits = False ) : <EOL> """<STR_LIT>""" <EOL> global ModelRelationshipSet <EOL> if ModelRelationshipSet is None : <EOL> from arelle import ModelRelationshipSet <EOL> key = ( arcrole , linkrole , linkqname , arcqname , includeProhibits ) <EOL> if key not in self . relationshipSets : <EOL> ModelRelationshipSet . create ( self , arcrole , linkrole , linkqname , arcqname , includeProhibits ) <EOL> return self . relationshipSets [ key ] <EOL> def baseSetModelLink ( self , linkElement ) : <EOL> for modelLink in self . baseSets [ ( "<STR_LIT>" , None , None , None ) ] : <EOL> if modelLink == linkElement : <EOL> return modelLink <EOL> return None <EOL> def roleTypeDefinition ( self , roleURI ) : <EOL> modelRoles = self . roleTypes . get ( roleURI , ( ) ) <EOL> if modelRoles : <EOL> return modelRoles [ <NUM_LIT:0> ] . definition or roleURI <EOL> return roleURI <EOL> def roleTypeName ( self , roleURI ) : <EOL> for pluginXbrlMethod in pluginClassMethods ( "<STR_LIT>" ) : <EOL> _roleTypeName = pluginXbrlMethod ( self , roleURI ) <EOL> if _roleTypeName : <EOL> return _roleTypeName <EOL> return self . roleTypeDefinition ( roleURI ) <EOL> def matchSubstitutionGroup ( self , elementQname , subsGrpMatchTable ) : <EOL> """<STR_LIT>""" <EOL> if elementQname in subsGrpMatchTable : <EOL> return subsGrpMatchTable [ elementQname ] <EOL> elementMdlObj = self . qnameConcepts . get ( elementQname ) <EOL> if elementMdlObj is not None : <EOL> subsGrpMdlObj = elementMdlObj . substitutionGroup <EOL> while subsGrpMdlObj is not None : <EOL> subsGrpQname = subsGrpMdlObj . qname <EOL> if subsGrpQname in subsGrpMatchTable : <EOL> return subsGrpMatchTable [ subsGrpQname ] <EOL> subsGrpMdlObj = subsGrpMdlObj . substitutionGroup <EOL> return subsGrpMatchTable . get ( None ) <EOL> def isInSubstitutionGroup ( self , elementQname , subsGrpQnames ) : <EOL> """<STR_LIT>""" <EOL> return self . matchSubstitutionGroup ( elementQname , { <EOL> qn : ( qn is not None ) for qn in ( subsGrpQnames if hasattr ( subsGrpQnames , '<STR_LIT>' ) else ( subsGrpQnames , ) ) + ( None , ) } ) <EOL> def createInstance ( self , url = None ) : <EOL> """<STR_LIT>""" <EOL> from arelle import ( ModelDocument , FileSource ) <EOL> if self . modelDocument . type == ModelDocument . Type . INSTANCE : <EOL> del self . facts [ : ] <EOL> self . factsInInstance . clear ( ) <EOL> del self . undefinedFacts [ : ] <EOL> self . contexts . clear ( ) <EOL> self . units . clear ( ) <EOL> self . modelDocument . idObjects . clear <EOL> del self . modelDocument . hrefObjects [ : ] <EOL> self . modelDocument . schemaLocationElements . clear ( ) <EOL> self . modelDocument . referencedNamespaces . clear ( ) <EOL> for child in list ( self . modelDocument . xmlRootElement ) : <EOL> if not ( isinstance ( child , ModelObject ) and child . namespaceURI == XbrlConst . link and <EOL> child . localName . endswith ( "<STR_LIT>" ) ) : <EOL> self . modelDocument . xmlRootElement . remove ( child ) <EOL> else : <EOL> priorFileSource = self . fileSource <EOL> self . fileSource = FileSource . FileSource ( url , self . modelManager . cntlr ) <EOL> if isHttpUrl ( self . uri ) : <EOL> schemaRefUri = self . uri <EOL> else : <EOL> schemaRefUri = os . path . relpath ( self . uri , os . path . dirname ( url ) ) <EOL> self . modelDocument = ModelDocument . create ( self , ModelDocument . Type . INSTANCE , url , schemaRefs = [ schemaRefUri ] , isEntry = True ) <EOL> if priorFileSource : <EOL> priorFileSource . close ( ) <EOL> self . closeFileSource = True <EOL> del self . entryLoadingUrl <EOL> from arelle import ViewWinDTS <EOL> for view in self . views : <EOL> if isinstance ( view , ViewWinDTS . ViewDTS ) : <EOL> self . modelManager . cntlr . uiThreadQueue . put ( ( view . view , [ ] ) ) <EOL> def saveInstance ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . modelDocument . save ( ** kwargs ) <EOL> @ property <EOL> def prefixedNamespaces ( self ) : <EOL> """<STR_LIT>""" <EOL> prefixedNamespaces = { } <EOL> for nsDocs in self . namespaceDocs . values ( ) : <EOL> for nsDoc in nsDocs : <EOL> ns = nsDoc . targetNamespace <EOL> if ns : <EOL> prefix = XmlUtil . xmlnsprefix ( nsDoc . xmlRootElement , ns ) <EOL> if prefix and prefix not in prefixedNamespaces : <EOL> prefixedNamespaces [ prefix ] = ns <EOL> return prefixedNamespaces <EOL> def matchContext ( self , entityIdentScheme , entityIdentValue , periodType , periodStart , periodEndInstant , dims , segOCCs , scenOCCs ) : <EOL> """<STR_LIT>""" <EOL> from arelle . ModelFormulaObject import Aspect <EOL> from arelle . ModelValue import dateUnionEqual <EOL> from arelle . XbrlUtil import sEqual <EOL> if dims : segAspect , scenAspect = ( Aspect . NON_XDT_SEGMENT , Aspect . NON_XDT_SCENARIO ) <EOL> else : segAspect , scenAspect = ( Aspect . COMPLETE_SEGMENT , Aspect . COMPLETE_SCENARIO ) <EOL> for c in self . contexts . values ( ) : <EOL> if ( c . entityIdentifier == ( entityIdentScheme , entityIdentValue ) and <EOL> ( ( c . isInstantPeriod and periodType == "<STR_LIT>" and dateUnionEqual ( c . instantDatetime , periodEndInstant , instantEndDate = True ) ) or <EOL> ( c . isStartEndPeriod and periodType == "<STR_LIT>" and dateUnionEqual ( c . startDatetime , periodStart ) and dateUnionEqual ( c . endDatetime , periodEndInstant , instantEndDate = True ) ) or <EOL> ( c . isForeverPeriod and periodType == "<STR_LIT>" ) ) and <EOL> ( dims is None or ( <EOL> ( c . qnameDims . keys ( ) == dims . keys ( ) ) and <EOL> all ( [ cDim . isEqualTo ( dims [ cDimQn ] ) for cDimQn , cDim in c . qnameDims . items ( ) ] ) ) ) and <EOL> all ( <EOL> all ( [ sEqual ( self , cOCCs [ i ] , mOCCs [ i ] ) for i in range ( len ( mOCCs ) ) ] ) <EOL> if len ( cOCCs ) == len ( mOCCs ) else False <EOL> for cOCCs , mOCCs in ( ( c . nonDimValues ( segAspect ) , segOCCs ) , <EOL> ( c . nonDimValues ( scenAspect ) , scenOCCs ) ) ) <EOL> ) : <EOL> return c <EOL> return None <EOL> def createContext ( self , entityIdentScheme , entityIdentValue , periodType , periodStart , periodEndInstant , priItem , dims , segOCCs , scenOCCs , <EOL> afterSibling = None , beforeSibling = None , id = None ) : <EOL> """<STR_LIT>""" <EOL> xbrlElt = self . modelDocument . xmlRootElement <EOL> if afterSibling == AUTO_LOCATE_ELEMENT : <EOL> afterSibling = XmlUtil . lastChild ( xbrlElt , XbrlConst . xbrli , ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> cntxId = id if id else '<STR_LIT>' . format ( len ( self . contexts ) + <NUM_LIT:1> ) <EOL> newCntxElt = XmlUtil . addChild ( xbrlElt , XbrlConst . xbrli , "<STR_LIT>" , attributes = ( "<STR_LIT:id>" , cntxId ) , <EOL> afterSibling = afterSibling , beforeSibling = beforeSibling ) <EOL> entityElt = XmlUtil . addChild ( newCntxElt , XbrlConst . xbrli , "<STR_LIT>" ) <EOL> XmlUtil . addChild ( entityElt , XbrlConst . xbrli , "<STR_LIT>" , <EOL> attributes = ( "<STR_LIT>" , entityIdentScheme ) , <EOL> text = entityIdentValue ) <EOL> periodElt = XmlUtil . addChild ( newCntxElt , XbrlConst . xbrli , "<STR_LIT>" ) <EOL> if periodType == "<STR_LIT>" : <EOL> XmlUtil . addChild ( periodElt , XbrlConst . xbrli , "<STR_LIT>" ) <EOL> elif periodType == "<STR_LIT>" : <EOL> XmlUtil . addChild ( periodElt , XbrlConst . xbrli , "<STR_LIT>" , <EOL> text = XmlUtil . dateunionValue ( periodEndInstant , subtractOneDay = True ) ) <EOL> elif periodType == "<STR_LIT>" : <EOL> XmlUtil . addChild ( periodElt , XbrlConst . xbrli , "<STR_LIT>" , <EOL> text = XmlUtil . dateunionValue ( periodStart ) ) <EOL> XmlUtil . addChild ( periodElt , XbrlConst . xbrli , "<STR_LIT>" , <EOL> text = XmlUtil . dateunionValue ( periodEndInstant , subtractOneDay = True ) ) <EOL> segmentElt = None <EOL> scenarioElt = None <EOL> from arelle . ModelInstanceObject import ModelDimensionValue <EOL> if dims : <EOL> '''<STR_LIT>''' <EOL> if priItem is not None : <EOL> dims [ <NUM_LIT:2> ] = priItem <EOL> fp = FactPrototype ( self , dims ) <EOL> del dims [ <NUM_LIT:2> ] <EOL> if not isFactDimensionallyValid ( self , fp , setPrototypeContextElements = True ) : <EOL> self . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = self , priItem = priItem ) <EOL> fpDims = fp . context . qnameDims <EOL> else : <EOL> fpDims = dims <EOL> for dimQname in sorted ( fpDims . keys ( ) ) : <EOL> dimValue = fpDims [ dimQname ] <EOL> if isinstance ( dimValue , ( DimValuePrototype , ModelDimensionValue ) ) : <EOL> dimMemberQname = dimValue . memberQname <EOL> contextEltName = dimValue . contextElement <EOL> else : <EOL> dimMemberQname = None <EOL> contextEltName = None <EOL> if contextEltName == "<STR_LIT>" : <EOL> if segmentElt is None : <EOL> segmentElt = XmlUtil . addChild ( entityElt , XbrlConst . xbrli , "<STR_LIT>" ) <EOL> contextElt = segmentElt <EOL> elif contextEltName == "<STR_LIT>" : <EOL> if scenarioElt is None : <EOL> scenarioElt = XmlUtil . addChild ( newCntxElt , XbrlConst . xbrli , "<STR_LIT>" ) <EOL> contextElt = scenarioElt <EOL> else : <EOL> self . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = self , dimension = dimQname ) , <EOL> continue <EOL> dimAttr = ( "<STR_LIT>" , XmlUtil . addQnameValue ( xbrlElt , dimQname ) ) <EOL> if dimValue . isTyped : <EOL> dimElt = XmlUtil . addChild ( contextElt , XbrlConst . xbrldi , "<STR_LIT>" , <EOL> attributes = dimAttr ) <EOL> if isinstance ( dimValue , ( ModelDimensionValue , DimValuePrototype ) ) and dimValue . isTyped : <EOL> XmlUtil . copyNodes ( dimElt , dimValue . typedMember ) <EOL> elif dimMemberQname : <EOL> dimElt = XmlUtil . addChild ( contextElt , XbrlConst . xbrldi , "<STR_LIT>" , <EOL> attributes = dimAttr , <EOL> text = XmlUtil . addQnameValue ( xbrlElt , dimMemberQname ) ) <EOL> if segOCCs : <EOL> if segmentElt is None : <EOL> segmentElt = XmlUtil . addChild ( entityElt , XbrlConst . xbrli , "<STR_LIT>" ) <EOL> XmlUtil . copyNodes ( segmentElt , segOCCs ) <EOL> if scenOCCs : <EOL> if scenarioElt is None : <EOL> scenarioElt = XmlUtil . addChild ( newCntxElt , XbrlConst . xbrli , "<STR_LIT>" ) <EOL> XmlUtil . copyNodes ( scenarioElt , scenOCCs ) <EOL> XmlValidate . validate ( self , newCntxElt ) <EOL> self . modelDocument . contextDiscover ( newCntxElt ) <EOL> return newCntxElt <EOL> def matchUnit ( self , multiplyBy , divideBy ) : <EOL> """<STR_LIT>""" <EOL> multiplyBy . sort ( ) <EOL> divideBy . sort ( ) <EOL> for u in self . units . values ( ) : <EOL> if u . measures == ( multiplyBy , divideBy ) : <EOL> return u <EOL> return None <EOL> def createUnit ( self , multiplyBy , divideBy , afterSibling = None , beforeSibling = None , id = None ) : <EOL> """<STR_LIT>""" <EOL> xbrlElt = self . modelDocument . xmlRootElement <EOL> if afterSibling == AUTO_LOCATE_ELEMENT : <EOL> afterSibling = XmlUtil . lastChild ( xbrlElt , XbrlConst . xbrli , ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> unitId = id if id else '<STR_LIT>' . format ( len ( self . units ) + <NUM_LIT:1> ) <EOL> newUnitElt = XmlUtil . addChild ( xbrlElt , XbrlConst . xbrli , "<STR_LIT>" , attributes = ( "<STR_LIT:id>" , unitId ) , <EOL> afterSibling = afterSibling , beforeSibling = beforeSibling ) <EOL> if len ( divideBy ) == <NUM_LIT:0> : <EOL> for multiply in multiplyBy : <EOL> XmlUtil . addChild ( newUnitElt , XbrlConst . xbrli , "<STR_LIT>" , text = XmlUtil . addQnameValue ( xbrlElt , multiply ) ) <EOL> else : <EOL> divElt = XmlUtil . addChild ( newUnitElt , XbrlConst . xbrli , "<STR_LIT>" ) <EOL> numElt = XmlUtil . addChild ( divElt , XbrlConst . xbrli , "<STR_LIT>" ) <EOL> denElt = XmlUtil . addChild ( divElt , XbrlConst . xbrli , "<STR_LIT>" ) <EOL> for multiply in multiplyBy : <EOL> XmlUtil . addChild ( numElt , XbrlConst . xbrli , "<STR_LIT>" , text = XmlUtil . addQnameValue ( xbrlElt , multiply ) ) <EOL> for divide in divideBy : <EOL> XmlUtil . addChild ( denElt , XbrlConst . xbrli , "<STR_LIT>" , text = XmlUtil . addQnameValue ( xbrlElt , divide ) ) <EOL> XmlValidate . validate ( self , newUnitElt ) <EOL> self . modelDocument . unitDiscover ( newUnitElt ) <EOL> return newUnitElt <EOL> @ property <EOL> def nonNilFactsInInstance ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . _nonNilFactsInInstance <EOL> except AttributeError : <EOL> self . _nonNilFactsInInstance = set ( f for f in self . factsInInstance if not f . isNil ) <EOL> return self . _nonNilFactsInInstance <EOL> @ property <EOL> def factsByQname ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . _factsByQname <EOL> except AttributeError : <EOL> self . _factsByQname = fbqn = defaultdict ( set ) <EOL> for f in self . factsInInstance : <EOL> if f . qname is not None : <EOL> fbqn [ f . qname ] . add ( f ) <EOL> return fbqn <EOL> def factsByDatatype ( self , notStrict , typeQname ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . _factsByDatatype [ notStrict , typeQname ] <EOL> except AttributeError : <EOL> self . _factsByDatatype = { } <EOL> return self . factsByDatatype ( notStrict , typeQname ) <EOL> except KeyError : <EOL> self . _factsByDatatype [ notStrict , typeQname ] = fbdt = set ( ) <EOL> for f in self . factsInInstance : <EOL> c = f . concept <EOL> if c . typeQname == typeQname or ( notStrict and c . type . isDerivedFrom ( typeQname ) ) : <EOL> fbdt . add ( f ) <EOL> return fbdt <EOL> def factsByPeriodType ( self , periodType ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . _factsByPeriodType [ periodType ] <EOL> except AttributeError : <EOL> self . _factsByPeriodType = fbpt = defaultdict ( set ) <EOL> for f in self . factsInInstance : <EOL> p = f . concept . periodType <EOL> if p : <EOL> fbpt [ p ] . add ( f ) <EOL> return self . factsByPeriodType ( periodType ) <EOL> except KeyError : <EOL> return set ( ) <EOL> def factsByDimMemQname ( self , dimQname , memQname = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> fbdq = self . _factsByDimQname [ dimQname ] <EOL> return fbdq [ memQname ] <EOL> except AttributeError : <EOL> self . _factsByDimQname = { } <EOL> return self . factsByDimMemQname ( dimQname , memQname ) <EOL> except KeyError : <EOL> self . _factsByDimQname [ dimQname ] = fbdq = defaultdict ( set ) <EOL> for fact in self . factsInInstance : <EOL> if fact . isItem and fact . context is not None : <EOL> dimValue = fact . context . dimValue ( dimQname ) <EOL> if isinstance ( dimValue , ModelValue . QName ) : <EOL> fbdq [ None ] . add ( fact ) <EOL> if dimQname in self . modelXbrl . qnameDimensionDefaults : <EOL> fbdq [ self . qnameDimensionDefaults [ dimQname ] ] . add ( fact ) <EOL> fbdq [ DEFAULT ] . add ( fact ) <EOL> elif dimValue is not None : <EOL> fbdq [ None ] . add ( fact ) <EOL> fbdq [ NONDEFAULT ] . add ( fact ) <EOL> if dimValue . isExplicit : <EOL> fbdq [ dimValue . memberQname ] . add ( fact ) <EOL> else : <EOL> fbdq [ DEFAULT ] . add ( fact ) <EOL> return fbdq [ memQname ] <EOL> def matchFact ( self , otherFact , unmatchedFactsStack = None , deemP0inf = False ) : <EOL> """<STR_LIT>""" <EOL> for fact in self . facts : <EOL> if ( fact . isTuple ) : <EOL> if otherFact . isDuplicateOf ( fact , unmatchedFactsStack = unmatchedFactsStack ) : <EOL> return fact <EOL> elif ( fact . qname == otherFact . qname and fact . isVEqualTo ( otherFact , deemP0inf = deemP0inf ) ) : <EOL> if not fact . isNumeric : <EOL> if fact . xmlLang == otherFact . xmlLang : <EOL> return fact <EOL> else : <EOL> if ( fact . decimals == otherFact . decimals and <EOL> fact . precision == otherFact . precision ) : <EOL> return fact <EOL> return None <EOL> def createFact ( self , conceptQname , attributes = None , text = None , parent = None , afterSibling = None , beforeSibling = None , validate = True ) : <EOL> """<STR_LIT>""" <EOL> if parent is None : parent = self . modelDocument . xmlRootElement <EOL> self . makeelementParentModelObject = parent <EOL> newFact = XmlUtil . addChild ( parent , conceptQname , attributes = attributes , text = text , <EOL> afterSibling = afterSibling , beforeSibling = beforeSibling ) <EOL> global ModelFact <EOL> if ModelFact is None : <EOL> from arelle . ModelInstanceObject import ModelFact <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> self . _factsByQname [ newFact . qname ] . add ( newFact ) <EOL> if not isinstance ( newFact , ModelFact ) : <EOL> return newFact <EOL> del self . makeelementParentModelObject <EOL> if validate : <EOL> XmlValidate . validate ( self , newFact ) <EOL> self . modelDocument . factDiscover ( newFact , parentElement = parent ) <EOL> if not newFact . isNil and hasattr ( self , "<STR_LIT>" ) : <EOL> self . _nonNilFactsInInstance . add ( newFact ) <EOL> if newFact . concept is not None : <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> del self . _factsByDatatype <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> self . _factsByPeriodType [ newFact . concept . periodType ] . add ( newFact ) <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> del self . _factsByDimQname <EOL> self . setIsModified ( ) <EOL> return newFact <EOL> def setIsModified ( self ) : <EOL> """<STR_LIT>""" <EOL> self . modelDocument . isModified = True <EOL> def isModified ( self ) : <EOL> """<STR_LIT>""" <EOL> md = self . modelDocument <EOL> if md is not None : <EOL> return md . isModified <EOL> else : <EOL> return False <EOL> def modelObject ( self , objectId ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( objectId , _INT_TYPES ) : <EOL> return self . modelObjects [ objectId ] <EOL> try : <EOL> return self . modelObjects [ _INT ( objectId . rpartition ( "<STR_LIT:_>" ) [ <NUM_LIT:2> ] ) ] <EOL> except ( IndexError , ValueError ) : <EOL> return None <EOL> def viewModelObject ( self , objectId ) : <EOL> """<STR_LIT>""" <EOL> modelObject = "<STR_LIT>" <EOL> try : <EOL> if isinstance ( objectId , ( ModelObject , FactPrototype ) ) : <EOL> modelObject = objectId <EOL> elif isinstance ( objectId , str ) and objectId . startswith ( "<STR_LIT:_>" ) : <EOL> modelObject = self . modelObject ( objectId ) <EOL> if modelObject is not None : <EOL> for view in self . views : <EOL> view . viewModelObject ( modelObject ) <EOL> except ( IndexError , ValueError , AttributeError ) as err : <EOL> self . modelManager . addToLog ( _ ( "<STR_LIT>" ) . format ( <EOL> modelObject , <EOL> err , traceback . format_tb ( sys . exc_info ( ) [ <NUM_LIT:2> ] ) ) ) <EOL> def effectiveMessageCode ( self , messageCodes ) : <EOL> effectiveMessageCode = None <EOL> _validationType = self . modelManager . disclosureSystem . validationType <EOL> _exclusiveTypesPattern = self . modelManager . disclosureSystem . exclusiveTypesPattern <EOL> for argCode in messageCodes if isinstance ( messageCodes , tuple ) else ( messageCodes , ) : <EOL> if ( isinstance ( argCode , ModelValue . QName ) or <EOL> ( _validationType and argCode . startswith ( _validationType ) ) or <EOL> ( not _exclusiveTypesPattern or _exclusiveTypesPattern . match ( argCode ) == None ) ) : <EOL> effectiveMessageCode = argCode <EOL> break <EOL> return effectiveMessageCode <EOL> def isLoggingEffectiveFor ( self , ** kwargs ) : <EOL> logger = self . logger <EOL> if "<STR_LIT>" in kwargs or "<STR_LIT>" in kwargs : <EOL> if "<STR_LIT>" in kwargs : <EOL> messageCodes = kwargs [ "<STR_LIT>" ] <EOL> else : <EOL> messageCodes = kwargs [ "<STR_LIT>" ] <EOL> messageCode = self . effectiveMessageCode ( messageCodes ) <EOL> codeEffective = ( messageCode and <EOL> ( not logger . messageCodeFilter or logger . messageCodeFilter . match ( messageCode ) ) ) <EOL> else : <EOL> codeEffective = True <EOL> if "<STR_LIT>" in kwargs and logger . messageLevelFilter : <EOL> levelEffective = logger . messageLevelFilter . match ( kwargs [ "<STR_LIT>" ] . lower ( ) ) <EOL> else : <EOL> levelEffective = True <EOL> return codeEffective and levelEffective <EOL> def logArguments ( self , codes , msg , codedArgs ) : <EOL> """<STR_LIT>""" <EOL> def propValues ( properties ) : <EOL> return [ ( p [ <NUM_LIT:0> ] , str ( p [ <NUM_LIT:1> ] ) ) if len ( p ) == <NUM_LIT:2> else ( p [ <NUM_LIT:0> ] , str ( p [ <NUM_LIT:1> ] ) , propValues ( p [ <NUM_LIT:2> ] ) ) <EOL> for p in properties if <NUM_LIT:2> <= len ( p ) <= <NUM_LIT:3> ] <EOL> messageCode = self . effectiveMessageCode ( codes ) <EOL> fmtArgs = { } <EOL> extras = { "<STR_LIT>" : messageCode } <EOL> modelObjectArgs = ( ) <EOL> for argName , argValue in codedArgs . items ( ) : <EOL> if argName in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> try : <EOL> entryUrl = self . modelDocument . uri <EOL> except AttributeError : <EOL> try : <EOL> entryUrl = self . entryLoadingUrl <EOL> except AttributeError : <EOL> entryUrl = self . fileSource . url <EOL> refs = [ ] <EOL> modelObjectArgs = argValue if isinstance ( argValue , ( tuple , list , set ) ) else ( argValue , ) <EOL> for arg in flattenSequence ( modelObjectArgs ) : <EOL> if arg is not None : <EOL> if isinstance ( arg , _STR_BASE ) : <EOL> objectUrl = arg <EOL> else : <EOL> try : <EOL> objectUrl = arg . modelDocument . uri <EOL> except AttributeError : <EOL> try : <EOL> objectUrl = self . modelDocument . uri <EOL> except AttributeError : <EOL> objectUrl = self . entryLoadingUrl <EOL> try : <EOL> file = UrlUtil . relativeUri ( entryUrl , objectUrl ) <EOL> except : <EOL> file = "<STR_LIT>" <EOL> ref = { } <EOL> if isinstance ( arg , ( ModelObject , ObjectPropertyViewWrapper ) ) : <EOL> _arg = arg . modelObject if isinstance ( arg , ObjectPropertyViewWrapper ) else arg <EOL> ref [ "<STR_LIT>" ] = file + "<STR_LIT:#>" + XmlUtil . elementFragmentIdentifier ( _arg ) <EOL> ref [ "<STR_LIT>" ] = _arg . sourceline <EOL> ref [ "<STR_LIT>" ] = _arg . objectId ( ) <EOL> if self . logRefObjectProperties : <EOL> try : <EOL> ref [ "<STR_LIT>" ] = propValues ( arg . propertyView ) <EOL> except AttributeError : <EOL> pass <EOL> if self . logRefHasPluginProperties : <EOL> refProperties = ref . get ( "<STR_LIT>" , { } ) <EOL> for pluginXbrlMethod in pluginClassMethods ( "<STR_LIT>" ) : <EOL> pluginXbrlMethod ( arg , refProperties , codedArgs ) <EOL> if refProperties : <EOL> ref [ "<STR_LIT>" ] = refProperties <EOL> else : <EOL> ref [ "<STR_LIT>" ] = file <EOL> try : <EOL> ref [ "<STR_LIT>" ] = arg . sourceline <EOL> except AttributeError : <EOL> pass <EOL> if self . logRefHasPluginAttrs : <EOL> refAttributes = { } <EOL> for pluginXbrlMethod in pluginClassMethods ( "<STR_LIT>" ) : <EOL> pluginXbrlMethod ( arg , refAttributes , codedArgs ) <EOL> if refAttributes : <EOL> ref [ "<STR_LIT>" ] = refAttributes <EOL> refs . append ( ref ) <EOL> extras [ "<STR_LIT>" ] = refs <EOL> elif argName == "<STR_LIT>" : <EOL> ref = { } <EOL> if isinstance ( argValue , ( tuple , list ) ) : <EOL> ref [ "<STR_LIT>" ] = str ( argValue [ <NUM_LIT:0> ] ) <EOL> if len ( argValue ) > <NUM_LIT:1> and argValue [ <NUM_LIT:1> ] : <EOL> ref [ "<STR_LIT>" ] = str ( argValue [ <NUM_LIT:1> ] ) <EOL> else : <EOL> ref [ "<STR_LIT>" ] = str ( argValue ) <EOL> extras [ "<STR_LIT>" ] = [ ref ] <EOL> elif argName == "<STR_LIT>" : <EOL> refs = [ ] <EOL> for arg in ( argValue if isinstance ( argValue , ( tuple , list ) ) else ( argValue , ) ) : <EOL> ref = { } <EOL> if isinstance ( arg , ( tuple , list ) ) : <EOL> ref [ "<STR_LIT>" ] = str ( arg [ <NUM_LIT:0> ] ) <EOL> if len ( arg ) > <NUM_LIT:1> and arg [ <NUM_LIT:1> ] : <EOL> ref [ "<STR_LIT>" ] = str ( arg [ <NUM_LIT:1> ] ) <EOL> else : <EOL> ref [ "<STR_LIT>" ] = str ( arg ) <EOL> refs . append ( ref ) <EOL> extras [ "<STR_LIT>" ] = refs <EOL> elif argName == "<STR_LIT>" : <EOL> if isinstance ( argValue , _INT_TYPES ) : <EOL> extras [ "<STR_LIT>" ] = argValue <EOL> elif argName not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if isinstance ( argValue , ( ModelValue . QName , ModelObject , bool , FileNamedStringIO , <EOL> tuple , list , set ) ) : <EOL> fmtArgs [ argName ] = str ( argValue ) <EOL> elif argValue is None : <EOL> fmtArgs [ argName ] = "<STR_LIT>" <EOL> elif isinstance ( argValue , _INT_TYPES ) : <EOL> fmtArgs [ argName ] = format_string ( self . modelManager . locale , '<STR_LIT>' , argValue ) <EOL> elif isinstance ( argValue , ( float , Decimal ) ) : <EOL> fmtArgs [ argName ] = format_string ( self . modelManager . locale , '<STR_LIT>' , argValue ) <EOL> elif isinstance ( argValue , dict ) : <EOL> fmtArgs [ argName ] = argValue <EOL> else : <EOL> fmtArgs [ argName ] = str ( argValue ) <EOL> if "<STR_LIT>" not in extras : <EOL> try : <EOL> file = os . path . basename ( self . modelDocument . uri ) <EOL> except AttributeError : <EOL> try : <EOL> file = os . path . basename ( self . entryLoadingUrl ) <EOL> except : <EOL> file = "<STR_LIT>" <EOL> extras [ "<STR_LIT>" ] = [ { "<STR_LIT>" : file } ] <EOL> for pluginXbrlMethod in pluginClassMethods ( "<STR_LIT>" ) : <EOL> msg = pluginXbrlMethod ( messageCode , msg , modelObjectArgs , fmtArgs ) or msg <EOL> return ( messageCode , <EOL> ( msg , fmtArgs ) if fmtArgs else ( msg , ) , <EOL> extras ) <EOL> def debug ( self , codes , msg , ** args ) : <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> self . log ( '<STR_LIT>' , codes , msg , ** args ) <EOL> def info ( self , codes , msg , ** args ) : <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> self . log ( '<STR_LIT>' , codes , msg , ** args ) <EOL> def warning ( self , codes , msg , ** args ) : <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> self . log ( '<STR_LIT>' , codes , msg , ** args ) <EOL> def log ( self , level , codes , msg , ** args ) : <EOL> """<STR_LIT>""" <EOL> logger = self . logger <EOL> messageCode , logArgs , extras = self . logArguments ( codes , msg , args ) <EOL> if messageCode == "<STR_LIT>" : <EOL> self . errors . append ( args [ "<STR_LIT>" ] ) <EOL> elif ( messageCode and <EOL> ( not logger . messageCodeFilter or logger . messageCodeFilter . match ( messageCode ) ) and <EOL> ( not logger . messageLevelFilter or logger . messageLevelFilter . match ( level . lower ( ) ) ) ) : <EOL> numericLevel = logging . _checkLevel ( level ) <EOL> self . logCount [ numericLevel ] = self . logCount . get ( numericLevel , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> if numericLevel >= self . errorCaptureLevel : <EOL> self . errors . append ( messageCode ) <EOL> """<STR_LIT>""" <EOL> logger . log ( numericLevel , * logArgs , exc_info = args . get ( "<STR_LIT>" ) , extra = extras ) <EOL> def error ( self , codes , msg , ** args ) : <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> self . log ( '<STR_LIT>' , codes , msg , ** args ) <EOL> def exception ( self , codes , msg , ** args ) : <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> self . log ( '<STR_LIT>' , codes , msg , ** args ) <EOL> def logProfileStats ( self ) : <EOL> """<STR_LIT>""" <EOL> timeTotal = format_string ( self . modelManager . locale , _ ( "<STR_LIT>" ) , self . profileStats . get ( "<STR_LIT>" , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) [ <NUM_LIT:1> ] ) <EOL> timeEFM = format_string ( self . modelManager . locale , _ ( "<STR_LIT>" ) , self . profileStats . get ( "<STR_LIT>" , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) [ <NUM_LIT:1> ] ) <EOL> self . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) + <EOL> '<STR_LIT>' . join ( format_string ( self . modelManager . locale , _ ( "<STR_LIT>" ) , ( statName , statValue [ <NUM_LIT:1> ] , statValue [ <NUM_LIT:2> ] ) , grouping = True ) <EOL> for statName , statValue in sorted ( self . profileStats . items ( ) , key = lambda item : item [ <NUM_LIT:1> ] ) ) + <EOL> "<STR_LIT>" , <EOL> modelObject = self . modelXbrl . modelDocument , profileStats = self . profileStats , <EOL> timeTotal = timeTotal , timeEFM = timeEFM ) <EOL> def profileStat ( self , name = None , stat = None ) : <EOL> '''<STR_LIT>''' <EOL> if self . modelManager . collectProfileStats : <EOL> import time <EOL> global profileStatNumber <EOL> try : <EOL> if name : <EOL> thisTime = stat if stat is not None else time . time ( ) - self . _startedTimeStat <EOL> mem = self . modelXbrl . modelManager . cntlr . memoryUsed <EOL> prevTime = self . profileStats . get ( name , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) [ <NUM_LIT:1> ] <EOL> self . profileStats [ name ] = ( profileStatNumber , thisTime + prevTime , mem ) <EOL> profileStatNumber += <NUM_LIT:1> <EOL> except AttributeError : <EOL> pass <EOL> if stat is None : <EOL> self . _startedTimeStat = time . time ( ) <EOL> def profileActivity ( self , activityCompleted = None , minTimeToShow = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> import time <EOL> try : <EOL> if activityCompleted : <EOL> timeTaken = time . time ( ) - self . _startedProfiledActivity <EOL> if timeTaken > minTimeToShow : <EOL> self . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = self . modelXbrl . modelDocument , activity = activityCompleted , <EOL> time = format_string ( self . modelManager . locale , "<STR_LIT>" , timeTaken , grouping = True ) ) <EOL> except AttributeError : <EOL> pass <EOL> self . _startedProfiledActivity = time . time ( ) <EOL> def saveDTSpackage ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . fileSource . isArchive : <EOL> return <EOL> from zipfile import ZipFile <EOL> import os <EOL> entryFilename = self . fileSource . url <EOL> pkgFilename = entryFilename + "<STR_LIT>" <EOL> with ZipFile ( pkgFilename , '<STR_LIT:w>' ) as zip : <EOL> numFiles = <NUM_LIT:0> <EOL> for fileUri in sorted ( self . urlDocs . keys ( ) ) : <EOL> if not isHttpUrl ( fileUri ) : <EOL> numFiles += <NUM_LIT:1> <EOL> zip . write ( fileUri , os . path . basename ( fileUri ) ) <EOL> self . info ( "<STR_LIT:info>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = self , <EOL> entryFile = os . path . basename ( entryFilename ) , packageOutputFile = pkgFilename , numberOfFiles = numFiles ) </s>
|
<s> '''<STR_LIT>''' <EOL> from collections import defaultdict <EOL> from math import ( log10 , isnan , isinf , fabs , trunc , fmod , floor , pow ) <EOL> import decimal <EOL> try : <EOL> from regex import compile as re_compile <EOL> except ImportError : <EOL> from re import compile as re_compile <EOL> import hashlib <EOL> from arelle import Locale , XbrlConst , XbrlUtil <EOL> from arelle . ModelObject import ObjectPropertyViewWrapper <EOL> from arelle . XmlValidate import UNVALIDATED , VALID <EOL> numberPattern = re_compile ( "<STR_LIT>" ) <EOL> ZERO = decimal . Decimal ( <NUM_LIT:0> ) <EOL> ONE = decimal . Decimal ( <NUM_LIT:1> ) <EOL> NaN = decimal . Decimal ( "<STR_LIT>" ) <EOL> floatNaN = float ( "<STR_LIT>" ) <EOL> floatINF = float ( "<STR_LIT>" ) <EOL> def validate ( modelXbrl , inferDecimals = False ) : <EOL> ValidateXbrlCalcs ( modelXbrl , inferDecimals ) . validate ( ) <EOL> class ValidateXbrlCalcs : <EOL> def __init__ ( self , modelXbrl , inferDecimals = False ) : <EOL> self . modelXbrl = modelXbrl <EOL> self . inferDecimals = inferDecimals <EOL> self . mapContext = { } <EOL> self . mapUnit = { } <EOL> self . sumFacts = defaultdict ( list ) <EOL> self . sumConceptBindKeys = defaultdict ( set ) <EOL> self . itemFacts = defaultdict ( list ) <EOL> self . itemConceptBindKeys = defaultdict ( set ) <EOL> self . duplicateKeyFacts = { } <EOL> self . duplicatedFacts = set ( ) <EOL> self . esAlFacts = defaultdict ( list ) <EOL> self . esAlConceptBindKeys = defaultdict ( set ) <EOL> self . conceptsInEssencesAlias = set ( ) <EOL> self . requiresElementFacts = defaultdict ( list ) <EOL> self . conceptsInRequiresElement = set ( ) <EOL> def validate ( self ) : <EOL> if not self . modelXbrl . contexts and not self . modelXbrl . facts : <EOL> return <EOL> if not self . inferDecimals : <EOL> self . modelXbrl . info ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . modelXbrl . profileActivity ( ) <EOL> uniqueContextHashes = { } <EOL> for context in self . modelXbrl . contexts . values ( ) : <EOL> h = context . contextDimAwareHash <EOL> if h in uniqueContextHashes : <EOL> if context . isEqualTo ( uniqueContextHashes [ h ] ) : <EOL> self . mapContext [ context ] = uniqueContextHashes [ h ] <EOL> else : <EOL> uniqueContextHashes [ h ] = context <EOL> del uniqueContextHashes <EOL> self . modelXbrl . profileActivity ( "<STR_LIT>" , minTimeToShow = <NUM_LIT:1.0> ) <EOL> uniqueUnitHashes = { } <EOL> for unit in self . modelXbrl . units . values ( ) : <EOL> h = unit . hash <EOL> if h in uniqueUnitHashes : <EOL> if unit . isEqualTo ( uniqueUnitHashes [ h ] ) : <EOL> self . mapUnit [ unit ] = uniqueUnitHashes [ h ] <EOL> else : <EOL> uniqueUnitHashes [ h ] = unit <EOL> self . modelXbrl . profileActivity ( "<STR_LIT>" , minTimeToShow = <NUM_LIT:1.0> ) <EOL> for baseSetKey in self . modelXbrl . baseSets . keys ( ) : <EOL> arcrole , ELR , linkqname , arcqname = baseSetKey <EOL> if ELR and linkqname and arcqname : <EOL> if arcrole in ( XbrlConst . essenceAlias , XbrlConst . requiresElement ) : <EOL> conceptsSet = { XbrlConst . essenceAlias : self . conceptsInEssencesAlias , <EOL> XbrlConst . requiresElement : self . conceptsInRequiresElement } [ arcrole ] <EOL> for modelRel in self . modelXbrl . relationshipSet ( arcrole , ELR , linkqname , arcqname ) . modelRelationships : <EOL> for concept in ( modelRel . fromModelObject , modelRel . toModelObject ) : <EOL> if concept is not None and concept . qname is not None : <EOL> conceptsSet . add ( concept ) <EOL> self . modelXbrl . profileActivity ( "<STR_LIT>" , minTimeToShow = <NUM_LIT:1.0> ) <EOL> self . bindFacts ( self . modelXbrl . facts , [ self . modelXbrl . modelDocument . xmlRootElement ] ) <EOL> self . modelXbrl . profileActivity ( "<STR_LIT>" , minTimeToShow = <NUM_LIT:1.0> ) <EOL> for baseSetKey in self . modelXbrl . baseSets . keys ( ) : <EOL> arcrole , ELR , linkqname , arcqname = baseSetKey <EOL> if ELR and linkqname and arcqname : <EOL> if arcrole in ( XbrlConst . summationItem , XbrlConst . essenceAlias , XbrlConst . requiresElement ) : <EOL> relsSet = self . modelXbrl . relationshipSet ( arcrole , ELR , linkqname , arcqname ) <EOL> if arcrole == XbrlConst . summationItem : <EOL> fromRelationships = relsSet . fromModelObjects ( ) <EOL> for sumConcept , modelRels in fromRelationships . items ( ) : <EOL> sumBindingKeys = self . sumConceptBindKeys [ sumConcept ] <EOL> dupBindingKeys = set ( ) <EOL> boundSumKeys = set ( ) <EOL> for modelRel in modelRels : <EOL> itemConcept = modelRel . toModelObject <EOL> if itemConcept is not None and itemConcept . qname is not None : <EOL> itemBindingKeys = self . itemConceptBindKeys [ itemConcept ] <EOL> boundSumKeys |= sumBindingKeys & itemBindingKeys <EOL> boundSums = defaultdict ( decimal . Decimal ) <EOL> boundSummationItems = defaultdict ( list ) <EOL> for modelRel in modelRels : <EOL> weight = modelRel . weightDecimal <EOL> itemConcept = modelRel . toModelObject <EOL> if itemConcept is not None : <EOL> for itemBindKey in boundSumKeys : <EOL> ancestor , contextHash , unit = itemBindKey <EOL> factKey = ( itemConcept , ancestor , contextHash , unit ) <EOL> if factKey in self . itemFacts : <EOL> for fact in self . itemFacts [ factKey ] : <EOL> if fact in self . duplicatedFacts : <EOL> dupBindingKeys . add ( itemBindKey ) <EOL> else : <EOL> roundedValue = roundFact ( fact , self . inferDecimals ) <EOL> boundSums [ itemBindKey ] += roundedValue * weight <EOL> boundSummationItems [ itemBindKey ] . append ( wrappedFactWithWeight ( fact , weight , roundedValue ) ) <EOL> for sumBindKey in boundSumKeys : <EOL> ancestor , contextHash , unit = sumBindKey <EOL> factKey = ( sumConcept , ancestor , contextHash , unit ) <EOL> if factKey in self . sumFacts : <EOL> sumFacts = self . sumFacts [ factKey ] <EOL> for fact in sumFacts : <EOL> if fact in self . duplicatedFacts : <EOL> dupBindingKeys . add ( sumBindKey ) <EOL> elif sumBindKey not in dupBindingKeys : <EOL> roundedSum = roundFact ( fact , self . inferDecimals ) <EOL> roundedItemsSum = roundFact ( fact , self . inferDecimals , vDecimal = boundSums [ sumBindKey ] ) <EOL> if roundedItemsSum != roundFact ( fact , self . inferDecimals ) : <EOL> d = inferredDecimals ( fact ) <EOL> if isnan ( d ) or isinf ( d ) : d = <NUM_LIT:4> <EOL> _boundSummationItems = boundSummationItems [ sumBindKey ] <EOL> unreportedContribingItemQnames = [ ] <EOL> for modelRel in modelRels : <EOL> itemConcept = modelRel . toModelObject <EOL> if ( itemConcept is not None and <EOL> ( itemConcept , ancestor , contextHash , unit ) not in self . itemFacts ) : <EOL> unreportedContribingItemQnames . append ( str ( itemConcept . qname ) ) <EOL> self . modelXbrl . log ( '<STR_LIT>' , "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = wrappedSummationAndItems ( fact , roundedSum , _boundSummationItems ) , <EOL> concept = sumConcept . qname , linkrole = ELR , <EOL> linkroleDefinition = self . modelXbrl . roleTypeDefinition ( ELR ) , <EOL> reportedSum = Locale . format_decimal ( self . modelXbrl . locale , roundedSum , <NUM_LIT:1> , max ( d , <NUM_LIT:0> ) ) , <EOL> computedSum = Locale . format_decimal ( self . modelXbrl . locale , roundedItemsSum , <NUM_LIT:1> , max ( d , <NUM_LIT:0> ) ) , <EOL> contextID = fact . context . id , unitID = fact . unit . id , <EOL> unreportedContributors = "<STR_LIT:U+002CU+0020>" . join ( unreportedContribingItemQnames ) or "<STR_LIT:none>" ) <EOL> del unreportedContribingItemQnames [ : ] <EOL> boundSummationItems . clear ( ) <EOL> elif arcrole == XbrlConst . essenceAlias : <EOL> for modelRel in relsSet . modelRelationships : <EOL> essenceConcept = modelRel . fromModelObject <EOL> aliasConcept = modelRel . toModelObject <EOL> essenceBindingKeys = self . esAlConceptBindKeys [ essenceConcept ] <EOL> aliasBindingKeys = self . esAlConceptBindKeys [ aliasConcept ] <EOL> for esAlBindKey in essenceBindingKeys & aliasBindingKeys : <EOL> ancestor , contextHash = esAlBindKey <EOL> essenceFactsKey = ( essenceConcept , ancestor , contextHash ) <EOL> aliasFactsKey = ( aliasConcept , ancestor , contextHash ) <EOL> if essenceFactsKey in self . esAlFacts and aliasFactsKey in self . esAlFacts : <EOL> for eF in self . esAlFacts [ essenceFactsKey ] : <EOL> for aF in self . esAlFacts [ aliasFactsKey ] : <EOL> essenceUnit = self . mapUnit . get ( eF . unit , eF . unit ) <EOL> aliasUnit = self . mapUnit . get ( aF . unit , aF . unit ) <EOL> if essenceUnit != aliasUnit : <EOL> self . modelXbrl . log ( '<STR_LIT>' , "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = ( modelRel , eF , aF ) , <EOL> essenceConcept = essenceConcept . qname , aliasConcept = aliasConcept . qname , <EOL> linkrole = ELR , <EOL> linkroleDefinition = self . modelXbrl . roleTypeDefinition ( ELR ) , <EOL> contextID = eF . context . id ) <EOL> if not XbrlUtil . vEqual ( eF , aF ) : <EOL> self . modelXbrl . log ( '<STR_LIT>' , "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = ( modelRel , eF , aF ) , <EOL> essenceConcept = essenceConcept . qname , aliasConcept = aliasConcept . qname , <EOL> linkrole = ELR , <EOL> linkroleDefinition = self . modelXbrl . roleTypeDefinition ( ELR ) , <EOL> contextID = eF . context . id ) <EOL> elif arcrole == XbrlConst . requiresElement : <EOL> for modelRel in relsSet . modelRelationships : <EOL> sourceConcept = modelRel . fromModelObject <EOL> requiredConcept = modelRel . toModelObject <EOL> if sourceConcept in self . requiresElementFacts and not requiredConcept in self . requiresElementFacts : <EOL> self . modelXbrl . log ( '<STR_LIT>' , "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = sourceConcept , <EOL> requiringConcept = sourceConcept . qname , requiredConcept = requiredConcept . qname , <EOL> linkrole = ELR , <EOL> linkroleDefinition = self . modelXbrl . roleTypeDefinition ( ELR ) ) <EOL> self . modelXbrl . profileActivity ( "<STR_LIT>" , minTimeToShow = <NUM_LIT:1.0> ) <EOL> self . modelXbrl . profileActivity ( ) <EOL> def bindFacts ( self , facts , ancestors ) : <EOL> for f in facts : <EOL> concept = f . concept <EOL> if concept is not None : <EOL> if concept . isNumeric : <EOL> for ancestor in ancestors : <EOL> context = self . mapContext . get ( f . context , f . context ) <EOL> contextHash = context . contextNonDimAwareHash if context is not None else hash ( None ) <EOL> unit = self . mapUnit . get ( f . unit , f . unit ) <EOL> calcKey = ( concept , ancestor , contextHash , unit ) <EOL> if not f . isNil : <EOL> self . itemFacts [ calcKey ] . append ( f ) <EOL> bindKey = ( ancestor , contextHash , unit ) <EOL> self . itemConceptBindKeys [ concept ] . add ( bindKey ) <EOL> if not f . isNil : <EOL> self . sumFacts [ calcKey ] . append ( f ) <EOL> self . sumConceptBindKeys [ concept ] . add ( bindKey ) <EOL> if calcKey in self . duplicateKeyFacts : <EOL> self . duplicatedFacts . add ( f ) <EOL> self . duplicatedFacts . add ( self . duplicateKeyFacts [ calcKey ] ) <EOL> else : <EOL> self . duplicateKeyFacts [ calcKey ] = f <EOL> elif concept . isTuple : <EOL> self . bindFacts ( f . modelTupleFacts , ancestors + [ f ] ) <EOL> if concept in self . conceptsInEssencesAlias and not f . isNil : <EOL> ancestor = ancestors [ - <NUM_LIT:1> ] <EOL> context = self . mapContext . get ( f . context , f . context ) <EOL> contextHash = context . contextNonDimAwareHash if context is not None else hash ( None ) <EOL> esAlKey = ( concept , ancestor , contextHash ) <EOL> self . esAlFacts [ esAlKey ] . append ( f ) <EOL> bindKey = ( ancestor , contextHash ) <EOL> self . esAlConceptBindKeys [ concept ] . add ( bindKey ) <EOL> if concept in self . conceptsInRequiresElement : <EOL> self . requiresElementFacts [ concept ] . append ( f ) <EOL> def roundFact ( fact , inferDecimals = False , vDecimal = None ) : <EOL> if vDecimal is None : <EOL> vStr = fact . value <EOL> try : <EOL> vDecimal = decimal . Decimal ( vStr ) <EOL> vFloatFact = float ( vStr ) <EOL> except ( decimal . InvalidOperation , ValueError ) : <EOL> vDecimal = NaN <EOL> vFloatFact = floatNaN <EOL> else : <EOL> if vDecimal . is_nan ( ) : <EOL> return vDecimal <EOL> vStr = None <EOL> try : <EOL> vFloatFact = float ( fact . value ) <EOL> except ValueError : <EOL> vFloatFact = floatNaN <EOL> dStr = fact . decimals <EOL> pStr = fact . precision <EOL> if dStr == "<STR_LIT>" or pStr == "<STR_LIT>" : <EOL> vRounded = vDecimal <EOL> elif inferDecimals : <EOL> if pStr : <EOL> p = int ( pStr ) <EOL> if p == <NUM_LIT:0> : <EOL> vRounded = NaN <EOL> elif vDecimal == <NUM_LIT:0> : <EOL> vRounded = ZERO <EOL> else : <EOL> vAbs = fabs ( vFloatFact ) <EOL> d = p - int ( floor ( log10 ( vAbs ) ) ) - <NUM_LIT:1> <EOL> vRounded = decimalRound ( vDecimal , d , decimal . ROUND_HALF_EVEN ) <EOL> elif dStr : <EOL> d = int ( dStr ) <EOL> vRounded = decimalRound ( vDecimal , d , decimal . ROUND_HALF_EVEN ) <EOL> else : <EOL> vRounded = vDecimal <EOL> else : <EOL> if dStr : <EOL> match = numberPattern . match ( vStr if vStr else str ( vDecimal ) ) <EOL> if match : <EOL> nonZeroInt , period , zeroDec , nonZeroDec , e , exp = match . groups ( ) <EOL> p = ( len ( nonZeroInt ) if nonZeroInt and ( len ( nonZeroInt ) ) > <NUM_LIT:0> else - len ( zeroDec ) ) + ( int ( exp ) if exp and ( len ( exp ) > <NUM_LIT:0> ) else <NUM_LIT:0> ) + ( int ( dStr ) ) <EOL> else : <EOL> p = <NUM_LIT:0> <EOL> elif pStr : <EOL> p = int ( pStr ) <EOL> else : <EOL> p = None <EOL> if p == <NUM_LIT:0> : <EOL> vRounded = NaN <EOL> elif vDecimal == <NUM_LIT:0> : <EOL> vRounded = vDecimal <EOL> elif p is not None : <EOL> vAbs = vDecimal . copy_abs ( ) <EOL> log = vAbs . log10 ( ) <EOL> d = p - int ( log ) - ( <NUM_LIT:1> if vAbs >= <NUM_LIT:1> else <NUM_LIT:0> ) <EOL> vRounded = decimalRound ( vDecimal , d , decimal . ROUND_HALF_UP ) <EOL> else : <EOL> vRounded = vDecimal <EOL> return vRounded <EOL> def decimalRound ( x , d , rounding ) : <EOL> if x . is_normal ( ) and - <NUM_LIT> <= d <= <NUM_LIT> : <EOL> if d >= <NUM_LIT:0> : <EOL> return x . quantize ( ONE . scaleb ( - d ) , rounding ) <EOL> else : <EOL> return x . scaleb ( d ) . quantize ( ONE , rounding ) . scaleb ( - d ) <EOL> return x <EOL> def inferredPrecision ( fact ) : <EOL> vStr = fact . value <EOL> dStr = fact . decimals <EOL> pStr = fact . precision <EOL> if dStr == "<STR_LIT>" or pStr == "<STR_LIT>" : <EOL> return floatINF <EOL> try : <EOL> vFloat = float ( vStr ) <EOL> if dStr : <EOL> match = numberPattern . match ( vStr if vStr else str ( vFloat ) ) <EOL> if match : <EOL> nonZeroInt , period , zeroDec , nonZeroDec , e , exp = match . groups ( ) <EOL> p = ( len ( nonZeroInt ) if nonZeroInt else ( - len ( zeroDec ) if nonZeroDec else <NUM_LIT:0> ) ) + ( int ( exp ) if exp else <NUM_LIT:0> ) + ( int ( dStr ) ) <EOL> if p < <NUM_LIT:0> : <EOL> p = <NUM_LIT:0> <EOL> else : <EOL> p = <NUM_LIT:0> <EOL> else : <EOL> return int ( pStr ) <EOL> except ValueError : <EOL> return floatNaN <EOL> if p == <NUM_LIT:0> : <EOL> return <NUM_LIT:0> <EOL> elif vFloat == <NUM_LIT:0> : <EOL> return <NUM_LIT:0> <EOL> else : <EOL> return p <EOL> def inferredDecimals ( fact ) : <EOL> vStr = fact . value <EOL> dStr = fact . decimals <EOL> pStr = fact . precision <EOL> if dStr == "<STR_LIT>" or pStr == "<STR_LIT>" : <EOL> return floatINF <EOL> try : <EOL> if pStr : <EOL> p = int ( pStr ) <EOL> if p == <NUM_LIT:0> : <EOL> return floatNaN <EOL> vFloat = float ( vStr ) <EOL> if vFloat == <NUM_LIT:0> : <EOL> return floatINF <EOL> else : <EOL> vAbs = fabs ( vFloat ) <EOL> return p - int ( floor ( log10 ( vAbs ) ) ) - <NUM_LIT:1> <EOL> elif dStr : <EOL> return int ( dStr ) <EOL> except ValueError : <EOL> pass <EOL> return floatNaN <EOL> def roundValue ( value , precision = None , decimals = None , scale = None ) : <EOL> try : <EOL> vDecimal = decimal . Decimal ( value ) <EOL> if scale : <EOL> iScale = int ( scale ) <EOL> vDecimal = vDecimal . scaleb ( iScale ) <EOL> if precision is not None : <EOL> vFloat = float ( value ) <EOL> if scale : <EOL> vFloat = pow ( vFloat , iScale ) <EOL> except ( decimal . InvalidOperation , ValueError ) : <EOL> return NaN <EOL> if precision is not None : <EOL> if not isinstance ( precision , ( int , float ) ) : <EOL> if precision == "<STR_LIT>" : <EOL> precision = floatINF <EOL> else : <EOL> try : <EOL> precision = int ( precision ) <EOL> except ValueError : <EOL> precision = floatNaN <EOL> if isinf ( precision ) : <EOL> vRounded = vDecimal <EOL> elif precision == <NUM_LIT:0> or isnan ( precision ) : <EOL> vRounded = NaN <EOL> elif vFloat == <NUM_LIT:0> : <EOL> vRounded = ZERO <EOL> else : <EOL> vAbs = fabs ( vFloat ) <EOL> log = log10 ( vAbs ) <EOL> d = precision - int ( log ) - ( <NUM_LIT:1> if vAbs >= <NUM_LIT:1> else <NUM_LIT:0> ) <EOL> vRounded = decimalRound ( vDecimal , d , decimal . ROUND_HALF_UP ) <EOL> elif decimals is not None : <EOL> if not isinstance ( decimals , ( int , float ) ) : <EOL> if decimals == "<STR_LIT>" : <EOL> decimals = floatINF <EOL> else : <EOL> try : <EOL> decimals = int ( decimals ) <EOL> except ValueError : <EOL> decimals = floatNaN <EOL> if isinf ( decimals ) : <EOL> vRounded = vDecimal <EOL> elif isnan ( decimals ) : <EOL> vRounded = NaN <EOL> else : <EOL> vRounded = decimalRound ( vDecimal , decimals , decimal . ROUND_HALF_EVEN ) <EOL> else : <EOL> vRounded = vDecimal <EOL> return vRounded <EOL> def insignificantDigits ( value , precision = None , decimals = None , scale = None ) : <EOL> try : <EOL> vDecimal = decimal . Decimal ( value ) <EOL> if scale : <EOL> iScale = int ( scale ) <EOL> vDecimal = vDecimal . scaleb ( iScale ) <EOL> if precision is not None : <EOL> vFloat = float ( value ) <EOL> if scale : <EOL> vFloat = pow ( vFloat , iScale ) <EOL> except ( decimal . InvalidOperation , ValueError ) : <EOL> return None <EOL> if precision is not None : <EOL> if not isinstance ( precision , ( int , float ) ) : <EOL> if precision == "<STR_LIT>" : <EOL> return None <EOL> else : <EOL> try : <EOL> precision = int ( precision ) <EOL> except ValueError : <EOL> return None <EOL> if isinf ( precision ) or precision == <NUM_LIT:0> or isnan ( precision ) or vFloat == <NUM_LIT:0> : <EOL> return None <EOL> else : <EOL> vAbs = fabs ( vFloat ) <EOL> log = log10 ( vAbs ) <EOL> decimals = precision - int ( log ) - ( <NUM_LIT:1> if vAbs >= <NUM_LIT:1> else <NUM_LIT:0> ) <EOL> elif decimals is not None : <EOL> if not isinstance ( decimals , ( int , float ) ) : <EOL> if decimals == "<STR_LIT>" : <EOL> return None <EOL> else : <EOL> try : <EOL> decimals = int ( decimals ) <EOL> except ValueError : <EOL> return None <EOL> if isinf ( decimals ) or isnan ( decimals ) : <EOL> return None <EOL> else : <EOL> return None <EOL> if vDecimal . is_normal ( ) and - <NUM_LIT> <= decimals <= <NUM_LIT> : <EOL> if decimals > <NUM_LIT:0> : <EOL> divisor = ONE . scaleb ( - decimals ) <EOL> else : <EOL> divisor = ONE . scaleb ( - decimals ) . quantize ( ONE , decimal . ROUND_HALF_UP ) <EOL> insignificantDigits = abs ( vDecimal ) % divisor <EOL> if insignificantDigits : <EOL> return ( vDecimal // divisor * divisor , <EOL> insignificantDigits ) <EOL> return None <EOL> def wrappedFactWithWeight ( fact , weight , roundedValue ) : <EOL> return ObjectPropertyViewWrapper ( fact , ( ( "<STR_LIT>" , weight ) , ( "<STR_LIT>" , roundedValue ) ) ) <EOL> def wrappedSummationAndItems ( fact , roundedSum , boundSummationItems ) : <EOL> '''<STR_LIT>''' <EOL> sha256 = hashlib . sha256 ( ) <EOL> for b in sorted ( boundSummationItems , key = lambda b : b . modelObject . qname ) : <EOL> sha256 . update ( b . modelObject . qname . namespaceURI . encode ( '<STR_LIT:utf-8>' , '<STR_LIT:replace>' ) ) <EOL> sha256 . update ( b . modelObject . qname . localName . encode ( '<STR_LIT:utf-8>' , '<STR_LIT:replace>' ) ) <EOL> sha256 . update ( str ( b . extraProperties [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) . encode ( '<STR_LIT:utf-8>' , '<STR_LIT:replace>' ) ) <EOL> itemValuesHash = sha256 . hexdigest ( ) <EOL> sha256 = hashlib . sha256 ( ) <EOL> sha256 . update ( fact . qname . namespaceURI . encode ( '<STR_LIT:utf-8>' , '<STR_LIT:replace>' ) ) <EOL> sha256 . update ( fact . qname . localName . encode ( '<STR_LIT:utf-8>' , '<STR_LIT:replace>' ) ) <EOL> sha256 . update ( str ( roundedSum ) . encode ( '<STR_LIT:utf-8>' , '<STR_LIT:replace>' ) ) <EOL> sumValueHash = sha256 . hexdigest ( ) <EOL> return [ ObjectPropertyViewWrapper ( fact , <EOL> ( ( "<STR_LIT>" , sumValueHash ) , <EOL> ( "<STR_LIT>" , itemValuesHash ) , <EOL> ( "<STR_LIT>" , roundedSum ) ) ) ] + boundSummationItems </s>
|
<s> '''<STR_LIT>''' <EOL> from tkinter import * <EOL> try : <EOL> from tkinter . ttk import * <EOL> except ImportError : <EOL> from ttk import * <EOL> from arelle . CntlrWinTooltip import ToolTip <EOL> class ViewPane : <EOL> def __init__ ( self , modelXbrl , tabWin , tabTitle , <EOL> contentView , hasToolTip = False , lang = None ) : <EOL> self . blockViewModelObject = <NUM_LIT:0> <EOL> self . tabWin = tabWin <EOL> self . viewFrame = contentView <EOL> self . viewFrame . view = self <EOL> tabWin . add ( self . viewFrame , text = tabTitle ) <EOL> self . modelXbrl = modelXbrl <EOL> self . hasToolTip = hasToolTip <EOL> self . toolTipText = StringVar ( ) <EOL> if hasToolTip : <EOL> self . toolTipText = StringVar ( ) <EOL> self . toolTip = ToolTip ( self . gridBody , <EOL> textvariable = self . toolTipText , <EOL> wraplength = <NUM_LIT> , <EOL> follow_mouse = True , <EOL> state = "<STR_LIT>" ) <EOL> self . toolTipColId = None <EOL> self . toolTipRowId = None <EOL> self . modelXbrl = modelXbrl <EOL> modelManager = self . modelXbrl . modelManager <EOL> self . contextMenuClick = modelManager . cntlr . contextMenuClick <EOL> self . lang = lang <EOL> if modelXbrl : <EOL> modelXbrl . views . append ( self ) <EOL> if not lang : <EOL> self . lang = modelXbrl . modelManager . defaultLang <EOL> def close ( self ) : <EOL> del self . viewFrame . view <EOL> self . tabWin . forget ( self . viewFrame ) <EOL> if self in self . modelXbrl . views : <EOL> self . modelXbrl . views . remove ( self ) <EOL> self . modelXbrl = None <EOL> def select ( self ) : <EOL> self . tabWin . select ( self . viewFrame ) <EOL> def onClick ( self , * args ) : <EOL> if self . modelXbrl : <EOL> self . modelXbrl . modelManager . cntlr . currentView = self <EOL> def leave ( self , * args ) : <EOL> self . toolTipColId = None <EOL> self . toolTipRowId = None <EOL> def motion ( self , * args ) : <EOL> pass <EOL> def contextMenu ( self ) : <EOL> try : <EOL> return self . menu <EOL> except AttributeError : <EOL> self . menu = Menu ( self . viewFrame , tearoff = <NUM_LIT:0> ) <EOL> return self . menu <EOL> def bindContextMenu ( self , widget ) : <EOL> if not widget . bind ( self . contextMenuClick ) : <EOL> widget . bind ( self . contextMenuClick , self . popUpMenu ) <EOL> def popUpMenu ( self , event ) : <EOL> self . menu . post ( event . x_root , event . y_root ) <EOL> def menuAddLangs ( self ) : <EOL> langsMenu = Menu ( self . viewFrame , tearoff = <NUM_LIT:0> ) <EOL> self . menu . add_cascade ( label = _ ( "<STR_LIT>" ) , menu = langsMenu , underline = <NUM_LIT:0> ) <EOL> for lang in sorted ( self . modelXbrl . langs ) : <EOL> langsMenu . add_cascade ( label = lang , underline = <NUM_LIT:0> , <EOL> command = lambda l = lang : self . setLang ( l ) ) <EOL> def setLang ( self , lang ) : <EOL> self . lang = lang <EOL> self . view ( ) </s>
|
<s> '''<STR_LIT>''' <EOL> import os , sys , re <EOL> from lxml import etree , html <EOL> from openpyxl . workbook import Workbook <EOL> from openpyxl . worksheet import ColumnDimension <EOL> from openpyxl . cell import get_column_letter <EOL> from openpyxl . style import Alignment <EOL> class Report ( ) : <EOL> def __init__ ( self , longName , shortName , htmlFileName ) : <EOL> self . longName = longName <EOL> self . shortName = shortName <EOL> self . htmlFileName = htmlFileName <EOL> def __repr__ ( self ) : <EOL> return ( "<STR_LIT>" <EOL> . format ( self . longName , self . shortName , self . htmlFileName ) ) <EOL> def intCol ( elt , attrName , default = None ) : <EOL> try : <EOL> return int ( elt . get ( attrName , default ) ) <EOL> except ( TypeError , ValueError ) : <EOL> return default <EOL> numberPattern = re . compile ( r"<STR_LIT>" ) <EOL> displayNonePattern = re . compile ( r"<STR_LIT>" ) <EOL> def saveTableToExelle ( rFilesDir ) : <EOL> reports = [ ] <EOL> try : <EOL> fsdoc = etree . parse ( os . path . join ( rFilesDir , "<STR_LIT>" ) ) <EOL> for rElt in fsdoc . iter ( tag = "<STR_LIT>" ) : <EOL> reports . append ( Report ( rElt . findtext ( "<STR_LIT>" ) , <EOL> rElt . findtext ( "<STR_LIT>" ) , <EOL> rElt . findtext ( "<STR_LIT>" ) ) ) <EOL> except ( EnvironmentError , <EOL> etree . LxmlError ) as err : <EOL> print ( "<STR_LIT>" . format ( rFilesDir , err ) ) <EOL> wb = Workbook ( encoding = '<STR_LIT:utf-8>' ) <EOL> for sheetName in wb . get_sheet_names ( ) : <EOL> ws = wb . get_sheet_by_name ( sheetName ) <EOL> if ws is not None : <EOL> wb . remove_sheet ( ws ) <EOL> sheetNames = set ( ) <EOL> for reportNum , report in enumerate ( reports ) : <EOL> sheetName = report . shortName [ : <NUM_LIT> ] <EOL> if sheetName in sheetNames : <EOL> sheetName = sheetName [ : <NUM_LIT> - len ( str ( reportNum ) ) ] + str ( reportNum ) <EOL> sheetNames . add ( sheetName ) <EOL> ws = wb . create_sheet ( title = sheetName ) <EOL> try : <EOL> rdoc = html . parse ( os . path . join ( rFilesDir , report . htmlFileName ) ) <EOL> row = - <NUM_LIT:1> <EOL> mergedAreas = { } <EOL> for tableElt in rdoc . iter ( tag = "<STR_LIT>" ) : <EOL> if tableElt . get ( "<STR_LIT:class>" ) == "<STR_LIT>" : <EOL> continue <EOL> if tableElt . getparent ( ) . tag == "<STR_LIT>" : <EOL> style = tableElt . getparent ( ) . get ( "<STR_LIT>" ) <EOL> if style and displayNonePattern . match ( style ) : <EOL> continue <EOL> colWidths = { } <EOL> for rowNum , trElt in enumerate ( tableElt . iter ( tag = "<STR_LIT>" ) ) : <EOL> for mergeCol in [ col <EOL> for col , mergedArea in mergedAreas . items ( ) <EOL> if mergedArea [ <NUM_LIT:1> ] > rowNum ] : <EOL> del mergedAreas [ mergeCol ] <EOL> col = <NUM_LIT:0> <EOL> for coltag in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> for cellElt in trElt . iter ( tag = coltag ) : <EOL> if col == <NUM_LIT:0> : <EOL> row += <NUM_LIT:1> <EOL> if col in mergedAreas : <EOL> col += mergedAreas [ col ] [ <NUM_LIT:0> ] - <NUM_LIT:1> <EOL> text = cellElt . text_content ( ) <EOL> colspan = intCol ( cellElt , "<STR_LIT>" , <NUM_LIT:1> ) <EOL> rowspan = intCol ( cellElt , "<STR_LIT>" , <NUM_LIT:1> ) <EOL> for elt in cellElt . iter ( ) : <EOL> style = elt . get ( "<STR_LIT>" ) <EOL> if style and "<STR_LIT>" in style : <EOL> try : <EOL> kw , sep , width = style . partition ( "<STR_LIT>" ) <EOL> if "<STR_LIT>" in width : <EOL> width , sep , kw = width . partition ( "<STR_LIT>" ) <EOL> width = float ( width ) * <NUM_LIT> <EOL> else : <EOL> width = float ( width ) <EOL> colWidths [ col ] = width <EOL> except ValueError : <EOL> pass <EOL> if rowspan > <NUM_LIT:1> : <EOL> mergedAreas [ col ] = ( colspan , row + rowspan - <NUM_LIT:1> ) <EOL> cell = ws . cell ( row = row , column = col ) <EOL> if text : <EOL> cell . value = text <EOL> if numberPattern . match ( text ) : <EOL> cell . style . alignment . horizontal = Alignment . HORIZONTAL_RIGHT <EOL> else : <EOL> cell . style . alignment . wrap_text = True <EOL> if colspan > <NUM_LIT:1> or rowspan > <NUM_LIT:1> : <EOL> ws . merge_cells ( start_row = row , end_row = row + rowspan - <NUM_LIT:1> , start_column = col , end_column = col + colspan - <NUM_LIT:1> ) <EOL> cell . style . alignment . vertical = Alignment . VERTICAL_TOP <EOL> if coltag == "<STR_LIT>" : <EOL> cell . style . alignment . horizontal = Alignment . HORIZONTAL_CENTER <EOL> cell . style . font . bold = True <EOL> cell . style . font . size = <NUM_LIT:9> <EOL> col += colspan <EOL> for col , width in colWidths . items ( ) : <EOL> ws . column_dimensions [ get_column_letter ( col + <NUM_LIT:1> ) ] . width = width <EOL> except ( EnvironmentError , <EOL> etree . LxmlError ) as err : <EOL> print ( "<STR_LIT>" . format ( report . htmlFileName , rFilesDir , err ) ) <EOL> wb . save ( os . path . join ( rFilesDir , "<STR_LIT>" ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> saveTableToExelle ( r"<STR_LIT>" ) </s>
|
<s> '''<STR_LIT>''' <EOL> def validateTableInfosetMenuEntender ( cntlr , validateMenu ) : <EOL> cntlr . modelManager . generateTableInfoset = cntlr . config . setdefault ( "<STR_LIT>" , False ) <EOL> from tkinter import BooleanVar <EOL> generateTableInfoset = BooleanVar ( value = cntlr . modelManager . generateTableInfoset ) <EOL> def setTableInfosetOption ( * args ) : <EOL> cntlr . config [ "<STR_LIT>" ] = cntlr . modelManager . generateTableInfoset = generateTableInfoset . get ( ) <EOL> generateTableInfoset . trace ( "<STR_LIT:w>" , setTableInfosetOption ) <EOL> validateMenu . add_checkbutton ( label = _ ( "<STR_LIT>" ) , <EOL> underline = <NUM_LIT:0> , <EOL> variable = generateTableInfoset , onvalue = True , offvalue = False ) <EOL> def validateTableInfosetCommandLineOptionExtender ( parser ) : <EOL> parser . add_option ( "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> help = _ ( "<STR_LIT>" ) ) <EOL> def validateTableInfosetCommandLineXbrlLoaded ( cntlr , options , modelXbrl , * args ) : <EOL> cntlr . modelManager . generateTableInfoset = getattr ( options , "<STR_LIT>" , False ) <EOL> def validateTableInfoset ( modelXbrl , resultTableUri ) : <EOL> diffToFile = not getattr ( modelXbrl . modelManager , '<STR_LIT>' , False ) <EOL> from arelle import ViewFileRenderedGrid <EOL> ViewFileRenderedGrid . viewRenderedGrid ( modelXbrl , <EOL> resultTableUri , <EOL> diffToFile = diffToFile ) <EOL> return True <EOL> __pluginInfo__ = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : validateTableInfosetMenuEntender , <EOL> '<STR_LIT>' : validateTableInfosetCommandLineOptionExtender , <EOL> '<STR_LIT>' : validateTableInfosetCommandLineXbrlLoaded , <EOL> '<STR_LIT>' : validateTableInfoset , <EOL> } </s>
|
<s> '''<STR_LIT>''' <EOL> import operator <EOL> from . SphinxContext import HyperspaceBindings , HyperspaceBinding <EOL> from . SphinxParser import ( astFunctionReference , astHyperspaceExpression , astNode , <EOL> astFormulaRule , astReportRule , <EOL> astVariableReference ) <EOL> from . SphinxMethods import ( methodImplementation , functionImplementation , <EOL> aggreateFunctionImplementation , aggreateFunctionAcceptsFactArgs , <EOL> moduleInit as SphinxMethodsModuleInit ) <EOL> from arelle . ModelFormulaObject import Aspect <EOL> from arelle . ModelValue import QName <EOL> from arelle . ModelInstanceObject import ModelFact <EOL> from arelle . ModelXbrl import DEFAULT , NONDEFAULT , DEFAULTorNONDEFAULT <EOL> from arelle import XbrlConst , XmlUtil <EOL> class SphinxException ( Exception ) : <EOL> def __init__ ( self , node , code , message , ** kwargs ) : <EOL> self . node = node <EOL> self . code = code <EOL> self . message = message <EOL> self . kwargs = kwargs <EOL> self . args = ( self . __repr__ ( ) , ) <EOL> def __repr__ ( self ) : <EOL> return _ ( '<STR_LIT>' ) . format ( self . code , self . message % self . kwargs , self . node . sourceFileLine ) <EOL> class SphinxSpecialValue : <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> def __repr__ ( self ) : <EOL> return self . name <EOL> UNBOUND = SphinxSpecialValue ( "<STR_LIT>" ) <EOL> NONE = SphinxSpecialValue ( "<STR_LIT:none>" ) <EOL> def evaluateRuleBase ( sphinxContext ) : <EOL> for constantNode in sphinxContext . constants . values ( ) : <EOL> constantNode . value = None <EOL> clearEvaluation ( sphinxContext ) <EOL> for preconditionNode in sphinxContext . ruleBasePreconditionNodes : <EOL> preconditionPasses = evaluate ( preconditionNode , sphinxContext ) <EOL> clearEvaluation ( sphinxContext ) <EOL> if not preconditionPasses : <EOL> return <EOL> for ruleProg in sphinxContext . rules : <EOL> evaluate ( ruleProg , sphinxContext ) <EOL> clearEvaluation ( sphinxContext ) <EOL> for constantNode in sphinxContext . constants . values ( ) : <EOL> constantNode . value = None <EOL> def clearEvaluation ( sphinxContext ) : <EOL> sphinxContext . tags . clear ( ) <EOL> sphinxContext . localVariables . clear ( ) <EOL> while sphinxContext . hyperspaceBindings : <EOL> sphinxContext . hyperspaceBindings . close ( ) <EOL> def evaluate ( node , sphinxContext , value = False , fallback = None , hsBoundFact = False ) : <EOL> if isinstance ( node , astNode ) : <EOL> if fallback is None : <EOL> result = evaluator [ node . __class__ . __name__ ] ( node , sphinxContext ) <EOL> else : <EOL> try : <EOL> result = evaluator [ node . __class__ . __name__ ] ( node , sphinxContext ) <EOL> except StopIteration : <EOL> if sphinxContext . formulaOptions . traceVariableSetExpressionEvaluation : <EOL> sphinxContext . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , node = str ( node ) ) <EOL> return fallback <EOL> if sphinxContext . formulaOptions . traceVariableSetExpressionEvaluation : <EOL> sphinxContext . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , node = str ( node ) , value = result ) <EOL> if result is not None : <EOL> if isinstance ( result , HyperspaceBinding ) : <EOL> if hsBoundFact : <EOL> return result . yieldedFact <EOL> elif value : <EOL> return result . value <EOL> if ( value or hsBoundFact ) and isinstance ( result , astNode ) : <EOL> return evaluate ( result , sphinxContext , value , fallback , hsBoundFact ) <EOL> return result <EOL> return result <EOL> elif isinstance ( node , ( tuple , list ) ) : <EOL> return [ evaluate ( item , sphinxContext , value , fallback , hsBoundFact ) <EOL> for item in node ] <EOL> elif isinstance ( node , set ) : <EOL> return set ( evaluate ( item , sphinxContext , value , fallback , hsBoundFact ) <EOL> for item in node ) <EOL> else : <EOL> return node <EOL> def evaluateAnnotationDeclaration ( node , sphinxContext ) : <EOL> return None <EOL> def evaluateBinaryOperation ( node , sphinxContext ) : <EOL> leftValue = evaluate ( node . leftExpr , sphinxContext , value = True , fallback = UNBOUND ) <EOL> rightValue = evaluate ( node . rightExpr , sphinxContext , value = True , fallback = UNBOUND ) <EOL> op = node . op <EOL> if sphinxContext . formulaOptions . traceVariableExpressionEvaluation : <EOL> sphinxContext . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , op = op , leftValue = leftValue , rightValue = rightValue ) <EOL> if op == "<STR_LIT>" : <EOL> if sphinxContext . ruleNode . bind == "<STR_LIT:left>" : <EOL> if rightValue is UNBOUND : raise StopIteration <EOL> elif sphinxContext . ruleNode . bind == "<STR_LIT:right>" : <EOL> if leftValue is UNBOUND : raise StopIteration <EOL> elif sphinxContext . ruleNode . bind == "<STR_LIT>" : <EOL> if leftValue is UNBOUND and rightValue is UNBOUND : raise StopIteration <EOL> else : <EOL> if leftValue is UNBOUND or rightValue is UNBOUND : raise StopIteration <EOL> return ( leftValue , rightValue ) <EOL> elif op in { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:+>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:->" } : <EOL> if leftValue is UNBOUND : <EOL> if op [ <NUM_LIT:0> ] == '<STR_LIT:|>' : <EOL> raise StopIteration <EOL> else : <EOL> leftValue = <NUM_LIT:0> <EOL> if rightValue is UNBOUND : <EOL> if op [ - <NUM_LIT:1> ] == '<STR_LIT:|>' : <EOL> raise StopIteration <EOL> else : <EOL> rightValue = <NUM_LIT:0> <EOL> else : <EOL> if leftValue is UNBOUND : <EOL> return UNBOUND <EOL> if rightValue is UNBOUND : <EOL> if op == "<STR_LIT>" and leftValue : <EOL> return True <EOL> return UNBOUND <EOL> if op == "<STR_LIT:/>" and rightValue == <NUM_LIT:0> : <EOL> return UNBOUND <EOL> try : <EOL> result = { '<STR_LIT:+>' : operator . add , '<STR_LIT:->' : operator . sub , '<STR_LIT:*>' : operator . mul , '<STR_LIT:/>' : operator . truediv , <EOL> '<STR_LIT:<>' : operator . lt , '<STR_LIT:>>' : operator . gt , '<STR_LIT>' : operator . le , '<STR_LIT>' : operator . ge , <EOL> '<STR_LIT>' : operator . eq , '<STR_LIT>' : operator . ne , <EOL> '<STR_LIT>' : operator . and_ , '<STR_LIT>' : operator . or_ , <EOL> } [ op ] ( leftValue , rightValue ) <EOL> return result <EOL> except KeyError : <EOL> sphinxContext . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , op = op , node = str ( node ) ) <EOL> except ( TypeError , ZeroDivisionError ) as err : <EOL> sphinxContext . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , op = op , node = str ( node ) , error = str ( err ) ) <EOL> return None <EOL> def evaluateConstant ( node , sphinxContext ) : <EOL> if node . value is None : <EOL> hsBindings = HyperspaceBindings ( sphinxContext ) <EOL> previousLocalVariables = sphinxContext . localVariables <EOL> sphinxContext . localVariables = { } <EOL> node . value = evaluate ( node . expr , sphinxContext ) <EOL> if sphinxContext . formulaOptions . traceVariableSetExpressionEvaluation : <EOL> sphinxContext . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , name = node . constantName , value = node . value ) <EOL> hsBindings . close ( ) <EOL> sphinxContext . localVariables = previousLocalVariables <EOL> return node . value <EOL> def evaluateFor ( node , sphinxContext ) : <EOL> hsBindings = sphinxContext . hyperspaceBindings <EOL> forBinding = hsBindings . forBinding ( node ) <EOL> sphinxContext . localVariables [ node . name ] = forBinding . yieldedValue <EOL> return evaluate ( node . expr , sphinxContext ) <EOL> def evaluateFunctionDeclaration ( node , sphinxContext , args ) : <EOL> overriddenVariables = { } <EOL> if isinstance ( args , dict ) : <EOL> argDict = dict ( ( name , value ) <EOL> for name , value in args . items ( ) <EOL> if name in node . params ) <EOL> else : <EOL> if len ( args ) != len ( node . params ) : <EOL> sphinxContext . modelXbrl . log ( "<STR_LIT>" , "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , <EOL> name = node . name , required = len ( node . params ) , provided = len ( args ) ) <EOL> return None <EOL> argDict = dict ( ( paramName , args [ i ] ) <EOL> for i , paramName in enumerate ( node . params ) ) <EOL> for name , value in argDict . items ( ) : <EOL> if name in sphinxContext . localVariables : <EOL> overriddenVariables [ name ] = sphinxContext . localVariables [ name ] <EOL> sphinxContext . localVariables [ name ] = value <EOL> def clearFunctionArgs ( ) : <EOL> for name in argDict . keys ( ) : <EOL> del sphinxContext . localVariables [ name ] <EOL> sphinxContext . localVariables . update ( overriddenVariables ) <EOL> overriddenVariables . clear ( ) <EOL> try : <EOL> result = evaluate ( node . expr , sphinxContext ) <EOL> clearFunctionArgs ( ) <EOL> return result <EOL> except StopIteration as ex : <EOL> clearFunctionArgs ( ) <EOL> raise ex <EOL> def evaluateFunctionReference ( node , sphinxContext ) : <EOL> name = node . name <EOL> if name in ( "<STR_LIT:error>" , "<STR_LIT>" , "<STR_LIT:info>" , "<STR_LIT>" ) : <EOL> sphinxContext . dynamicSeverity = node . name <EOL> elif name == "<STR_LIT>" : <EOL> return UNBOUND <EOL> if name in aggreateFunctionImplementation : <EOL> return evaluateAggregateFunction ( node , sphinxContext , name ) <EOL> if name in sphinxContext . functions : <EOL> resolveValues = sphinxContext . functions [ name ] . functionType == "<STR_LIT>" <EOL> namedParametersAssignedTo = sphinxContext . localVariables <EOL> else : <EOL> resolveValues = True <EOL> if name in ( "<STR_LIT:error>" , "<STR_LIT>" , "<STR_LIT:info>" , "<STR_LIT>" ) : <EOL> namedParametersAssignedTo = sphinxContext . tags <EOL> else : <EOL> namedParametersAssignedTo = sphinxContext . localVariables <EOL> for localVar in node . localVariables : <EOL> evaluate ( localVar , sphinxContext ) <EOL> args = [ ] <EOL> tagName = None <EOL> l = len ( node . args ) <EOL> for i in range ( l ) : <EOL> arg = node . args [ i ] <EOL> if arg == "<STR_LIT:=>" : <EOL> if i > <NUM_LIT:0> : <EOL> tagName = node . args [ i - <NUM_LIT:1> ] <EOL> elif i == l - <NUM_LIT:1> or node . args [ i + <NUM_LIT:1> ] != "<STR_LIT:=>" : <EOL> if resolveValues : <EOL> arg = evaluate ( arg , sphinxContext , value = True ) <EOL> elif ( isinstance ( arg , astVariableReference ) and <EOL> getattr ( sphinxContext . localVariables . get ( arg . variableName ) , <EOL> "<STR_LIT>" , False ) ) : <EOL> arg = sphinxContext . localVariables [ arg . variableName ] <EOL> elif isinstance ( arg , astNode ) : <EOL> arg . isMacroParameter = True <EOL> args . append ( arg ) <EOL> if tagName : <EOL> namedParametersAssignedTo [ tagName ] = arg <EOL> tagName = None <EOL> if name in ( "<STR_LIT:error>" , "<STR_LIT>" , "<STR_LIT:info>" , "<STR_LIT>" ) : <EOL> result = None <EOL> elif name in sphinxContext . functions : <EOL> result = evaluateFunctionDeclaration ( sphinxContext . functions [ name ] , sphinxContext , args ) <EOL> elif name in functionImplementation : <EOL> result = functionImplementation [ name ] ( node , sphinxContext , args ) <EOL> else : <EOL> raise SphinxException ( node , <EOL> "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> name = name ) <EOL> for localVar in node . localVariables : <EOL> del sphinxContext . localVariables [ localVar . name ] <EOL> return result <EOL> def evaluateAggregateFunction ( node , sphinxContext , name ) : <EOL> args = [ ] <EOL> iterateAbove , bindingsLen = getattr ( node , "<STR_LIT>" , ( None , None ) ) <EOL> firstTime = bindingsLen is None <EOL> hsBindings = sphinxContext . hyperspaceBindings <EOL> parentAggregationNode = hsBindings . aggregationNode <EOL> parentIsValuesIteration = hsBindings . isValuesIteration <EOL> hsBindings . aggregationNode = node <EOL> hsBindings . isValuesIteration = False <EOL> prevHsBindingsLen = len ( hsBindings . hyperspaceBindings ) <EOL> hsBoundFact = aggreateFunctionAcceptsFactArgs [ name ] <EOL> arg = node . args [ <NUM_LIT:0> ] <EOL> try : <EOL> while ( True ) : <EOL> for localVar in node . localVariables : <EOL> evaluate ( localVar , sphinxContext ) <EOL> value = evaluate ( arg , sphinxContext , value = True , hsBoundFact = hsBoundFact ) <EOL> if isinstance ( value , ( list , set ) ) : <EOL> for listArg in value : <EOL> if value is not UNBOUND : <EOL> args . append ( evaluate ( listArg , sphinxContext , value = True ) ) <EOL> elif value is not UNBOUND : <EOL> args . append ( value ) <EOL> if firstTime : <EOL> if len ( hsBindings . hyperspaceBindings ) == prevHsBindingsLen : <EOL> break <EOL> else : <EOL> firstTime = False <EOL> iterateAbove = prevHsBindingsLen - <NUM_LIT:1> <EOL> bindingsLen = len ( hsBindings . hyperspaceBindings ) <EOL> node . aggregationHsBindings = ( iterateAbove , bindingsLen ) <EOL> hsBindings . next ( iterateAbove , bindingsLen ) <EOL> except StopIteration : <EOL> pass <EOL> hsBindings . isValuesIteration = parentIsValuesIteration <EOL> hsBindings . aggregationNode = parentAggregationNode <EOL> for localVar in node . localVariables : <EOL> if localVar in sphinxContext . localVariables : <EOL> del sphinxContext . localVariables [ localVar . name ] <EOL> if sphinxContext . formulaOptions . traceVariableExpressionEvaluation : <EOL> sphinxContext . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , name = name , <EOL> args = "<STR_LIT:U+002C>" . join ( str ( a ) for a in args ) ) <EOL> try : <EOL> return aggreateFunctionImplementation [ name ] ( node , sphinxContext , args ) <EOL> except ( TypeError , ZeroDivisionError ) as err : <EOL> sphinxContext . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , name = name , node = str ( node ) , error = str ( err ) ) <EOL> return None <EOL> def evaluateHyperspaceExpression ( node , sphinxContext ) : <EOL> hsBindings = sphinxContext . hyperspaceBindings <EOL> nodeBinding = hsBindings . nodeBinding ( node ) <EOL> return nodeBinding <EOL> def evaluateIf ( node , sphinxContext ) : <EOL> condition = evaluate ( node . condition , sphinxContext , value = True ) <EOL> if condition : <EOL> expr = node . thenExpr <EOL> else : <EOL> expr = node . elseExpr <EOL> return evaluate ( expr , sphinxContext ) <EOL> def evaluateMessage ( node , sphinxContext , resultTags , hsBindings ) : <EOL> def evaluateTagExpr ( tagExpr , modifier ) : <EOL> if modifier == "<STR_LIT:value>" : <EOL> value = evaluate ( tagExpr , sphinxContext , value = True ) <EOL> elif modifier == "<STR_LIT>" : <EOL> value = contextView ( sphinxContext , tagExpr ) <EOL> else : <EOL> value = "<STR_LIT>" . format ( evaluate ( tagExpr , sphinxContext , value = True ) , <EOL> contextView ( sphinxContext ) ) <EOL> return value <EOL> msgstr = evaluate ( node . message , sphinxContext , value = True ) <EOL> text = [ ] <EOL> args = [ ] <EOL> i = <NUM_LIT:0> <EOL> while True : <EOL> j = msgstr . find ( "<STR_LIT>" , i ) <EOL> if j >= <NUM_LIT:0> : <EOL> text . append ( msgstr [ i : j ] ) <EOL> k = msgstr . find ( "<STR_LIT:}>" , j + <NUM_LIT:2> ) <EOL> if k > j : <EOL> text . append ( "<STR_LIT:{>" + str ( len ( args ) ) + "<STR_LIT:}>" ) <EOL> tag , sep , modifier = msgstr [ j + <NUM_LIT:2> : k ] . strip ( ) . partition ( "<STR_LIT:.>" ) <EOL> if tag == "<STR_LIT>" : <EOL> value = contextView ( sphinxContext ) , <EOL> elif tag in resultTags : <EOL> value = evaluateTagExpr ( resultTags . tags [ tag ] , modifier ) <EOL> elif tag in sphinxContext . tags : <EOL> value = evaluateTagExpr ( sphinxContext . tags [ tag ] , modifier ) <EOL> elif tag in sphinxContext . taggedConstants : <EOL> value = evaluateTagExpr ( evaluateConstant ( sphinxContext . taggedConstants [ tag ] , sphinxContext ) , modifier ) <EOL> elif tag in ( "<STR_LIT>" , "<STR_LIT:left>" , "<STR_LIT:right>" , "<STR_LIT>" ) : <EOL> value = '<STR_LIT>' . format ( tag ) <EOL> else : <EOL> sphinxContext . modelXbrl . log ( "<STR_LIT>" , "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , <EOL> tag = tag ) <EOL> value = "<STR_LIT>" + tag + "<STR_LIT:}>" <EOL> args . append ( value ) <EOL> i = k + <NUM_LIT:1> <EOL> else : <EOL> text . append ( msgstr [ i : ] ) <EOL> break <EOL> messageStr = '<STR_LIT>' . join ( text ) <EOL> return messageStr . format ( * args ) <EOL> def evaluateMethodReference ( node , sphinxContext ) : <EOL> args = [ ] <EOL> for i , nodeArg in enumerate ( node . args ) : <EOL> arg = evaluate ( nodeArg , <EOL> sphinxContext , <EOL> value = True , <EOL> hsBoundFact = ( i == <NUM_LIT:0> ) ) <EOL> args . append ( arg ) <EOL> return methodImplementation . get ( node . name , <EOL> methodImplementation [ "<STR_LIT>" ] <EOL> ) ( node , sphinxContext , args ) <EOL> def evaluateNoOp ( node , sphinxContext ) : <EOL> return None <EOL> def evaluateNumericLiteral ( node , sphinxContext ) : <EOL> return node . value <EOL> def evaluatePreconditionDeclaration ( node , sphinxContext ) : <EOL> hsBindings = HyperspaceBindings ( sphinxContext ) <EOL> result = evaluate ( node . expr , sphinxContext , value = True ) <EOL> hsBindings . close ( ) <EOL> return result <EOL> def evaluatePreconditionReference ( node , sphinxContext ) : <EOL> preconditionPasses = True <EOL> for name in node . names : <EOL> if name in sphinxContext . preconditionNodes : <EOL> if not evaluate ( sphinxContext . preconditionNodes [ name ] , sphinxContext , value = True ) : <EOL> preconditionPasses = False <EOL> clearEvaluation ( sphinxContext ) <EOL> if not preconditionPasses : <EOL> break <EOL> return preconditionPasses <EOL> def evaluateQnameLiteral ( node , sphinxContext ) : <EOL> return node . value <EOL> def evaluateReportRule ( node , sphinxContext ) : <EOL> return None <EOL> def evaluateRuleBasePrecondition ( node , sphinxContext ) : <EOL> if node . precondition : <EOL> return evaluate ( node . precondition , sphinxContext , value = True ) <EOL> return True <EOL> def evaluateStringLiteral ( node , sphinxContext ) : <EOL> return node . text <EOL> def evaluateTagAssignment ( node , sphinxContext ) : <EOL> result = evaluate ( node . expr , sphinxContext , value = True ) <EOL> sphinxContext . tags [ node . tagName ] = result <EOL> return result <EOL> def evaluateTagReference ( node , sphinxContext ) : <EOL> try : <EOL> return sphinxContext . tags [ node . name ] <EOL> except KeyError : <EOL> raise SphinxException ( node , <EOL> "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> name = node . name ) <EOL> def evaluateRule ( node , sphinxContext ) : <EOL> isFormulaRule = isinstance ( node , astFormulaRule ) <EOL> isReportRule = isinstance ( node , astReportRule ) <EOL> name = ( node . name or ( "<STR_LIT>" if isReportRule else "<STR_LIT>" ) ) <EOL> nodeId = node . nodeTypeName + '<STR_LIT:U+0020>' + name <EOL> if node . precondition : <EOL> result = evaluate ( node . precondition , sphinxContext , value = True ) <EOL> if sphinxContext . formulaOptions . traceVariableSetExpressionResult : <EOL> sphinxContext . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , node = nodeId , value = result ) <EOL> if not result : <EOL> return None <EOL> sphinxContext . ruleNode = node <EOL> hsBindings = None <EOL> ruleIteration = <NUM_LIT:0> <EOL> try : <EOL> hsBindings = HyperspaceBindings ( sphinxContext ) <EOL> while True : <EOL> ruleIteration += <NUM_LIT:1> <EOL> sphinxContext . dynamicSeverity = None <EOL> sphinxContext . tags . clear ( ) <EOL> sphinxContext . localVariables . clear ( ) <EOL> if sphinxContext . formulaOptions . traceVariableSetExpressionResult : <EOL> sphinxContext . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , node = nodeId , iteration = ruleIteration ) <EOL> for varAssignNode in node . variableAssignments : <EOL> evaluateVariableAssignment ( varAssignNode , sphinxContext ) <EOL> result = evaluate ( node . expr , sphinxContext , value = True ) <EOL> if result is UNBOUND : <EOL> result = None <EOL> elif isFormulaRule : <EOL> left , right = result <EOL> if left is UNBOUND : <EOL> difference = UNBOUND <EOL> elif right is UNBOUND : <EOL> difference = UNBOUND <EOL> else : <EOL> difference = abs ( left - right ) <EOL> result = difference != <NUM_LIT:0> <EOL> resultTags = { "<STR_LIT:left>" : left , "<STR_LIT:right>" : right , "<STR_LIT>" : difference } <EOL> sphinxContext . dynamicSeverity = None <EOL> if node . severity in sphinxContext . functions : <EOL> evaluateFunctionDeclaration ( sphinxContext . functions [ node . severity ] , <EOL> sphinxContext , <EOL> { "<STR_LIT>" : difference , "<STR_LIT:left>" : left , "<STR_LIT:right>" : right } ) <EOL> if sphinxContext . dynamicSeverity is None or sphinxContext . dynamicSeverity == "<STR_LIT>" : <EOL> sphinxContext . dynamicSeverity = None <EOL> result = False <EOL> else : <EOL> if isReportRule : <EOL> resultTags = { "<STR_LIT:value>" : result } <EOL> else : <EOL> resultTags = { } <EOL> if sphinxContext . formulaOptions . traceVariableSetExpressionResult : <EOL> sphinxContext . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , node = nodeId , iteration = ruleIteration , <EOL> result = result , <EOL> severity = ( sphinxContext . dynamicSeverity or node . severity or <EOL> ( "<STR_LIT:info>" if isReportRule else "<STR_LIT:error>" ) ) ) <EOL> if ( ( result or isReportRule ) or <EOL> ( sphinxContext . dynamicSeverity and sphinxContext . dynamicSeverity != "<STR_LIT>" ) ) : <EOL> severity = ( sphinxContext . dynamicSeverity or node . severity or <EOL> ( "<STR_LIT:info>" if isReportRule else "<STR_LIT:error>" ) ) <EOL> if isinstance ( severity , astFunctionReference ) : <EOL> severity = severity . name <EOL> logSeverity = { "<STR_LIT:error>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:info>" : "<STR_LIT>" } [ severity ] <EOL> if node . message : <EOL> sphinxContext . modelXbrl . log ( logSeverity , name , <EOL> evaluateMessage ( node . message , sphinxContext , resultTags , hsBindings ) , <EOL> sourceFileLine = [ node . sourceFileLine ] + <EOL> [ ( fact . modelDocument . uri , fact . sourceline ) for fact in hsBindings . boundFacts ] , <EOL> severity = severity ) <EOL> elif isFormulaRule : <EOL> sphinxContext . modelXbrl . log ( logSeverity , <EOL> name , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = [ node . sourceFileLine ] + <EOL> [ ( fact . modelDocument . uri , fact . sourceline ) for fact in hsBindings . boundFacts ] , <EOL> severity = severity , <EOL> value = difference , <EOL> aspects = contextView ( sphinxContext ) ) <EOL> elif isReportRule : <EOL> sphinxContext . modelXbrl . log ( logSeverity , <EOL> name , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = [ node . sourceFileLine ] + <EOL> [ ( fact . modelDocument . uri , fact . sourceline ) for fact in hsBindings . boundFacts ] , <EOL> severity = severity , <EOL> value = result , <EOL> aspects = contextView ( sphinxContext ) ) <EOL> else : <EOL> sphinxContext . modelXbrl . log ( logSeverity , <EOL> name , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = [ node . sourceFileLine ] + <EOL> [ ( fact . modelDocument . uri , fact . sourceline ) for fact in hsBindings . boundFacts ] , <EOL> severity = severity , <EOL> aspects = contextView ( sphinxContext ) ) <EOL> hsBindings . next ( ) <EOL> except StopIteration : <EOL> if sphinxContext . formulaOptions . traceVariableSetExpressionResult : <EOL> sphinxContext . modelXbrl . info ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> sourceFileLine = node . sourceFileLine , node = nodeId ) <EOL> except SphinxException as ex : <EOL> sphinxContext . modelXbrl . log ( "<STR_LIT>" , <EOL> ex . code , <EOL> _ ( "<STR_LIT>" ) , <EOL> node = nodeId , <EOL> ruleName = name , <EOL> exception = ex . message % ex . kwargs , <EOL> sourceFileLine = [ node . sourceFileLine ] + ( [ ex . node . sourceFileLine ] if ex . node is not node else [ ] ) , <EOL> ** ex . kwargs ) <EOL> if hsBindings is not None : <EOL> hsBindings . close ( ) <EOL> return None <EOL> def noop ( arg ) : <EOL> return arg <EOL> def evaluateUnaryOperation ( node , sphinxContext ) : <EOL> if node . op == "<STR_LIT>" : <EOL> return node . expr <EOL> value = evaluate ( node . expr , sphinxContext , value = True , fallback = UNBOUND ) <EOL> if value is UNBOUND : <EOL> return UNBOUND <EOL> try : <EOL> result = { '<STR_LIT:+>' : operator . pos , '<STR_LIT:->' : operator . neg , '<STR_LIT>' : operator . not_ , <EOL> '<STR_LIT>' : noop , <EOL> } [ node . op ] ( value ) <EOL> return result <EOL> except KeyError : <EOL> sphinxContext . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = node , op = node . op ) <EOL> return None <EOL> def evaluateValuesIteration ( node , sphinxContext ) : <EOL> hsBindings = sphinxContext . hyperspaceBindings <EOL> if hsBindings . aggregationNode is None : <EOL> sphinxContext . modelXbrl . error ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> modelObject = node ) <EOL> else : <EOL> hsBindings . isValuesIteration = True <EOL> return evaluate ( node . expr , sphinxContext ) <EOL> def evaluateVariableAssignment ( node , sphinxContext ) : <EOL> result = evaluate ( node . expr , sphinxContext ) <EOL> sphinxContext . localVariables [ node . variableName ] = result <EOL> if node . tagName : <EOL> sphinxContext . tags [ node . tagName ] = result <EOL> return result <EOL> def evaluateVariableReference ( node , sphinxContext ) : <EOL> try : <EOL> return sphinxContext . localVariables [ node . variableName ] <EOL> except KeyError : <EOL> if node . variableName in sphinxContext . constants : <EOL> return evaluateConstant ( sphinxContext . constants [ node . variableName ] , sphinxContext ) <EOL> raise SphinxException ( node , <EOL> "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> name = node . variableName ) <EOL> def evaluateWith ( node , sphinxContext ) : <EOL> hsBindings = sphinxContext . hyperspaceBindings <EOL> withRestrictionBinding = hsBindings . nodeBinding ( node . restrictionExpr , isWithRestrictionNode = True ) <EOL> hsBindings . withRestrictionBindings . append ( withRestrictionBinding ) <EOL> try : <EOL> for varAssignNode in node . variableAssignments : <EOL> evaluateVariableAssignment ( varAssignNode , sphinxContext ) <EOL> result = evaluate ( node . bodyExpr , sphinxContext ) <EOL> except Exception as ex : <EOL> del hsBindings . withRestrictionBindings [ - <NUM_LIT:1> ] <EOL> raise ex <EOL> del hsBindings . withRestrictionBindings [ - <NUM_LIT:1> ] <EOL> return result <EOL> def contextView ( sphinxContext , fact = None ) : <EOL> if isinstance ( fact , ModelFact ) : <EOL> return "<STR_LIT>" . format ( fact . qname , <EOL> "<STR_LIT:U+002CU+0020>" . join ( "<STR_LIT>" . format ( aspectName ( aspect ) , <EOL> factAspectValue ( fact , aspect , view = True ) ) <EOL> for aspect , fact in sphinxContext . hyperspaceBindings . aspectBoundFacts . items ( ) <EOL> if factAspectValue ( fact , aspect ) and aspect != Aspect . CONCEPT ) ) <EOL> else : <EOL> return "<STR_LIT>" . format ( "<STR_LIT:U+002CU+0020>" . join ( "<STR_LIT>" . format ( aspectName ( aspect ) , <EOL> factAspectValue ( fact , aspect , view = True ) ) <EOL> for aspect , fact in sphinxContext . hyperspaceBindings . aspectBoundFacts . items ( ) <EOL> if factAspectValue ( fact , aspect ) ) ) <EOL> def aspectName ( aspect ) : <EOL> if isinstance ( aspect , QName ) : <EOL> return aspect <EOL> return { Aspect . LOCATION : "<STR_LIT>" , <EOL> Aspect . CONCEPT : "<STR_LIT>" , <EOL> Aspect . ENTITY_IDENTIFIER : "<STR_LIT>" , <EOL> Aspect . PERIOD : "<STR_LIT>" , <EOL> Aspect . UNIT : "<STR_LIT>" , <EOL> Aspect . NON_XDT_SEGMENT : "<STR_LIT>" , <EOL> Aspect . NON_XDT_SCENARIO : "<STR_LIT>" , <EOL> } . get ( aspect ) <EOL> if aspect in Aspect . label : <EOL> return Aspect . label [ aspect ] <EOL> else : <EOL> return str ( aspect ) <EOL> def factAspectValue ( fact , aspect , view = False ) : <EOL> if fact is DEFAULT : <EOL> return '<STR_LIT:none>' <EOL> elif fact is NONDEFAULT : <EOL> return '<STR_LIT:*>' <EOL> elif fact is DEFAULTorNONDEFAULT : <EOL> return '<STR_LIT>' <EOL> elif aspect == Aspect . LOCATION : <EOL> parentQname = fact . getparent ( ) . qname <EOL> if parentQname == XbrlConst . qnXbrliXbrl : <EOL> return NONE <EOL> return parentQname <EOL> elif aspect == Aspect . CONCEPT : <EOL> return fact . qname <EOL> elif fact . isTuple or fact . context is None : <EOL> return NONE <EOL> elif aspect == Aspect . UNIT : <EOL> if fact . unit is None : <EOL> return NONE <EOL> measures = fact . unit . measures <EOL> if measures [ <NUM_LIT:1> ] : <EOL> return "<STR_LIT>" . format ( '<STR_LIT:U+0020>' . join ( str ( m ) for m in measures [ <NUM_LIT:0> ] ) , <EOL> '<STR_LIT:U+0020>' . join ( str ( m ) for m in measures [ <NUM_LIT:1> ] ) ) <EOL> else : <EOL> return '<STR_LIT:U+0020>' . join ( str ( m ) for m in measures [ <NUM_LIT:0> ] ) <EOL> else : <EOL> context = fact . context <EOL> if aspect == Aspect . PERIOD : <EOL> return ( "<STR_LIT>" if context . isForeverPeriod else <EOL> XmlUtil . dateunionValue ( context . instantDatetime , subtractOneDay = True ) if context . isInstantPeriod else <EOL> XmlUtil . dateunionValue ( context . startDatetime ) + "<STR_LIT:->" + XmlUtil . dateunionValue ( context . endDatetime , subtractOneDay = True ) ) <EOL> elif aspect == Aspect . ENTITY_IDENTIFIER : <EOL> if view : <EOL> return context . entityIdentifier [ <NUM_LIT:1> ] <EOL> else : <EOL> return context . entityIdentifier <EOL> elif aspect in ( Aspect . COMPLETE_SEGMENT , Aspect . COMPLETE_SCENARIO , <EOL> Aspect . NON_XDT_SEGMENT , Aspect . NON_XDT_SCENARIO ) : <EOL> return '<STR_LIT>' . join ( XmlUtil . xmlstring ( elt , stripXmlns = True , prettyPrint = True ) <EOL> for elt in context . nonDimValues ( aspect ) ) <EOL> elif aspect == Aspect . DIMENSIONS : <EOL> return context . dimAspects ( fact . xpCtx . defaultDimensionAspects ) <EOL> elif isinstance ( aspect , QName ) : <EOL> dimValue = context . dimValue ( aspect ) <EOL> if dimValue is None : <EOL> return NONE <EOL> else : <EOL> if isinstance ( dimValue , QName ) : <EOL> return dimValue <EOL> elif dimValue . isExplicit : <EOL> return dimValue . memberQname <EOL> else : <EOL> return dimValue . typedMember . xValue <EOL> evaluator = { <EOL> "<STR_LIT>" : evaluateAnnotationDeclaration , <EOL> "<STR_LIT>" : evaluateBinaryOperation , <EOL> "<STR_LIT>" : evaluateNoOp , <EOL> "<STR_LIT>" : evaluateFor , <EOL> "<STR_LIT>" : evaluateRule , <EOL> "<STR_LIT>" : evaluateFunctionDeclaration , <EOL> "<STR_LIT>" : evaluateFunctionReference , <EOL> "<STR_LIT>" : evaluateHyperspaceExpression , <EOL> "<STR_LIT>" : evaluateIf , <EOL> "<STR_LIT>" : evaluateMessage , <EOL> "<STR_LIT>" : evaluateMethodReference , <EOL> "<STR_LIT>" : evaluateNoOp , <EOL> "<STR_LIT>" : evaluateNoOp , <EOL> "<STR_LIT>" : evaluateNoOp , <EOL> "<STR_LIT>" : evaluateNumericLiteral , <EOL> "<STR_LIT>" : evaluatePreconditionDeclaration , <EOL> "<STR_LIT>" : evaluateQnameLiteral , <EOL> "<STR_LIT>" : evaluateRule , <EOL> "<STR_LIT>" : evaluateNoOp , <EOL> "<STR_LIT>" : evaluateRuleBasePrecondition , <EOL> "<STR_LIT>" : evaluatePreconditionReference , <EOL> "<STR_LIT>" : evaluateStringLiteral , <EOL> "<STR_LIT>" : evaluateTagAssignment , <EOL> "<STR_LIT>" : evaluateTagReference , <EOL> "<STR_LIT>" : evaluateRule , <EOL> "<STR_LIT>" : evaluateValuesIteration , <EOL> "<STR_LIT>" : evaluateVariableAssignment , <EOL> "<STR_LIT>" : evaluateVariableReference , <EOL> "<STR_LIT>" : evaluateUnaryOperation , <EOL> "<STR_LIT>" : evaluateWith , <EOL> } <EOL> SphinxMethodsModuleInit ( ) </s>
|
<s> '''<STR_LIT>''' <EOL> def dialogRssWatchDBextender ( dialog , frame , row , options , cntlr , openFileImage , openDatabaseImage ) : <EOL> from tkinter import PhotoImage , N , S , E , W <EOL> from tkinter . simpledialog import askstring <EOL> from arelle . CntlrWinTooltip import ToolTip <EOL> from arelle . UiUtil import gridCell , label <EOL> try : <EOL> from tkinter . ttk import Button <EOL> except ImportError : <EOL> from ttk import Button <EOL> def enterConnectionString ( ) : <EOL> from arelle . DialogUserPassword import askDatabase <EOL> db = askDatabase ( cntlr . parent , dialog . cellDBconnection . value . split ( '<STR_LIT:U+002C>' ) if dialog . cellDBconnection . value else None ) <EOL> if db : <EOL> dbConnectionString = '<STR_LIT:U+002C>' . join ( db ) <EOL> dialog . options [ "<STR_LIT>" ] = dbConnectionString <EOL> dialog . cellDBconnection . setValue ( dbConnectionString ) <EOL> else : <EOL> dialog . options . pop ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> label ( frame , <NUM_LIT:1> , row , "<STR_LIT>" ) <EOL> dialog . cellDBconnection = gridCell ( frame , <NUM_LIT:2> , row , options . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> ToolTip ( dialog . cellDBconnection , text = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , wraplength = <NUM_LIT> ) <EOL> enterDBconnectionButton = Button ( frame , image = openDatabaseImage , width = <NUM_LIT:12> , command = enterConnectionString ) <EOL> enterDBconnectionButton . grid ( row = row , column = <NUM_LIT:3> , sticky = W ) </s>
|
<s> import os , fnmatch , xml . dom . minidom , datetime <EOL> def main ( ) : <EOL> topDirectory = "<STR_LIT>" <EOL> testcaseName = "<STR_LIT>" <EOL> ownerName = "<STR_LIT>" <EOL> ownerEmail = "<STR_LIT>" <EOL> entryRelativeFilePaths = [ ] <EOL> for root , dirs , files in os . walk ( topDirectory ) : <EOL> for fileName in files : <EOL> if fnmatch . fnmatch ( fileName , '<STR_LIT>' ) : <EOL> fullFilePath = os . path . join ( root , fileName ) <EOL> entryRelativeFilePaths . append ( os . path . relpath ( fullFilePath , topDirectory ) ) <EOL> lines = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( testcaseName , datetime . date . today ( ) ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( ownerName ) , <EOL> '<STR_LIT>' . format ( ownerEmail ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( ownerEmail ) , <EOL> '<STR_LIT>' . format ( testcaseName ) , <EOL> ] <EOL> num = <NUM_LIT:1> <EOL> for entryFile in entryRelativeFilePaths : <EOL> fileName = os . path . basename ( entryFile ) <EOL> lines . append ( "<STR_LIT>" . format ( fileName , num ) ) <EOL> num += <NUM_LIT:1> <EOL> lines . append ( "<STR_LIT>" . format ( fileName ) ) <EOL> lines . append ( "<STR_LIT>" ) <EOL> lines . append ( "<STR_LIT>" . format ( entryFile . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) ) ) <EOL> lines . append ( "<STR_LIT>" ) <EOL> lines . append ( "<STR_LIT>" ) <EOL> lines . append ( "<STR_LIT>" ) <EOL> lines . append ( '<STR_LIT>' ) <EOL> with open ( os . path . join ( topDirectory , "<STR_LIT>" ) , "<STR_LIT:w>" ) as fh : <EOL> fh . write ( '<STR_LIT:\n>' . join ( lines ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
|
<s> from . gen . tags import _Tags <EOL> class Tags ( _Tags ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
|
<s> '''<STR_LIT>''' <EOL> import sys <EOL> import os . path <EOL> import gzip <EOL> import zipfile <EOL> from xml . sax import make_parser <EOL> from xml . sax . handler import ContentHandler <EOL> from xml . sax import saxutils <EOL> class gmlhandler ( ContentHandler ) : <EOL> def __init__ ( self , preparer ) : <EOL> self . preparer = preparer <EOL> self . first_elm = True <EOL> self . feat = None <EOL> self . recording = False <EOL> def startElement ( self , name , attrs ) : <EOL> if self . first_elm : <EOL> self . first_elm = False <EOL> output ( '<STR_LIT>' ) <EOL> try : <EOL> name = name . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> pass <EOL> if name in self . preparer . feat_types : <EOL> self . buffer = [ ] <EOL> self . recording = True <EOL> tmp = '<STR_LIT:<>' + name <EOL> for ( name , value ) in attrs . items ( ) : <EOL> try : <EOL> name = name . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> pass <EOL> tmp += '<STR_LIT>' % ( name , saxutils . quoteattr ( value ) ) <EOL> tmp += '<STR_LIT:>>' <EOL> if self . recording : <EOL> self . buffer . append ( tmp ) <EOL> else : <EOL> output ( tmp ) <EOL> return <EOL> def characters ( self , ch ) : <EOL> if len ( ch . strip ( ) ) > <NUM_LIT:0> : <EOL> if self . recording : <EOL> self . buffer . append ( saxutils . escape ( ch ) ) <EOL> else : <EOL> output ( saxutils . escape ( ch ) ) <EOL> def endElement ( self , name ) : <EOL> try : <EOL> name = name . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> pass <EOL> if self . recording : <EOL> self . buffer . append ( '<STR_LIT>' + name + '<STR_LIT:>>' ) <EOL> else : <EOL> output ( '<STR_LIT>' + name + '<STR_LIT:>>' ) <EOL> if name in self . preparer . feat_types : <EOL> self . recording = False <EOL> output ( self . preparer . prepare_feature ( '<STR_LIT>' . join ( self . buffer ) ) ) <EOL> self . buffer = [ ] <EOL> def output ( str ) : <EOL> try : <EOL> sys . stdout . write ( str . encode ( '<STR_LIT>' , '<STR_LIT>' ) . decode ( '<STR_LIT>' ) ) <EOL> except UnicodeEncodeError : <EOL> sys . stdout . write ( str . encode ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> class prep_gml ( ) : <EOL> def __init__ ( self , inputfile ) : <EOL> self . feat_types = [ ] <EOL> def get_feat_types ( self ) : <EOL> return self . feat_types <EOL> def prepare_feature ( self , feat_str ) : <EOL> return feat_str <EOL> def main ( ) : <EOL> if len ( sys . argv ) < <NUM_LIT:2> : <EOL> print ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> inputfile = sys . argv [ <NUM_LIT:1> ] <EOL> if os . path . exists ( inputfile ) : <EOL> prep_class = '<STR_LIT>' <EOL> try : <EOL> prep_class = sys . argv [ <NUM_LIT:2> ] <EOL> except IndexError : <EOL> pass <EOL> prep_class = get_preparer ( prep_class ) <EOL> preparer = prep_class ( inputfile ) <EOL> parser = make_parser ( ) <EOL> parser . setContentHandler ( gmlhandler ( preparer ) ) <EOL> if os . path . splitext ( inputfile ) [ <NUM_LIT:1> ] . lower ( ) == '<STR_LIT>' : <EOL> archive = zipfile . ZipFile ( inputfile , '<STR_LIT:r>' ) <EOL> for filename in archive . namelist ( ) : <EOL> file = archive . open ( filename ) <EOL> try : <EOL> parser . parse ( file ) <EOL> except : <EOL> pass <EOL> else : <EOL> if os . path . splitext ( inputfile ) [ <NUM_LIT:1> ] . lower ( ) == '<STR_LIT>' : <EOL> file = gzip . open ( inputfile , '<STR_LIT:r>' ) <EOL> else : <EOL> file = open ( inputfile , '<STR_LIT:r>' ) <EOL> parser . parse ( file ) <EOL> else : <EOL> print ( '<STR_LIT>' + inputfile ) <EOL> def get_preparer ( prep_class ) : <EOL> parts = prep_class . split ( '<STR_LIT:.>' ) <EOL> if len ( parts ) > <NUM_LIT:1> : <EOL> prep_module = parts [ <NUM_LIT:0> ] <EOL> prep_module = __import__ ( prep_module ) <EOL> prep_class = getattr ( prep_module , parts [ <NUM_LIT:1> ] ) <EOL> else : <EOL> prep_class = globals ( ) [ prep_class ] <EOL> return prep_class <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
|
<s> from django . contrib import admin </s>
|
<s> import csv <EOL> from . import eigen <EOL> import axelrod . interaction_utils as iu <EOL> from numpy import mean , nanmedian , std <EOL> try : <EOL> from StringIO import StringIO <EOL> except ImportError : <EOL> from io import StringIO <EOL> class ResultSet ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , players , interactions , with_morality = True ) : <EOL> """<STR_LIT>""" <EOL> self . players = players <EOL> self . nplayers = len ( players ) <EOL> self . interactions = interactions <EOL> self . nrepetitions = len ( interactions ) <EOL> self . build_all ( with_morality ) <EOL> def build_all ( self , with_morality ) : <EOL> """<STR_LIT>""" <EOL> self . wins = self . build_wins ( ) <EOL> self . match_lengths = self . build_match_lengths ( ) <EOL> self . scores = self . build_scores ( ) <EOL> self . normalised_scores = self . build_normalised_scores ( ) <EOL> self . ranking = self . build_ranking ( ) <EOL> self . ranked_names = self . build_ranked_names ( ) <EOL> self . payoffs = self . build_payoffs ( ) <EOL> self . payoff_matrix = self . build_payoff_matrix ( ) <EOL> self . payoff_stddevs = self . build_payoff_stddevs ( ) <EOL> self . score_diffs = self . build_score_diffs ( ) <EOL> self . payoff_diffs_means = self . build_payoff_diffs_means ( ) <EOL> if with_morality : <EOL> self . cooperation = self . build_cooperation ( ) <EOL> self . normalised_cooperation = self . build_normalised_cooperation ( ) <EOL> self . vengeful_cooperation = self . build_vengeful_cooperation ( ) <EOL> self . cooperating_rating = self . build_cooperating_rating ( ) <EOL> self . good_partner_matrix = self . build_good_partner_matrix ( ) <EOL> self . good_partner_rating = self . build_good_partner_rating ( ) <EOL> self . eigenmoses_rating = self . build_eigenmoses_rating ( ) <EOL> self . eigenjesus_rating = self . build_eigenjesus_rating ( ) <EOL> @ property <EOL> def _null_results_matrix ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> replist = list ( range ( self . nrepetitions ) ) <EOL> return [ [ [ <NUM_LIT:0> for j in plist ] for i in plist ] for r in replist ] <EOL> def build_match_lengths ( self ) : <EOL> """<STR_LIT>""" <EOL> match_lengths = self . _null_results_matrix <EOL> for rep in range ( self . nrepetitions ) : <EOL> for player_pair_index , interactions in self . interactions [ rep ] . items ( ) : <EOL> player , opponent = player_pair_index <EOL> match_lengths [ rep ] [ player ] [ opponent ] = len ( interactions ) <EOL> if player != opponent : <EOL> match_lengths [ rep ] [ opponent ] [ player ] = len ( interactions ) <EOL> return match_lengths <EOL> def build_scores ( self ) : <EOL> """<STR_LIT>""" <EOL> scores = [ [ <NUM_LIT:0> for rep in range ( self . nrepetitions ) ] for _ in <EOL> range ( self . nplayers ) ] <EOL> for rep , inter_dict in enumerate ( self . interactions ) : <EOL> for index_pair , interactions in inter_dict . items ( ) : <EOL> if index_pair [ <NUM_LIT:0> ] != index_pair [ <NUM_LIT:1> ] : <EOL> final_scores = iu . compute_final_score ( interactions ) <EOL> for player in range ( <NUM_LIT:2> ) : <EOL> player_index = index_pair [ player ] <EOL> player_score = final_scores [ player ] <EOL> scores [ player_index ] [ rep ] += player_score <EOL> return scores <EOL> def build_ranked_names ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ str ( self . players [ i ] ) for i in self . ranking ] <EOL> def build_wins ( self ) : <EOL> """<STR_LIT>""" <EOL> wins = [ [ <NUM_LIT:0> for rep in range ( self . nrepetitions ) ] for _ in <EOL> range ( self . nplayers ) ] <EOL> for rep , inter_dict in enumerate ( self . interactions ) : <EOL> for index_pair , interactions in inter_dict . items ( ) : <EOL> if index_pair [ <NUM_LIT:0> ] != index_pair [ <NUM_LIT:1> ] : <EOL> for player in range ( <NUM_LIT:2> ) : <EOL> player_index = index_pair [ player ] <EOL> winner_index = iu . compute_winner_index ( interactions ) <EOL> if winner_index is not False and player == winner_index : <EOL> wins [ player_index ] [ rep ] += <NUM_LIT:1> <EOL> return wins <EOL> def build_normalised_scores ( self ) : <EOL> """<STR_LIT>""" <EOL> normalised_scores = [ <EOL> [ [ ] for rep in range ( self . nrepetitions ) ] for _ in <EOL> range ( self . nplayers ) ] <EOL> for rep , inter_dict in enumerate ( self . interactions ) : <EOL> for index_pair , interactions in inter_dict . items ( ) : <EOL> if index_pair [ <NUM_LIT:0> ] != index_pair [ <NUM_LIT:1> ] : <EOL> scores_per_turn = iu . compute_final_score_per_turn ( interactions ) <EOL> for player in range ( <NUM_LIT:2> ) : <EOL> player_index = index_pair [ player ] <EOL> score_per_turn = scores_per_turn [ player ] <EOL> normalised_scores [ player_index ] [ rep ] . append ( score_per_turn ) <EOL> for i , rep in enumerate ( normalised_scores ) : <EOL> for j , player_scores in enumerate ( rep ) : <EOL> normalised_scores [ i ] [ j ] = mean ( player_scores ) <EOL> return normalised_scores <EOL> def build_ranking ( self ) : <EOL> """<STR_LIT>""" <EOL> return sorted ( range ( self . nplayers ) , <EOL> key = lambda i : - nanmedian ( self . normalised_scores [ i ] ) ) <EOL> def build_payoffs ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> payoffs = [ [ [ ] for opponent in plist ] for player in plist ] <EOL> for player in plist : <EOL> for opponent in plist : <EOL> utilities = [ ] <EOL> for rep in self . interactions : <EOL> if ( player , opponent ) in rep : <EOL> interactions = rep [ ( player , opponent ) ] <EOL> utilities . append ( iu . compute_final_score_per_turn ( interactions ) [ <NUM_LIT:0> ] ) <EOL> if ( opponent , player ) in rep : <EOL> interactions = rep [ ( opponent , player ) ] <EOL> utilities . append ( iu . compute_final_score_per_turn ( interactions ) [ <NUM_LIT:1> ] ) <EOL> payoffs [ player ] [ opponent ] = utilities <EOL> return payoffs <EOL> def build_payoff_matrix ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> payoff_matrix = [ [ [ ] for opponent in plist ] for player in plist ] <EOL> for player in plist : <EOL> for opponent in plist : <EOL> utilities = self . payoffs [ player ] [ opponent ] <EOL> if utilities : <EOL> payoff_matrix [ player ] [ opponent ] = mean ( utilities ) <EOL> else : <EOL> payoff_matrix [ player ] [ opponent ] = <NUM_LIT:0> <EOL> return payoff_matrix <EOL> def build_payoff_stddevs ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> payoff_stddevs = [ [ [ <NUM_LIT:0> ] for opponent in plist ] for player in plist ] <EOL> for player in plist : <EOL> for opponent in plist : <EOL> utilities = self . payoffs [ player ] [ opponent ] <EOL> if utilities : <EOL> payoff_stddevs [ player ] [ opponent ] = std ( utilities ) <EOL> else : <EOL> payoff_stddevs [ player ] [ opponent ] = <NUM_LIT:0> <EOL> return payoff_stddevs <EOL> def build_score_diffs ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> score_diffs = [ [ [ <NUM_LIT:0> ] * self . nrepetitions for opponent in plist ] <EOL> for player in plist ] <EOL> for player in plist : <EOL> for opponent in plist : <EOL> for r , rep in enumerate ( self . interactions ) : <EOL> if ( player , opponent ) in rep : <EOL> scores = iu . compute_final_score_per_turn ( rep [ ( player , <EOL> opponent ) ] ) <EOL> diff = ( scores [ <NUM_LIT:0> ] - scores [ <NUM_LIT:1> ] ) <EOL> score_diffs [ player ] [ opponent ] [ r ] = diff <EOL> if ( opponent , player ) in rep : <EOL> scores = iu . compute_final_score_per_turn ( rep [ ( opponent , <EOL> player ) ] ) <EOL> diff = ( scores [ <NUM_LIT:1> ] - scores [ <NUM_LIT:0> ] ) <EOL> score_diffs [ player ] [ opponent ] [ r ] = diff <EOL> return score_diffs <EOL> def build_payoff_diffs_means ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> payoff_diffs_means = [ [ <NUM_LIT:0> for opponent in plist ] for player in plist ] <EOL> for player in plist : <EOL> for opponent in plist : <EOL> diffs = [ ] <EOL> for rep in self . interactions : <EOL> if ( player , opponent ) in rep : <EOL> scores = iu . compute_final_score_per_turn ( rep [ ( player , <EOL> opponent ) ] ) <EOL> diffs . append ( scores [ <NUM_LIT:0> ] - scores [ <NUM_LIT:1> ] ) <EOL> if ( opponent , player ) in rep : <EOL> scores = iu . compute_final_score_per_turn ( rep [ ( opponent , <EOL> player ) ] ) <EOL> diffs . append ( scores [ <NUM_LIT:1> ] - scores [ <NUM_LIT:0> ] ) <EOL> if diffs : <EOL> payoff_diffs_means [ player ] [ opponent ] = mean ( diffs ) <EOL> else : <EOL> payoff_diffs_means [ player ] [ opponent ] = <NUM_LIT:0> <EOL> return payoff_diffs_means <EOL> def build_cooperation ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> cooperations = [ [ <NUM_LIT:0> for opponent in plist ] for player in plist ] <EOL> for player in plist : <EOL> for opponent in plist : <EOL> if player != opponent : <EOL> for rep in self . interactions : <EOL> coop_count = <NUM_LIT:0> <EOL> if ( player , opponent ) in rep : <EOL> interactions = rep [ ( player , opponent ) ] <EOL> coop_count = iu . compute_cooperations ( interactions ) [ <NUM_LIT:0> ] <EOL> if ( opponent , player ) in rep : <EOL> interactions = rep [ ( opponent , player ) ] <EOL> coop_count = iu . compute_cooperations ( interactions ) [ <NUM_LIT:1> ] <EOL> cooperations [ player ] [ opponent ] += coop_count <EOL> return cooperations <EOL> def build_normalised_cooperation ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> normalised_cooperations = [ [ <NUM_LIT:0> for opponent in plist ] for player in plist ] <EOL> for player in plist : <EOL> for opponent in plist : <EOL> coop_counts = [ ] <EOL> for rep in self . interactions : <EOL> if ( player , opponent ) in rep : <EOL> interactions = rep [ ( player , opponent ) ] <EOL> coop_counts . append ( iu . compute_normalised_cooperation ( interactions ) [ <NUM_LIT:0> ] ) <EOL> if ( opponent , player ) in rep : <EOL> interactions = rep [ ( opponent , player ) ] <EOL> coop_counts . append ( iu . compute_normalised_cooperation ( interactions ) [ <NUM_LIT:1> ] ) <EOL> if ( ( player , opponent ) not in rep ) and ( ( opponent , player ) not in rep ) : <EOL> coop_counts . append ( <NUM_LIT:0> ) <EOL> normalised_cooperations [ player ] [ opponent ] = mean ( coop_counts ) <EOL> return normalised_cooperations <EOL> def build_vengeful_cooperation ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ [ <NUM_LIT:2> * ( element - <NUM_LIT:0.5> ) for element in row ] <EOL> for row in self . normalised_cooperation ] <EOL> def build_cooperating_rating ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> total_length_v_opponent = [ zip ( * [ rep [ player_index ] for <EOL> rep in self . match_lengths ] ) <EOL> for player_index in plist ] <EOL> lengths = [ [ sum ( e ) for j , e in enumerate ( row ) if i != j ] for i , row in <EOL> enumerate ( total_length_v_opponent ) ] <EOL> return [ sum ( cs ) / max ( <NUM_LIT:1> , float ( sum ( ls ) ) ) for cs , ls <EOL> in zip ( self . cooperation , lengths ) ] <EOL> def build_good_partner_matrix ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> good_partner_matrix = [ [ <NUM_LIT:0> for opponent in plist ] for player in plist ] <EOL> for player in plist : <EOL> for opponent in plist : <EOL> if player != opponent : <EOL> for rep in self . interactions : <EOL> if ( player , opponent ) in rep : <EOL> interaction = rep [ ( player , opponent ) ] <EOL> coops = iu . compute_cooperations ( interaction ) <EOL> if coops [ <NUM_LIT:0> ] >= coops [ <NUM_LIT:1> ] : <EOL> good_partner_matrix [ player ] [ opponent ] += <NUM_LIT:1> <EOL> if ( opponent , player ) in rep : <EOL> interaction = rep [ ( opponent , player ) ] <EOL> coops = iu . compute_cooperations ( interaction ) <EOL> if coops [ <NUM_LIT:0> ] <= coops [ <NUM_LIT:1> ] : <EOL> good_partner_matrix [ player ] [ opponent ] += <NUM_LIT:1> <EOL> return good_partner_matrix <EOL> def build_good_partner_rating ( self ) : <EOL> """<STR_LIT>""" <EOL> plist = list ( range ( self . nplayers ) ) <EOL> good_partner_rating = [ ] <EOL> for player_index in plist : <EOL> total_interactions = <NUM_LIT:0> <EOL> for rep in self . interactions : <EOL> total_interactions += len ( <EOL> [ pair for pair in rep . keys ( ) <EOL> if player_index in pair and pair [ <NUM_LIT:0> ] != pair [ <NUM_LIT:1> ] ] ) <EOL> rating = sum ( self . good_partner_matrix [ player_index ] ) / max ( <NUM_LIT:1> , float ( total_interactions ) ) <EOL> good_partner_rating . append ( rating ) <EOL> return good_partner_rating <EOL> def build_eigenjesus_rating ( self ) : <EOL> """<STR_LIT>""" <EOL> eigenvector , eigenvalue = eigen . principal_eigenvector ( <EOL> self . normalised_cooperation ) <EOL> return eigenvector . tolist ( ) <EOL> def build_eigenmoses_rating ( self ) : <EOL> """<STR_LIT>""" <EOL> eigenvector , eigenvalue = eigen . principal_eigenvector ( <EOL> self . vengeful_cooperation ) <EOL> return eigenvector . tolist ( ) <EOL> def csv ( self ) : <EOL> """<STR_LIT>""" <EOL> csv_string = StringIO ( ) <EOL> header = "<STR_LIT:U+002C>" . join ( self . ranked_names ) + "<STR_LIT:\n>" <EOL> csv_string . write ( header ) <EOL> writer = csv . writer ( csv_string , lineterminator = "<STR_LIT:\n>" ) <EOL> for irep in range ( self . nrepetitions ) : <EOL> data = [ self . normalised_scores [ rank ] [ irep ] <EOL> for rank in self . ranking ] <EOL> writer . writerow ( list ( map ( str , data ) ) ) <EOL> return csv_string . getvalue ( ) <EOL> class ResultSetFromFile ( ResultSet ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename , with_morality = True ) : <EOL> """<STR_LIT>""" <EOL> self . players , self . interactions = self . _read_csv ( filename ) <EOL> self . nplayers = len ( self . players ) <EOL> self . nrepetitions = len ( self . interactions ) <EOL> self . build_all ( with_morality ) <EOL> def _read_csv ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> players_d = { } <EOL> interactions_d = { } <EOL> with open ( filename , '<STR_LIT:r>' ) as f : <EOL> for row in csv . reader ( f ) : <EOL> index_pair = ( int ( row [ <NUM_LIT:0> ] ) , int ( row [ <NUM_LIT:1> ] ) ) <EOL> players = ( row [ <NUM_LIT:2> ] , row [ <NUM_LIT:3> ] ) <EOL> inters = row [ <NUM_LIT:4> : ] <EOL> for index , player in zip ( index_pair , players ) : <EOL> if index not in players : <EOL> players_d [ index ] = player <EOL> interactions_d [ index_pair ] = [ self . _string_to_interactions ( inter ) <EOL> for inter in inters ] <EOL> nreps = len ( inters ) <EOL> players = [ ] <EOL> for i in range ( len ( players_d ) ) : <EOL> players . append ( players_d [ i ] ) <EOL> interactions = [ ] <EOL> for rep in range ( nreps ) : <EOL> pair_to_interactions_d = { } <EOL> for index_pair , inters in interactions_d . items ( ) : <EOL> pair_to_interactions_d [ index_pair ] = inters [ rep ] <EOL> interactions . append ( pair_to_interactions_d ) <EOL> return players , interactions <EOL> def _string_to_interactions ( self , string ) : <EOL> """<STR_LIT>""" <EOL> return iu . string_to_interactions ( string ) </s>
|
<s> from axelrod import Actions , Player <EOL> C , D = Actions . C , Actions . D <EOL> class MindController ( Player ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> classifier = { <EOL> '<STR_LIT>' : - <NUM_LIT:10> , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False <EOL> } <EOL> @ staticmethod <EOL> def strategy ( opponent ) : <EOL> """<STR_LIT>""" <EOL> opponent . strategy = lambda opponent : C <EOL> return D <EOL> class MindWarper ( Player ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> classifier = { <EOL> '<STR_LIT>' : - <NUM_LIT:10> , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def __setattr__ ( self , name , val ) : <EOL> if name == '<STR_LIT>' : <EOL> pass <EOL> else : <EOL> self . __dict__ [ name ] = val <EOL> @ staticmethod <EOL> def strategy ( opponent ) : <EOL> opponent . strategy = lambda opponent : C <EOL> return D <EOL> class MindBender ( MindWarper ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> classifier = { <EOL> '<STR_LIT>' : - <NUM_LIT:10> , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False <EOL> } <EOL> @ staticmethod <EOL> def strategy ( opponent ) : <EOL> opponent . __dict__ [ '<STR_LIT>' ] = lambda opponent : C <EOL> return D </s>
|
<s> """<STR_LIT>""" <EOL> import unittest <EOL> import axelrod <EOL> class TestEcosystem ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cooperators = axelrod . Tournament ( players = [ <EOL> axelrod . Cooperator ( ) , <EOL> axelrod . Cooperator ( ) , <EOL> axelrod . Cooperator ( ) , <EOL> axelrod . Cooperator ( ) , <EOL> ] ) <EOL> defector_wins = axelrod . Tournament ( players = [ <EOL> axelrod . Cooperator ( ) , <EOL> axelrod . Cooperator ( ) , <EOL> axelrod . Cooperator ( ) , <EOL> axelrod . Defector ( ) , <EOL> ] ) <EOL> cls . res_cooperators = cooperators . play ( ) <EOL> cls . res_defector_wins = defector_wins . play ( ) <EOL> def test_init ( self ) : <EOL> """<STR_LIT>""" <EOL> eco = axelrod . Ecosystem ( self . res_cooperators ) <EOL> pops = eco . population_sizes <EOL> self . assertEqual ( eco . nplayers , <NUM_LIT:4> ) <EOL> self . assertEqual ( len ( pops ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( pops [ <NUM_LIT:0> ] ) , <NUM_LIT:4> ) <EOL> self . assertAlmostEqual ( sum ( pops [ <NUM_LIT:0> ] ) , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( list ( set ( pops [ <NUM_LIT:0> ] ) ) , [ <NUM_LIT> ] ) <EOL> eco = axelrod . Ecosystem ( self . res_cooperators , population = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> pops = eco . population_sizes <EOL> self . assertEqual ( eco . nplayers , <NUM_LIT:4> ) <EOL> self . assertEqual ( len ( pops ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( pops [ <NUM_LIT:0> ] ) , <NUM_LIT:4> ) <EOL> self . assertAlmostEqual ( sum ( pops [ <NUM_LIT:0> ] ) , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( pops [ <NUM_LIT:0> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> eco = axelrod . Ecosystem ( self . res_cooperators , population = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:2> ] ) <EOL> pops = eco . population_sizes <EOL> self . assertEqual ( eco . nplayers , <NUM_LIT:4> ) <EOL> self . assertEqual ( len ( pops ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( pops [ <NUM_LIT:0> ] ) , <NUM_LIT:4> ) <EOL> self . assertAlmostEqual ( sum ( pops [ <NUM_LIT:0> ] ) , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( pops [ <NUM_LIT:0> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . assertRaises ( TypeError , axelrod . Ecosystem , self . res_cooperators , population = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . assertRaises ( TypeError , axelrod . Ecosystem , self . res_cooperators , population = [ <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_fitness ( self ) : <EOL> fitness = lambda p : <NUM_LIT:2> * p <EOL> eco = axelrod . Ecosystem ( self . res_cooperators , fitness = fitness ) <EOL> self . assertTrue ( eco . fitness ( <NUM_LIT:10> ) , <NUM_LIT:20> ) <EOL> def test_cooperators ( self ) : <EOL> """<STR_LIT>""" <EOL> eco = axelrod . Ecosystem ( self . res_cooperators ) <EOL> eco . reproduce ( <NUM_LIT:100> ) <EOL> pops = eco . population_sizes <EOL> self . assertEqual ( len ( pops ) , <NUM_LIT> ) <EOL> for p in pops : <EOL> self . assertEqual ( len ( p ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( sum ( p ) , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( list ( set ( p ) ) , [ <NUM_LIT> ] ) <EOL> def test_defector_wins ( self ) : <EOL> """<STR_LIT>""" <EOL> eco = axelrod . Ecosystem ( self . res_defector_wins ) <EOL> eco . reproduce ( <NUM_LIT:1000> ) <EOL> pops = eco . population_sizes <EOL> self . assertEqual ( len ( pops ) , <NUM_LIT> ) <EOL> for p in pops : <EOL> self . assertEqual ( len ( p ) , <NUM_LIT:4> ) <EOL> self . assertAlmostEqual ( sum ( p ) , <NUM_LIT:1.0> ) <EOL> last = pops [ - <NUM_LIT:1> ] <EOL> self . assertAlmostEqual ( last [ <NUM_LIT:0> ] , <NUM_LIT:0.0> ) <EOL> self . assertAlmostEqual ( last [ <NUM_LIT:1> ] , <NUM_LIT:0.0> ) <EOL> self . assertAlmostEqual ( last [ <NUM_LIT:2> ] , <NUM_LIT:0.0> ) <EOL> self . assertAlmostEqual ( last [ <NUM_LIT:3> ] , <NUM_LIT:1.0> ) </s>
|
<s> """<STR_LIT>""" <EOL> import random <EOL> import axelrod <EOL> from axelrod import simulate_play , Game <EOL> from . test_player import TestPlayer , test_responses <EOL> C , D = axelrod . Actions . C , axelrod . Actions . D <EOL> class TestRiskyQLearner ( TestPlayer ) : <EOL> name = '<STR_LIT>' <EOL> player = axelrod . RiskyQLearner <EOL> expected_classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : set ( [ "<STR_LIT>" ] ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def test_payoff_matrix ( self ) : <EOL> ( R , P , S , T ) = Game ( ) . RPST ( ) <EOL> payoff_matrix = { C : { C : R , D : S } , D : { C : T , D : P } } <EOL> p1 = self . player ( ) <EOL> self . assertEqual ( p1 . payoff_matrix , payoff_matrix ) <EOL> def test_qs_update ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . RiskyQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT> } , '<STR_LIT>' : { C : <NUM_LIT> , D : <NUM_LIT:0> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) <EOL> def test_vs_update ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . RiskyQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Vs , { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Vs , { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> def test_prev_state_updates ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . RiskyQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . prev_state , '<STR_LIT>' ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . prev_state , '<STR_LIT>' ) <EOL> def test_strategy ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . RiskyQLearner ( ) <EOL> p1 . state = '<STR_LIT>' <EOL> p1 . Qs = { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } , '<STR_LIT>' : { C : <NUM_LIT:2> , D : <NUM_LIT:6> } } <EOL> p2 = axelrod . Cooperator ( ) <EOL> test_responses ( self , p1 , p2 , [ ] , [ ] , [ C , D , C , C , D , C , C ] ) <EOL> def test_reset_method ( self ) : <EOL> """<STR_LIT>""" <EOL> P1 = axelrod . RiskyQLearner ( ) <EOL> P1 . Qs = { '<STR_LIT>' : { C : <NUM_LIT:0> , D : - <NUM_LIT> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } <EOL> P1 . Vs = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> P1 . history = [ C , D , D , D ] <EOL> P1 . prev_state = C <EOL> P1 . reset ( ) <EOL> self . assertEqual ( P1 . prev_state , '<STR_LIT>' ) <EOL> self . assertEqual ( P1 . history , [ ] ) <EOL> self . assertEqual ( P1 . Vs , { '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> self . assertEqual ( P1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) <EOL> class TestArrogantQLearner ( TestPlayer ) : <EOL> name = '<STR_LIT>' <EOL> player = axelrod . ArrogantQLearner <EOL> expected_classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : set ( [ "<STR_LIT>" ] ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def test_qs_update ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . ArrogantQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> play_1 , play_2 = simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT> } , '<STR_LIT>' : { C : <NUM_LIT> , D : <NUM_LIT:0> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) <EOL> def test_vs_update ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . ArrogantQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Vs , { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Vs , { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> def test_prev_state_updates ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . ArrogantQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . prev_state , '<STR_LIT>' ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . prev_state , '<STR_LIT>' ) <EOL> def test_strategy ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:9> ) <EOL> p1 = axelrod . ArrogantQLearner ( ) <EOL> p1 . state = '<STR_LIT>' <EOL> p1 . Qs = { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } , '<STR_LIT>' : { C : <NUM_LIT:2> , D : <NUM_LIT:6> } } <EOL> p2 = axelrod . Cooperator ( ) <EOL> test_responses ( self , p1 , p2 , [ ] , [ ] , [ C , C , C , C , C , C , C ] ) <EOL> def test_reset_method ( self ) : <EOL> """<STR_LIT>""" <EOL> P1 = axelrod . ArrogantQLearner ( ) <EOL> P1 . Qs = { '<STR_LIT>' : { C : <NUM_LIT:0> , D : - <NUM_LIT> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } <EOL> P1 . Vs = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> P1 . history = [ C , D , D , D ] <EOL> P1 . prev_state = C <EOL> P1 . reset ( ) <EOL> self . assertEqual ( P1 . prev_state , '<STR_LIT>' ) <EOL> self . assertEqual ( P1 . history , [ ] ) <EOL> self . assertEqual ( P1 . Vs , { '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> self . assertEqual ( P1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) <EOL> class TestHesitantQLearner ( TestPlayer ) : <EOL> name = '<STR_LIT>' <EOL> player = axelrod . HesitantQLearner <EOL> expected_classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : set ( [ "<STR_LIT>" ] ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def test_qs_update ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . HesitantQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0.1> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0.1> } , '<STR_LIT>' : { C : <NUM_LIT> , D : <NUM_LIT:0> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) <EOL> def test_vs_update ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . HesitantQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Vs , { '<STR_LIT>' : <NUM_LIT:0.1> , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Vs , { '<STR_LIT>' : <NUM_LIT:0.1> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> def test_prev_state_updates ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . HesitantQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . prev_state , '<STR_LIT>' ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . prev_state , '<STR_LIT>' ) <EOL> def test_strategy ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:9> ) <EOL> p1 = axelrod . HesitantQLearner ( ) <EOL> p1 . state = '<STR_LIT>' <EOL> p1 . Qs = { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } , '<STR_LIT>' : { C : <NUM_LIT:2> , D : <NUM_LIT:6> } } <EOL> p2 = axelrod . Cooperator ( ) <EOL> test_responses ( self , p1 , p2 , [ ] , [ ] , [ C , C , C , C , C , C , C ] ) <EOL> def test_reset_method ( self ) : <EOL> """<STR_LIT>""" <EOL> P1 = axelrod . HesitantQLearner ( ) <EOL> P1 . Qs = { '<STR_LIT>' : { C : <NUM_LIT:0> , D : - <NUM_LIT> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } <EOL> P1 . Vs = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> P1 . history = [ C , D , D , D ] <EOL> P1 . prev_state = C <EOL> P1 . reset ( ) <EOL> self . assertEqual ( P1 . prev_state , '<STR_LIT>' ) <EOL> self . assertEqual ( P1 . history , [ ] ) <EOL> self . assertEqual ( P1 . Vs , { '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> self . assertEqual ( P1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) <EOL> class TestCautiousQLearner ( TestPlayer ) : <EOL> name = '<STR_LIT>' <EOL> player = axelrod . CautiousQLearner <EOL> expected_classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : set ( [ "<STR_LIT>" ] ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def test_qs_update ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . CautiousQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0.1> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0.1> } , '<STR_LIT>' : { C : <NUM_LIT> , D : <NUM_LIT:0> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0.0> } } ) <EOL> def test_vs_update ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . CautiousQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Vs , { '<STR_LIT>' : <NUM_LIT:0.1> , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . Vs , { '<STR_LIT>' : <NUM_LIT:0.1> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> def test_prev_state_updates ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:5> ) <EOL> p1 = axelrod . CautiousQLearner ( ) <EOL> p2 = axelrod . Cooperator ( ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . prev_state , '<STR_LIT>' ) <EOL> simulate_play ( p1 , p2 ) <EOL> self . assertEqual ( p1 . prev_state , '<STR_LIT>' ) <EOL> def test_strategy ( self ) : <EOL> """<STR_LIT>""" <EOL> random . seed ( <NUM_LIT:9> ) <EOL> p1 = axelrod . CautiousQLearner ( ) <EOL> p1 . state = '<STR_LIT>' <EOL> p1 . Qs = { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } , '<STR_LIT>' : { C : <NUM_LIT:2> , D : <NUM_LIT:6> } } <EOL> p2 = axelrod . Cooperator ( ) <EOL> test_responses ( self , p1 , p2 , [ ] , [ ] , [ C , C , C , C , C , C , C ] ) <EOL> def test_reset_method ( self ) : <EOL> """<STR_LIT>""" <EOL> P1 = axelrod . CautiousQLearner ( ) <EOL> P1 . Qs = { '<STR_LIT>' : { C : <NUM_LIT:0> , D : - <NUM_LIT> } , '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } <EOL> P1 . Vs = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> P1 . history = [ C , D , D , D ] <EOL> P1 . prev_state = C <EOL> P1 . reset ( ) <EOL> self . assertEqual ( P1 . prev_state , '<STR_LIT>' ) <EOL> self . assertEqual ( P1 . history , [ ] ) <EOL> self . assertEqual ( P1 . Vs , { '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> self . assertEqual ( P1 . Qs , { '<STR_LIT>' : { C : <NUM_LIT:0> , D : <NUM_LIT:0> } } ) </s>
|
<s> import json <EOL> import requests <EOL> from azureml . errors import AzureMLConflictHttpError <EOL> try : <EOL> from urlparse import urljoin <EOL> except ImportError : <EOL> from urllib . parse import urljoin <EOL> from azureml . errors import ( <EOL> AzureMLHttpError , <EOL> ) <EOL> __author__ = '<STR_LIT>' <EOL> __version__ = '<STR_LIT>' <EOL> class _RestClient ( object ) : <EOL> SERVICE_ROOT = '<STR_LIT>' <EOL> INTERMEDIATE_DATASET_URI_FMT = SERVICE_ROOT + '<STR_LIT>' <EOL> EXPERIMENTS_URI_FMT = SERVICE_ROOT + '<STR_LIT>' <EOL> DATASOURCES_URI_FMT = SERVICE_ROOT + '<STR_LIT>' <EOL> DATASOURCE_URI_FMT = SERVICE_ROOT + '<STR_LIT>' <EOL> UPLOAD_URI_FMI = SERVICE_ROOT + '<STR_LIT>' <EOL> UPLOAD_CHUNK_URI_FMT = SERVICE_ROOT + '<STR_LIT>' <EOL> SESSION_ID_HEADER_NAME = '<STR_LIT>' <EOL> SESSION_ID_HEADER_VALUE = '<STR_LIT>' <EOL> ACCESS_TOKEN_HEADER_NAME = '<STR_LIT>' <EOL> CONTENT_TYPE_HEADER_NAME = '<STR_LIT:Content-Type>' <EOL> CONTENT_TYPE_HEADER_VALUE_JSON = '<STR_LIT>' <EOL> CHUNK_SIZE = <NUM_LIT> <EOL> DEFAULT_OWNER = '<STR_LIT>' <EOL> USER_AGENT_HEADER_NAME = '<STR_LIT>' <EOL> USER_AGENT_HEADER_VALUE = '<STR_LIT>' + __version__ <EOL> def __init__ ( self , service_endpoint , access_token ) : <EOL> self . _service_endpoint = service_endpoint <EOL> self . _access_token = access_token <EOL> def get_experiments ( self , workspace_id ) : <EOL> """<STR_LIT>""" <EOL> api_path = self . EXPERIMENTS_URI_FMT . format ( workspace_id ) <EOL> return self . _send_get_req ( api_path ) <EOL> def get_datasets ( self , workspace_id ) : <EOL> """<STR_LIT>""" <EOL> api_path = self . DATASOURCES_URI_FMT . format ( workspace_id ) <EOL> return self . _send_get_req ( api_path ) <EOL> def get_dataset ( self , workspace_id , dataset_id ) : <EOL> """<STR_LIT>""" <EOL> api_path = self . DATASOURCE_URI_FMT . format ( workspace_id , dataset_id ) <EOL> return self . _send_get_req ( api_path ) <EOL> def open_intermediate_dataset_contents ( self , workspace_id , experiment_id , <EOL> node_id , port_name ) : <EOL> return self . _get_intermediate_dataset_contents ( <EOL> workspace_id , <EOL> experiment_id , <EOL> node_id , <EOL> port_name , <EOL> stream = True ) . raw <EOL> def read_intermediate_dataset_contents_binary ( self , workspace_id , <EOL> experiment_id , node_id , <EOL> port_name ) : <EOL> return self . _get_intermediate_dataset_contents ( <EOL> workspace_id , <EOL> experiment_id , <EOL> node_id , <EOL> port_name , <EOL> stream = False ) . content <EOL> def read_intermediate_dataset_contents_text ( self , workspace_id , <EOL> experiment_id , node_id , <EOL> port_name ) : <EOL> return self . _get_intermediate_dataset_contents ( <EOL> workspace_id , <EOL> experiment_id , <EOL> node_id , <EOL> port_name , <EOL> stream = False ) . text <EOL> def _get_intermediate_dataset_contents ( self , workspace_id , experiment_id , <EOL> node_id , port_name , stream ) : <EOL> api_path = self . INTERMEDIATE_DATASET_URI_FMT . format ( <EOL> workspace_id , experiment_id , node_id , port_name ) <EOL> response = requests . get ( <EOL> url = urljoin ( self . _service_endpoint , api_path ) , <EOL> headers = self . _get_headers ( ) , <EOL> stream = stream , <EOL> ) <EOL> return response <EOL> def open_dataset_contents ( self , url ) : <EOL> response = requests . get ( url , stream = True ) <EOL> return response . raw <EOL> def read_dataset_contents_binary ( self , url ) : <EOL> response = requests . get ( url ) <EOL> return response . content <EOL> def read_dataset_contents_text ( self , url ) : <EOL> response = requests . get ( url ) <EOL> return response . text <EOL> def upload_dataset ( self , workspace_id , name , description , data_type_id , <EOL> raw_data , family_id ) : <EOL> api_path = self . UPLOAD_URI_FMI . format ( workspace_id , data_type_id ) <EOL> upload_result = self . _send_post_req ( api_path , data = b'<STR_LIT>' ) <EOL> upload_id = upload_result [ "<STR_LIT>" ] <EOL> total_chunks = int ( ( len ( raw_data ) + ( self . CHUNK_SIZE - <NUM_LIT:1> ) ) / self . CHUNK_SIZE ) <EOL> for chunk in range ( total_chunks ) : <EOL> chunk_url = self . UPLOAD_CHUNK_URI_FMT . format ( <EOL> workspace_id , <EOL> total_chunks , <EOL> chunk , <EOL> upload_id , <EOL> data_type_id , <EOL> ) <EOL> chunk_data = raw_data [ chunk * self . CHUNK_SIZE : ( chunk + <NUM_LIT:1> ) * self . CHUNK_SIZE ] <EOL> self . _send_post_req ( chunk_url , data = chunk_data ) <EOL> metadata = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:Name>" : name , <EOL> "<STR_LIT>" : data_type_id , <EOL> "<STR_LIT>" : description , <EOL> "<STR_LIT>" : family_id , <EOL> "<STR_LIT>" : self . DEFAULT_OWNER , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : upload_id , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True <EOL> } <EOL> try : <EOL> api_path = self . DATASOURCES_URI_FMT . format ( workspace_id ) <EOL> except AzureMLConflictHttpError as e : <EOL> raise AzureMLConflictHttpError ( <EOL> '<STR_LIT>' . format ( name ) , <EOL> e . status_code <EOL> ) <EOL> datasource_id = self . _send_post_req ( <EOL> api_path , json . dumps ( metadata ) , self . CONTENT_TYPE_HEADER_VALUE_JSON ) <EOL> return datasource_id <EOL> def _send_get_req ( self , api_path ) : <EOL> response = requests . get ( <EOL> url = urljoin ( self . _service_endpoint , api_path ) , <EOL> headers = self . _get_headers ( ) <EOL> ) <EOL> if response . status_code >= <NUM_LIT> : <EOL> raise AzureMLHttpError ( response . text , response . status_code ) <EOL> return response . json ( ) <EOL> def _send_post_req ( self , api_path , data , content_type = None ) : <EOL> response = requests . post ( <EOL> url = urljoin ( self . _service_endpoint , api_path ) , <EOL> data = data , <EOL> headers = self . _get_headers ( content_type ) <EOL> ) <EOL> if response . status_code >= <NUM_LIT> : <EOL> raise AzureMLHttpError ( response . text , response . status_code ) <EOL> return response . json ( ) <EOL> def _get_headers ( self , content_type = None ) : <EOL> headers = { <EOL> self . USER_AGENT_HEADER_NAME : self . USER_AGENT_HEADER_VALUE , <EOL> self . CONTENT_TYPE_HEADER_NAME : self . CONTENT_TYPE_HEADER_VALUE_JSON , <EOL> self . SESSION_ID_HEADER_NAME : self . SESSION_ID_HEADER_VALUE , <EOL> self . ACCESS_TOKEN_HEADER_NAME : self . _access_token <EOL> } <EOL> if content_type : <EOL> headers [ self . CONTENT_TYPE_HEADER_NAME ] = content_type <EOL> return headers </s>
|
<s> from enum import Enum <EOL> class OSType ( Enum ) : <EOL> linux = "<STR_LIT>" <EOL> windows = "<STR_LIT>" <EOL> unmapped = "<STR_LIT>" <EOL> class CertificateState ( Enum ) : <EOL> active = "<STR_LIT>" <EOL> deleting = "<STR_LIT>" <EOL> deletefailed = "<STR_LIT>" <EOL> class CertificateFormat ( Enum ) : <EOL> pfx = "<STR_LIT>" <EOL> cer = "<STR_LIT>" <EOL> unmapped = "<STR_LIT>" <EOL> class ComputeNodeFillType ( Enum ) : <EOL> spread = "<STR_LIT>" <EOL> pack = "<STR_LIT>" <EOL> unmapped = "<STR_LIT>" <EOL> class CertificateStoreLocation ( Enum ) : <EOL> currentuser = "<STR_LIT>" <EOL> localmachine = "<STR_LIT>" <EOL> unmapped = "<STR_LIT>" <EOL> class CertificateVisibility ( Enum ) : <EOL> starttask = "<STR_LIT>" <EOL> task = "<STR_LIT>" <EOL> remoteuser = "<STR_LIT>" <EOL> unmapped = "<STR_LIT>" <EOL> class PoolLifetimeOption ( Enum ) : <EOL> jobschedule = "<STR_LIT>" <EOL> job = "<STR_LIT>" <EOL> unmapped = "<STR_LIT>" <EOL> class JobScheduleState ( Enum ) : <EOL> active = "<STR_LIT>" <EOL> completed = "<STR_LIT>" <EOL> disabled = "<STR_LIT>" <EOL> terminating = "<STR_LIT>" <EOL> deleting = "<STR_LIT>" <EOL> class SchedulingErrorCategory ( Enum ) : <EOL> usererror = "<STR_LIT>" <EOL> servererror = "<STR_LIT>" <EOL> unmapped = "<STR_LIT>" <EOL> class JobState ( Enum ) : <EOL> active = "<STR_LIT>" <EOL> disabling = "<STR_LIT>" <EOL> disabled = "<STR_LIT>" <EOL> enabling = "<STR_LIT>" <EOL> terminating = "<STR_LIT>" <EOL> completed = "<STR_LIT>" <EOL> deleting = "<STR_LIT>" <EOL> class JobPreparationTaskState ( Enum ) : <EOL> running = "<STR_LIT>" <EOL> completed = "<STR_LIT>" <EOL> class JobReleaseTaskState ( Enum ) : <EOL> running = "<STR_LIT>" <EOL> completed = "<STR_LIT>" <EOL> class PoolState ( Enum ) : <EOL> active = "<STR_LIT>" <EOL> deleting = "<STR_LIT>" <EOL> upgrading = "<STR_LIT>" <EOL> class AllocationState ( Enum ) : <EOL> steady = "<STR_LIT>" <EOL> resizing = "<STR_LIT>" <EOL> stopping = "<STR_LIT>" <EOL> class TaskState ( Enum ) : <EOL> active = "<STR_LIT>" <EOL> preparing = "<STR_LIT>" <EOL> running = "<STR_LIT>" <EOL> completed = "<STR_LIT>" <EOL> class TaskAddStatus ( Enum ) : <EOL> success = "<STR_LIT:success>" <EOL> clienterror = "<STR_LIT>" <EOL> servererror = "<STR_LIT>" <EOL> unmapped = "<STR_LIT>" <EOL> class StartTaskState ( Enum ) : <EOL> running = "<STR_LIT>" <EOL> completed = "<STR_LIT>" <EOL> class ComputeNodeState ( Enum ) : <EOL> idle = "<STR_LIT>" <EOL> rebooting = "<STR_LIT>" <EOL> reimaging = "<STR_LIT>" <EOL> running = "<STR_LIT>" <EOL> unusable = "<STR_LIT>" <EOL> creating = "<STR_LIT>" <EOL> starting = "<STR_LIT>" <EOL> waitingforstarttask = "<STR_LIT>" <EOL> starttaskfailed = "<STR_LIT>" <EOL> unknown = "<STR_LIT>" <EOL> leavingpool = "<STR_LIT>" <EOL> offline = "<STR_LIT>" <EOL> class SchedulingState ( Enum ) : <EOL> enabled = "<STR_LIT>" <EOL> disabled = "<STR_LIT>" <EOL> class DisableJobOption ( Enum ) : <EOL> requeue = "<STR_LIT>" <EOL> terminate = "<STR_LIT>" <EOL> wait = "<STR_LIT>" <EOL> class ComputeNodeDeallocationOption ( Enum ) : <EOL> requeue = "<STR_LIT>" <EOL> terminate = "<STR_LIT>" <EOL> taskcompletion = "<STR_LIT>" <EOL> retaineddata = "<STR_LIT>" <EOL> class ComputeNodeRebootOption ( Enum ) : <EOL> requeue = "<STR_LIT>" <EOL> terminate = "<STR_LIT>" <EOL> taskcompletion = "<STR_LIT>" <EOL> retaineddata = "<STR_LIT>" <EOL> class ComputeNodeReimageOption ( Enum ) : <EOL> requeue = "<STR_LIT>" <EOL> terminate = "<STR_LIT>" <EOL> taskcompletion = "<STR_LIT>" <EOL> retaineddata = "<STR_LIT>" <EOL> class DisableComputeNodeSchedulingOption ( Enum ) : <EOL> requeue = "<STR_LIT>" <EOL> terminate = "<STR_LIT>" <EOL> taskcompletion = "<STR_LIT>" </s>
|
<s> from msrest . serialization import Model <EOL> class ComputeNodeGetRemoteLoginSettingsOptions ( Model ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , timeout = <NUM_LIT:30> , client_request_id = None , return_client_request_id = None , ocp_date = None ) : <EOL> self . timeout = timeout <EOL> self . client_request_id = client_request_id <EOL> self . return_client_request_id = return_client_request_id <EOL> self . ocp_date = ocp_date </s>
|
<s> from msrest . serialization import Model <EOL> class JobEnableOptions ( Model ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , timeout = <NUM_LIT:30> , client_request_id = None , return_client_request_id = None , ocp_date = None , if_match = None , if_none_match = None , if_modified_since = None , if_unmodified_since = None ) : <EOL> self . timeout = timeout <EOL> self . client_request_id = client_request_id <EOL> self . return_client_request_id = return_client_request_id <EOL> self . ocp_date = ocp_date <EOL> self . if_match = if_match <EOL> self . if_none_match = if_none_match <EOL> self . if_modified_since = if_modified_since <EOL> self . if_unmodified_since = if_unmodified_since </s>
|
<s> from msrest . serialization import Model <EOL> class JobScheduleTerminateOptions ( Model ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , timeout = <NUM_LIT:30> , client_request_id = None , return_client_request_id = None , ocp_date = None , if_match = None , if_none_match = None , if_modified_since = None , if_unmodified_since = None ) : <EOL> self . timeout = timeout <EOL> self . client_request_id = client_request_id <EOL> self . return_client_request_id = return_client_request_id <EOL> self . ocp_date = ocp_date <EOL> self . if_match = if_match <EOL> self . if_none_match = if_none_match <EOL> self . if_modified_since = if_modified_since <EOL> self . if_unmodified_since = if_unmodified_since </s>
|
<s> from msrest . serialization import Model <EOL> class PoolEvaluateAutoScaleOptions ( Model ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , timeout = <NUM_LIT:30> , client_request_id = None , return_client_request_id = None , ocp_date = None ) : <EOL> self . timeout = timeout <EOL> self . client_request_id = client_request_id <EOL> self . return_client_request_id = return_client_request_id <EOL> self . ocp_date = ocp_date </s>
|
<s> from msrest . serialization import Model <EOL> class StartTaskInformation ( Model ) : <EOL> """<STR_LIT>""" <EOL> _validation = { <EOL> '<STR_LIT:state>' : { '<STR_LIT>' : True } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : True } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : True } , <EOL> } <EOL> _attribute_map = { <EOL> '<STR_LIT:state>' : { '<STR_LIT:key>' : '<STR_LIT:state>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:int>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:int>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> } <EOL> def __init__ ( self , state , start_time , retry_count , end_time = None , exit_code = None , scheduling_error = None , last_retry_time = None ) : <EOL> self . state = state <EOL> self . start_time = start_time <EOL> self . end_time = end_time <EOL> self . exit_code = exit_code <EOL> self . scheduling_error = scheduling_error <EOL> self . retry_count = retry_count <EOL> self . last_retry_time = last_retry_time </s>
|
<s> from msrest . pipeline import ClientRawResponse <EOL> import uuid <EOL> from . . import models <EOL> class ApplicationOperations ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , client , config , serializer , deserializer ) : <EOL> self . _client = client <EOL> self . _serialize = serializer <EOL> self . _deserialize = deserializer <EOL> self . config = config <EOL> def list ( <EOL> self , application_list_options = None , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> max_results = None <EOL> if application_list_options is not None : <EOL> max_results = application_list_options . max_results <EOL> timeout = None <EOL> if application_list_options is not None : <EOL> timeout = application_list_options . timeout <EOL> client_request_id = None <EOL> if application_list_options is not None : <EOL> client_request_id = application_list_options . client_request_id <EOL> return_client_request_id = None <EOL> if application_list_options is not None : <EOL> return_client_request_id = application_list_options . return_client_request_id <EOL> ocp_date = None <EOL> if application_list_options is not None : <EOL> ocp_date = application_list_options . ocp_date <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> if max_results is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , max_results , '<STR_LIT:int>' ) <EOL> if timeout is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , timeout , '<STR_LIT:int>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> if client_request_id is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , client_request_id , '<STR_LIT:str>' ) <EOL> if return_client_request_id is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , return_client_request_id , '<STR_LIT:bool>' ) <EOL> if ocp_date is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , ocp_date , '<STR_LIT>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> raise models . BatchErrorException ( self . _deserialize , response ) <EOL> return response <EOL> deserialized = models . ApplicationSummaryPaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . ApplicationSummaryPaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def get ( <EOL> self , application_id , application_get_options = None , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> timeout = None <EOL> if application_get_options is not None : <EOL> timeout = application_get_options . timeout <EOL> client_request_id = None <EOL> if application_get_options is not None : <EOL> client_request_id = application_get_options . client_request_id <EOL> return_client_request_id = None <EOL> if application_get_options is not None : <EOL> return_client_request_id = application_get_options . return_client_request_id <EOL> ocp_date = None <EOL> if application_get_options is not None : <EOL> ocp_date = application_get_options . ocp_date <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , application_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> if timeout is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , timeout , '<STR_LIT:int>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> if client_request_id is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , client_request_id , '<STR_LIT:str>' ) <EOL> if return_client_request_id is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , return_client_request_id , '<STR_LIT:bool>' ) <EOL> if ocp_date is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , ocp_date , '<STR_LIT>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> raise models . BatchErrorException ( self . _deserialize , response ) <EOL> deserialized = None <EOL> header_dict = { } <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> header_dict = { <EOL> '<STR_LIT>' : '<STR_LIT:str>' , <EOL> '<STR_LIT>' : '<STR_LIT:str>' , <EOL> '<STR_LIT>' : '<STR_LIT:str>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> client_raw_response . add_headers ( header_dict ) <EOL> return client_raw_response <EOL> return deserialized </s>
|
<s> from msrest . serialization import Model <EOL> class ApplicationCreateParameters ( Model ) : <EOL> """<STR_LIT>""" <EOL> _validation = { <EOL> '<STR_LIT>' : { '<STR_LIT>' : True } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : True } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : True } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : True } , <EOL> } <EOL> _attribute_map = { <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:bool>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> } <EOL> def __init__ ( self , available_to_other_tenants , display_name , homepage , identifier_uris , reply_urls = None , key_credentials = None , password_credentials = None ) : <EOL> self . available_to_other_tenants = available_to_other_tenants <EOL> self . display_name = display_name <EOL> self . homepage = homepage <EOL> self . identifier_uris = identifier_uris <EOL> self . reply_urls = reply_urls <EOL> self . key_credentials = key_credentials <EOL> self . password_credentials = password_credentials </s>
|
<s> from . authorization_management_client import AuthorizationManagementClient , AuthorizationManagementClientConfiguration <EOL> from . version import VERSION <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> __version__ = VERSION </s>
|
<s> VERSION = "<STR_LIT>" </s>
|
<s> from msrest . pipeline import ClientRawResponse <EOL> from msrestazure . azure_exceptions import CloudError <EOL> import uuid <EOL> from . . import models <EOL> class ApplicationOperations ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , client , config , serializer , deserializer ) : <EOL> self . _client = client <EOL> self . _serialize = serializer <EOL> self . _deserialize = deserializer <EOL> self . config = config <EOL> def activate_application_package ( <EOL> self , resource_group_name , account_name , id , version , format , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> parameters = models . ActivateApplicationPackageParameters ( format = format ) <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' , max_length = <NUM_LIT> , min_length = <NUM_LIT:3> , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT:id>' : self . _serialize . url ( "<STR_LIT:id>" , id , '<STR_LIT:str>' ) , <EOL> '<STR_LIT:version>' : self . _serialize . url ( "<STR_LIT:version>" , version , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> body_content = self . _serialize . body ( parameters , '<STR_LIT>' ) <EOL> request = self . _client . post ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , body_content , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def add_application ( <EOL> self , resource_group_name , account_name , application_id , allow_updates = None , display_name = None , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> parameters = None <EOL> if allow_updates is not None or display_name is not None : <EOL> parameters = models . AddApplicationParameters ( allow_updates = allow_updates , display_name = display_name ) <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' , max_length = <NUM_LIT> , min_length = <NUM_LIT:3> , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , application_id , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> if parameters is not None : <EOL> body_content = self . _serialize . body ( parameters , '<STR_LIT>' ) <EOL> else : <EOL> body_content = None <EOL> request = self . _client . put ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , body_content , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def delete_application ( <EOL> self , resource_group_name , account_name , application_id , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' , max_length = <NUM_LIT> , min_length = <NUM_LIT:3> , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , application_id , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . delete ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def get_application ( <EOL> self , resource_group_name , account_name , application_id , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' , max_length = <NUM_LIT> , min_length = <NUM_LIT:3> , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , application_id , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def update_application ( <EOL> self , resource_group_name , account_name , application_id , parameters , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' , max_length = <NUM_LIT> , min_length = <NUM_LIT:3> , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , application_id , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> body_content = self . _serialize . body ( parameters , '<STR_LIT>' ) <EOL> request = self . _client . patch ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , body_content , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def add_application_package ( <EOL> self , resource_group_name , account_name , application_id , version , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' , max_length = <NUM_LIT> , min_length = <NUM_LIT:3> , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , application_id , '<STR_LIT:str>' ) , <EOL> '<STR_LIT:version>' : self . _serialize . url ( "<STR_LIT:version>" , version , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . put ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def delete_application_package ( <EOL> self , resource_group_name , account_name , application_id , version , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' , max_length = <NUM_LIT> , min_length = <NUM_LIT:3> , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , application_id , '<STR_LIT:str>' ) , <EOL> '<STR_LIT:version>' : self . _serialize . url ( "<STR_LIT:version>" , version , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . delete ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def get_application_package ( <EOL> self , resource_group_name , account_name , application_id , version , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' , max_length = <NUM_LIT> , min_length = <NUM_LIT:3> , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , application_id , '<STR_LIT:str>' ) , <EOL> '<STR_LIT:version>' : self . _serialize . url ( "<STR_LIT:version>" , version , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def list ( <EOL> self , resource_group_name , account_name , maxresults = None , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' , max_length = <NUM_LIT> , min_length = <NUM_LIT:3> , pattern = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> if maxresults is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , maxresults , '<STR_LIT:int>' ) <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . ApplicationPaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . ApplicationPaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized </s>
|
<s> from msrest . paging import Paged <EOL> class ProfilePaged ( Paged ) : <EOL> """<STR_LIT>""" <EOL> _attribute_map = { <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT:value>' , '<STR_LIT:type>' : '<STR_LIT>' } <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ProfilePaged , self ) . __init__ ( * args , ** kwargs ) </s>
|
<s> from msrest . serialization import Model <EOL> class BootDiagnosticsInstanceView ( Model ) : <EOL> """<STR_LIT>""" <EOL> _attribute_map = { <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> } <EOL> def __init__ ( self , console_screenshot_blob_uri = None , serial_console_log_blob_uri = None ) : <EOL> self . console_screenshot_blob_uri = console_screenshot_blob_uri <EOL> self . serial_console_log_blob_uri = serial_console_log_blob_uri </s>
|
<s> from msrest . serialization import Model <EOL> class UpgradePolicy ( Model ) : <EOL> """<STR_LIT>""" <EOL> _attribute_map = { <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> } <EOL> def __init__ ( self , mode = None ) : <EOL> self . mode = mode </s>
|
<s> from msrest . serialization import Model <EOL> class VirtualMachineScaleSetOSProfile ( Model ) : <EOL> """<STR_LIT>""" <EOL> _attribute_map = { <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> } <EOL> def __init__ ( self , computer_name_prefix = None , admin_username = None , admin_password = None , custom_data = None , windows_configuration = None , linux_configuration = None , secrets = None ) : <EOL> self . computer_name_prefix = computer_name_prefix <EOL> self . admin_username = admin_username <EOL> self . admin_password = admin_password <EOL> self . custom_data = custom_data <EOL> self . windows_configuration = windows_configuration <EOL> self . linux_configuration = linux_configuration <EOL> self . secrets = secrets </s>
|
<s> from msrest . pipeline import ClientRawResponse <EOL> from msrestazure . azure_exceptions import CloudError <EOL> from msrestazure . azure_operation import AzureOperationPoller <EOL> import uuid <EOL> from . . import models <EOL> class VirtualMachinesOperations ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , client , config , serializer , deserializer ) : <EOL> self . _client = client <EOL> self . _serialize = serializer <EOL> self . _deserialize = deserializer <EOL> self . config = config <EOL> def capture ( <EOL> self , resource_group_name , vm_name , parameters , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> body_content = self . _serialize . body ( parameters , '<STR_LIT>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . post ( url , query_parameters ) <EOL> return self . _client . send ( <EOL> request , header_parameters , body_content , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT:200> , <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) <EOL> def create_or_update ( <EOL> self , resource_group_name , vm_name , parameters , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> body_content = self . _serialize . body ( parameters , '<STR_LIT>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . put ( url , query_parameters ) <EOL> return self . _client . send ( <EOL> request , header_parameters , body_content , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT:200> , <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if response . status_code == <NUM_LIT> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) <EOL> def delete ( <EOL> self , resource_group_name , vm_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . delete ( url , query_parameters ) <EOL> return self . _client . send ( request , header_parameters , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT> , <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) <EOL> def get ( <EOL> self , resource_group_name , vm_name , expand = None , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> if expand is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , expand , '<STR_LIT>' ) <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def deallocate ( <EOL> self , resource_group_name , vm_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . post ( url , query_parameters ) <EOL> return self . _client . send ( request , header_parameters , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) <EOL> def generalize ( <EOL> self , resource_group_name , vm_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . post ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def list ( <EOL> self , resource_group_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . VirtualMachinePaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . VirtualMachinePaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def list_all ( <EOL> self , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . VirtualMachinePaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . VirtualMachinePaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def list_available_sizes ( <EOL> self , resource_group_name , vm_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . VirtualMachineSizePaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . VirtualMachineSizePaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def power_off ( <EOL> self , resource_group_name , vm_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . post ( url , query_parameters ) <EOL> return self . _client . send ( request , header_parameters , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) <EOL> def restart ( <EOL> self , resource_group_name , vm_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . post ( url , query_parameters ) <EOL> return self . _client . send ( request , header_parameters , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) <EOL> def start ( <EOL> self , resource_group_name , vm_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . post ( url , query_parameters ) <EOL> return self . _client . send ( request , header_parameters , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) <EOL> def redeploy ( <EOL> self , resource_group_name , vm_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , vm_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . post ( url , query_parameters ) <EOL> return self . _client . send ( request , header_parameters , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) </s>
|
<s> from msrest . pipeline import ClientRawResponse <EOL> from msrestazure . azure_exceptions import CloudError <EOL> from msrestazure . azure_operation import AzureOperationPoller <EOL> import uuid <EOL> from . . import models <EOL> class AccountOperations ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , client , config , serializer , deserializer ) : <EOL> self . _client = client <EOL> self . _serialize = serializer <EOL> self . _deserialize = deserializer <EOL> self . config = config <EOL> def get_storage_account ( <EOL> self , resource_group_name , account_name , storage_account_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , storage_account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def delete_storage_account ( <EOL> self , resource_group_name , account_name , storage_account_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , storage_account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . delete ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def update_storage_account ( <EOL> self , resource_group_name , account_name , storage_account_name , properties , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> parameters = models . AddStorageAccountParameters ( properties = properties ) <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , storage_account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> body_content = self . _serialize . body ( parameters , '<STR_LIT>' ) <EOL> request = self . _client . patch ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , body_content , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def add_storage_account ( <EOL> self , resource_group_name , account_name , storage_account_name , properties , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> parameters = models . AddStorageAccountParameters ( properties = properties ) <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , storage_account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> body_content = self . _serialize . body ( parameters , '<STR_LIT>' ) <EOL> request = self . _client . put ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , body_content , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def get_storage_container ( <EOL> self , resource_group_name , account_name , storage_account_name , container_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , storage_account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , container_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def list_storage_containers ( <EOL> self , resource_group_name , account_name , storage_account_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , storage_account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . BlobContainerPaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . BlobContainerPaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def storage_containers_list_next ( <EOL> self , next_link , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , next_link , '<STR_LIT:str>' , skip_quote = True ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . BlobContainerPaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . BlobContainerPaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def sas_tokens_list_next ( <EOL> self , next_link , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , next_link , '<STR_LIT:str>' , skip_quote = True ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . post ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . SasTokenInfoPaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . SasTokenInfoPaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def list_sas_tokens ( <EOL> self , resource_group_name , account_name , storage_account_name , container_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , storage_account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , container_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . post ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . SasTokenInfoPaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . SasTokenInfoPaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def get_data_lake_store_account ( <EOL> self , resource_group_name , account_name , data_lake_store_account_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , data_lake_store_account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def delete_data_lake_store_account ( <EOL> self , resource_group_name , account_name , data_lake_store_account_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , data_lake_store_account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . delete ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def add_data_lake_store_account ( <EOL> self , resource_group_name , account_name , data_lake_store_account_name , properties , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> parameters = models . AddDataLakeStoreParameters ( properties = properties ) <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , data_lake_store_account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> body_content = self . _serialize . body ( parameters , '<STR_LIT>' ) <EOL> request = self . _client . put ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , body_content , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> def list_storage_accounts ( <EOL> self , resource_group_name , account_name , filter = None , top = None , skip = None , expand = None , select = None , orderby = None , count = None , search = None , format = None , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> if filter is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , filter , '<STR_LIT:str>' ) <EOL> if top is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , top , '<STR_LIT:int>' ) <EOL> if skip is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , skip , '<STR_LIT:int>' ) <EOL> if expand is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , expand , '<STR_LIT:str>' ) <EOL> if select is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , select , '<STR_LIT:str>' ) <EOL> if orderby is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , orderby , '<STR_LIT:str>' ) <EOL> if count is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT:count>" , count , '<STR_LIT:bool>' ) <EOL> if search is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , search , '<STR_LIT:str>' ) <EOL> if format is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , format , '<STR_LIT:str>' ) <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . StorageAccountInfoPaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . StorageAccountInfoPaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def list_data_lake_store_accounts ( <EOL> self , resource_group_name , account_name , filter = None , top = None , skip = None , expand = None , select = None , orderby = None , count = None , search = None , format = None , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> if filter is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , filter , '<STR_LIT:str>' ) <EOL> if top is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , top , '<STR_LIT:int>' ) <EOL> if skip is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , skip , '<STR_LIT:int>' ) <EOL> if expand is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , expand , '<STR_LIT:str>' ) <EOL> if select is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , select , '<STR_LIT:str>' ) <EOL> if orderby is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , orderby , '<STR_LIT:str>' ) <EOL> if count is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT:count>" , count , '<STR_LIT:bool>' ) <EOL> if search is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , search , '<STR_LIT:str>' ) <EOL> if format is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , format , '<STR_LIT:str>' ) <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . DataLakeStoreAccountInfoPaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . DataLakeStoreAccountInfoPaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def list_by_resource_group ( <EOL> self , resource_group_name , filter = None , top = None , skip = None , expand = None , select = None , orderby = None , count = None , search = None , format = None , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> if filter is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , filter , '<STR_LIT:str>' ) <EOL> if top is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , top , '<STR_LIT:int>' ) <EOL> if skip is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , skip , '<STR_LIT:int>' ) <EOL> if expand is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , expand , '<STR_LIT:str>' ) <EOL> if select is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , select , '<STR_LIT:str>' ) <EOL> if orderby is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , orderby , '<STR_LIT:str>' ) <EOL> if count is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT:count>" , count , '<STR_LIT:bool>' ) <EOL> if search is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , search , '<STR_LIT:str>' ) <EOL> if format is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , format , '<STR_LIT:str>' ) <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . DataLakeAnalyticsAccountPaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . DataLakeAnalyticsAccountPaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def list ( <EOL> self , filter = None , top = None , skip = None , expand = None , select = None , orderby = None , count = None , search = None , format = None , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> def internal_paging ( next_link = None , raw = False ) : <EOL> if not next_link : <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> if filter is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , filter , '<STR_LIT:str>' ) <EOL> if top is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , top , '<STR_LIT:int>' ) <EOL> if skip is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , skip , '<STR_LIT:int>' ) <EOL> if expand is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , expand , '<STR_LIT:str>' ) <EOL> if select is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , select , '<STR_LIT:str>' ) <EOL> if orderby is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , orderby , '<STR_LIT:str>' ) <EOL> if count is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT:count>" , count , '<STR_LIT:bool>' ) <EOL> if search is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , search , '<STR_LIT:str>' ) <EOL> if format is not None : <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , format , '<STR_LIT:str>' ) <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> else : <EOL> url = next_link <EOL> query_parameters = { } <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> return response <EOL> deserialized = models . DataLakeAnalyticsAccountPaged ( internal_paging , self . _deserialize . dependencies ) <EOL> if raw : <EOL> header_dict = { } <EOL> client_raw_response = models . DataLakeAnalyticsAccountPaged ( internal_paging , self . _deserialize . dependencies , header_dict ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def get ( <EOL> self , resource_group_name , account_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> request = self . _client . get ( url , query_parameters ) <EOL> response = self . _client . send ( request , header_parameters , ** operation_config ) <EOL> if response . status_code not in [ <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> def delete ( <EOL> self , resource_group_name , account_name , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , account_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . delete ( url , query_parameters ) <EOL> return self . _client . send ( request , header_parameters , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT:200> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( None , response ) <EOL> return client_raw_response <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) <EOL> def create ( <EOL> self , resource_group_name , name , parameters , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT:name>' : self . _serialize . url ( "<STR_LIT:name>" , name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> body_content = self . _serialize . body ( parameters , '<STR_LIT>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . put ( url , query_parameters ) <EOL> return self . _client . send ( <EOL> request , header_parameters , body_content , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT> , <NUM_LIT:200> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) <EOL> def update ( <EOL> self , resource_group_name , name , parameters , custom_headers = { } , raw = False , ** operation_config ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' <EOL> path_format_arguments = { <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , resource_group_name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT:name>' : self . _serialize . url ( "<STR_LIT:name>" , name , '<STR_LIT:str>' ) , <EOL> '<STR_LIT>' : self . _serialize . url ( "<STR_LIT>" , self . config . subscription_id , '<STR_LIT:str>' ) <EOL> } <EOL> url = self . _client . format_url ( url , ** path_format_arguments ) <EOL> query_parameters = { } <EOL> query_parameters [ '<STR_LIT>' ] = self . _serialize . query ( "<STR_LIT>" , self . config . api_version , '<STR_LIT:str>' ) <EOL> header_parameters = { } <EOL> header_parameters [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if self . config . generate_client_request_id : <EOL> header_parameters [ '<STR_LIT>' ] = str ( uuid . uuid1 ( ) ) <EOL> if custom_headers : <EOL> header_parameters . update ( custom_headers ) <EOL> if self . config . accept_language is not None : <EOL> header_parameters [ '<STR_LIT>' ] = self . _serialize . header ( "<STR_LIT>" , self . config . accept_language , '<STR_LIT:str>' ) <EOL> body_content = self . _serialize . body ( parameters , '<STR_LIT>' ) <EOL> def long_running_send ( ) : <EOL> request = self . _client . patch ( url , query_parameters ) <EOL> return self . _client . send ( <EOL> request , header_parameters , body_content , ** operation_config ) <EOL> def get_long_running_status ( status_link , headers = { } ) : <EOL> request = self . _client . get ( status_link ) <EOL> request . headers . update ( headers ) <EOL> return self . _client . send ( <EOL> request , header_parameters , ** operation_config ) <EOL> def get_long_running_output ( response ) : <EOL> if response . status_code not in [ <NUM_LIT:200> , <NUM_LIT> ] : <EOL> exp = CloudError ( response ) <EOL> exp . request_id = response . headers . get ( '<STR_LIT>' ) <EOL> raise exp <EOL> deserialized = None <EOL> if response . status_code == <NUM_LIT:200> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if response . status_code == <NUM_LIT> : <EOL> deserialized = self . _deserialize ( '<STR_LIT>' , response ) <EOL> if raw : <EOL> client_raw_response = ClientRawResponse ( deserialized , response ) <EOL> return client_raw_response <EOL> return deserialized <EOL> if raw : <EOL> response = long_running_send ( ) <EOL> return get_long_running_output ( response ) <EOL> long_running_operation_timeout = operation_config . get ( <EOL> '<STR_LIT>' , <EOL> self . config . long_running_operation_timeout ) <EOL> return AzureOperationPoller ( <EOL> long_running_send , get_long_running_output , <EOL> get_long_running_status , long_running_operation_timeout ) </s>
|
<s> from . catalog_item import CatalogItem <EOL> class USqlSchema ( CatalogItem ) : <EOL> """<STR_LIT>""" <EOL> _attribute_map = { <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT:version>' : { '<STR_LIT:key>' : '<STR_LIT:version>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT:name>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> } <EOL> def __init__ ( self , compute_account_name = None , version = None , database_name = None , name = None ) : <EOL> super ( USqlSchema , self ) . __init__ ( compute_account_name = compute_account_name , version = version ) <EOL> self . database_name = database_name <EOL> self . name = name </s>
|
<s> from msrest . serialization import Model <EOL> class JobResource ( Model ) : <EOL> """<STR_LIT>""" <EOL> _attribute_map = { <EOL> '<STR_LIT:name>' : { '<STR_LIT:key>' : '<STR_LIT:name>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT:type>' : { '<STR_LIT:key>' : '<STR_LIT:type>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> } <EOL> def __init__ ( self , name = None , resource_path = None , type = None ) : <EOL> self . name = name <EOL> self . resource_path = resource_path <EOL> self . type = type </s>
|
<s> from . file_operation_result import FileOperationResult <EOL> from . acl_status import AclStatus <EOL> from . acl_status_result import AclStatusResult <EOL> from . content_summary import ContentSummary <EOL> from . content_summary_result import ContentSummaryResult <EOL> from . file_status_properties import FileStatusProperties <EOL> from . file_statuses import FileStatuses <EOL> from . file_statuses_result import FileStatusesResult <EOL> from . file_status_result import FileStatusResult <EOL> from . data_lake_store_file_system_management_client_enums import ( <EOL> FileType , <EOL> AppendModeType , <EOL> ) <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] </s>
|
<s> from msrest . paging import Paged <EOL> class WorkflowAccessKeyPaged ( Paged ) : <EOL> """<STR_LIT>""" <EOL> _attribute_map = { <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT:value>' , '<STR_LIT:type>' : '<STR_LIT>' } <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( WorkflowAccessKeyPaged , self ) . __init__ ( * args , ** kwargs ) </s>
|
<s> VERSION = "<STR_LIT>" </s>
|
<s> from msrest . serialization import Model <EOL> class Error ( Model ) : <EOL> """<STR_LIT>""" <EOL> _attribute_map = { <EOL> '<STR_LIT:code>' : { '<STR_LIT:key>' : '<STR_LIT:code>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT:message>' : { '<STR_LIT:key>' : '<STR_LIT:message>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT:target>' : { '<STR_LIT:key>' : '<STR_LIT:target>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> } <EOL> def __init__ ( self , code = None , message = None , target = None , details = None , inner_error = None ) : <EOL> self . code = code <EOL> self . message = message <EOL> self . target = target <EOL> self . details = details <EOL> self . inner_error = inner_error </s>
|
<s> from . resource import Resource <EOL> class LocalNetworkGateway ( Resource ) : <EOL> """<STR_LIT>""" <EOL> _validation = { <EOL> '<STR_LIT:name>' : { '<STR_LIT>' : True } , <EOL> '<STR_LIT:type>' : { '<STR_LIT>' : True } , <EOL> } <EOL> _attribute_map = { <EOL> '<STR_LIT:id>' : { '<STR_LIT:key>' : '<STR_LIT:id>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT:name>' : { '<STR_LIT:key>' : '<STR_LIT:name>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT:type>' : { '<STR_LIT:key>' : '<STR_LIT:type>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT:location>' : { '<STR_LIT:key>' : '<STR_LIT:location>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> } <EOL> def __init__ ( self , id = None , location = None , tags = None , local_network_address_space = None , gateway_ip_address = None , bgp_settings = None , resource_guid = None , provisioning_state = None , etag = None ) : <EOL> super ( LocalNetworkGateway , self ) . __init__ ( id = id , location = location , tags = tags ) <EOL> self . local_network_address_space = local_network_address_space <EOL> self . gateway_ip_address = gateway_ip_address <EOL> self . bgp_settings = bgp_settings <EOL> self . resource_guid = resource_guid <EOL> self . provisioning_state = provisioning_state <EOL> self . etag = etag </s>
|
<s> from . sub_resource import SubResource <EOL> class VirtualNetworkGatewayIPConfiguration ( SubResource ) : <EOL> """<STR_LIT>""" <EOL> _attribute_map = { <EOL> '<STR_LIT:id>' : { '<STR_LIT:key>' : '<STR_LIT:id>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT:name>' : { '<STR_LIT:key>' : '<STR_LIT:name>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> } <EOL> def __init__ ( self , id = None , private_ip_address = None , private_ip_allocation_method = None , subnet = None , public_ip_address = None , provisioning_state = None , name = None , etag = None ) : <EOL> super ( VirtualNetworkGatewayIPConfiguration , self ) . __init__ ( id = id ) <EOL> self . private_ip_address = private_ip_address <EOL> self . private_ip_allocation_method = private_ip_allocation_method <EOL> self . subnet = subnet <EOL> self . public_ip_address = public_ip_address <EOL> self . provisioning_state = provisioning_state <EOL> self . name = name <EOL> self . etag = etag </s>
|
<s> from setuptools import setup <EOL> try : <EOL> import azure <EOL> try : <EOL> ver = azure . __version__ <EOL> raise Exception ( <EOL> '<STR_LIT>' . format ( ver ) + <EOL> '<STR_LIT>' <EOL> ) <EOL> except AttributeError : <EOL> pass <EOL> except ImportError : <EOL> pass <EOL> setup ( <EOL> name = '<STR_LIT>' , <EOL> version = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> long_description = open ( '<STR_LIT>' , '<STR_LIT:r>' ) . read ( ) , <EOL> license = '<STR_LIT>' , <EOL> author = '<STR_LIT>' , <EOL> author_email = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> classifiers = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> zip_safe = False , <EOL> packages = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> install_requires = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> ) </s>
|
<s> from msrest . paging import Paged <EOL> class SharedAccessAuthorizationRuleResourcePaged ( Paged ) : <EOL> """<STR_LIT>""" <EOL> _attribute_map = { <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT:str>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:key>' : '<STR_LIT:value>' , '<STR_LIT:type>' : '<STR_LIT>' } <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( SharedAccessAuthorizationRuleResourcePaged , self ) . __init__ ( * args , ** kwargs ) </s>
|
<s> from . feature_client import FeatureClient , FeatureClientConfiguration <EOL> from . version import VERSION <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> __version__ = VERSION </s>
|