Best JavaScript code snippet using fast-check-monorepo
shlwapi.py
Source:shlwapi.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3# Copyright (c) 2009-2014, Mario Vilas4# All rights reserved.5#6# Redistribution and use in source and binary forms, with or without7# modification, are permitted provided that the following conditions are met:8#9# * Redistributions of source code must retain the above copyright notice,10# this list of conditions and the following disclaimer.11# * Redistributions in binary form must reproduce the above copyright12# notice,this list of conditions and the following disclaimer in the13# documentation and/or other materials provided with the distribution.14# * Neither the name of the copyright holder nor the names of its15# contributors may be used to endorse or promote products derived from16# this software without specific prior written permission.17#18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28# POSSIBILITY OF SUCH DAMAGE.29"""30Wrapper for shlwapi.dll in ctypes.31"""32__revision__ = "$Id$"33from winappdbg.win32.defines import *34from winappdbg.win32.kernel32 import *35#==============================================================================36# This is used later on to calculate the list of exported symbols.37_all = None38_all = set(vars().keys())39#==============================================================================40OS_WINDOWS = 041OS_NT = 142OS_WIN95ORGREATER = 243OS_NT4ORGREATER = 344OS_WIN98ORGREATER = 545OS_WIN98_GOLD = 646OS_WIN2000ORGREATER = 747OS_WIN2000PRO = 848OS_WIN2000SERVER = 949OS_WIN2000ADVSERVER = 1050OS_WIN2000DATACENTER = 1151OS_WIN2000TERMINAL = 1252OS_EMBEDDED = 1353OS_TERMINALCLIENT = 1454OS_TERMINALREMOTEADMIN = 1555OS_WIN95_GOLD = 1656OS_MEORGREATER = 1757OS_XPORGREATER = 1858OS_HOME = 1959OS_PROFESSIONAL = 2060OS_DATACENTER = 2161OS_ADVSERVER = 2262OS_SERVER = 2363OS_TERMINALSERVER = 2464OS_PERSONALTERMINALSERVER = 2565OS_FASTUSERSWITCHING = 2666OS_WELCOMELOGONUI = 2767OS_DOMAINMEMBER = 2868OS_ANYSERVER = 2969OS_WOW6432 = 3070OS_WEBSERVER = 3171OS_SMALLBUSINESSSERVER = 3272OS_TABLETPC = 3373OS_SERVERADMINUI = 3474OS_MEDIACENTER = 3575OS_APPLIANCE = 3676#--- shlwapi.dll --------------------------------------------------------------77# BOOL IsOS(78# DWORD dwOS79# );80def IsOS(dwOS):81 try:82 _IsOS = windll.shlwapi.IsOS83 _IsOS.argtypes = [DWORD]84 _IsOS.restype = bool85 except AttributeError:86 # According to MSDN, on Windows versions prior to Vista87 # this function is exported only by ordinal number 437.88 # http://msdn.microsoft.com/en-us/library/bb773795%28VS.85%29.aspx89 _GetProcAddress = windll.kernel32.GetProcAddress90 _GetProcAddress.argtypes = [HINSTANCE, DWORD]91 _GetProcAddress.restype = LPVOID92 _IsOS = windll.kernel32.GetProcAddress(windll.shlwapi._handle, 437)93 _IsOS = WINFUNCTYPE(bool, DWORD)(_IsOS)94 return _IsOS(dwOS)95# LPTSTR PathAddBackslash(96# LPTSTR lpszPath97# );98def PathAddBackslashA(lpszPath):99 _PathAddBackslashA = windll.shlwapi.PathAddBackslashA100 _PathAddBackslashA.argtypes = [LPSTR]101 _PathAddBackslashA.restype = LPSTR102 lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH)103 retval = _PathAddBackslashA(lpszPath)104 if retval == NULL:105 raise ctypes.WinError()106 return lpszPath.value107def PathAddBackslashW(lpszPath):108 _PathAddBackslashW = windll.shlwapi.PathAddBackslashW109 _PathAddBackslashW.argtypes = [LPWSTR]110 _PathAddBackslashW.restype = LPWSTR111 lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH)112 retval = _PathAddBackslashW(lpszPath)113 if retval == NULL:114 raise ctypes.WinError()115 return lpszPath.value116PathAddBackslash = GuessStringType(PathAddBackslashA, PathAddBackslashW)117# BOOL PathAddExtension(118# LPTSTR pszPath,119# LPCTSTR pszExtension120# );121def PathAddExtensionA(lpszPath, pszExtension = None):122 _PathAddExtensionA = windll.shlwapi.PathAddExtensionA123 _PathAddExtensionA.argtypes = [LPSTR, LPSTR]124 _PathAddExtensionA.restype = bool125 _PathAddExtensionA.errcheck = RaiseIfZero126 if not pszExtension:127 pszExtension = None128 lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH)129 _PathAddExtensionA(lpszPath, pszExtension)130 return lpszPath.value131def PathAddExtensionW(lpszPath, pszExtension = None):132 _PathAddExtensionW = windll.shlwapi.PathAddExtensionW133 _PathAddExtensionW.argtypes = [LPWSTR, LPWSTR]134 _PathAddExtensionW.restype = bool135 _PathAddExtensionW.errcheck = RaiseIfZero136 if not pszExtension:137 pszExtension = None138 lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH)139 _PathAddExtensionW(lpszPath, pszExtension)140 return lpszPath.value141PathAddExtension = GuessStringType(PathAddExtensionA, PathAddExtensionW)142# BOOL PathAppend(143# LPTSTR pszPath,144# LPCTSTR pszMore145# );146def PathAppendA(lpszPath, pszMore = None):147 _PathAppendA = windll.shlwapi.PathAppendA148 _PathAppendA.argtypes = [LPSTR, LPSTR]149 _PathAppendA.restype = bool150 _PathAppendA.errcheck = RaiseIfZero151 if not pszMore:152 pszMore = None153 lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH)154 _PathAppendA(lpszPath, pszMore)155 return lpszPath.value156def PathAppendW(lpszPath, pszMore = None):157 _PathAppendW = windll.shlwapi.PathAppendW158 _PathAppendW.argtypes = [LPWSTR, LPWSTR]159 _PathAppendW.restype = bool160 _PathAppendW.errcheck = RaiseIfZero161 if not pszMore:162 pszMore = None163 lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH)164 _PathAppendW(lpszPath, pszMore)165 return lpszPath.value166PathAppend = GuessStringType(PathAppendA, PathAppendW)167# LPTSTR PathCombine(168# LPTSTR lpszDest,169# LPCTSTR lpszDir,170# LPCTSTR lpszFile171# );172def PathCombineA(lpszDir, lpszFile):173 _PathCombineA = windll.shlwapi.PathCombineA174 _PathCombineA.argtypes = [LPSTR, LPSTR, LPSTR]175 _PathCombineA.restype = LPSTR176 lpszDest = ctypes.create_string_buffer("", max(MAX_PATH, len(lpszDir) + len(lpszFile) + 1))177 retval = _PathCombineA(lpszDest, lpszDir, lpszFile)178 if retval == NULL:179 return None180 return lpszDest.value181def PathCombineW(lpszDir, lpszFile):182 _PathCombineW = windll.shlwapi.PathCombineW183 _PathCombineW.argtypes = [LPWSTR, LPWSTR, LPWSTR]184 _PathCombineW.restype = LPWSTR185 lpszDest = ctypes.create_unicode_buffer(u"", max(MAX_PATH, len(lpszDir) + len(lpszFile) + 1))186 retval = _PathCombineW(lpszDest, lpszDir, lpszFile)187 if retval == NULL:188 return None189 return lpszDest.value190PathCombine = GuessStringType(PathCombineA, PathCombineW)191# BOOL PathCanonicalize(192# LPTSTR lpszDst,193# LPCTSTR lpszSrc194# );195def PathCanonicalizeA(lpszSrc):196 _PathCanonicalizeA = windll.shlwapi.PathCanonicalizeA197 _PathCanonicalizeA.argtypes = [LPSTR, LPSTR]198 _PathCanonicalizeA.restype = bool199 _PathCanonicalizeA.errcheck = RaiseIfZero200 lpszDst = ctypes.create_string_buffer("", MAX_PATH)201 _PathCanonicalizeA(lpszDst, lpszSrc)202 return lpszDst.value203def PathCanonicalizeW(lpszSrc):204 _PathCanonicalizeW = windll.shlwapi.PathCanonicalizeW205 _PathCanonicalizeW.argtypes = [LPWSTR, LPWSTR]206 _PathCanonicalizeW.restype = bool207 _PathCanonicalizeW.errcheck = RaiseIfZero208 lpszDst = ctypes.create_unicode_buffer(u"", MAX_PATH)209 _PathCanonicalizeW(lpszDst, lpszSrc)210 return lpszDst.value211PathCanonicalize = GuessStringType(PathCanonicalizeA, PathCanonicalizeW)212# BOOL PathRelativePathTo(213# _Out_ LPTSTR pszPath,214# _In_ LPCTSTR pszFrom,215# _In_ DWORD dwAttrFrom,216# _In_ LPCTSTR pszTo,217# _In_ DWORD dwAttrTo218# );219def PathRelativePathToA(pszFrom = None, dwAttrFrom = FILE_ATTRIBUTE_DIRECTORY, pszTo = None, dwAttrTo = FILE_ATTRIBUTE_DIRECTORY):220 _PathRelativePathToA = windll.shlwapi.PathRelativePathToA221 _PathRelativePathToA.argtypes = [LPSTR, LPSTR, DWORD, LPSTR, DWORD]222 _PathRelativePathToA.restype = bool223 _PathRelativePathToA.errcheck = RaiseIfZero224 # Make the paths absolute or the function fails.225 if pszFrom:226 pszFrom = GetFullPathNameA(pszFrom)[0]227 else:228 pszFrom = GetCurrentDirectoryA()229 if pszTo:230 pszTo = GetFullPathNameA(pszTo)[0]231 else:232 pszTo = GetCurrentDirectoryA()233 # Argh, this function doesn't receive an output buffer size!234 # We'll try to guess the maximum possible buffer size.235 dwPath = max((len(pszFrom) + len(pszTo)) * 2 + 1, MAX_PATH + 1)236 pszPath = ctypes.create_string_buffer('', dwPath)237 # Also, it doesn't set the last error value.238 # Whoever coded it must have been drunk or tripping on acid. Or both.239 # The only failure conditions I've seen were invalid paths, paths not240 # on the same drive, or the path is not absolute.241 SetLastError(ERROR_INVALID_PARAMETER)242 _PathRelativePathToA(pszPath, pszFrom, dwAttrFrom, pszTo, dwAttrTo)243 return pszPath.value244def PathRelativePathToW(pszFrom = None, dwAttrFrom = FILE_ATTRIBUTE_DIRECTORY, pszTo = None, dwAttrTo = FILE_ATTRIBUTE_DIRECTORY):245 _PathRelativePathToW = windll.shlwapi.PathRelativePathToW246 _PathRelativePathToW.argtypes = [LPWSTR, LPWSTR, DWORD, LPWSTR, DWORD]247 _PathRelativePathToW.restype = bool248 _PathRelativePathToW.errcheck = RaiseIfZero249 # Refer to PathRelativePathToA to know why this code is so ugly.250 if pszFrom:251 pszFrom = GetFullPathNameW(pszFrom)[0]252 else:253 pszFrom = GetCurrentDirectoryW()254 if pszTo:255 pszTo = GetFullPathNameW(pszTo)[0]256 else:257 pszTo = GetCurrentDirectoryW()258 dwPath = max((len(pszFrom) + len(pszTo)) * 2 + 1, MAX_PATH + 1)259 pszPath = ctypes.create_unicode_buffer(u'', dwPath)260 SetLastError(ERROR_INVALID_PARAMETER)261 _PathRelativePathToW(pszPath, pszFrom, dwAttrFrom, pszTo, dwAttrTo)262 return pszPath.value263PathRelativePathTo = GuessStringType(PathRelativePathToA, PathRelativePathToW)264# BOOL PathFileExists(265# LPCTSTR pszPath266# );267def PathFileExistsA(pszPath):268 _PathFileExistsA = windll.shlwapi.PathFileExistsA269 _PathFileExistsA.argtypes = [LPSTR]270 _PathFileExistsA.restype = bool271 return _PathFileExistsA(pszPath)272def PathFileExistsW(pszPath):273 _PathFileExistsW = windll.shlwapi.PathFileExistsW274 _PathFileExistsW.argtypes = [LPWSTR]275 _PathFileExistsW.restype = bool276 return _PathFileExistsW(pszPath)277PathFileExists = GuessStringType(PathFileExistsA, PathFileExistsW)278# LPTSTR PathFindExtension(279# LPCTSTR pszPath280# );281def PathFindExtensionA(pszPath):282 _PathFindExtensionA = windll.shlwapi.PathFindExtensionA283 _PathFindExtensionA.argtypes = [LPSTR]284 _PathFindExtensionA.restype = LPSTR285 pszPath = ctypes.create_string_buffer(pszPath)286 return _PathFindExtensionA(pszPath)287def PathFindExtensionW(pszPath):288 _PathFindExtensionW = windll.shlwapi.PathFindExtensionW289 _PathFindExtensionW.argtypes = [LPWSTR]290 _PathFindExtensionW.restype = LPWSTR291 pszPath = ctypes.create_unicode_buffer(pszPath)292 return _PathFindExtensionW(pszPath)293PathFindExtension = GuessStringType(PathFindExtensionA, PathFindExtensionW)294# LPTSTR PathFindFileName(295# LPCTSTR pszPath296# );297def PathFindFileNameA(pszPath):298 _PathFindFileNameA = windll.shlwapi.PathFindFileNameA299 _PathFindFileNameA.argtypes = [LPSTR]300 _PathFindFileNameA.restype = LPSTR301 pszPath = ctypes.create_string_buffer(pszPath)302 return _PathFindFileNameA(pszPath)303def PathFindFileNameW(pszPath):304 _PathFindFileNameW = windll.shlwapi.PathFindFileNameW305 _PathFindFileNameW.argtypes = [LPWSTR]306 _PathFindFileNameW.restype = LPWSTR307 pszPath = ctypes.create_unicode_buffer(pszPath)308 return _PathFindFileNameW(pszPath)309PathFindFileName = GuessStringType(PathFindFileNameA, PathFindFileNameW)310# LPTSTR PathFindNextComponent(311# LPCTSTR pszPath312# );313def PathFindNextComponentA(pszPath):314 _PathFindNextComponentA = windll.shlwapi.PathFindNextComponentA315 _PathFindNextComponentA.argtypes = [LPSTR]316 _PathFindNextComponentA.restype = LPSTR317 pszPath = ctypes.create_string_buffer(pszPath)318 return _PathFindNextComponentA(pszPath)319def PathFindNextComponentW(pszPath):320 _PathFindNextComponentW = windll.shlwapi.PathFindNextComponentW321 _PathFindNextComponentW.argtypes = [LPWSTR]322 _PathFindNextComponentW.restype = LPWSTR323 pszPath = ctypes.create_unicode_buffer(pszPath)324 return _PathFindNextComponentW(pszPath)325PathFindNextComponent = GuessStringType(PathFindNextComponentA, PathFindNextComponentW)326# BOOL PathFindOnPath(327# LPTSTR pszFile,328# LPCTSTR *ppszOtherDirs329# );330def PathFindOnPathA(pszFile, ppszOtherDirs = None):331 _PathFindOnPathA = windll.shlwapi.PathFindOnPathA332 _PathFindOnPathA.argtypes = [LPSTR, LPSTR]333 _PathFindOnPathA.restype = bool334 pszFile = ctypes.create_string_buffer(pszFile, MAX_PATH)335 if not ppszOtherDirs:336 ppszOtherDirs = None337 else:338 szArray = ""339 for pszOtherDirs in ppszOtherDirs:340 if pszOtherDirs:341 szArray = "%s%s\0" % (szArray, pszOtherDirs)342 szArray = szArray + "\0"343 pszOtherDirs = ctypes.create_string_buffer(szArray)344 ppszOtherDirs = ctypes.pointer(pszOtherDirs)345 if _PathFindOnPathA(pszFile, ppszOtherDirs):346 return pszFile.value347 return None348def PathFindOnPathW(pszFile, ppszOtherDirs = None):349 _PathFindOnPathW = windll.shlwapi.PathFindOnPathA350 _PathFindOnPathW.argtypes = [LPWSTR, LPWSTR]351 _PathFindOnPathW.restype = bool352 pszFile = ctypes.create_unicode_buffer(pszFile, MAX_PATH)353 if not ppszOtherDirs:354 ppszOtherDirs = None355 else:356 szArray = u""357 for pszOtherDirs in ppszOtherDirs:358 if pszOtherDirs:359 szArray = u"%s%s\0" % (szArray, pszOtherDirs)360 szArray = szArray + u"\0"361 pszOtherDirs = ctypes.create_unicode_buffer(szArray)362 ppszOtherDirs = ctypes.pointer(pszOtherDirs)363 if _PathFindOnPathW(pszFile, ppszOtherDirs):364 return pszFile.value365 return None366PathFindOnPath = GuessStringType(PathFindOnPathA, PathFindOnPathW)367# LPTSTR PathGetArgs(368# LPCTSTR pszPath369# );370def PathGetArgsA(pszPath):371 _PathGetArgsA = windll.shlwapi.PathGetArgsA372 _PathGetArgsA.argtypes = [LPSTR]373 _PathGetArgsA.restype = LPSTR374 pszPath = ctypes.create_string_buffer(pszPath)375 return _PathGetArgsA(pszPath)376def PathGetArgsW(pszPath):377 _PathGetArgsW = windll.shlwapi.PathGetArgsW378 _PathGetArgsW.argtypes = [LPWSTR]379 _PathGetArgsW.restype = LPWSTR380 pszPath = ctypes.create_unicode_buffer(pszPath)381 return _PathGetArgsW(pszPath)382PathGetArgs = GuessStringType(PathGetArgsA, PathGetArgsW)383# BOOL PathIsContentType(384# LPCTSTR pszPath,385# LPCTSTR pszContentType386# );387def PathIsContentTypeA(pszPath, pszContentType):388 _PathIsContentTypeA = windll.shlwapi.PathIsContentTypeA389 _PathIsContentTypeA.argtypes = [LPSTR, LPSTR]390 _PathIsContentTypeA.restype = bool391 return _PathIsContentTypeA(pszPath, pszContentType)392def PathIsContentTypeW(pszPath, pszContentType):393 _PathIsContentTypeW = windll.shlwapi.PathIsContentTypeW394 _PathIsContentTypeW.argtypes = [LPWSTR, LPWSTR]395 _PathIsContentTypeW.restype = bool396 return _PathIsContentTypeW(pszPath, pszContentType)397PathIsContentType = GuessStringType(PathIsContentTypeA, PathIsContentTypeW)398# BOOL PathIsDirectory(399# LPCTSTR pszPath400# );401def PathIsDirectoryA(pszPath):402 _PathIsDirectoryA = windll.shlwapi.PathIsDirectoryA403 _PathIsDirectoryA.argtypes = [LPSTR]404 _PathIsDirectoryA.restype = bool405 return _PathIsDirectoryA(pszPath)406def PathIsDirectoryW(pszPath):407 _PathIsDirectoryW = windll.shlwapi.PathIsDirectoryW408 _PathIsDirectoryW.argtypes = [LPWSTR]409 _PathIsDirectoryW.restype = bool410 return _PathIsDirectoryW(pszPath)411PathIsDirectory = GuessStringType(PathIsDirectoryA, PathIsDirectoryW)412# BOOL PathIsDirectoryEmpty(413# LPCTSTR pszPath414# );415def PathIsDirectoryEmptyA(pszPath):416 _PathIsDirectoryEmptyA = windll.shlwapi.PathIsDirectoryEmptyA417 _PathIsDirectoryEmptyA.argtypes = [LPSTR]418 _PathIsDirectoryEmptyA.restype = bool419 return _PathIsDirectoryEmptyA(pszPath)420def PathIsDirectoryEmptyW(pszPath):421 _PathIsDirectoryEmptyW = windll.shlwapi.PathIsDirectoryEmptyW422 _PathIsDirectoryEmptyW.argtypes = [LPWSTR]423 _PathIsDirectoryEmptyW.restype = bool424 return _PathIsDirectoryEmptyW(pszPath)425PathIsDirectoryEmpty = GuessStringType(PathIsDirectoryEmptyA, PathIsDirectoryEmptyW)426# BOOL PathIsNetworkPath(427# LPCTSTR pszPath428# );429def PathIsNetworkPathA(pszPath):430 _PathIsNetworkPathA = windll.shlwapi.PathIsNetworkPathA431 _PathIsNetworkPathA.argtypes = [LPSTR]432 _PathIsNetworkPathA.restype = bool433 return _PathIsNetworkPathA(pszPath)434def PathIsNetworkPathW(pszPath):435 _PathIsNetworkPathW = windll.shlwapi.PathIsNetworkPathW436 _PathIsNetworkPathW.argtypes = [LPWSTR]437 _PathIsNetworkPathW.restype = bool438 return _PathIsNetworkPathW(pszPath)439PathIsNetworkPath = GuessStringType(PathIsNetworkPathA, PathIsNetworkPathW)440# BOOL PathIsRelative(441# LPCTSTR lpszPath442# );443def PathIsRelativeA(pszPath):444 _PathIsRelativeA = windll.shlwapi.PathIsRelativeA445 _PathIsRelativeA.argtypes = [LPSTR]446 _PathIsRelativeA.restype = bool447 return _PathIsRelativeA(pszPath)448def PathIsRelativeW(pszPath):449 _PathIsRelativeW = windll.shlwapi.PathIsRelativeW450 _PathIsRelativeW.argtypes = [LPWSTR]451 _PathIsRelativeW.restype = bool452 return _PathIsRelativeW(pszPath)453PathIsRelative = GuessStringType(PathIsRelativeA, PathIsRelativeW)454# BOOL PathIsRoot(455# LPCTSTR pPath456# );457def PathIsRootA(pszPath):458 _PathIsRootA = windll.shlwapi.PathIsRootA459 _PathIsRootA.argtypes = [LPSTR]460 _PathIsRootA.restype = bool461 return _PathIsRootA(pszPath)462def PathIsRootW(pszPath):463 _PathIsRootW = windll.shlwapi.PathIsRootW464 _PathIsRootW.argtypes = [LPWSTR]465 _PathIsRootW.restype = bool466 return _PathIsRootW(pszPath)467PathIsRoot = GuessStringType(PathIsRootA, PathIsRootW)468# BOOL PathIsSameRoot(469# LPCTSTR pszPath1,470# LPCTSTR pszPath2471# );472def PathIsSameRootA(pszPath1, pszPath2):473 _PathIsSameRootA = windll.shlwapi.PathIsSameRootA474 _PathIsSameRootA.argtypes = [LPSTR, LPSTR]475 _PathIsSameRootA.restype = bool476 return _PathIsSameRootA(pszPath1, pszPath2)477def PathIsSameRootW(pszPath1, pszPath2):478 _PathIsSameRootW = windll.shlwapi.PathIsSameRootW479 _PathIsSameRootW.argtypes = [LPWSTR, LPWSTR]480 _PathIsSameRootW.restype = bool481 return _PathIsSameRootW(pszPath1, pszPath2)482PathIsSameRoot = GuessStringType(PathIsSameRootA, PathIsSameRootW)483# BOOL PathIsUNC(484# LPCTSTR pszPath485# );486def PathIsUNCA(pszPath):487 _PathIsUNCA = windll.shlwapi.PathIsUNCA488 _PathIsUNCA.argtypes = [LPSTR]489 _PathIsUNCA.restype = bool490 return _PathIsUNCA(pszPath)491def PathIsUNCW(pszPath):492 _PathIsUNCW = windll.shlwapi.PathIsUNCW493 _PathIsUNCW.argtypes = [LPWSTR]494 _PathIsUNCW.restype = bool495 return _PathIsUNCW(pszPath)496PathIsUNC = GuessStringType(PathIsUNCA, PathIsUNCW)497# XXX WARNING498# PathMakePretty turns filenames into all lowercase.499# I'm not sure how well that might work on Wine.500# BOOL PathMakePretty(501# LPCTSTR pszPath502# );503def PathMakePrettyA(pszPath):504 _PathMakePrettyA = windll.shlwapi.PathMakePrettyA505 _PathMakePrettyA.argtypes = [LPSTR]506 _PathMakePrettyA.restype = bool507 _PathMakePrettyA.errcheck = RaiseIfZero508 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)509 _PathMakePrettyA(pszPath)510 return pszPath.value511def PathMakePrettyW(pszPath):512 _PathMakePrettyW = windll.shlwapi.PathMakePrettyW513 _PathMakePrettyW.argtypes = [LPWSTR]514 _PathMakePrettyW.restype = bool515 _PathMakePrettyW.errcheck = RaiseIfZero516 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)517 _PathMakePrettyW(pszPath)518 return pszPath.value519PathMakePretty = GuessStringType(PathMakePrettyA, PathMakePrettyW)520# void PathRemoveArgs(521# LPTSTR pszPath522# );523def PathRemoveArgsA(pszPath):524 _PathRemoveArgsA = windll.shlwapi.PathRemoveArgsA525 _PathRemoveArgsA.argtypes = [LPSTR]526 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)527 _PathRemoveArgsA(pszPath)528 return pszPath.value529def PathRemoveArgsW(pszPath):530 _PathRemoveArgsW = windll.shlwapi.PathRemoveArgsW531 _PathRemoveArgsW.argtypes = [LPWSTR]532 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)533 _PathRemoveArgsW(pszPath)534 return pszPath.value535PathRemoveArgs = GuessStringType(PathRemoveArgsA, PathRemoveArgsW)536# void PathRemoveBackslash(537# LPTSTR pszPath538# );539def PathRemoveBackslashA(pszPath):540 _PathRemoveBackslashA = windll.shlwapi.PathRemoveBackslashA541 _PathRemoveBackslashA.argtypes = [LPSTR]542 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)543 _PathRemoveBackslashA(pszPath)544 return pszPath.value545def PathRemoveBackslashW(pszPath):546 _PathRemoveBackslashW = windll.shlwapi.PathRemoveBackslashW547 _PathRemoveBackslashW.argtypes = [LPWSTR]548 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)549 _PathRemoveBackslashW(pszPath)550 return pszPath.value551PathRemoveBackslash = GuessStringType(PathRemoveBackslashA, PathRemoveBackslashW)552# void PathRemoveExtension(553# LPTSTR pszPath554# );555def PathRemoveExtensionA(pszPath):556 _PathRemoveExtensionA = windll.shlwapi.PathRemoveExtensionA557 _PathRemoveExtensionA.argtypes = [LPSTR]558 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)559 _PathRemoveExtensionA(pszPath)560 return pszPath.value561def PathRemoveExtensionW(pszPath):562 _PathRemoveExtensionW = windll.shlwapi.PathRemoveExtensionW563 _PathRemoveExtensionW.argtypes = [LPWSTR]564 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)565 _PathRemoveExtensionW(pszPath)566 return pszPath.value567PathRemoveExtension = GuessStringType(PathRemoveExtensionA, PathRemoveExtensionW)568# void PathRemoveFileSpec(569# LPTSTR pszPath570# );571def PathRemoveFileSpecA(pszPath):572 _PathRemoveFileSpecA = windll.shlwapi.PathRemoveFileSpecA573 _PathRemoveFileSpecA.argtypes = [LPSTR]574 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)575 _PathRemoveFileSpecA(pszPath)576 return pszPath.value577def PathRemoveFileSpecW(pszPath):578 _PathRemoveFileSpecW = windll.shlwapi.PathRemoveFileSpecW579 _PathRemoveFileSpecW.argtypes = [LPWSTR]580 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)581 _PathRemoveFileSpecW(pszPath)582 return pszPath.value583PathRemoveFileSpec = GuessStringType(PathRemoveFileSpecA, PathRemoveFileSpecW)584# BOOL PathRenameExtension(585# LPTSTR pszPath,586# LPCTSTR pszExt587# );588def PathRenameExtensionA(pszPath, pszExt):589 _PathRenameExtensionA = windll.shlwapi.PathRenameExtensionA590 _PathRenameExtensionA.argtypes = [LPSTR, LPSTR]591 _PathRenameExtensionA.restype = bool592 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)593 if _PathRenameExtensionA(pszPath, pszExt):594 return pszPath.value595 return None596def PathRenameExtensionW(pszPath, pszExt):597 _PathRenameExtensionW = windll.shlwapi.PathRenameExtensionW598 _PathRenameExtensionW.argtypes = [LPWSTR, LPWSTR]599 _PathRenameExtensionW.restype = bool600 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)601 if _PathRenameExtensionW(pszPath, pszExt):602 return pszPath.value603 return None604PathRenameExtension = GuessStringType(PathRenameExtensionA, PathRenameExtensionW)605# BOOL PathUnExpandEnvStrings(606# LPCTSTR pszPath,607# LPTSTR pszBuf,608# UINT cchBuf609# );610def PathUnExpandEnvStringsA(pszPath):611 _PathUnExpandEnvStringsA = windll.shlwapi.PathUnExpandEnvStringsA612 _PathUnExpandEnvStringsA.argtypes = [LPSTR, LPSTR]613 _PathUnExpandEnvStringsA.restype = bool614 _PathUnExpandEnvStringsA.errcheck = RaiseIfZero615 cchBuf = MAX_PATH616 pszBuf = ctypes.create_string_buffer("", cchBuf)617 _PathUnExpandEnvStringsA(pszPath, pszBuf, cchBuf)618 return pszBuf.value619def PathUnExpandEnvStringsW(pszPath):620 _PathUnExpandEnvStringsW = windll.shlwapi.PathUnExpandEnvStringsW621 _PathUnExpandEnvStringsW.argtypes = [LPWSTR, LPWSTR]622 _PathUnExpandEnvStringsW.restype = bool623 _PathUnExpandEnvStringsW.errcheck = RaiseIfZero624 cchBuf = MAX_PATH625 pszBuf = ctypes.create_unicode_buffer(u"", cchBuf)626 _PathUnExpandEnvStringsW(pszPath, pszBuf, cchBuf)627 return pszBuf.value628PathUnExpandEnvStrings = GuessStringType(PathUnExpandEnvStringsA, PathUnExpandEnvStringsW)629#==============================================================================630# This calculates the list of exported symbols.631_all = set(vars().keys()).difference(_all)632__all__ = [_x for _x in _all if not _x.startswith('_')]633__all__.sort()...
wrapper_util.py
Source:wrapper_util.py
...32 sys.stderr.write('Error: Python %d.%d is not supported. Please use '33 'version %s.\n' % (version_tuple[0], version_tuple[1],34 minimum_version_string))35 sys.exit(1)36def get_dir_path(script_file, sibling):37 """Get a path to the directory of the script script_file.38 By default, the canonical path (symlinks resolved) will be returned. In some39 environments the canonical directory is not sufficient because different40 parts of the SDK are referenced by symlinks, including script_file.41 In this case, the non-canonical path to script_file's directory will be42 returned (i.e., the directory where the symlink lives, not the directory43 where it points).44 Args:45 script_file: The script file whose directory is wanted.46 sibling: Relative path to a sibling of script_file. Choose a sibling47 that is potentially symlinked into the parent directory.48 Returns:49 A directory name.50 Raises:51 ValueError: If no proper path could be determined.52 """53 if 'GAE_SDK_ROOT' in os.environ:54 gae_sdk_root = os.path.abspath(os.environ['GAE_SDK_ROOT'])55 os.environ['GAE_SDK_ROOT'] = gae_sdk_root56 for dir_path in [gae_sdk_root,57 os.path.join(gae_sdk_root, 'google_appengine')]:58 if os.path.exists(os.path.join(dir_path, sibling)):59 return dir_path60 raise ValueError('GAE_SDK_ROOT %r does not refer to a valid SDK '61 'directory' % gae_sdk_root)62 else:63 py_file = script_file.replace('.pyc', '.py')64 dir_paths = [os.path.abspath(os.path.dirname(os.path.realpath(py_file))),65 os.path.abspath(os.path.dirname(py_file))]66 for dir_path in dir_paths:67 sibling_path = os.path.join(dir_path, sibling)68 if os.path.exists(sibling_path):69 return dir_path70 raise ValueError('Could not determine SDK root; please set GAE_SDK_ROOT '71 'environment variable.')72class Paths(object):73 """Encapsulates the path and unwrapped script details for a wrapper script.74 Most of the attributes of this object are there so that wrapper_script_v175 can continue to export the same global variables it historically has, in case76 any end-users are referencing those.77 Attributes:78 default_script_dir: the path where the corresponding unwrapped script will79 be found, apart from a few exceptional scripts.80 """81 def __init__(self, dir_path):82 """Make a new Paths object.83 Args:84 dir_path: the directory path where the calling script is to be found.85 This directory should have a lib subdirectory.86 """87 self.v1_extra_paths = [88 dir_path,89 os.path.join(dir_path, 'lib', 'antlr3'),90 os.path.join(dir_path, 'lib', 'django-0.96'),91 os.path.join(dir_path, 'lib', 'fancy_urllib'),92 os.path.join(dir_path, 'lib', 'ipaddr'),93 os.path.join(dir_path, 'lib', 'jinja2-2.6'),94 os.path.join(dir_path, 'lib', 'protorpc-1.0'),95 os.path.join(dir_path, 'lib', 'PyAMF'),96 os.path.join(dir_path, 'lib', 'markupsafe'),97 os.path.join(dir_path, 'lib', 'webob_0_9'),98 os.path.join(dir_path, 'lib', 'webapp2-2.5.2'),99 os.path.join(dir_path, 'lib', 'yaml', 'lib'),100 os.path.join(dir_path, 'lib', 'simplejson'),101 os.path.join(dir_path, 'lib', 'rsa'),102 os.path.join(dir_path, 'lib', 'pyasn1'),103 os.path.join(dir_path, 'lib', 'pyasn1_modules'),104 ]105 self.api_server_extra_paths = [106 os.path.join(dir_path, 'lib', 'argparse'),107 ]108 self.endpointscfg_extra_paths = [109 os.path.join(dir_path, 'lib', 'cherrypy'),110 os.path.join(dir_path, 'lib', 'concurrent'),111 os.path.join(dir_path, 'lib', 'endpoints-1.0'),112 ]113 self.oauth_client_extra_paths = [114 os.path.join(dir_path, 'lib', 'google-api-python-client'),115 os.path.join(dir_path, 'lib', 'httplib2'),116 os.path.join(dir_path, 'lib', 'python-gflags'),117 ]118 self.google_sql_extra_paths = self.oauth_client_extra_paths + [119 os.path.join(dir_path, 'lib', 'enum'),120 os.path.join(dir_path, 'lib', 'grizzled'),121 os.path.join(dir_path, 'lib', 'oauth2'),122 os.path.join(dir_path, 'lib', 'prettytable'),123 os.path.join(dir_path, 'lib', 'sqlcmd'),124 ]125 devappserver2_dir = os.path.join(126 dir_path, 'google', 'appengine', 'tools', 'devappserver2')127 php_runtime_dir = os.path.join(devappserver2_dir, 'php')128 python_runtime_dir = os.path.join(devappserver2_dir, 'python')129 stub_paths = [130 os.path.join(dir_path, 'lib', 'antlr3'),131 os.path.join(dir_path, 'lib', 'fancy_urllib'),132 os.path.join(dir_path, 'lib', 'ipaddr'),133 os.path.join(dir_path, 'lib', 'yaml-3.10'),134 os.path.join(dir_path, 'lib', 'rsa'),135 os.path.join(dir_path, 'lib', 'pyasn1'),136 os.path.join(dir_path, 'lib', 'pyasn1_modules'),137 ]138 self.v2_extra_paths = stub_paths + [139 dir_path,140 os.path.join(dir_path, 'lib', 'simplejson'),141 os.path.join(dir_path, 'lib', 'django-1.4'),142 os.path.join(dir_path, 'lib', 'endpoints-1.0'),143 os.path.join(dir_path, 'lib', 'jinja2-2.6'),144 os.path.join(dir_path, 'lib', 'protorpc-1.0'),145 os.path.join(dir_path, 'lib', 'PyAMF-0.6.1'),146 os.path.join(dir_path, 'lib', 'markupsafe-0.15'),147 os.path.join(dir_path, 'lib', 'webob-1.2.3'),148 os.path.join(dir_path, 'lib', 'webapp2-2.5.2'),149 ]150 devappserver2_paths = stub_paths + [151 dir_path,152 os.path.join(dir_path, 'lib', 'concurrent'),153 os.path.join(dir_path, 'lib', 'cherrypy'),154 os.path.join(dir_path, 'lib', 'requests'),155 os.path.join(dir_path, 'lib', 'six'),156 os.path.join(dir_path, 'lib', 'websocket'),157 os.path.join(dir_path, 'lib', 'docker'),158 os.path.join(dir_path, 'lib', 'jinja2-2.6'),159 os.path.join(dir_path, 'lib', 'webob-1.2.3'),160 os.path.join(dir_path, 'lib', 'webapp2-2.5.1'),161 ]162 php_runtime_paths = [163 dir_path,164 os.path.join(dir_path, 'lib', 'concurrent'),165 os.path.join(dir_path, 'lib', 'cherrypy'),166 os.path.join(dir_path, 'lib', 'yaml-3.10'),167 ]168 python_runtime_paths = [169 dir_path,170 os.path.join(dir_path, 'lib', 'concurrent'),171 os.path.join(dir_path, 'lib', 'cherrypy'),172 os.path.join(dir_path, 'lib', 'fancy_urllib'),173 os.path.join(dir_path, 'lib', 'protorpc-1.0'),174 os.path.join(dir_path, 'lib', 'yaml-3.10'),175 ]176 self._script_to_paths = {177 'api_server.py': self.v1_extra_paths + self.api_server_extra_paths,178 'appcfg.py': self.v1_extra_paths + self.oauth_client_extra_paths,179 'backends_conversion.py': self.v1_extra_paths,180 'bulkload_client.py': self.v1_extra_paths,181 'bulkloader.py': self.v1_extra_paths + self.oauth_client_extra_paths,182 'dev_appserver.py': devappserver2_paths,183 'download_appstats.py': self.v1_extra_paths,184 'endpointscfg.py': self.v1_extra_paths + self.endpointscfg_extra_paths,185 'gen_protorpc.py': self.v1_extra_paths,186 'google_sql.py': self.v1_extra_paths + self.google_sql_extra_paths,187 'old_dev_appserver.py': self.v1_extra_paths,188 'php_cli.py': devappserver2_paths,189 'remote_api_shell.py': self.v1_extra_paths,190 'vmboot.py': self.v1_extra_paths,191 '_php_runtime.py': php_runtime_paths,192 '_python_runtime.py': python_runtime_paths,193 }194 self._wrapper_name_to_real_name = {195 'old_dev_appserver.py': 'dev_appserver_main.py',196 'dev_appserver.py': 'devappserver2.py',197 '_php_runtime.py': 'runtime.py',198 '_python_runtime.py': 'runtime.py',199 }200 self.default_script_dir = os.path.join(201 dir_path, 'google', 'appengine', 'tools')202 self.google_sql_dir = os.path.join(203 dir_path, 'google', 'storage', 'speckle', 'python', 'tool')204 self._script_to_dir = {205 'google_sql.py': self.google_sql_dir,206 'dev_appserver.py': devappserver2_dir,207 '_php_runtime.py': php_runtime_dir,208 '_python_runtime.py': python_runtime_dir,209 }210 self._sys_paths_to_scrub = {211 'dev_appserver.py':212 [os.path.normcase(os.path.join(dir_path, 'launcher'))],213 }214 def script_paths(self, script_name):215 """Returns the sys.path prefix appropriate for this script.216 Args:217 script_name: the basename of the script, for example 'appcfg.py'.218 """219 try:220 return self._script_to_paths[script_name]221 except KeyError:222 raise KeyError('Script name %s not recognized' % script_name)223 def script_file(self, script_name):224 """Returns the absolute name of the wrapped script.225 Args:226 script_name: the basename of the script, for example 'appcfg.py'.227 """228 script_dir = self._script_to_dir.get(script_name, self.default_script_dir)229 script_name = self._wrapper_name_to_real_name.get(script_name, script_name)230 return os.path.join(script_dir, script_name)231 def scrub_path(self, script_name, paths):232 """Removes bad paths from a list of paths.233 Args:234 script_name: the basename of the script, for example 'appcfg.py'.235 paths: a list of paths236 Returns:237 The list of paths with any bad paths removed.238 """239 sys_paths_to_scrub = self._sys_paths_to_scrub.get(script_name, [])240 return [path for path in paths...
test_util_filepath.py
Source:test_util_filepath.py
1import unittest2import vdebug.opts3from vdebug.util import FilePath4from vdebug.error import FilePathError5class LocalFilePathTest(unittest.TestCase):6 def setUp(self):7 vdebug.opts.Options.set({'path_maps':{}})8 def test_as_local(self):9 filename = "/home/user/some/path"10 file = FilePath(filename)11 self.assertEqual(filename,file.as_local())12 def test_remote_prefix(self):13 prefix = "file://"14 filename = "/home/user/some/path"15 file = FilePath(prefix+filename)16 self.assertEqual(filename,file.as_local())17 def test_quoted(self):18 quoted = "file:///home/user/file%2etcl"19 file = FilePath(quoted)20 self.assertEqual("/home/user/file.tcl",file.as_local())21 def test_win(self):22 quoted = "file:///C:/home/user/file%2etcl"23 file = FilePath(quoted)24 self.assertEqual("C:\\home\\user\\file.tcl",file.as_local())25 def test_as_remote(self):26 filename = "/home/user/some/path"27 file = FilePath(filename)28 self.assertEqual("file://"+filename,file.as_remote())29 def test_eq(self):30 filename = "/home/user/some/path"31 file1 = FilePath(filename)32 file2 = FilePath(filename)33 assert file1 == file234 def test_eq_false(self):35 filename1 = "/home/user/some/path"36 file1 = FilePath(filename1)37 filename2 = "/home/user/some/other/path"38 file2 = FilePath(filename2)39 self.assertFalse(file1 == file2)40 def test_neq(self):41 filename1 = "/home/user/some/path"42 file1 = FilePath(filename1)43 filename2 = "/home/user/some/other/path"44 file2 = FilePath(filename2)45 assert file1 != file246 def test_neq_false(self):47 filename = "/home/user/some/path"48 file1 = FilePath(filename)49 file2 = FilePath(filename)50 self.assertFalse(file1 != file2)51 def test_add(self):52 filename = "/home/user/some/path"53 file = FilePath(filename)54 append = "/myfile.txt"55 assert (file + append) == (filename + append)56 def test_add_reverse(self):57 filename = "/user/some/path"58 file = FilePath(filename)59 prepend = "/home/"60 assert (prepend + file) == (prepend + filename)61 def test_empty_file_raises_error(self):62 self.assertRaises(FilePathError,FilePath,"")63class RemotePathTest(unittest.TestCase):64 def setUp(self):65 vdebug.opts.Options.set({'path_maps':{'remote1':'local1', 'remote2':'local2'}})66 def test_as_local(self):67 filename = "/remote1/path/to/file"68 file = FilePath(filename)69 self.assertEqual("/local1/path/to/file",file.as_local())70 filename = "/remote2/path/to/file"71 file = FilePath(filename)72 self.assertEqual("/local2/path/to/file",file.as_local())73 def test_as_local_with_uri(self):74 filename = "file:///remote1/path/to/file"75 file = FilePath(filename)76 self.assertEqual("/local1/path/to/file",file.as_local())77 filename = "file:///remote2/path/to/file"78 file = FilePath(filename)79 self.assertEqual("/local2/path/to/file",file.as_local())80 def test_as_local_does_nothing(self):81 filename = "/the/remote/path/to/file"82 file = FilePath(filename)83 self.assertEqual("/the/remote/path/to/file",file.as_local())84 def test_as_remote_with_unix_paths(self):85 filename = "/local1/path/to/file"86 file = FilePath(filename)87 self.assertEqual("file:///remote1/path/to/file",file.as_remote())88 filename = "file:///local2/path/to/file"89 file = FilePath(filename)90 self.assertEqual("file:///remote2/path/to/file",file.as_remote())91 def test_as_remote_with_win_paths(self):92 filename = "C:/local1/path/to/file"93 file = FilePath(filename)94 self.assertEqual("file:///C:/remote1/path/to/file",file.as_remote())95 filename = "file:///C:/local2/path/to/file"96 file = FilePath(filename)97 self.assertEqual("file:///C:/remote2/path/to/file",file.as_remote())98 def test_as_remote_with_backslashed_win_paths(self):99 filename = "C:\\local1\\path\\to\\file"100 file = FilePath(filename)101 self.assertEqual("file:///C:/remote1/path/to/file",file.as_remote())102 filename = "C:\\local2\\path\\to\\file"103 file = FilePath(filename)104 self.assertEqual("file:///C:/remote2/path/to/file",file.as_remote())105 filename = "C:/local2/path/to/file"106 file = FilePath(filename)107 self.assertEqual("C:\\local2\\path\\to\\file",file.as_local())108class RemoteWinLocalUnixPathTest(unittest.TestCase):109 def setUp(self):110 vdebug.opts.Options.set({'path_maps':{'G:\\remote\\path':'/local/path', 'G:\\remote2\\path':'/local2/path'}})111 def test_as_local(self):112 filename = "G:\\remote\\path\\to\\file"113 file = FilePath(filename)114 self.assertEqual("/local/path/to/file",file.as_local())115 filename = "file:///G:/remote2/path/to/file"116 file = FilePath(filename)117 self.assertEqual("/local2/path/to/file",file.as_local())118 def test_as_local_does_nothing(self):119 filename = "/the/path/to/file"120 file = FilePath(filename)121 self.assertEqual("/the/path/to/file",file.as_local())122 def test_as_remote(self):123 filename = "/local/path/to/file"124 file = FilePath(filename)125 self.assertEqual("file:///G:/remote/path/to/file",file.as_remote())126 filename = "file:///local2/path/to/file"127 file = FilePath(filename)128 self.assertEqual("file:///G:/remote2/path/to/file",file.as_remote())129class RemoteUnixLocalWinPathTest(unittest.TestCase):130 def setUp(self):131 vdebug.opts.Options.set({'path_maps':{'/remote/path':'G:\\local\\path', '/remote2/path':'G:\\local2\\path'}})132 def test_as_local(self):133 filename = "/remote/path/to/file"134 file = FilePath(filename)135 self.assertEqual("G:\\local\\path\\to\\file",file.as_local())136 filename = "file:///remote2/path/to/file"137 file = FilePath(filename)138 self.assertEqual("G:\\local2\\path\\to\\file",file.as_local())139 def test_as_local_does_nothing(self):140 filename = "G:\\the\\path\\to\\file"141 file = FilePath(filename)142 self.assertEqual("G:\\the\\path\\to\\file",file.as_local())143 def test_as_remote(self):144 filename = "G:\\local\\path\\to\\file"145 file = FilePath(filename)146 self.assertEqual("file:///remote/path/to/file",file.as_remote())147 filename = "file:///G:/local2/path/to/file"148 file = FilePath(filename)149 self.assertEqual("file:///remote2/path/to/file",file.as_remote())150class MismatchingSeparatorsTest(unittest.TestCase):151 def setUp(self):152 vdebug.opts.Options.set({'path_maps':{'remote1/':'local1', 'remote2':'local2/'}})153 def test_as_local(self):154 filename = "/remote1/path/to/file"155 file = FilePath(filename)156 self.assertEqual("/local1/path/to/file",file.as_local())157 filename = "/remote2/path/to/file"158 file = FilePath(filename)159 self.assertEqual("/local2/path/to/file",file.as_local())160 def test_as_remote(self):161 filename = "/local1/path/to/file"162 file = FilePath(filename)163 self.assertEqual("file:///remote1/path/to/file",file.as_remote())164 filename = "/local2/path/to/file"165 file = FilePath(filename)...
tracing_project.py
Source:tracing_project.py
...23 for dirpath, _, filenames in os.walk(source_path):24 for f in filenames:25 if f.startswith('.'):26 continue27 x = os.path.abspath(os.path.join(dirpath, f))28 all_filenames.add(x)29 return all_filenames30def _IsFilenameATest(x):31 if x.endswith('_test.js'):32 return True33 if x.endswith('_test.html'):34 return True35 if x.endswith('_unittest.js'):36 return True37 if x.endswith('_unittest.html'):38 return True39 # TODO(nduca): Add content test?40 return False41class TracingProject(object):42 catapult_path = os.path.abspath(43 os.path.join(os.path.dirname(__file__), os.path.pardir))44 tracing_root_path = os.path.join(catapult_path, 'tracing')45 trace_processor_root_path = os.path.join(catapult_path, 'trace_processor')46 tracing_src_path = os.path.join(tracing_root_path, 'tracing')47 extras_path = os.path.join(tracing_src_path, 'extras')48 ui_extras_path = os.path.join(tracing_src_path, 'ui', 'extras')49 catapult_third_party_path = os.path.join(catapult_path, 'third_party')50 polymer_path = os.path.join(catapult_third_party_path, 'polymer')51 tracing_third_party_path = os.path.join(tracing_root_path, 'third_party')52 py_vulcanize_path = os.path.join(catapult_third_party_path, 'py_vulcanize')53 vinn_path = os.path.join(catapult_third_party_path, 'vinn')54 jszip_path = os.path.join(tracing_third_party_path, 'jszip')55 glmatrix_path = os.path.join(56 tracing_third_party_path, 'gl-matrix', 'dist')57 mannwhitneyu_path = os.path.join(58 tracing_third_party_path, 'mannwhitneyu')59 ui_path = os.path.join(tracing_src_path, 'ui')60 d3_path = os.path.join(tracing_third_party_path, 'd3')61 chai_path = os.path.join(tracing_third_party_path, 'chai')62 mocha_path = os.path.join(tracing_third_party_path, 'mocha')63 oboe_path = os.path.join(tracing_third_party_path, 'oboe')64 mre_path = os.path.join(tracing_src_path, 'mre')65 metrics_path = os.path.join(tracing_src_path, 'metrics')66 diagnostics_path = os.path.join(tracing_src_path, 'value', 'diagnostics')67 value_ui_path = os.path.join(tracing_src_path, 'value', 'ui')68 metrics_ui_path = os.path.join(tracing_src_path, 'metrics', 'ui')69 test_data_path = os.path.join(tracing_root_path, 'test_data')70 skp_data_path = os.path.join(tracing_root_path, 'skp_data')71 rjsmin_path = os.path.join(72 tracing_third_party_path, 'tvcm', 'third_party', 'rjsmin')73 rcssmin_path = os.path.join(74 tracing_third_party_path, 'tvcm', 'third_party', 'rcssmin')75 def __init__(self):76 self.source_paths = []77 self.source_paths.append(self.tracing_root_path)78 self.source_paths.append(self.polymer_path)79 self.source_paths.append(self.tracing_third_party_path)80 self.source_paths.append(self.mre_path)81 self.source_paths.append(self.jszip_path)82 self.source_paths.append(self.glmatrix_path)83 self.source_paths.append(self.mannwhitneyu_path)84 self.source_paths.append(self.d3_path)85 self.source_paths.append(self.chai_path)86 self.source_paths.append(self.mocha_path)87 self.source_paths.append(self.oboe_path)88 def CreateVulcanizer(self):89 from py_vulcanize import project as project_module90 return project_module.Project(self.source_paths)91 def IsD8CompatibleFile(self, filename):92 if filename.startswith(self.ui_path):93 return False94 if filename.startswith(self.value_ui_path):95 return False96 if filename.startswith(self.metrics_ui_path):97 return False98 return True99 def FindAllTestModuleRelPaths(self, pred=None):100 if pred is None:101 pred = lambda x: True102 all_filenames = _FindAllFilesRecursive([self.tracing_src_path])103 test_module_filenames = [x for x in all_filenames if104 _IsFilenameATest(x) and pred(x)]105 test_module_filenames.sort()106 return [os.path.relpath(x, self.tracing_root_path)107 for x in test_module_filenames]108 def FindAllMetricsModuleRelPaths(self):109 all_filenames = _FindAllFilesRecursive([self.tracing_src_path])110 all_metrics_module_filenames = []111 for x in all_filenames:112 if x.startswith(self.metrics_path) and not _IsFilenameATest(x):113 all_metrics_module_filenames.append(x)114 all_metrics_module_filenames.sort()115 return [os.path.relpath(x, self.tracing_root_path)116 for x in all_metrics_module_filenames]117 def FindAllDiagnosticsModuleRelPaths(self):118 all_filenames = _FindAllFilesRecursive([self.tracing_src_path])119 all_diagnostics_module_filenames = []120 for x in all_filenames:121 if x.startswith(self.diagnostics_path) and not _IsFilenameATest(x):122 all_diagnostics_module_filenames.append(x)123 all_diagnostics_module_filenames.sort()124 return [os.path.relpath(x, self.tracing_root_path)125 for x in all_diagnostics_module_filenames]126 def FindAllD8TestModuleRelPaths(self):127 return self.FindAllTestModuleRelPaths(pred=self.IsD8CompatibleFile)128 def GetConfigNames(self):129 config_files = [130 os.path.join(self.ui_extras_path, x)131 for x in os.listdir(self.ui_extras_path)132 if x.endswith('_config.html')133 ]134 config_files = [x for x in config_files if os.path.isfile(x)]135 config_basenames = [os.path.basename(x) for x in config_files]136 config_names = [re.match('(.+)_config.html$', x).group(1)137 for x in config_basenames]138 return config_names...
macpath.pyi
Source:macpath.pyi
...28 # ----- os.path function stubs -----29 if sys.version_info >= (3, 6):30 # Overloads are necessary to work around python/mypy#3644.31 @overload32 def abspath(path: _PathLike[AnyStr]) -> AnyStr: ...33 @overload34 def abspath(path: AnyStr) -> AnyStr: ...35 @overload36 def basename(path: _PathLike[AnyStr]) -> AnyStr: ...37 @overload38 def basename(path: AnyStr) -> AnyStr: ...39 @overload40 def dirname(path: _PathLike[AnyStr]) -> AnyStr: ...41 @overload42 def dirname(path: AnyStr) -> AnyStr: ...43 @overload44 def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ...45 @overload46 def expanduser(path: AnyStr) -> AnyStr: ...47 @overload48 def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ...49 @overload50 def expandvars(path: AnyStr) -> AnyStr: ...51 @overload52 def normcase(path: _PathLike[AnyStr]) -> AnyStr: ...53 @overload54 def normcase(path: AnyStr) -> AnyStr: ...55 @overload56 def normpath(path: _PathLike[AnyStr]) -> AnyStr: ...57 @overload58 def normpath(path: AnyStr) -> AnyStr: ...59 if sys.platform == 'win32':60 @overload61 def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...62 @overload63 def realpath(path: AnyStr) -> AnyStr: ...64 else:65 @overload66 def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ...67 @overload68 def realpath(filename: AnyStr) -> AnyStr: ...69 else:70 def abspath(path: AnyStr) -> AnyStr: ...71 def basename(path: AnyStr) -> AnyStr: ...72 def dirname(path: AnyStr) -> AnyStr: ...73 def expanduser(path: AnyStr) -> AnyStr: ...74 def expandvars(path: AnyStr) -> AnyStr: ...75 def normcase(path: AnyStr) -> AnyStr: ...76 def normpath(path: AnyStr) -> AnyStr: ...77 if sys.platform == 'win32':78 def realpath(path: AnyStr) -> AnyStr: ...79 else:80 def realpath(filename: AnyStr) -> AnyStr: ...81 if sys.version_info >= (3, 6):82 # In reality it returns str for sequences of _StrPath and bytes for sequences83 # of _BytesPath, but mypy does not accept such a signature.84 def commonpath(paths: Sequence[_PathType]) -> Any: ...85 elif sys.version_info >= (3, 5):86 def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...87 # NOTE: Empty lists results in '' (str) regardless of contained type.88 # Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes89 # So, fall back to Any90 def commonprefix(list: Sequence[_PathType]) -> Any: ...91 if sys.version_info >= (3, 3):92 def exists(path: Union[_PathType, int]) -> bool: ...93 else:94 def exists(path: _PathType) -> bool: ...95 def lexists(path: _PathType) -> bool: ...96 # These return float if os.stat_float_times() == True,97 # but int is a subclass of float.98 def getatime(path: _PathType) -> float: ...99 def getmtime(path: _PathType) -> float: ...100 def getctime(path: _PathType) -> float: ...101 def getsize(path: _PathType) -> int: ...102 def isabs(path: _PathType) -> bool: ...103 def isfile(path: _PathType) -> bool: ...104 def isdir(path: _PathType) -> bool: ...105 def islink(path: _PathType) -> bool: ...106 def ismount(path: _PathType) -> bool: ...107 if sys.version_info < (3, 0):108 # Make sure signatures are disjunct, and allow combinations of bytes and unicode.109 # (Since Python 2 allows that, too)110 # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in111 # a type error.112 @overload113 def join(__p1: bytes, *p: bytes) -> bytes: ...114 @overload115 def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...116 @overload117 def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...118 @overload119 def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...120 @overload121 def join(__p1: Text, *p: _PathType) -> Text: ...122 elif sys.version_info >= (3, 6):123 # Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway.124 @overload125 def join(path: _StrPath, *paths: _StrPath) -> Text: ...126 @overload127 def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ...128 else:129 def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...130 @overload131 def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ...132 @overload133 def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ...134 def samefile(path1: _PathType, path2: _PathType) -> bool: ...135 def sameopenfile(fp1: int, fp2: int) -> bool: ...136 def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ...137 if sys.version_info >= (3, 6):138 @overload139 def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...140 @overload141 def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...142 @overload143 def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...144 @overload145 def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ...146 @overload147 def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ......
prepare_test_data.py
Source:prepare_test_data.py
...9# Generic helper to read data from 'CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY' to local machine10# One should use this helper when copying code is needed11# TODO: Update the other data loaders to reuse this code12def _data_copier(src_files, dst_files):13 src_files = [os.path.normpath(os.path.join((os.environ[envvar]), \14 *src_file.split("/"))) for src_file in src_files]15 16 dst_files = [os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(os.getcwd())), \17 *dst_file.split("/"))) for dst_file in dst_files] 18 19 if not len(src_files) == len(dst_files):20 raise Exception('The length of src and dst should be same')21 22 for src_dst_file in zip(src_files, dst_files):23 # Note index 0 is the source and index 1 is destination24 if not os.path.isfile(src_dst_file[1]):25 # copy from backup location26 print("Copying file from: ", src_dst_file[0])27 print("Copying file to: ", src_dst_file[1])28 copyfile( src_dst_file[0], src_dst_file[1])29 else:30 print("Reusing cached file", src_dst_file[1]) 31def prepare_CIFAR10_data(): 32 base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),33 *"../../../../Examples/Image/DataSets/CIFAR-10".split("/"))34 base_path = os.path.normpath(base_path)35 # If {train,test}_map.txt don't exist locally, copy to local location36 if not (os.path.isfile(os.path.join(base_path, 'train_map.txt')) and os.path.isfile(os.path.join(base_path, 'test_map.txt'))): 37 # copy from backup location 38 base_path_bak = os.path.join(os.environ[envvar],39 *"Image/CIFAR/v0/cifar-10-batches-py".split("/"))40 base_path_bak = os.path.normpath(base_path_bak)41 42 copyfile(os.path.join(base_path_bak, 'train_map.txt'), os.path.join(base_path, 'train_map.txt'))43 copyfile(os.path.join(base_path_bak, 'test_map.txt'), os.path.join(base_path, 'test_map.txt'))44 if not os.path.isdir(os.path.join(base_path, 'cifar-10-batches-py')): 45 os.mkdir(os.path.join(base_path, 'cifar-10-batches-py'))46 copyfile(os.path.join(base_path_bak, 'data.zip'), os.path.join(base_path, 'cifar-10-batches-py', 'data.zip'))47 copyfile(os.path.join(base_path_bak, 'CIFAR-10_mean.xml'), os.path.join(base_path, 'CIFAR-10_mean.xml'))48 return base_path49def prepare_ImageNet_data():50 base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),51 *"../../../../Examples/Image/DataSets/ImageNet/test_data".split("/"))52 base_path = os.path.normpath(base_path)53 if not os.path.isdir(base_path):54 os.mkdir(base_path)55 56 # If val1024_map.txt don't exist locally, copy to local location57 if not (os.path.isfile(os.path.join(base_path, 'train_map.txt')) and os.path.isfile(os.path.join(base_path, 'val_map.txt'))):58 # copy from backup location 59 base_path_bak = os.path.join(os.environ[envvar],60 *"Image/ImageNet/2012/v0".split("/"))61 base_path_bak = os.path.normpath(base_path_bak)62 63 copyfile(os.path.join(base_path_bak, 'val1024_map.txt'), os.path.join(base_path, 'train_map.txt'))64 copyfile(os.path.join(base_path_bak, 'val1024_map.txt'), os.path.join(base_path, 'val_map.txt'))65 copyfile(os.path.join(base_path_bak, 'val1024.zip'), os.path.join(base_path, 'val1024.zip'))66 return base_path67def prepare_Grocery_data():68 base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),69 *"../../../../Examples/Image/DataSets/Grocery".split("/"))70 base_path = os.path.normpath(base_path)71 # If val1024_map.txt don't exist locally, copy to local location72 if not os.path.isfile(os.path.join(base_path, 'test.txt')):73 # copy from backup location74 base_path_bak = os.path.join(os.environ[envvar],75 *"Image/Grocery".split("/"))76 base_path_bak = os.path.normpath(base_path_bak)77 zip_path = os.path.join(base_path, '..', 'Grocery.zip')78 copyfile(os.path.join(base_path_bak, 'Grocery.zip'), zip_path)79 with zipfile.ZipFile(zip_path) as myzip:80 myzip.extractall(os.path.join(base_path, '..'))81 return base_path82def an4_dataset_directory():83 base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),84 *"../../../../Examples/Speech/AN4/Data".split("/"))85 base_path = os.path.normpath(base_path)86 return base_path87def cmudict_dataset_directory():88 base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),89 *"../../../../Examples/SequenceToSequence/CMUDict/Data".split("/"))90 base_path = os.path.normpath(base_path)91 return base_path92 93# Read the flower and animal data set file94def prepare_resnet_v1_model():95 src_file = "PreTrainedModels/ResNet/v1/ResNet_18.model"96 dst_file = "Examples/Image/PretrainedModels/ResNet_18.model"97 98 _data_copier([src_file], [dst_file])99 100# Read the flower and animal data set file101def prepare_flower_data():102 src_files = ["Image/Flowers/102flowers.tgz", 103 "Image/Flowers/imagelabels.mat", 104 "Image/Flowers/imagelabels.mat"]...
file_io.py
Source:file_io.py
...62 src_path=src_path, dst_path=dst_path, overwrite=overwrite63 )64 return shutil.copyfile(src_path, dst_path)65 @staticmethod66 def get_local_path(path: str, **kwargs) -> str:67 if FVCorePathManager:68 return FVCorePathManager.get_local_path(path, **kwargs)69 return path70 @staticmethod71 def exists(path: str) -> bool:72 if FVCorePathManager:73 return FVCorePathManager.exists(path)74 return os.path.exists(path)75 @staticmethod76 def isfile(path: str) -> bool:77 if FVCorePathManager:78 return FVCorePathManager.isfile(path)79 return os.path.isfile(path)80 @staticmethod81 def ls(path: str) -> List[str]:82 if FVCorePathManager:...
fs_utils.py
Source:fs_utils.py
1import sys2from bot import aria2, LOGGER, DOWNLOAD_DIR, get_client3import shutil4import os5import pathlib6import magic7import tarfile8from .exceptions import NotSupportedExtractionArchive9def clean_download(path: str):10 if os.path.exists(path):11 LOGGER.info(f"Cleaning download: {path}")12 shutil.rmtree(path)13def start_cleanup():14 try:15 shutil.rmtree(DOWNLOAD_DIR)16 except FileNotFoundError:17 pass18def clean_all():19 aria2.remove_all(True)20 get_client().torrents_delete(torrent_hashes="all", delete_files=True)21 try:22 shutil.rmtree(DOWNLOAD_DIR)23 except FileNotFoundError:24 pass25def exit_clean_up(signal, frame):26 try:27 LOGGER.info("Please wait, while we clean up the downloads and stop running downloads")28 clean_all()29 sys.exit(0)30 except KeyboardInterrupt:31 LOGGER.warning("Force Exiting before the cleanup finishes!")32 sys.exit(1)33def get_path_size(path):34 if os.path.isfile(path):35 return os.path.getsize(path)36 total_size = 037 for root, dirs, files in os.walk(path):38 for f in files:39 abs_path = os.path.join(root, f)40 total_size += os.path.getsize(abs_path)41 return total_size42def tar(org_path):43 tar_path = org_path + ".tar"44 #path = pathlib.PurePath(org_path)45 LOGGER.info(f'Tar: orig_path: {org_path}, tar_path: {tar_path}')46 tar = tarfile.open(tar_path, "w")47 tar.add(org_path, arcname=os.path.basename(org_path))48 tar.close()49 return tar_path50def zip(name, path):51 root_dir = os.path.dirname(path)52 base_dir = os.path.basename(path.strip(os.sep))53 zip_file = shutil.make_archive(name, "zip", root_dir, base_dir)54 zip_path = shutil.move(zip_file, root_dir)55 LOGGER.info(f"Zip: {zip_path}")56 return zip_path57def get_base_name(orig_path: str):58 if orig_path.endswith(".tar.bz2"):59 return orig_path.replace(".tar.bz2", "")60 elif orig_path.endswith(".tar.gz"):61 return orig_path.replace(".tar.gz", "")62 elif orig_path.endswith(".bz2"):63 return orig_path.replace(".bz2", "")64 elif orig_path.endswith(".gz"):65 return orig_path.replace(".gz", "")66 elif orig_path.endswith(".tar.xz"):67 return orig_path.replace(".tar.xz", "")68 elif orig_path.endswith(".tar"):69 return orig_path.replace(".tar", "")70 elif orig_path.endswith(".tbz2"):71 return orig_path.replace("tbz2", "")72 elif orig_path.endswith(".tgz"):73 return orig_path.replace(".tgz", "")74 elif orig_path.endswith(".zip"):75 return orig_path.replace(".zip", "")76 elif orig_path.endswith(".7z"):77 return orig_path.replace(".7z", "")78 elif orig_path.endswith(".Z"):79 return orig_path.replace(".Z", "")80 elif orig_path.endswith(".rar"):81 return orig_path.replace(".rar", "")82 elif orig_path.endswith(".iso"):83 return orig_path.replace(".iso", "")84 elif orig_path.endswith(".wim"):85 return orig_path.replace(".wim", "")86 elif orig_path.endswith(".cab"):87 return orig_path.replace(".cab", "")88 elif orig_path.endswith(".apm"):89 return orig_path.replace(".apm", "")90 elif orig_path.endswith(".arj"):91 return orig_path.replace(".arj", "")92 elif orig_path.endswith(".chm"):93 return orig_path.replace(".chm", "")94 elif orig_path.endswith(".cpio"):95 return orig_path.replace(".cpio", "")96 elif orig_path.endswith(".cramfs"):97 return orig_path.replace(".cramfs", "")98 elif orig_path.endswith(".deb"):99 return orig_path.replace(".deb", "")100 elif orig_path.endswith(".dmg"):101 return orig_path.replace(".dmg", "")102 elif orig_path.endswith(".fat"):103 return orig_path.replace(".fat", "")104 elif orig_path.endswith(".hfs"):105 return orig_path.replace(".hfs", "")106 elif orig_path.endswith(".lzh"):107 return orig_path.replace(".lzh", "")108 elif orig_path.endswith(".lzma"):109 return orig_path.replace(".lzma", "")110 elif orig_path.endswith(".lzma2"):111 return orig_path.replace(".lzma2", "")112 elif orig_path.endswith(".mbr"):113 return orig_path.replace(".mbr", "")114 elif orig_path.endswith(".msi"):115 return orig_path.replace(".msi", "")116 elif orig_path.endswith(".mslz"):117 return orig_path.replace(".mslz", "")118 elif orig_path.endswith(".nsis"):119 return orig_path.replace(".nsis", "")120 elif orig_path.endswith(".ntfs"):121 return orig_path.replace(".ntfs", "")122 elif orig_path.endswith(".rpm"):123 return orig_path.replace(".rpm", "")124 elif orig_path.endswith(".squashfs"):125 return orig_path.replace(".squashfs", "")126 elif orig_path.endswith(".udf"):127 return orig_path.replace(".udf", "")128 elif orig_path.endswith(".vhd"):129 return orig_path.replace(".vhd", "")130 elif orig_path.endswith(".xar"):131 return orig_path.replace(".xar", "")132 else:133 raise NotSupportedExtractionArchive('File format not supported for extraction')134def get_mime_type(file_path):135 mime = magic.Magic(mime=True)136 mime_type = mime.from_file(file_path)137 mime_type = mime_type if mime_type else "text/plain"...
Using AI Code Generation
1const { path } = require('fast-check-monorepo');2console.log(path);3const { path } = require('fast-check-monorepo');4console.log(path);5const { path } = require('fast-check-monorepo');6console.log(path);7const { path } = require('fast-check-monorepo');8console.log(path);9const { path } = require('fast-check-monorepo');10console.log(path);11const { path } = require('fast-check-monorepo');12console.log(path);13const { path } = require('fast-check-monorepo');14console.log(path);15const { path } = require('fast-check-monorepo');16console.log(path);17const { path } = require('fast-check-monorepo');18console.log(path);19const { path } = require('fast-check-monorepo');20console.log(path);21const { path } = require('fast-check-monorepo');22console.log(path);23const { path } = require('fast-check-monorepo');24console.log(path);25const { path } = require('fast-check-monorepo');26console.log(path);27const { path } = require('fast-check-monorepo');28console.log(path);
Using AI Code Generation
1const path = require('path');2const { path } = require('fast-check-monorepo');3console.log(path);4const path = require('path');5const { path } = require('fast-check-monorepo');6console.log(path);7const path = require('path');8const { path } = require('fast-check-monorepo');9console.log(path);10const path = require('path');11const { path } = require('fast-check-monorepo');12console.log(path);13const path = require('path');14const { path } = require('fast-check-monorepo');15console.log(path);16const path = require('path');17const { path } = require('fast-check-monorepo');18console.log(path);19const path = require('path');20const { path } = require('fast-check-monorepo');21console.log(path);22const path = require('path');23const { path } = require('fast-check-monorepo');24console.log(path);25const path = require('path');26const { path } = require('fast-check-monorepo');27console.log(path);28const path = require('path');29const { path } = require('fast-check-monorepo');30console.log(path);31const path = require('path');32const { path } = require('fast-check-monorepo');33console.log(path);34const path = require('path');35const { path } = require('
Using AI Code Generation
1const path = require('path');2const fc = require('fast-check');3console.log(path.join(__dirname, 'index.js'));4const path = require('path');5const fc = require('fast-check');6console.log(path.join(__dirname, 'index.js'));7const path = require('path');8const fc = require('fast-check');9console.log(path.join(__dirname, 'index.js'));10const path = require('path');11const fc = require('fast-check');12console.log(path.join(__dirname, 'index.js'));13const path = require('path');14const fc = require('fast-check');15console.log(path.join(__dirname, 'index.js'));16const path = require('path');17const fc = require('fast-check');18console.log(path.join(__dirname, 'index.js'));19const path = require('path');20const fc = require('fast-check');21console.log(path.join(__dirname, 'index.js'));22const path = require('path');23const fc = require('fast-check');24console.log(path.join(__dirname, 'index.js'));25const path = require('path');26const fc = require('fast-check');27console.log(path.join(__dirname, 'index.js'));28const path = require('path');29const fc = require('fast-check');30console.log(path.join(__dirname, 'index.js'));31const path = require('path');32const fc = require('fast-check');33console.log(path.join(__dirname, 'index.js'));
Using AI Code Generation
1var path = require('path');2var path2 = require('path2');3console.log('path', path.join('a', 'b'));4console.log('path2', path2.join('a', 'b'));5var path = require('path');6var path2 = require('path2');7console.log('path', path.join('a', 'b'));8console.log('path2', path2.join('a', 'b'));9var path = require('path');10var path2 = require('path2');11console.log('path', path.join('a', 'b'));12console.log('path2', path2.join('a', 'b'));13var path = require('path');14var path2 = require('path2');15console.log('path', path.join('a', 'b'));16console.log('path2', path2.join('a', 'b'));17var path = require('path');18var path2 = require('path2');19console.log('path', path.join('a', 'b'));20console.log('path2', path2.join('a', 'b'));21var path = require('path');22var path2 = require('path2');23console.log('path', path.join('a', 'b'));24console.log('path2', path2.join('a', 'b'));25var path = require('path');26var path2 = require('path2');27console.log('path', path.join('a', 'b'));28console.log('path2', path2.join('a', 'b'));29var path = require('path');30var path2 = require('path2');31console.log('path', path.join('a', 'b'));32console.log('path2', path2.join('a', 'b'));
Using AI Code Generation
1const { path } = require('fast-check-monorepo');2describe('path', () => {3 it('should return the path to the file', () => {4 expect(path).toBe('test3.js');5 });6});7const path = require('path');8module.exports = {9 path: path.resolve(__dirname, 'index.js'),10};11const path = require('path');12module.exports = {13 path: path.resolve(__dirname, 'index.js'),14};
Using AI Code Generation
1const fc = require("fast-check");2const path = require("path");3fc.assert(4 fc.property(fc.string(), fc.string(), (str1, str2) => {5 const p = path.join(str1, str2);6 return p.indexOf(str1) === 0 && p.indexOf(str2) === 0;7 })8);9const fc = require("fast-check");10const path = require("path");11fc.assert(12 fc.property(fc.string(), fc.string(), (str1, str2) => {13 const p = path.join(str1, str2);14 return p.indexOf(str1) === 0 && p.indexOf(str2) === 0;15 })16);17const fc = require("fast-check");18const path = require("path");19fc.assert(20 fc.property(fc.string(), fc.string(), (str1, str2) => {21 const p = path.join(str1, str2);22 return p.indexOf(str1) === 0 && p.indexOf(str2) === 0;23 })24);25const fc = require("fast-check");26const path = require("path");27fc.assert(28 fc.property(fc.string(), fc.string(), (str1, str2) => {29 const p = path.join(str1, str2);30 return p.indexOf(str1) === 0 && p.indexOf(str2) === 0;31 })32);33const fc = require("fast-check");34const path = require("path");35fc.assert(36 fc.property(fc.string(), fc.string(), (str1, str2) => {37 const p = path.join(str1, str2);38 return p.indexOf(str1) === 0 && p.indexOf(str2) === 0;39 })40);41const fc = require("fast-check
Using AI Code Generation
1const path = require('path');2const { check, property } = require(path.join(__dirname, '..', 'fast-check-monorepo', 'lib', 'check'));3check(4 property([check.integer], (xs) => {5 return xs.filter((x) => x > 0).length <= xs.length;6 })7);8const path = require('path');9const { check, property } = require(path.join(__dirname, '..', 'fast-check-monorepo', 'lib', 'check'));10check(11 property([check.integer], (xs) => {12 return xs.filter((x) => x > 0).length <= xs.length;13 })14);15const path = require('path');16const { check, property } = require(path.join(__dirname, '..', 'fast-check-monorepo', 'lib', 'check'));17check(18 property([check.integer], (xs) => {19 return xs.filter((x) => x > 0).length <= xs.length;20 })21);22const path = require('path');23const { check, property } = require(path.join(__dirname, '..', 'fast-check-monorepo', 'lib', 'check'));24check(25 property([check.integer], (xs) => {26 return xs.filter((x) => x > 0).length <= xs.length;27 })28);29const path = require('path');30const { check, property } = require(path.join(__dirname, '..', 'fast-check-monorepo', 'lib', 'check'));31check(32 property([check.integer], (xs) => {33 return xs.filter((x) => x > 0).length <= xs.length;34 })35);36const path = require('path');37const { check, property } = require(path.join(__dirname, '..', 'fast-check-monorepo', 'lib', 'check'));38check(39 property([check.integer], (xs) => {40 return xs.filter((x) => x >
Using AI Code Generation
1const {path} = require('fast-check');2const {expect} = require('chai');3describe('path', function() {4 it('should generate a path', function() {5 const pathGen = path();6 const pathResult = pathGen.next().value;7 expect(pathResult).to.be.a('string');8 });9});10const {path} = require('fast-check');11const {expect} = require('chai');12describe('path', function() {13 it('should generate a path', function() {14 const pathGen = path();15 const pathResult = pathGen.next().value;16 expect(pathResult).to.be.a('string');17 });18});19const {path} = require('fast-check');20const {expect} = require('chai');21describe('path', function() {22 it('should generate a path', function() {23 const pathGen = path();24 const pathResult = pathGen.next().value;25 expect(pathResult).to.be.a('string');26 });27});28const {path} = require('fast-check');29const {expect} = require('chai');30describe('path', function() {31 it('should generate a path', function() {32 const pathGen = path();33 const pathResult = pathGen.next().value;34 expect(pathResult).to.be.a('string');35 });36});37const {path} = require('fast-check');38const {expect} = require('chai');39describe('path', function() {40 it('should generate a path', function() {41 const pathGen = path();42 const pathResult = pathGen.next().value;43 expect(pathResult).to.be.a('string');44 });45});46const {path} = require('fast-check');47const {expect} = require('chai');48describe('path',
Using AI Code Generation
1const { path } = require('fast-check-monorepo')2const fc = require('fast-check')3const arb = fc.array(fc.string(), 10, 20).map(path)4console.log(arb)5const { path } = require('fast-check')6const fc = require('fast-check')7const arb = fc.array(fc.string(), 10, 20).map(path)8console.log(arb)9const { path } = require('fast-check-monorepo')10const fc = require('fast-check')11const arb = fc.array(fc.string(), 10, 20).map(path)12console.log(arb)13const { path } = require('fast-check')14const fc = require('fast-check')15const arb = fc.array(fc.string(), 10, 20).map(path)16console.log(arb)17const { path } = require('fast-check-monorepo')18const fc = require('fast-check')19const arb = fc.array(fc.string(), 10, 20).map(path)20console.log(arb)21const { path } = require('fast-check')22const fc = require('fast-check')23const arb = fc.array(fc.string(), 10, 20).map(path)24console.log(arb)25const { path } = require('fast-check-monorepo')26const fc = require('fast-check')27const arb = fc.array(fc.string(), 10, 20).map(path)28console.log(arb)29const { path } = require('fast-check')30const fc = require('fast-check')31const arb = fc.array(fc.string(), 10, 20).map(path)32console.log(arb)33const { path } = require('fast-check-monorepo')34const fc = require('fast-check')35const arb = fc.array(fc.string(), 10, 20).map(path)36console.log(arb)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!