idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
53,800
def com_google_fonts_check_metadata_nameid_font_name ( ttFont , style , font_metadata ) : from fontbakery . utils import get_name_entry_strings from fontbakery . constants import RIBBI_STYLE_NAMES if style in RIBBI_STYLE_NAMES : font_familynames = get_name_entry_strings ( ttFont , NameID . FONT_FAMILY_NAME ) nameid = N...
METADATA . pb font . name value should be same as the family name declared on the name table .
53,801
def com_google_fonts_check_metadata_match_fullname_postscript ( font_metadata ) : import re regex = re . compile ( r"\W" ) post_script_name = regex . sub ( "" , font_metadata . post_script_name ) fullname = regex . sub ( "" , font_metadata . full_name ) if fullname != post_script_name : yield FAIL , ( "METADATA.pb font...
METADATA . pb font . full_name and font . post_script_name fields have equivalent values ?
53,802
def com_google_fonts_check_metadata_match_filename_postscript ( font_metadata ) : post_script_name = font_metadata . post_script_name filename = os . path . splitext ( font_metadata . filename ) [ 0 ] if filename != post_script_name : yield FAIL , ( "METADATA.pb font filename=\"{}\" does not match" " post_script_name=\...
METADATA . pb font . filename and font . post_script_name fields have equivalent values?
53,803
def com_google_fonts_check_metadata_valid_name_values ( style , font_metadata , font_familynames , typographic_familynames ) : from fontbakery . constants import RIBBI_STYLE_NAMES if style in RIBBI_STYLE_NAMES : familynames = font_familynames else : familynames = typographic_familynames failed = False for font_familyna...
METADATA . pb font . name field contains font name in right format?
53,804
def com_google_fonts_check_metadata_valid_full_name_values ( style , font_metadata , font_familynames , typographic_familynames ) : from fontbakery . constants import RIBBI_STYLE_NAMES if style in RIBBI_STYLE_NAMES : familynames = font_familynames if familynames == [ ] : yield SKIP , "No FONT_FAMILYNAME" else : familyn...
METADATA . pb font . full_name field contains font name in right format?
53,805
def com_google_fonts_check_metadata_valid_filename_values ( font , family_metadata ) : expected = os . path . basename ( font ) failed = True for font_metadata in family_metadata . fonts : if font_metadata . filename == expected : failed = False yield PASS , ( "METADATA.pb filename field contains" " font name in right ...
METADATA . pb font . filename field contains font name in right format?
53,806
def com_google_fonts_check_metadata_valid_post_script_name_values ( font_metadata , font_familynames ) : for font_familyname in font_familynames : psname = "" . join ( str ( font_familyname ) . split ( ) ) if psname in "" . join ( font_metadata . post_script_name . split ( "-" ) ) : yield PASS , ( "METADATA.pb postScri...
METADATA . pb font . post_script_name field contains font name in right format?
53,807
def com_google_fonts_check_metadata_valid_copyright ( font_metadata ) : import re string = font_metadata . copyright does_match = re . search ( r'Copyright [0-9]{4} The .* Project Authors \([^\@]*\)' , string ) if does_match : yield PASS , "METADATA.pb copyright string is good" else : yield FAIL , ( "METADATA.pb: Copyr...
Copyright notices match canonical pattern in METADATA . pb
53,808
def com_google_fonts_check_font_copyright ( ttFont ) : import re from fontbakery . utils import get_name_entry_strings failed = False for string in get_name_entry_strings ( ttFont , NameID . COPYRIGHT_NOTICE ) : does_match = re . search ( r'Copyright [0-9]{4} The .* Project Authors \([^\@]*\)' , string ) if does_match ...
Copyright notices match canonical pattern in fonts
53,809
def com_google_fonts_check_metadata_italic_style ( ttFont , font_metadata ) : from fontbakery . utils import get_name_entry_strings from fontbakery . constants import MacStyle if font_metadata . style != "italic" : yield SKIP , "This check only applies to italic fonts." else : font_fullname = get_name_entry_strings ( t...
METADATA . pb font . style italic matches font internals?
53,810
def com_google_fonts_check_metadata_normal_style ( ttFont , font_metadata ) : from fontbakery . utils import get_name_entry_strings from fontbakery . constants import MacStyle if font_metadata . style != "normal" : yield SKIP , "This check only applies to normal fonts." else : font_familyname = get_name_entry_strings (...
METADATA . pb font . style normal matches font internals?
53,811
def com_google_fonts_check_metadata_nameid_family_and_full_names ( ttFont , font_metadata ) : from fontbakery . utils import get_name_entry_strings font_familynames = get_name_entry_strings ( ttFont , NameID . TYPOGRAPHIC_FAMILY_NAME ) if font_familynames : font_familyname = font_familynames [ 0 ] else : font_familynam...
METADATA . pb font . name and font . full_name fields match the values declared on the name table?
53,812
def com_google_fonts_check_metadata_match_weight_postscript ( font_metadata ) : WEIGHTS = { "Thin" : 100 , "ThinItalic" : 100 , "ExtraLight" : 200 , "ExtraLightItalic" : 200 , "Light" : 300 , "LightItalic" : 300 , "Regular" : 400 , "Italic" : 400 , "Medium" : 500 , "MediumItalic" : 500 , "SemiBold" : 600 , "SemiBoldIta...
METADATA . pb weight matches postScriptName .
53,813
def com_google_fonts_check_unitsperem_strict ( ttFont ) : upm_height = ttFont [ "head" ] . unitsPerEm ACCEPTABLE = [ 16 , 32 , 64 , 128 , 256 , 500 , 512 , 1000 , 1024 , 2000 , 2048 ] if upm_height not in ACCEPTABLE : yield FAIL , ( f"Font em size (unitsPerEm) is {upm_height}." " If possible, please consider using 1000...
Stricter unitsPerEm criteria for Google Fonts .
53,814
def remote_styles ( family_metadata ) : def download_family_from_Google_Fonts ( family_name ) : from zipfile import ZipFile from fontbakery . utils import download_file url_prefix = 'https://fonts.google.com/download?family=' url = '{}{}' . format ( url_prefix , family_name . replace ( ' ' , '+' ) ) return ZipFile ( do...
Get a dictionary of TTFont objects of all font files of a given family as currently hosted at Google Fonts .
53,815
def github_gfonts_ttFont ( ttFont , license ) : if not license : return from fontbakery . utils import download_file from fontTools . ttLib import TTFont from urllib . request import HTTPError LICENSE_DIRECTORY = { "OFL.txt" : "ofl" , "UFL.txt" : "ufl" , "LICENSE.txt" : "apache" } filename = os . path . basename ( ttFo...
Get a TTFont object of a font downloaded from Google Fonts git repository .
53,816
def com_google_fonts_check_version_bump ( ttFont , api_gfonts_ttFont , github_gfonts_ttFont ) : v_number = ttFont [ "head" ] . fontRevision api_gfonts_v_number = api_gfonts_ttFont [ "head" ] . fontRevision github_gfonts_v_number = github_gfonts_ttFont [ "head" ] . fontRevision failed = False if v_number == api_gfonts_v...
Version number has increased since previous release on Google Fonts?
53,817
def com_google_fonts_check_production_glyphs_similarity ( ttFont , api_gfonts_ttFont ) : def glyphs_surface_area ( ttFont ) : from fontTools . pens . areaPen import AreaPen glyphs = { } glyph_set = ttFont . getGlyphSet ( ) area_pen = AreaPen ( glyph_set ) for glyph in glyph_set . keys ( ) : glyph_set [ glyph ] . draw (...
Glyphs are similiar to Google Fonts version?
53,818
def com_google_fonts_check_italic_angle ( ttFont , style ) : failed = False value = ttFont [ "post" ] . italicAngle if value > 0 : failed = True yield FAIL , Message ( "positive" , ( "The value of post.italicAngle is positive, which" " is likely a mistake and should become negative," " from {} to {}." ) . format ( valu...
Checking post . italicAngle value .
53,819
def com_google_fonts_check_mac_style ( ttFont , style ) : from fontbakery . utils import check_bit_entry from fontbakery . constants import MacStyle expected = "Italic" in style yield check_bit_entry ( ttFont , "head" , "macStyle" , expected , bitmask = MacStyle . ITALIC , bitname = "ITALIC" ) expected = style in [ "Bo...
Checking head . macStyle value .
53,820
def com_google_fonts_check_contour_count ( ttFont ) : from fontbakery . glyphdata import desired_glyph_data as glyph_data from fontbakery . utils import ( get_font_glyph_data , pretty_print_list ) desired_glyph_data = { } for glyph in glyph_data : desired_glyph_data [ glyph [ 'unicode' ] ] = glyph bad_glyphs = [ ] desi...
Check if each glyph has the recommended amount of contours .
53,821
def com_google_fonts_check_metadata_nameid_copyright ( ttFont , font_metadata ) : failed = False for nameRecord in ttFont [ 'name' ] . names : string = nameRecord . string . decode ( nameRecord . getEncoding ( ) ) if nameRecord . nameID == NameID . COPYRIGHT_NOTICE and string != font_metadata . copyright : failed = Tru...
Copyright field for this font on METADATA . pb matches all copyright notice entries on the name table ?
53,822
def com_google_fonts_check_name_mandatory_entries ( ttFont , style ) : from fontbakery . utils import get_name_entry_strings from fontbakery . constants import RIBBI_STYLE_NAMES required_nameIDs = [ NameID . FONT_FAMILY_NAME , NameID . FONT_SUBFAMILY_NAME , NameID . FULL_FONT_NAME , NameID . POSTSCRIPT_NAME ] if style ...
Font has all mandatory name table entries ?
53,823
def com_google_fonts_check_name_copyright_length ( ttFont ) : from fontbakery . utils import get_name_entries failed = False for notice in get_name_entries ( ttFont , NameID . COPYRIGHT_NOTICE ) : notice_str = notice . string . decode ( notice . getEncoding ( ) ) if len ( notice_str ) > 500 : failed = True yield FAIL ,...
Length of copyright notice must not exceed 500 characters .
53,824
def com_google_fonts_check_fontv ( ttFont ) : from fontv . libfv import FontVersion fv = FontVersion ( ttFont ) if fv . version and ( fv . is_development or fv . is_release ) : yield PASS , "Font version string looks GREAT!" else : yield INFO , ( "Version string is: \"{}\"\n" "The version string must ideally include a ...
Check for font - v versioning
53,825
def com_google_fonts_check_negative_advance_width ( ttFont ) : failed = False for glyphName in ttFont [ "glyf" ] . glyphs : coords = ttFont [ "glyf" ] [ glyphName ] . coordinates rightX = coords [ - 3 ] [ 0 ] leftX = coords [ - 4 ] [ 0 ] advwidth = rightX - leftX if advwidth < 0 : failed = True yield FAIL , ( "glyph '{...
Check that advance widths cannot be inferred as negative .
53,826
def com_google_fonts_check_varfont_generate_static ( ttFont ) : import tempfile from fontTools . varLib import mutator try : loc = { k . axisTag : float ( ( k . maxValue + k . minValue ) / 2 ) for k in ttFont [ 'fvar' ] . axes } with tempfile . TemporaryFile ( ) as instance : font = mutator . instantiateVariableFont ( ...
Check a static ttf can be generated from a variable font .
53,827
def com_google_fonts_check_smart_dropout ( ttFont ) : INSTRUCTIONS = b"\xb8\x01\xff\x85\xb0\x04\x8d" if ( "prep" in ttFont and INSTRUCTIONS in ttFont [ "prep" ] . program . getBytecode ( ) ) : yield PASS , ( "'prep' table contains instructions" " enabling smart dropout control." ) else : yield FAIL , ( "'prep' table do...
Font enables smart dropout control in prep table instructions?
53,828
def com_google_fonts_check_aat ( ttFont ) : UNWANTED_TABLES = { 'EBSC' , 'Zaph' , 'acnt' , 'ankr' , 'bdat' , 'bhed' , 'bloc' , 'bmap' , 'bsln' , 'fdsc' , 'feat' , 'fond' , 'gcid' , 'just' , 'kerx' , 'lcar' , 'ltag' , 'mort' , 'morx' , 'opbd' , 'prop' , 'trak' , 'xref' } unwanted_tables_found = [ ] for table in ttFont ....
Are there unwanted Apple tables?
53,829
def com_google_fonts_check_fvar_name_entries ( ttFont ) : failed = False for instance in ttFont [ "fvar" ] . instances : entries = [ entry for entry in ttFont [ "name" ] . names if entry . nameID == instance . subfamilyNameID ] if len ( entries ) == 0 : failed = True yield FAIL , ( f"Named instance with coordinates {in...
All name entries referenced by fvar instances exist on the name table?
53,830
def com_google_fonts_check_varfont_weight_instances ( ttFont ) : failed = False for instance in ttFont [ "fvar" ] . instances : if 'wght' in instance . coordinates and instance . coordinates [ 'wght' ] % 100 != 0 : failed = True yield FAIL , ( "Found an variable font instance with" f" 'wght'={instance.coordinates['wght...
Variable font weight coordinates must be multiples of 100 .
53,831
def com_google_fonts_check_family_tnum_horizontal_metrics ( fonts ) : from fontbakery . constants import RIBBI_STYLE_NAMES from fontTools . ttLib import TTFont RIBBI_ttFonts = [ TTFont ( f ) for f in fonts if style ( f ) in RIBBI_STYLE_NAMES ] tnum_widths = { } for ttFont in RIBBI_ttFonts : glyphs = ttFont . getGlyphSe...
All tabular figures must have the same width across the RIBBI - family .
53,832
def com_google_fonts_check_ligature_carets ( ttFont , ligature_glyphs ) : if ligature_glyphs == - 1 : yield FAIL , Message ( "malformed" , "Failed to lookup ligatures." " This font file seems to be malformed." " For more info, read:" " https://github.com" "/googlefonts/fontbakery/issues/1596" ) elif "GDEF" not in ttFon...
Are there caret positions declared for every ligature?
53,833
def com_google_fonts_check_kerning_for_non_ligated_sequences ( ttFont , ligatures , has_kerning_info ) : def look_for_nonligated_kern_info ( table ) : for pairpos in table . SubTable : for i , glyph in enumerate ( pairpos . Coverage . glyphs ) : if not hasattr ( pairpos , 'PairSet' ) : continue for pairvalue in pairpos...
Is there kerning info for non - ligated sequences?
53,834
def com_google_fonts_check_name_family_and_style_max_length ( ttFont ) : from fontbakery . utils import ( get_name_entries , get_name_entry_strings ) failed = False for familyname in get_name_entries ( ttFont , NameID . FONT_FAMILY_NAME ) : plat = familyname . platformID familyname_str = familyname . string . decode ( ...
Combined length of family and style must not exceed 27 characters .
53,835
def com_google_fonts_check_family_control_chars ( ttFonts ) : unacceptable_cc_list = [ "uni0001" , "uni0002" , "uni0003" , "uni0004" , "uni0005" , "uni0006" , "uni0007" , "uni0008" , "uni0009" , "uni000A" , "uni000B" , "uni000C" , "uni000E" , "uni000F" , "uni0010" , "uni0011" , "uni0012" , "uni0013" , "uni0014" , "uni0...
Does font file include unacceptable control character glyphs?
53,836
def gfonts_repo_structure ( fonts ) : from fontbakery . utils import get_absolute_path abspath = get_absolute_path ( fonts [ 0 ] ) return abspath . split ( os . path . sep ) [ - 3 ] in [ "ufl" , "ofl" , "apache" ]
The family at the given font path follows the files and directory structure typical of a font project hosted on the Google Fonts repo on GitHub ?
53,837
def com_google_fonts_check_repo_dirname_match_nameid_1 ( fonts , gfonts_repo_structure ) : from fontTools . ttLib import TTFont from fontbakery . utils import ( get_name_entry_strings , get_absolute_path , get_regular ) regular = get_regular ( fonts ) if not regular : yield FAIL , "The font seems to lack a regular." en...
Directory name in GFonts repo structure must match NameID 1 of the regular .
53,838
def com_google_fonts_check_family_panose_proportion ( ttFonts ) : failed = False proportion = None for ttFont in ttFonts : if proportion is None : proportion = ttFont [ 'OS/2' ] . panose . bProportion if proportion != ttFont [ 'OS/2' ] . panose . bProportion : failed = True if failed : yield FAIL , ( "PANOSE proportion...
Fonts have consistent PANOSE proportion?
53,839
def com_google_fonts_check_family_panose_familytype ( ttFonts ) : failed = False familytype = None for ttfont in ttFonts : if familytype is None : familytype = ttfont [ 'OS/2' ] . panose . bFamilyType if familytype != ttfont [ 'OS/2' ] . panose . bFamilyType : failed = True if failed : yield FAIL , ( "PANOSE family typ...
Fonts have consistent PANOSE family type?
53,840
def com_google_fonts_check_code_pages ( ttFont ) : if not hasattr ( ttFont [ 'OS/2' ] , "ulCodePageRange1" ) or not hasattr ( ttFont [ 'OS/2' ] , "ulCodePageRange2" ) or ( ttFont [ 'OS/2' ] . ulCodePageRange1 == 0 and ttFont [ 'OS/2' ] . ulCodePageRange2 == 0 ) : yield FAIL , ( "No code pages defined in the OS/2 table"...
Check code page character ranges
53,841
def com_google_fonts_check_glyf_unused_data ( ttFont ) : try : expected_glyphs = len ( ttFont . getGlyphOrder ( ) ) actual_glyphs = len ( ttFont [ 'glyf' ] . glyphs ) diff = actual_glyphs - expected_glyphs if diff < 0 : yield FAIL , Message ( "unreachable-data" , ( "Glyf table has unreachable data at the end of " " the...
Is there any unused data at the end of the glyf table?
53,842
def com_google_fonts_check_points_out_of_bounds ( ttFont ) : failed = False out_of_bounds = [ ] for glyphName in ttFont [ 'glyf' ] . keys ( ) : glyph = ttFont [ 'glyf' ] [ glyphName ] coords = glyph . getCoordinates ( ttFont [ 'glyf' ] ) [ 0 ] for x , y in coords : if x < glyph . xMin or x > glyph . xMax or y < glyph ....
Check for points out of bounds .
53,843
def com_daltonmaag_check_ufolint ( font ) : import subprocess ufolint_cmd = [ "ufolint" , font ] try : subprocess . check_output ( ufolint_cmd , stderr = subprocess . STDOUT ) except subprocess . CalledProcessError as e : yield FAIL , ( "ufolint failed the UFO source. Output follows :" "\n\n{}\n" ) . format ( e . outpu...
Run ufolint on UFO source directory .
53,844
def com_daltonmaag_check_required_fields ( ufo_font ) : recommended_fields = [ ] for field in [ "unitsPerEm" , "ascender" , "descender" , "xHeight" , "capHeight" , "familyName" ] : if ufo_font . info . __dict__ . get ( "_" + field ) is None : recommended_fields . append ( field ) if recommended_fields : yield FAIL , f"...
Check that required fields are present in the UFO fontinfo .
53,845
def com_daltonmaag_check_recommended_fields ( ufo_font ) : recommended_fields = [ ] for field in [ "postscriptUnderlineThickness" , "postscriptUnderlinePosition" , "versionMajor" , "versionMinor" , "styleName" , "copyright" , "openTypeOS2Panose" ] : if ufo_font . info . __dict__ . get ( "_" + field ) is None : recommen...
Check that recommended fields are present in the UFO fontinfo .
53,846
def com_daltonmaag_check_unnecessary_fields ( ufo_font ) : unnecessary_fields = [ ] for field in [ "openTypeNameUniqueID" , "openTypeNameVersion" , "postscriptUniqueID" , "year" ] : if ufo_font . info . __dict__ . get ( "_" + field ) is not None : unnecessary_fields . append ( field ) if unnecessary_fields : yield WARN...
Check that no unnecessary fields are present in the UFO fontinfo .
53,847
def setup_argparse ( self , argument_parser ) : import glob import logging import argparse def get_fonts ( pattern ) : fonts_to_check = [ ] for fullpath in glob . glob ( pattern ) : fullpath_absolute = os . path . abspath ( fullpath ) if fullpath_absolute . lower ( ) . endswith ( ".ufo" ) and os . path . isdir ( fullpa...
Set up custom arguments needed for this profile .
53,848
def com_google_fonts_check_whitespace_widths ( ttFont ) : from fontbakery . utils import get_glyph_name space_name = get_glyph_name ( ttFont , 0x0020 ) nbsp_name = get_glyph_name ( ttFont , 0x00A0 ) space_width = ttFont [ 'hmtx' ] [ space_name ] [ 0 ] nbsp_width = ttFont [ 'hmtx' ] [ nbsp_name ] [ 0 ] if space_width > ...
Whitespace and non - breaking space have the same width?
53,849
def update_by_config ( self , config_dict ) : policy_enabling_map = self . _get_enabling_map ( config_dict ) self . enabled_policies = [ ] for policy_name , is_policy_enabled in policy_enabling_map . items ( ) : if not self . _is_policy_exists ( policy_name ) : self . _warn_unexistent_policy ( policy_name ) continue if...
Update policies set by the config dictionary .
53,850
def _build_cmdargs ( argv ) : parser = _build_arg_parser ( ) namespace = parser . parse_args ( argv [ 1 : ] ) cmdargs = vars ( namespace ) return cmdargs
Build command line arguments dict to use ; - displaying usages - vint . linting . env . build_environment
53,851
def parse ( self , lint_target ) : decoder = Decoder ( default_decoding_strategy ) decoded = decoder . decode ( lint_target . read ( ) ) decoded_and_lf_normalized = decoded . replace ( '\r\n' , '\n' ) return self . parse_string ( decoded_and_lf_normalized )
Parse vim script file and return the AST .
53,852
def parse_string ( self , string ) : lines = string . split ( '\n' ) reader = vimlparser . StringReader ( lines ) parser = vimlparser . VimLParser ( self . _enable_neovim ) ast = parser . parse ( reader ) ast [ 'pos' ] = { 'col' : 1 , 'i' : 0 , 'lnum' : 1 } for plugin in self . plugins : plugin . process ( ast ) return...
Parse vim script string and return the AST .
53,853
def parse_string_expr ( self , string_expr_node ) : string_expr_node_value = string_expr_node [ 'value' ] string_expr_str = string_expr_node_value [ 1 : - 1 ] if string_expr_node_value [ 0 ] == "'" : string_expr_str = string_expr_str . replace ( "''" , "'" ) else : string_expr_str = string_expr_str . replace ( '\\"' , ...
Parse a string node content .
53,854
def is_builtin_variable ( id_node ) : if NodeType ( id_node [ 'type' ] ) is not NodeType . IDENTIFIER : return False id_value = id_node [ 'value' ] if id_value . startswith ( 'v:' ) : return True if is_builtin_function ( id_node ) : return True if id_value in [ 'key' , 'val' ] : return is_on_lambda_string_context ( id_...
Whether the specified node is a builtin identifier .
53,855
def is_builtin_function ( id_node ) : if NodeType ( id_node [ 'type' ] ) is not NodeType . IDENTIFIER : return False id_value = id_node [ 'value' ] if not is_function_identifier ( id_node ) : return False return id_value in BuiltinFunctions
Whether the specified node is a builtin function name identifier . The given identifier should be a child node of NodeType . CALL .
53,856
def attach_identifier_attributes ( self , ast ) : redir_assignment_parser = RedirAssignmentParser ( ) ast_with_parsed_redir = redir_assignment_parser . process ( ast ) map_and_filter_parser = CallNodeParser ( ) ast_with_parse_map_and_filter_and_redir = map_and_filter_parser . process ( ast_with_parsed_redir ) traverse ...
Attach 5 flags to the AST .
53,857
def create_violation_report ( self , node , lint_context ) : return { 'name' : self . name , 'level' : self . level , 'description' : self . description , 'reference' : self . reference , 'position' : { 'line' : node [ 'pos' ] [ 'lnum' ] , 'column' : node [ 'pos' ] [ 'col' ] , 'path' : lint_context [ 'lint_target' ] . ...
Returns a violation report for the node .
53,858
def get_policy_config ( self , lint_context ) : policy_config = lint_context [ 'config' ] . get ( 'policies' , { } ) . get ( self . __class__ . __name__ , { } ) return policy_config
Returns a config of the concrete policy . For example a config of ProhibitSomethingEvil is located on config . policies . ProhibitSomethingEvil .
53,859
def get_violation_if_found ( self , node , lint_context ) : if self . is_valid ( node , lint_context ) : return None return self . create_violation_report ( node , lint_context )
Returns a violation if the node is invalid .
53,860
def import_all_policies ( ) : pkg_name = _get_policy_package_name_for_test ( ) pkg_path_list = pkg_name . split ( '.' ) pkg_path = str ( Path ( _get_vint_root ( ) , * pkg_path_list ) . resolve ( ) ) for _ , module_name , is_pkg in pkgutil . iter_modules ( [ pkg_path ] ) : if not is_pkg : module_fqn = pkg_name + '.' + m...
Import all policies that were registered by vint . linting . policy_registry .
53,861
def process ( self , ast ) : id_classifier = IdentifierClassifier ( ) attached_ast = id_classifier . attach_identifier_attributes ( ast ) self . _scope_tree_builder . enter_new_scope ( ScopeVisibility . SCRIPT_LOCAL ) traverse ( attached_ast , on_enter = self . _enter_handler , on_leave = self . _leave_handler ) self ....
Build a scope tree and links between scopes and identifiers by the specified ast . You can access the built scope tree and the built links by . scope_tree and . link_registry .
53,862
def cli ( argv = None ) : kwargs = parse_arguments ( argv or sys . argv [ 1 : ] ) log_level = kwargs . pop ( 'log_level' ) logging . basicConfig ( format = '%(levelname)s | %(message)s' , level = log_level ) logger = logging . getLogger ( __name__ ) sub_log_level = logging . ERROR if log_level == logging . getLevelName...
CLI entry point for mozdownload .
53,863
def query_builds_by_revision ( self , revision , job_type_name = 'Build' , debug_build = False ) : builds = set ( ) try : self . logger . info ( 'Querying {url} for list of builds for revision: {revision}' . format ( url = self . client . server_url , revision = revision ) ) option_hash = None for key , values in self ...
Retrieve build folders for a given revision with the help of Treeherder .
53,864
def urljoin ( * fragments ) : parts = [ fragment . rstrip ( '/' ) for fragment in fragments [ : len ( fragments ) - 1 ] ] parts . append ( fragments [ - 1 ] ) return '/' . join ( parts )
Concatenate multi part strings into urls .
53,865
def create_md5 ( path ) : m = hashlib . md5 ( ) with open ( path , "rb" ) as f : while True : data = f . read ( 8192 ) if not data : break m . update ( data ) return m . hexdigest ( )
Create the md5 hash of a file using the hashlib library .
53,866
def filter ( self , filter ) : if hasattr ( filter , '__call__' ) : return [ entry for entry in self . entries if filter ( entry ) ] else : pattern = re . compile ( filter , re . IGNORECASE ) return [ entry for entry in self . entries if pattern . match ( entry ) ]
Filter entries by calling function or applying regex .
53,867
def handle_starttag ( self , tag , attrs ) : if not tag == 'a' : return for attr in attrs : if attr [ 0 ] == 'href' : url = urllib . unquote ( attr [ 1 ] ) self . active_url = url . rstrip ( '/' ) . split ( '/' ) [ - 1 ] return
Callback for when a tag gets opened .
53,868
def handle_data ( self , data ) : if not self . active_url : return if data . strip ( '/' ) == self . active_url : self . entries . append ( self . active_url )
Callback when the data of a tag has been collected .
53,869
def dst ( self , dt ) : dst_start_date = self . first_sunday ( dt . year , 3 ) + timedelta ( days = 7 ) + timedelta ( hours = 2 ) dst_end_date = self . first_sunday ( dt . year , 11 ) + timedelta ( hours = 2 ) if dst_start_date <= dt . replace ( tzinfo = None ) < dst_end_date : return timedelta ( hours = 1 ) else : ret...
Calculate delta for daylight saving .
53,870
def first_sunday ( self , year , month ) : date = datetime ( year , month , 1 , 0 ) days_until_sunday = 6 - date . weekday ( ) return date + timedelta ( days = days_until_sunday )
Get the first sunday of a month .
53,871
def binary ( self ) : def _get_binary ( ) : parser = self . _create_directory_parser ( self . path ) if not parser . entries : raise errors . NotFoundError ( 'No entries found' , self . path ) pattern = re . compile ( self . binary_regex , re . IGNORECASE ) for entry in parser . entries : try : self . _binary = pattern...
Return the name of the build .
53,872
def url ( self ) : return urllib . quote ( urljoin ( self . path , self . binary ) , safe = '%/:=&?~#+!$,;\'@()*[]|' )
Return the URL of the build .
53,873
def filename ( self ) : if self . _filename is None : if os . path . splitext ( self . destination ) [ 1 ] : target_file = self . destination else : target_file = os . path . join ( self . destination , self . build_filename ( self . binary ) ) self . _filename = os . path . abspath ( target_file ) return self . _filen...
Return the local filename of the build .
53,874
def download ( self ) : def total_seconds ( td ) : if hasattr ( td , 'total_seconds' ) : return td . total_seconds ( ) else : return ( td . microseconds + ( td . seconds + td . days * 24 * 3600 ) * 10 ** 6 ) / 10 ** 6 if os . path . isfile ( os . path . abspath ( self . filename ) ) : self . logger . info ( "File has a...
Download the specified file .
53,875
def show_matching_builds ( self , builds ) : self . logger . info ( 'Found %s build%s: %s' % ( len ( builds ) , len ( builds ) > 1 and 's' or '' , len ( builds ) > 10 and ' ... ' . join ( [ ', ' . join ( builds [ : 5 ] ) , ', ' . join ( builds [ - 5 : ] ) ] ) or ', ' . join ( builds ) ) )
Output the matching builds .
53,876
def is_build_dir ( self , folder_name ) : url = '%s/' % urljoin ( self . base_url , self . monthly_build_list_regex , folder_name ) if self . application in APPLICATIONS_MULTI_LOCALE and self . locale != 'multi' : url = '%s/' % urljoin ( url , self . locale ) parser = self . _create_directory_parser ( url ) pattern = r...
Return whether or not the given dir contains a build .
53,877
def get_build_info_for_date ( self , date , build_index = None ) : url = urljoin ( self . base_url , self . monthly_build_list_regex ) has_time = date and date . time ( ) self . logger . info ( 'Retrieving list of builds from %s' % url ) parser = self . _create_directory_parser ( url ) regex = r'%(DATE)s-(\d+-)+%(BRANC...
Return the build information for a given date .
53,878
def monthly_build_list_regex ( self ) : return r'nightly/%(YEAR)s/%(MONTH)s/' % { 'YEAR' : self . date . year , 'MONTH' : str ( self . date . month ) . zfill ( 2 ) }
Return the regex for the folder containing builds of a month .
53,879
def filename ( self ) : if os . path . splitext ( self . destination ) [ 1 ] : target_file = self . destination else : parsed_url = urlparse ( self . url ) source_filename = ( parsed_url . path . rpartition ( '/' ) [ - 1 ] or parsed_url . hostname ) target_file = os . path . join ( self . destination , source_filename ...
File name of the downloaded file .
53,880
def query_versions ( self , version = None ) : if version not in RELEASE_AND_CANDIDATE_LATEST_VERSIONS : return [ version ] url = urljoin ( self . base_url , 'releases/' ) parser = self . _create_directory_parser ( url ) if version : versions = parser . filter ( RELEASE_AND_CANDIDATE_LATEST_VERSIONS [ version ] ) from ...
Check specified version and resolve special values .
53,881
def build_list_regex ( self ) : regex = 'tinderbox-builds/%(BRANCH)s-%(PLATFORM)s%(L10N)s%(DEBUG)s/' return regex % { 'BRANCH' : self . branch , 'PLATFORM' : '' if self . locale_build else self . platform_regex , 'L10N' : 'l10n' if self . locale_build else '' , 'DEBUG' : '-debug' if self . debug_build else '' }
Return the regex for the folder which contains the list of builds .
53,882
def date_matches ( self , timestamp ) : if self . date is None : return False timestamp = datetime . fromtimestamp ( float ( timestamp ) , self . timezone ) if self . date . date ( ) == timestamp . date ( ) : return True return False
Determine whether the timestamp date is equal to the argument date .
53,883
def get_build_info_for_index ( self , build_index = None ) : url = urljoin ( self . base_url , self . build_list_regex ) self . logger . info ( 'Retrieving list of builds from %s' % url ) parser = self . _create_directory_parser ( url ) parser . entries = parser . filter ( r'^\d+$' ) if self . timestamp : parser . entr...
Get additional information for the build at the given index .
53,884
def create_default_options_getter ( ) : options = [ ] try : ttyname = subprocess . check_output ( args = [ 'tty' ] ) . strip ( ) options . append ( b'ttyname=' + ttyname ) except subprocess . CalledProcessError as e : log . warning ( 'no TTY found: %s' , e ) display = os . environ . get ( 'DISPLAY' ) if display is not ...
Return current TTY and DISPLAY settings for GnuPG pinentry .
53,885
def write ( p , line ) : log . debug ( '%s <- %r' , p . args , line ) p . stdin . write ( line ) p . stdin . flush ( )
Send and flush a single line to the subprocess stdin .
53,886
def expect ( p , prefixes , confidential = False ) : resp = p . stdout . readline ( ) log . debug ( '%s -> %r' , p . args , resp if not confidential else '********' ) for prefix in prefixes : if resp . startswith ( prefix ) : return resp [ len ( prefix ) : ] raise UnexpectedError ( resp )
Read a line and return it without required prefix .
53,887
def interact ( title , description , prompt , binary , options ) : args = [ binary ] p = subprocess . Popen ( args = args , stdin = subprocess . PIPE , stdout = subprocess . PIPE , env = os . environ ) p . args = args expect ( p , [ b'OK' ] ) title = util . assuan_serialize ( title . encode ( 'ascii' ) ) write ( p , b'...
Use GPG pinentry program to interact with the user .
53,888
def get_passphrase ( self , prompt = 'Passphrase:' ) : passphrase = None if self . cached_passphrase_ack : passphrase = self . cached_passphrase_ack . get ( ) if passphrase is None : passphrase = interact ( title = '{} passphrase' . format ( self . device_name ) , prompt = prompt , description = None , binary = self . ...
Ask the user for passphrase .
53,889
def export_public_keys ( self , identities ) : public_keys = [ ] with self . device : for i in identities : pubkey = self . device . pubkey ( identity = i ) vk = formats . decompress_pubkey ( pubkey = pubkey , curve_name = i . curve_name ) public_key = formats . export_public_key ( vk = vk , label = i . to_string ( ) )...
Export SSH public keys from the device .
53,890
def sign_ssh_challenge ( self , blob , identity ) : msg = _parse_ssh_blob ( blob ) log . debug ( '%s: user %r via %r (%r)' , msg [ 'conn' ] , msg [ 'user' ] , msg [ 'auth' ] , msg [ 'key_type' ] ) log . debug ( 'nonce: %r' , msg [ 'nonce' ] ) fp = msg [ 'public_key' ] [ 'fingerprint' ] log . debug ( 'fingerprint: %s' ,...
Sign given blob using a private key on the device .
53,891
def fingerprint ( blob ) : digest = hashlib . md5 ( blob ) . digest ( ) return ':' . join ( '{:02x}' . format ( c ) for c in bytearray ( digest ) )
Compute SSH fingerprint for specified blob .
53,892
def parse_pubkey ( blob ) : fp = fingerprint ( blob ) s = io . BytesIO ( blob ) key_type = util . read_frame ( s ) log . debug ( 'key type: %s' , key_type ) assert key_type in SUPPORTED_KEY_TYPES , key_type result = { 'blob' : blob , 'type' : key_type , 'fingerprint' : fp } if key_type == SSH_NIST256_KEY_TYPE : curve_n...
Parse SSH public key from given blob .
53,893
def export_public_key ( vk , label ) : key_type , blob = serialize_verifying_key ( vk ) log . debug ( 'fingerprint: %s' , fingerprint ( blob ) ) b64 = base64 . b64encode ( blob ) . decode ( 'ascii' ) return u'{} {} {}\n' . format ( key_type . decode ( 'ascii' ) , b64 , label )
Export public key to text format .
53,894
def import_public_key ( line ) : log . debug ( 'loading SSH public key: %r' , line ) file_type , base64blob , name = line . split ( ) blob = base64 . b64decode ( base64blob ) result = parse_pubkey ( blob ) result [ 'name' ] = name . encode ( 'utf-8' ) assert result [ 'type' ] == file_type . encode ( 'ascii' ) log . deb...
Parse public key textual format as saved at a . pub file .
53,895
def parse_packets ( stream ) : reader = util . Reader ( stream ) while True : try : value = reader . readfmt ( 'B' ) except EOFError : return log . debug ( 'prefix byte: %s' , bin ( value ) ) assert util . bit ( value , 7 ) == 1 tag = util . low_bits ( value , 6 ) if util . bit ( value , 6 ) == 0 : length_type = util ....
Support iterative parsing of available GPG packets .
53,896
def digest_packets ( packets , hasher ) : data_to_hash = io . BytesIO ( ) for p in packets : data_to_hash . write ( p [ '_to_hash' ] ) hasher . update ( data_to_hash . getvalue ( ) ) return hasher . digest ( )
Compute digest on specified packets according to _to_hash field .
53,897
def load_by_keygrip ( pubkey_bytes , keygrip ) : stream = io . BytesIO ( pubkey_bytes ) packets = list ( parse_packets ( stream ) ) packets_per_pubkey = [ ] for p in packets : if p [ 'type' ] == 'pubkey' : packets_per_pubkey . append ( [ ] ) packets_per_pubkey [ - 1 ] . append ( p ) for packets in packets_per_pubkey : ...
Return public key and first user ID for specified keygrip .
53,898
def load_signature ( stream , original_data ) : signature , = list ( parse_packets ( ( stream ) ) ) hash_alg = HASH_ALGORITHMS [ signature [ 'hash_alg' ] ] digest = digest_packets ( [ { '_to_hash' : original_data } , signature ] , hasher = hashlib . new ( hash_alg ) ) assert signature [ 'hash_prefix' ] == digest [ : 2 ...
Load signature from stream and compute GPG digest for verification .
53,899
def remove_armor ( armored_data ) : stream = io . BytesIO ( armored_data ) lines = stream . readlines ( ) [ 3 : - 1 ] data = base64 . b64decode ( b'' . join ( lines ) ) payload , checksum = data [ : - 3 ] , data [ - 3 : ] assert util . crc24 ( payload ) == checksum return payload
Decode armored data into its binary form .