<s> import sublime <EOL> import sublime_plugin <EOL> import random <EOL> import datetime <EOL> import string <EOL> import os <EOL> import uuid <EOL> PACKAGES_PATH = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> def get_settings ( ) : <EOL> return sublime . load_settings ( '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> class RandomWindow ( sublime_plugin . WindowCommand ) : <EOL> def get_range ( self , input ) : <EOL> try : <EOL> start , stop = input . split ( '<STR_LIT:->' ) <EOL> start = int ( start ) <EOL> stop = int ( stop ) <EOL> self . insert ( { '<STR_LIT:start>' : start , '<STR_LIT>' : stop } ) <EOL> except : <EOL> sublime . error_message ( '<STR_LIT>' ) <EOL> def insert ( self , kwargs ) : <EOL> view = self . window . active_view ( ) <EOL> view . run_command ( self . text_command , kwargs ) <EOL> '''<STR_LIT>''' <EOL> class RandomText ( sublime_plugin . TextCommand ) : <EOL> def insert ( self , view , generator ) : <EOL> sels = self . view . sel ( ) <EOL> for region in sels : <EOL> output = generator ( ) <EOL> self . view . insert ( view , region . begin ( ) , output ) <EOL> def get_data_file ( self , filename ) : <EOL> words = [ ] <EOL> word_file = os . path . join ( PACKAGES_PATH + '<STR_LIT>' , filename ) <EOL> with open ( word_file ) as f : <EOL> words = f . read ( ) . splitlines ( ) <EOL> return words <EOL> def get_words ( self ) : <EOL> return self . get_data_file ( '<STR_LIT>' ) <EOL> def get_first_names ( self ) : <EOL> return self . get_data_file ( '<STR_LIT>' ) <EOL> def get_last_names ( self ) : <EOL> return self . get_data_file ( '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> class RandomIntWindowCommand ( RandomWindow ) : <EOL> def run ( self ) : <EOL> self . text_command = '<STR_LIT>' <EOL> self . window . show_input_panel ( '<STR_LIT>' , '<STR_LIT>' , self . get_range , None , None ) <EOL> class RandomFloatWindowCommand ( RandomWindow ) : <EOL> def run ( self ) : <EOL> self . text_command = '<STR_LIT>' <EOL> self . window . show_input_panel ( '<STR_LIT>' , '<STR_LIT>' , self . get_range , None , None ) <EOL> '''<STR_LIT>''' <EOL> '''<STR_LIT>''' <EOL> class RandomIntCommand ( RandomText ) : <EOL> def generate_int ( self ) : <EOL> output = random . randint ( self . start , self . stop ) <EOL> return str ( output ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . start = kwargs [ '<STR_LIT:start>' ] <EOL> self . stop = kwargs [ '<STR_LIT>' ] <EOL> self . insert ( view , self . generate_int ) <EOL> class RandomFloatCommand ( RandomText ) : <EOL> def generate_float ( self ) : <EOL> output = random . uniform ( self . start , self . stop ) <EOL> output = '<STR_LIT>' . format ( output ) <EOL> return str ( output ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . start = kwargs [ '<STR_LIT:start>' ] <EOL> self . stop = kwargs [ '<STR_LIT>' ] <EOL> self . insert ( view , self . generate_float ) <EOL> class RandomLetterCommand ( RandomText ) : <EOL> def generate_letters ( self ) : <EOL> upper_range = random . randint ( <NUM_LIT:3> , <NUM_LIT:20> ) <EOL> output = '<STR_LIT>' <EOL> for letter in range ( <NUM_LIT:0> , upper_range ) : <EOL> output += random . choice ( string . ascii_letters ) <EOL> return output <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_letters ) <EOL> class RandomLetterAndNumberCommand ( RandomText ) : <EOL> def generate_letters_and_numbers ( self ) : <EOL> upper_range = random . randint ( <NUM_LIT:3> , <NUM_LIT:20> ) <EOL> output = '<STR_LIT>' <EOL> for letter in range ( <NUM_LIT:0> , upper_range ) : <EOL> output += random . choice ( string . ascii_letters + string . digits ) <EOL> return output <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_letters_and_numbers ) <EOL> class RandomWordCommand ( RandomText ) : <EOL> def generate_word ( self ) : <EOL> words = self . get_words ( ) <EOL> return random . choice ( words ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_word ) <EOL> class RandomTextCommand ( RandomText ) : <EOL> def generate_text ( self ) : <EOL> words = self . get_words ( ) <EOL> return '<STR_LIT:U+0020>' . join ( [ random . choice ( words ) for i in range ( <NUM_LIT:0> , <NUM_LIT> ) ] ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_text ) <EOL> class RandomUuidCommand ( RandomText ) : <EOL> def generate_uuid ( self ) : <EOL> return str ( uuid . uuid4 ( ) ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_uuid ) <EOL> class RandomFirstNameCommand ( RandomText ) : <EOL> def generate_first_name ( self ) : <EOL> first_names = self . get_first_names ( ) <EOL> return random . choice ( first_names ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_first_name ) <EOL> class RandomLastNameCommand ( RandomText ) : <EOL> def generate_last_name ( self ) : <EOL> last_names = self . get_last_names ( ) <EOL> return random . choice ( last_names ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_last_name ) <EOL> class RandomFullNameCommand ( RandomText ) : <EOL> def generate_full_name ( self ) : <EOL> first_names = self . get_first_names ( ) <EOL> last_names = self . get_last_names ( ) <EOL> return '<STR_LIT>' % ( random . choice ( first_names ) , random . choice ( last_names ) ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_full_name ) <EOL> class RandomUrlCommand ( RandomText ) : <EOL> def generate_url ( self ) : <EOL> r_words = [ random . choice ( self . get_words ( ) ) for i in range ( <NUM_LIT:0> , <NUM_LIT:7> ) ] <EOL> scheme = random . choice ( [ '<STR_LIT:http>' , '<STR_LIT>' ] ) <EOL> domain = r_words [ <NUM_LIT:0> ] <EOL> path = '<STR_LIT:/>' . join ( r_words [ <NUM_LIT:1> : <NUM_LIT:3> ] ) <EOL> query = '<STR_LIT>' % ( r_words [ <NUM_LIT:4> ] , r_words [ <NUM_LIT:5> ] ) <EOL> fragment = r_words [ <NUM_LIT:6> ] <EOL> url = '<STR_LIT>' % ( scheme , domain , path , query , fragment ) <EOL> return url . lower ( ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_url ) <EOL> class RandomEmailCommand ( RandomText ) : <EOL> def generate_email ( self ) : <EOL> settings = get_settings ( ) <EOL> u_name = self . get_words ( ) <EOL> u_name = random . choice ( u_name ) <EOL> domain = settings . get ( '<STR_LIT>' , self . get_words ( ) ) <EOL> domain = random . choice ( domain ) <EOL> seq = settings . get ( '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top_domain = random . choice ( seq ) <EOL> email = '<STR_LIT>' % ( u_name , domain , top_domain ) <EOL> return email . lower ( ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_email ) <EOL> class RandomHexColorCommand ( RandomText ) : <EOL> def generate_hex_color ( self ) : <EOL> return '<STR_LIT>' % random . randint ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_hex_color ) <EOL> class RandomDateCommand ( RandomText ) : <EOL> def generate_random_date ( self ) : <EOL> max_year = get_settings ( ) . get ( '<STR_LIT>' , ( datetime . datetime . now ( ) . year , ) ) [ <NUM_LIT:0> ] <EOL> min_year = get_settings ( ) . get ( '<STR_LIT>' , ( <NUM_LIT> , ) ) [ <NUM_LIT:0> ] <EOL> year = random . randint ( min_year , max_year ) <EOL> month = random . randint ( <NUM_LIT:1> , <NUM_LIT:12> ) <EOL> day = random . randint ( <NUM_LIT:1> , <NUM_LIT> ) <EOL> date = datetime . date ( year , month , day ) <EOL> return date . isoformat ( ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_random_date ) <EOL> class RandomIpv4AddressCommand ( RandomText ) : <EOL> def generate_ipv4_address ( self ) : <EOL> return "<STR_LIT>" % ( random . randint ( <NUM_LIT:0> , <NUM_LIT:255> ) , random . randint ( <NUM_LIT:0> , <NUM_LIT:255> ) , random . randint ( <NUM_LIT:0> , <NUM_LIT:255> ) , random . randint ( <NUM_LIT:0> , <NUM_LIT:255> ) ) <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_ipv4_address ) <EOL> class RandomIpv6AddressCommand ( RandomText ) : <EOL> def generate_hexbyte ( self ) : <EOL> choice = "<STR_LIT>" <EOL> return "<STR_LIT>" % ( random . choice ( choice ) , random . choice ( choice ) ) <EOL> def generate_ipv6_address ( self ) : <EOL> address = "<STR_LIT>" <EOL> for x in range ( <NUM_LIT:0> , <NUM_LIT:8> ) : <EOL> address += self . generate_hexbyte ( ) <EOL> address += self . generate_hexbyte ( ) <EOL> if x < <NUM_LIT:7> : <EOL> address += "<STR_LIT::>" <EOL> return address <EOL> def run ( self , view , ** kwargs ) : <EOL> self . insert ( view , self . generate_ipv6_address ) <EOL> '''<STR_LIT>''' </s>
