Module Expr Str Import alias Assign NameStore Str Assign NameStore Num Assign NameStore NameLoad Assign NameStore Num TryExcept body ImportFrom alias Assign NameStore Call NameLoad NameLoad Str NameLoad Assign NameStore Call NameLoad NameLoad Str NameLoad Assign NameStore Call NameLoad NameLoad Str NameLoad Assign NameStore Call NameLoad NameLoad Str NameLoad handlers ExceptHandler type NameLoad body Pass ClassDef bases NameLoad body FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults NameLoad NameLoad NameLoad Num body Assign AttributeStore NameLoad attr BoolOpOr NameLoad NameLoad Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr Assign NameStore BoolOpOr NameLoad NameLoad Assign AttributeStore NameLoad attr BinOpSub BinOpPow AttributeLoad NameLoad attr NameLoad Num Assign AttributeStore NameLoad attr BoolOpOr NameLoad NameLoad Assign AttributeStore NameLoad attr Dict Assign AttributeStore NameLoad attr Dict Assign AttributeStore NameLoad attr BoolOpOr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore AttributeLoad NameLoad attr While CompareGt NameLoad NameLoad body AugAssignMult NameStore AttributeLoad NameLoad attr Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str If CompareIn NameLoad AttributeLoad NameLoad attr body Return SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr NameLoad Assign NameStore BoolOpOr BoolOpAnd CompareGt Call NameLoad AttributeLoad NameLoad attr Num BinOpDiv Call NameLoad AttributeLoad NameLoad attr Num Num For NameStore Call NameLoad NameLoad Num Num body If CompareEq BinOpMod NameLoad NameLoad Num body Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad NameLoad Return NameLoad For NameStore Call NameLoad NameLoad BinOpAdd NameLoad Num Num body If CompareEq BinOpMod NameLoad NameLoad Num body Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad NameLoad Return NameLoad For NameStore ListLoad Num Num Num Num Num body If CompareEq BinOpMod NameLoad NameLoad Num body Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad NameLoad Return NameLoad Raise NameLoad BinOpMod Str NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Return BinOpSub BinOpDiv BinOpMult NameLoad AttributeLoad NameLoad attr Num Num decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Return BinOpAdd BinOpMod BinOpMult BinOpAdd NameLoad NameLoad BinOpDiv NameLoad NameLoad BinOpAdd NameLoad Num Num decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore Str While BoolOpOr BoolOpAnd AttributeLoad NameLoad attr CompareLtE Call NameLoad NameLoad AttributeLoad NameLoad attr CompareLtE BinOpPow AttributeLoad NameLoad attr Call NameLoad NameLoad NameLoad body Assign NameStore BinOpAdd SubscriptLoad AttributeLoad NameLoad attr Index BinOpMod NameLoad AttributeLoad NameLoad attr NameLoad Assign NameStore BinOpDiv NameLoad AttributeLoad NameLoad attr Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str If CompareLt NameLoad Num body Return NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Return Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call NameLoad ImportFrom alias Assign NameStore Call NameLoad For NameStore Call NameLoad BinOpAdd NameLoad Num body If CompareIn Call AttributeLoad NameLoad attr NameLoad NameLoad body Print NameLoad Return NameLoad Assign SubscriptStore NameLoad Index Call AttributeLoad NameLoad attr NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults NameLoad body Expr Str If UnaryOpNot NameLoad body Assign NameStore Num ImportFrom alias Assign NameStore Call NameLoad BinOpMod Str NameLoad Str Print Call AttributeLoad NameLoad attr keyword Num decorator_list If CompareEq NameLoad Str body Print Str Assign NameStore Call NameLoad Print Num Call AttributeLoad NameLoad attr Num Print Num Call AttributeLoad NameLoad attr Num Print Num Call AttributeLoad NameLoad attr Num Print Num Call AttributeLoad NameLoad attr Num Print Num Call AttributeLoad NameLoad attr Num Print Num Call AttributeLoad NameLoad attr Num Print Str Call AttributeLoad NameLoad attr BinOpSub BinOpPow Num Num Num Print Str Call AttributeLoad NameLoad attr BinOpPow Num Num Print Str Call AttributeLoad NameLoad attr Num Print Str Call AttributeLoad NameLoad attr Num
N/A N/A  Generates and decodes a unique ID, which can use characters to shorten its
    length.

     Author: Will Hardy
       Date: December 2008
      Usage: >>> encode(1)
             "KSR68"
Description: Invoice numbers like "0000004" are unprofessional in that they 
             expose how many sales a system has made, and can be used to monitor
             the rate of sales over a given time.  They are also harder for 
             customers to read back to you, especially if they are 10 digits 
             long.  
             These functions convert an integer (from eg an ID AutoField) to a
             short unique string. This is done simply using a perfect hash
             function and converting the result into a string of user friendly
             characters.

 N/A math N/A DEFAULT_VALID_CHARS 3456789ACDEFGHJKLQRSTUVWXY N/A DEFAULT_OFFSET_PERCENT 30 N/A DEFAULT_STRING_LENGTH None N/A DEFAULT_MINIMUM_LENGTH 5 N/A N/A django.conf settings N/A DEFAULT_VALID_CHARS N/A getattr settings FRIENDLY_ID_VALID_CHARS DEFAULT_VALID_CHARS N/A DEFAULT_OFFSET_PERCENT N/A getattr settings FRIENDLY_ID_OFFSET_PERCENT DEFAULT_OFFSET_PERCENT N/A DEFAULT_STRING_LENGTH N/A getattr settings FRIENDLY_ID_STRING_LENGTH DEFAULT_STRING_LENGTH N/A DEFAULT_MINIMUM_LENGTH N/A getattr settings FRIENDLY_ID_MINIMUM_LENGTH DEFAULT_MINIMUM_LENGTH N/A N/A N/A ImportError N/A N/A FriendlyID N/A object N/A __init__ N/A N/A self offset_percent valid_chars string_length minimum_length N/A None None None 5 N/A N/A N/A self valid_chars N/A valid_chars DEFAULT_VALID_CHARS N/A N/A self number_valid_chars N/A len N/A self valid_chars N/A minimum_length N/A minimum_length DEFAULT_MINIMUM_LENGTH N/A N/A self minimum_size N/A N/A N/A self number_valid_chars minimum_length 1 N/A N/A self offset_percent N/A offset_percent DEFAULT_OFFSET_PERCENT N/A N/A self _period_cache N/A N/A N/A self _offset_cache N/A N/A N/A self string_length N/A string_length DEFAULT_STRING_LENGTH N/A get_size N/A N/A self num N/A N/A N/A  Returns the size of the field for the given number.  N/A possible_size N/A self minimum_size N/A N/A num possible_size N/A N/A possible_size N/A self number_valid_chars N/A possible_size N/A get_period N/A N/A self size N/A N/A N/A  Automatically find a suitable period to use.
            Factors are best, because they will have 1 left over when 
            dividing SIZE+1.
            This only needs to be run once, on import.
         N/A N/A size N/A self _period_cache N/A N/A N/A N/A self _period_cache N/A size N/A highest_acceptable_factor N/A int N/A N/A math sqrt size N/A starting_point N/A N/A N/A N/A len N/A self valid_chars 14 N/A N/A len N/A self valid_chars 2 13 N/A p N/A xrange starting_point 7 -1 N/A N/A N/A N/A size p 0 N/A N/A N/A N/A self _period_cache N/A size p N/A p N/A p N/A xrange highest_acceptable_factor N/A starting_point 1 -1 N/A N/A N/A N/A size p 0 N/A N/A N/A N/A self _period_cache N/A size p N/A p N/A p N/A 6 5 4 3 2 N/A N/A N/A N/A size p 0 N/A N/A N/A N/A self _period_cache N/A size p N/A p N/A Exception N/A No valid period could be found for SIZE=%d.
Try avoiding prime numbers :-) SIZE N/A get_offset N/A N/A self size N/A N/A N/A N/A N/A N/A size N/A self offset_percent 100 1 N/A perfect_hash N/A N/A self num size N/A N/A N/A  Translate a number to another unique number, using a perfect hash function.
         N/A period N/A N/A self get_period size N/A offset N/A N/A self get_offset size N/A N/A N/A N/A N/A num offset N/A size period N/A size 1 1 N/A friendly_string N/A N/A self num size N/A N/A N/A  Convert a base 10 number to a base X string.
            Charcters from VALID_CHARS are chosen, to convert the number 
            to eg base 24, if there are 24 characters to choose from.
            Use valid chars to choose characters that are friendly, avoiding
            ones that could be confused in print or over the phone.
         N/A string N/A N/A N/A N/A self string_length N/A N/A len string N/A self string_length N/A N/A N/A self number_valid_chars N/A len string size N/A N/A string N/A N/A N/A self valid_chars N/A N/A num N/A self number_valid_chars string N/A num N/A num N/A self number_valid_chars N/A string N/A encode N/A N/A self num N/A N/A N/A  Encode a simple number, using a perfect hash and converting to a 
            more user friendly string of characters.
         N/A N/A num 0 N/A N/A None N/A size N/A N/A self get_size num N/A hash N/A N/A self perfect_hash num size N/A N/A N/A self friendly_string hash size N/A N/A test N/A N/A max_number N/A N/A N/A  Test every single value for uniqueness and that they are properly decoded.
        This can take some time for large SIZE values, but need only be done once
        if the settings do not change.
     N/A fi N/A FriendlyID collections defaultdict N/A a N/A defaultdict N/A i N/A range N/A max_number 1 N/A N/A N/A N/A N/A fi encode i a N/A N/A a N/A False N/A N/A a N/A N/A N/A fi encode i i N/A True N/A performance_test N/A N/A num N/A None N/A N/A  Run test for the given data to test system performance. 
        (This is used for developing optimisations)
     N/A N/A num N/A N/A num 5000 timeit Timer N/A t N/A Timer N/A test(%s) num from __main__ import test N/A N/A N/A t timeit number 1 N/A N/A N/A __name__ __main__ N/A N/A Here's a quick demonstration: N/A fi N/A FriendlyID N/A 1 N/A N/A fi encode 1 N/A 2 N/A N/A fi encode 2 N/A 3 N/A N/A fi encode 3 N/A 3 N/A N/A fi encode 3 N/A 0 N/A N/A fi encode 0 N/A -1 N/A N/A fi encode -1 N/A 26**5-1 N/A N/A fi encode N/A N/A 26 5 1 N/A 26**5   N/A N/A fi encode N/A 26 5 N/A big number      N/A N/A fi encode 9999999999999999999999999999999999999999999999999999999999 N/A same big number N/A N/A fi encode 9999999999999999999999999999999999999999999999999999999999